示例#1
0
        private void MessageInput(byte[] pkg)
        {
            byte cmd0 = pkg[2];
            byte cmd1 = pkg[3];

            switch (cmd0 & 0x0F)
            {
            case 0x01:    //system layer
                Output.Remove(0x21, cmd1, 0x00);
                if ((cmd1 == 0x08) || (cmd1 == 0x09))
                {
                    Device.InputMessage(pkg, pkg.Length);
                }
                break;

            case 0x05:    //zdo layer
                Output.Remove(0x25, (byte)(cmd1 & 0x7F), 0x00);
                if ((cmd0 & 0xF0) == 0x40)
                {
                    Device.InputMessage(pkg, pkg.Length);
                }
                break;

            case 0x09:    //app layer
                if ((cmd0 & 0xF0) == 0x40)
                {
                    UInt16 addr = ZigbeeCommon.BtoU16(pkg, 4);
                    Output.Remove(addr);
                    AppProc(pkg, pkg.Length);
                }
                break;
            }
        }
        public void ReqSendCommand(byte cmd0, byte cmd1, byte seq, byte stry, byte[] data)
        {
            Send_t snd = new Send_t();

            snd.cmd0    = cmd0;
            snd.cmd1    = cmd1;
            snd.seq     = seq;
            snd.runtime = ZigbeeApi.myZtool.GetSendTimeout();
            snd.stry    = stry;
            snd.data    = new byte[data.Length];
            Array.Copy(data, snd.data, data.Length);
            if (SendList != null)
            {
                if (snd.cmd0 == 0x29)
                {
                    UInt16 addr  = ZigbeeCommon.BtoU16(data, 0);
                    byte   point = data[2];
                    UInt16 cID   = ZigbeeCommon.BtoU16(data, 5);
                    byte   dlen  = data[7];
                    byte[] buf   = new byte[dlen];
                    Array.Copy(data, 8, buf, 0, dlen);
                    ZigbeeApi.myZtool.UpdateTestCommandInfo(ZigbeeApi.Device.GetDeviceCount(), addr, point, cID, buf);

                    ZigbeeApi.Device.SendCount(addr);
                }
                SendList.Add(snd);
            }
        }
示例#3
0
        private void NVMessageProc(byte[] data, int len)
        {
            switch (NVOperationType)
            {
            case ZigbeeCommon.NVReadNetWorkInfo:
                if (data[4] == 0x00)    //check success
                {
                    byte   channel = data[6];
                    UInt16 addr    = ZigbeeCommon.BtoU16(data, 7);
                    Array.Copy(data, 9, ExAddr, 0, 8);
                    UInt16 panID = ZigbeeCommon.BtoU16(data, 17);
                    Channel = channel;
                    PanID   = panID;
                    ZigbeeApi.myZtool.UptateNetWorkInfoTextBox(channel, panID);
                }
                break;

            case ZigbeeCommon.NVReadPreConfigKey:
                if (data[4] == 0x00)    //check success
                {
                    byte slen = data[5];
                    byte seq  = data[6];
                    Array.Copy(data, 7, NwkKey, 0, 16);
                    ZigbeeApi.myZtool.UpdatePreConfigKey(NwkKey);
                }
                break;
            }
        }
示例#4
0
        private void DeviceLeaveProc(byte[] data, int len)
        {
            UInt16 srcAddr;
            int    Index = 4;

            srcAddr = ZigbeeCommon.BtoU16(data, Index);
            Remove(srcAddr);
        }
示例#5
0
        private void NewJoinProc(byte[] data, int len)
        {
            UInt16 srcAddr;
            UInt16 devAddr;
            int    Index = 4;

            srcAddr = ZigbeeCommon.BtoU16(data, Index); Index += 2;
            devAddr = ZigbeeCommon.BtoU16(data, Index); Index += 2;
            byte[] exAddr = new byte[8];
            Array.Copy(data, Index, exAddr, 0, 8);
            AddDevice(devAddr, exAddr);
        }
 public void Poll()
 {
     try
     {
         if (SendList.Count > 0)
         {
             Send_t pkg = (Send_t)SendList[0];
             if (pkg.runtime >= ZigbeeCommon.Tick)
             {
                 pkg.runtime = pkg.runtime - ZigbeeCommon.Tick;
             }
             else
             {
                 pkg.runtime = 0;
             }
             if (pkg.runtime == 0)
             {
                 pkg.runtime = ZigbeeApi.myZtool.GetSendTimeout();
                 if (pkg.stry > 0)
                 {
                     Send(pkg.cmd0, pkg.cmd1, pkg.data);
                     pkg.stry--;
                     return;
                 }
                 else
                 {
                     if (pkg.cmd0 == 0x29)
                     {
                         UInt16 addr = ZigbeeCommon.BtoU16(pkg.data, 0);
                         ZigbeeApi.Device.LossCount(addr);
                     }
                     SendList.Remove(pkg);
                 }
             }
         }
     }
     catch (System.InvalidOperationException ex)
     {
         return;
     }
 }
 public void Remove(UInt16 addr)
 {
     try
     {
         foreach (Send_t pkg in SendList)
         {
             if (pkg.cmd0 == 0x29)
             {
                 UInt16 daddr = ZigbeeCommon.BtoU16(pkg.data, 0);
                 if (daddr == addr)
                 {
                     SendList.Remove(pkg);
                 }
             }
         }
     }
     catch (System.InvalidOperationException ex)
     {
         return;
     }
 }
