AliOS-Things--EMW3060--linkkitapp

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28877125/article/details/82868010

windows10 环境下,编译完成之后下载到模块里面去:

一、编译信息

编译信息如下:

> Executing task: aos make linkkitapp@mk3060 <

aos-cube version: 0.2.60
Check if required tools for mk3060 exist
Build AOS Now
TOOLCHAIN_PATH=D:/Output/AliOS/AliOS-Things/build/compiler/gcc-arm-none-eabi/Win32/bin/
Components: linkkitapp board_mk3060 moc108 vcall kernel_init auto_component linkkit_sdk iotx-hal netmgr framework libywss uOTA cjson cli armv5 newlib_stub rhino yloop kv alicrypto digest_algorithm net framework_runtime app_runtime libprov activation chip_code mbedtls hal log vfs irot vfs_device libkm libplat_gen
Skipping building bootloader due to \"total\" is not set

Making out/linkkitapp@mk3060/ld/mx108.ld
Compiling auto_component
Making out/linkkitapp@mk3060/libraries/auto_component.a
Making [email protected]

Making [email protected]
Making [email protected]

                        AOS MEMORY MAP
|=================================================================|
| MODULE                                   | ROM       | RAM      |
|=================================================================|
| newlib_stub                              | 296       | 0        |
| alicrypto                                | 40100     | 8784     |
| kv                                       | 2929      | 36       |
| libc_nano                                | 29062     | 464      |
| vcall                                    | 6013      | 4        |
| kernel_init                              | 1147      | 48       |
| rhino                                    | 14225     | 7721     |
| libplat_gen                              | 513       | 0        |
| framework                                | 240       | 12       |
| uOTA                                     | 13345     | 858      |
| vfs                                      | 1875      | 1209     |
| digest_algorithm                         | 224       | 0        |
| libgcc                                   | 6168      | 0        |
| linkkitapp                               | 19898     | 22       |
| activation                               | 2743      | 8776     |
| chip_code                                | 298       | 240      |
| libprov                                  | 624       | 0        |
| libywss                                  | 40256     | 1442     |
| yloop                                    | 1421      | 24       |
| board_mk3060                             | 598       | 24       |
| iotx-hal                                 | 7583      | 224      |
| moc108                                   | 346       | 32       |
| armv5                                    | 388       | 0        |
| netmgr                                   | 1823      | 246      |
| libmoc108                                | 165113    | 52761    |
| mbedtls                                  | 27953     | 76       |
| cjson                                    | 1958      | 20       |
| libiot_sdk                               | 373371    | 3172     |
| log                                      | 402       | 20       |
| net                                      | 46165     | 3676     |
| cli                                      | 5945      | 549      |
| hal                                      | 478       | 12       |
| *fill*                                   | 555       | 192      |
|=================================================================|
| TOTAL (bytes)                            | 814055    | 90644    |
|=================================================================|
870468
55a091ce758cbd91d263de6360df4b85
Build complete
Making .gdbinit

内存

ROM:0.81MB
RAM:90.644KB

模组 RAM Flash
EMW3060 256KB 2MB

上电复位之后

