void HandlePreferredGatewayChanges(
            LoRaRequest request,
            LoRaDevice loRaDevice,
            FunctionBundlerResult bundlerResult)
        {
            var preferredGatewayResult = bundlerResult.PreferredGatewayResult;

            if (preferredGatewayResult.IsSuccessful())
            {
                var currentIsPreferredGateway = bundlerResult.PreferredGatewayResult.PreferredGatewayID == this.configuration.GatewayID;

                var preferredGatewayChanged = bundlerResult.PreferredGatewayResult.PreferredGatewayID != loRaDevice.PreferredGatewayID;
                if (preferredGatewayChanged)
                {
                    Logger.Log(loRaDevice.DevEUI, $"preferred gateway changed from '{loRaDevice.PreferredGatewayID}' to '{preferredGatewayResult.PreferredGatewayID}'", LogLevel.Debug);
                }

                if (preferredGatewayChanged)
                {
                    loRaDevice.UpdatePreferredGatewayID(bundlerResult.PreferredGatewayResult.PreferredGatewayID, acceptChanges: !currentIsPreferredGateway);
                }

                // Save the region if we are the winning gateway and it changed
                if (request.Region.LoRaRegion != loRaDevice.LoRaRegion)
                {
                    loRaDevice.UpdateRegion(request.Region.LoRaRegion, acceptChanges: !currentIsPreferredGateway);
                }
            }
            else
            {
                Logger.Log(loRaDevice.DevEUI, $"failed to resolve preferred gateway: {preferredGatewayResult}", LogLevel.Error);
            }
        }
 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);
         }
     }
 }
Example #3
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);
         }
     }
 }
Example #4
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);
                }
            }
        }
        private async Task <FunctionBundlerResult> TryUseBundler(LoRaRequest request, LoRaDevice loRaDevice, LoRaPayloadData loraPayload, bool useMultipleGateways)
        {
            FunctionBundlerResult bundlerResult = null;

            if (useMultipleGateways)
            {
                var bundler = this.functionBundlerProvider.CreateIfRequired(this.configuration.GatewayID, loraPayload, loRaDevice, this.deduplicationFactory, request);
                if (bundler != null)
                {
                    bundlerResult = await bundler.Execute();

                    if (bundlerResult.NextFCntDown.HasValue)
                    {
                        // we got a new framecounter down. Make sure this
                        // gets saved eventually to the twins
                        loRaDevice.SetFcntDown(bundlerResult.NextFCntDown.Value);
                    }
                }
            }

            return(bundlerResult);
        }
Example #7
0
 public void ProcessResult(FunctionBundlerExecutionContext context, FunctionBundlerResult result)
 {
 }