Ejemplo n.º 1
2
void app_start(int, char**) {

	// setup the EthernetInterface
	eth.init();	// DHCP
	eth.connect();
	
	// initialize the ipv4 tcp/ip stack
	lwipv4_socket_init();

	// setup the M2MInterface
	srand(time(NULL));
	uint16_t port = rand() % 65535 + 12345;
	srv = M2MInterfaceFactory::create_interface(observer,endpoint,type,
		lifetime,port,domain,M2MInterface::UDP,M2MInterface::LwIP_IPv4,context_address);

	// setup the Security object		
	sec = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
	sec->set_resource_value(M2MSecurity::M2MServerUri,address);
	sec->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity);

	// setup the Device object
	dev = M2MInterfaceFactory::create_device();
	dev->create_resource(M2MDevice::Manufacturer,"Freescale");
	dev->create_resource(M2MDevice::DeviceType,"frdm-k64f");
	dev->create_resource(M2MDevice::ModelNumber,"M64FN1MOVLL12");
	dev->create_resource(M2MDevice::SerialNumber,"EB1524XXXX");

	// setup the sensor objects
	obj = M2MInterfaceFactory::create_object("loc");
	M2MObjectInstance* ins = obj->create_object_instance();
	M2MResource* resx = ins->create_dynamic_resource("x","accel",M2MResourceInstance::INTEGER,true);
	resx->set_operation(M2MBase::GET_PUT_ALLOWED);
	resx->set_value((const uint8_t*)"0",1);
	M2MResource* resy = ins->create_dynamic_resource("y","accel",M2MResourceInstance::INTEGER,true);
	resy->set_operation(M2MBase::GET_PUT_ALLOWED);
	resy->set_value((const uint8_t*)"0",1);

	
	// Assemble the list of objects to register
	M2MObjectList list;
	list.push_back(dev);
	list.push_back(obj);

	// setup registration event
	Ticker timer;
	timer.attach(&reg,&Registrar::update,20);

	// enable accelerometer
	printf("Initializied accelerometer\r\n");
	accel.enable();
	Ticker sampler;
	sampler.attach(sample,5);

	// schedule 
	FunctionPointer1<void, M2MObjectList> fp(&reg, &Registrar::setup);
	minar::Scheduler::postCallback(fp.bind(list));
	minar::Scheduler::postCallback(sample).period(minar::milliseconds(10000));
	minar::Scheduler::start();
}
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 3
0
 M2MObject* create_led_object() {
     _sdw_led_object = M2MInterfaceFactory::create_object("311");
     
     if (_sdw_led_object) {
         M2MObjectInstance* inst = _sdw_led_object->create_object_instance();
         if (inst) {
             M2MResource* res = inst->create_dynamic_resource("5850",
                                                              "LED",
                                                              M2MResourceInstance::STRING,
                                                              false);
             if (res) {
                 char buffer[10] = "";
                 memset(buffer,0,10);
                 strcpy(buffer,"0");
                 if (__led == 1) strcpy(buffer,"1");
                 
                 // set the value of the LED 
                 res->set_operation(M2MBase::GET_PUT_ALLOWED);   // we allow GET and PUT of the LED
                 res->set_value((const uint8_t*)buffer,
                                (const uint32_t)strlen(buffer));
             }
         }
     }
     return _sdw_led_object;
 }
