OSStatus MICOStartApplication( mico_Context_t * const inContext ) { app_log_trace(); OSStatus err = kNoErr; require_action(inContext, exit, err = kParamErr); haProtocolInit(inContext); PlatformUartInitialize(inContext); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, 0x500, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") ); if(inContext->flashContentInRam.appConfig.localServerEnable == true){ err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, 0x200, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") ); } if(inContext->flashContentInRam.appConfig.remoteServerEnable == true){ err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, 0x500, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") ); } exit: return err; }
OSStatus MICOStartApplication( mico_Context_t * const inContext ) { app_log_trace(); OSStatus err = kNoErr; require_action(inContext, exit, err = kParamErr); inContext->appStatus.statusNumber = 0x01; #ifdef MICO_I2C_CP if( MicoMFiAuthInitialize( MICO_I2C_CP ) == kNoErr ) inContext->appStatus.useMFiAuth = true; else #endif inContext->appStatus.useMFiAuth = false; /*Bonjour for service searching*/ if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true) MICOStartBonjourService( Station, inContext ); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "HomeKit Server", homeKitListener_thread, 0x500, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the Homekit thread.") ); exit: return err; }
int application_start(void) { app_log_trace(); OSStatus err = kNoErr; mico_uart_config_t uart_config; app_context_t* app_context; mico_Context_t* mico_context; /* Create application context */ app_context = ( app_context_t *)calloc(1, sizeof(app_context_t) ); require_action( app_context, exit, err = kNoMemoryErr ); /* Create mico system context and read application's config data from flash */ mico_context = mico_system_context_init( sizeof( application_config_t) ); app_context->appConfig = mico_system_context_get_user_data( mico_context ); /* mico system initialize */ err = mico_system_init( mico_context ); require_noerr( err, exit ); /* Bonjour for service searching */ MICOStartBonjourService( Station, app_context ); /* Protocol initialize */ sppProtocolInit( app_context ); /*UART receive thread*/ uart_config.baud_rate = app_context->appConfig->USART_BaudRate; uart_config.data_width = DATA_WIDTH_8BIT; uart_config.parity = NO_PARITY; uart_config.stop_bits = STOP_BITS_1; uart_config.flow_control = FLOW_CONTROL_DISABLED; if(mico_context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true) uart_config.flags = UART_WAKEUP_ENABLE; else uart_config.flags = UART_WAKEUP_DISABLE; ring_buffer_init ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH ); MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer ); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_UART_RECV_THREAD, (void*)app_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") ); /* Local TCP server thread */ if(app_context->appConfig->localServerEnable == true) { err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, STACK_SIZE_LOCAL_TCP_SERVER_THREAD, (void*)app_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") ); } /* Remote TCP client thread */ if(app_context->appConfig->remoteServerEnable == true) { err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)app_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") ); } exit: mico_rtos_delete_thread(NULL); return err; }
/* MICO APP entrance */ OSStatus MICOStartApplication( mico_Context_t * const mico_context ) { app_log_trace(); OSStatus err = kNoErr; require_action(mico_context, exit, err = kParamErr); // LED on when Wi-Fi connected. MicoSysLed(false); /* Bonjour for service searching */ if(mico_context->flashContentInRam.micoSystemConfig.bonjourEnable == true) { MICOStartBonjourService( Station, mico_context ); } /* start cloud service */ #if (MICO_CLOUD_TYPE == CLOUD_FOGCLOUD) err = MicoStartFogCloudService( mico_context ); app_log("MICO CloudService: FogCloud."); require_noerr_action( err, exit, app_log("ERROR: Unable to start FogCloud service.") ); #elif (MICO_CLOUD_TYPE == CLOUD_ALINK) app_log("MICO CloudService: Alink."); #elif (MICO_CLOUD_TYPE == CLOUD_DISABLED) app_log("MICO CloudService: disabled."); #else #error "MICO cloud service type is not defined"? #endif /* start user thread */ err = startUserMainThread( mico_context ); require_noerr_action( err, exit, app_log("ERROR: start user_main thread failed!") ); exit: return err; }
/* MICO system callback: Restore default configuration provided by application */ void appRestoreDefault_callback(void * const user_config_data, uint32_t size) { app_log_trace(); UNUSED_PARAMETER(size); application_config_t* appConfig = user_config_data; appConfig->configDataVer = CONFIGURATION_VERSION; appConfig->bonjourServicePort = BONJOUR_SERVICE_PORT; }
/* MICO APP entrance */ OSStatus MICOStartApplication( mico_Context_t * const mico_context ) { app_log_trace(); OSStatus err = kNoErr; LinkStatusTypeDef wifi_link_status; require_action(mico_context, exit, err = kParamErr); app_log("Application version: %s", mico_context->flashContentInRam.appConfig.fogcloudConfig.romVersion); // LED on when Wi-Fi connected. MicoSysLed(false); // init application wifi link status do{ err = micoWlanGetLinkStatus(&wifi_link_status); if(kNoErr != err){ mico_thread_sleep(3); } }while(kNoErr != err); if(1 == wifi_link_status.is_connected){ mico_context->appStatus.isWifiConnected = true; } else{ mico_context->appStatus.isWifiConnected = false; } /* Bonjour for service searching */ if(mico_context->flashContentInRam.micoSystemConfig.bonjourEnable == true) { MICOStartBonjourService( Station, mico_context ); } /* start cloud service */ #if (MICO_CLOUD_TYPE == CLOUD_FOGCLOUD) app_log("MICO CloudService: FogCloud."); err = MicoStartFogCloudService( mico_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start FogCloud service.") ); #elif (MICO_CLOUD_TYPE == CLOUD_ALINK) app_log("MICO CloudService: Alink."); #elif (MICO_CLOUD_TYPE == CLOUD_DISABLED) app_log("MICO CloudService: disabled."); #else #error "MICO cloud service type is not defined"? #endif /* start user thread */ err = startUserMainThread( mico_context ); require_noerr_action( err, exit, app_log("ERROR: start user_main thread failed!") ); exit: return err; }
OSStatus startUserMainThread(mico_Context_t *mico_context) { app_log_trace(); OSStatus err = kNoErr; require_action(mico_context, exit, err = kParamErr); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "user_main", user_main_thread, STACK_SIZE_USER_MAIN_THREAD, mico_context ); exit: return err; }
/* user main thread created by MICO APP thread */ void user_main_thread(void* arg) { app_log_trace(); OSStatus err = kUnknownErr; app_context_t *app_context = (app_context_t *)arg; // loop in user mian function && must not return err = user_main(app_context); // never get here only if user work error. app_log("ERROR: user_main thread exit err=%d, system will reboot...", err); err = mico_system_power_perform(app_context->mico_context, eState_Software_Reset); UNUSED_PARAMETER(err); mico_rtos_delete_thread(NULL); }
OSStatus MICOStartApplication( mico_Context_t * const inContext ) { app_log_trace(); OSStatus err = kNoErr; require_action(inContext, exit, err = kParamErr); /*Bonjour for service searching*/ if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true) MICOStartBonjourService( Station, inContext ); /* start virtual device */ err = MVDInit(inContext); require_noerr_action( err, exit, app_log("ERROR: virtual device start failed!") ); exit: return err; }
OSStatus MICOStartApplication( mico_Context_t * const inContext ) { app_log_trace(); OSStatus err = kNoErr; mico_uart_config_t uart_config; require_action(inContext, exit, err = kParamErr); haProtocolInit(inContext); /*Bonjour for service searching*/ if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true) MICOStartBonjourService( Station, inContext ); /*UART receive thread*/ uart_config.baud_rate = inContext->flashContentInRam.appConfig.USART_BaudRate; uart_config.data_width = DATA_WIDTH_8BIT; uart_config.parity = NO_PARITY; uart_config.stop_bits = STOP_BITS_1; uart_config.flow_control = FLOW_CONTROL_DISABLED; if(inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true) uart_config.flags = UART_WAKEUP_ENABLE; else uart_config.flags = UART_WAKEUP_DISABLE; ring_buffer_init ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH ); MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer ); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, 0x200, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") ); if(inContext->flashContentInRam.appConfig.localServerEnable == true){ err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, 0x350, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") ); } if(inContext->flashContentInRam.appConfig.remoteServerEnable == true){ err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, 0x300, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") ); } exit: return err; }
OSStatus MICOStartApplication( mico_Context_t * const inContext ) { app_log_trace(); OSStatus err = kNoErr; require_action(inContext, exit, err = kParamErr); MX_Init(); AC_Init(); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") ); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "HF_Cloudfunc", MX_Cloudfunc, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the MX_Cloudfunc thread.") ); exit: return err; }
int application_start(void) { app_log_trace(); OSStatus err = kNoErr; app_context_t* app_context; mico_Context_t* mico_context; LinkStatusTypeDef wifi_link_status; /* Create application context */ app_context = ( app_context_t *)calloc(1, sizeof(app_context_t) ); require_action( app_context, exit, err = kNoMemoryErr ); /* Create mico system context and read application's config data from flash */ mico_context = mico_system_context_init( sizeof( application_config_t) ); require_action(mico_context, exit, err = kNoResourcesErr); app_context->appConfig = mico_system_context_get_user_data( mico_context ); app_context->mico_context = mico_context; app_context_global = app_context; /* user params restore check */ if(app_context->appConfig->configDataVer != CONFIGURATION_VERSION){ err = mico_system_context_restore(mico_context); require_noerr( err, exit ); } /* mico system initialize */ err = mico_system_init( mico_context ); require_noerr( err, exit ); MicoSysLed(true); // fix for AP down problem err = mico_system_notify_register( mico_notify_WIFI_CONNECT_FAILED, (void *)appNotify_ConnectFailedHandler, app_context->mico_context ); require_noerr_action(err, exit, app_log("ERROR: MICOAddNotification (mico_notify_WIFI_CONNECT_FAILED) failed!") ); //#ifdef USE_MiCOKit_EXT // /* user test mode to test MiCOKit-EXT board */ // if(MicoExtShouldEnterTestMode()){ // app_log("Enter ext-board test mode by key2."); // micokit_ext_mfg_test(mico_context); // } //#endif // block here if no wifi configuration. while(1){ if( mico_context->flashContentInRam.micoSystemConfig.configured == wLanUnConfigured || mico_context->flashContentInRam.micoSystemConfig.configured == unConfigured){ mico_thread_msleep(100); } else{ break; } } /* Bonjour for service searching */ MICOStartBonjourService( Station, app_context ); /* check wifi link status */ do{ err = micoWlanGetLinkStatus(&wifi_link_status); if(kNoErr != err){ mico_thread_sleep(3); } }while(kNoErr != err); if(1 == wifi_link_status.is_connected){ app_context->appStatus.isWifiConnected = true; MicoRfLed(true); } else{ app_context->appStatus.isWifiConnected = false; MicoRfLed(false); } /* start cloud service */ #if (MICO_CLOUD_TYPE == CLOUD_FOGCLOUD) app_log("MICO CloudService: FogCloud."); err = MiCOStartFogCloudService( app_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start FogCloud service.") ); #elif (MICO_CLOUD_TYPE == CLOUD_ALINK) app_log("MICO CloudService: Alink."); #elif (MICO_CLOUD_TYPE == CLOUD_DISABLED) app_log("MICO CloudService: disabled."); #else #error "MICO cloud service type is not defined"? #endif /* start user thread */ err = startUserMainThread( app_context ); require_noerr_action( err, exit, app_log("ERROR: start user_main thread failed!") ); exit: mico_rtos_delete_thread(NULL); return err; }
int application_start(void) { app_log_trace(); OSStatus err = kNoErr; app_context_t* app_context; mico_Context_t* mico_context; LinkStatusTypeDef wifi_link_status; /* Create application context */ app_context = ( app_context_t *)calloc(1, sizeof(app_context_t) ); require_action( app_context, exit, err = kNoMemoryErr ); /* Create mico system context and read application's config data from flash */ mico_context = mico_system_context_init( sizeof( application_config_t) ); require_action(mico_context, exit, err = kNoResourcesErr); app_context->appConfig = mico_system_context_get_user_data( mico_context ); app_context->mico_context = mico_context; /* user params restore check */ if(app_context->appConfig->configDataVer != CONFIGURATION_VERSION){ err = mico_system_context_restore(mico_context); require_noerr( err, exit ); } /* mico system initialize */ err = mico_system_init( mico_context ); require_noerr( err, exit ); MicoSysLed(true); /* Bonjour for service searching */ MICOStartBonjourService( Station, app_context ); /* user test mode: MiCOKit-EXT */ /* check wifi link status */ do{ err = micoWlanGetLinkStatus(&wifi_link_status); if(kNoErr != err){ mico_thread_sleep(3); } }while(kNoErr != err); if(1 == wifi_link_status.is_connected){ app_context->appStatus.isWifiConnected = true; MicoRfLed(true); } else{ app_context->appStatus.isWifiConnected = false; MicoRfLed(false); } /* start cloud service */ #if (MICO_CLOUD_TYPE == CLOUD_FOGCLOUD) app_log("MICO CloudService: FogCloud."); err = MiCOStartFogCloudService( app_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start FogCloud service.") ); #elif (MICO_CLOUD_TYPE == CLOUD_ALINK) app_log("MICO CloudService: Alink."); #elif (MICO_CLOUD_TYPE == CLOUD_SITEWHERE) app_log("MICO CloudService: SiteWhere."); err = MiCOStartSiteWhereService( app_context ); require_noerr_action( err, exit, app_log("ERROR: Unable to start SiteWhere service.") ); #elif (MICO_CLOUD_TYPE == CLOUD_DISABLED) app_log("MICO CloudService: disabled."); #else #error "MICO cloud service type is not defined"? #endif /* start user thread */ err = startUserMainThread( app_context ); require_noerr_action( err, exit, app_log("ERROR: start user_main thread failed!") ); exit: mico_rtos_delete_thread(NULL); return err; }