//Nekaj spremenljivk ki jih potrebujemo public void ParseFrame(byte[] data) { //UECP_Parser UECP = new UECP_Parser(); //We have to initialize our class UECPFrame = RDSTools.RemoveByteStuffing(data); //Lets fill out array with data now Array.Copy(UECPFrame, 0, STA, 0, 1); //START Array.Copy(UECPFrame, 0 + 1, ADD, 0, 2); Array.Copy(UECPFrame, 0 + 1 + 2, SQC, 0, 1); Array.Copy(UECPFrame, 0 + 1 + 2 + 1, MFL, 0, 1); //We need this now Array.Copy(UECPFrame, 0 + 1 + 2 + 1 + 1, MSG, 0, MFL[0]); //We need MFL now Array.Copy(UECPFrame, 0 + 1 + 2 + 1 + 1 + MFL[0], CRC, 0, 2); //We still need MFL, to know where to start copying Array.Copy(UECPFrame, Array.IndexOf(UECPFrame, (byte)0xFF), STP, 0, 1); //STOP //Console.WriteLine(Encoding.Default.GetString(UECPFrame).Trim()); //Console.WriteLine(Tools.ByteArrayToString(UECPFrame)); //Lets fill out array with data now //Check CRC Now List <byte> CRC2Calculate = Tools.array2ListAtRange(UECPFrame, 0 + 1, 0 + 1 + 2 + 1 + 1 + (int)MFL[0]); List <byte> CRC2Check = CRC.ToList(); CRCOK = RDSTools.check_crc(CRC2Calculate, CRC2Check); //IF CRC IS OK IT SHOULD BE TRUE Console.WriteLine(CRCOK); ParseMessage(); //Check CRC Now }
public int dMEL; //MEL (Decimal) //Spremenljivke (vse kar ima S pred imenom ni byteArray) public void ParseMessage() { UECP_Parser UECP = new UECP_Parser(); //MEC /* * The Message Element Code identifies a particular * message, as defined in Section 3. * The Message Element Codeis within the range 01..FD. * The codes 00, FE and FF are not permitted for defining a MEC, * as they are used in this specification with a special meaning, * always defined in the conventions for a specific command. */ Array.Copy(MSG, 0, MEC, 0, 1); sMEC = RDSTools.FormatMEC(((MEC)MEC[0]).ToString()); bMEC = MEC[0].ToString("X2"); //Console.WriteLine("MEC: " + sMEC + " (" + bMEC + ")"); //MEC //PI (01) //DSN /* * The Data Set Number (DSN) permits a message to be targeted to the following within an encoder: * - a specific data set, * - the current data set, * - all data sets. */ Array.Copy(MSG, 1, DSN, 0, 1); dDSN = DSN[0]; if (dDSN == 0) { sDSN = "Current data set"; } else if (dDSN >= 1 && dDSN <= 253) { sDSN = "Specific data set"; } else if (dDSN == 254) { sDSN = "All data sets except the current data set"; } else if (dDSN == 255) { sDSN = "All data sets"; } //DSN //PSN /* * The Programme Service Number (PSN) permits a message element to operate a number of * services within one or more data sets and the corresponding addressing is shown in Table 6 */ Array.Copy(MSG, 2, PSN, 0, 1); dPSN = PSN[0]; if (dPSN == 0) { sPSN = "Special PSN for main service of specified data set(s)"; } else if (dPSN >= 1 && dPSN <= 255) { sPSN = "Specific service within data set(s)"; } //PSN //MEL Array.Copy(MSG, 3, MEL, 0, 1); dMEL = MEL[0]; //MEL Array.Copy(MSG, 3, MED, 0, dMEL); //MED //MED //Console.WriteLine("MEC: " + sMEC + " (" + bMEC + ")"); //Because we will have more than 5 conditions we will use switch instead of if/else switch (sMEC) { case "PI": ParsePI(dMEL, MED); break; case "PS": ParsePS(dMEL, MED); break; } }