Exemple #1
0
 internal FunctionBundler(string devEui, LoRaDeviceAPIServiceBase deviceApi, FunctionBundlerRequest request, IList <IFunctionBundlerExecutionItem> executionItems, FunctionBundlerExecutionContext executionContext)
 {
     this.devEui           = devEui;
     this.deviceApi        = deviceApi;
     this.request          = request;
     this.executionItems   = executionItems;
     this.executionContext = executionContext;
 }
Exemple #2
0
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     if (context is null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return(context.LoRaPayload.IsConfirmed || context.LoRaPayload.IsMacAnswerRequired);
 }
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     if (context is null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return(context.DeduplicationFactory.Create(context.LoRaDevice) != null);
 }
Exemple #4
0
 public void Prepare(FunctionBundlerExecutionContext context, FunctionBundlerRequest request)
 {
     if (request is null)
     {
         throw new ArgumentNullException(nameof(request));
     }
     request.FunctionItems |= FunctionBundlerItemType.FCntDown;
 }
Exemple #5
0
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     if (context is null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return(context.LoRaPayload.IsDataRateNetworkControlled);
 }
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     if (context is null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return(context.LoRaDevice.ClassType == LoRaDeviceClassType.C && string.IsNullOrEmpty(context.LoRaDevice.GatewayID));
 }
Exemple #7
0
        public FunctionBundler CreateIfRequired(
            string gatewayId,
            LoRaPayloadData loRaPayload,
            LoRaDevice loRaDevice,
            IDeduplicationStrategyFactory deduplicationFactory,
            LoRaRequest request)
        {
            if (!string.IsNullOrEmpty(loRaDevice.GatewayID))
            {
                // single gateway mode
                return(null);
            }

            var context = new FunctionBundlerExecutionContext
            {
                DeduplicationFactory = deduplicationFactory,
                FCntDown             = loRaDevice.FCntDown,
                FCntUp      = loRaPayload.GetFcnt(),
                GatewayId   = gatewayId,
                LoRaDevice  = loRaDevice,
                LoRaPayload = loRaPayload,
                Request     = request
            };

            var qualifyingExecutionItems = new List <IFunctionBundlerExecutionItem>(functionItems.Count);

            for (var i = 0; i < functionItems.Count; i++)
            {
                var itm = functionItems[i];
                if (itm.RequiresExecution(context))
                {
                    qualifyingExecutionItems.Add(itm);
                }
            }

            if (qualifyingExecutionItems.Count == 0)
            {
                return(null);
            }

            var bundlerRequest = new FunctionBundlerRequest
            {
                ClientFCntDown = context.FCntDown,
                ClientFCntUp   = context.FCntUp,
                GatewayId      = gatewayId,
                Rssi           = context.Request.Rxpk.Rssi,
            };

            for (var i = 0; i < qualifyingExecutionItems.Count; i++)
            {
                qualifyingExecutionItems[i].Prepare(context, bundlerRequest);
            }

            Logger.Log(loRaDevice.DevEUI, "FunctionBundler request: ", bundlerRequest, LogLevel.Debug);

            return(new FunctionBundler(loRaDevice.DevEUI, this.deviceApi, bundlerRequest, qualifyingExecutionItems, context));
        }
 public void ProcessResult(FunctionBundlerExecutionContext context, FunctionBundlerResult result)
 {
     if (result.AdrResult != null)
     {
         if (result.AdrResult.CanConfirmToDevice && result.AdrResult.FCntDown > 0)
         {
             context.LoRaDevice.SetFcntDown(context.LoRaDevice.FCntDown);
         }
     }
 }
Exemple #9
0
 public void ProcessResult(FunctionBundlerExecutionContext context, FunctionBundlerResult result)
 {
     if (result.DeduplicationResult != null)
     {
         var strategy = context.DeduplicationFactory.Create(context.LoRaDevice);
         if (strategy != null)
         {
             result.DeduplicationResult = strategy.Process(result.DeduplicationResult, context.FCntUp);
         }
     }
 }
Exemple #10
0
 internal FunctionBundler(DevEui devEui,
                          LoRaDeviceAPIServiceBase deviceApi,
                          FunctionBundlerRequest request,
                          IList <IFunctionBundlerExecutionItem> executionItems,
                          FunctionBundlerExecutionContext executionContext,
                          ILogger <FunctionBundler> logger)
 {
     this.devEui           = devEui;
     this.deviceApi        = deviceApi;
     this.request          = request;
     this.executionItems   = executionItems;
     this.executionContext = executionContext;
     this.logger           = logger;
 }
        public void Prepare(FunctionBundlerExecutionContext context, FunctionBundlerRequest request)
        {
            request.AdrRequest = new LoRaADRRequest
            {
                DataRate              = context.Request.Region.GetDRFromFreqAndChan(context.Request.Rxpk.Datr),
                FCntDown              = context.FCntDown,
                FCntUp                = context.FCntUp,
                GatewayId             = context.GatewayId,
                MinTxPowerIndex       = context.Request.Region.TXPowertoMaxEIRP.Count - 1,
                PerformADRCalculation = context.LoRaPayload.IsAdrReq,
                RequiredSnr           = (float)context.Request.Rxpk.RequiredSnr
            };

            request.FunctionItems |= FunctionBundlerItemType.ADR;
        }
