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