Пример #1
0
        public async Task ProcessMessageAsync(byte[] message)
        {
            try
            {
                startTimeProcessing = DateTime.UtcNow;
                GatewayID           = Environment.GetEnvironmentVariable("IOTEDGE_DEVICEID");
                LoRaMessageWrapper loraMessage           = new LoRaMessageWrapper(message);
                byte[]             udpMsgForPktForwarder = new Byte[0];
                if (!loraMessage.IsLoRaMessage)
                {
                    udpMsgForPktForwarder = ProcessNonLoraMessage(loraMessage);
                }
                else
                {
                    if (RegionFactory.CurrentRegion == null)
                    {
                        RegionFactory.Create(loraMessage.PktFwdPayload.GetPktFwdMessage().Rxpks[0]);
                    }
                    //join message
                    if (loraMessage.LoRaMessageType == LoRaMessageType.JoinRequest)
                    {
                        udpMsgForPktForwarder = await ProcessJoinRequest(loraMessage);
                    }
                    //normal message
                    else if (loraMessage.LoRaMessageType == LoRaMessageType.UnconfirmedDataUp || loraMessage.LoRaMessageType == LoRaMessageType.ConfirmedDataUp)
                    {
                        udpMsgForPktForwarder = await ProcessLoraMessage(loraMessage);
                    }
                }

                //send reply to pktforwarder
                await UdpServer.UdpSendMessage(udpMsgForPktForwarder);
            }
            catch (Exception ex)
            {
                Logger.Log($"Error processing the message {ex.Message}, {ex.StackTrace}", Logger.LoggingLevel.Error);
            }
        }
        public async Task processMessage(byte[] message)
        {
            startTimeProcessing = DateTime.UtcNow;

            //gate the edge device id for checking if the device is linked to a specific gateway
            if (string.IsNullOrEmpty(GatewayID))
            {
                GatewayID = Environment.GetEnvironmentVariable("IOTEDGE_DEVICEID");
            }

            LoRaMessage loraMessage = new LoRaMessage(message);

            byte[] udpMsgForPktForwarder = new Byte[0];

            if (!loraMessage.isLoRaMessage)
            {
                udpMsgForPktForwarder = ProcessNonLoraMessage(loraMessage);
            }
            else
            {
                //join message
                if (loraMessage.loRaMessageType == LoRaMessageType.JoinRequest)
                {
                    udpMsgForPktForwarder = await ProcessJoinRequest(loraMessage);
                }

                //normal message
                else if (loraMessage.loRaMessageType == LoRaMessageType.UnconfirmedDataUp || loraMessage.loRaMessageType == LoRaMessageType.ConfirmedDataUp)
                {
                    udpMsgForPktForwarder = await ProcessLoraMessage(loraMessage);
                }
            }


            //send reply to pktforwarder
            await UdpServer.UdpSendMessage(udpMsgForPktForwarder);
        }