源码文件还是很多的,先从主函数开始一层层梳理
- 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%sn",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 failedn");
- return ;
- }
-
- memset(id, 0, sizeof(id_info_t));
- if(get_uid(id) != SPI_FLASH_RESULT_OK)
- {
- os_printf("et_user_main, get_uid errorn");
- free(id);
- return ;
- }
-
- g_cloud_handle = et_create_context(id->uid, id->appkey, SECRETKEY);
- if(NULL == g_cloud_handle)
- os_printf("Init et account failedn");
- 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 failn");
- }
-
- do
- {
- rc = et_login_cloud(g_cloud_handle, g_cloud_con_para);
- if(rc != 0)
- {
- os_printf("login_cloud failn");
- }
- num++;
- vTaskDelay(num*100*porttiCK_RATE_MS);
- }while(rc != 0 && num < 3 && to_stop_app == 0);
- if(rc == 0)
- {
- os_printf("now start init friendn");
- 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 failedn");
- else
- os_printf("Get online buddies sucessn");
- rc = et_sub_allbuddies_state(g_cloud_handle);
- if(rc < 0)
- os_printf("Sub all buddies state failedn");
- else
- os_printf("Sub all buddies state sucessn");
- }
- 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 !!! rn");
- 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!!! rn");
- 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);
- }
- }
复制代码
果然是更深一层的操作系统部分,定时器设定、wifi状态设定、是否建立应用层主函数
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:%sn", system_get_sdk_version());
- if(get_fac_norm_mode(&result) != SPI_FLASH_RESULT_OK)
- {
- os_printf("get_fac_norm_mode error, NORMAL moden");
- }
-
- if(result == FAC_MODE)
- {
- os_printf("run in factory moden");
- uart_init_new_uart1(BIT_RATE_115200);
- UART_SetPrintPort(UART1);
- uart_init_new(BIT_RATE_9600, result);
- return;
- }
- os_printf("run in normal moden");
- // 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=%sn", 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);
- }
复制代码
在这一层对当前进度信息包括SDK的版本等不断输出,分别创建任务处理wifi控制led的和按键配置,并且具体的像GPIO的配制、wifi参数的配制、操作系统定时器的设置等底层基础 的进行了设置
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这个函数开始,一层层的,按照参考流程把主体函数给拎出来,从而对整体的源码就有了个初步了解
0
|
|
|
|