Beispiel #1
0
 public TestLoRaDeviceFactory(
     NetworkServerConfiguration configuration,
     ILoRaDeviceClient loRaDeviceClient,
     ILoRaDeviceClientConnectionManager connectionManager,
     LoRaDeviceCache deviceCache,
     ILoRaDataRequestHandler requestHandler)
     : this(requestHandler, connectionManager, deviceCache, configuration, loRaDeviceClient)
 {
 }
        internal async Task <DuplicateMsgResult> GetDuplicateMessageResultAsync(DevEui devEUI, string gatewayId, uint clientFCntUp, uint clientFCntDown, ILogger logger = null)
        {
            var isDuplicate     = true;
            var processedDevice = gatewayId;

            using (var deviceCache = new LoRaDeviceCache(this.cacheStore, devEUI, gatewayId))
            {
                if (await deviceCache.TryToLockAsync())
                {
                    // we are owning the lock now
                    if (deviceCache.TryGetInfo(out var cachedDeviceState))
                    {
                        var updateCacheState = false;

                        if (cachedDeviceState.FCntUp < clientFCntUp)
                        {
                            isDuplicate      = false;
                            updateCacheState = true;
                        }
                        else if (cachedDeviceState.FCntUp == clientFCntUp && cachedDeviceState.GatewayId == gatewayId)
                        {
                            isDuplicate     = false;
                            processedDevice = cachedDeviceState.GatewayId;
                        }
                        else
                        {
                            processedDevice = cachedDeviceState.GatewayId;
                        }

                        if (updateCacheState)
                        {
                            cachedDeviceState.FCntUp    = clientFCntUp;
                            cachedDeviceState.GatewayId = gatewayId;
                            _ = deviceCache.StoreInfo(cachedDeviceState);
                        }
                    }
                    else
                    {
                        // initialize
                        isDuplicate = false;
                        var state = deviceCache.Initialize(clientFCntUp, clientFCntDown);
                        logger?.LogDebug("initialized state for {id}:{gwid} = {state}", devEUI, gatewayId, state);
                    }
                }
                else
                {
                    processedDevice = "[unknown]";
                    logger?.LogWarning("Failed to acquire lock");
                }
            }

            return(new DuplicateMsgResult
            {
                IsDuplicate = isDuplicate,
                GatewayId = processedDevice
            });
        }
Beispiel #3
0
        internal DuplicateMsgResult GetDuplicateMessageResult(string devEUI, string gatewayId, uint clientFCntUp, uint clientFCntDown)
        {
            var    isDuplicate     = true;
            string processedDevice = gatewayId;

            using (var deviceCache = new LoRaDeviceCache(this.cacheStore, devEUI, gatewayId))
            {
                if (deviceCache.TryToLock())
                {
                    // we are owning the lock now
                    if (deviceCache.TryGetInfo(out DeviceCacheInfo cachedDeviceState))
                    {
                        var updateCacheState = false;

                        if (cachedDeviceState.FCntUp < clientFCntUp)
                        {
                            isDuplicate      = false;
                            updateCacheState = true;
                        }
                        else if (cachedDeviceState.FCntUp == clientFCntUp && cachedDeviceState.GatewayId == gatewayId)
                        {
                            isDuplicate     = false;
                            processedDevice = cachedDeviceState.GatewayId;
                        }
                        else
                        {
                            processedDevice = cachedDeviceState.GatewayId;
                        }

                        if (updateCacheState)
                        {
                            cachedDeviceState.FCntUp    = clientFCntUp;
                            cachedDeviceState.GatewayId = gatewayId;
                            deviceCache.StoreInfo(cachedDeviceState);
                        }
                    }
                    else
                    {
                        // initialize
                        isDuplicate = false;
                        var state = deviceCache.Initialize(clientFCntUp, clientFCntDown);
                    }
                }
            }

            return(new DuplicateMsgResult
            {
                IsDuplicate = isDuplicate,
                GatewayId = processedDevice
            });
        }
 public TestDeviceFactory(NetworkServerConfiguration configuration             = null,
                          ILoRaDeviceClientConnectionManager connectionManager = null,
                          LoRaDeviceCache loRaDeviceCache         = null,
                          Action <Mock <LoRaDevice> > deviceSetup = null,
                          Meter meter = null)
     : base(configuration ?? new NetworkServerConfiguration(),
            new Mock <ILoRaDataRequestHandler>().Object,
            connectionManager ?? new Mock <ILoRaDeviceClientConnectionManager>().Object,
            loRaDeviceCache,
            NullLoggerFactory.Instance,
            NullLogger <LoRaDeviceFactory> .Instance,
            meter)
 {
     this.deviceSetup = deviceSetup;
 }
Beispiel #5
0
 private TestLoRaDeviceFactory(ILoRaDataRequestHandler requestHandler,
                               ILoRaDeviceClientConnectionManager connectionManager,
                               LoRaDeviceCache deviceCache,
                               NetworkServerConfiguration configuration,
                               ILoRaDeviceClient loRaDeviceClient)
     : base(configuration ?? new NetworkServerConfiguration {
     GatewayID = MessageProcessorTestBase.ServerGatewayID
 },
            requestHandler,
            connectionManager,
            deviceCache,
            NullLoggerFactory.Instance,
            NullLogger <LoRaDeviceFactory> .Instance,
            meter: null)
 {
     this.loRaDeviceClient = loRaDeviceClient;
 }
Beispiel #6
0
 public TestLoRaDeviceFactory(ILoRaDeviceClient loRaDeviceClient, ILoRaDataRequestHandler requestHandler, LoRaDeviceCache deviceCache, ILoRaDeviceClientConnectionManager connectionManager = null)
     : this(requestHandler, connectionManager, deviceCache, null, loRaDeviceClient)
 {
 }
Beispiel #7
0
 public TestLoRaDeviceFactory(ILoRaDeviceClient loRaDeviceClient, LoRaDeviceCache deviceCache, ILoRaDeviceClientConnectionManager connectionManager = null)
     : this(null, connectionManager, deviceCache, null, loRaDeviceClient)
 {
 }