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); }