void micoNotify_WifiStatusHandler(WiFiEvent event, mico_Context_t * const inContext) { mico_log_trace(); (void)inContext; switch (event) { case NOTIFY_STATION_UP: mico_log("Station up"); MicoRfLed(true); break; case NOTIFY_STATION_DOWN: mico_log("Station down"); MicoRfLed(false); break; case NOTIFY_AP_UP: mico_log("uAP established"); MicoRfLed(true); break; case NOTIFY_AP_DOWN: mico_log("uAP deleted"); MicoRfLed(false); break; default: break; } return; }
void scan_wifi_complete_call_back(ScanResult *wifi_si_result ,mico_Context_t * const context_tmp) { u8 j=0; mico_log("the sisi num is %d",wifi_si_result->ApNum); if(0!=wifi_si_result->ApNum) { for(j=0;j<wifi_si_result->ApNum;j++) { mico_log("the ap name is %s",(wifi_si_result->ApList+j)->ssid); //printf("the ap name is %s",(wifi_si_result->ApList+i)->ssid); mico_log("the ap signal strength is %d",(wifi_si_result->ApList+j)->ApPower); if(0==strcmp(context_tmp->flashContentInRam.micoSystemConfig.ssid,(char *)(wifi_si_result->ApList+j)->ssid)) { if((wifi_si_result->ApList+j)->ApPower<40) //--1 { Clr_LED_HIG; Clr_LED_LIGHT; Set_LED_NET; } if((wifi_si_result->ApList+j)->ApPower>40&&(wifi_si_result->ApList+j)->ApPower<70) //--2 { Clr_LED_HIG; Set_LED_LIGHT; Set_LED_NET; } if((wifi_si_result->ApList+j)->ApPower>70) { Set_LED_HIG; Set_LED_LIGHT; Set_LED_NET; } } //mico_log(wifi_si_result->ApList->ssid); } } }
void proces_init_out_dis(mico_i2c_device_t *slave_device) { SlaveMessge s_messge; s_messge.id=ID_WIND; KvVarProtect(TRUE); s_messge.value=kv_sys_sate.STATE_WIND; if(FALSE==Set_Slave_Vaule(slave_device,&s_messge)) { mico_log("set the wind vaue failed"); } s_messge.id=ID_LIGHT; s_messge.value=kv_sys_sate.STATE_LIGHT; if(FALSE==Set_Slave_Vaule(slave_device,&s_messge)) { mico_log("set the light vaue failed"); } if(buzz_silent!=STATE_BUZ) { s_messge.id=ID_BUZZ; s_messge.value=STATE_BUZ; if(FALSE==Set_Slave_Vaule(slave_device,&s_messge)) { mico_log("set the buzze vaue failed"); } STATE_BUZ=buzz_silent; } KvVarProtect(FALSE); }
void micoNotify_WifiStatusHandler(WiFiEvent event, mico_Context_t * const inContext) { mico_log_trace(); (void)inContext; switch (event) { case NOTIFY_STATION_UP: mico_log("Station up"); break; case NOTIFY_STATION_DOWN: mico_log("Station down"); break; default: break; } return; }
void _ConnectToAP( mico_Context_t * const inContext) { mico_log_trace(); network_InitTypeDef_adv_st wNetConfig; mico_log("connect to %s.....", inContext->flashContentInRam.micoSystemConfig.ssid); memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_adv_st)); mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex); strncpy((char*)wNetConfig.ap_info.ssid, inContext->flashContentInRam.micoSystemConfig.ssid, maxSsidLen); memcpy(wNetConfig.ap_info.bssid, inContext->flashContentInRam.micoSystemConfig.bssid, 6); wNetConfig.ap_info.channel = inContext->flashContentInRam.micoSystemConfig.channel; wNetConfig.ap_info.security = inContext->flashContentInRam.micoSystemConfig.security; memcpy(wNetConfig.key, inContext->flashContentInRam.micoSystemConfig.key, inContext->flashContentInRam.micoSystemConfig.keyLength); wNetConfig.key_len = inContext->flashContentInRam.micoSystemConfig.keyLength; if(inContext->flashContentInRam.micoSystemConfig.dhcpEnable == true) wNetConfig.dhcpMode = DHCP_Client; else wNetConfig.dhcpMode = DHCP_Disable; strncpy((char*)wNetConfig.local_ip_addr, inContext->flashContentInRam.micoSystemConfig.localIp, maxIpLen); strncpy((char*)wNetConfig.net_mask, inContext->flashContentInRam.micoSystemConfig.netMask, maxIpLen); strncpy((char*)wNetConfig.gateway_ip_addr, inContext->flashContentInRam.micoSystemConfig.gateWay, maxIpLen); strncpy((char*)wNetConfig.dnsServer_ip_addr, inContext->flashContentInRam.micoSystemConfig.dnsServer, maxIpLen); mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex); wNetConfig.wifi_retry_interval = 100; StartAdvNetwork(&wNetConfig); }
void micoNotify_StackOverflowErrHandler(char *taskname, mico_Context_t * const inContext) { mico_log_trace(); (void)inContext; mico_log("Thread %s overflow, system rebooting", taskname); MicoSystemReboot(); }
void micoNotify_WlanFatalErrHandler(mico_Context_t * const inContext) { mico_log_trace(); (void)inContext; mico_log("Wlan Fatal Err!"); MicoSystemReboot(); }
USED void PlatformEasyLinkButtonClickedCallback(void) { mico_log_trace(); bool needsUpdate = false; mico_log("PlatformEasyLinkButtonClickedCallback"); if(context->flashContentInRam.micoSystemConfig.easyLinkByPass != EASYLINK_BYPASS_NO){ context->flashContentInRam.micoSystemConfig.easyLinkByPass = EASYLINK_BYPASS_NO; needsUpdate = true; } if(context->flashContentInRam.micoSystemConfig.configured == allConfigured){ context->flashContentInRam.micoSystemConfig.configured = wLanUnConfigured; needsUpdate = true; } if(needsUpdate == true) MICOUpdateConfiguration(context); context->micoStatus.sys_state = eState_Software_Reset; require(context->micoStatus.sys_state_change_sem, exit); mico_rtos_set_semaphore(&context->micoStatus.sys_state_change_sem); exit: return; }
void proces_out_dis(mico_i2c_device_t *slave_device) { SlaveMessge s_messge; KvVarProtect(TRUE); if(kv_sys_sate_old.STATE_WIND!=kv_sys_sate.STATE_WIND && kv_sys_sate.STATE_WIND!=baochaochange) { s_messge.id=ID_WIND; s_messge.value=kv_sys_sate.STATE_WIND; if(FALSE==Set_Slave_Vaule(slave_device,&s_messge)) { mico_log("set the wind vaue failed"); } } if(kv_sys_sate_old.STATE_LIGHT!=kv_sys_sate.STATE_LIGHT) { s_messge.id=ID_LIGHT; s_messge.value=kv_sys_sate.STATE_LIGHT; if(FALSE==Set_Slave_Vaule(slave_device,&s_messge)) { mico_log("set the light vaue failed"); } } if(buzz_silent!=STATE_BUZ) { s_messge.id=ID_BUZZ; s_messge.value=STATE_BUZ; if(FALSE==Set_Slave_Vaule(slave_device,&s_messge)) { mico_log("set the buzze vaue failed"); } STATE_BUZ=buzz_silent; } kv_sys_sate_old.STATE_SYS=kv_sys_sate.STATE_SYS; kv_sys_sate_old.STATE_LIGHT=kv_sys_sate.STATE_LIGHT; kv_sys_sate_old.STATE_NET=kv_sys_sate.STATE_NET; kv_sys_sate_old.STATE_WIND=kv_sys_sate.STATE_WIND; KvVarProtect(FALSE); }
USED void PlatformEasyLinkButtonLongPressedCallback(void) { mico_log_trace(); mico_log("PlatformEasyLinkButtonLongPressedCallback"); MICORestoreDefault(context); context->micoStatus.sys_state = eState_Software_Reset; require(context->micoStatus.sys_state_change_sem, exit); mico_rtos_set_semaphore(&context->micoStatus.sys_state_change_sem); exit: return; }
void seng_key_messge(KvKeyId kv_key_id,bool short_long) { #if 0 //qxf need't OsAslMsgT KEY_VALUE_MSG; memset(&KEY_VALUE_MSG, 0, sizeof(KEY_VALUE_MSG)); //KvKeyMessge keymessge; //keymessge.key_id=kv_key_id; //keymessge.key_short_long=short_long; KEY_VALUE_MSG.Arg=kv_key_id; KEY_VALUE_MSG.Arg2=short_long; // KEY_VALUE_MSG.MsgId = RH_KEY_PRESS_EVENT_MSG; #if 0 if(kNoErr!=OsAslMsgQueueSendMsg(&KV_QUE,&KEY_VALUE_MSG,OS_ASL_WAIT_FOREVER)) { mico_log("send key value mess failed----------failed"); } #endif //SendMsgToRhTask(&KEY_VALUE_MSG); #endif }
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) { 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 WACPlatformParameters_t* WAC_Params = NULL; WAC_Params = calloc(1, sizeof(WACPlatformParameters_t)); require(WAC_Params, exit); str2hex((unsigned char *)para.mac, WAC_Params->macAddress, 6); WAC_Params->isUnconfigured = 1; WAC_Params->supportsAirPlay = 0; WAC_Params->supportsAirPrint = 0; WAC_Params->supports2_4GHzWiFi = 1; WAC_Params->supports5GHzWiFi = 0; WAC_Params->supportsWakeOnWireless = 0; WAC_Params->firmwareRevision = FIRMWARE_REVISION; WAC_Params->hardwareRevision = HARDWARE_REVISION; WAC_Params->serialNumber = SERIAL_NUMBER; WAC_Params->name = context->flashContentInRam.micoSystemConfig.name; WAC_Params->model = MODEL; WAC_Params->manufacturer = MANUFACTURER; WAC_Params->numEAProtocols = 1; WAC_Params->eaBundleSeedID = BUNDLE_SEED_ID; WAC_Params->eaProtocols = (char **)eaProtocols;; err = startMFiWAC( context, WAC_Params, 1200); free(WAC_Params); 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 ); // } err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mDNSResponder", mDNSResponder_thread, 0x1000, (void*)context ); require_noerr_action( err, exit, mico_log("ERROR: Unable to start mDNSResponder thread.") ); /*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(200); 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) { OSStatus err = kNoErr; IPStatusTypedef para; struct tm currentTime; mico_rtc_time_t time; char wifi_ver[64]; mico_log_trace(); #if 1 /*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 ); err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WIFI_Fatal_ERROR, (void *)micoNotify_WlanFatalErrHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_Stack_Overflow_ERROR, (void *)micoNotify_StackOverflowErrHandler ); require_noerr( err, exit ); #endif /*wlan driver and tcpip init*/ MicoInit(); MicoSysLed(true); /**********************add ethernet**********************/ add_ethernet(); //sleep(5000); /*********************************************************/ mico_log("Free memory %d bytes", MicoGetMemoryInfo()->free_memory) ; /* Enter test mode, call a build-in test function amd output on STDIO */ if(MicoShouldEnterMFGMode()==true) mico_mfg_test(); /*Read current time from RTC.*/ MicoRtcGetTime(&time); currentTime.tm_sec = time.sec; currentTime.tm_min = time.min; currentTime.tm_hour = time.hr; currentTime.tm_mday = time.date; currentTime.tm_wday = time.weekday; currentTime.tm_mon = time.month - 1; currentTime.tm_year = time.year + 100; mico_log("Current Time: %s",asctime(¤tTime)); micoWlanGetIPStatus(¶, Station); formatMACAddr(context->micoStatus.mac, (char *)¶.mac); MicoGetRfVer(wifi_ver, sizeof(wifi_ver)); mico_log("%s mxchipWNet library version: %s", APP_INFO, MicoGetVer()); mico_log("Wi-Fi driver version %s, mac %s", wifi_ver, context->micoStatus.mac); /*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); /* Regisist notifications */ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); /*************add ethernet********Why add twice?***********/ //add_ethernet(); if(context->flashContentInRam.micoSystemConfig.configured != allConfigured){ mico_log("Empty configuration. Starting configuration mode..."); #if (MICO_CONFIG_MODE == CONFIG_MODE_EASYLINK) || (MICO_CONFIG_MODE == CONFIG_MODE_EASYLINK_WITH_SOFTAP) err = startEasyLink( context ); require_noerr( err, exit ); #elif (MICO_CONFIG_MODE == CONFIG_MODE_SOFT_AP) err = startEasyLinkSoftAP( context ); require_noerr( err, exit ); #elif (MICO_CONFIG_MODE == CONFIG_MODE_AIRKISS) err = startAirkiss( context ); require_noerr( err, exit ); #elif (MICO_CONFIG_MODE == CONFIG_MODE_WPS) || MICO_CONFIG_MODE == defined (CONFIG_MODE_WPS_WITH_SOFTAP) err = startWPS( context ); require_noerr( err, exit ); #elif ( MICO_CONFIG_MODE == CONFIG_MODE_WAC) WACPlatformParameters_t* WAC_Params = NULL; WAC_Params = calloc(1, sizeof(WACPlatformParameters_t)); require(WAC_Params, exit); str2hex((unsigned char *)para.mac, WAC_Params->macAddress, 6); WAC_Params->isUnconfigured = 1; WAC_Params->supportsAirPlay = 0; WAC_Params->supportsAirPrint = 0; WAC_Params->supports2_4GHzWiFi = 1; WAC_Params->supports5GHzWiFi = 0; WAC_Params->supportsWakeOnWireless = 0; WAC_Params->firmwareRevision = FIRMWARE_REVISION; WAC_Params->hardwareRevision = HARDWARE_REVISION; WAC_Params->serialNumber = SERIAL_NUMBER; WAC_Params->name = context->flashContentInRam.micoSystemConfig.name; WAC_Params->model = MODEL; WAC_Params->manufacturer = MANUFACTURER; WAC_Params->numEAProtocols = 1; WAC_Params->eaBundleSeedID = BUNDLE_SEED_ID; WAC_Params->eaProtocols = (char **)eaProtocols; err = startMFiWAC( context, WAC_Params, 1200); free(WAC_Params); require_noerr( err, exit ); #else #error "Wi-Fi configuration mode is not defined"? #endif } else{ mico_log("Available configuration. Starting Wi-Fi connection..."); 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){ micoWlanEnablePowerSave(); } if(context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true){ MicoMcuPowerSaveConfig(true); } /*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.") ); } err = MICOStartNTPClient(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the NTP client thread.") ); /*Start mico application*/ err = MICOStartApplication( context ); require_noerr( err, exit ); _ConnectToAP( context ); } mico_log("Free memory %d bytes", MicoGetMemoryInfo()->free_memory) ; /*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); MicoSystemReboot(); break; case eState_Wlan_Powerdown: sendNotifySYSWillPowerOff(); mico_thread_msleep(500); micoWlanPowerOff(); break; case eState_Standby: mico_log("Enter standby mode"); sendNotifySYSWillPowerOff(); mico_thread_msleep(200); micoWlanPowerOff(); MicoSystemStandBy(MICO_WAIT_FOREVER); 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; }
void micoNotify_ConnectFailedHandler(OSStatus err, mico_Context_t * const inContext) { mico_log_trace(); (void)inContext; mico_log("Wlan Connection Err %d", err); }
int application_start(void) { OSStatus err = kNoErr; IPStatusTypedef para; struct tm currentTime; mico_rtc_time_t time; char wifi_ver[64] = {0}; mico_log_trace(); /*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);//ram互斥初始化 mico_rtos_init_semaphore(&context->micoStatus.sys_state_change_sem, 1);//系统状态信号量 mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY, "sys", _sys_state_thread, 800, NULL ); MICOReadConfiguration( context );//读flash数据 err = MICOInitNotificationCenter ( context ); err = MICOAddNotification( mico_notify_READ_APP_INFO, (void *)micoNotify_ReadAppInfoHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WIFI_Fatal_ERROR, (void *)micoNotify_WlanFatalErrHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_Stack_Overflow_ERROR, (void *)micoNotify_StackOverflowErrHandler ); require_noerr( err, exit ); /*wlan driver and tcpip init*/ mico_log( "MiCO starting..." ); MicoInit(); #ifdef MICO_CLI_ENABLE MicoCliInit(); #endif MicoSysLed(true); mico_log("Free memory %d bytes", MicoGetMemoryInfo()->free_memory); micoWlanGetIPStatus(¶, Station); formatMACAddr(context->micoStatus.mac, (char *)para.mac); MicoGetRfVer(wifi_ver, sizeof(wifi_ver)); mico_log("ip = %s,mac=%s",para.ip,para.mac); mico_log("%s mxchipWNet library version: %s", APP_INFO, MicoGetVer()); mico_log("Wi-Fi driver version %s, mac %s", wifi_ver, context->micoStatus.mac); /*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/2, _watchdog_reload_timer_handler, NULL); mico_start_timer(&_watchdog_reload_timer); /* Enter test mode, call a build-in test function amd output on MFG UART */ if(MicoShouldEnterMFGMode()==true){ mico_log( "Enter MFG mode by MFG button" ); mico_mfg_test(context); } /*Read current time from RTC.*/ if( MicoRtcGetTime(&time) == kNoErr ){ currentTime.tm_sec = time.sec; currentTime.tm_min = time.min; currentTime.tm_hour = time.hr; currentTime.tm_mday = time.date; currentTime.tm_wday = time.weekday; currentTime.tm_mon = time.month - 1; currentTime.tm_year = time.year + 100; mico_log("Current Time: %s",asctime(¤tTime)); }else mico_log("RTC function unsupported"); /* Regisist notifications */ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); if( context->flashContentInRam.micoSystemConfig.configured == wLanUnConfigured || context->flashContentInRam.micoSystemConfig.configured == unConfigured){ mico_log("Empty configuration. Starting configuration mode..."); //HERE TO config network #if (MICO_CONFIG_MODE == CONFIG_MODE_EASYLINK) || (MICO_CONFIG_MODE == CONFIG_MODE_EASYLINK_WITH_SOFTAP) err = startEasyLink( context ); require_noerr( err, exit ); #elif (MICO_CONFIG_MODE == CONFIG_MODE_SOFT_AP) err = startEasyLinkSoftAP( context ); require_noerr( err, exit ); #elif (MICO_CONFIG_MODE == CONFIG_MODE_AIRKISS) err = startAirkiss( context ); require_noerr( err, exit ); #elif (MICO_CONFIG_MODE == CONFIG_MODE_WPS) || MICO_CONFIG_MODE == defined (CONFIG_MODE_WPS_WITH_SOFTAP) err = startWPS( context ); require_noerr( err, exit ); #elif ( MICO_CONFIG_MODE == CONFIG_MODE_WAC) WACPlatformParameters_t* WAC_Params = NULL; WAC_Params = calloc(1, sizeof(WACPlatformParameters_t)); require(WAC_Params, exit); str2hex((unsigned char *)para.mac, WAC_Params->macAddress, 6); WAC_Params->isUnconfigured = 1; WAC_Params->supportsAirPlay = 0; WAC_Params->supportsAirPrint = 0; WAC_Params->supports2_4GHzWiFi = 1; WAC_Params->supports5GHzWiFi = 0; WAC_Params->supportsWakeOnWireless = 0; WAC_Params->firmwareRevision = FIRMWARE_REVISION; WAC_Params->hardwareRevision = HARDWARE_REVISION; WAC_Params->serialNumber = SERIAL_NUMBER; WAC_Params->name = context->flashContentInRam.micoSystemConfig.name; WAC_Params->model = MODEL; WAC_Params->manufacturer = MANUFACTURER; WAC_Params->numEAProtocols = 1; WAC_Params->eaBundleSeedID = BUNDLE_SEED_ID; WAC_Params->eaProtocols = (char **)eaProtocols; err = startMFiWAC( context, WAC_Params, MICO_I2C_CP, 1200 ); free(WAC_Params); require_noerr( err, exit ); #else #error "Wi-Fi configuration mode is not defined" #endif } else{ mico_log("Available configuration. Starting Wi-Fi connection..."); _ConnectToAP( context ); } #ifdef MFG_MODE_AUTO if( context->flashContentInRam.micoSystemConfig.configured == mfgConfigured ){ mico_log( "Enter MFG mode automatically" ); mico_mfg_test(context); mico_thread_sleep(MICO_NEVER_TIMEOUT); } #endif 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){ micoWlanEnablePowerSave(); } if(context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true){ MicoMcuPowerSaveConfig(true); } /*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.") ); } err = MICOStartNTPClient(context); require_noerr_action( err, exit, mico_log("ERROR: Unable to start the NTP client thread.") ); /*Start mico application*/ err = MICOStartApplication( context ); require_noerr( err, exit ); mico_log("Free memory %d bytes", MicoGetMemoryInfo()->free_memory) ; require_noerr_action( err, exit, mico_log("Closing main thread with err num: %d.", err) ); exit: mico_rtos_delete_thread(NULL); return kNoErr; }
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 按键检测 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ void key_check(mico_i2c_device_t *slave_device) { //SlaveMessge slave_messge; KvKeyMessge key_messge; Set_REST;//开启按键检测 KvVarProtect(TRUE); if(!state_key_keep) { //大风键处理 if(!Get_KEY_HIG) { KEY.KEY_HIG++; if(KEY.KEY_HIG == 300) { mico_log("in high wind key\r\n"); state_key_keep=1; /////////////////////////////////////////////////////////////////////// micoWlanStartScan(); wifi_display=1; /////////////////////////////////////////////////////////////////////// } } else { /////////////////////////////////////////////////////////////////////// //短按键程序 if(KEY.KEY_HIG>15&&KEY.KEY_HIG<100) { state_key_keep=1; /********上报按键键值**********************************/ seng_key_messge(kv_key_hig,KEY_SHORT); /**************---------------------------******************/ /*****************************************************以下内容可以注释**********************************/ if(kv_sys_sate.STATE_SYS ==1) { STATE_BUZ=buzz_one_sing; if(kv_sys_sate.STATE_WIND == 6||kv_sys_sate.STATE_WIND == 3)//爆抄 kv_sys_sate.STATE_WIND = 0; else kv_sys_sate.STATE_WIND = 6; } else if(kv_sys_sate.STATE_SYS ==2)//延时关机退出延时 { STATE_BUZ=buzz_one_sing; kv_sys_sate.STATE_SYS = 1; } /**************----------------------------------------------------------------------------------------------------------------******************/ } /////////////////////////////////////////////////////////////////////// KEY.KEY_HIG=0;// } //小风键处理 if(!Get_KEY_LOW) { KEY.KEY_LOW++; if(KEY.KEY_LOW == 15) { KEY.KEY_LOW= 0; state_key_keep=1; /********上报按键键值**********************************/ seng_key_messge(kv_key_low,KEY_SHORT); /**************---------------------------******************/ /*****************************************************以下内容可以注释**********************************/ #if 0 if(kv_sys_sate.STATE_SYS == 1) { STATE_BUZ=buzz_one_sing; if(kv_sys_sate.STATE_WIND ==1) kv_sys_sate.STATE_WIND = 0; else if(kv_sys_sate.STATE_WIND == 2) kv_sys_sate.STATE_WIND = 1; else if(kv_sys_sate.STATE_WIND == 3) kv_sys_sate.STATE_WIND = 2; else kv_sys_sate.STATE_WIND = 3; } #else if(kv_sys_sate.STATE_SYS == 1) { STATE_BUZ=buzz_one_sing; if(kv_sys_sate.STATE_WIND ==2 || kv_sys_sate.STATE_WIND ==1) kv_sys_sate.STATE_WIND = 0; else kv_sys_sate.STATE_WIND = 2; } #endif else if(kv_sys_sate.STATE_SYS == 2)//延时关机退出延时 { STATE_BUZ=buzz_one_sing; kv_sys_sate.STATE_SYS = 1; } /**************----------------------------------------------------------------------------------------------------------------******************/ } } else KEY.KEY_LOW=0; //照明键处理 if(!Get_KEY_LIGHT) { KEY.KEY_LIGHT++; if(KEY.KEY_LIGHT == 15) { KEY.KEY_LIGHT= 0; state_key_keep=1; /********上报按键键值**********************************/ seng_key_messge(kv_key_light,KEY_SHORT); /**************---------------------------******************/ /*****************************************************以下内容可以注释**********************************/ // BUZZ.STATE_BUZ = 1; STATE_BUZ=buzz_one_sing; if(kv_sys_sate.STATE_LIGHT) kv_sys_sate.STATE_LIGHT=0; else kv_sys_sate.STATE_LIGHT=1; /**************----------------------------------------------------------------------------------------------------------------******************/ } } else KEY.KEY_LIGHT=0; //网络按键处理 if(!Get_KEY_NET)/////////////////////////////////////////////////////////网络按键处理 { KEY.KEY_NET++; if(KEY.KEY_NET==300) { state_key_keep=1; /********上报按键键值**********************************/ seng_key_messge(kv_key_net,KEY_LONG); /**************---------------------------******************/ /*****************************************************此处联网按键长按处理**********************************/ STATE_BUZ=buzz_one_sing; // kv_sys_sate.STATE_NET=0x02; /**************----------------------------------------------------------------------------------------------------------------******************/ } } else { if((KEY.KEY_NET>15)&&(KEY.KEY_NET<100)) { state_key_keep=1; /********上报按键键值**********************************/ seng_key_messge(kv_key_net,KEY_SHORT); /****************---------------------------******************/ /*****************************************************此处联网按键短按处理**********************************/ STATE_BUZ=buzz_one_sing; /**************----------------------------------------------------------------------------------------------------------------******************/ // kv_sys_sate.STATE_NET=0x01; } KEY.KEY_NET=0; } //开关键处理 if(!Get_KEY_POWER) { KEY.KEY_POWER++; if(KEY.KEY_POWER == 15) { // mico_log("come here the power key buuton"); /********上报按键键值**********************************/ seng_key_messge(kv_key_power,KEY_SHORT); /**************---------------------------******************/ KEY.KEY_POWER= 0; state_key_keep=1; /*****************************************************以下内容可以注释**********************************/ if(kv_sys_sate.STATE_SYS == 1) { if(kv_sys_sate.STATE_WIND == 0) { // BUZZ.STATE_BUZ = 3; STATE_BUZ=buzz_system_off; /* slave_messge.id=ID_BUZZ slave_messge.value=buzz_system_off; if(FALSE==Set_Slave_Vaule(slave_device,&slave_messge)) { mico_log("set the buzze vaue failed"); }*/ kv_sys_sate.STATE_SYS = 0; kv_sys_sate.STATE_LIGHT = 0; } else { //BUZZ.STATE_BUZ = 1; STATE_BUZ=buzz_one_sing; /* slave_messge.id=ID_BUZZ slave_messge.value=buzz_one_sing; if(FALSE==Set_Slave_Vaule(slave_device,&slave_messge)) { mico_log("set the buzze vaue failed"); }*/ kv_sys_sate.STATE_SYS = 2; } } else if(kv_sys_sate.STATE_SYS == 2) { //BUZZ.STATE_BUZ = 3; STATE_BUZ=buzz_system_off; /* slave_messge.id=ID_BUZZ slave_messge.value=buzz_system_off; if(FALSE==Set_Slave_Vaule(slave_device,&slave_messge)) { mico_log("set the buzze vaue failed"); }*/ kv_sys_sate.STATE_SYS = 0; kv_sys_sate.STATE_LIGHT = 0; } else { //BUZZ.STATE_BUZ = 2; STATE_BUZ=buzz_system_on; /* slave_messge.id=ID_BUZZ slave_messge.value=buzz_system_on; if(FALSE==Set_Slave_Vaule(slave_device,&slave_messge)) { mico_log("set the buzze vaue failed"); } */ kv_sys_sate.STATE_SYS = 1; } /**************----------------------------------------------------------------------------------------------------------------******************/ } } else KEY.KEY_POWER=0; } KvVarProtect(FALSE); if(Get_KEY_HIG&&Get_KEY_LOW&&Get_KEY_LIGHT&&Get_KEY_NET&&Get_KEY_POWER) { //KEY.KEY_KEEP++; state_key_keep=0; KEY.KEY_KEEP=0; } else { KEY.KEY_KEEP++; //state_key_keep=0; // KEY.KEY_KEEP=0; } /*if((KEY.KEY_LOW||KEY.KEY_HIG||KEY.KEY_LIGHT||KEY.KEY_NET||KEY.KEY_POWER)==0) { state_key_keep=0; KEY.KEY_KEEP=0; //KEY.KEY_KEEP++; } else { KEY.KEY_KEEP++; //state_key_keep=0; //KEY.KEY_KEEP=0; }*/ if(KEY.KEY_KEEP>500)//复位按键 Clr_REST; }