|
@@ -24,10 +24,12 @@ import com.google.gson.JsonObject; |
|
@@ -24,10 +24,12 @@ import com.google.gson.JsonObject; |
24
|
import com.google.gson.reflect.TypeToken;
|
24
|
import com.google.gson.reflect.TypeToken;
|
25
|
import lombok.extern.slf4j.Slf4j;
|
25
|
import lombok.extern.slf4j.Slf4j;
|
26
|
import org.eclipse.leshan.core.model.ResourceModel;
|
26
|
import org.eclipse.leshan.core.model.ResourceModel;
|
|
|
27
|
+import org.eclipse.leshan.core.node.LwM2mMultipleResource;
|
27
|
import org.eclipse.leshan.core.node.LwM2mObject;
|
28
|
import org.eclipse.leshan.core.node.LwM2mObject;
|
28
|
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
|
29
|
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
|
29
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
30
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
30
|
import org.eclipse.leshan.core.node.LwM2mResource;
|
31
|
import org.eclipse.leshan.core.node.LwM2mResource;
|
|
|
32
|
+import org.eclipse.leshan.core.node.LwM2mSingleResource;
|
31
|
import org.eclipse.leshan.core.observation.Observation;
|
33
|
import org.eclipse.leshan.core.observation.Observation;
|
32
|
import org.eclipse.leshan.core.request.ContentFormat;
|
34
|
import org.eclipse.leshan.core.request.ContentFormat;
|
33
|
import org.eclipse.leshan.core.request.WriteRequest;
|
35
|
import org.eclipse.leshan.core.request.WriteRequest;
|
|
@@ -54,6 +56,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; |
|
@@ -54,6 +56,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; |
54
|
import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
|
56
|
import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
|
55
|
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
|
57
|
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
|
56
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
|
58
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
|
|
|
59
|
+import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper;
|
57
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
|
60
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
|
58
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
|
61
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
|
59
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile;
|
62
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientProfile;
|
|
@@ -92,7 +95,6 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle |
|
@@ -92,7 +95,6 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle |
92
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO;
|
95
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO;
|
93
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE;
|
96
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE;
|
94
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_STRATEGY_2;
|
97
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_STRATEGY_2;
|
95
|
-import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper;
|
|
|
96
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.DISCOVER;
|
98
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.DISCOVER;
|
97
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.EXECUTE;
|
99
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.EXECUTE;
|
98
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE;
|
100
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE;
|
|
@@ -294,23 +296,31 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -294,23 +296,31 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
294
|
@Override
|
296
|
@Override
|
295
|
public void onUpdateValueAfterReadResponse(Registration registration, String path, ReadResponse response, Lwm2mClientRpcRequest rpcRequest) {
|
297
|
public void onUpdateValueAfterReadResponse(Registration registration, String path, ReadResponse response, Lwm2mClientRpcRequest rpcRequest) {
|
296
|
if (response.getContent() != null) {
|
298
|
if (response.getContent() != null) {
|
|
|
299
|
+ Object value = null;
|
297
|
if (response.getContent() instanceof LwM2mObject) {
|
300
|
if (response.getContent() instanceof LwM2mObject) {
|
298
|
LwM2mObject lwM2mObject = (LwM2mObject) response.getContent();
|
301
|
LwM2mObject lwM2mObject = (LwM2mObject) response.getContent();
|
|
|
302
|
+ if (rpcRequest != null) {
|
|
|
303
|
+ value = lwM2mObject.toString();
|
|
|
304
|
+ }
|
299
|
this.updateObjectResourceValue(registration, lwM2mObject, path);
|
305
|
this.updateObjectResourceValue(registration, lwM2mObject, path);
|
300
|
} else if (response.getContent() instanceof LwM2mObjectInstance) {
|
306
|
} else if (response.getContent() instanceof LwM2mObjectInstance) {
|
301
|
LwM2mObjectInstance lwM2mObjectInstance = (LwM2mObjectInstance) response.getContent();
|
307
|
LwM2mObjectInstance lwM2mObjectInstance = (LwM2mObjectInstance) response.getContent();
|
|
|
308
|
+ if (rpcRequest != null) {
|
|
|
309
|
+ value = lwM2mObjectInstance.toString();
|
|
|
310
|
+ }
|
302
|
this.updateObjectInstanceResourceValue(registration, lwM2mObjectInstance, path);
|
311
|
this.updateObjectInstanceResourceValue(registration, lwM2mObjectInstance, path);
|
303
|
} else if (response.getContent() instanceof LwM2mResource) {
|
312
|
} else if (response.getContent() instanceof LwM2mResource) {
|
304
|
LwM2mResource lwM2mResource = (LwM2mResource) response.getContent();
|
313
|
LwM2mResource lwM2mResource = (LwM2mResource) response.getContent();
|
305
|
if (rpcRequest != null) {
|
314
|
if (rpcRequest != null) {
|
306
|
- Object valueResp = lwM2mResource.isMultiInstances() ? lwM2mResource.getValues() : lwM2mResource.getValue();
|
|
|
307
|
- Object value = this.converter.convertValue(valueResp, lwM2mResource.getType(), ResourceModel.Type.STRING,
|
|
|
308
|
- new LwM2mPath(convertPathFromIdVerToObjectId(path)));
|
|
|
309
|
- rpcRequest.setValueMsg(String.format("%s", value));
|
|
|
310
|
- this.sentRpcRequest(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE);
|
315
|
+ value = lwM2mResource.isMultiInstances() ? ((LwM2mMultipleResource) lwM2mResource).toString() :
|
|
|
316
|
+ ((LwM2mSingleResource) lwM2mResource).toString();
|
311
|
}
|
317
|
}
|
312
|
this.updateResourcesValue(registration, lwM2mResource, path);
|
318
|
this.updateResourcesValue(registration, lwM2mResource, path);
|
313
|
}
|
319
|
}
|
|
|
320
|
+ if (rpcRequest != null) {
|
|
|
321
|
+ rpcRequest.setValueMsg(String.format("%s", value));
|
|
|
322
|
+ this.sentRpcRequest(rpcRequest, response.getCode().getName(), (String) value, LOG_LW2M_VALUE);
|
|
|
323
|
+ }
|
314
|
}
|
324
|
}
|
315
|
}
|
325
|
}
|
316
|
|
326
|
|
|
@@ -616,7 +626,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -616,7 +626,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
616
|
public void sendLogsToThingsboard(String logMsg, String registrationId) {
|
626
|
public void sendLogsToThingsboard(String logMsg, String registrationId) {
|
617
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registrationId);
|
627
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registrationId);
|
618
|
if (logMsg != null && sessionInfo != null) {
|
628
|
if (logMsg != null && sessionInfo != null) {
|
619
|
- if(logMsg.length() > 1024){
|
629
|
+ if (logMsg.length() > 1024) {
|
620
|
logMsg = logMsg.substring(0, 1024);
|
630
|
logMsg = logMsg.substring(0, 1024);
|
621
|
}
|
631
|
}
|
622
|
this.helper.sendParametersOnThingsboardTelemetry(this.helper.getKvLogyToThingsboard(logMsg), sessionInfo);
|
632
|
this.helper.sendParametersOnThingsboardTelemetry(this.helper.getKvLogyToThingsboard(logMsg), sessionInfo);
|
|
@@ -656,10 +666,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -656,10 +666,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
656
|
/**
|
666
|
/**
|
657
|
* @param registration -
|
667
|
* @param registration -
|
658
|
* @param lwM2mObject -
|
668
|
* @param lwM2mObject -
|
659
|
- * @param path -
|
669
|
+ * @param pathIdVer -
|
660
|
*/
|
670
|
*/
|
661
|
- private void updateObjectResourceValue(Registration registration, LwM2mObject lwM2mObject, String path) {
|
|
|
662
|
- LwM2mPath pathIds = new LwM2mPath(path);
|
671
|
+ private void updateObjectResourceValue(Registration registration, LwM2mObject lwM2mObject, String pathIdVer) {
|
|
|
672
|
+ LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer));
|
663
|
lwM2mObject.getInstances().forEach((instanceId, instance) -> {
|
673
|
lwM2mObject.getInstances().forEach((instanceId, instance) -> {
|
664
|
String pathInstance = pathIds.toString() + "/" + instanceId;
|
674
|
String pathInstance = pathIds.toString() + "/" + instanceId;
|
665
|
this.updateObjectInstanceResourceValue(registration, instance, pathInstance);
|
675
|
this.updateObjectInstanceResourceValue(registration, instance, pathInstance);
|
|
@@ -669,10 +679,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -669,10 +679,10 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
669
|
/**
|
679
|
/**
|
670
|
* @param registration -
|
680
|
* @param registration -
|
671
|
* @param lwM2mObjectInstance -
|
681
|
* @param lwM2mObjectInstance -
|
672
|
- * @param path -
|
682
|
+ * @param pathIdVer -
|
673
|
*/
|
683
|
*/
|
674
|
- private void updateObjectInstanceResourceValue(Registration registration, LwM2mObjectInstance lwM2mObjectInstance, String path) {
|
|
|
675
|
- LwM2mPath pathIds = new LwM2mPath(path);
|
684
|
+ private void updateObjectInstanceResourceValue(Registration registration, LwM2mObjectInstance lwM2mObjectInstance, String pathIdVer) {
|
|
|
685
|
+ LwM2mPath pathIds = new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer));
|
676
|
lwM2mObjectInstance.getResources().forEach((resourceId, resource) -> {
|
686
|
lwM2mObjectInstance.getResources().forEach((resourceId, resource) -> {
|
677
|
String pathRez = pathIds.toString() + "/" + resourceId;
|
687
|
String pathRez = pathIds.toString() + "/" + resourceId;
|
678
|
this.updateResourcesValue(registration, resource, pathRez);
|
688
|
this.updateResourcesValue(registration, resource, pathRez);
|
|
@@ -782,8 +792,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -782,8 +792,8 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
782
|
lwM2MClient.getPendingReadRequests().addAll(pathSend);
|
792
|
lwM2MClient.getPendingReadRequests().addAll(pathSend);
|
783
|
ConcurrentHashMap<String, Object> finalParams = params;
|
793
|
ConcurrentHashMap<String, Object> finalParams = params;
|
784
|
pathSend.forEach(target -> {
|
794
|
pathSend.forEach(target -> {
|
785
|
- lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
|
|
|
786
|
- finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null);
|
795
|
+ lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
|
|
|
796
|
+ finalParams != null ? finalParams.get(target) : null, this.config.getTimeout(), null);
|
787
|
});
|
797
|
});
|
788
|
if (OBSERVE.equals(typeOper)) {
|
798
|
if (OBSERVE.equals(typeOper)) {
|
789
|
lwM2MClient.initReadValue(this, null);
|
799
|
lwM2MClient.initReadValue(this, null);
|
|
@@ -932,10 +942,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -932,10 +942,9 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
932
|
public void onWriteResponseOk(Registration registration, String path, WriteRequest request) {
|
942
|
public void onWriteResponseOk(Registration registration, String path, WriteRequest request) {
|
933
|
if (request.getNode() instanceof LwM2mResource) {
|
943
|
if (request.getNode() instanceof LwM2mResource) {
|
934
|
this.updateResourcesValue(registration, ((LwM2mResource) request.getNode()), path);
|
944
|
this.updateResourcesValue(registration, ((LwM2mResource) request.getNode()), path);
|
935
|
- }
|
|
|
936
|
- else if (request.getNode() instanceof LwM2mObjectInstance) {
|
945
|
+ } else if (request.getNode() instanceof LwM2mObjectInstance) {
|
937
|
((LwM2mObjectInstance) request.getNode()).getResources().forEach((resId, resource) -> {
|
946
|
((LwM2mObjectInstance) request.getNode()).getResources().forEach((resId, resource) -> {
|
938
|
- this.updateResourcesValue(registration, resource, path+ "/" + resId);
|
947
|
+ this.updateResourcesValue(registration, resource, path + "/" + resId);
|
939
|
});
|
948
|
});
|
940
|
}
|
949
|
}
|
941
|
|
950
|
|
|
@@ -1421,7 +1430,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
|
@@ -1421,7 +1430,6 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler |
1421
|
}
|
1430
|
}
|
1422
|
|
1431
|
|
1423
|
/**
|
1432
|
/**
|
1424
|
- *
|
|
|
1425
|
* @param lwM2MClient -
|
1433
|
* @param lwM2MClient -
|
1426
|
*/
|
1434
|
*/
|
1427
|
public void updateFirmwareClient(LwM2mClient lwM2MClient) {
|
1435
|
public void updateFirmwareClient(LwM2mClient lwM2MClient) {
|