示例#8
0
        public void MessageInput(byte[] data, int len)
        {
            UInt16 srcAddr;
            int    startID = 0;
            int    index   = 4;//start of data

            srcAddr = ZigbeeCommon.BtoU16(data, index); index += 2;
            if (data[index++] == 0x00)//if succees
            {
                byte totalNum   = data[index++];
                byte startDevID = data[index++];
                byte curNum     = data[index++];
                for (int i = 0; i < curNum; i++)
                {
                    index += 16;
                    UInt16 DevAddr = ZigbeeCommon.BtoU16(data, index);
                    if (ZigbeeApi.Device.CheckExist(DevAddr) == false)
                    {
                        ZigbeeApi.Device.AddDevice(DevAddr, null);
                    }
                    index += 2;
                    byte devType = (byte)((data[index] & 0x03) + 1);
                    index += 3;
                    byte lqi = data[index++];
                    //if ((devType == 0x02))
                    //     ZigbeeApi.Instance.ReqAssoc(DevAddr, 0);
                    startID = AddDeviceAssoc(srcAddr, devType, DevAddr, lqi);
                }
                startID = startDevID + curNum;
                if (startID < totalNum)
                {
                    ZigbeeApi.Instance.ReqAssoc(srcAddr, (byte)startID);
                }
                else
                {
                    SetFinishedFlag(srcAddr, true);
                }
            }
        }
示例#9
0
        private void ReadDescribeResponse(byte[] data, int len)
        {
            int    Index   = 4;
            UInt16 srcAddr = ZigbeeCommon.BtoU16(data, Index); Index += 2;
            byte   state   = data[Index++];

            if (state == 0x00)//succeed
            {
                UInt16   devAddr   = ZigbeeCommon.BtoU16(data, Index); Index += 2;
                byte     dlen      = data[Index++];
                byte     point     = data[Index++];
                UInt16   profileID = ZigbeeCommon.BtoU16(data, Index); Index += 2;
                UInt16   deviceID  = ZigbeeCommon.BtoU16(data, Index); Index += 2;
                byte     ver       = data[Index++];
                byte     inNum     = data[Index++];
                UInt16[] IncID     = ConvertcID(data, Index, inNum); Index += (inNum * 2);
                byte     outNum    = data[Index++];
                UInt16[] OutcID    = ConvertcID(data, Index, outNum);
                AddDescribe(srcAddr, point, deviceID, ver, IncID, OutcID);
                NewDeviceList.Add(srcAddr);
            }
        }
示例#10
0
        private void AppProc(byte[] pkg, int len)
        {
            int  Index = 4;
            byte cmd0;
            byte cmd1;
            byte dlen;

            cmd0 = pkg[2];
            cmd1 = pkg[3];
            dlen = pkg[4];
            UInt16 addr = ZigbeeCommon.BtoU16(pkg, Index);

            if (Device.CheckExist(addr) == true)
            {
                string str = "app rec:";
                str += ZigbeeCommon.BtoHexStr(pkg, 0, pkg.Length);
                myZtool.UpdateRecieveTextBox(str);
                Device.ReceiveCount(addr);
            }
            else
            {
                Device.AddDevice(addr, null);
            }
        }
示例#11
0
        private void ReadPointResponse(byte[] data, int len)
        {
            UInt16 srcAddr;
            UInt16 devAddr;
            int    Index;
            byte   pNum;
            byte   state;

            Index   = 1 + 1 + 1 + 1;
            srcAddr = ZigbeeCommon.BtoU16(data, Index); Index += 2;
            state   = data[Index++];
            if (state == 0x00)//succeed
            {
                devAddr = ZigbeeCommon.BtoU16(data, Index); Index += 2;
                pNum    = data[Index]; Index += 1;
                byte[] points = new byte[pNum];
                Array.Copy(data, Index, points, 0, pNum);
                for (int i = 0; i < points.Length; i++)
                {
                    ReqDescribe(srcAddr, points[i]);
                }
                AddPoints(srcAddr, points);
            }
        }