Ejemplo n.º 1
0
void Test_M2MResource::test_execute_params()
{
    M2MResource::M2MExecuteParameter *params = new M2MResource::M2MExecuteParameter();
    CHECK(params->get_argument_value() == NULL);
    CHECK(params->get_argument_value_length() == 0);
    CHECK(params->get_argument_object_name() == "");
    CHECK(params->get_argument_resource_name() == "");
    CHECK(params->get_argument_object_instance_id() == 0);

    uint8_t value[] = {"test"};
    int length = sizeof(value);
    params->_value = (uint8_t*)malloc(length);
    memcpy(params->_value,value,length);
    params->_value_length = length;
    params->_object_name = "object";
    params->_resource_name = "resource";
    params->_object_instance_id = 0;
    CHECK(params->_value == params->get_argument_value());
    CHECK(params->_value_length == params->get_argument_value_length());
    CHECK(params->_resource_name == params->get_argument_resource_name());
    CHECK(params->_object_name == params->get_argument_object_name());
    CHECK(params->_object_instance_id == params->get_argument_object_instance_id());

    delete params;
}
Ejemplo n.º 2
0
void Test_M2MResource::test_execute_params()
{
    M2MResource::M2MExecuteParameter *params = new M2MResource::M2MExecuteParameter();
    CHECK(params->get_argument_value() == NULL);
    CHECK( params->get_argument_value_length() == 0);

    uint8_t value[] = {"test"};
    int length = sizeof(value);
    params->_value = (uint8_t*)malloc(length);
    memcpy(params->_value,value,length);
    params->_value_length = length;

    CHECK(params->_value == params->get_argument_value());
    CHECK(params->_value_length == params->get_argument_value_length());

    delete params;
}
Ejemplo n.º 3
0
    void blink(void *argument) {
        // read the value of 'Pattern'
        status_ticker.detach();
        green_led = LED_OFF;

        M2MObjectInstance* inst = led_object->object_instance();
        M2MResource* res = inst->resource("5853");
        // Clear previous blink data
        blink_args->clear();

        // values in mbed Client are all buffers, and we need a vector of int's
        uint8_t* buffIn = NULL;
        uint32_t sizeIn;
        res->get_value(buffIn, sizeIn);

        // turn the buffer into a string, and initialize a vector<int> on the heap
        std::string s((char*)buffIn, sizeIn);
        free(buffIn);
        printf("led_execute_callback pattern=%s\n", s.c_str());

        // our pattern is something like 500:200:500, so parse that
        std::size_t found = s.find_first_of(":");
        while (found!=std::string::npos) {
            blink_args->blink_pattern.push_back(atoi((const char*)s.substr(0,found).c_str()));
            s = s.substr(found+1);
            found=s.find_first_of(":");
            if(found == std::string::npos) {
                blink_args->blink_pattern.push_back(atoi((const char*)s.c_str()));
            }
        }
        // check if POST contains payload
        if (argument) {
            M2MResource::M2MExecuteParameter* param = (M2MResource::M2MExecuteParameter*)argument;
            String object_name = param->get_argument_object_name();
            uint16_t object_instance_id = param->get_argument_object_instance_id();
            String resource_name = param->get_argument_resource_name();
            int payload_length = param->get_argument_value_length();
            uint8_t* payload = param->get_argument_value();
            printf("Resource: %s/%d/%s executed\n", object_name.c_str(), object_instance_id, resource_name.c_str());
            printf("Payload: %.*s\n", payload_length, payload);
        }
        // do_blink is called with the vector, and starting at -1
        blinky_thread.start(callback(this, &LedResource::do_blink));
    }