int main() { printf("============== Before allocating blocks ==============\n"); display_mallinfo(); MbedClient mbed_client; 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); bool result = mbed_client.create_interface(); if(true == result) { printf("\nInterface created\n"); } result = mbed_client.create_bootstrap_object(); if(true == result) { printf("Bootstrap object created"); } result = mbed_client.create_register_object(); if(true == result) { printf("Register object created"); } result = mbed_client.create_device_object(); if(true == result) { printf("\nDevice object created !!\n"); } result = mbed_client.create_generic_object(); if(true == result) { printf("\nGeneric object created\n"); } // printf("Bootstrapping endpoint\n"); // mbed_client.test_bootstrap(); printf("Registering endpoint\n"); mbed_client.test_register(); pthread_create(&bootstrap_thread, NULL, &wait_for_bootstrap, (void*) &mbed_client); pthread_create(&observation_thread, NULL, &send_observation, (void*) &mbed_client); pthread_create(&unregister_thread, NULL, &wait_for_unregister, (void*) &mbed_client); pthread_join(bootstrap_thread, NULL); pthread_join(unregister_thread, NULL); pthread_join(observation_thread, NULL); printf("\n============== After freeing blocks ==============\n"); display_mallinfo(); exit(EXIT_SUCCESS); }
void app_start(int, char **) { // set the baud rate for output printing get_stdio_serial().baud(YOTTA_CFG_K64F_BORDER_ROUTER_BAUD); // set heap size and memory error handler for this application ns_dyn_mem_init(app_stack_heap, APP_DEFINED_HEAP_SIZE, app_heap_error_handler, 0); trace_init(); // set up the tracing library set_trace_print_function(trace_printer); set_trace_config(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_DEBUG | TRACE_CARRIAGE_RETURN); const char *mac_src = STR(YOTTA_CFG_K64F_BORDER_ROUTER_BACKHAUL_MAC_SRC); if (strcmp(mac_src, "BOARD") == 0) { /* Setting the MAC Address from UID (A yotta function) * Takes UID Mid low and UID low and shuffles them around. */ mbed_mac_address((char *)mac); } else if (strcmp(mac_src, "CONFIG") == 0) { /* MAC is defined by the user through yotta configuration */ const uint8_t mac48[] = YOTTA_CFG_K64F_BORDER_ROUTER_BACKHAUL_MAC; for (uint32_t i = 0; i < sizeof(mac); ++i) { mac[i] = mac48[i]; } } // run LED toggler in the Minar scheduler minar::Scheduler::postCallback(mbed::util::FunctionPointer0<void> (toggle_led1).bind()).period(minar::milliseconds(500)); tr_info("Starting K64F border router..."); border_router_start(); }
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); }
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 }