OSStatus micokit_ext_init(void) { OSStatus err = kUnknownErr; err = user_modules_init(); return err; }
/* user main function, called by AppFramework after FogCloud connected. */ OSStatus user_main( mico_Context_t * const mico_context ) { user_log_trace(); OSStatus err = kUnknownErr; /* init user modules (pins && sensor init)*/ err = user_modules_init(); require_noerr_action( err, exit, user_log("ERROR: user_modules_init err=%d.", err) ); /* recovery user settings from flash && set initail state of user modules */ //err = user_settings_recovery(mico_context, &g_user_context); //require_noerr_action( err, exit, user_log("ERROR: user_settings_recovery err=%d.", err) ); #if (MICO_CLOUD_TYPE != CLOUD_DISABLED) /* start properties notify task */ err = mico_start_properties_notify(mico_context, service_table, MICO_PROPERTIES_NOTIFY_INTERVAL_MS, STACK_SIZE_NOTIFY_THREAD); require_noerr_action( err, exit, user_log("ERROR: mico_start_properties_notify err = %d.", err) ); #endif while(1){ /* user thread running state */ user_display(&g_user_context); user_test(&g_user_context); /* check every 1 seconds */ mico_thread_msleep(1000); /* save user settings into flash */ //err = user_settings_update(mico_context, &g_user_context); //require_noerr_action( err, exit, user_log("ERROR: user_settings_update err=%d.", err) ); } exit: user_log("ERROR: user_main exit with err=%d", err); return err; }
void acaUartInterface_thread(void *inContext) { client_log_trace(); OSStatus err = kUnknownErr; arrayent_net_status_t arg; arrayent_return_e ret; //int8_t retry = 0; uint16_t len = 0; static char property[150]; mico_rtos_init_semaphore(&_wifiConnected_sem, 1);//初始化信号量 /* Regisist notifications */ err = mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void *)notify_WifiStatusHandler, (void *)inContext);//??? require_noerr( err, exit ); while(_wifiConnected == false){//after few time connected wifi success.??? mico_rtos_get_semaphore(&_wifiConnected_sem, 200000); client_log("Waiting for Wi-Fi network..."); mico_thread_sleep(1); } user_modules_init(); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, "Arrayent "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Connecting... "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " "); configureArrayent(inContext); //Initialize Arrayent stack client_log("Initializing Arrayent daemon..."); ret = ArrayentInit(); if(ret != ARRAYENT_SUCCESS) { client_log("Failed to initialize Arrayent daemon.%d", ret); return; } client_log("Arrayent daemon successfully initialized!"); //Wait for Arrayent to finish connecting to the server do { ret = ArrayentNetStatus(&arg);//get connecting status to server if(ret != ARRAYENT_SUCCESS) { client_log("Failed to connect to Arrayent network."); } client_log("Waiting for good network status."); mico_thread_sleep(1); } while(!(arg.connected_to_server));//after few time connected server success. client_log("Connected to Arrayent network!\r\n"); _connection_lost = false; OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, "Connected "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Arrayent! "); OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " "); ArrayentSetProperty("DC","0"); mico_thread_msleep(200); ArrayentSetProperty("RGB","off"); err = mico_rtos_create_thread(NULL, MICO_DEFAULT_LIBRARY_PRIORITY, "update", update_property, STACK_SIZE_UART_RECV_THREAD, (void*)inContext); require_noerr_action( err, exit, client_log("ERROR: Unable to start the update_property thread.") ); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "except", except_handle, STACK_SIZE_UART_RECV_THREAD, (void*)inContext); require_noerr_action( err, exit, client_log("ERROR: Unable to start the except_handle thread.") ); while(1) { //sure wifi connected. if(_wifiConnected == false){ mico_rtos_get_semaphore(&_wifiConnected_sem, 200000); continue; } //sure server connected. if(_connection_lost && _wifiConnected){ do { ret = ArrayentNetStatus(&arg);//get connecting status to server if(ret != ARRAYENT_SUCCESS) { client_log("Failed to connect to Arrayent network."); } client_log("Waiting for good network status."); mico_thread_sleep(1); } while(!(arg.connected_to_server)); _connection_lost = false; } len = sizeof(property); if(ARRAYENT_SUCCESS==ArrayentRecvProperty(property,&len,10000)){//receive property data from server client_log("property = %s\n\r",property); if(0!=checkCmd(property, inContext)){//parse cmd success //_response = false; //retry = 1; client_log("%s", property); } } } exit: client_log("Exit: ACA App exit with err = %d", err); mico_rtos_delete_thread(NULL); return; }