OSStatus MVDInit(mico_Context_t* const inContext) { OSStatus err = kUnknownErr; //init MVD status inContext->appStatus.virtualDevStatus.isCloudConnected = false; inContext->appStatus.virtualDevStatus.RecvRomFileSize = 0; //init MCU connect interface //err = MVDDevInterfaceInit(inContext); //require_noerr_action(err, exit, // mvd_log("ERROR: virtual device mcu interface init failed!") ); //init cloud service interface err = MVDCloudInterfaceInit(inContext); require_noerr_action(err, exit, mvd_log("ERROR: virtual device cloud interface init failed!") ); // wifi notify err = mico_rtos_init_semaphore(&_wifi_station_on_sem, 1); require_noerr_action(err, exit, mvd_log("ERROR: mico_rtos_init_semaphore (_wifi_station_on_sem) failed!") ); err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)mvdNotify_WifiStatusHandler ); require_noerr_action(err, exit, mvd_log("ERROR: MICOAddNotification (mico_notify_WIFI_STATUS_CHANGED) failed!") ); // start MVD main thread err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "MVD main", MVDMainThread, STACK_SIZE_MVD_MAIN_THREAD, inContext ); 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; }
OSStatus HealthInit(app_context_t *app_context) { u8 idx; OSStatus err; for(idx = 0; idx < MAX_DEPTH_PUTDOWN; idx++) { putdown_timer[idx].index = idx; } // check if schedule remind timneout every 1 minute for(idx = 0; idx < MAX_DEPTH_SCHEDULE; idx++) { schedule_timer[idx].index = idx; err = mico_init_timer(&schedule_timer[idx].timer, 60*UpTicksPerSecond(), ScheduleTimeout, &schedule_timer[idx]); if(kNoErr != err) { user_log("[ERR]HealthInit: create schedule_timer[%d] failed", idx); } else { user_log("[DBG]HealthInit: create schedule_timer[%d] success", idx); } err = mico_start_timer(&schedule_timer[idx].timer); if(kNoErr != err) { user_log("[ERR]HealthInit: start schedule_timer[%d] failed", idx); } else { user_log("[DBG]HealthInit: start schedule_timer[%d] success", idx); } } #if 0 // initialize if outTrigger is implement by semaphore err = mico_rtos_init_semaphore(&semaphore_getup, 1); require_noerr_action(err, exit, user_log("[ERR]HealthInit: create semaphore_getup failed")); user_log("[DBG]HealthInit: create semaphore_getup success"); err = mico_rtos_init_semaphore(&semaphore_putdown, 1); require_noerr_action(err, exit, user_log("[ERR]HealthInit: create semaphore_putdown failed")); user_log("[DBG]HealthInit: create semaphore_putdown success"); #endif /* err = mico_init_timer(&timer_health_notify, 2*UpTicksPerSecond(), MOChangedNotification, app_context); require_noerr_action(err, exit, user_log("[ERR]HealthInit: create timer_health_notify failed")); user_log("[DBG]HealthInit: create timer_health_notify success"); err = mico_start_timer(&timer_health_notify); require_noerr_action(err, exit, user_log("[ERR]HealthInit: start timer_health_notify failed")); user_log("[DBG]HealthInit: start timer_health_notify success"); */ // start the health monitor thread err = mico_rtos_create_thread(&health_monitor_thread_handle, MICO_APPLICATION_PRIORITY, "health_monitor", health_thread, STACK_SIZE_HEALTH_THREAD, app_context); require_noerr_action( err, exit, user_log("[ERR]HealthInit: create health thread failed!")); user_log("[DBG]HealthInit: create health thread success!"); exit: return err; }
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; }
void ConfigSoftApWillStart(mico_Context_t * const inContext ) { OSStatus err; mico_uart_config_t uart_config; mico_stop_timer(&_Led_EL_timer); mico_deinit_timer( &_Led_EL_timer ); mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL); mico_start_timer(&_Led_EL_timer); sppProtocolInit(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; 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*)inContext ); require_noerr_action( err, exit, config_delegate_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, STACK_SIZE_LOCAL_TCP_SERVER_THREAD, (void*)inContext ); require_noerr_action( err, exit, config_delegate_log("ERROR: Unable to start the local server thread.") ); } exit: return; }
/* user main function, called by AppFramework. */ OSStatus user_main( app_context_t * const app_context ) { user_log_trace(); OSStatus err = kUnknownErr; user_log("User main thread start..."); // start prop get/set thread err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "prop_recv", property_recv, STACK_SIZE_PROP_RECV_THREAD, (void*)app_context); require_noerr_action( err, exit, user_log("ERROR: Unable to start the prop_recv thread.") ); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "prop_update", property_update, STACK_SIZE_PROP_UPDATE_THREAD, (void*)app_context); require_noerr_action( err, exit, user_log("ERROR: Unable to start the prop_update thread.") ); /* main loop for user display */ while(1){ // system work state show on OLED system_state_display(app_context); mico_thread_sleep(1); } exit: user_log("ERROR: user_main exit with err=%d", err); return err; }
OSStatus MicoStartFogCloudService(mico_Context_t* const inContext) { OSStatus err = kUnknownErr; //init MicoFogCloud status inContext->appStatus.fogcloudStatus.isCloudConnected = false; inContext->appStatus.fogcloudStatus.RecvRomFileSize = 0; inContext->appStatus.fogcloudStatus.isActivated = inContext->flashContentInRam.appConfig.fogcloudConfig.isActivated; inContext->appStatus.fogcloudStatus.isOTAInProgress = false; //init fogcloud service interface err = fogCloudInit(inContext); require_noerr_action(err, exit, fogcloud_log("ERROR: FogCloud interface init failed!") ); err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)fogNotify_WifiStatusHandler ); require_noerr_action(err, exit, fogcloud_log("ERROR: MICOAddNotification (mico_notify_WIFI_STATUS_CHANGED) failed!") ); // start MicoFogCloud main thread (dev reset && ota check, then start fogcloud service) err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "fog_main", fogcloud_main_thread, STACK_SIZE_FOGCLOUD_MAIN_THREAD, inContext ); exit: return err; }
OSStatus user_uartInit(void) { OSStatus err = kUnknownErr; mico_uart_config_t uart_config; //USART init uart_config.baud_rate = 115200; 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; uart_config.flags = UART_WAKEUP_DISABLE; ring_buffer_init ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, USER_UART_BUFFER_LENGTH ); MicoUartInitialize( USER_UART, &uart_config, (ring_buffer_t *)&rx_buffer ); //USART receive thread 启动uart接收线程 err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_USART_RECV_THREAD, NULL ); require_noerr_action( err, exit, user_uart_log("ERROR: Unable to start the USART recv thread.") ); //ZCB Msg Handle Thread 启动 ZCB Msg 处理线程 err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "ZCB Msg Handle", ZCB_MessageHandle_thread, STACK_SIZE_ZCBMSG_HANDLE_THREAD, NULL ); require_noerr_action( err, exit, user_uart_log("ERROR: Unable to start the zcbMsg hdl thread.") ); return kNoErr; exit: return err; }
/* user main function, called by AppFramework. */ OSStatus user_main( app_context_t * const app_context ) { user_log_trace(); OSStatus err = kUnknownErr; user_log("User main task start..."); err = user_uartInit(); require_noerr_action( err, exit, user_log("ERROR: user_uartInit err = %d.", err) ); user_log("start photo..."); unsigned char* image="hello world"; user_uartSend( image,strlen(image)); char aa[200]; memset(aa, '\0', 200); mico_thread_sleep(5); int len=user_uartRecv((unsigned char *)aa, 200); user_log("uart_data_recv: [%d][%.*s]", len, len,(unsigned char*)aa); user_log("end..."); #if (MICO_CLOUD_TYPE != CLOUD_DISABLED) /* start fogcloud msg handle task */ err = start_fog_msg_handler(app_context); require_noerr_action( err, exit, user_log("ERROR: start_fog_msg_handler err = %d.", err) ); /* start properties notify task(upload data) */ err = mico_start_properties_notify(app_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 /* main loop for user display */ while(1){ // check every 1 seconds mico_thread_sleep(1); // system work state show on OLED system_state_display(app_context, &g_user_context); } exit: user_log("ERROR: user_main exit with err=%d", err); return err; }
/* 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; }
static int web_send_wifisetting_page(httpd_request_t *req) { OSStatus err = kNoErr; err = httpd_send_all_header(req, HTTP_RES_200, sizeof(wifisetting), HTTP_CONTENT_HTML_STR); require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisetting headers.") ); err = httpd_send_body(req->sock, wifisetting, sizeof(wifisetting)); require_noerr_action( err, exit, app_httpd_log("ERROR: Unable to send http wifisetting body.") ); exit: return err; }
OSStatus fogCloudDevActivate(app_context_t* const inContext, MVDActivateRequestData_t devActivateRequestData) { cloud_if_log_trace(); OSStatus err = kUnknownErr; cloud_if_log("Device activate..."); //ok, set cloud context strncpy(easyCloudContext.service_config_info.loginId, devActivateRequestData.loginId, MAX_SIZE_LOGIN_ID); strncpy(easyCloudContext.service_config_info.devPasswd, devActivateRequestData.devPasswd, MAX_SIZE_DEV_PASSWD); strncpy(easyCloudContext.service_config_info.userToken, devActivateRequestData.user_token, MAX_SIZE_USER_TOKEN); // activate request err = FogCloudActivate(&easyCloudContext); require_noerr_action(err, exit, cloud_if_log("ERROR: fogCloudDevActivate failed! err=%d", err) ); inContext->appStatus.fogcloudStatus.isActivated = true; // write activate data back to flash mico_rtos_lock_mutex(&inContext->mico_context->flashContentInRam_mutex); inContext->appConfig->fogcloudConfig.isActivated = true; strncpy(inContext->appConfig->fogcloudConfig.deviceId, easyCloudContext.service_status.deviceId, MAX_SIZE_DEVICE_ID); strncpy(inContext->appConfig->fogcloudConfig.masterDeviceKey, easyCloudContext.service_status.masterDeviceKey, MAX_SIZE_DEVICE_KEY); strncpy(inContext->appConfig->fogcloudConfig.loginId, easyCloudContext.service_config_info.loginId, MAX_SIZE_LOGIN_ID); strncpy(inContext->appConfig->fogcloudConfig.devPasswd, easyCloudContext.service_config_info.devPasswd, MAX_SIZE_DEV_PASSWD); strncpy(inContext->appConfig->fogcloudConfig.userToken, easyCloudContext.service_config_info.userToken, MAX_SIZE_USER_TOKEN); err = mico_system_context_update(inContext->mico_context); mico_rtos_unlock_mutex(&inContext->mico_context->flashContentInRam_mutex); require_noerr_action(err, exit, cloud_if_log("ERROR: activate write flash failed! err=%d", err) ); return kNoErr; exit: return err; }
OSStatus MVDCloudInterfaceResetCloudDevInfo(mico_Context_t* const inContext, MVDResetRequestData_t devResetRequestData) { OSStatus err = kUnknownErr; // login_id/dev_passwd ok ? if((0 != strncmp(inContext->flashContentInRam.appConfig.virtualDevConfig.loginId, devResetRequestData.loginId, strlen(inContext->flashContentInRam.appConfig.virtualDevConfig.loginId))) || (0 != strncmp(inContext->flashContentInRam.appConfig.virtualDevConfig.devPasswd, devResetRequestData.devPasswd, strlen(inContext->flashContentInRam.appConfig.virtualDevConfig.devPasswd)))) { // devPass err cloud_if_log("ERROR: MVDCloudInterfaceResetCloudDevInfo: loginId/devPasswd mismatch!"); return kMismatchErr; } cloud_if_log("MVDCloudInterfaceResetCloudDevInfo: loginId/devPasswd ok!"); err = EasyCloudDeviceReset(&easyCloudContext); require_noerr_action( err, exit, cloud_if_log("ERROR: EasyCloudDeviceReset failed! err=%d", err) ); mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex); inContext->flashContentInRam.appConfig.virtualDevConfig.isActivated = false; // need to reActivate sprintf(inContext->flashContentInRam.appConfig.virtualDevConfig.deviceId, DEFAULT_DEVICE_ID); sprintf(inContext->flashContentInRam.appConfig.virtualDevConfig.masterDeviceKey, DEFAULT_DEVICE_KEY); sprintf(inContext->flashContentInRam.appConfig.virtualDevConfig.loginId, DEFAULT_LOGIN_ID); sprintf(inContext->flashContentInRam.appConfig.virtualDevConfig.devPasswd, DEFAULT_DEV_PASSWD); inContext->appStatus.virtualDevStatus.isCloudConnected = false; MICOUpdateConfiguration(inContext); mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex); exit: return err; }
// bme280_sensor_init OSStatus bme280_sensor_deinit(void) { OSStatus err = kUnknownErr; s32 com_rslt = BME280_ERROR; err = MicoI2cFinalize(&user_i2c_device); require_noerr_action( err, exit, bme280_user_log("BME280_ERROR: MicoI2cFinalize err = %d.", err)); /*********************** START DE-INITIALIZATION ************************/ /* For de-initialization it is required to set the mode of * the sensor as "SLEEP" * the device reaches the lowest power consumption only * In SLEEP mode no measurements are performed * All registers are accessible * by using the below API able to set the power mode as SLEEP*/ /* Set the power mode as SLEEP*/ com_rslt = bme280_set_power_mode(BME280_SLEEP_MODE); /************************** END DE-INITIALIZATION ***********************/ if(0 == com_rslt){ err = kNoErr; } exit: return err; }
OSStatus bmg160_sensor_deinit(void) { OSStatus err = kUnknownErr; s32 com_rslt = BMG160_ERROR; err = MicoI2cFinalize(&bmg160_i2c_device); require_noerr_action( err, exit, bmg160_user_log("BMG160_ERROR: MicoI2cFinalize err = %d.", err)); /*---------------------------------------------------------------------------* *********************** START DE-INITIALIZATION ***************************** *--------------------------------------------------------------------------*/ /* For de-initialization it is required to set the mode of * the sensor as "DEEPSUSPEND" * the device reaches the lowest power consumption only * interface selection is kept alive * No data acquisition is performed * The DEEPSUSPEND mode set from the register 0x11 bit 5 * by using the below API able to set the power mode as DEEPSUSPEND * For the read/ write operation it is required to provide least 450us * micro second delay*/ com_rslt = bmg160_set_power_mode(BMG160_MODE_DEEPSUSPEND); /*--------------------------------------------------------------------------* *********************** END DE-INITIALIZATION ************************** *---------------------------------------------------------------------------*/ if(0 == com_rslt){ err = kNoErr; } exit: return err; }
OSStatus bmm050_sensor_deinit(void) { OSStatus err = kUnknownErr; s32 com_rslt = BMM050_ERROR; err = MicoI2cFinalize(&bmm050_i2c_device); require_noerr_action( err, exit, bmm050_user_log("BMM050_ERROR: MicoI2cFinalize err = %d.", err)); /*---------------------------------------------------------------------------* *********************** START DE-INITIALIZATION ***************************** *--------------------------------------------------------------------------*/ /* For de-initialization it is required to set the mode of * the sensor as "SUSPEND" * the SUSPEND mode set from the register 0x4B bit BMM050_INIT_VALUE should be disabled * by using the below API able to set the power mode as SUSPEND*/ /* Set the power mode as SUSPEND*/ com_rslt = bmm050_set_functional_state(BMM050_SUSPEND_MODE); /*--------------------------------------------------------------------------* *********************** END DE-INITIALIZATION ************************** *---------------------------------------------------------------------------*/ if(0 == com_rslt){ err = kNoErr; } exit: return err; }
OSStatus fogCloudDevAuthorize(app_context_t* const inContext, MVDAuthorizeRequestData_t devAuthorizeReqData) { cloud_if_log_trace(); OSStatus err = kUnknownErr; easycloud_service_state_t cloudServiceState = FOGCLOUD_STOPPED; cloud_if_log("Device authorize..."); cloudServiceState = FogCloudServiceState(&easyCloudContext); if (FOGCLOUD_STOPPED == cloudServiceState) { return kStateErr; } //ok, set cloud context strncpy(easyCloudContext.service_config_info.loginId, devAuthorizeReqData.loginId, MAX_SIZE_LOGIN_ID); strncpy(easyCloudContext.service_config_info.devPasswd, devAuthorizeReqData.devPasswd, MAX_SIZE_DEV_PASSWD); strncpy(easyCloudContext.service_config_info.userToken, devAuthorizeReqData.user_token, MAX_SIZE_USER_TOKEN); err = FogCloudAuthorize(&easyCloudContext); require_noerr_action( err, exit, cloud_if_log("ERROR: authorize failed! err=%d", err) ); return kNoErr; exit: return err; }
OSStatus fogCloudResetCloudDevInfo(app_context_t* const inContext, MVDResetRequestData_t devResetRequestData) { OSStatus err = kUnknownErr; cloud_if_log("Delete device info from cloud..."); err = FogCloudDeviceReset(&easyCloudContext); require_noerr_action( err, exit, cloud_if_log("ERROR: FogCloudDeviceReset failed! err=%d", err) ); inContext->appStatus.fogcloudStatus.isActivated = false; mico_rtos_lock_mutex(&inContext->mico_context->flashContentInRam_mutex); inContext->appConfig->fogcloudConfig.isActivated = false; // need to reActivate inContext->appConfig->fogcloudConfig.owner_binding = false; // no owner binding sprintf(inContext->appConfig->fogcloudConfig.deviceId, DEFAULT_DEVICE_ID); sprintf(inContext->appConfig->fogcloudConfig.masterDeviceKey, DEFAULT_DEVICE_KEY); sprintf(inContext->appConfig->fogcloudConfig.loginId, DEFAULT_LOGIN_ID); sprintf(inContext->appConfig->fogcloudConfig.devPasswd, DEFAULT_DEV_PASSWD); inContext->appStatus.fogcloudStatus.isCloudConnected = false; err = mico_system_context_update(inContext->mico_context); mico_rtos_unlock_mutex(&inContext->mico_context->flashContentInRam_mutex); exit: return err; }
OSStatus MVDDevInterfaceInit(mico_Context_t* const inContext) { OSStatus err = kUnknownErr; mico_uart_config_t uart_config; //USART init uart_config.baud_rate = inContext->flashContentInRam.appConfig.virtualDevConfig.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_MCU, &uart_config, (ring_buffer_t *)&rx_buffer ); //USART receive thread err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_USART_RECV_THREAD, (void*)inContext ); require_noerr_action( err, exit, dev_if_log("ERROR: Unable to start the USART recv thread.") ); return kNoErr; exit: return err; }
static OSStatus ccrsa_pub_decode_apple(ccrsa_pub_ctx_t pubkey, size_t pkcs1_size, const uint8_t* pkcs1) { OSStatus result = errSecParam; DERItem keyItem = {(DERByte *)pkcs1, pkcs1_size}; DERRSAPubKeyApple decodedKey; require_noerr_action(DERParseSequence(&keyItem, DERNumRSAPubKeyAppleItemSpecs, DERRSAPubKeyAppleItemSpecs, &decodedKey, sizeof(decodedKey)), errOut, result = errSecDecode); // We could honor the recipricol, but we don't think this is used enough to care. // Don't bother exploding the below function to try to handle this case, it computes. require_noerr(ccrsa_pub_init(pubkey, decodedKey.modulus.length, decodedKey.modulus.data, decodedKey.pubExponent.length, decodedKey.pubExponent.data), errOut); result = errSecSuccess; errOut: return result; }
OSStatus startEasyLink( mico_Context_t * const inContext) { easylink_log_trace(); OSStatus err = kUnknownErr; easylinkClient_fd = -1; mico_mcu_powersave_config(true); err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)EasyLinkNotify_WifiStatusHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_WiFI_PARA_CHANGED, (void *)EasyLinkNotify_WiFIParaChangedHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_EASYLINK_COMPLETED, (void *)EasyLinkNotify_EasyLinkCompleteHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_EASYLINK_GET_EXTRA_DATA, (void *)EasyLinkNotify_EasyLinkGetExtraDataHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_DHCP_COMPLETED, (void *)EasyLinkNotify_DHCPCompleteHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)EasyLinkNotify_SYSWillPoerOffHandler ); require_noerr( err, exit ); // Start the EasyLink thread ConfigWillStart(inContext); mico_rtos_init_semaphore(&easylink_sem, 1); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "EASYLINK", easylink_thread, 0x1000, (void*)inContext ); require_noerr_action( err, exit, easylink_log("ERROR: Unable to start the EasyLink thread.") ); exit: return err; }
int application_start( void ) { OSStatus err = kNoErr; IPStatusTypedef para; MicoInit( ); /*The notification message for the registered WiFi status change*/ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler ); require_noerr( err, exit ); err = mico_rtos_init_semaphore(&tcp_sem, 1); require_noerr( err, exit ); connect_ap( ); mico_rtos_get_semaphore(&tcp_sem, MICO_WAIT_FOREVER); micoWlanGetIPStatus(¶, Station); tcp_server_log("tcp server ip: %s", para.ip); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "TCP_server", tcp_server_thread, 0x800, NULL ); require_noerr_action( err, exit, tcp_server_log("ERROR: Unable to start the tcp server thread.") ); return err; exit: tcp_server_log("ERROR, err: %d", err); 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 ) { OSStatus err = kNoErr; is_easylink_success = 0; MicoInit( ); /*The notification message for the registered WiFi status change*/ err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler ); require_noerr( err, exit ); err = MICOAddNotification( mico_notify_EASYLINK_WPS_COMPLETED, (void *)EasyLinkNotify_EasyLinkCompleteHandler ); require_noerr(err, exit); err = MICOAddNotification( mico_notify_EASYLINK_GET_EXTRA_DATA, (void *)EasyLinkNotify_EasyLinkGetExtraDataHandler ); require_noerr(err, exit); // Start the EasyLink thread mico_rtos_init_semaphore(&easylink_sem, 1); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "EASYLINK", easylink_thread, 0x800, NULL ); require_noerr_action( err, exit, wifi_easylink_log("ERROR: Unable to start the EasyLink thread.") ); return err; exit: wifi_easylink_log("ERROR, err: %d", err); return err; }
OSStatus apds9930_sensor_init(void) { OSStatus err = kNoErr; uint8_t device_id; MicoI2cFinalize(&apds_i2c_device); /*int apds9930 sensor i2c device*/ err = MicoI2cInitialize(&apds_i2c_device); require_noerr_action( err, exit, apds9930_log("APDS9930_ERROR: MicoI2cInitialize err = %d.", err) ); if( false == MicoI2cProbeDevice(&apds_i2c_device, 5) ){ apds9930_log("APDS9930_ERROR: no i2c device found!"); err = kNotFoundErr; goto exit; } APDS9930_Clear_intrtrupt(); err = APDS9930_Read_RegData(ID_ADDR, &device_id); require_noerr( err, exit ); if(APDS9930_ID != device_id){ apds9930_log("APDS9930_ERROR: device id err"); err = kNotFoundErr; goto exit; } apds9930_enable(); exit: return err; }
static kern_return_t validate_symbols(KXLDKext *kext) { kern_return_t rval = KERN_FAILURE; KXLDSymtabIterator iter; KXLDSym *sym = NULL; u_int error = FALSE; char *demangled_name = NULL; size_t demangled_length = 0; /* Check for any unresolved symbols */ kxld_symtab_iterator_init(&iter, kxld_object_get_symtab(kext->kext), kxld_sym_is_unresolved, FALSE); while ((sym = kxld_symtab_iterator_get_next(&iter))) { if (!error) { error = TRUE; kxld_log(kKxldLogLinking, kKxldLogErr, "The following symbols are unresolved for this kext:"); } kxld_log(kKxldLogLinking, kKxldLogErr, "\t%s", kxld_demangle(sym->name, &demangled_name, &demangled_length)); } require_noerr_action(error, finish, rval=KERN_FAILURE); rval = KERN_SUCCESS; finish: if (demangled_name) kxld_free(demangled_name, demangled_length); return rval; }
void ConfigSoftApWillStart(mico_Context_t * const inContext ) { OSStatus err; sppProtocolInit(inContext); PlatformUartInitialize(inContext); err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, 0x500, (void*)inContext ); require_noerr_action( err, exit, config_delegate_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, config_delegate_log("ERROR: Unable to start the local server thread.") ); } exit: return; }
int requestqueue_enqueue_server_ping(u_int32_t delay) { int error, error2; webdav_requestqueue_element_t * request_element_ptr; pthread_t request_thread; error = pthread_mutex_lock(&requests_lock); require_noerr_action(error, pthread_mutex_lock, webdav_kill(-1)); request_element_ptr = malloc(sizeof(webdav_requestqueue_element_t)); require_action(request_element_ptr != NULL, malloc_request_element_ptr, error = EIO); request_element_ptr->type = WEBDAV_SERVER_PING_TYPE; request_element_ptr->element.serverping.delay = delay; /* Insert server pings at head of request queue. They must be executed immediately since they are */ /* used to detect when connectivity to the host has been restored. */ request_element_ptr->next = waiting_requests.item_head; ++(waiting_requests.request_count); if ( waiting_requests.item_head == NULL ) { /* request queue was empty */ waiting_requests.item_head = waiting_requests.item_tail = request_element_ptr; } else { /* this request is the new head */ waiting_requests.item_head = request_element_ptr; } if (gIdleThreadCount > 0) { /* Already have one or more threads just waiting for work to do. Just kick the requests_condvar to wake up the threads */ error = pthread_cond_signal(&requests_condvar); require_noerr(error, pthread_cond_signal); } else { /* No idle threads, so try to create one if we have not reached out maximum number of threads */ if (gCurrThreadCount < WEBDAV_REQUEST_THREADS) { error = pthread_create(&request_thread, &gRequest_thread_attr, (void *) handle_request_thread, (void *) NULL); require_noerr(error, pthread_create_signal); gCurrThreadCount += 1; } } pthread_create_signal: pthread_cond_signal: malloc_request_element_ptr: error2 = pthread_mutex_unlock(&requests_lock); require_noerr_action(error2, pthread_mutex_unlock, error = (error == 0) ? error2 : error; webdav_kill(-1)); pthread_mutex_unlock: pthread_mutex_lock: return (error); }
int requestqueue_enqueue_download(struct node_entry *node, struct ReadStreamRec *readStreamRecPtr) { int error, error2; webdav_requestqueue_element_t * request_element_ptr; pthread_t request_thread; error = pthread_mutex_lock(&requests_lock); require_noerr_action(error, pthread_mutex_lock, webdav_kill(-1)); request_element_ptr = malloc(sizeof(webdav_requestqueue_element_t)); require_action(request_element_ptr != NULL, malloc_request_element_ptr, error = EIO); request_element_ptr->type = WEBDAV_DOWNLOAD_TYPE; request_element_ptr->element.download.node = node; request_element_ptr->element.download.readStreamRecPtr = readStreamRecPtr; /* Insert downloads at head of request queue. They must be executed immediately since the download is holding a stream reference. */ request_element_ptr->next = waiting_requests.item_head; ++(waiting_requests.request_count); if ( waiting_requests.item_head == NULL ) { /* request queue was empty */ waiting_requests.item_head = waiting_requests.item_tail = request_element_ptr; } else { /* this request is the new head */ waiting_requests.item_head = request_element_ptr; } if (gIdleThreadCount > 0) { /* Already have one or more threads just waiting for work to do. Just kick the requests_condvar to wake up the threads */ error = pthread_cond_signal(&requests_condvar); require_noerr(error, pthread_cond_signal); } else { /* No idle threads, so try to create one if we have not reached out maximum number of threads */ if (gCurrThreadCount < WEBDAV_REQUEST_THREADS) { error = pthread_create(&request_thread, &gRequest_thread_attr, (void *) handle_request_thread, (void *) NULL); require_noerr(error, pthread_create_signal); gCurrThreadCount += 1; } } pthread_create_signal: pthread_cond_signal: malloc_request_element_ptr: error2 = pthread_mutex_unlock(&requests_lock); require_noerr_action(error2, pthread_mutex_unlock, error = (error == 0) ? error2 : error; webdav_kill(-1)); pthread_mutex_unlock: pthread_mutex_lock: return (error); }