コード例 #1
0
ファイル: WriteTest.java プロジェクト: emmelmann-fokus/leshan
  @Test
  public void can_write_object_instance() {
    // write device timezone and offset
    LwM2mResource utcOffset = LwM2mSingleResource.newStringResource(14, "+02");
    LwM2mResource timeZone = LwM2mSingleResource.newStringResource(15, "Europe/Paris");
    WriteResponse response =
        helper.server.send(
            helper.getClient(), new WriteRequest(Mode.REPLACE, 3, 0, utcOffset, timeZone));

    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());

    // read the timezone to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getClient(), new ReadRequest(3, 0));
    LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();
    assertEquals(utcOffset, instance.getResource(14));
    assertEquals(timeZone, instance.getResource(15));
  }
コード例 #2
0
    @Override
    public void visit(LwM2mObjectInstance instance) {
      LOG.trace("Encoding object instance {} into TLV", instance);

      // The instance is encoded as an array of resource TLVs.
      Tlv[] rTlvs = encodeResources(instance.getResources().values());

      try {
        out.write(TlvEncoder.encode(rTlvs).array());
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }