Пример #1
0
        public LoRaMessage(LoRaGenericPayload payload, LoRaMessageType type, byte[] physicalToken, string _datr, uint _rfch, double _freq, long _tmst)
        {
            //construct a Join Accept Message
            if (type == LoRaMessageType.JoinAccept)
            {
                payloadMessage = (LoRaPayloadJoinAccept)payload;
                loraMetadata   = new LoRaMetada(payloadMessage, type);
                var downlinkmsg = new DownlinkPktFwdMessage(loraMetadata.rawB64data, _datr, _rfch, _freq, _tmst + 5000000);

                var jsonMsg = JsonConvert.SerializeObject(downlinkmsg);
                Console.WriteLine(jsonMsg);
                var messageBytes = Encoding.Default.GetBytes(jsonMsg);

                physicalPayload = new PhysicalPayload(physicalToken, PhysicalIdentifier.PULL_RESP, messageBytes);
            }
            else if (type == LoRaMessageType.UnconfirmedDataDown)
            {
                payloadMessage = (LoRaPayloadStandardData)payload;
                loraMetadata   = new LoRaMetada(payloadMessage, type);
                var downlinkmsg = new DownlinkPktFwdMessage(loraMetadata.rawB64data, _datr, _rfch, _freq, _tmst + 1000000);

                var jsonMsg = JsonConvert.SerializeObject(downlinkmsg);
                Console.WriteLine(jsonMsg);
                var messageBytes = Encoding.Default.GetBytes(jsonMsg);

                physicalPayload = new PhysicalPayload(physicalToken, PhysicalIdentifier.PULL_RESP, messageBytes);
            }
            else if (type == LoRaMessageType.ConfirmedDataDown)
            {
                payloadMessage = (LoRaPayloadStandardData)payload;
                loraMetadata   = new LoRaMetada(payloadMessage, type);
                var downlinkmsg = new DownlinkPktFwdMessage(loraMetadata.rawB64data, _datr, _rfch, _freq, _tmst + 1000000);

                var jsonMsg = JsonConvert.SerializeObject(downlinkmsg);
                Console.WriteLine(jsonMsg);
                var messageBytes = Encoding.Default.GetBytes(jsonMsg);

                physicalPayload = new PhysicalPayload(physicalToken, PhysicalIdentifier.PULL_RESP, messageBytes);
            }
        }
Пример #2
0
        /// <summary>
        /// This contructor is used in case of uplink message, hence we don't know the message type yet
        /// </summary>
        /// <param name="inputMessage"></param>
        public LoRaMessage(byte[] inputMessage)
        {
            //packet normally sent by the gateway as heartbeat. TODO find more elegant way to integrate.

            physicalPayload = new PhysicalPayload(inputMessage);
            if (physicalPayload.message != null)
            {
                loraMetadata = new LoRaMetada(physicalPayload.message);
                //set up the parts of the raw message
                //status message
                if (loraMetadata.rawB64data != null)
                {
                    byte[] convertedInputMessage = Convert.FromBase64String(loraMetadata.rawB64data);
                    var    messageType           = convertedInputMessage[0] >> 5;
                    loRaMessageType = (LoRaMessageType)messageType;
                    //Uplink Message
                    if (messageType == (int)LoRaMessageType.UnconfirmedDataUp)
                    {
                        payloadMessage = new LoRaPayloadStandardData(convertedInputMessage);
                    }
                    else if (messageType == (int)LoRaMessageType.ConfirmedDataUp)
                    {
                        payloadMessage = new LoRaPayloadStandardData(convertedInputMessage);
                    }
                    else if (messageType == (int)LoRaMessageType.JoinRequest)
                    {
                        payloadMessage = new LoRaPayloadJoinRequest(convertedInputMessage);
                    }
                    isLoRaMessage = true;
                }
                else
                {
                    isLoRaMessage = false;
                }
            }
            else
            {
                isLoRaMessage = false;
            }
        }
Пример #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 LoRaMessage(LoRaGenericPayload payload, LoRaMessageType type, byte[] physicalToken)
        {
            //construct a Join Accept Message
            if (type == LoRaMessageType.JoinAccept)
            {
                payloadMessage = (LoRaPayloadJoinAccept)payload;
                loraMetadata   = new LoRaMetada(payloadMessage, type);
                var downlinkmsg  = new DownlinkPktFwdMessage(loraMetadata.rawB64data);
                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();
            }
        }