Ejemplo n.º 4
0
bool M2MLWClient::create_dynamic_resource_int(const char *name,
                                          bool observable,
                                          bool multiple_instance,
                                          uint16_t object_instance,
                                          uint8_t resource_operation)
{
    bool success = false;
    String name_string;
    if(name) {
        name_string += name;
    }
    if(_object) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            M2MResource *res = inst->create_dynamic_resource(name,"resource",
                                                             M2MResourceInstance::INTEGER,
                                                             observable, multiple_instance);
            if(res) {
                success = true;
                res->set_operation(int_to_operation(resource_operation));
            }
        }
    }
    return success;
}
void Test_M2MInterfaceImpl::test_register_object()
{
    M2MSecurity *sec = new M2MSecurity(M2MSecurity::M2MServer);
    m2msecurity_stub::int_value = 2;

    M2MObject *object = new M2MObject("test");
    M2MObjectInstance *ins = object->create_object_instance();
    ins->create_dynamic_resource("test","type",M2MResourceInstance::STRING,false,false);

    M2MObjectList list;
    list.push_back(object);

    String *val = new String("coaps://[2001:12:12:23::23:FF]:5685");
    m2msecurity_stub::string_value = val;
    m2mnsdlinterface_stub::bool_value = true;
    m2mconnectionhandler_stub::bool_value = true;
    impl->register_object(sec,list);
    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER);

    impl->_register_ongoing = false;
    impl->_current_state = M2MInterfaceImpl::STATE_IDLE;
    impl->register_object(sec,list);
    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER);

    delete val;
    val = new String("coaps://[10.45.3.83:5685");
    impl->_register_ongoing = false;
    impl->_current_state = M2MInterfaceImpl::STATE_IDLE;
    m2msecurity_stub::string_value = val;
    m2mnsdlinterface_stub::bool_value = true;
    m2mconnectionhandler_stub::bool_value = true;

    delete impl->_security;
    impl->_security = NULL;
    sec = new M2MSecurity(M2MSecurity::M2MServer);
    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE);
    CHECK(observer->error_occured == true);
    observer->error_occured = false;
    delete val;
    val = new String("coaps://10.45.3.83]:5685");

    impl->_register_ongoing = false;
    impl->_current_state = M2MInterfaceImpl::STATE_IDLE;

    m2msecurity_stub::string_value = val;
    m2mnsdlinterface_stub::bool_value = true;
    m2mconnectionhandler_stub::bool_value = true;

    delete impl->_security;
    impl->_security = NULL;
    sec = new M2MSecurity(M2MSecurity::M2MServer);
    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE);
    CHECK(observer->error_occured == true);

    observer->error_occured = false;
    delete val;
    val = new String("coaps://10.45.3.83:5685");
    delete impl->_security;
    impl->_security = NULL;
    sec = new M2MSecurity(M2MSecurity::M2MServer);

    impl->_register_ongoing = false;
    impl->_current_state = M2MInterfaceImpl::STATE_IDLE;

    m2msecurity_stub::string_value = val;
    m2mnsdlinterface_stub::bool_value = true;
    m2mconnectionhandler_stub::bool_value = true;

    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER);

    observer->error_occured = false;
    delete val;
    val = new String("coap://10.45.3.83:5685");
    delete impl->_security;
    impl->_security = NULL;
    sec = new M2MSecurity(M2MSecurity::M2MServer);

    impl->_register_ongoing = false;
    impl->_current_state = M2MInterfaceImpl::STATE_IDLE;

    m2msecurity_stub::string_value = val;
    m2mnsdlinterface_stub::bool_value = true;
    m2mconnectionhandler_stub::bool_value = true;

    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER);

    delete val;
    val = new String("coap://10.45.3.83:5685");
    impl->register_object(sec,list);
    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_REGISTER);


    impl->_current_state =  M2MInterfaceImpl::STATE_IDLE;
    m2mconnectionhandler_stub::bool_value = true;
    m2mnsdlinterface_stub::bool_value = false;

    delete impl->_security;
    impl->_security = NULL;
    sec = new M2MSecurity(M2MSecurity::M2MServer);
    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE);
    CHECK(observer->error_occured == true);


    impl->_current_state =  M2MInterfaceImpl::STATE_IDLE;
    m2mconnectionhandler_stub::bool_value = false;
    m2mnsdlinterface_stub::bool_value = true;

    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE);
    CHECK(observer->error_occured == true);


    impl->_register_ongoing = false;
    impl->_current_state =  M2MInterfaceImpl::STATE_BOOTSTRAP;
    m2mconnectionhandler_stub::bool_value = true;
    m2mnsdlinterface_stub::bool_value = true;

    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_BOOTSTRAP);
    CHECK(observer->error_occured == true);

    impl->_current_state =  M2MInterfaceImpl::STATE_IDLE;
    m2mconnectionhandler_stub::bool_value = true;
    m2mnsdlinterface_stub::bool_value = true;

    impl->register_object(sec,list);

    CHECK(impl->_current_state == M2MInterfaceImpl::STATE_IDLE);
    CHECK(observer->error_occured == true);

    impl->_current_state =  M2MInterfaceImpl::STATE_BOOTSTRAP;
    m2mconnectionhandler_stub::bool_value = true;
    m2mnsdlinterface_stub::bool_value = true;

    impl->register_object(sec,list);

    CHECK(observer->error_occured == true);


    delete val;
    val = NULL;

    list.clear();
    delete object;
    delete sec;
}