예제 #1
0
        public bool TryGetInfo(out DeviceCacheInfo info)
        {
            EnsureLockOwner();

            info = this.cacheStore.GetObject <DeviceCacheInfo>(this.cacheKey);
            return(info != null);
        }
        public bool Initialize(uint fCntUp = 0, uint fCntDown = 0)
        {
            // it is the first message from this device
            var serverStateForDeviceInfo = new DeviceCacheInfo
            {
                FCntDown  = fCntDown,
                FCntUp    = fCntUp,
                GatewayId = this.gatewayId
            };

            return(this.StoreInfo(serverStateForDeviceInfo, true));
        }
예제 #3
0
        public bool TryGetInfo(out DeviceCacheInfo info)
        {
            info = null;
            this.EnsureLockOwner();

            string cachedFCnt = this.cacheStore.StringGet(this.cacheKey);

            if (string.IsNullOrEmpty(cachedFCnt))
            {
                return(false);
            }

            info = JsonConvert.DeserializeObject <DeviceCacheInfo>(cachedFCnt);
            return(info != null);
        }
예제 #4
0
        internal static uint ProcessExistingDeviceInfo(LoRaDeviceCache deviceCache, DeviceCacheInfo cachedDeviceState, string gatewayId, uint clientFCntUp, uint clientFCntDown)
        {
            uint newFCntDown = 0;

            if (cachedDeviceState != null)
            {
                // we have a state in the cache matching this device and now we own the lock
                if (clientFCntUp > cachedDeviceState.FCntUp)
                {
                    // it is a new message coming up by the first gateway
                    if (clientFCntDown >= cachedDeviceState.FCntDown)
                    {
                        newFCntDown = clientFCntDown + 1;
                    }
                    else
                    {
                        newFCntDown = cachedDeviceState.FCntDown + 1;
                    }

                    cachedDeviceState.FCntUp    = clientFCntUp;
                    cachedDeviceState.FCntDown  = newFCntDown;
                    cachedDeviceState.GatewayId = gatewayId;

                    deviceCache.StoreInfo(cachedDeviceState);
                }
                else if (clientFCntUp == cachedDeviceState.FCntUp && gatewayId == cachedDeviceState.GatewayId)
                {
                    // it is a retry message coming up by the same first gateway
                    newFCntDown = cachedDeviceState.FCntDown + 1;
                    cachedDeviceState.FCntDown = newFCntDown;

                    deviceCache.StoreInfo(cachedDeviceState);
                }
            }

            return(newFCntDown);
        }
 public bool StoreInfo(DeviceCacheInfo info, bool initialize = false)
 {
     this.EnsureLockOwner();
     return(this.cacheStore.StringSet(this.cacheKey, JsonConvert.SerializeObject(info), new TimeSpan(1, 0, 0, 0), initialize));
 }
예제 #6
0
 public void StoreInfo(DeviceCacheInfo info)
 {
     this.EnsureLockOwner();
     this.cacheStore.StringSet(this.cacheKey, JsonConvert.SerializeObject(info), new TimeSpan(30, 0, 0, 0));
 }