AliOS-Things--linkkitapp (5)看源码笔记

一、主函数解析

1、工程入口函数:application_start()

int application_start(int argc, char **argv)
{
#ifdef CONFIG_PRINT_HEAP
    print_heap();
    aos_post_delayed_action(5000, duration_work, NULL);
#endif

#ifdef CSP_LINUXHOST
    signal(SIGPIPE, SIG_IGN);
#endif

#if AOS_ATCMD
    at.set_mode(ASYN);
    at.init(AT_RECV_PREFIX, AT_RECV_SUCCESS_POSTFIX, AT_RECV_FAIL_POSTFIX,
            AT_SEND_DELIMITER, 1000);
#endif

#ifdef WITH_SAL
    sal_init();
#endif

    aos_set_log_level(AOS_LL_NONE);
    netmgr_init();
    aos_register_event_filter(EV_KEY, linkkit_key_process, NULL);
    aos_register_event_filter(EV_WIFI, wifi_service_event, NULL);
    aos_register_event_filter(EV_YUNIO, cloud_service_event, NULL);

#ifdef CONFIG_AOS_CLI
    aos_cli_register_command(&resetcmd);
    aos_cli_register_command(&ncmd);
#endif

    set_iotx_info();
    aos_task_new("netmgr", start_netmgr, NULL, 4096);
    aos_loop_run();

    return 0;
}

2、条件编译是个啥?

 在入口函数中一共有5个条件编译

  • CONFIG_PRINT_HEAP:打印堆信息
  • CSP_LINUXHOST:
  • AOS_ATCMD:AT指令功能
  • WITH_SAL:AliOS Things网络适配框架 - SAL
  • CONFIG_AOS_CLI:CLI调试功能

3、纯粹的代码

int application_start(int argc, char **argv)
{
    aos_set_log_level(AOS_LL_NONE);
    netmgr_init();
    aos_register_event_filter(EV_KEY, linkkit_key_process, NULL);
    aos_register_event_filter(EV_WIFI, wifi_service_event, NULL);
    aos_register_event_filter(EV_YUNIO, cloud_service_event, NULL);
    
    set_iotx_info();
    aos_task_new("netmgr", start_netmgr, NULL, 4096);
    aos_loop_run();

    return 0;
}
  • aos_set_log_level(AOS_LL_NONE):设置AOS的日志打印水平
    • AOS_LL_NONE:关闭日志
    • AOS_LL_FATAL:输出致命日志
    • AOS_LL_ERROR:输出致命日志加错误日志
    • AOS_LL_WARN:输出致命日志、错误和警告的日志 (默认日志水平)
    • AOS_LL_INFO:输出信息、警告和错误日志
    • AOS_LL_DEBUG:输出调试、信息、警告、错误、致命日志
  • netmgr_init():这里其实也是个条件编译,编译条件是:NET_WITH_WIFI
  • aos_register_event_filter(EV_KEY, linkkit_key_process, NULL):按键点击事件,处理进程,事件过滤器
  • aos_register_event_filter(EV_WIFI, wifi_service_event, NULL):WiFi连接事件,处理进程,事件过滤
  • aos_register_event_filter(EV_YUNIO, cloud_service_event, NULL):云平台连接事件,处理进程,事件过滤
  • set_iotx_info():设置产品的四元组:PK、PS、DN、DS
  • aos_task_new("netmgr", start_netmgr, NULL, 4096):创建一个任务“netmgr”
  • aos_loop_run():进入loop循环

二、函数解析

1、aos_register_event_filter

声明:

/**
 * Register system event filter callback.
 *
 * @param[in]  type  event type interested.
 * @param[in]  cb    system event callback.
 * @param[in]  priv  private data past to cb.
 *
 * @return  the operation status, 0 is OK, others is error.
 */
int aos_register_event_filter(uint16_t type, aos_event_cb cb, void *priv);

定义:

int aos_register_event_filter(uint16_t type, aos_event_cb cb, void *priv)
{
    return SYS_CALL3(SYS_REGISTER_EVENT_FILTER, int, uint16_t, type,
                     aos_event_cb, cb, void *, priv);
}

2、aos_task_new

3、aos_loop_run

你可能感兴趣的:(C)