예제 #1
0
        private List <Byte> parseATresponse(List <Byte> packet)
        {
            char[] atIds = new char[2];
            atIds[0] = (char)packet[0];       //get LSB
            atIds[1] = (char)packet[1];       //get MSB

            String atcmd = new string(atIds); //make the at string

            packet.RemoveRange(0, 2);         //remove the at identifier

            AT_RESPONSE_STATUS status = (AT_RESPONSE_STATUS)packet[0];

            if (status != AT_RESPONSE_STATUS.OK)        //check response status..throw exception
            {                                           //on anything other than ok.....
                String msg = " AT Response : {0}";
                msg = String.Format(msg, status);
                throw new Xbee_Exception(msg);
            }

            packet.RemoveAt(0);                         //remove the status byte

            switch (atcmd)
            {
            case "NI":
                break;

                //parsing of other at commands to be done
            }
            return(packet);
        }
예제 #2
0
        public List <Byte> parseATresponse(List <Byte> packet, String atCommand)
        {
            #region TRACE_CODE
            String traceString = DateTime.Now.ToString();
            foreach (Byte b in packet)
            {
                traceString += "0x" + b.ToString("x2") + " ";
            }
            traceString += Environment.NewLine;

            _xbeeTrace.TraceInformation(traceString);
            foreach (TraceListener l in _xbeeTrace.Listeners)
            {
                l.Flush();
            }

            #endregion


            if (communicationMode == COMMUNICATION_MODE.RAW)
            {
                return(packet);
            }

            if (packet[0] != (Byte)ESCAPE_CHARS.STX)        //check for start delimiter
            {
                throw new Xbee_Exception("Start Delimiter Error");
            }

            packet.RemoveAt(0);                                                    //remove the start delimiter
            Byte[] packetLengthArray = { packet[1], packet[0] };                   //msb and lsb of length
            short  packetLength      = BitConverter.ToInt16(packetLengthArray, 0); //convert to short

            packet.RemoveRange(0, 2);                                              //remove the length fields

            Byte checksum = packet[packet.Count - 1];                              //get the received checksum


            if (communicationMode == COMMUNICATION_MODE.API_ESC)
            {
                packet = removeEscapeChars(packet);
            }

            packet.RemoveAt(packet.Count - 1);            //remove the checksum from the packet



            if (computeCheckSum(packet) != checksum)       //validate checksum
            {
                throw new Xbee_Exception("Checksum Error");
            }

            if (packetLength != packet.Count)       //verify received byte count
            {
                throw new Xbee_Exception("Recevied Length mismatch ");
            }
            if (packet[0] != (Byte)API_ID.ATRSP)    //verify api id
            {
                throw new Xbee_Exception(" API identifier mismatch");
            }
            else
            {
                packet.RemoveAt(0);     //remove the api id
            }

            packet.RemoveAt(0);         //remove frame id
            char[] atIds = new char[2];
            atIds[0] = (char)packet[0]; //get LSB
            atIds[1] = (char)packet[1]; //get MSB

            String atcmd = new string(atIds);



            if (atcmd != atCommand)
            {
                throw new Xbee_Exception(" AT command mismatch");
            }

            packet.RemoveRange(0, 2);

            AT_RESPONSE_STATUS status = (AT_RESPONSE_STATUS)packet[0];

            if (status != AT_RESPONSE_STATUS.OK)
            {
                String msg = " AT Response : {0}";
                msg = String.Format(msg, status);
                throw new Xbee_Exception(msg);
            }

            packet.RemoveAt(0);  //remove the status byte

            return(packet);
        }