コード例 #1
0
ファイル: main.cpp プロジェクト: wotio/FRDMk64f-to-wotio-mds
    M2MObject* create_generic_object() {
        _object = M2MInterfaceFactory::create_object("Test");
        if(_object) {
            M2MObjectInstance* inst = _object->create_object_instance();
            if(inst) {
                    M2MResource* res = inst->create_dynamic_resource("D",
                                                                     "ResourceTest",
                                                                     M2MResourceInstance::INTEGER,
                                                                     true);
                    char buffer[20];
                    int size = sprintf(buffer,"%d",_value);
                    res->set_operation(M2MBase::GET_PUT_ALLOWED);
                    res->set_value((const uint8_t*)buffer,
                                   (const uint32_t)size);
                    _value++;

                    inst->create_static_resource("S",
                                                 "ResourceTest",
                                                 M2MResourceInstance::STRING,
                                                 STATIC_VALUE,
                                                 sizeof(STATIC_VALUE)-1);
            }
        }
        return _object;
    }
コード例 #2
0
ファイル: lwm2mtest.cpp プロジェクト: Blue-Design/mbed-client
bool M2MLWClient::create_static_resource_string(const char *name,
                                                const char *value,
                                                bool multiple_instance,
                                                uint16_t object_instance)
{
    bool success = false;
    String name_string;
    if(name) {
        name_string += name;
    }
    String value_string;
    if(value) {
        value_string += value;
    }
    if(_object) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            if(inst->create_static_resource(name,"resource",
                                            M2MResourceInstance::STRING,
                                            (const uint8_t*)value_string.c_str(),
                                            value_string.size()) != NULL) {
                success = true;
            }
        }
    }
    return success;
}
コード例 #3
0
ファイル: lwm2mtest.cpp プロジェクト: Blue-Design/mbed-client
bool M2MLWClient::create_static_resource_int(const char *name,
                                             int64_t value,
                                             bool multiple_instance,
                                             uint16_t object_instance)
{
    bool success = false;
    String name_string;
    String value_string;

    if(name) {
        name_string += name;
    }

    char value_buffer[20];
    sprintf(value_buffer,"%ld",value);
    value_string += value_buffer;

    if(_object) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            if(inst->create_static_resource(name,"resource",
                                            M2MResourceInstance::INTEGER,
                                            (const uint8_t*)value_string.c_str(),
                                            value_string.size()) != NULL) {
                success = true;
            }
        }
    }
    return success;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: Guokai19900920/mbed-client
    bool create_generic_object() {
        bool success = false;
        _object = M2MInterfaceFactory::create_object("10");
        if(_object) {
            _object->set_operation(M2MBase::GET_PUT_POST_ALLOWED);
            M2MObjectInstance* inst = _object->create_object_instance();
            if(inst) {
                inst->set_operation(M2MBase::GET_PUT_POST_ALLOWED);
                inst->set_observable(false);
                char buffer[20];
                int size = sprintf(buffer,"%d",_value);

                inst->create_static_resource("0",
                                             "ResourceTest",
                                             M2MResourceInstance::INTEGER,
                                             STATIC_VALUE,
                                             sizeof(STATIC_VALUE)-1);

                M2MResourceInstance* instance = inst->create_dynamic_resource_instance("1",
                                                "ResourceTest",
                                                M2MResourceInstance::INTEGER,
                                                true,0);

                if(instance) {
                    instance->set_operation(M2MBase::GET_PUT_POST_ALLOWED);
                    instance->set_value((const uint8_t*)buffer,
                                        (const uint32_t)size);
                    instance->set_execute_function(execute_callback(this,&MbedClient::execute_function));
                    _value++;
                }
            }
        }
        return success;
    }