当前位置: 首页>>代码示例>>Java>>正文


Java LwM2mResource类代码示例

本文整理汇总了Java中org.eclipse.leshan.core.node.LwM2mResource的典型用法代码示例。如果您正苦于以下问题:Java LwM2mResource类的具体用法?Java LwM2mResource怎么用?Java LwM2mResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LwM2mResource类属于org.eclipse.leshan.core.node包,在下文中一共展示了LwM2mResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cannot_create_instance_with_extraneous_resources

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Ignore
@Test
public void cannot_create_instance_with_extraneous_resources() throws InterruptedException {
    // create ACL instance
    LwM2mObjectInstance instance = new LwM2mObjectInstance(0, Arrays.<LwM2mResource> asList(
            LwM2mSingleResource.newIntegerResource(3, 123), LwM2mSingleResource.newIntegerResource(50, 123)));
    CreateRequest request = new CreateRequest(2, instance);
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(), request);

    // verify result
    assertEquals(ResponseCode.BAD_REQUEST, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // try to read to check if the instance is not created
    // client registration
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(2, 0));
    assertEquals(ResponseCode.NOT_FOUND, readResponse.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:22,代码来源:CreateTest.java

示例2: write

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Override
public WriteResponse write(int resourceid, LwM2mResource value) {
    LOG.info("Write on Device Resource " + resourceid + " value " + value);
    switch (resourceid) {
    case 13:
        return WriteResponse.notFound();
    case 14:
        setUtcOffset((String) value.getValue());
        fireResourcesChange(resourceid);
        return WriteResponse.success();
    case 15:
        setTimezone((String) value.getValue());
        fireResourcesChange(resourceid);
        return WriteResponse.success();
    default:
        return super.write(resourceid, value);
    }
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:19,代码来源:KETIVirtualDevice.java

示例3: convertToSecurityInstance

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private LwM2mObjectInstance convertToSecurityInstance(int instanceId, ServerSecurity securityConfig) {
    Collection<LwM2mResource> resources = new ArrayList<>();

    resources.add(LwM2mSingleResource.newStringResource(0, securityConfig.uri));
    resources.add(LwM2mSingleResource.newBooleanResource(1, securityConfig.bootstrapServer));
    resources.add(LwM2mSingleResource.newIntegerResource(2, securityConfig.securityMode.code));
    resources.add(LwM2mSingleResource.newBinaryResource(3, securityConfig.publicKeyOrId));
    resources.add(LwM2mSingleResource.newBinaryResource(4, securityConfig.serverPublicKeyOrId));
    resources.add(LwM2mSingleResource.newBinaryResource(5, securityConfig.secretKey));
    resources.add(LwM2mSingleResource.newIntegerResource(6, securityConfig.smsSecurityMode.code));
    resources.add(LwM2mSingleResource.newBinaryResource(7, securityConfig.smsBindingKeyParam));
    resources.add(LwM2mSingleResource.newBinaryResource(8, securityConfig.smsBindingKeySecret));
    resources.add(LwM2mSingleResource.newStringResource(9, securityConfig.serverSmsNumber));
    resources.add(LwM2mSingleResource.newIntegerResource(10, securityConfig.serverId));
    resources.add(LwM2mSingleResource.newIntegerResource(11, securityConfig.clientOldOffTime));

    return new LwM2mObjectInstance(instanceId, resources);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:19,代码来源:BootstrapHandler.java

示例4: parseResourceTlv

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private static LwM2mResource parseResourceTlv(Tlv tlv, int objectId, int objectInstanceId, LwM2mModel model)
        throws InvalidValueException {
    LwM2mPath resourcePath = new LwM2mPath(objectId, objectInstanceId, tlv.getIdentifier());
    Type expectedType = getResourceType(resourcePath, model);
    Integer resourceId = tlv.getIdentifier();
    switch (tlv.getType()) {
    case MULTIPLE_RESOURCE:
        return LwM2mMultipleResource.newResource(resourceId,
                parseTlvValues(tlv.getChildren(), expectedType, resourcePath), expectedType);
    case RESOURCE_VALUE:
        return LwM2mSingleResource.newResource(resourceId,
                parseTlvValue(tlv.getValue(), expectedType, resourcePath), expectedType);
    default:
        throw new InvalidValueException("Invalid TLV value", resourcePath);
    }
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:17,代码来源:LwM2mNodeTlvDecoder.java

示例5: visit

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Override
public void visit(LwM2mObject object) {
    LOG.trace("Encoding Object {} into JSON", object);
    // Validate request path
    if (!requestPath.isObject()) {
        throw new IllegalArgumentException("Invalid request path for JSON object encoding");
    }

    // Create resources
    resourceList = new ArrayList<>();
    for (LwM2mObjectInstance instance : object.getInstances().values()) {
        for (LwM2mResource resource : instance.getResources().values()) {
            String prefixPath = Integer.toString(instance.getId()) + "/" + Integer.toString(resource.getId());
            resourceList.addAll(lwM2mResourceToJsonArrayEntry(prefixPath, timestamp, resource));
        }
    }
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:18,代码来源:LwM2mNodeJsonEncoder.java

示例6: convertToServerInstance

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private LwM2mObjectInstance convertToServerInstance(int instanceId, ServerConfig serverConfig) {
    Collection<LwM2mResource> resources = new ArrayList<>();

    resources.add(LwM2mSingleResource.newIntegerResource(0, serverConfig.shortId));
    resources.add(LwM2mSingleResource.newIntegerResource(1, serverConfig.lifetime));
    if (serverConfig.defaultMinPeriod != null)
        resources.add(LwM2mSingleResource.newIntegerResource(2, serverConfig.defaultMinPeriod));
    if (serverConfig.defaultMaxPeriod != null)
        resources.add(LwM2mSingleResource.newIntegerResource(3, serverConfig.defaultMaxPeriod));
    if (serverConfig.disableTimeout != null)
        resources.add(LwM2mSingleResource.newIntegerResource(5, serverConfig.disableTimeout));
    resources.add(LwM2mSingleResource.newBooleanResource(6, serverConfig.notifIfDisabled));
    if (serverConfig.binding != null)
        resources.add(LwM2mSingleResource.newStringResource(7, serverConfig.binding.name()));

    return new LwM2mObjectInstance(instanceId, resources);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:18,代码来源:BootstrapHandler.java

示例7: doCreate

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Override
protected CreateResponse doCreate(CreateRequest request) {
    Integer instanceId = request.getInstanceId();
    if (instanceId == null) {
        // the client is in charge to generate the id of the new instance
        if (instances.isEmpty()) {
            instanceId = 0;
        } else {
            instanceId = Collections.max(instances.keySet()) + 1;
        }
    }

    LwM2mInstanceEnabler newInstance = instanceFactory.create(getObjectModel());

    for (LwM2mResource resource : request.getResources()) {
        newInstance.write(resource.getId(), resource);
    }
    instances.put(instanceId, newInstance);
    listenInstance(newInstance, instanceId);

    return CreateResponse.success(new LwM2mPath(request.getPath().getObjectId(), instanceId).toString());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:23,代码来源:ObjectEnabler.java

示例8: write

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Override
public WriteResponse write(int resourceid, LwM2mResource value) {

    switch (resourceid) {

    case 14: // utc offset
        utcOffset = (String) value.getValue();
        fireResourcesChange(resourceid);
        return WriteResponse.success();

    case 15: // timezone
        timezone = (String) value.getValue();
        fireResourcesChange(resourceid);
        return WriteResponse.success();

    default:
        return super.write(resourceid, value);
    }
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:20,代码来源:Device.java

示例9: can_create_instance_of_object_without_instance_id

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Test
public void can_create_instance_of_object_without_instance_id() throws InterruptedException {
    // create ACL instance
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2,
            new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(0, 123) }));

    // verify result
    assertEquals(ResponseCode.CREATED, response.getCode());
    assertEquals("2/0", response.getLocation());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // create a second ACL instance
    response = helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2,
            new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(0, 123) }));

    // verify result
    assertEquals(ResponseCode.CREATED, response.getCode());
    assertEquals("2/1", response.getLocation());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

}
 
开发者ID:eclipse,项目名称:leshan,代码行数:24,代码来源:CreateTest.java

示例10: cannot_create_instance_without_all_required_resources

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
@Ignore
@Test
public void cannot_create_instance_without_all_required_resources() throws InterruptedException {
    // create ACL instance
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(),
            new CreateRequest(2, new LwM2mResource[0]));

    // verify result
    assertEquals(ResponseCode.BAD_REQUEST, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // try to read to check if the instance is not created
    // client registration
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(2, 0));
    assertEquals(ResponseCode.NOT_FOUND, readResponse.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:20,代码来源:CreateTest.java

示例11: write_string_resource

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private void write_string_resource(ContentFormat format) throws InterruptedException {
    // write resource
    String expectedvalue = "stringvalue";
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_ID, expectedvalue));

    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
            new ReadRequest(TEST_OBJECT_ID, 0, STRING_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertEquals(expectedvalue, resource.getValue());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:18,代码来源:WriteTest.java

示例12: write_boolean_resource

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private void write_boolean_resource(ContentFormat format) throws InterruptedException {
    // write resource
    boolean expectedvalue = true;
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(format, TEST_OBJECT_ID, 0, BOOLEAN_RESOURCE_ID, expectedvalue));

    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
            new ReadRequest(TEST_OBJECT_ID, 0, BOOLEAN_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertEquals(expectedvalue, resource.getValue());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:18,代码来源:WriteTest.java

示例13: write_integer_resource

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private void write_integer_resource(ContentFormat format) throws InterruptedException {
    // write resource
    long expectedvalue = 999l;
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(format, TEST_OBJECT_ID, 0, INTEGER_RESOURCE_ID, expectedvalue));

    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
            new ReadRequest(TEST_OBJECT_ID, 0, INTEGER_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertEquals(expectedvalue, resource.getValue());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:18,代码来源:WriteTest.java

示例14: write_float_resource

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private void write_float_resource(ContentFormat format) throws InterruptedException {
    // write resource
    double expectedvalue = 999.99;
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(format, TEST_OBJECT_ID, 0, FLOAT_RESOURCE_ID, expectedvalue));

    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
            new ReadRequest(TEST_OBJECT_ID, 0, FLOAT_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertEquals(expectedvalue, resource.getValue());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:18,代码来源:WriteTest.java

示例15: write_time_resource

import org.eclipse.leshan.core.node.LwM2mResource; //导入依赖的package包/类
private void write_time_resource(ContentFormat format) throws InterruptedException {
    // write resource
    Date expectedvalue = new Date(946681000l); // second accuracy
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(format, TEST_OBJECT_ID, 0, TIME_RESOURCE_ID, expectedvalue));

    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));

    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
            new ReadRequest(TEST_OBJECT_ID, 0, TIME_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertEquals(expectedvalue, resource.getValue());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:18,代码来源:WriteTest.java


注:本文中的org.eclipse.leshan.core.node.LwM2mResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。