enter low level!
mac fc:ee:e6: 8:6c:b7
leave low level!
app_init finished
start-----------hal
trace config close!!!
[000004]<V> aos framework init.
[000004]<V> IOTX_AWSS_START
awss version: smarthome-bd18d6d<DEBUG> [zconfig_init#2115] : awss lib smarthome-bd18d6d

Soft_AP_start
chan 1
[1] ssid:CMCC-WEB, mac:5866ba6f6760, chn:1, auth:open, none, none, rssi:-236, adha:0
[2] ssid:CMCC, mac:5866ba6f6761, chn:1, auth:wpa2-8021x, aes, aes, rssi:-236, adha:0

 由上可知,linkkitapp例程开始之后就会进入配网模式,这在代码中怎么体现的呢?

二、代码分析

1、哪里是入口主函数?

int application_start(int argc, char **argv)
{
    aos_set_log_level(AOS_LL_DEBUG);
    
    printf("Hello liefyuan\r\n");
    
    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;
}

打印了信息,说明确实是以这个函数作为入口的。

enter low level!
mac fc:ee:e6: 8:6c:b7
leave low level!
app_init finished
start-----------hal
trace config close!!!
[000004]<V> aos framework init.
Hello liefyuan
[000004]<V> IOTX_AWSS_START

2、哪里是进入配网模式的?

死办法,如下:

int application_start(int argc, char **argv)
{
    aos_set_log_level(AOS_LL_DEBUG);

    printf("Hello 1\r\n");

    netmgr_init();
    printf("Hello 2\r\n");
    aos_register_event_filter(EV_KEY, linkkit_key_process, NULL);
    printf("Hello 3\r\n");
    aos_register_event_filter(EV_WIFI, wifi_service_event, NULL);
    printf("Hello 4\r\n");
    aos_register_event_filter(EV_YUNIO, cloud_service_event, NULL);
    printf("Hello 5\r\n");

    set_iotx_info();
    printf("Hello 6\r\n");
    aos_task_new("netmgr", start_netmgr, NULL, 4096);
    printf("Hello 7\r\n");

    aos_loop_run();
    printf("Hello 8\r\n");

    return 0;
}

打印信息

trace config close!!!
[000004]<V> aos framework init.
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
[000006]<V> IOTX_AWSS_START
awss version: smarthome-bd18d6d<DEBUG> [zconfig_init#2115] : awss lib smarthome-bd18d6d

Soft_AP_start

可以推测出来,以下就是进入配网模式的函数。

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

3、配网模式函数:aos_task_new(“netmgr”, start_netmgr, NULL, 4096);

看看它的的定义:
 可以看出这是个任务创建函数,有点FreeRTOS的任务创建风格。路径为:AliOS-Things\include\aos\kernel.h

/**
 * Create a task.
 *
 * @param[in]  name       task name.
 * @param[in]  fn         function to run.
 * @param[in]  arg        argument of the function.
 * @param[in]  stacksize  stack-size in bytes.
 *
 * @return  0: success.
 */
int aos_task_new(const char *name, void (*fn)(void *), void *arg, int stack_size);

于是知道了start_netmgr是个函数名字,看看这个函数是咋样的:

static void start_netmgr(void *p)
{
    iotx_event_regist_cb(linkkit_event_monitor);
    netmgr_start(true);
    aos_task_exit(0);
}

从函数名上可以看到,这个函数里面注册了一个事件回调函数:

/**
 * @brief event list used for iotx_regist_event_monitor_cb
 */
enum iotx_event_t {
    IOTX_AWSS_START = 0x1000,       // AWSS start without enbale, just supports device discover
    IOTX_AWSS_ENABLE,               // AWSS enable
    IOTX_AWSS_LOCK_CHAN,            // AWSS lock channel(Got AWSS sync packet)
    IOTX_AWSS_CS_ERR,               // AWSS AWSS checksum is error
    IOTX_AWSS_PASSWD_ERR,           // AWSS decrypt passwd error
    IOTX_AWSS_GOT_SSID_PASSWD,      // AWSS parse ssid and passwd successfully
    IOTX_AWSS_CONNECT_ADHA,         // AWSS try to connnect adha (device discover, router solution)
    IOTX_AWSS_CONNECT_ADHA_FAIL,    // AWSS fails to connect adha
    IOTX_AWSS_CONNECT_AHA,          // AWSS try to connect aha (AP solution)
    IOTX_AWSS_CONNECT_AHA_FAIL,     // AWSS fails to connect aha
    IOTX_AWSS_SETUP_NOTIFY,         // AWSS sends out device setup information (AP and router solution)
    IOTX_AWSS_CONNECT_ROUTER,       // AWSS try to connect destination router
    IOTX_AWSS_CONNECT_ROUTER_FAIL,  // AWSS fails to connect destination router.
    IOTX_AWSS_GOT_IP,               // AWSS connects destination successfully and got ip address
    IOTX_AWSS_SUC_NOTIFY,           // AWSS sends out success notify (AWSS sucess)
    IOTX_AWSS_BIND_NOTIFY,          // AWSS sends out bind notify information to support bind between user and device
    IOTX_CONN_CLOUD = 0x2000,       // Device try to connect cloud
    IOTX_CONN_CLOUD_FAIL,           // Device fails to connect cloud, refer to net_sockets.h for error code
    IOTX_CONN_CLOUD_SUC,            // Device connects cloud successfully
    IOTX_RESET = 0x3000,            // Linkkit reset success (just got reset response from cloud without any other operation)
};

/**
 * @brief register callback to monitor all event from system.
 *             注册监控回调函数来监控所有来自系统的事件
 * @param callback, when some event occurs, the system will trigger callback to user.
 *                  refer to enum iotx_event_t for event list supported.
 *          当有某些时间发生时,系统将触发用户的回调函数,事件列表上列举的事件类型都支持
 * @return 0 when success, -1 when fail.
 * @note: user should make sure that callback is not block and runs to complete fast.
 */
extern int iotx_event_regist_cb(void (*monitor_cb)(int event));

看看事件监视器函数linkkit_event_monitor()是咋样的:

  • linkkit_event_monit函数不能阻塞运行,应该要运行一些能够快速运行的操作
  • 如果用户想要做一些费时的复杂操作,用户应该创建一个任务来做,
  • 而不是在linkkit_event_monit函数中去做复杂操作。
/*
 * Note:
 * the linkkit_event_monitor must not block and should run to complete fast
 * if user wants to do complex operation with much time,
 * user should post one task to do this, not implement complex operation in
 * linkkit_event_monitor
 */

static void linkkit_event_monitor(int event)
{
    switch (event) {
        case IOTX_AWSS_START: // AWSS start without enbale, just supports device
                              // discover
            // operate led to indicate user
            LOG("IOTX_AWSS_START");
            break;
        case IOTX_AWSS_ENABLE: // AWSS enable
            LOG("IOTX_AWSS_ENABLE");
            // operate led to indicate user
            break;
        case IOTX_AWSS_LOCK_CHAN: // AWSS lock channel(Got AWSS sync packet)
            LOG("IOTX_AWSS_LOCK_CHAN");
            // operate led to indicate user
            break;
        case IOTX_AWSS_PASSWD_ERR: // AWSS decrypt passwd error
            LOG("IOTX_AWSS_PASSWD_ERR");
            // operate led to indicate user
            break;
        case IOTX_AWSS_GOT_SSID_PASSWD:
            LOG("IOTX_AWSS_GOT_SSID_PASSWD");
            // operate led to indicate user
            break;
        case IOTX_AWSS_CONNECT_ADHA: // AWSS try to connnect adha (device
                                     // discover, router solution)
            LOG("IOTX_AWSS_CONNECT_ADHA");
            // operate led to indicate user
            break;
        case IOTX_AWSS_CONNECT_ADHA_FAIL: // AWSS fails to connect adha
            LOG("IOTX_AWSS_CONNECT_ADHA_FAIL");
            // operate led to indicate user
            break;
        case IOTX_AWSS_CONNECT_AHA: // AWSS try to connect aha (AP solution)
            LOG("IOTX_AWSS_CONNECT_AHA");
            // operate led to indicate user
            break;
        case IOTX_AWSS_CONNECT_AHA_FAIL: // AWSS fails to connect aha
            LOG("IOTX_AWSS_CONNECT_AHA_FAIL");
            // operate led to indicate user
            break;
        case IOTX_AWSS_SETUP_NOTIFY: // AWSS sends out device setup information
                                     // (AP and router solution)
            LOG("IOTX_AWSS_SETUP_NOTIFY");
            // operate led to indicate user
            break;
        case IOTX_AWSS_CONNECT_ROUTER: // AWSS try to connect destination router
            LOG("IOTX_AWSS_CONNECT_ROUTER");
            // operate led to indicate user
            break;
        case IOTX_AWSS_CONNECT_ROUTER_FAIL: // AWSS fails to connect destination
                                            // router.
            LOG("IOTX_AWSS_CONNECT_ROUTER_FAIL");
            // operate led to indicate user
            break;
        case IOTX_AWSS_GOT_IP: // AWSS connects destination successfully and got
                               // ip address
            LOG("IOTX_AWSS_GOT_IP");
            // operate led to indicate user
            break;
        case IOTX_AWSS_SUC_NOTIFY: // AWSS sends out success notify (AWSS
                                   // sucess)
            LOG("IOTX_AWSS_SUC_NOTIFY");
            // operate led to indicate user
            break;
        case IOTX_AWSS_BIND_NOTIFY: // AWSS sends out bind notify information to
                                    // support bind between user and device
            LOG("IOTX_AWSS_BIND_NOTIFY");
            // operate led to indicate user
            break;
        case IOTX_CONN_CLOUD: // Device try to connect cloud
            LOG("IOTX_CONN_CLOUD");
            // operate led to indicate user
            break;
        case IOTX_CONN_CLOUD_FAIL: // Device fails to connect cloud, refer to
                                   // net_sockets.h for error code
            LOG("IOTX_CONN_CLOUD_FAIL");
            // operate led to indicate user
            break;
        case IOTX_CONN_CLOUD_SUC: // Device connects cloud successfully
            LOG("IOTX_CONN_CLOUD_SUC");
            // operate led to indicate user
            break;
        case IOTX_RESET: // Linkkit reset success (just got reset response from
                         // cloud without any other operation)
            LOG("IOTX_RESET");
            // operate led to indicate user
            break;
        default:
            break;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_28877125/article/details/82868010