- 易迪拓培训,专注于微波、射频、天线设计工程师的培养
熟悉固件源码
录入:edatop.com 点击:
源码文件还是很多的,先从主函数开始一层层梳理
通篇的os_printf,还有最后的vTaskDelete无不表明了,这涉及到操作系统了
g_cloud_con_para的相关配置,虽然注销掉了,但这可能就是涉及云端的处理部分了
但这不是主函数的开始
由给出的参考流程可知,在往上还有些初始化才对
查找函数调用,确实
xTaskCreate(et_user_main, "et_user_main", 512, NULL, 5, NULL);调用了之前的那个函数
而user_esp_platform_check_ip这个函数也在更上一层的user_init中被调用
xTaskCreate(user_wifi_led_control, "wifi_led_control", 256, NULL, 2, NULL);
xTaskCreate(airkiss_key_poll_task, "smartconfig_task", 256, NULL, 2, NULL);
而user_init这个函数才是整个用户应用程序的开始,
不过再往前的系统初始化部分没找到
从user_init这个函数开始,一层层的,按照参考流程把主体函数给拎出来,从而对整体的源码就有了个初步了解
- void et_user_main(void *pvParameters)
- {
- et_int32 rc = -1;
- et_int32 num = 0;
- id_info_t *id;
- /* g_cloud_con_para.auto_relogin = TRUE;
- g_cloud_con_para.clr_offline_mes = TRUE;
- g_cloud_con_para.server_addr = ADDRESS;
- g_cloud_con_para.server_port = PORT;*/
- os_printf("ET U-SDK var%s\n",et_sdk_var());
-
- to_stop_app = 0;
- id = (id_info_t *)malloc(sizeof(id_info_t));
- if(id == NULL)
- {
- os_printf("et_user_main, malloc id failed\n");
- return ;
- }
-
- memset(id, 0, sizeof(id_info_t));
- if(get_uid(id) != SPI_FLASH_RESULT_OK)
- {
- os_printf("et_user_main, get_uid error\n");
- free(id);
- return ;
- }
-
- g_cloud_handle = et_create_context(id->uid, id->appkey, SECRETKEY);
- if(NULL == g_cloud_handle)
- os_printf("Init et account failed\n");
- et_set_callback(g_cloud_handle,et_message_process, et_event_process);
-
- rc = et_start_svr(g_cloud_handle);
- if(rc != 0)
- {
- os_printf("et_start_svr fail\n");
- }
-
- do
- {
- rc = et_login_cloud(g_cloud_handle, g_cloud_con_para);
- if(rc != 0)
- {
- os_printf("login_cloud fail\n");
- }
- num++;
- vTaskDelay(num*100*portTICK_RATE_MS);
- }while(rc != 0 && num < 3 && to_stop_app == 0);
- if(rc == 0)
- {
- os_printf("now start init friend\n");
- init_clients();
- // rc = et_get_buddies_online(g_cloud_handle);
- rc = et_req_buddies_list(g_cloud_handle, LIST_ONLINE);
- if(rc < 0)
- os_printf("Get online buddies failed\n");
- else
- os_printf("Get online buddies sucess\n");
- rc = et_sub_allbuddies_state(g_cloud_handle);
- if(rc < 0)
- os_printf("Sub all buddies state failed\n");
- else
- os_printf("Sub all buddies state sucess\n");
- }
- free(id);
- vTaskDelete(NULL);
- return ;
- }
通篇的os_printf,还有最后的vTaskDelete无不表明了,这涉及到操作系统了
g_cloud_con_para的相关配置,虽然注销掉了,但这可能就是涉及云端的处理部分了
但这不是主函数的开始
由给出的参考流程可知,在往上还有些初始化才对
查找函数调用,确实
- /******************************************************************************
- * FunctionName : user_esp_platform_check_ip
- * Description : check whether get ip addr or not
- * Parameters : none
- * Returns : none
- *******************************************************************************/
- void ICACHE_FLASH_ATTR
- user_esp_platform_check_ip(void)
- {
- static et_uint32 time = 0;
- struct ip_info ipconfig;
- os_timer_disarm(&test_timer);
- //get ip info of ESP8266 station
- wifi_get_ip_info(STATION_IF, &ipconfig);
- if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0)
- {
- os_printf("got ip ! \r\n");
- user_set_wifi_led_on();
- if (user_main_start_flag == 0)
- {
- user_main_start_flag = 1;
- xTaskCreate(et_user_main, "et_user_main", 512, NULL, 5, NULL);
- }
- wifi_reconnect_start_flag = 1;
- }
- else
- {
- if (wifi_station_get_connect_status() == STATION_WRONG_PASSWORD
- || wifi_station_get_connect_status() == STATION_NO_AP_FOUND
- || wifi_station_get_connect_status() == STATION_CONNECT_FAIL)
- {
- if ((system_get_time() - time) >= 5000000)
- {
- os_printf("connect fail wrong password or ssid wrong! \r\n");
- time = system_get_time();
- }
-
- if (air_kiss_start_flag == 1)
- {
- wifi_station_set_reconnect_policy(false);
- smartconfig_stop();
- air_kiss_start_flag = 0;
- }
- }
-
- //re-arm timer to check ip
- os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
- os_timer_arm(&test_timer, 1000, 0);
- }
- }
xTaskCreate(et_user_main, "et_user_main", 512, NULL, 5, NULL);调用了之前的那个函数
而user_esp_platform_check_ip这个函数也在更上一层的user_init中被调用
- /******************************************************************************
- * FunctionName : user_init
- * Description : entry of user application, init user function here
- * Parameters : none
- * Returns : none
- *******************************************************************************/
- void user_init(void)
- {
- key_gpio_t key;
- struct station_config config;
- struct ip_info info;
- et_uchar result=0;
-
- os_printf("now SDK version:%s\n", system_get_sdk_version());
- if(get_fac_norm_mode(&result) != SPI_FLASH_RESULT_OK)
- {
- os_printf("get_fac_norm_mode error, NORMAL mode\n");
- }
-
- if(result == FAC_MODE)
- {
- os_printf("run in factory mode\n");
- uart_init_new_uart1(BIT_RATE_115200);
- UART_SetPrintPort(UART1);
- uart_init_new(BIT_RATE_9600, result);
- return;
- }
- os_printf("run in normal mode\n");
- // show logo
- user_show_logo();
- if (RETURN_OK != user_get_work_mode(&work_mode))
- {
- os_printf("get work mode fail !\n");
- return;
- }
- if (RETURN_OK != user_init_work_mode(work_mode, result))
- {
- os_printf("init work mode fail !\n");
- return;
- }
- // wifi led control
- xTaskCreate(user_wifi_led_control, "wifi_led_control", 256, NULL, 2, NULL);
- //wifi event handle
- wifi_set_event_handler_cb(et_wifi_event_cb);
-
- memset(&key, 0, sizeof(key_gpio_t));
- key.key_gpio_pin = AIRKISS_KEY_IO_PIN;
- key.key_num = AIRKISS_KEY_IO_NUM;
- airkiss_key_init(&key);
- wifi_set_opmode(STATION_MODE);
- wifi_reconnect_start_flag = 0;
- xTaskCreate(airkiss_key_poll_task, "smartconfig_task", 256, NULL, 2, NULL);
- memset(&config, 0, sizeof(struct station_config));
- if(wifi_station_get_config_default(&config) == true)
- {
- os_printf("ssid=%s\n", config.ssid);
- wifi_station_set_config_current(&config);
- //for static ip set
- /*wifi_station_dhcpc_stop();
- IP4_ADDR(&info.ip, 192, 168, 1, 43);
- IP4_ADDR(&info.gw, 192, 168, 1, 1);
- IP4_ADDR(&info.netmask, 255, 255, 255, 0);
- wifi_set_ip_info(STATION_IF, &info);*/
- }
-
- os_timer_disarm(&test_timer);
- os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
- os_timer_arm(&test_timer, 1000, 0);
- }
xTaskCreate(user_wifi_led_control, "wifi_led_control", 256, NULL, 2, NULL);
xTaskCreate(airkiss_key_poll_task, "smartconfig_task", 256, NULL, 2, NULL);
而user_init这个函数才是整个用户应用程序的开始,
不过再往前的系统初始化部分没找到
从user_init这个函数开始,一层层的,按照参考流程把主体函数给拎出来,从而对整体的源码就有了个初步了解
很好,如果可以把下一篇,上一篇留在片尾的话,可以更方便观看者。
不错 加油
上一篇:一号互联e信WiFi+无线会议案例
下一篇:求大神指点迷津