/******************************************************************************* * Function Name : main. * Description : main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void app_setup_and_loop(void) { system_part2_post_init(); HAL_Core_Init(); // We have running firmware, otherwise we wouldn't have gotten here DECLARE_SYS_HEALTH(ENTERED_Main); PMIC().begin(); FuelGauge().wakeup(); DEBUG("Hello from Particle!"); String s = spark_deviceID(); INFO("Device %s started", s.c_str()); manage_safe_mode(); #if defined (START_DFU_FLASHER_SERIAL_SPEED) || defined (START_YMODEM_FLASHER_SERIAL_SPEED) USB_USART_LineCoding_BitRate_Handler(system_lineCodingBitRateHandler); #endif bool threaded = system_thread_get_state(NULL) != spark::feature::DISABLED && (system_mode()!=SAFE_MODE); Network_Setup(threaded); #if PLATFORM_THREADING if (threaded) { SystemThread.start(); ApplicationThread.start(); } else { SystemThread.setCurrentThread(); ApplicationThread.setCurrentThread(); } #endif if(!threaded) { /* Main loop */ while (1) { app_loop(false); } } }
template<typename Config> void SystemSetupConsole<Config>::handle(char c) { if ('i' == c) { // see if we have any additional properties. This is true // for Cellular and Mesh devices. hal_system_info_t info = {}; info.size = sizeof(info); HAL_OTA_Add_System_Info(&info, true, nullptr); LOG(TRACE, "device info key/value count: %d", info.key_value_count); if (info.key_value_count) { print("Device ID: "); String id = spark_deviceID(); print(id.c_str()); print("\r\n"); for (int i=0; i<info.key_value_count; i++) { char key[20]; if (!filter_key(info.key_values[i].key, key, sizeof(key))) { print(key); print(": "); print(info.key_values[i].value); print("\r\n"); } } } else { #if PLATFORM_ID<3 print("Your core id is "); #else print("Your device id is "); #endif String id = spark_deviceID(); print(id.c_str()); print("\r\n"); } HAL_OTA_Add_System_Info(&info, false, nullptr); } else if ('m' == c) { print("Your device MAC address is\r\n"); IPConfig config = {}; #if !HAL_PLATFORM_WIFI auto conf = static_cast<const IPConfig*>(network_config(0, 0, 0)); #else auto conf = static_cast<const IPConfig*>(network_config(NETWORK_INTERFACE_WIFI_STA, 0, 0)); #endif if (conf && conf->size) { memcpy(&config, conf, std::min(sizeof(config), (size_t)conf->size)); } const uint8_t* addr = config.nw.uaMacAddr; print(bytes2hex(addr++, 1).c_str()); for (int i = 1; i < 6; i++) { print(":"); print(bytes2hex(addr++, 1).c_str()); } print("\r\n"); } else if ('f' == c) { serial.println("Waiting for the binary file to be sent ... (press 'a' to abort)"); system_firmwareUpdate(&serial); } else if ('x' == c) { exit(); } else if ('s' == c) { auto prefix = "{"; auto suffix = "}\r\n"; WrappedStreamAppender appender(serial, (const uint8_t*)prefix, strlen(prefix), (const uint8_t*)suffix, strlen(suffix)); system_module_info(append_instance, &appender); } else if ('v' == c) { StreamAppender appender(serial); append_system_version_info(&appender); print("\r\n"); } else if ('L' == c) { system_set_flag(SYSTEM_FLAG_STARTUP_LISTEN_MODE, 1, nullptr); System.enterSafeMode(); } else if ('c' == c) { bool claimed = HAL_IsDeviceClaimed(nullptr); print("Device claimed: "); print(claimed ? "yes" : "no"); print("\r\n"); } else if ('C' == c) { char code[64]; print("Enter 63-digit claim code: "); read_line(code, 63); if (strlen(code)==63) { HAL_Set_Claim_Code(code); print("Claim code set to: "); print(code); } else { print("Sorry, claim code is not 63 characters long. Claim code unchanged."); } print("\r\n"); } else if ('d' == c) { system_format_diag_data(nullptr, 0, 0, StreamAppender::append, &serial, nullptr); print("\r\n"); } }