public DownlinkPktFwdMessage Serialize(string appKey, string datr, double freq, long tmst, string devEUI) { var algoinput = this.Mhdr.ToArray().Concat(this.AppNonce.ToArray()).Concat(this.NetID.ToArray()).Concat(this.DevAddr.ToArray()).Concat(this.DlSettings.ToArray()).Concat(this.RxDelay.ToArray()).ToArray(); if (!this.CfList.Span.IsEmpty) algoinput = algoinput.Concat(this.CfList.ToArray()).ToArray(); this.CalculateMic(appKey, algoinput); this.PerformEncryption(appKey); var downlinkPktFwdMessage = new DownlinkPktFwdMessage(this.GetByteMessage(), datr, freq, tmst); if (Logger.LoggerLevel < LogLevel.Information) { var jsonMsg = JsonConvert.SerializeObject(downlinkPktFwdMessage); if (devEUI.Length != 0) { Logger.Log(devEUI, $"{((LoRaMessageType)this.Mhdr.Span[0]).ToString()} {jsonMsg}", LogLevel.Debug); } else { Logger.Log(ConversionHelper.ByteArrayToString(this.DevAddr.Span.ToArray()), $"{((LoRaMessageType)this.Mhdr.Span[0]).ToString()} {jsonMsg}", LogLevel.Debug); } } return downlinkPktFwdMessage; }
async Task IPacketForwarder.SendDownstreamAsync(DownlinkPktFwdMessage downstreamMessage) { try { if (downstreamMessage?.Txpk != null) { var jsonMsg = JsonConvert.SerializeObject(downstreamMessage); var messageByte = Encoding.UTF8.GetBytes(jsonMsg); var token = await this.GetTokenAsync(); PhysicalPayload pyld = new PhysicalPayload(token, PhysicalIdentifier.PULL_RESP, messageByte); if (this.pullAckRemoteLoRaAggregatorPort != 0 && !string.IsNullOrEmpty(this.pullAckRemoteLoRaAddress)) { Logger.Log("UDP", $"sending message with ID {ConversionHelper.ByteArrayToString(token)}, to {this.pullAckRemoteLoRaAddress}:{this.pullAckRemoteLoRaAggregatorPort}", LogLevel.Debug); await this.UdpSendMessageAsync(pyld.GetMessage(), this.pullAckRemoteLoRaAddress, this.pullAckRemoteLoRaAggregatorPort); Logger.Log("UDP", $"message sent with ID {ConversionHelper.ByteArrayToString(token)}", LogLevel.Debug); } else { Logger.Log( "UDP", "waiting for first pull_ack message from the packet forwarder. The received message was discarded as the network server is still starting.", LogLevel.Debug); } } } catch (Exception ex) { Logger.Log("UDP", $"error processing the message {ex.Message}, {ex.StackTrace}", LogLevel.Error); } }
public override void NotifySucceeded(LoRaDevice loRaDevice, DownlinkPktFwdMessage downlink) { base.NotifySucceeded(loRaDevice, downlink); this.ResponseDownlink = downlink; this.ProcessingSucceeded = true; this.complete.Release(); }
public LoRaMessageWrapper(LoRaPayload payload, LoRaMessageType type, byte[] physicalToken, string datr, uint rfch, double freq, long tmst) { LoRaPayloadMessage = payload; PktFwdPayload = new DownlinkPktFwdMessage(Convert.ToBase64String(LoRaPayloadMessage.GetByteMessage()), datr, rfch, freq, tmst); var jsonMsg = JsonConvert.SerializeObject(PktFwdPayload); Logger.Log(ConversionHelper.ByteArrayToString(payload.GetLoRaMessage().DevEUI.ToArray()), $"{((MType)(payload.Mhdr.Span[0])).ToString()} {jsonMsg}", Logger.LoggingLevel.Full); var messageBytes = Encoding.Default.GetBytes(jsonMsg); PhysicalPayload = new PhysicalPayload(physicalToken, PhysicalIdentifier.PULL_RESP, messageBytes); }
private void EnsureDownlinkIsCorrect(DownlinkPktFwdMessage downlink, SimulatedDevice simDevice, ReceivedLoRaCloudToDeviceMessage sentMessage) { Assert.NotNull(downlink); Assert.NotNull(downlink.Txpk); Assert.True(downlink.Txpk.Imme); Assert.Equal(0, downlink.Txpk.Tmst); Assert.NotEmpty(downlink.Txpk.Data); byte[] downstreamPayloadBytes = Convert.FromBase64String(downlink.Txpk.Data); var downstreamPayload = new LoRaPayloadData(downstreamPayloadBytes); Assert.Equal(sentMessage.Fport, downstreamPayload.GetFPort()); Assert.Equal(downstreamPayload.DevAddr.ToArray(), ConversionHelper.StringToByteArray(simDevice.DevAddr)); var decryptedPayload = downstreamPayload.GetDecryptedPayload(simDevice.AppSKey); Assert.Equal(sentMessage.Payload, Encoding.UTF8.GetString(decryptedPayload)); }
/// <summary> /// This contructor is used in case of downlink message /// </summary> /// <param name="inputMessage"></param> /// <param name="type"> /// 0 = Join Request /// 1 = Join Accept /// 2 = Unconfirmed Data up /// 3 = Unconfirmed Data down /// 4 = Confirmed Data up /// 5 = Confirmed Data down /// 6 = Rejoin Request</param> public LoRaMessageWrapper(LoRaPayload payload, LoRaMessageType type, byte[] physicalToken) { LoRaPayloadMessage = payload; // construct a Join Accept Message if (type == LoRaMessageType.JoinAccept) { var downlinkmsg = new DownlinkPktFwdMessage(Convert.ToBase64String(payload.GetByteMessage())); PktFwdPayload = downlinkmsg; var jsonMsg = JsonConvert.SerializeObject(downlinkmsg); var messageBytes = Encoding.Default.GetBytes(jsonMsg); PhysicalPayload = new PhysicalPayload(physicalToken, PhysicalIdentifier.PULL_RESP, messageBytes); } else if (type == LoRaMessageType.UnconfirmedDataDown) { throw new NotImplementedException(); } else if (type == LoRaMessageType.ConfirmedDataDown) { throw new NotImplementedException(); } }
public override void NotifySucceeded(LoRaDevice loRaDevice, DownlinkPktFwdMessage downlink) { this.wrappedRequest.NotifySucceeded(loRaDevice, downlink); this.LogProcessingTime(loRaDevice?.DevEUI); }
internal DownlinkMessageBuilderResponse(DownlinkPktFwdMessage downlinkPktFwdMessage, bool isMessageTooLong) { this.DownlinkPktFwdMessage = downlinkPktFwdMessage; this.IsMessageTooLong = isMessageTooLong; }
public LoRaDeviceRequestProcessResult(LoRaDevice loRaDevice, LoRaRequest request, DownlinkPktFwdMessage downlinkMessage = null) { this.LoRaDevice = loRaDevice; this.Request = request; this.DownlinkMessage = downlinkMessage; }
public virtual void NotifySucceeded(LoRaDevice loRaDevice, DownlinkPktFwdMessage downlink) { }
public Task SendDownstreamAsync(DownlinkPktFwdMessage message) { this.DownlinkMessages.Add(message); return(Task.FromResult(0)); }