//// Sends unconfirmed message
        public async Task SendDataMessageAsync(LoRaRequest loRaRequest, CancellationToken cancellationToken = default)
        {
            var payload = (LoRaPayloadData)loRaRequest.Payload;

            await SerializeAndSendMessageAsync(
                new UpstreamDataRequest(MHdr : uint.Parse(loRaRequest.Payload.MHdr.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture),
                                        DevAddr : int.Parse(payload.DevAddr.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture),
                                        FCtrl : (uint)payload.FrameControlFlags,
                                        FCnt : payload.Fcnt,
                                        FOpts : payload.Fopts.ToHex(),
                                        FPort : (int)payload.Fport,
                                        FrmPayload : payload.Frmpayload.ToHex(),
                                        Mic : payload.Mic.Value.AsInt32,
                                        Dr : loRaRequest.RadioMetadata.DataRate,
                                        Freq : loRaRequest.RadioMetadata.Frequency.AsUInt64,
                                        UpInfo : new UpInfo(GpsTime : loRaRequest.RadioMetadata.UpInfo.GpsTime,
                                                            Rctx : 10,
                                                            Rssi : loRaRequest.RadioMetadata.UpInfo.ReceivedSignalStrengthIndication,
                                                            Xtime : loRaRequest.RadioMetadata.UpInfo.Xtime,
                                                            Snr : loRaRequest.RadioMetadata.UpInfo.SignalNoiseRatio)), cancellationToken);
        }
Exemple #2
0
        public void When_Faulty_MAC_Message_Is_Received_Processing_Abort_Without_Infinite_Loop()
        {
            var simulatedDevice = new SimulatedDevice(TestDeviceInfo.CreateABPDevice(1, gatewayID: this.ServerConfiguration.GatewayID));
            var payload         = simulatedDevice.CreateUnconfirmedDataUpMessage("1234", fcnt: 10);

            simulatedDevice.FrmCntUp = 9;

            // Create Rxpk
            var rxpk = payload.SerializeUplink(simulatedDevice.AppSKey, simulatedDevice.NwkSKey).Rxpk[0];

            var loraDevice = this.CreateLoRaDevice(simulatedDevice);

            this.LoRaDeviceClient.Setup(x => x.SendEventAsync(It.IsNotNull <LoRaDeviceTelemetry>(), null))
            .ReturnsAsync(true);

            this.LoRaDeviceClient.Setup(x => x.ReceiveAsync(It.IsNotNull <TimeSpan>()))
            .ReturnsAsync((Message)null);

            var deviceRegistry = new LoRaDeviceRegistry(this.ServerConfiguration, this.NewNonEmptyCache(loraDevice), this.LoRaDeviceApi.Object, this.LoRaDeviceFactory);

            // Send to message processor
            var messageProcessor = new MessageDispatcher(
                this.ServerConfiguration,
                deviceRegistry,
                this.FrameCounterUpdateStrategyProvider);

            var request = new LoRaRequest(
                new Rxpk
            {
                Data = "QDDaAAGxfh0FAI6wAENHbvgt1UK5Je1uPo/bLPB9HlnOXLGlLRUrTtA0KOHrZhusGl+L4g=="
            },
                null,
                DateTime.Now);

            messageProcessor.DispatchRequest(request);
        }
 public virtual DownlinkMessageBuilderResponse DownlinkMessageBuilderResponseAssert(LoRaRequest request,
                                                                                    LoRaDevice loRaDevice,
                                                                                    LoRaOperationTimeWatcher timeWatcher,
                                                                                    LoRaADRResult loRaADRResult,
                                                                                    IReceivedLoRaCloudToDeviceMessage cloudToDeviceMessage,
                                                                                    uint?fcntDown,
                                                                                    bool fpending)
 {
     ActualCloudToDeviceMessage = cloudToDeviceMessage;
     return(DownlinkMessageBuilder.CreateDownlinkMessage(this.configuration, loRaDevice, request, timeWatcher,
                                                         cloudToDeviceMessage, fpending, fcntDown ?? 0, loRaADRResult, NullLogger.Instance));
 }
 protected override Task SendMessageDownstreamAsync(LoRaRequest request, DownlinkMessageBuilderResponse confirmDownlinkMessageBuilderResp)
 => Task.FromResult(SendMessageDownstreamAsyncAssert(confirmDownlinkMessageBuilderResp));
 protected override DownlinkMessageBuilderResponse DownlinkMessageBuilderResponse(LoRaRequest request,
                                                                                  LoRaDevice loRaDevice,
                                                                                  LoRaOperationTimeWatcher timeWatcher,
                                                                                  LoRaADRResult loRaADRResult,
                                                                                  IReceivedLoRaCloudToDeviceMessage cloudToDeviceMessage,
                                                                                  uint?fcntDown,
                                                                                  bool fpending) =>
 DownlinkMessageBuilderResponseAssert(request, loRaDevice, timeWatcher, loRaADRResult, cloudToDeviceMessage, fcntDown, fpending);
 protected override Task <bool> SendDeviceEventAsync(LoRaRequest request, LoRaDevice loRaDevice, LoRaOperationTimeWatcher timeWatcher, object decodedValue, bool isDuplicate, byte[] decryptedPayloadData)
 => Task.FromResult(SendDeviceAsyncAssert());
 protected override Task <LoRaADRResult> PerformADR(LoRaRequest request, LoRaDevice loRaDevice, LoRaPayloadData loraPayload, uint payloadFcnt, LoRaADRResult loRaADRResult, ILoRaDeviceFrameCounterUpdateStrategy frameCounterStrategy)
 => Task.FromResult(PerformADRAssert());
 protected override Task <FunctionBundlerResult> TryUseBundler(LoRaRequest request, LoRaDevice loRaDevice, LoRaPayloadData loraPayload, bool useMultipleGateways)
 => Task.FromResult(TryUseBundlerAssert());