Search in sources :

Example 6 with PowerMode

use of org.thingsboard.server.common.data.device.data.PowerMode in project thingsboard by thingsboard.

the class LwM2mClientContextImpl method getPowerMode.

private PowerMode getPowerMode(LwM2mClient lwM2MClient) {
    PowerMode powerMode = lwM2MClient.getPowerMode();
    if (powerMode == null) {
        Lwm2mDeviceProfileTransportConfiguration deviceProfile = getProfile(lwM2MClient.getProfileId());
        powerMode = deviceProfile.getClientLwM2mSettings().getPowerMode();
    }
    return powerMode;
}
Also used : PowerMode(org.thingsboard.server.common.data.device.data.PowerMode) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)

Example 7 with PowerMode

use of org.thingsboard.server.common.data.device.data.PowerMode in project thingsboard by thingsboard.

the class LwM2mClientContextImpl method sendMsgsAfterSleeping.

@Override
public void sendMsgsAfterSleeping(LwM2mClient lwM2MClient) {
    if (LwM2MClientState.REGISTERED.equals(lwM2MClient.getState())) {
        PowerMode powerMode = getPowerMode(lwM2MClient);
        if (PowerMode.PSM.equals(powerMode) || PowerMode.E_DRX.equals(powerMode)) {
            modelConfigService.sendUpdates(lwM2MClient);
            defaultLwM2MUplinkMsgHandler.initAttributes(lwM2MClient, false);
            TransportProtos.TransportToDeviceActorMsg persistentRpcRequestMsg = TransportProtos.TransportToDeviceActorMsg.newBuilder().setSessionInfo(lwM2MClient.getSession()).setSendPendingRPC(TransportProtos.SendPendingRPCMsg.newBuilder().build()).build();
            context.getTransportService().process(persistentRpcRequestMsg, TransportServiceCallback.EMPTY);
            otaUpdateService.init(lwM2MClient);
        }
    }
}
Also used : PowerMode(org.thingsboard.server.common.data.device.data.PowerMode) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos)

Example 8 with PowerMode

use of org.thingsboard.server.common.data.device.data.PowerMode in project thingsboard by thingsboard.

the class LwM2mClientContextImpl method isDownlinkAllowed.

@Override
public boolean isDownlinkAllowed(LwM2mClient client) {
    PowerMode powerMode = client.getPowerMode();
    OtherConfiguration profileSettings = null;
    if (powerMode == null) {
        var clientProfile = getProfile(client.getProfileId());
        profileSettings = clientProfile.getClientLwM2mSettings();
        powerMode = profileSettings.getPowerMode();
        if (powerMode == null) {
            powerMode = PowerMode.DRX;
        }
    }
    if (PowerMode.DRX.equals(powerMode) || otaUpdateService.isOtaDownloading(client)) {
        return true;
    }
    client.lock();
    long timeSinceLastUplink = System.currentTimeMillis() - client.getLastUplinkTime();
    try {
        if (PowerMode.PSM.equals(powerMode)) {
            Long psmActivityTimer = client.getPsmActivityTimer();
            if (psmActivityTimer == null && profileSettings != null) {
                psmActivityTimer = profileSettings.getPsmActivityTimer();
            }
            if (psmActivityTimer == null || psmActivityTimer == 0L) {
                psmActivityTimer = config.getPsmActivityTimer();
            }
            return timeSinceLastUplink <= psmActivityTimer;
        } else {
            Long pagingTransmissionWindow = client.getPagingTransmissionWindow();
            if (pagingTransmissionWindow == null && profileSettings != null) {
                pagingTransmissionWindow = profileSettings.getPagingTransmissionWindow();
            }
            if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) {
                pagingTransmissionWindow = config.getPagingTransmissionWindow();
            }
            boolean allowed = timeSinceLastUplink <= pagingTransmissionWindow;
            if (!allowed) {
                return client.checkFirstDownlink();
            } else {
                return true;
            }
        }
    } finally {
        client.unlock();
    }
}
Also used : OtherConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration) PowerMode(org.thingsboard.server.common.data.device.data.PowerMode)

Example 9 with PowerMode

use of org.thingsboard.server.common.data.device.data.PowerMode in project thingsboard by thingsboard.

the class LwM2mClientContextImpl method compareAndSetSleepFlag.

private boolean compareAndSetSleepFlag(LwM2mClient client, boolean sleeping) {
    if (sleeping == client.isAsleep()) {
        log.trace("[{}] Client is already at sleeping: {}, ignoring event: {}", client.getEndpoint(), client.isAsleep(), sleeping);
        return false;
    }
    client.lock();
    try {
        if (sleeping == client.isAsleep()) {
            log.trace("[{}] Client is already at sleeping: {}, ignoring event: {}", client.getEndpoint(), client.isAsleep(), sleeping);
            return false;
        } else {
            PowerMode powerMode = getPowerMode(client);
            if (PowerMode.PSM.equals(powerMode) || PowerMode.E_DRX.equals(powerMode)) {
                log.trace("[{}] Switch sleeping from: {} to: {}", client.getEndpoint(), client.isAsleep(), sleeping);
                client.setAsleep(sleeping);
                update(client);
                return true;
            } else {
                return false;
            }
        }
    } finally {
        client.unlock();
    }
}
Also used : PowerMode(org.thingsboard.server.common.data.device.data.PowerMode)

Aggregations

PowerMode (org.thingsboard.server.common.data.device.data.PowerMode)9 PowerSavingConfiguration (org.thingsboard.server.common.data.device.data.PowerSavingConfiguration)3 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ByteString (com.google.protobuf.ByteString)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1