Beispiel #1
0
bool M2MLWClient::set_resource_instance_value(const char *name,
                                              const char *value,
                                              uint16_t object_instance,
                                              uint16_t resource_instance)
{
    bool success = false;
    String name_string;
    String value_string;
    if(name) {
        name_string += name;
    }
    if(value) {
        value_string += value;
    }

    if(_object && name_string.length() > 0) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            M2MResource *res = inst->resource(name_string);
            if (res) {
                M2MResourceInstance *res_inst = res->resource_instance(resource_instance);
                if(res_inst) {
                    if (res_inst->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
                        success = true;
                    }
                }
            }
        }
    }
    return success;
}
Beispiel #2
0
M2MResourceInstance* M2MDevice::get_resource_instance(DeviceResource dev_res,
                                                      uint16_t instance_id) const
{
    M2MResource* res = NULL;
    M2MResourceInstance* inst = NULL;
    if(_device_instance) {
        res = _device_instance->resource(resource_name(dev_res));
        if(res) {
            if(res->supports_multiple_instances()) {
               inst = res->resource_instance(instance_id);
            } else {
                inst = res;
            }
        }
    }
    return inst;
}
Beispiel #3
0
 void update_resource() {
     if(_object) {
         M2MObjectInstance* inst = _object->object_instance();
         if(inst) {
             M2MResource* res = inst->resource("1");
             res = inst->resource("1");
             if(res) {
                 M2MResourceInstance *res_inst = res->resource_instance(0);
                 if(res_inst) {
                     char buffer1[20];
                     int size1 = sprintf(buffer1,"%d",_value);
                     res_inst->set_value((const uint8_t*)buffer1,
                                         (const uint32_t)size1);
                     _value++;
                 }
             }
         }
     }
 }