示例#1
0
        public bool SendMessage(vscp_message_d msg)
        {
            string data = "SEND 0," + msg.vclass.ToString() + "," + msg.vtype.ToString() + "," + msg.oaddr.ToString() + ",0,-,";


            for (int i = 0; i < msg.data.Length; i++)
            {
                data += msg.data[i].ToString();
                if (i != msg.data_len - 1)
                {
                    data += ",";
                }
            }

            data += "\r\n";

            tcp.Send(Encoding.ASCII.GetBytes(data));

            data = ReadTCP();


            if (!data.Contains("+OK"))
            {
                return(false);
            }



            return(true);
        }
示例#2
0
        private void send_message_VSCP(vscp_message msg)
        {
            vscp_message_d mes = new vscp_message_d();



            mes.priority  = (uint)msg.priority;
            mes.oaddr     = (uint)msg.nickname;
            mes.vclass    = (uint)msg.vclass;
            mes.vtype     = (uint)msg.type;
            mes.hardcoded = msg.hard_mask;
            mes.data_len  = (uint)msg.data.Length;



            mes.data = new byte[msg.data.Length / 2];


            for (int i = 0; i < mes.data.Length; i++)
            {
                mes.data[i] = Convert.ToByte(msg.data.Substring(i * 2, 1) + msg.data.Substring(i * 2 + 1, 1), 16);
            }

            vscp.SendMessage(mes);
        }
示例#3
0
        public vscp_message_d[] GetMsg(int count)
        {
            if (!tcp.isConnected | (count == -1))
            {
                return(null);
            }

            vscp_message_d[] msg = new vscp_message_d[count];

            for (int i = 0; i < count; i++)
            {
                msg[i] = new vscp_message_d();
            }



            tcp.Send(Encoding.ASCII.GetBytes("RETR " + count.ToString() + "\r\n"));


            string rc = ReadTCP();



            //   head  class  type  obid   timestamp                           guid
            //   112,  20,    9,    1,    1884336112, FF:FF:FF:FF:FF:FF:FF:FE:7A:79:05:4C:00:01:00:01,  0, 0, 1
            //     0    1     2     3          4                                     5                  6  7  8

            if (!rc.Contains("+OK"))
            {
                return(null);
            }


            rc = rc.Replace("\r", "");

            string[] data = rc.Split('\n');


            for (int i = 0; i < count; i++)
            {
                if (data[i].Contains("+OK"))
                {
                    break;
                }

                string[] val = data[i].Split(',');

                msg[i].vclass    = Convert.ToUInt32(val[1]);
                msg[i].vtype     = Convert.ToUInt32(val[2]);
                msg[i].timestamp = Convert.ToUInt32(val[4]) / 1000;
                msg[i].oaddr     = Convert.ToUInt32(val[3]);

                uint pom = Convert.ToUInt32(val[0]);

                msg[i].priority = (pom & 0xE) >> 5;

                // TODO if((head & 0xE)


                pom = (uint)val.Length - 6;

                if (pom > 0)
                {
                    msg[i].data_len = pom;

                    msg[i].data = new byte[pom];

                    for (int x = 0; x < pom; x++)
                    {
                        msg[i].data[x] = Convert.ToByte(val[6 + x], 10);
                    }
                }
            }

            return(msg);
        }
        public vscp_message_d[] GetMsg(int count)
        {
            if (!tcp.isConnected | (count == -1))
                return null;

            vscp_message_d[] msg = new vscp_message_d[count];

            for (int i = 0; i < count; i++)
                msg[i] = new vscp_message_d();

            tcp.Send(Encoding.ASCII.GetBytes("RETR " + count.ToString() +"\r\n"));

            string rc = ReadTCP();

            //   head  class  type  obid   timestamp                           guid
            //   112,  20,    9,    1,    1884336112, FF:FF:FF:FF:FF:FF:FF:FE:7A:79:05:4C:00:01:00:01,  0, 0, 1
            //     0    1     2     3          4                                     5                  6  7  8

             if (!rc.Contains("+OK"))
                return null;

            rc = rc.Replace("\r", "");

            string[] data = rc.Split('\n');

            for (int i = 0; i < count; i++)
            {

                if (data[i].Contains("+OK"))
                    break;

                string[] val = data[i].Split(',');

                msg[i].vclass = Convert.ToUInt32(val[1]);
                msg[i].vtype = Convert.ToUInt32(val[2]);
                msg[i].timestamp = Convert.ToUInt32(val[4]) / 1000;
                msg[i].oaddr = Convert.ToUInt32(val[3]);

                uint pom = Convert.ToUInt32(val[0]);

                msg[i].priority = (pom & 0xE) >> 5;

                // TODO if((head & 0xE)

                pom = (uint)val.Length - 6;

                if (pom > 0)
                {
                    msg[i].data_len = pom;

                    msg[i].data = new byte[pom];

                    for (int x = 0; x < pom; x++)
                    {
                        msg[i].data[x] = Convert.ToByte(val[6 + x], 10);
                    }
                }
            }

            return msg;
        }
        public bool SendMessage(vscp_message_d msg)
        {
            string data = "SEND 0," + msg.vclass.ToString() + "," + msg.vtype.ToString() + "," + msg.oaddr.ToString() + ",0,-,";

            for (int i = 0; i < msg.data.Length; i++)
            {
                data += msg.data[i].ToString();
                if (i != msg.data_len - 1)
                    data += ",";
            }

            data += "\r\n";

            tcp.Send(Encoding.ASCII.GetBytes(data));

            data = ReadTCP();

            if (!data.Contains("+OK"))
                return false;

            return true;
        }
示例#6
0
        private void send_message_VSCP(vscp_message msg)
        {
            vscp_message_d mes = new vscp_message_d();

            mes.priority = (uint)msg.priority;
            mes.oaddr = (uint)msg.nickname;
            mes.vclass = (uint)msg.vclass;
            mes.vtype = (uint)msg.type;
            mes.hardcoded = msg.hard_mask;
            mes.data_len = (uint)msg.data.Length;

            mes.data = new byte[msg.data.Length / 2];

            for (int i = 0; i < mes.data.Length; i++)
                mes.data[i] = Convert.ToByte(msg.data.Substring(i * 2, 1) + msg.data.Substring(i * 2 + 1, 1), 16);

            vscp.SendMessage(mes);
        }