コード例 #1
0
void app_start(int, char **)
{
	pc.baud(115200);  //Setting the Baud-Rate for trace output
    printf("Start mbed-client-example-6lowpan\r\n");

    // Instantiate the class which implements
    // LWM2M Client API
    mbedclient = new MbedClient();
    obs_button = new InterruptIn(OBS_BUTTON);
    unreg_button = new InterruptIn(UNREG_BUTTON);

    // This sets up the network interface configuration which will be used
    // by LWM2M Client API to communicate with mbed Device server.
    AbstractMesh *mesh_api;
    int8_t status;
#ifdef APPL_BOOTSTRAP_MODE_THREAD
    mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD);
    uint8_t eui64[8];
    int8_t rf_device_id = rf_device_register();
    // Read mac address after registering the device.
    rf_read_mac_address(&eui64[0]);
    char *pskd = (char *)"Secret password";
    status = ((MeshThread *)mesh_api)->init(rf_device_id, AbstractMesh::mesh_network_handler_t(mbedclient, &MbedClient::mesh_network_handler), eui64, pskd);
#else /* APPL_BOOTSTRAP_MODE_THREAD */
    mesh_api = (Mesh6LoWPAN_ND *)MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND);
    status = ((Mesh6LoWPAN_ND *)mesh_api)->init(rf_device_register(), AbstractMesh::mesh_network_handler_t(mbedclient, &MbedClient::mesh_network_handler));
