// Creates a new instance of UdpServer public static UdpServer Create() { var configuration = NetworkServerConfiguration.CreateFromEnviromentVariables(); var loRaDeviceAPIService = new LoRaDeviceAPIService(configuration, new ServiceFacadeHttpClientProvider(configuration, ApiVersion.LatestVersion)); var frameCounterStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(configuration.GatewayID, loRaDeviceAPIService); var deduplicationStrategyFactory = new DeduplicationStrategyFactory(loRaDeviceAPIService); var adrStrategyProvider = new LoRaADRStrategyProvider(); var cache = new MemoryCache(new MemoryCacheOptions()); var dataHandlerImplementation = new DefaultLoRaDataRequestHandler(configuration, frameCounterStrategyProvider, new LoRaPayloadDecoder(), deduplicationStrategyFactory, adrStrategyProvider, new LoRAADRManagerFactory(loRaDeviceAPIService), new FunctionBundlerProvider(loRaDeviceAPIService)); var connectionManager = new LoRaDeviceClientConnectionManager(cache); var loRaDeviceFactory = new LoRaDeviceFactory(configuration, dataHandlerImplementation, connectionManager); var loRaDeviceRegistry = new LoRaDeviceRegistry(configuration, cache, loRaDeviceAPIService, loRaDeviceFactory); var messageDispatcher = new MessageDispatcher(configuration, loRaDeviceRegistry, frameCounterStrategyProvider); var udpServer = new UdpServer(configuration, messageDispatcher, loRaDeviceAPIService, loRaDeviceRegistry); // TODO: review dependencies var classCMessageSender = new DefaultClassCDevicesMessageSender(configuration, loRaDeviceRegistry, udpServer, frameCounterStrategyProvider); dataHandlerImplementation.SetClassCMessageSender(classCMessageSender); udpServer.SetClassCMessageSender(classCMessageSender); return(udpServer); }
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); }