LWM2M: add logs
This commit is contained in:
parent
1f00ae833d
commit
dfa4433ce9
@ -352,7 +352,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
@Override
|
||||
public void onAttributeUpdate(AttributeUpdateNotificationMsg msg, TransportProtos.SessionInfoProto sessionInfo) {
|
||||
LwM2mClient lwM2MClient = clientContext.getClient(sessionInfo);
|
||||
if (msg.getSharedUpdatedCount() > 0) {
|
||||
if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) {
|
||||
log.warn ("2) OnAttributeUpdate, SharedUpdatedList() [{}]", msg.getSharedUpdatedList());
|
||||
msg.getSharedUpdatedList().forEach(tsKvProto -> {
|
||||
String pathName = tsKvProto.getKv().getKey();
|
||||
String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName);
|
||||
@ -387,7 +388,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
}
|
||||
|
||||
});
|
||||
} else if (msg.getSharedDeletedCount() > 0) {
|
||||
} else if (msg.getSharedDeletedCount() > 0 && lwM2MClient != null) {
|
||||
msg.getSharedUpdatedList().forEach(tsKvProto -> {
|
||||
String pathName = tsKvProto.getKv().getKey();
|
||||
Object valueNew = getValueFromKvProto(tsKvProto.getKv());
|
||||
@ -397,6 +398,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
});
|
||||
log.info("[{}] delete [{}] onAttributeUpdate", msg.getSharedDeletedList(), sessionInfo);
|
||||
}
|
||||
else if (lwM2MClient == null) {
|
||||
log.error ("OnAttributeUpdate, lwM2MClient is null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -443,6 +447,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, SessionInfoProto sessionInfo) {
|
||||
// #1
|
||||
this.checkRpcRequestTimeout();
|
||||
log.warn ("4) toDeviceRpcRequestMsg: [{}], sessionUUID: [{}]", toDeviceRpcRequestMsg, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
|
||||
String bodyParams = StringUtils.trimToNull(toDeviceRpcRequestMsg.getParams()) != null ? toDeviceRpcRequestMsg.getParams() : "null";
|
||||
LwM2mTypeOper lwM2mTypeOper = setValidTypeOper(toDeviceRpcRequestMsg.getMethodName());
|
||||
UUID requestUUID = new UUID(toDeviceRpcRequestMsg.getRequestIdMSB(), toDeviceRpcRequestMsg.getRequestIdLSB());
|
||||
@ -502,6 +507,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
|
||||
@Override
|
||||
public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, SessionInfoProto sessionInfo) {
|
||||
log.warn ("5) nToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
|
||||
transportService.process(sessionInfo, toDeviceResponse, null);
|
||||
}
|
||||
|
||||
@ -882,10 +888,16 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
*/
|
||||
private Object getResourceValueFormatKv(LwM2mClient lwM2MClient, String pathIdVer) {
|
||||
LwM2mResource resourceValue = this.getResourceValueFromLwM2MClient(lwM2MClient, pathIdVer);
|
||||
ResourceModel.Type currentType = resourceValue.getType();
|
||||
ResourceModel.Type expectedType = this.helper.getResourceModelTypeEqualsKvProtoValueType(currentType, pathIdVer);
|
||||
return this.converter.convertValue(resourceValue.getValue(), currentType, expectedType,
|
||||
new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)));
|
||||
if (resourceValue != null) {
|
||||
ResourceModel.Type currentType = resourceValue.getType();
|
||||
ResourceModel.Type expectedType = this.helper.getResourceModelTypeEqualsKvProtoValueType(currentType, pathIdVer);
|
||||
return this.converter.convertValue(resourceValue.getValue(), currentType, expectedType,
|
||||
new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)));
|
||||
}
|
||||
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1246,22 +1258,28 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
*/
|
||||
public void updateAttributeFromThingsboard(List<TransportProtos.TsKvProto> tsKvProtos, TransportProtos.SessionInfoProto sessionInfo) {
|
||||
LwM2mClient lwM2MClient = clientContext.getClient(sessionInfo);
|
||||
tsKvProtos.forEach(tsKvProto -> {
|
||||
String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, tsKvProto.getKv().getKey());
|
||||
if (pathIdVer != null) {
|
||||
// #1.1
|
||||
if (lwM2MClient.getDelayedRequests().containsKey(pathIdVer) && tsKvProto.getTs() > lwM2MClient.getDelayedRequests().get(pathIdVer).getTs()) {
|
||||
lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
|
||||
} else if (!lwM2MClient.getDelayedRequests().containsKey(pathIdVer)) {
|
||||
lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
|
||||
if (lwM2MClient != null) {
|
||||
log.warn("1) UpdateAttributeFromThingsboard, tsKvProtos [{}]", tsKvProtos);
|
||||
tsKvProtos.forEach(tsKvProto -> {
|
||||
String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, tsKvProto.getKv().getKey());
|
||||
if (pathIdVer != null) {
|
||||
// #1.1
|
||||
if (lwM2MClient.getDelayedRequests().containsKey(pathIdVer) && tsKvProto.getTs() > lwM2MClient.getDelayedRequests().get(pathIdVer).getTs()) {
|
||||
lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
|
||||
} else if (!lwM2MClient.getDelayedRequests().containsKey(pathIdVer)) {
|
||||
lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// #2.1
|
||||
lwM2MClient.getDelayedRequests().forEach((pathIdVer, tsKvProto) -> {
|
||||
this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer),
|
||||
getValueFromKvProto(tsKvProto.getKv()), pathIdVer);
|
||||
});
|
||||
});
|
||||
// #2.1
|
||||
lwM2MClient.getDelayedRequests().forEach((pathIdVer, tsKvProto) -> {
|
||||
this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer),
|
||||
getValueFromKvProto(tsKvProto.getKv()), pathIdVer);
|
||||
});
|
||||
}
|
||||
else {
|
||||
log.error("UpdateAttributeFromThingsboard, lwM2MClient is null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1350,6 +1368,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
||||
public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) {
|
||||
if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())
|
||||
&& response.getType().equals(FirmwareType.FIRMWARE.name())) {
|
||||
log.warn ("7) firmware start with ver: [{}]",response.getVersion());
|
||||
lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion());
|
||||
lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle());
|
||||
lwM2MClient.getFwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId());
|
||||
|
||||
@ -83,11 +83,17 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
|
||||
|
||||
@Override
|
||||
public LwM2mClient getClient(TransportProtos.SessionInfoProto sessionInfo) {
|
||||
return lwM2mClientsByEndpoint.values().stream().filter(c ->
|
||||
LwM2mClient lwM2mClient = lwM2mClientsByEndpoint.values().stream().filter(c ->
|
||||
(new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()))
|
||||
.equals((new UUID(c.getSession().getSessionIdMSB(), c.getSession().getSessionIdLSB())))
|
||||
|
||||
).findAny().get();
|
||||
if (lwM2mClient == null) {
|
||||
log.warn("Device TimeOut? lwM2mClient is null.");
|
||||
log.warn("SessionInfo input [{}], lwM2mClientsByEndpoint size: [{}]", sessionInfo, lwM2mClientsByEndpoint.values().size());
|
||||
log.error("", new RuntimeException());
|
||||
}
|
||||
return lwM2mClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -155,12 +155,13 @@ public class LwM2mFwSwUpdate {
|
||||
*/
|
||||
private void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
|
||||
this.stateUpdate = FirmwareUpdateStatus.DOWNLOADING.name();
|
||||
// this.observeStateUpdate();
|
||||
|
||||
this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null);
|
||||
int chunkSize = 0;
|
||||
int chunk = 0;
|
||||
byte[] firmwareChunk = handler.firmwareDataCache.get(this.currentId.toString(), chunkSize, chunk);
|
||||
String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration());
|
||||
log.warn ("8) firmware send save to : [{}]", targetIdVer);
|
||||
request.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(),
|
||||
firmwareChunk, handler.config.getTimeout(), null);
|
||||
}
|
||||
|
||||
@ -43,6 +43,9 @@ public class LwM2mValueConverterImpl implements LwM2mValueConverter {
|
||||
@Override
|
||||
public Object convertValue(Object value, Type currentType, Type expectedType, LwM2mPath resourcePath)
|
||||
throws CodecException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (expectedType == null) {
|
||||
/** unknown resource, trusted value */
|
||||
return value;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user