コード例 #1
0
        protected override async Task HandleAsync(PulseReport request, IList <OutgoingMessage> outgoingMessages,
                                                  CancellationToken cToken)
        {
            var node = await _findNodeQuery.ByRfIdAsync(request.FromRfAddress,
                                                        NodeInclude.AggregatedData | NodeInclude.Ports);

            if (node == null)
            {
                throw new NodeNotFoundException(request.FromRfAddress);
            }
            _touchNode.Touch(node, request.Rssi);

            var port = node.Ports.OfType <PulseSensor>().SingleOrDefault(_ => _.PortNumber == request.PortNumber);

            if (port == null)
            {
                node.Ports.Add(port = new PulseSensor()
                {
                    Node       = node,
                    PortNumber = request.PortNumber,
                    PulseCount = 0,
                });
            }
            port.PulseCount += request.NewPulse;
            port.History     = new List <PulseHistory>
            {
                new PulseHistory
                {
                    Timestamp = _timeProvider.UtcNow,
                    Rssi      = request.Rssi,
                    NewPulses = request.NewPulse,
                    Total     = port.PulseCount,
                }
            };
        }
コード例 #2
0
        protected override async Task HandleAsync(PushButtonPressedReport request,
                                                  IList <OutgoingMessage> outgoingMessages, CancellationToken cToken)
        {
            var node = await _findNodeQuery.ByRfIdAsync(request.FromRfAddress,
                                                        NodeInclude.AggregatedData | NodeInclude.Ports);

            if (node == null)
            {
                throw new NodeNotFoundException(request.FromRfAddress);
            }
            _touchNode.Touch(node, request.Rssi);

            var port = node.Ports.OfType <PushButtonSensor>().SingleOrDefault(_ => _.PortNumber == request.PortNumber);

            if (port == null)
            {
                if (request.PortNumber < (byte)ReservedPortNumber.Last)
                {
                    throw new ArgumentException($"PortNumber {request.PortNumber} is reserved.");
                }
                if (node.Ports.Any(x => x.PortNumber == request.PortNumber))
                {
                    throw new ArgumentException("A port already exist with that number that is not of type PushButton");
                }
                node.Ports.Add(port = new PushButtonSensor()
                {
                    Node       = node,
                    PortNumber = request.PortNumber,
                });
            }

            port.LastPressStyle = request.PressStyle;
            port.History        = new List <PushButtonHistory>
            {
                new PushButtonHistory()
                {
                    Timestamp  = _timeProvider.UtcNow,
                    Rssi       = request.Rssi,
                    PressStyle = request.PressStyle,
                }
            };

            //Check for trigger
            var triggers = await _findTriggersForPortQuery.ByPortIdAsync <PushTrigger>(port.Id, cToken);

            foreach (var trigger in triggers)
            {
                if (trigger.PressStyle == request.PressStyle)
                {
                    var actions = _coreLogic.GetActionsFor(trigger);
                    foreach (var a in actions)
                    {
                        outgoingMessages.Add(_actionToCommandMapper.Map(a));
                    }
                }
            }
        }
コード例 #3
0
        protected override async Task HandleAsync(PulseReport request, IList <OutgoingMessage> outgoingMessages, CancellationToken cToken)
        {
            var node = await _findNodeQuery.ByRfIdAsync(request.FromNodeId);

            if (node == null)
            {
                throw new NodeNotFoundException(request.FromNodeId);
            }
            await _touchNode.TouchAsync(node, request.Rssi);
        }
コード例 #4
0
        protected override async Task HandleAsync(NodeInfoReport request, IList <OutgoingMessage> outgoingMessages, CancellationToken cToken)
        {
            var node = await _findNodeQuery.ByRfIdAsync(request.FromNodeId);

            if (node == null)
            {
                throw new NodeNotFoundException(request.FromNodeId);
            }
            await _touchNode.TouchAsync(node, request.Rssi);

            node.LatestValues.SendErrorCount = request.SendErrorCount;
            var nodeInfo = new NodeHealthHistory {
                SendErrorCount = request.SendErrorCount
            };

            node.LatestValues.VIn = request.Voltage;
            nodeInfo.VIn          = request.Voltage;
            node.CommunicationHistory.Add(nodeInfo);
        }
コード例 #5
0
        protected override async Task HandleAsync(EnvironmentalReport request, IList <OutgoingMessage> outgoingMessages, CancellationToken cToken)
        {
            var node = await _findNodeQuery.ByRfIdAsync(request.FromRfAddress, NodeInclude.AggregatedData | NodeInclude.Ports);

            if (node == null)
            {
                throw new NodeNotFoundException(request.FromRfAddress);
            }
            _touchNode.Touch(node, request.Rssi);
            var envPort = node.Ports.OfType <EnvironmentSensor>().SingleOrDefault();

            if (envPort == null)
            {
                envPort = new EnvironmentSensor
                {
                    PortNumber      = (byte)ReservedPortNumber.Environment,
                    Name            = "Env",
                    UpdateFrequency = 1,
                };
                node.Ports.Add(envPort);
            }

            envPort.History = new List <EnvironmentHistory>
            {
                new EnvironmentHistory
                {
                    Humidity    = request.Humidity,
                    Temperature = request.Temperature,
                    Pressure    = request.Pressure,
                    Rssi        = request.Rssi,
                    Timestamp   = _timeProvider.UtcNow
                }
            };
            node.AggregatedData.Humidity            = request.Humidity;
            node.AggregatedData.Temperature         = request.Temperature;
            node.AggregatedData.AtmosphericPressure = request.Pressure;
        }
コード例 #6
0
        protected override async Task HandleAsync(NodeInfoReport request, IList <OutgoingMessage> outgoingMessages,
                                                  CancellationToken cToken)
        {
            var node = await _findNodeQuery.ByRfIdAsync(request.FromRfAddress,
                                                        NodeInclude.AggregatedData | NodeInclude.Ports);

            if (node == null)
            {
                throw new NodeNotFoundException(request.FromRfAddress);
            }
            _touchNode.Touch(node, request.Rssi);
            var healthPort = node.Ports.OfType <NodeHealthSensor>().SingleOrDefault();

            if (healthPort == null)
            {
                healthPort = new NodeHealthSensor
                {
                    PortNumber      = (byte)ReservedPortNumber.NodeHealth,
                    Name            = "Health",
                    UpdateFrequency = 1,
                };
                node.Ports.Add(healthPort);
            }

            healthPort.History = new List <NodeHealthHistory>
            {
                new NodeHealthHistory
                {
                    Timestamp      = _timeProvider.UtcNow,
                    Rssi           = request.Rssi,
                    SendErrorCount = request.SendErrorCount,
                    VIn            = request.Voltage,
                }
            };
            node.AggregatedData.SendErrorCount = request.SendErrorCount;
            node.AggregatedData.VIn            = request.Voltage;
        }