use of org.eclipse.leshan.core.attributes.Attribute in project thingsboard by thingsboard.
the class LwM2MTransportUtil method createWriteAttributes.
private static Attribute[] createWriteAttributes(Object params, DefaultLwM2mUplinkMsgHandler serviceImpl, String target) {
List<Attribute> attributeLists = new ArrayList<>();
Map<String, Object> map = JacksonUtil.convertValue(params, new TypeReference<>() {
});
map.forEach((k, v) -> {
if (StringUtils.trimToNull(v.toString()) != null) {
Object attrValue = convertWriteAttributes(k, v, serviceImpl, target);
if (attrValue != null) {
Attribute attribute = createAttribute(k, attrValue);
if (attribute != null) {
attributeLists.add(new Attribute(k, attrValue));
}
}
}
});
return attributeLists.toArray(Attribute[]::new);
}
use of org.eclipse.leshan.core.attributes.Attribute 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