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; } }
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; }
/* * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver. * @param event, describes the sender, receiver and event type. * * NOTE: Interrupts requested by HW are possible during this function! */ void tasklet_main(arm_event_s *event) { uint8_t master_key[16]; /**Border Router ND setup*/ static link_configuration_s link_setup; device_configuration_s device_config; uint8_t networkid[16]; uint32_t channel_mask; channel_mask = (uint32_t) 1 << RF_CHANNEL; char psdK[] = "Kukkuu!"; device_config.PSKd_ptr = psdK; device_config.leaderCap = true; int8_t retval; if (event->sender == 0) { arm_library_event_type_e event_type; event_type = (arm_library_event_type_e) event->event_type; switch (event_type) { //This event is delivered every and each time when there is new information of network connectivity. case ARM_LIB_NWK_INTERFACE_EVENT: /* Network Event state event handler */ app_parse_network_event(event); break; case ARM_LIB_TASKLET_INIT_EVENT: /*Event with type EV_INIT is an initialiser event of NanoStack OS. * The event is delivered when the NanoStack OS is running fine. This event should be delivered ONLY ONCE. */ node_main_tasklet_id = event->receiver; /* Bootsrapping Thread network */ arm_nwk_interface_configure_6lowpan_bootstrap_set(net_rf_id, NET_6LOWPAN_ROUTER, NET_6LOWPAN_THREAD); arm_nwk_6lowpan_link_scan_paramameter_set(net_rf_id, channel_list, 5); rf_read_mac_address(link_setup.extended_random_mac); link_setup.extended_random_mac[0] |= 0x02; //Initialize Thread stack to leader mode link_setup.steering_data_len = 0; memcpy(networkid, "Arm Powered Core", 16); memcpy(link_setup.name, networkid, 16); link_setup.panId = THREAD_NTW_PAN_ID; link_setup.rfChannel = RF_CHANNEL; link_setup.Protocol_id = THREAD_PROTOCOL_ID; link_setup.version = THREAD_PROTOCOL_VERSION; memcpy(link_setup.mesh_local_ula_prefix,br_thread_ml_prefix, 8); arm_nwk_6lowpan_gp_address_mode(net_rf_id, NET_6LOWPAN_GP16_ADDRESS, 0xffff, 1); memcpy(master_key, default_net_security_key, 16); memcpy(link_setup.master_key,default_net_security_key, 16 ); link_setup.key_rotation = 3600; link_setup.key_sequence = 0; memcpy(link_setup.mesh_local_ula_prefix,br_thread_ml_prefix, 8); thread_managenet_node_init(net_rf_id, channel_mask, &device_config, &link_setup); retval = arm_nwk_interface_up(net_rf_id); if (retval != 0) { //debug_int(retval); tr_debug("Start Fail code: %d", retval); } else { tr_debug("6LoWPAN IP Bootstrap started"); network_ready(); } break; case ARM_LIB_SYSTEM_TIMER_EVENT: eventOS_event_timer_cancel(event->event_id, node_main_tasklet_id); if(event->event_id == 1) { if(arm_nwk_interface_up(net_rf_id) == 0) { tr_debug("Start Network bootstrap Again"); } } break; default: break; } } }