Commit dfa4433ce97cb1636ee1c93d5f487cfc280e4833

Authored by nickAS21
1 parent 1f00ae83

LWM2M: add logs

... ... @@ -352,7 +352,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
352 352 @Override
353 353 public void onAttributeUpdate(AttributeUpdateNotificationMsg msg, TransportProtos.SessionInfoProto sessionInfo) {
354 354 LwM2mClient lwM2MClient = clientContext.getClient(sessionInfo);
355   - if (msg.getSharedUpdatedCount() > 0) {
  355 + if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) {
  356 + log.warn ("2) OnAttributeUpdate, SharedUpdatedList() [{}]", msg.getSharedUpdatedList());
356 357 msg.getSharedUpdatedList().forEach(tsKvProto -> {
357 358 String pathName = tsKvProto.getKv().getKey();
358 359 String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, pathName);
... ... @@ -387,7 +388,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
387 388 }
388 389
389 390 });
390   - } else if (msg.getSharedDeletedCount() > 0) {
  391 + } else if (msg.getSharedDeletedCount() > 0 && lwM2MClient != null) {
391 392 msg.getSharedUpdatedList().forEach(tsKvProto -> {
392 393 String pathName = tsKvProto.getKv().getKey();
393 394 Object valueNew = getValueFromKvProto(tsKvProto.getKv());
... ... @@ -397,6 +398,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
397 398 });
398 399 log.info("[{}] delete [{}] onAttributeUpdate", msg.getSharedDeletedList(), sessionInfo);
399 400 }
  401 + else if (lwM2MClient == null) {
  402 + log.error ("OnAttributeUpdate, lwM2MClient is null");
  403 + }
400 404 }
401 405
402 406 /**
... ... @@ -443,6 +447,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
443 447 public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, SessionInfoProto sessionInfo) {
444 448 // #1
445 449 this.checkRpcRequestTimeout();
  450 + log.warn ("4) toDeviceRpcRequestMsg: [{}], sessionUUID: [{}]", toDeviceRpcRequestMsg, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
446 451 String bodyParams = StringUtils.trimToNull(toDeviceRpcRequestMsg.getParams()) != null ? toDeviceRpcRequestMsg.getParams() : "null";
447 452 LwM2mTypeOper lwM2mTypeOper = setValidTypeOper(toDeviceRpcRequestMsg.getMethodName());
448 453 UUID requestUUID = new UUID(toDeviceRpcRequestMsg.getRequestIdMSB(), toDeviceRpcRequestMsg.getRequestIdLSB());
... ... @@ -502,6 +507,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
502 507
503 508 @Override
504 509 public void onToDeviceRpcResponse(TransportProtos.ToDeviceRpcResponseMsg toDeviceResponse, SessionInfoProto sessionInfo) {
  510 + log.warn ("5) nToDeviceRpcResponse: [{}], sessionUUID: [{}]", toDeviceResponse, new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()));
505 511 transportService.process(sessionInfo, toDeviceResponse, null);
506 512 }
507 513
... ... @@ -882,10 +888,16 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
882 888 */
883 889 private Object getResourceValueFormatKv(LwM2mClient lwM2MClient, String pathIdVer) {
884 890 LwM2mResource resourceValue = this.getResourceValueFromLwM2MClient(lwM2MClient, pathIdVer);
885   - ResourceModel.Type currentType = resourceValue.getType();
886   - ResourceModel.Type expectedType = this.helper.getResourceModelTypeEqualsKvProtoValueType(currentType, pathIdVer);
887   - return this.converter.convertValue(resourceValue.getValue(), currentType, expectedType,
888   - new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)));
  891 + if (resourceValue != null) {
  892 + ResourceModel.Type currentType = resourceValue.getType();
  893 + ResourceModel.Type expectedType = this.helper.getResourceModelTypeEqualsKvProtoValueType(currentType, pathIdVer);
  894 + return this.converter.convertValue(resourceValue.getValue(), currentType, expectedType,
  895 + new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)));
  896 + }
  897 +
  898 + else {
  899 + return null;
  900 + }