Exemple #12
0
        public void ProcessResult(FunctionBundlerExecutionContext context, FunctionBundlerResult result)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (result is null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result.AdrResult != null)
            {
                if (result.AdrResult.CanConfirmToDevice && result.AdrResult.FCntDown > 0)
                {
                    context.LoRaDevice.SetFcntDown(context.LoRaDevice.FCntDown);
                }
            }
        }
        public void ProcessResult(FunctionBundlerExecutionContext context, FunctionBundlerResult result)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (result is null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result.DeduplicationResult != null)
            {
                var strategy = context.DeduplicationFactory.Create(context.LoRaDevice);
                if (strategy != null)
                {
                    result.DeduplicationResult = strategy.Process(result.DeduplicationResult, context.FCntUp);
                }
            }
        }
Exemple #14
0
        public void Prepare(FunctionBundlerExecutionContext context, FunctionBundlerRequest request)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            request.AdrRequest = new LoRaADRRequest
            {
                DataRate              = context.Request.RadioMetadata.DataRate,
                FCntDown              = context.FCntDown,
                FCntUp                = context.FCntUp,
                GatewayId             = context.GatewayId,
                MinTxPowerIndex       = context.Request.Region.TXPowertoMaxEIRP.Count - 1,
                PerformADRCalculation = context.LoRaPayload.IsAdrAckRequested,
                RequiredSnr           = (float)context.Request.Region.RequiredSnr(context.Request.RadioMetadata.DataRate)
            };

            request.FunctionItems |= FunctionBundlerItemType.ADR;
        }
Exemple #15
0
 public void ProcessResult(FunctionBundlerExecutionContext context, FunctionBundlerResult result)
 {
 }
Exemple #16
0
 public void Prepare(FunctionBundlerExecutionContext context, FunctionBundlerRequest request)
 {
     request.FunctionItems |= FunctionBundlerItemType.FCntDown;
 }
Exemple #17
0
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     return(context.LoRaPayload.IsConfirmed || context.LoRaPayload.IsMacAnswerRequired);
 }
Exemple #18
0
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     return(context.LoRaDevice.ClassType == LoRaDeviceClassType.C && string.IsNullOrEmpty(context.LoRaDevice.GatewayID));
 }
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     return(context.LoRaPayload.IsAdrEnabled);
 }
        public FunctionBundler CreateIfRequired(
            string gatewayId,
            LoRaPayloadData loRaPayload,
            LoRaDevice loRaDevice,
            IDeduplicationStrategyFactory deduplicationFactory,
            LoRaRequest request)
        {
            if (loRaPayload is null)
            {
                throw new System.ArgumentNullException(nameof(loRaPayload));
            }
            if (loRaDevice is null)
            {
                throw new System.ArgumentNullException(nameof(loRaDevice));
            }
            if (!string.IsNullOrEmpty(loRaDevice.GatewayID))
            {
                // single gateway mode
                return(null);
            }

            var context = new FunctionBundlerExecutionContext(gatewayId, loRaPayload.Fcnt, loRaDevice.FCntDown,
                                                              loRaPayload, loRaDevice, deduplicationFactory, request);

            var qualifyingExecutionItems = new List <IFunctionBundlerExecutionItem>(functionItems.Count);

            for (var i = 0; i < functionItems.Count; i++)
            {
                var itm = functionItems[i];
                if (itm.RequiresExecution(context))
                {
                    qualifyingExecutionItems.Add(itm);
                }
            }

            if (qualifyingExecutionItems.Count == 0)
            {
                return(null);
            }

            var bundlerRequest = new FunctionBundlerRequest
            {
                ClientFCntDown = context.FCntDown,
                ClientFCntUp   = context.FCntUp,
                GatewayId      = gatewayId,
                Rssi           = context.Request.RadioMetadata.UpInfo.ReceivedSignalStrengthIndication,
            };

            for (var i = 0; i < qualifyingExecutionItems.Count; i++)
            {
                qualifyingExecutionItems[i].Prepare(context, bundlerRequest);
                this.logger.LogDebug("FunctionBundler request finished preparing.");
            }

            if (this.logger.IsEnabled(LogLevel.Debug))
            {
                this.logger.LogDebug($"FunctionBundler request: {JsonSerializer.Serialize(bundlerRequest)}");
            }

            return(new FunctionBundler(loRaDevice.DevEUI, this.deviceApi, bundlerRequest, qualifyingExecutionItems, context, loggerFactory.CreateLogger <FunctionBundler>()));
        }
Exemple #21
0
 public bool RequiresExecution(FunctionBundlerExecutionContext context)
 {
     return(context.DeduplicationFactory.Create(context.LoRaDevice) != null);
 }
Exemple #22
0
        public void Prepare(FunctionBundlerExecutionContext context, FunctionBundlerRequest request)
        {
            request.FunctionItems |= FunctionBundlerItemType.PreferredGateway;

            Logger.Log(context.LoRaDevice.DevEUI, "FunctionBundler ADR request finished preparing.", LogLevel.Debug);
        }