示例#1
0
        public virtual void ProcessPacket(XBeeResponse packet)
        {
            if (Finished)
            {
                return;
            }

            var packetAccepted = Filter == null || Filter.Accepted(packet);

            var finished = Filter != null && Filter.Finished();

            if (!packetAccepted)
            {
                return;
            }

            if (ResponseHandler != null)
            {
                ResponseHandler.Invoke(packet, finished);
            }
            else
            {
                Packets.Add(packet);
            }

            Finished = finished;
        }
示例#2
0
        private XBeeResponse ParsePacket()
        {
            try
            {
                ParseStartTime = DateTime.Now;
                BytesRead      = 0;
                _checksum.Clear();

                // length of api structure, starting here (not including start byte or length bytes, or checksum)
                // length doesn't account for escaped bytes
                Length = UshortUtils.ToUshort(Read("Length MSB"), Read("Length LSB"));

                Logger.LowDebug("packet length is " + ByteUtils.ToBase16(Length));

                // total packet length = stated length + 1 start byte + 1 checksum byte + 2 length bytes

                ApiId = (ApiId)Read("API ID");

                Logger.LowDebug("Handling ApiId: " + ApiId);

                // TODO parse I/O data page 12. 82 API Identifier Byte for 64 bit address A/D data (83 is for 16bit A/D data)
                // TODO XBeeResponse should implement an abstract parse method

                _response = GetResponse(ApiId);

                if (_response == null)
                {
                    Logger.Warn("Did not find a response handler for ApiId [" + ByteUtils.ToBase16((byte)ApiId));
                    _response = new GenericResponse();
                }

                _response.Parse(this);
                _response.Checksum = Read("Checksum");

                if (RemainingBytes > 0)
                {
                    throw new XBeeParseException("There are remaining bytes after parsing the packet");
                }

                _response.Finish();
            }
            catch (Exception e)
            {
                Logger.Error("Failed to parse packet due to exception. " + e.Message);
                _response = new ErrorResponse {
                    ErrorMsg = e.Message, Exception = e
                };
            }
            finally
            {
                if (_response != null)
                {
                    _response.Length = Length;
                    _response.ApiId  = ApiId;
                }
            }

            return(_response);
        }
        public virtual bool Accepted(XBeeResponse packet)
        {
#if WINDOWS_UWP
            return(packet.GetType() == _expectedType || packet.GetType().GetTypeInfo().IsSubclassOf(_expectedType));
#else
            return(_expectedType.IsInstanceOfType(packet));
#endif
        }
示例#4
0
 public virtual bool Accepted(XBeeResponse packet)
 {
     #if WINDOWS_UWP
     return packet.GetType() == _expectedType || packet.GetType().GetTypeInfo().IsSubclassOf(_expectedType);
     #else
     return _expectedType.IsInstanceOfType(packet);
     #endif
 }
示例#5
0
 public bool Equals(XBeeResponse other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Arrays.AreEqual(other.RawPacketBytes, RawPacketBytes)
         && Arrays.AreEqual(other._processedPacketBytes, _processedPacketBytes)
         && Equals(other.Length, Length)
         && Equals(other.ApiId, ApiId)
         && other.Checksum == Checksum
         && other.Error.Equals(Error);
 }
示例#6
0
        public override bool Accepted(XBeeResponse packet)
        {
            if (!base.Accepted(packet))
                return false;

            if (_expectedCount == 0)
                return false;

            _expectedCount--;
            _finished = _expectedCount == 0;
            return true;
        }
        public override bool Accepted(XBeeResponse packet)
        {
            if (!base.Accepted(packet))
            {
                return(false);
            }

            if (_expectedCount == 0)
            {
                return(false);
            }

            _expectedCount--;
            _finished = _expectedCount == 0;
            return(true);
        }
示例#8
0
 public bool Equals(XBeeResponse other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Arrays.AreEqual(other.RawPacketBytes, RawPacketBytes) &&
            Arrays.AreEqual(other._processedPacketBytes, _processedPacketBytes) &&
            Equals(other.Length, Length) &&
            Equals(other.ApiId, ApiId) &&
            other.Checksum == Checksum &&
            other.Error.Equals(Error));
 }
示例#9
0
        public virtual void ProcessPacket(XBeeResponse packet)
        {
            if (Finished)
                return;

            var packetAccepted = Filter == null || Filter.Accepted(packet);

            Finished = (Filter != null && Filter.Finished());

            if (!packetAccepted)
                return;

            if (ResponseHandler != null)
            {
                ResponseHandler.Invoke(packet, Finished);
            }
            else
            {
                Packets.Add(packet);
            }
        }
示例#10
0
 public virtual bool Accepted(XBeeResponse packet)
 {
     return(_expectedType.IsInstanceOfType(packet));
 }
