Exemple #1
0
        protected override async Task HandleAsync(NodeStartedReport request, IList <OutgoingMessage> outgoingMessages, CancellationToken cToken)
        {
            var node = await _findNodeQuery.BySignatureAsync(request.Signature, NodeInclude.Metadata | NodeInclude.AggregatedData);

            if (node == default(Node))
            {
                Logger.Info(() => $"Node not found based on signature {request.Signature}. A node will be created.");
                var rfId = _rfIdGenerationStrategy.FindAvailableRfAddress();
                node = await _createNodeCommand.ExecuteAsync(request.Signature, rfId, request.NodeType);
            }

            _nodeLogger.Log(node, "STRT");
            node.Metadata.Version = request.Version;
            node.AggregatedData.NodeStartCount = request.StartCount;
            node.AggregatedData.StartupTime    = _timeProvider.UtcNow;
            node.Metadata.NodeType             = request.NodeType;
            _touchNode.Touch(node, request.Rssi);

            outgoingMessages.Add(new NodeConfigCommand
            {
                Signature     = request.Signature,
                ToRfAddress   = request.FromRfAddress,
                NewRfAddress  = node.RfAddress,
                ExtraFeatures = node.Metadata.ExtraFeatures
            });
        }
Exemple #2
0
        protected override async Task HandleAsync(NodeStartedReport request, IList <OutgoingMessage> outgoingMessages, CancellationToken cToken)
        {
            var node = await _findNodeQuery.BySignatureAsync(request.Signature, NodeInclude.Facts | NodeInclude.Config);

            if (node == default(Node))
            {
                Logger.Debug("Node not found based on signature {0}. A node will be created.", request.Signature);
                var rfId = await _rfIdGenerationStrategy.FindAvailableRfAddressAsync(
                    Constants.NetworkId,
                    cToken,
                    request.NeedNewRfAddress?(byte)0 : request.FromNodeId);

                node = await _createNodeCommand.ExecuteAsync(request.Signature, rfId);
            }
            else if (request.NeedNewRfAddress)
            {
                Logger.Debug("Node was found based on signature {0} but a new rfAddress was requestd", request.Signature);
                node.RfAddress = await _rfIdGenerationStrategy.FindAvailableRfAddressAsync(Constants.NetworkId, cToken);
            }

            if (node.RfAddress != request.FromNodeId)
            {
                Logger.Debug("Node with signature {1} received a new rfAddress ({0}).", node.RfAddress, node.Signature);
                outgoingMessages.Add(new NodeConfigCommand
                {
                    ToNodeId     = request.FromNodeId,
                    Signature    = request.Signature,
                    NewRfAddress = node.RfAddress
                });
            }
            else
            {
                outgoingMessages.Add(new NodeConfigCommand
                {
                    ToNodeId  = request.FromNodeId,
                    Signature = request.Signature,
                });
            }
            node.Configuration.Version    = $"{request.Major}.{request.Minor}";
            node.LatestValues.StartupTime = _timeProvider.UtcNow;
            node.AddLog("STRT");
            await _touchNode.TouchAsync(node, request.Rssi);
        }