#endif /* APPL_BOOTSTRAP_MODE */

    if (status != MESH_ERROR_NONE) {
        printf("Mesh network initialization failed %d!\r\n", status);
        return;
    }

    // Set up Hardware interrupt button.
    // On press of SW3 button on K64F board, example application
    // will call unregister API towards mbed Device Server
    unreg_button->fall(mbedclient, &MbedClient::test_unregister);

    // On press of SW2 button on K64F board, example application
    // will send observation towards mbed Device Server
    obs_button->fall(mbedclient, &MbedClient::update_resource);

    status = mesh_api->connect();
    if (status != MESH_ERROR_NONE) {
        printf("Can't connect to mesh network!\r\n");
        return;
    }
}
コード例 #2
0
int MeshInterfaceNanostack::register_rf()
{
    nanostack_lock();

    rf_device_id = rf_device_register();
    if (rf_device_id < 0) {
        nanostack_unlock();
        return -1;
    }
    // Read mac address after registering the device.
    rf_read_mac_address(eui64);
    sprintf(mac_addr_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]);

    nanostack_unlock();

    return 0;
}
コード例 #3
0
void app_start(int, char **)
{
	char if_desciption[] = "6LoWPAN_NODE";

	pc.baud(115200);  //Setting the Baud-Rate for trace output
    ns_dyn_mem_init(app_stack_heap, APP_DEFINED_HEAP_SIZE, app_heap_error_handler,0);
    randLIB_seed_random();
    platform_timer_enable();
    eventOS_scheduler_init();
    trace_init();
	set_trace_print_function( trace_printer );
    set_trace_config(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_CARRIAGE_RETURN);
	tr_debug("M \r\n");
    net_init_core();
    rf_phy_device_register_id = rf_device_register();
    net_rf_id = arm_nwk_interface_init(NET_INTERFACE_RF_6LOWPAN, rf_phy_device_register_id, if_desciption);
    eventOS_event_handler_create(&tasklet_main, ARM_LIB_TASKLET_INIT_EVENT);
}
コード例 #4
0
int8_t NanostackRfPhyEfr32::rf_register()
{

    rf_if_lock();

    if (rf != NULL) {
        rf_if_unlock();
        error("Multiple registrations of NanostackRfPhyEfr32 not supported");
        return -1;
    }

    int8_t radio_id = rf_device_register();
    if (radio_id < 0) {
        rf = NULL;
    } else {
        rf = this;
    }

    rf_if_unlock();
    return radio_id;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: peknis01/mbed-mesh-api-1
void app_start(int, char **)
{
    MBED_HOSTTEST_TIMEOUT(5);
    MBED_HOSTTEST_SELECT(default);
    MBED_HOSTTEST_DESCRIPTION(Mesh network API tests);
    MBED_HOSTTEST_START("mbed-mesh-api");

    // set tracing baud rate
    static Serial pc(USBTX, USBRX);
    pc.baud(115200);

    // before registering RF device mesh network needs to be created
    Mesh6LoWPAN_ND *mesh_api = (Mesh6LoWPAN_ND *)MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND);
    delete mesh_api;
    rf_device_id = rf_device_register();

    testMeshApi = new TestMeshApi;

    FunctionPointer0<void> fp(testMeshApi, &TestMeshApi::runTests);
    minar::Scheduler::postCallback(fp.bind());
}
コード例 #6
0
ファイル: main.cpp プロジェクト: GoodDada/mbed-client
void app_start(int /*argc*/, char* /*argv*/[]) {
#else
int main() {
#endif

    // Instantiate the class which implements
    // mbed Client API
    MbedClient mbed_client;

#ifdef TARGET_LIKE_LINUX
    pthread_t unregister_thread;
    pthread_t observation_thread;

    m2mclient = &mbed_client;

    trace_init();
    set_trace_print_function( trace_printer );
    set_trace_config(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_DEBUG|TRACE_CARRIAGE_RETURN);

    signal(SIGINT, (signalhandler_t)ctrl_c_handle_function);

#else
    // This sets up the network interface configuration which will be used
    // by LWM2M Client API to communicate with mbed Device server.

#ifdef SIXLOWPAN_INTERFACE

    Mesh6LoWPAN_ND *mesh_api = Mesh6LoWPAN_ND::getInstance();
    int8_t status;

    status = mesh_api->init(rf_device_register(), mesh_network_callback);
    if (status != MESH_ERROR_NONE)
    {
        tr_error("Mesh network initialization failed %d!", status);
        return 1;
    }

    status = mesh_api->connect();
    if (status != MESH_ERROR_NONE)
    {
        tr_error("Can't connect to mesh network!");
        return 1;
    }

    do
    {
        mesh_api->processEvent();
    } while(mesh_network_state != MESH_CONNECTED);


#else
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();

    lwipv4_socket_init();
#endif

    // Set up Hardware interrupt button.
    InterruptIn obs_button(OBS_BUTTON);
    InterruptIn unreg_button(UNREG_BUTTON);

    // On press of SW3 button on K64F board, example application
    // will call unregister API towards mbed Device Server
    unreg_button.fall(&mbed_client,&MbedClient::test_unregister);

    // On press of SW2 button on K64F board, example application
    // will send observation towards mbed Device Server
    obs_button.fall(&mbed_client,&MbedClient::update_resource);


#endif

    // Create LWM2M Client API interface to manage bootstrap,
    // register and unregister

    //These 2 are defining the secure connection usage
    M2MSecurity::SecurityModeType mode = M2MSecurity::NoSecurity;
    _have_secure_conn = (mode == M2MSecurity::Certificate || mode == M2MSecurity::Psk);
    //    SecurityNotSet,
    //    Psk = 0,
    //    Certificate = 2,
    //    NoSecurity = 3

    mbed_client.create_interface();

#ifdef TARGET_LIKE_LINUX

#if defined (BOOTSTRAP_ENABLED)
    pthread_t bootstrap_thread;
    // Create LWM2M bootstrap object specifying bootstrap server
    // information.
    M2MSecurity* security_object = mbed_client.create_bootstrap_object(_have_secure_conn);
    // Issue bootstrap command.
    mbed_client.test_bootstrap(security_object);

    pthread_create(&bootstrap_thread, NULL, &wait_for_bootstrap, (void*) &mbed_client);
    pthread_join(bootstrap_thread, NULL);

#else
    M2MSecurity *register_object = mbed_client.create_register_object(_have_secure_conn);

    if( mode == M2MSecurity::Certificate ){
        register_object->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
        register_object->set_resource_value(M2MSecurity::ServerPublicKey,server_cert,server_cert_len);
        register_object->set_resource_value(M2MSecurity::PublicKey,cert,cert_len);
        register_object->set_resource_value(M2MSecurity::Secretkey,key,key_len);
    }else if( mode == M2MSecurity::Psk ){
        register_object->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Psk);
        register_object->set_resource_value(M2MSecurity::ServerPublicKey,psk_identity,psk_identity_len);
        register_object->set_resource_value(M2MSecurity::PublicKey,psk_identity,psk_identity_len);
        register_object->set_resource_value(M2MSecurity::Secretkey,psk,psk_len);
    }else{
        register_object->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity);
    }

    mbed_client.set_register_object(register_object);
    M2MDevice* device_object = mbed_client.create_device_object();

    M2MObject* object = mbed_client.create_generic_object();

    M2MObjectList object_list;
    object_list.push_back(device_object);
    object_list.push_back(object);

    mbed_client.test_register(object_list);
