Lwm2m: backEnd: add PUT_TYPE_OPER_WRITE_UPDATE
This commit is contained in:
parent
ff56bd8863
commit
4f3707c1e1
@ -99,11 +99,13 @@ public class LwM2MTransportHandler {
|
|||||||
/**
|
/**
|
||||||
* Replaces the Object Instance or the Resource(s) with the new value provided in the “Write” operation. (see
|
* Replaces the Object Instance or the Resource(s) with the new value provided in the “Write” operation. (see
|
||||||
* section 5.3.3 of the LW M2M spec).
|
* section 5.3.3 of the LW M2M spec).
|
||||||
|
* if all resources are to be replaced
|
||||||
*/
|
*/
|
||||||
public static final String POST_TYPE_OPER_WRITE_REPLACE = "replace";
|
public static final String POST_TYPE_OPER_WRITE_REPLACE = "replace";
|
||||||
/**
|
/**
|
||||||
* Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see section
|
* Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see section
|
||||||
* 5.3.3 of the LW M2M spec).
|
* 5.3.3 of the LW M2M spec).
|
||||||
|
* if this is a partial update request
|
||||||
*/
|
*/
|
||||||
public static final String PUT_TYPE_OPER_WRITE_UPDATE = "update";
|
public static final String PUT_TYPE_OPER_WRITE_UPDATE = "update";
|
||||||
public static final String PUT_TYPE_OPER_WRITE_ATTRIBUTES = "wright-attributes";
|
public static final String PUT_TYPE_OPER_WRITE_ATTRIBUTES = "wright-attributes";
|
||||||
@ -152,34 +154,6 @@ public class LwM2MTransportHandler {
|
|||||||
return coapConfig;
|
return coapConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String getValueTypeToString (Object value, ResourceModel.Type type, int val) {
|
|
||||||
// try{
|
|
||||||
// switch (type) {
|
|
||||||
// case STRING: // String
|
|
||||||
// case OBJLNK: // ObjectLink
|
|
||||||
// return value.toString();
|
|
||||||
// case INTEGER: // Long
|
|
||||||
// return Long.toString((long) value);
|
|
||||||
// case BOOLEAN: // Boolean
|
|
||||||
// return Boolean.toString((Boolean) value);
|
|
||||||
// case FLOAT: // Double
|
|
||||||
// return Double.toString((Double) value);
|
|
||||||
// case TIME: // Date
|
|
||||||
// return Long.toString(((Date) value).getTime());
|
|
||||||
//// String DATE_FORMAT = "MMM d, yyyy HH:mm a";
|
|
||||||
//// DateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
|
|
||||||
//// return formatter.format(new Date(Integer.toUnsignedLong((Integer) value)));
|
|
||||||
// case OPAQUE: // byte[] value, base64
|
|
||||||
// return Hex.encodeHexString((byte[])value);
|
|
||||||
// default:
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error(e.getStackTrace().toString());
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static boolean equalsResourceValue(Object valueOld, Object valueNew, ResourceModel.Type type, LwM2mPath resourcePath) throws CodecException {
|
public static boolean equalsResourceValue(Object valueOld, Object valueNew, ResourceModel.Type type, LwM2mPath resourcePath) throws CodecException {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import org.eclipse.californium.core.coap.Response;
|
|||||||
import org.eclipse.leshan.core.attributes.Attribute;
|
import org.eclipse.leshan.core.attributes.Attribute;
|
||||||
import org.eclipse.leshan.core.attributes.AttributeSet;
|
import org.eclipse.leshan.core.attributes.AttributeSet;
|
||||||
import org.eclipse.leshan.core.model.ResourceModel;
|
import org.eclipse.leshan.core.model.ResourceModel;
|
||||||
|
import org.eclipse.leshan.core.node.LwM2mNode;
|
||||||
import org.eclipse.leshan.core.node.LwM2mPath;
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
||||||
import org.eclipse.leshan.core.node.LwM2mSingleResource;
|
import org.eclipse.leshan.core.node.LwM2mSingleResource;
|
||||||
import org.eclipse.leshan.core.node.ObjectLink;
|
import org.eclipse.leshan.core.node.ObjectLink;
|
||||||
@ -146,7 +147,6 @@ public class LwM2MTransportRequest {
|
|||||||
break;
|
break;
|
||||||
case POST_TYPE_OPER_EXECUTE:
|
case POST_TYPE_OPER_EXECUTE:
|
||||||
if (params != null && resource != null && !resource.multiple) {
|
if (params != null && resource != null && !resource.multiple) {
|
||||||
// request = new ExecuteRequest(target, LwM2MTransportHandler.getValueTypeToString(params, resType));
|
|
||||||
request = new ExecuteRequest(target, (String) this.converter.convertValue(params, resource.type, ResourceModel.Type.STRING, resultIds));
|
request = new ExecuteRequest(target, (String) this.converter.convertValue(params, resource.type, ResourceModel.Type.STRING, resultIds));
|
||||||
} else {
|
} else {
|
||||||
request = new ExecuteRequest(target);
|
request = new ExecuteRequest(target);
|
||||||
@ -168,7 +168,8 @@ public class LwM2MTransportRequest {
|
|||||||
if (resultIds.getResourceId() >= 0) {
|
if (resultIds.getResourceId() >= 0) {
|
||||||
ResourceModel resourceModel = lwServer.getModelProvider().getObjectModel(registration).getObjectModel(resultIds.getObjectId()).resources.get(resultIds.getResourceId());
|
ResourceModel resourceModel = lwServer.getModelProvider().getObjectModel(registration).getObjectModel(resultIds.getObjectId()).resources.get(resultIds.getResourceId());
|
||||||
ResourceModel.Type typeRes = resourceModel.type;
|
ResourceModel.Type typeRes = resourceModel.type;
|
||||||
// request = getWriteRequestResource(resultIds.getObjectId(), resultIds.getInstanceId(), resultIds.getResourceId(), params, typeRes);
|
LwM2mNode node = LwM2mSingleResource.newStringResource(resultIds.getResourceId(), (String) this.converter.convertValue(params, resource.type, ResourceModel.Type.STRING, resultIds));
|
||||||
|
request = new WriteRequest(WriteRequest.Mode.UPDATE, contentFormat, target, node);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUT_TYPE_OPER_WRITE_ATTRIBUTES:
|
case PUT_TYPE_OPER_WRITE_ATTRIBUTES:
|
||||||
|
|||||||
@ -515,7 +515,6 @@ public class LwM2MTransportService {
|
|||||||
private void getParametersFromProfile(JsonObject attributes, JsonObject telemetry, Registration registration, Set<String> path) {
|
private void getParametersFromProfile(JsonObject attributes, JsonObject telemetry, Registration registration, Set<String> path) {
|
||||||
AttrTelemetryObserveValue attrTelemetryObserveValue = lwM2mInMemorySecurityStore.getProfiles().get(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid());
|
AttrTelemetryObserveValue attrTelemetryObserveValue = lwM2mInMemorySecurityStore.getProfiles().get(lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getProfileUuid());
|
||||||
attrTelemetryObserveValue.getPostAttributeProfile().forEach(p -> {
|
attrTelemetryObserveValue.getPostAttributeProfile().forEach(p -> {
|
||||||
// ResultIds pathIds = new ResultIds(p.getAsString().toString());
|
|
||||||
LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString());
|
LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString());
|
||||||
if (pathIds.isResource()) {
|
if (pathIds.isResource()) {
|
||||||
if (path == null || path.contains(p.getAsString())) {
|
if (path == null || path.contains(p.getAsString())) {
|
||||||
@ -524,7 +523,6 @@ public class LwM2MTransportService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
attrTelemetryObserveValue.getPostTelemetryProfile().forEach(p -> {
|
attrTelemetryObserveValue.getPostTelemetryProfile().forEach(p -> {
|
||||||
// ResultIds pathIds = new ResultIds(p.getAsString().toString());
|
|
||||||
LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString());
|
LwM2mPath pathIds = new LwM2mPath(p.getAsString().toString());
|
||||||
if (pathIds.isResource()) {
|
if (pathIds.isResource()) {
|
||||||
if (path == null || path.contains(p.getAsString())) {
|
if (path == null || path.contains(p.getAsString())) {
|
||||||
@ -545,10 +543,8 @@ public class LwM2MTransportService {
|
|||||||
if (resName != null && !resName.isEmpty()) {
|
if (resName != null && !resName.isEmpty()) {
|
||||||
String resValue = null;
|
String resValue = null;
|
||||||
try {
|
try {
|
||||||
// resValue = lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getResourceValueString(path);
|
|
||||||
resValue = this.getResourceValueToString(lwM2MClient, path);
|
resValue = this.getResourceValueToString(lwM2MClient, path);
|
||||||
if (resValue != null) {
|
if (resValue != null) {
|
||||||
// log.info("addParameters Path: [{}] ResValue : [{}] nameParam [{}]", path, lwM2mInMemorySecurityStore.getSessions().get(registration.getId()).getResourceValue(path), nameParam);
|
|
||||||
parameters.addProperty(resName, resValue);
|
parameters.addProperty(resName, resValue);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -1061,10 +1057,7 @@ public class LwM2MTransportService {
|
|||||||
*/
|
*/
|
||||||
private void updateResourceValueObserve(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, Set<String> targets, String typeOper) {
|
private void updateResourceValueObserve(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, Set<String> targets, String typeOper) {
|
||||||
targets.forEach(target -> {
|
targets.forEach(target -> {
|
||||||
// ResultIds pathIds = new ResultIds(target);
|
|
||||||
LwM2mPath pathIds = new LwM2mPath(target);
|
LwM2mPath pathIds = new LwM2mPath(target);
|
||||||
// if (pathIds.isResource() && lwM2MClient.getModelObjects().get(pathIds.getObjectId())
|
|
||||||
// .getInstances().get(pathIds.getObjectInstanceId()).getResource(pathIds.getResourceId()).getValue() != null) {
|
|
||||||
if (pathIds.isResource()) {
|
if (pathIds.isResource()) {
|
||||||
if (GET_TYPE_OPER_READ.equals(typeOper)) {
|
if (GET_TYPE_OPER_READ.equals(typeOper)) {
|
||||||
lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user