コード例 #1
0
        //fcnt also here
        #endregion

        public LoRaMessageAdapter(LoRaPayload loRaGenericPayload)
        {
            if (loRaGenericPayload.GetType() == typeof(LoRaPayloadJoinAccept))
            {
                LoRaMessageAdapterEnum = LoRaMessageAdapterEnum.JoinAccept;
                AppNonce   = ((LoRaPayloadJoinAccept)loRaGenericPayload).AppNonce;
                CfList     = ((LoRaPayloadJoinAccept)loRaGenericPayload).CfList;
                DlSettings = ((LoRaPayloadJoinAccept)loRaGenericPayload).DlSettings;
                Fcnt       = ((LoRaPayloadJoinAccept)loRaGenericPayload).Fcnt;
                NetID      = ((LoRaPayloadJoinAccept)loRaGenericPayload).NetID;
                RxDelay    = ((LoRaPayloadJoinAccept)loRaGenericPayload).RxDelay;
            }
            else if (loRaGenericPayload.GetType() == typeof(LoRaPayloadJoinRequest))
            {
                LoRaMessageAdapterEnum = LoRaMessageAdapterEnum.JoinRequest;
                AppEUI   = ((LoRaPayloadJoinRequest)loRaGenericPayload).AppEUI;
                DevEUI   = ((LoRaPayloadJoinRequest)loRaGenericPayload).DevEUI;
                DevNonce = ((LoRaPayloadJoinRequest)loRaGenericPayload).DevNonce;
            }
            else if (loRaGenericPayload.GetType() == typeof(LoRaPayloadData))
            {
                LoRaMessageAdapterEnum = LoRaMessageAdapterEnum.Data;
                Direction  = ((LoRaPayloadData)loRaGenericPayload).Direction;
                Fcnt       = ((LoRaPayloadData)loRaGenericPayload).Fcnt;
                Fctrl      = ((LoRaPayloadData)loRaGenericPayload).Fctrl;
                Fopts      = ((LoRaPayloadData)loRaGenericPayload).Fopts;
                Fport      = ((LoRaPayloadData)loRaGenericPayload).Fport;
                Frmpayload = ((LoRaPayloadData)loRaGenericPayload).Frmpayload;
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 /// <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();
     }
 }
コード例 #4
0
        public static bool TryCreateLoRaPayload(Rxpk rxpk, out LoRaPayload loRaPayloadMessage)
        {
            byte[] convertedInputMessage = Convert.FromBase64String(rxpk.Data);
            var    messageType           = convertedInputMessage[0];

            switch (messageType)
            {
            case (int)LoRaMessageType.UnconfirmedDataUp:
            case (int)LoRaMessageType.ConfirmedDataUp:
                loRaPayloadMessage = new LoRaPayloadData(convertedInputMessage);
                break;

            case (int)LoRaMessageType.JoinRequest:
                loRaPayloadMessage = new LoRaPayloadJoinRequest(convertedInputMessage);
                break;

            default:
                loRaPayloadMessage = null;
                return(false);
            }

            loRaPayloadMessage.LoRaMessageType = (LoRaMessageType)messageType;
            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoRaPayload"/> class.
        /// Constructor used by the simulator
        /// </summary>
        public static bool TryCreateLoRaPayloadForSimulator(Txpk txpk, string appKey, out LoRaPayload loRaPayload)
        {
            if (txpk.Data != null)
            {
                byte[] convertedInputMessage = Convert.FromBase64String(txpk.Data);
                switch ((LoRaMessageType)convertedInputMessage[0])
                {
                case LoRaMessageType.JoinRequest:
                    loRaPayload = new LoRaPayloadJoinRequest();
                    return(true);

                case LoRaMessageType.JoinAccept:
                    loRaPayload = new LoRaPayloadJoinAccept(convertedInputMessage, appKey);
                    return(true);

                case LoRaMessageType.UnconfirmedDataDown:
                case LoRaMessageType.UnconfirmedDataUp:
                case LoRaMessageType.ConfirmedDataUp:
                case LoRaMessageType.ConfirmedDataDown:
                    loRaPayload = new LoRaPayloadData();
                    return(true);
                }
            }

            loRaPayload = null;
            return(false);
        }