Пример #1
0
        /// <summary>
        /// Decodes from a header packet if the service is being transmitted serially, and signals a header to the magazines if it is.
        /// </summary>
        /// <param name="packet">The teletext packet to be decoded.</param>
        private void DecodeHeader(Packet packet)
        {
            // Get the serial flag
            bool magazineSerial = false;
            byte controlByte    = Decode.Hamming84(packet.Data[7]);

            if (controlByte != 0xff)
            {
                magazineSerial = Convert.ToBoolean((byte)(controlByte & 0x01));
            }
            // If the flag is set, loop through each magazine and signal to them that a header has been received
            if (magazineSerial)
            {
                for (int i = 0; i < 8; i++)
                {
                    // Only signal a header has been received if the magazine is not the one for this header
                    if (i + 1 != packet.Magazine)
                    {
                        Magazine[i].SerialHeaderReceived();
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Initialises a new instance of the <see cref="T:TtxFromTS.Teletext.Packet"/> class.
        /// </summary>
        /// <param name="packetData">The teletext packet data to be decoded.</param>
        public Packet(byte[] packetData)
        {
            // Store the original full packet data
            FullPacketData = packetData;
            // Retrieve the field
            Field = !Convert.ToBoolean((packetData[0] >> 2) & 0x1);
            // Retrieve the line number
            LineNumber = (byte)(Decode.Reverse(packetData[0]) & 0xF);
            // Retrieve the framing code
            FramingCode = packetData[1];
            // Check the framing code is valid, otherwise mark the packet as containing errors
            DecodingError = FramingCode != 0x27;
            // Retrieve and decode the magazine number
            byte address1 = Decode.Hamming84(packetData[2]);

            Magazine = address1 & 0x07;
            // Check the magazine number is valid, otherwise mark the packet as containing errors, and change 0 to 8
            if (Magazine > 7)
            {
                Magazine      = null;
                DecodingError = true;
            }
            else if (Magazine == 0)
            {
                Magazine = 8;
            }
            // Retrieve and decode the packet number
            byte address2 = Decode.Hamming84(packetData[3]);

            Number = (address1 >> 3) | (address2 << 1);
            // Set the packet type from the packet number, or if it is not a valid number mark the packet as containing errors
            switch (Number)
            {
            case 0:
                Type = PacketType.Header;
                break;

            case int packetNumber when packetNumber <= 23:
                Type = PacketType.PageBody;
                break;

            case 24:
                Type = PacketType.Fastext;
                break;

            case 25:
                Type = PacketType.TOPCommentary;
                break;

            case 26:
                Type = PacketType.PageReplacements;
                break;

            case 27:
                Type = PacketType.LinkedPages;
                break;

            case 28:
                Type = PacketType.PageEnhancements;
                break;

            case 29:
                Type = PacketType.MagazineEnhancements;
                break;

            case int packetNumber when packetNumber == 30 && Magazine == 8:
                Type = PacketType.BroadcastServiceData;
                break;

            default:
                Number        = null;
                DecodingError = true;
                break;
            }
            // Retrieve packet data
            Data = new byte[packetData.Length - 4];
            Buffer.BlockCopy(packetData, 4, Data, 0, packetData.Length - 4);
        }
Пример #3
0
        /// <summary>
        /// Decodes information from a broadcast services data packet.
        /// </summary>
        /// <param name="packet">The teletext packet to be decoded.</param>
        private void DecodeBroadcastServiceData(Packet packet)
        {
            // Get the designation byte
            byte designationByte = Decode.Hamming84(packet.Data[0]);

            // Check the designation byte does not have unrecoverable errors, and if it does ignore the packet
            if (designationByte == 0xff)
            {
                return;
            }
            // Decode the designation code and multiplex status
            bool multiplexed = Convert.ToBoolean(designationByte & 0x01);
            int  designation = designationByte >> 1;

            // Check the designation code is 0 (format 1) or 1 (format 2), otherwise ignore the packet
            if (designation > 1)
            {
                return;
            }
            // Set the multiplexed status
            Multiplexed = !multiplexed;
            // If the packet is format 1, decode the network identification code
            if (designation == 0)
            {
                byte[] networkID = { packet.Data[7], packet.Data[8] };
                NetworkID = BitConverter.ToString(networkID).Replace("-", "");
            }
            // Get the status display
            byte[] statusCharacters = new byte[packet.Data.Length - 20];
            for (int i = 20; i < packet.Data.Length; i++)
            {
                statusCharacters[i - 20] = Decode.OddParity(packet.Data[i]);
            }
            StatusDisplay = Encoding.ASCII.GetString(statusCharacters);
            // Decode the digits for the inital page number
            byte pageUnits = Decode.Hamming84(packet.Data[1]);
            byte pageTens  = Decode.Hamming84(packet.Data[2]);
            // Decode the bytes for the initial subcode
            byte subcode1 = Decode.Hamming84(packet.Data[3]);
            byte subcode2 = Decode.Hamming84(packet.Data[4]);
            byte subcode3 = Decode.Hamming84(packet.Data[5]);
            byte subcode4 = Decode.Hamming84(packet.Data[6]);

            // If the subcode bytes containing the magazine number contains errors, stop processing
            if (subcode2 == 0xff || subcode4 == 0xff)
            {
                return;
            }
            // If the page number digits don't contain errors, set the initial page number
            if (pageUnits != 0xff && pageTens != 0xff)
            {
                // Get the magazine number, changing 0 to 8
                byte magazineNumber = (byte)((subcode2 >> 3) | ((subcode4 & 0x0C) >> 1));
                if (magazineNumber == 0)
                {
                    magazineNumber = 8;
                }
                // Set the initial page number
                InitialPage = magazineNumber.ToString("X1") + ((pageTens << 4) | pageUnits).ToString("X2");
            }
            // If the remaining subcode bytes don't contain any errors, set the subcode
            if (subcode1 != 0xff && subcode3 != 0xff)
            {
                byte[] fullSubcode = { (byte)(((subcode4 & 0x03) << 4) | subcode3), (byte)(((subcode2 & 0x07) << 4) | subcode1) };
                InitialSubcode = BitConverter.ToString(fullSubcode).Replace("-", "");
            }
        }