@ -44,8 +44,6 @@ import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.device.data.lwm2m.ObjectAttributes ;
import org.thingsboard.server.common.data.device.data.lwm2m.TelemetryMappingConfiguration ;
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration ;
import org.thingsboard.server.common.data.id.OtaPackageId ;
import org.thingsboard.server.common.data.ota.OtaPackageType ;
import org.thingsboard.server.common.data.ota.OtaPackageUtil ;
import org.thingsboard.server.common.transport.TransportService ;
import org.thingsboard.server.common.transport.TransportServiceCallback ;
@ -66,9 +64,9 @@ import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext ;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mFwSwUpdate ;
import org.thingsboard.server.transport.lwm2m.server.client.ParametersAnalyzeResult ;
import org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto ;
import org.thingsboard.server.transport.lwm2m.server.common.LwM2MExecutorAwareService ;
import org.thingsboard.server.transport.lwm2m.server.downlink.DownlinkRequestCallback ;
import org.thingsboard.server.transport.lwm2m.server.downlink.LwM2mDownlinkMsgHandler ;
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveCallback ;
@ -82,12 +80,14 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallbac
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest ;
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesCallback ;
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest ;
import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService ;
import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService ;
import org.thingsboard.server.transport.lwm2m.server.rpc.LwM2MRpcRequestHandler ;
import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore ;
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl ;
import javax.annotation.PostConstruct ;
import javax.annotation.PreDestroy ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Collections ;
@ -105,9 +105,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors ;
import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH ;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_3_VER_ID ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_5_ID ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_5_VER_ID ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_DELIVERY_METHOD ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_NAME_ID ;
@ -115,22 +113,17 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.F
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_STATE_ID ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_ERROR ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_INFO ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_TELEMETRY ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.LOG_LWM2M_WARN ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SW_ID ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertOtaUpdateValueToString ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertObjectIdToVersionedId ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.convertOtaUpdateValueToString ;
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.fromVersionedIdToObjectId ;
@Slf4j
@Service
@TbLwM2mTransportComponent
public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mUplinkMsgHandler {
private ExecutorService registrationExecutor ;
private ExecutorService updateRegistrationExecutor ;
private ExecutorService unRegistrationExecutor ;
public LwM2mValueConverterImpl converter ;
private final TransportService transportService ;
@ -138,6 +131,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
private final LwM2MAttributesService attributesService ;
private final LwM2MOtaUpdateService otaService ;
public final LwM2MTransportServerConfig config ;
private final LwM2MTelemetryLogService logService ;
public final OtaPackageDataCache otaPackageDataCache ;
public final LwM2mTransportServerHelper helper ;
private final TbLwM2MDtlsSessionStore sessionStore ;
@ -148,8 +142,10 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
public final Map < String , Integer > firmwareUpdateState ;
public DefaultLwM2MUplinkMsgHandler ( TransportService transportService ,
LwM2MTransportServerConfig config , LwM2mTransportServerHelper helper ,
LwM2MTransportServerConfig config ,
LwM2mTransportServerHelper helper ,
LwM2mClientContext clientContext ,
LwM2MTelemetryLogService logService ,
@Lazy LwM2MOtaUpdateService otaService ,
@Lazy LwM2MAttributesService attributesService ,
@Lazy LwM2MRpcRequestHandler rpcHandler ,
@ -162,6 +158,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
this . config = config ;
this . helper = helper ;
this . clientContext = clientContext ;
this . logService = logService ;
this . rpcHandler = rpcHandler ;
this . defaultLwM2MDownlinkMsgHandler = defaultLwM2MDownlinkMsgHandler ;
this . otaPackageDataCache = otaPackageDataCache ;
@ -171,14 +168,27 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
}
@PostConstruct
public void initAttributes ( ) {
public void init ( ) {
super . init ( ) ;
this . context . getScheduler ( ) . scheduleAtFixedRate ( this : : reportActivity , new Random ( ) . nextInt ( ( int ) config . getSessionReportTimeout ( ) ) , config . getSessionReportTimeout ( ) , TimeUnit . MILLISECONDS ) ;
this . registrationExecutor = ThingsBoardExecutors . newWorkStealingPool ( this . config . getRegisteredPoolSize ( ) , "LwM2M registration" ) ;
this . updateRegistrationExecutor = ThingsBoardExecutors . newWorkStealingPool ( this . config . getUpdateRegisteredPoolSize ( ) , "LwM2M update registration" ) ;
this . unRegistrationExecutor = ThingsBoardExecutors . newWorkStealingPool ( this . config . getUnRegisteredPoolSize ( ) , "LwM2M unRegistration" ) ;
this . converter = LwM2mValueConverterImpl . getInstance ( ) ;
}
@PreDestroy
public void destroy ( ) {
super . destroy ( ) ;
}
@Override
protected String getExecutorName ( ) {
return "LwM2M uplink" ;
}
@Override
protected int getExecutorSize ( ) {
return config . getUplinkPoolSize ( ) ;
}
/ * *
* Start registration device
* Create session : Map < String < registrationId > , LwM2MClient >
@ -194,7 +204,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
* @param previousObservations - may be null
* /
public void onRegistered ( Registration registration , Collection < Observation > previousObservations ) {
r egistrationE xecutor. submit ( ( ) - > {
executor . submit ( ( ) - > {
LwM2mClient lwM2MClient = this . clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) ;
try {
log . warn ( "[{}] [{{}] Client: create after Registration" , registration . getEndpoint ( ) , registration . getId ( ) ) ;
@ -204,7 +214,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
log . info ( "[{}] Closing old session: {}" , registration . getEndpoint ( ) , new UUID ( oldSessionInfo . get ( ) . getSessionIdMSB ( ) , oldSessionInfo . get ( ) . getSessionIdLSB ( ) ) ) ;
closeSession ( oldSessionInfo . get ( ) ) ;
}
this . logToTelemetry ( lwM2MClient , LOG_LWM2M_INFO + ": Client registered with registration id: " + registration . getId ( ) ) ;
logService . log ( lwM2MClient , LOG_LWM2M_INFO + ": Client registered with registration id: " + registration . getId ( ) ) ;
SessionInfoProto sessionInfo = lwM2MClient . getSession ( ) ;
transportService . registerAsyncSession ( sessionInfo , new LwM2mSessionMsgListener ( this , attributesService , rpcHandler , sessionInfo ) ) ;
log . warn ( "40) sessionId [{}] Registering rpc subscription after Registration client" , new UUID ( sessionInfo . getSessionIdMSB ( ) , sessionInfo . getSessionIdLSB ( ) ) ) ;
@ -215,8 +225,6 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
. setSubscribeToRPC ( TransportProtos . SubscribeToRPCMsg . newBuilder ( ) . setSessionType ( TransportProtos . SessionType . ASYNC ) . build ( ) )
. build ( ) ;
transportService . process ( msg , null ) ;
this . getInfoFirmwareUpdate ( lwM2MClient ) ;
this . getInfoSoftwareUpdate ( lwM2MClient ) ;
this . initClientTelemetry ( lwM2MClient ) ;
this . initAttributes ( lwM2MClient ) ;
otaService . init ( lwM2MClient ) ;
@ -229,11 +237,11 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
// Race condition detected and the client was in progress of unregistration while new registration arrived. Let's try again.
onRegistered ( registration , previousObservations ) ;
} else {
this . logToTelemetry ( lwM2MClient , LOG_LWM2M_WARN + ": Client registration failed due to invalid state: " + stateException . getState ( ) ) ;
logService . log ( lwM2MClient , LOG_LWM2M_WARN + ": Client registration failed due to invalid state: " + stateException . getState ( ) ) ;
}
} catch ( Throwable t ) {
log . error ( "[{}] endpoint [{}] error Unable registration." , registration . getEndpoint ( ) , t ) ;
this . logToTelemetry ( lwM2MClient , LOG_LWM2M_WARN + ": Client registration failed due to: " + t . getMessage ( ) ) ;
logService . log ( lwM2MClient , LOG_LWM2M_WARN + ": Client registration failed due to: " + t . getMessage ( ) ) ;
}
} ) ;
}
@ -244,7 +252,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
* @param registration - Registration LwM2M Client
* /
public void updatedReg ( Registration registration ) {
updat eRegistrationE xecutor. submit ( ( ) - > {
executor . submit ( ( ) - > {
LwM2mClient lwM2MClient = clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) ;
try {
log . warn ( "[{}] [{{}] Client: update after Registration" , registration . getEndpoint ( ) , registration . getId ( ) ) ;
@ -265,7 +273,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
}
} catch ( Throwable t ) {
log . error ( "[{}] endpoint [{}] error Unable update registration." , registration . getEndpoint ( ) , t ) ;
this . logToTelemetry ( lwM2MClient , LOG_LWM2M_ERROR + String . format ( ": Client update Registration, %s" , t . getMessage ( ) ) ) ;
logService . log ( lwM2MClient , LOG_LWM2M_ERROR + String . format ( ": Client update Registration, %s" , t . getMessage ( ) ) ) ;
}
} ) ;
}
@ -275,10 +283,10 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
* @param observations - ! ! ! Warn : if have not finishing unReg , then this operation will be finished on next Client ` s connect
* /
public void unReg ( Registration registration , Collection < Observation > observations ) {
unR egistrationE xecutor. submit ( ( ) - > {
executor . submit ( ( ) - > {
LwM2mClient client = clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) ;
try {
this . logToTelemetry ( client , LOG_LWM2M_INFO + ": Client unRegistration" ) ;
logService . log ( client , LOG_LWM2M_INFO + ": Client unRegistration" ) ;
clientContext . unregister ( client , registration ) ;
SessionInfoProto sessionInfo = client . getSession ( ) ;
if ( sessionInfo ! = null ) {
@ -292,7 +300,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
log . info ( "[{}] delete registration: [{}] {}." , registration . getEndpoint ( ) , stateException . getState ( ) , stateException . getMessage ( ) ) ;
} catch ( Throwable t ) {
log . error ( "[{}] endpoint [{}] error Unable un registration." , registration . getEndpoint ( ) , t ) ;
this . logToTelemetry ( client , LOG_LWM2M_ERROR + String . format ( ": Client Unable un Registration, %s" , t . getMessage ( ) ) ) ;
logService . log ( client , LOG_LWM2M_ERROR + String . format ( ": Client Unable un Registration, %s" , t . getMessage ( ) ) ) ;
}
} ) ;
}
@ -305,7 +313,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
@Override
public void onSleepingDev ( Registration registration ) {
log . info ( "[{}] [{}] Received endpoint Sleeping version event" , registration . getId ( ) , registration . getEndpoint ( ) ) ;
this . logToTelemetry ( clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) , LOG_LWM2M_INFO + ": Client is sleeping!" ) ;
logService . log ( clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) , LOG_LWM2M_INFO + ": Client is sleeping!" ) ;
//TODO: associate endpointId with device information.
}
@ -403,29 +411,10 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
@Override
public void onAwakeDev ( Registration registration ) {
log . trace ( "[{}] [{}] Received endpoint Awake version event" , registration . getId ( ) , registration . getEndpoint ( ) ) ;
this . logToTelemetry ( clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) , LOG_LWM2M_INFO + ": Client is awake!" ) ;
logService . log ( clientContext . getClientByEndpoint ( registration . getEndpoint ( ) ) , LOG_LWM2M_INFO + ": Client is awake!" ) ;
//TODO: associate endpointId with device information.
}
/ * *
* @param logMsg - text msg
* @param registrationId - Id of Registration LwM2M Client
* /
@Override
public void logToTelemetry ( String registrationId , String logMsg ) {
logToTelemetry ( clientContext . getClientByRegistrationId ( registrationId ) , logMsg ) ;
}
@Override
public void logToTelemetry ( LwM2mClient client , String logMsg ) {
if ( logMsg ! = null & & client ! = null & & client . getSession ( ) ! = null ) {
if ( logMsg . length ( ) > 1024 ) {
logMsg = logMsg . substring ( 0 , 1024 ) ;
}
this . helper . sendParametersOnThingsboardTelemetry ( this . helper . getKvStringtoThingsboard ( LOG_LWM2M_TELEMETRY , logMsg ) , client . getSession ( ) ) ;
}
}
/ * *
* # 1 clientOnlyObserveAfterConnect = = true
* - Only Observe Request to the client marked as observe from the profile configuration .
@ -441,10 +430,6 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
Lwm2mDeviceProfileTransportConfiguration profile = clientContext . getProfile ( lwM2MClient . getProfileId ( ) ) ;
Set < String > supportedObjects = clientContext . getSupportedIdVerInClient ( lwM2MClient ) ;
if ( supportedObjects ! = null & & supportedObjects . size ( ) > 0 ) {
if ( LwM2mTransportUtil . LwM2MClientStrategy . CLIENT_STRATEGY_2 . code = = profile . getClientLwM2mSettings ( ) . getClientOnlyObserveAfterConnect ( ) ) {
// #2
supportedObjects . forEach ( versionedId - > sendReadRequest ( lwM2MClient , versionedId ) ) ;
}
// #1
this . sendReadRequests ( lwM2MClient , profile , supportedObjects ) ;
this . sendObserveRequests ( lwM2MClient , profile , supportedObjects ) ;
@ -461,7 +446,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
CountDownLatch latch = new CountDownLatch ( targetIds . size ( ) ) ;
targetIds . forEach ( versionedId - > sendReadRequest ( lwM2MClient , versionedId ,
new TbLwM2MLatchCallback < > ( latch , new TbLwM2MReadCallback ( this , lwM2MClient , versionedId ) ) ) ) ;
new TbLwM2MLatchCallback < > ( latch , new TbLwM2MReadCallback ( this , logService , l wM2MClient , versionedId ) ) ) ) ;
try {
latch . await ( ) ;
} catch ( InterruptedException e ) {
@ -475,7 +460,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
CountDownLatch latch = new CountDownLatch ( targetIds . size ( ) ) ;
targetIds . forEach ( targetId - > sendObserveRequest ( lwM2MClient , targetId ,
new TbLwM2MLatchCallback < > ( latch , new TbLwM2MObserveCallback ( this , lwM2MClient , targetId ) ) ) ) ;
new TbLwM2MLatchCallback < > ( latch , new TbLwM2MObserveCallback ( this , logService , l wM2MClient , targetId ) ) ) ) ;
try {
latch . await ( ) ;
} catch ( InterruptedException e ) {
@ -501,11 +486,11 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
private void sendDiscoverRequest ( LwM2mClient lwM2MClient , String targetId ) {
TbLwM2MDiscoverRequest request = TbLwM2MDiscoverRequest . builder ( ) . versionedId ( targetId ) . timeout ( this . config . getTimeout ( ) ) . build ( ) ;
defaultLwM2MDownlinkMsgHandler . sendDiscoverRequest ( lwM2MClient , request , new TbLwM2MDiscoverCallback ( this , lwM2MClient , targetId ) ) ;
defaultLwM2MDownlinkMsgHandler . sendDiscoverRequest ( lwM2MClient , request , new TbLwM2MDiscoverCallback ( logService , lwM2MClient , targetId ) ) ;
}
private void sendReadRequest ( LwM2mClient lwM2MClient , String versionedId ) {
sendReadRequest ( lwM2MClient , versionedId , new TbLwM2MReadCallback ( this , lwM2MClient , versionedId ) ) ;
sendReadRequest ( lwM2MClient , versionedId , new TbLwM2MReadCallback ( this , logService , l wM2MClient , versionedId ) ) ;
}
private void sendReadRequest ( LwM2mClient lwM2MClient , String versionedId , DownlinkRequestCallback < ReadRequest , ReadResponse > callback ) {
@ -514,7 +499,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
}
private void sendObserveRequest ( LwM2mClient lwM2MClient , String versionedId ) {
sendObserveRequest ( lwM2MClient , versionedId , new TbLwM2MObserveCallback ( this , lwM2MClient , versionedId ) ) ;
sendObserveRequest ( lwM2MClient , versionedId , new TbLwM2MObserveCallback ( this , logService , l wM2MClient , versionedId ) ) ;
}
private void sendObserveRequest ( LwM2mClient lwM2MClient , String versionedId , DownlinkRequestCallback < ObserveRequest , ObserveResponse > callback ) {
@ -524,12 +509,12 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
private void sendWriteAttributesRequest ( LwM2mClient lwM2MClient , String targetId , ObjectAttributes params ) {
TbLwM2MWriteAttributesRequest request = TbLwM2MWriteAttributesRequest . builder ( ) . versionedId ( targetId ) . attributes ( params ) . timeout ( this . config . getTimeout ( ) ) . build ( ) ;
defaultLwM2MDownlinkMsgHandler . sendWriteAttributesRequest ( lwM2MClient , request , new TbLwM2MWriteAttributesCallback ( this , lwM2MClient , targetId ) ) ;
defaultLwM2MDownlinkMsgHandler . sendWriteAttributesRequest ( lwM2MClient , request , new TbLwM2MWriteAttributesCallback ( logService , lwM2MClient , targetId ) ) ;
}
private void sendCancelObserveRequest ( String versionedId , LwM2mClient client ) {
TbLwM2MCancelObserveRequest request = TbLwM2MCancelObserveRequest . builder ( ) . versionedId ( versionedId ) . timeout ( this . config . getTimeout ( ) ) . build ( ) ;
defaultLwM2MDownlinkMsgHandler . sendCancelObserveRequest ( client , request , new TbLwM2MCancelObserveCallback ( this , client , versionedId ) ) ;
defaultLwM2MDownlinkMsgHandler . sendCancelObserveRequest ( client , request , new TbLwM2MCancelObserveCallback ( logService , client , versionedId ) ) ;
}
private void updateObjectResourceValue ( LwM2mClient client , LwM2mObject lwM2mObject , String pathIdVer ) {
@ -565,9 +550,9 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
if ( path . equals ( convertObjectIdToVersionedId ( FW_NAME_ID , registration ) ) ) {
otaService . onCurrentFirmwareNameUpdate ( lwM2MClient , ( String ) lwM2mResource . getValue ( ) ) ;
} else if ( path . equals ( convertObjectIdToVersionedId ( FW_3_VER_ID , registration ) ) ) {
otaService . onCurrentFirmwareVersionUpdate ( lwM2MClient , ( String ) lwM2mResource . getValue ( ) ) ;
otaService . onCurrentFirmwareVersion3 Update ( lwM2MClient , ( String ) lwM2mResource . getValue ( ) ) ;
} else if ( path . equals ( convertObjectIdToVersionedId ( FW_5_VER_ID , registration ) ) ) {
otaService . onCurrentFirmwareVersionUpdate ( lwM2MClient , ( String ) lwM2mResource . getValue ( ) ) ;
otaService . onCurrentFirmwareVersion5 Update ( lwM2MClient , ( String ) lwM2mResource . getValue ( ) ) ;
} else if ( path . equals ( convertObjectIdToVersionedId ( FW_STATE_ID , registration ) ) ) {
otaService . onCurrentFirmwareStateUpdate ( lwM2MClient , ( Long ) lwM2mResource . getValue ( ) ) ;
} else if ( path . equals ( convertObjectIdToVersionedId ( FW_RESULT_ID , registration ) ) ) {
@ -919,93 +904,7 @@ public class DefaultLwM2MUplinkMsgHandler implements LwM2mUplinkMsgHandler {
DonAsynchron . withCallback ( attributesService . getSharedAttributes ( lwM2MClient , keysToFetch ) ,
v - > attributesService . onAttributesUpdate ( lwM2MClient , v ) ,
t - > log . error ( "[{}] Failed to get attributes" , lwM2MClient . getEndpoint ( ) , t ) ,
registrationExecutor ) ;
}
}
public void getInfoFirmwareUpdate ( LwM2mClient lwM2MClient ) {
if ( lwM2MClient . getRegistration ( ) . getSupportedVersion ( FW_5_ID ) ! = null ) {
SessionInfoProto sessionInfo = this . getSessionInfo ( lwM2MClient ) ;
if ( sessionInfo ! = null ) {
DefaultLwM2MUplinkMsgHandler handler = this ;
this . transportService . process ( sessionInfo , createOtaPackageRequestMsg ( sessionInfo , OtaPackageType . FIRMWARE . name ( ) ) ,
new TransportServiceCallback < > ( ) {
@Override
public void onSuccess ( TransportProtos . GetOtaPackageResponseMsg response ) {
if ( TransportProtos . ResponseStatus . SUCCESS . equals ( response . getResponseStatus ( ) )
& & response . getType ( ) . equals ( OtaPackageType . FIRMWARE . name ( ) ) ) {
LwM2mFwSwUpdate fwUpdate = lwM2MClient . getFwUpdate ( DefaultLwM2MUplinkMsgHandler . this , clientContext ) ;
// if (rpcRequest != null) {
// fwUpdate.setStateUpdate(INITIATED.name());
// }
if ( ! FAILED . name ( ) . equals ( fwUpdate . getStateUpdate ( ) ) ) {
log . warn ( "7) firmware start with ver: [{}]" , response . getVersion ( ) ) ;
// fwUpdate.setRpcRequest(rpcRequest);
fwUpdate . setCurrentVersion ( response . getVersion ( ) ) ;
fwUpdate . setCurrentTitle ( response . getTitle ( ) ) ;
fwUpdate . setCurrentId ( new UUID ( response . getOtaPackageIdMSB ( ) , response . getOtaPackageIdLSB ( ) ) ) ;
// if (rpcRequest == null) {
fwUpdate . sendReadObserveInfo ( defaultLwM2MDownlinkMsgHandler ) ;
// } else {
// fwUpdate.writeFwSwWare(handler, defaultLwM2MDownlinkMsgHandler);
// }
} else {
String msgError = String . format ( "OtaPackage device: %s, version: %s, stateUpdate: %s" ,
lwM2MClient . getDeviceName ( ) , response . getVersion ( ) , fwUpdate . getStateUpdate ( ) ) ;
log . warn ( "7_1 [{}]" , msgError ) ;
}
} else {
String msgError = String . format ( "OtaPackage device: %s, responseStatus: %s" ,
lwM2MClient . getDeviceName ( ) , response . getResponseStatus ( ) . toString ( ) ) ;
log . trace ( msgError ) ;
// if (rpcRequest != null) {
//TODO: refactor
// sendErrorRpcResponse(rpcRequest, msgError, sessionInfo);
// }
}
}
@Override
public void onError ( Throwable e ) {
log . trace ( "Failed to process firmwareUpdate " , e ) ;
}
} ) ;
}
}
}
public void getInfoSoftwareUpdate ( LwM2mClient lwM2MClient ) {
if ( lwM2MClient . getRegistration ( ) . getSupportedVersion ( SW_ID ) ! = null ) {
SessionInfoProto sessionInfo = this . getSessionInfo ( lwM2MClient ) ;
if ( sessionInfo ! = null ) {
DefaultLwM2MUplinkMsgHandler handler = this ;
transportService . process ( sessionInfo , createOtaPackageRequestMsg ( sessionInfo , OtaPackageType . SOFTWARE . name ( ) ) ,
new TransportServiceCallback < > ( ) {
@Override
public void onSuccess ( TransportProtos . GetOtaPackageResponseMsg response ) {
if ( TransportProtos . ResponseStatus . SUCCESS . equals ( response . getResponseStatus ( ) )
& & response . getType ( ) . equals ( OtaPackageType . SOFTWARE . name ( ) ) ) {
// lwM2MClient.getSwUpdate().setRpcRequest(rpcRequest);
lwM2MClient . getSwUpdate ( ) . setCurrentVersion ( response . getVersion ( ) ) ;
lwM2MClient . getSwUpdate ( ) . setCurrentTitle ( response . getTitle ( ) ) ;
lwM2MClient . getSwUpdate ( ) . setCurrentId ( new OtaPackageId ( new UUID ( response . getOtaPackageIdMSB ( ) , response . getOtaPackageIdLSB ( ) ) ) . getId ( ) ) ;
lwM2MClient . getSwUpdate ( ) . sendReadObserveInfo ( defaultLwM2MDownlinkMsgHandler ) ;
// if (rpcRequest == null) {
lwM2MClient . getSwUpdate ( ) . sendReadObserveInfo ( defaultLwM2MDownlinkMsgHandler ) ;
// } else {
// lwM2MClient.getSwUpdate().writeFwSwWare(handler, defaultLwM2MDownlinkMsgHandler);
// }
} else {
log . trace ( "Software [{}] [{}]" , lwM2MClient . getDeviceName ( ) , response . getResponseStatus ( ) . toString ( ) ) ;
}
}
@Override
public void onError ( Throwable e ) {
log . trace ( "Failed to process softwareUpdate " , e ) ;
}
} ) ;
}
executor ) ;
}
}