Exemple #1
0
        public uint GetNextFCntDown(string devEUI, string gatewayId, uint clientFCntUp, uint clientFCntDown)
        {
            uint newFCntDown = 0;

            using (var deviceCache = new LoRaDeviceCache(this.deviceCache, devEUI, gatewayId))
            {
                if (deviceCache.TryToLock())
                {
                    if (deviceCache.TryGetInfo(out DeviceCacheInfo serverStateForDeviceInfo))
                    {
                        newFCntDown = ProcessExistingDeviceInfo(deviceCache, serverStateForDeviceInfo, gatewayId, clientFCntUp, clientFCntDown);
                    }
                    else
                    {
                        var state = deviceCache.Initialize(clientFCntUp, clientFCntDown + 1);
                        newFCntDown = state.FCntDown;
                    }
                }
            }

            return(newFCntDown);
        }
Exemple #2
0
        public async Task <uint> GetNextFCntDownAsync(DevEui devEUI, string gatewayId, uint clientFCntUp, uint clientFCntDown)
        {
            uint newFCntDown = 0;

            using (var deviceCache = new LoRaDeviceCache(this.deviceCache, devEUI, gatewayId))
            {
                if (await deviceCache.TryToLockAsync())
                {
                    if (deviceCache.TryGetInfo(out var serverStateForDeviceInfo))
                    {
                        newFCntDown = ProcessExistingDeviceInfo(deviceCache, serverStateForDeviceInfo, gatewayId, clientFCntUp, clientFCntDown);
                    }
                    else
                    {
                        newFCntDown = clientFCntDown + 1;
                        var state = deviceCache.Initialize(clientFCntUp, newFCntDown);
                    }
                }
            }

            return(newFCntDown);
        }