Exemple #1
0
        private int check_package(byte[] pdata, int startID, int len)
        {
            int  slen;
            byte fcs, sum;

            if (len < 5)
            {
                return(1);
            }
            slen = (pdata[startID + 1] + 5);
            if (slen > len)//package length error!
            {
                return(1);
            }
            fcs = pdata[startID + (slen - 1)];
            sum = ZigbeeCommon.GetXor(pdata, startID + 1, (slen - 2));
            if (fcs == sum)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
        private int Send(byte cmd0, byte cmd1, byte[] data)
        {
            int slen = data.Length + 5;

            byte[] buf = new byte[slen];
            buf[0] = 0xFE;
            buf[1] = (byte)data.Length;
            buf[2] = cmd0;
            buf[3] = cmd1;
            Array.Copy(data, 0, buf, 4, data.Length);
            buf[slen - 1] = ZigbeeCommon.GetXor(buf, 1, (slen - 1));
            String str = "snd:" + ZigbeeCommon.BtoHexStr(buf, 0, buf.Length);

            ZigbeeApi.myZtool.UpdateSendTextBox(str);
            if (ZigbeeApi.Uart.IsOpen)
            {
                ZigbeeApi.Uart.Write(buf, 0, buf.Length);
            }
            return(0);
        }