use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.
the class TlvDecoder method decodeObjlnk.
/**
* Decodes a byte array into a objlnk value.
*/
public static ObjectLink decodeObjlnk(byte[] value) throws TlvException {
ByteBuffer bff = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN);
bff.put(value);
int val1 = bff.getShort(0) & 0xFFFF;
int val2 = bff.getShort(2) & 0xFFFF;
return new ObjectLink(val1, val2);
}
use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.
the class WriteTest method can_write_single_instance_objlnk_resource_in_text.
@Test
public void can_write_single_instance_objlnk_resource_in_text() throws InterruptedException {
// Write objlnk resource in TEXT format
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TEXT, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, new ObjectLink(10245, 0)));
// Verify Write result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// Reading back the written OBJLNK value
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(ContentFormat.TEXT, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID));
LwM2mSingleResource resource = (LwM2mSingleResource) readResponse.getContent();
// verify read value
assertEquals(((ObjectLink) resource.getValue()).getObjectId(), 10245);
assertEquals(((ObjectLink) resource.getValue()).getObjectInstanceId(), 0);
}
use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.
the class WriteTest method can_write_multi_instance_objlnk_resource_in_tlv.
@Test
public void can_write_multi_instance_objlnk_resource_in_tlv() throws InterruptedException {
Map<Integer, ObjectLink> neighbourCellReport = new HashMap<>();
neighbourCellReport.put(0, new ObjectLink(10245, 1));
neighbourCellReport.put(1, new ObjectLink(10242, 2));
neighbourCellReport.put(2, new ObjectLink(10244, 3));
// Write objlnk resource in TLV format
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TLV, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_MULTI_INSTANCE_RESOURCE_ID, neighbourCellReport, Type.OBJLNK));
// Verify Write result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// Reading back the written OBJLNK value
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_MULTI_INSTANCE_RESOURCE_ID));
LwM2mMultipleResource resource = (LwM2mMultipleResource) readResponse.getContent();
// verify read value
assertEquals(((ObjectLink) resource.getValue(0)).getObjectId(), 10245);
assertEquals(((ObjectLink) resource.getValue(0)).getObjectInstanceId(), 1);
assertEquals(((ObjectLink) resource.getValue(1)).getObjectId(), 10242);
assertEquals(((ObjectLink) resource.getValue(1)).getObjectInstanceId(), 2);
assertEquals(((ObjectLink) resource.getValue(2)).getObjectId(), 10244);
assertEquals(((ObjectLink) resource.getValue(2)).getObjectInstanceId(), 3);
}
use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.
the class TlvDecoderTest method decode_object_link.
@Test
public void decode_object_link() throws TlvException {
String dataStr = "12345678";
byte[] bytes = Hex.decodeHex(dataStr.toCharArray());
ObjectLink objlnk = TlvDecoder.decodeObjlnk(bytes);
assertEquals(0x1234, objlnk.getObjectId());
assertEquals(0x5678, objlnk.getObjectInstanceId());
dataStr = "ffffffff";
bytes = Hex.decodeHex(dataStr.toCharArray());
objlnk = TlvDecoder.decodeObjlnk(bytes);
assertEquals(0xffff, objlnk.getObjectId());
assertEquals(0xffff, objlnk.getObjectInstanceId());
}
use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_invalid_multi_resource_2_instance_with_the_same_id.
@Test(expected = CodecException.class)
public void tlv_invalid_multi_resource_2_instance_with_the_same_id() {
Tlv resInstance1 = new Tlv(TlvType.RESOURCE_INSTANCE, null, TlvEncoder.encodeObjlnk(new ObjectLink(100, 1)), 0);
Tlv resInstance2 = new Tlv(TlvType.RESOURCE_INSTANCE, null, TlvEncoder.encodeObjlnk(new ObjectLink(101, 2)), 0);
Tlv multiResource = new Tlv(TlvType.MULTIPLE_RESOURCE, new Tlv[] { resInstance1, resInstance2 }, null, 22);
byte[] content = TlvEncoder.encode(new Tlv[] { multiResource }).array();
decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 22), model);
}
Aggregations