use of org.eclipse.leshan.core.attributes.AttributeSet in project thingsboard by thingsboard.
the class DefaultLwM2mDownlinkMsgHandler method sendWriteAttributesRequest.
/**
* Example # 1:
* AttributeSet attributes = new AttributeSet(new Attribute(Attribute.MINIMUM_PERIOD, 10L),
* new Attribute(Attribute.MAXIMUM_PERIOD, 100L));
* WriteAttributesRequest requestTest = new WriteAttributesRequest(3, 0, 14, attributes);
* sendSimpleRequest(client, requestTest, request.getTimeout(), callback);
* <p>
* Example # 2
* Dimension and Object version are read only attributes.
* addAttribute(attributes, DIMENSION, params.getDim(), dim -> dim >= 0 && dim <= 255);
* addAttribute(attributes, OBJECT_VERSION, params.getVer(), StringUtils::isNotEmpty, Function.identity());
*/
@Override
public void sendWriteAttributesRequest(LwM2mClient client, TbLwM2MWriteAttributesRequest request, DownlinkRequestCallback<WriteAttributesRequest, WriteAttributesResponse> callback) {
try {
validateVersionedId(client, request);
if (request.getAttributes() == null) {
throw new IllegalArgumentException("Attributes to write are not specified!");
}
ObjectAttributes params = request.getAttributes();
List<Attribute> attributes = new LinkedList<>();
addAttribute(attributes, MAXIMUM_PERIOD, params.getPmax());
addAttribute(attributes, MINIMUM_PERIOD, params.getPmin());
addAttribute(attributes, GREATER_THAN, params.getGt());
addAttribute(attributes, LESSER_THAN, params.getLt());
addAttribute(attributes, STEP, params.getSt());
AttributeSet attributeSet = new AttributeSet(attributes);
sendSimpleRequest(client, new WriteAttributesRequest(request.getObjectId(), attributeSet), request.getTimeout(), callback);
} catch (InvalidRequestException e) {
callback.onValidationError(request.toString(), e.getMessage());
}
}
Aggregations