Exemplo n.º 1
0
        /*
         * Create a new decoder from bytes containing a
         * complete UECP frame, from STA to STO.
         * See 2.2.1 General Frame Format
         */
        //public byte[] UECPFrame = new byte[19];
        //public byte[] UECPFrame = new byte[263];


        public void Decode()
        {
            UECP_Parser uecp = new UECP_Parser();
            //Now lets start parsing our Message Field

            //Now lets start parsing our Message Field

            //uecp.ParseMessage();
            //Console.WriteLine(Tools.ByteArrayToString(UECPFrame));
            //Console.WriteLine("Break Here");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            UECP_Parser uecp   = new UECP_Parser();
            UECP        play   = new UECP();
            TcpListener server = new TcpListener(IPAddress.Any, 4002);

            // we set our IP address as server's address, and we also set the port: 9999

            server.Start();                                       // this will start the server

            while (true)                                          //we wait for a connection
            {
                TcpClient client = server.AcceptTcpClient();      //if a connection exists, the server will accept it

                NetworkStream ns = client.GetStream();            //networkstream is used to send/receive messages

                byte[] hello = new byte[100];                     //any message must be serialized (converted to byte array)
                hello = Encoding.Default.GetBytes("hello world"); //conversion string => byte array

                ns.Write(hello, 0, hello.Length);                 //sending the message

                while (client.Connected)                          //while the client is connected, we look for incoming messages
                {
                    byte[] msg = new byte[1024];                  //the messages arrive as byte array
                    //ns.Read(msg, 0, msg.);   //the same networkstream reads the message sent by the client
                    //ns.Read(uecp.UECPFrame, 0, 19);
                    ns.Read(uecp.UECPFrame, 0, uecp.UECPFrame.Length);
                    uecp.ParseFrame(uecp.UECPFrame);
                    //play.Decode();
                    //Console.WriteLine(Encoding.Default.GetString(uecp.UECPFrame).Trim());
                    //Array.Copy(msg, uecp.UECPFrame, 255);
                    //Console.WriteLine("Break Here");
                    //Console.WriteLine(Encoding.Default.GetString(msg).Trim()); //now , we write the message as string
                }
            }
        }
Exemplo n.º 3
0
        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;
            }
        }