889 901 }
890 902
891 903 /**
... ... @@ -1246,22 +1258,28 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1246 1258 */
1247 1259 public void updateAttributeFromThingsboard(List<TransportProtos.TsKvProto> tsKvProtos, TransportProtos.SessionInfoProto sessionInfo) {
1248 1260 LwM2mClient lwM2MClient = clientContext.getClient(sessionInfo);
1249   - tsKvProtos.forEach(tsKvProto -> {
1250   - String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, tsKvProto.getKv().getKey());
1251   - if (pathIdVer != null) {
1252   - // #1.1
1253   - if (lwM2MClient.getDelayedRequests().containsKey(pathIdVer) && tsKvProto.getTs() > lwM2MClient.getDelayedRequests().get(pathIdVer).getTs()) {
1254   - lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
1255   - } else if (!lwM2MClient.getDelayedRequests().containsKey(pathIdVer)) {
1256   - lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
  1261 + if (lwM2MClient != null) {
  1262 + log.warn("1) UpdateAttributeFromThingsboard, tsKvProtos [{}]", tsKvProtos);
  1263 + tsKvProtos.forEach(tsKvProto -> {
  1264 + String pathIdVer = this.getPresentPathIntoProfile(sessionInfo, tsKvProto.getKv().getKey());
  1265 + if (pathIdVer != null) {
  1266 + // #1.1
  1267 + if (lwM2MClient.getDelayedRequests().containsKey(pathIdVer) && tsKvProto.getTs() > lwM2MClient.getDelayedRequests().get(pathIdVer).getTs()) {
  1268 + lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
  1269 + } else if (!lwM2MClient.getDelayedRequests().containsKey(pathIdVer)) {
  1270 + lwM2MClient.getDelayedRequests().put(pathIdVer, tsKvProto);
  1271 + }
1257 1272 }
1258   - }
1259   - });
1260   - // #2.1
1261   - lwM2MClient.getDelayedRequests().forEach((pathIdVer, tsKvProto) -> {
1262   - this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer),
1263   - getValueFromKvProto(tsKvProto.getKv()), pathIdVer);
1264   - });
  1273 + });
  1274 + // #2.1
  1275 + lwM2MClient.getDelayedRequests().forEach((pathIdVer, tsKvProto) -> {
  1276 + this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer),
  1277 + getValueFromKvProto(tsKvProto.getKv()), pathIdVer);
  1278 + });
  1279 + }
  1280 + else {
  1281 + log.error("UpdateAttributeFromThingsboard, lwM2MClient is null");
  1282 + }
1265 1283 }
1266 1284
1267 1285 /**
... ... @@ -1350,6 +1368,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
1350 1368 public void onSuccess(TransportProtos.GetFirmwareResponseMsg response) {
1351 1369 if (TransportProtos.ResponseStatus.SUCCESS.equals(response.getResponseStatus())
1352 1370 && response.getType().equals(FirmwareType.FIRMWARE.name())) {
  1371 + log.warn ("7) firmware start with ver: [{}]",response.getVersion());
1353 1372 lwM2MClient.getFwUpdate().setCurrentVersion(response.getVersion());
1354 1373 lwM2MClient.getFwUpdate().setCurrentTitle(response.getTitle());
1355 1374 lwM2MClient.getFwUpdate().setCurrentId(new FirmwareId(new UUID(response.getFirmwareIdMSB(), response.getFirmwareIdLSB())).getId());
... ...
... ... @@ -83,11 +83,17 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
83 83
84 84 @Override
85 85 public LwM2mClient getClient(TransportProtos.SessionInfoProto sessionInfo) {
86   - return lwM2mClientsByEndpoint.values().stream().filter(c ->
  86 + LwM2mClient lwM2mClient = lwM2mClientsByEndpoint.values().stream().filter(c ->
87 87 (new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB()))
88 88 .equals((new UUID(c.getSession().getSessionIdMSB(), c.getSession().getSessionIdLSB())))
89 89
90 90 ).findAny().get();
  91 + if (lwM2mClient == null) {
  92 + log.warn("Device TimeOut? lwM2mClient is null.");
  93 + log.warn("SessionInfo input [{}], lwM2mClientsByEndpoint size: [{}]", sessionInfo, lwM2mClientsByEndpoint.values().size());
  94 + log.error("", new RuntimeException());
  95 + }
  96 + return lwM2mClient;
91 97 }
92 98
93 99 @Override
... ...
... ... @@ -155,12 +155,13 @@ public class LwM2mFwSwUpdate {
155 155 */
156 156 private void writeFwSwWare(DefaultLwM2MTransportMsgHandler handler, LwM2mTransportRequest request) {
157 157 this.stateUpdate = FirmwareUpdateStatus.DOWNLOADING.name();
158   -// this.observeStateUpdate();
  158 +
159 159 this.sendLogs(handler, WRITE_REPLACE.name(), LOG_LW2M_INFO, null);
160 160 int chunkSize = 0;
161 161 int chunk = 0;
162 162 byte[] firmwareChunk = handler.firmwareDataCache.get(this.currentId.toString(), chunkSize, chunk);
163 163 String targetIdVer = convertPathFromObjectIdToIdVer(this.pathPackageId, this.lwM2MClient.getRegistration());
  164 + log.warn ("8) firmware send save to : [{}]", targetIdVer);
164 165 request.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(),
165 166 firmwareChunk, handler.config.getTimeout(), null);
166 167 }
... ...
... ... @@ -43,6 +43,9 @@ public class LwM2mValueConverterImpl implements LwM2mValueConverter {
43 43 @Override
44 44 public Object convertValue(Object value, Type currentType, Type expectedType, LwM2mPath resourcePath)
45 45 throws CodecException {
  46 + if (value == null) {
  47 + return null;
  48 + }
46 49 if (expectedType == null) {
47 50 /** unknown resource, trusted value */
48 51 return value;
... ...