示例#11
0
        private XBeeResponse ParsePacket()
        {
            try
            {
                ParseStartTime = DateTime.Now;
                BytesRead = 0;
                _checksum.Clear();
                
                // length of api structure, starting here (not including start byte or length bytes, or checksum)
                // length doesn't account for escaped bytes
                Length = UshortUtils.ToUshort(Read("Length MSB"), Read("Length LSB"));

                Logger.LowDebug("packet length is " + ByteUtils.ToBase16(Length));

                // total packet length = stated length + 1 start byte + 1 checksum byte + 2 length bytes

                ApiId = (ApiId)Read("API ID");

                Logger.LowDebug("Handling ApiId: " + ApiId);

                // TODO parse I/O data page 12. 82 API Identifier Byte for 64 bit address A/D data (83 is for 16bit A/D data)
                // TODO XBeeResponse should implement an abstract parse method

                _response = GetResponse(ApiId);

                if (_response == null)
                {
                    Logger.Warn("Did not find a response handler for ApiId [" + ByteUtils.ToBase16((byte)ApiId));
                    _response = new GenericResponse();
                }

                _response.Parse(this);
                _response.Checksum = Read("Checksum");

                if (RemainingBytes > 0)
                    throw new XBeeParseException("There are remaining bytes after parsing the packet");

                _response.Finish();
            }
            catch (Exception e)
            {
                Logger.Error("Failed to parse packet due to exception. " + e.Message);
                _response = new ErrorResponse { ErrorMsg = e.Message, Exception = e };
            }
            finally
            {
                if (_response != null)
                {
                    _response.Length = Length;
                    _response.ApiId = ApiId;
                }
            }

            return _response;
        }
示例#12
0
 protected void OnModemStatusReceived(XBeeResponse response, bool finished)
 {
     var statusResponse = (ModemStatusResponse) response;
     NotifyStatusChanged(statusResponse.Status);
 }
示例#13
0
        protected void OnDataReceived(XBeeResponse response, bool finished)
        {
            if (response is Api.Wpan.RxResponse)
            {
                var rxResponse = response as Api.Wpan.RxResponse;
                NotifyDataReceived(rxResponse.Payload, rxResponse.Source);
            }
            else if (response is RxResponse)
            {
                if (response is ExplicitRxResponse)
                {
                    var profileId = (response as ExplicitRxResponse).ProfileId;
                    var clusterId = (response as ExplicitRxResponse).ClusterId;

                    // if module AtCmd.ApiOptions has been set to value other than default (0)
                    // received API frames will be transported using explicit frames
                    // those frames have profile id set to Zigbee.ProfileId.Digi
                    if (profileId != (ushort)ProfileId.Digi)
                        return;

                    // cluster id will be set to ApiId value
                    switch ((ApiId)clusterId)
                    {
                        case ApiId.TxRequest16:
                        case ApiId.TxRequest64:
                        case ApiId.ZnetTxRequest:
                        case ApiId.ZnetExplicitTxRequest:
                            break;

                        default:
                            return;
                    }
                }

                var rxResponse = response as RxResponse;
                NotifyDataReceived(rxResponse.Payload, rxResponse.SourceSerial);
            }
        }
示例#14
0
        protected void OnAddressReceived(XBeeResponse response, bool finished)
        {
            if (response is RemoteAtResponse)
            {
                var atResponse = response as RemoteAtResponse;
                AddressLookup[atResponse.RemoteSerial] = atResponse.RemoteAddress;
            }
            else if (response is RxResponse)
            {
                var zigbeeResponse = response as RxResponse;
                AddressLookup[zigbeeResponse.SourceSerial] = zigbeeResponse.SourceAddress;
            }
            else if (response is TxStatusResponse && _currentRequest is Api.Zigbee.TxRequest)
            {
                var txRequest = _currentRequest as Api.Zigbee.TxRequest;
                var txResponse = response as TxStatusResponse;
                var dataDelivered = txResponse.DeliveryStatus == TxStatusResponse.DeliveryResult.Success;

                AddressLookup[txRequest.DestinationSerial] = dataDelivered
                    ? txResponse.DestinationAddress
                    : XBeeAddress16.Unknown;
            }
            else if (response is NodeIdentificationResponse)
            {
                var identPacket = response as NodeIdentificationResponse;
                AddressLookup[identPacket.Sender.SerialNumber] = identPacket.Sender.NetworkAddress;
                AddressLookup[identPacket.Remote.SerialNumber] = identPacket.Remote.NetworkAddress;
            }
        }
示例#15
0
        protected DiscoverResult GetDiscoverResponse(XBeeResponse response)
        {
            var discoverResponse = Config.IsSeries1()
                    ? (DiscoverResult) Api.Wpan.DiscoverResult.Parse(response)
                    : Api.Zigbee.DiscoverResult.Parse(response);

            if (_addressLookupEnabled)
            {
                var nodeInfo = discoverResponse.NodeInfo;
                AddressLookup[nodeInfo.SerialNumber] = nodeInfo.NetworkAddress;
            }

            return discoverResponse;
        }
示例#16
0
 public virtual bool Accepted(XBeeResponse packet)
 {
     return _expectedType.IsInstanceOfType(packet);
 }