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; }
/* 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; }
OSStatus MICOStartApplication( mico_Context_t * const inContext ) { app_log_trace(); OSStatus err = kNoErr; require_action(inContext, exit, err = kParamErr); sppProtocolInit(inContext); PlatformUartInitialize(inContext); /*Bonjour for service searching*/ if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true) MICOStartBonjourService( Station, inContext ); 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, 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, 0x300, (void*)inContext ); require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client 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; }
void _easylinkStartSoftAp( mico_Context_t * const inContext) { OSStatus err; easylink_log_trace(); network_InitTypeDef_st wNetConfig; memset(&wNetConfig, 0, sizeof(network_InitTypeDef_st)); wNetConfig.wifi_mode = Soft_AP; snprintf(wNetConfig.wifi_ssid, 32, "MXCHIP_%c%c%c%c%c%c", inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \ inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] ); strcpy((char*)wNetConfig.wifi_key, ""); strcpy((char*)wNetConfig.local_ip_addr, "10.10.10.1"); strcpy((char*)wNetConfig.net_mask, "255.255.255.0"); strcpy((char*)wNetConfig.gateway_ip_addr, "10.10.10.1"); wNetConfig.dhcpMode = DHCP_Server; micoWlanStart(&wNetConfig); easylink_log("Establish soft ap: %s.....", wNetConfig.wifi_ssid); if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true){ err = MICOStartBonjourService( Soft_AP , inContext ); require_noerr(err, exit); } if(inContext->flashContentInRam.micoSystemConfig.configServerEnable == true){ err = MICOStartConfigServer ( inContext ); require_noerr(err, exit); } ConfigSoftApWillStart( inContext ); exit: return; }
/* 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 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; }
int application_start(void) { OSStatus err = kNoErr; net_para_st para; Platform_Init(); /*Read current configurations*/ context = ( mico_Context_t *)malloc(sizeof(mico_Context_t) ); require_action( context, exit, err = kNoMemoryErr ); memset(context, 0x0, sizeof(mico_Context_t)); mico_rtos_init_mutex(&context->flashContentInRam_mutex); mico_rtos_init_semaphore(&context->micoStatus.sys_state_change_sem, 1); MICOReadConfiguration( context ); err = MICOInitNotificationCenter ( context ); err = MICOAddNotification( mico_notify_READ_APP_INFO, (void *)micoNotify_ReadAppInfoHandler ); require_noerr( err, exit ); /*wlan driver and tcpip init*/ mxchipInit(); getNetPara(¶, Station); formatMACAddr(context->micoStatus.mac, (char *)¶.mac); mico_log_trace(); mico_log("%s mxchipWNet library version: %s", APP_INFO, system_lib_version()); /*Start system monotor thread*/ err = MICOStartSystemMonitor(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the system monitor.") ); err = MICORegisterSystemMonitor(&mico_monitor, APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000); require_noerr( err, exit ); mico_init_timer(&_watchdog_reload_timer,APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000-100, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); if(context->flashContentInRam.micoSystemConfig.configured != allConfigured){ mico_log("Empty configuration. Starting configuration mode..."); #ifdef CONFIG_MODE_EASYLINK err = startEasyLink( context ); require_noerr( err, exit ); #endif #ifdef CONFIG_MODE_WAC err = startMfiWac( context ); require_noerr( err, exit ); #endif } else{ mico_log("Available configuration. Starting Wi-Fi connection..."); /* Regisist notifications */ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WiFI_PARA_CHANGED, (void *)micoNotify_WiFIParaChangedHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_DHCP_COMPLETED, (void *)micoNotify_DHCPCompleteHandler ); require_noerr( err, exit ); if(context->flashContentInRam.micoSystemConfig.rfPowerSaveEnable == true){ ps_enable(); } if(context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true){ mico_mcu_powersave_config(true); } /*Bonjour service for searching*/ if(context->flashContentInRam.micoSystemConfig.bonjourEnable == true){ err = MICOStartBonjourService( Station, context ); require_noerr( err, exit ); } /*Local configuration server*/ if(context->flashContentInRam.micoSystemConfig.configServerEnable == true){ err = MICOStartConfigServer(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the local server thread.") ); } /*Start mico application*/ err = MICOStartApplication( context ); require_noerr( err, exit ); _ConnectToAP( context ); } /*System status changed*/ while(mico_rtos_get_semaphore(&context->micoStatus.sys_state_change_sem, MICO_WAIT_FOREVER)==kNoErr){ switch(context->micoStatus.sys_state){ case eState_Normal: break; case eState_Software_Reset: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); PlatformSoftReboot(); break; case eState_Wlan_Powerdown: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); wifi_power_down(); break; case eState_Standby: mico_log("Enter standby mode"); sendNotifySYSWillPowerOff(); mico_thread_msleep(100); wifi_power_down(); Platform_Enter_STANDBY(); break; default: break; } } require_noerr_action( err, exit, mico_log("Closing main thread with err num: %d.", err) ); exit: mico_rtos_delete_thread(NULL); return kNoErr; }
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; }