#endif

    pthread_create(&observation_thread, NULL, &send_observation, (void*) &mbed_client);
    pthread_create(&unregister_thread, NULL, &wait_for_unregister, (void*) &mbed_client);
    pthread_join(unregister_thread, NULL);

#else

#if defined (BOOTSTRAP_ENABLED)
    // Create LWM2M bootstrap object specifying bootstrap server
    // information.
    M2MSecurity* security_object = mbed_client.create_bootstrap_object(_have_secure_conn);

    // Issue bootstrap command.
    mbed_client.test_bootstrap(security_object);

    // Wait till the bootstrap callback is called successfully.
    // Callback comes in bootstrap_done()
#ifdef SIXLOWPAN_INTERFACE
    /* wait network to be established */
    do {
        mesh_interface_run();
    } while(!mbed_client.bootstrap_successful());
#else
    while (!mbed_client.bootstrap_successful()) { __WFI(); }
#endif

#else

    M2MSecurity *register_object = mbed_client.create_register_object(_have_secure_conn);

    if( mode == M2MSecurity::Certificate ){
        register_object->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
        register_object->set_resource_value(M2MSecurity::ServerPublicKey,server_cert,server_cert_len);
        register_object->set_resource_value(M2MSecurity::PublicKey,cert,cert_len);
        register_object->set_resource_value(M2MSecurity::Secretkey,key,key_len);
    }else if( mode == M2MSecurity::Psk ){
        register_object->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Psk);
        register_object->set_resource_value(M2MSecurity::ServerPublicKey,psk_identity,psk_identity_len);
        register_object->set_resource_value(M2MSecurity::PublicKey,psk_identity,psk_identity_len);
        register_object->set_resource_value(M2MSecurity::Secretkey,psk,psk_len);
    }else{
        register_object->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity);
    }

    mbed_client.set_register_object(register_object);

#endif

    // Create LWM2M device object specifying device resources
    // as per OMA LWM2M specification.
    M2MDevice* device_object = mbed_client.create_device_object();

    M2MObject* object = mbed_client.create_generic_object();

    // Add all the objects that you would like to register
    // into the list and pass the list for register API.
    M2MObjectList object_list;
    object_list.push_back(device_object);
    object_list.push_back(object);

    // Issue register command.

    FunctionPointer1<void, M2MObjectList> fp(&mbed_client, &MbedClient::test_register);
    minar::Scheduler::postCallback(fp.bind(object_list));

    minar::Scheduler::start();

    // Wait till the register callback is called successfully.
    // Callback comes in object_registered()
#ifdef SIXLOWPAN_INTERFACE
    /* wait network to be established */
    do {
        mesh_api->processEvent();
    } while(!mbed_client.register_successful());
#endif

    // Wait for the unregister successful callback,
    // Callback comes in object_unregsitered(), this will be
    // waiting for user to press SW2 button on K64F board.
#ifdef SIXLOWPAN_INTERFACE
    /* wait network to be established */
    do {
        mesh_api->processEvent();
    } while(!mbed_client.unregister_successful());
#endif


#if defined(BOOTSTRAP_ENABLED)
    // This will turn on the LED on the board specifying that
    // the application has run successfully.
    notify_completion(mbed_client.unregister_successful() &&
                      mbed_client.register_successful() &&
                      mbed_client.bootstrap_successful());

    // Delete security object created for bootstrapping
    if(security_object) {
        delete security_object;
    }

#else

    // Disconnect the connect and teardown the network interface
#ifdef SIXLOWPAN_INTERFACE
    mesh_api->disconnect();
#else
    eth.disconnect();
#endif
#endif //BOOTSTRAP_ENABLED

    // Delete device object created for registering device
    // resources.
    if(device_object) {
        M2MDevice::delete_instance();
    }
    if(object) {
        delete object;
    }

#endif //TARGET_LIKE_LINUX

#ifndef TARGET_LIKE_MBED
return 0;
#endif
}