Skip to content

Commit

Permalink
server-demo: Add ObjLink write support.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 28, 2021
1 parent 99ea91f commit 3cb4007
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.node.LwM2mResourceInstance;
import org.eclipse.leshan.core.node.LwM2mSingleResource;
import org.eclipse.leshan.core.node.ObjectLink;
import org.eclipse.leshan.core.util.Hex;

import com.fasterxml.jackson.core.JsonParseException;
Expand Down Expand Up @@ -181,6 +182,20 @@ private Object deserializeValue(JsonNode val, ResourceModel.Type type) {
raiseUnexpectedType(val, type, "string", val.getNodeType());
}
break;
case OBJLNK:
if (val.isObject()) {
if (val.has("objectId") && val.has("objectInstanceId")) {
JsonNode objectId = val.get("objectId");
JsonNode objectInstanceId = val.get("objectInstanceId");
if (objectId.canConvertToInt() && objectId.canConvertToExactIntegral() && //
objectInstanceId.canConvertToInt() && objectInstanceId.canConvertToExactIntegral()) {
return new ObjectLink(objectId.asInt(), objectInstanceId.asInt());
}
}
}
raiseUnexpectedType(val, type, "object{objectId:integer, objectInstanceId:integer}", val.getNodeType());
break;

default:
break;
}
Expand Down
@@ -0,0 +1,94 @@
<!-----------------------------------------------------------------------------
* Copyright (c) 2021 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
----------------------------------------------------------------------------->
<template>
<v-row>
<v-col>
<v-text-field
single-line
label="Object Id"
:rules="[(v) => !v || isValidId(v) || 'Invalid object id']"
:value="objectId"
@input="$emit('input', objectIdChanged($event))"
clearable
/>
</v-col>
<v-col>
<v-text-field
single-line
label="Object Instance Id"
:rules="[(v) => !v || isValidId(v) || 'Invalid object instance id']"
:value="objectInstanceId"
@input="$emit('input', objectInstanceIdChanged($event))"
clearable
/>
</v-col>
</v-row>
</template>
<script>
import { isInteger } from "../../../js/utils.js";
/**
* An input for OBJLNK single value LWM2M node ("Single Instance Resource" or "Resource Instance")
*/
export default {
props: {
value: null, // the input value for this LWM2M Node (v-model)
resourcedef: Object, // the model of the resource
},
data() {
return {
objectId: "",
objectInstanceId: "",
};
},
watch: {
value(v) {
this.objectId = v.objectId;
this.objectInstanceId = v.objectInstanceId;
},
},
methods: {
convertToNumber(v){
if (isInteger(v)){
return Number(v)
}else{
return v;
}
},
isValidId(v) {
return isInteger(v);
},
objectIdChanged(v) {
if (v === "" && this.objectInstanceId === "") {
return null;
} else {
return {
objectId: this.convertToNumber(v),
objectInstanceId: this.objectInstanceId,
};
}
},
objectInstanceIdChanged(v) {
if (this.objectId === "" && v === "") {
return null;
} else {
return {
objectId: this.objectId,
objectInstanceId: this.convertToNumber(v)
};
}
},
},
};
</script>
Expand Up @@ -29,6 +29,12 @@
:value="value"
@input="$emit('input', convertValue($event))"
/>
<obj-link-value-input
v-else-if="resourcedef.type == 'objlnk'"
:resourcedef="resourcedef"
:value="value"
@input="$emit('input', convertValue($event))"
/>
<v-text-field
v-else
:label="resourcedef.type"
Expand All @@ -43,12 +49,13 @@ import BooleanValueInput from "./BooleanValueInput.vue";
import DateTimeValueInput from "./DateTimeValueInput.vue";
import OpaqueValueInput from "./OpaqueValueInput.vue";
import { isInteger, isNumber } from "../../../js/utils.js";
import ObjLinkValueInput from './ObjLinkValueInput.vue';
/**
* An input for single value LWM2M node ("Single Instance Resource" or "Resource Instance")
*/
export default {
components: { BooleanValueInput, OpaqueValueInput, DateTimeValueInput },
components: { BooleanValueInput, OpaqueValueInput, DateTimeValueInput, ObjLinkValueInput },
props: {
value: null, // the input value for this LWM2M Node (v-model)
resourcedef: Object, // the model of the resource
Expand Down

0 comments on commit 3cb4007

Please sign in to comment.