/// <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("-", ""); } }