/// <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.
            if (inputMessage.Length > 12 && inputMessage.Length != 111)
            {
                processed       = true;
                physicalPayload = new PhysicalPayload(inputMessage);
                loraMetadata    = new LoRaMetada(physicalPayload.message);
                //set up the parts of the raw message
                byte[] convertedInputMessage = Convert.FromBase64String(loraMetadata.rawB64data);
                var    messageType           = convertedInputMessage[0] >> 5;

                //Uplink Message
                if (messageType == 2)
                {
                    payloadMessage = new LoRaPayloadUplink(convertedInputMessage);
                }
                if (messageType == 0)
                {
                    payloadMessage = new LoRaPayloadJoinRequest(convertedInputMessage);
                }
            }
            else
            {
                Console.WriteLine(BitConverter.ToString(inputMessage));
                processed = false;
            }
        }
        /// <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);

                physicalPayload         = new PhysicalPayload(physicalToken, 0x03, Encoding.Default.GetBytes(loraMetadata.rawB64data));
                physicalPayload.message = ((LoRaPayloadJoinAccept)payload).getFinalMessage(physicalToken);
            }
            else if (type == LoRaMessageType.UnconfirmedDataDown)
            {
                throw new NotImplementedException();
            }
            else if (type == LoRaMessageType.ConfirmedDataDown)
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 3
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);

                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);
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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();
            }
        }
 public LoRaMessage(byte[] inputMessage)
 {
     lorametadata = new LoRaMetada(inputMessage);
     //set up the parts of the raw message
     payloadMessage = new LoRaPayloadMessage(Convert.FromBase64String(lorametadata.rawB64data));
 }