Exemplo n.º 1
0
bool M2MLWClient::create_dynamic_resource_instance_string(const char *name,
                                                   bool observable,
                                                   bool multiple_instance,
                                                   uint16_t object_instance,
                                                   uint16_t resource_instance,
                                                   uint8_t resource_instance_operation)
{
    bool success = false;
    String name_string;
    if(name) {
        name_string += name;
    }
    if(_object) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            M2MResourceInstance *res = inst->create_dynamic_resource_instance(name,"resource",
                                                                      M2MResourceInstance::STRING,
                                                                      observable,
                                                                      resource_instance);
            if( res) {
                success = true;
                res->set_operation(int_to_operation(resource_instance_operation));
            }
        }
    }
    return success;
}
Exemplo n.º 2
0
    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;
    }