Beispiel #1
0
        private void OnData(V2ExtensionPacket v2ExtensionPacket)
        {
            try
            {
                using (var ms = new MemoryStream(v2ExtensionPacket.Payload.Payload))
                {
                    var header = PayloadHelper.ReadData <PayloadPacketHeader>(ms);
                    if (FilterDoublePackets(header) == false)
                    {
                        Interlocked.Increment(ref _doublePacketsCount);
                        return;
                    }


                    if (!_dataCallbacks.TryGetValue(header.Path, out var callback))
                    {
                        //_logger.Warn($"Receive unsupported data '{packetInfo.Path}'");
                        return;
                    }
                    callback(new DeviceIdentity {
                        ComponentId = v2ExtensionPacket.ComponenId, SystemId = v2ExtensionPacket.SystemId
                    }, ms);
                }
            }
            catch (Exception e)
            {
                _logger.Warn($"Error execute data:{e.Message}");
            }
        }
Beispiel #2
0
        private bool CheckPacketTarget(V2ExtensionPacket packet)
        {
            var network   = (packet.Payload.TargetNetwork == 0 || _identity.NetworkId == 0 || packet.Payload.TargetNetwork == _identity.NetworkId);
            var system    = (packet.Payload.TargetSystem == 0 || _identity.SystemId == 0 || packet.Payload.TargetSystem == _identity.SystemId);
            var component = (packet.Payload.TargetComponent == 0 || _identity.ComponenId == 0 || packet.Payload.TargetComponent == _identity.ComponenId);

            return(network && system && component);
        }
Beispiel #3
0
        private void OnData(V2ExtensionPacket v2ExtensionPacket)
        {
            try
            {
                Interlocked.Increment(ref _txPacketsCounter);

                PayloadPacketHeader packetInfo = null;

                using (var ms = new MemoryStream(v2ExtensionPacket.Payload.Payload))
                {
                    packetInfo = PayloadHelper.ReadData <PayloadPacketHeader>(ms);

                    if (FilterDoublePackets(packetInfo) == false)
                    {
                        Interlocked.Increment(ref _doublePacketsCounter);
                        return;
                    }


                    var data = new byte[ms.Length - ms.Position];
                    ms.Read(data, 0, data.Length);
                    var pkt = new V2Packet
                    {
                        Device = new DeviceIdentity {
                            ComponentId = v2ExtensionPacket.ComponenId, SystemId = v2ExtensionPacket.SystemId
                        },
                        Header      = packetInfo,
                        Data        = data,
                        MessageType = v2ExtensionPacket.Payload.MessageType,
                    };
                    _onData.OnNext(pkt);
                }
            }
            catch (Exception e)
            {
                _logger.Warn($"Error execute data:{e.Message}");
            }
        }