在实际的应用开发中,用户需要用到大量的功能组件,才能完成最终应用的开发,本文将向用户介绍如何高效地在您的AliOS Things应用中加入功能组件。
以现有的helloworld为模板,创建基于developerkit的工程,工程目录在当前目录的tmp里,工程名称为myapp。
# 创建工程
$ aos create project -b developerkit -t helloworld -d tmp myapp
# 进入工程目录
$ cd tmp/myapp
# 编译
$ aos make
编译完成后,可以看到当前工程所用到的所有组件。
AOS MEMORY MAP
|=================================================================|
| MODULE | ROM | RAM |
|=================================================================|
| arch_armv7m | 292 | 0 |
| at | 4458 | 421 |
| board_developerkit | 5667 | 1519 |
| device_sal_bk7231 | 8252 | 317 |
| kernel_init | 94 | 0 |
| kv | 1753 | 24 |
| libc_nano | 14157 | 464 |
| libgcc | 3280 | 0 |
| mcu_stm32l4xx_cube | 23848 | 7709 |
| myapp | 83 | 0 |
| netmgr | 62 | 8 |
| newlib_stub | 306 | 0 |
| osal_aos | 698 | 0 |
| rhino | 11997 | 7910 |
| sal | 68 | 4 |
| ulog | 377 | 7 |
| vfs | 1160 | 1113 |
| yloop | 1514 | 32 |
| *fill* | 138 | 1580 |
|=================================================================|
| TOTAL (bytes) | 78204 | 21108 |
|=================================================================|
下载程序 ./out/myapp@developerkit/binary/myapp@developerkit.bin
并运行,可通过串口看到设备端运行的日志。
Welcome to AliOS Things
nano entry here!
hello world! count 0
hello world! count 1
hello world! count 2
hello world! count 3
hello world! count 4
hello world! count 5
hello world! count 6
hello world! count 7
添加新的组件
在用户代码里面使用 #include
引入组件的头文件,如增加cjson组件。
打开helloworld.c文件,按下面提示信息加入头文件 cJSON.h
及调用相应的API cJSON_Version()
。
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <aos/kernel.h>
#include <cJSON.h> // 改动1,增加组件头文件
int application_start(int argc, char *argv[])
{
int count = 0;
printf("nano entry here!\r\n");
while(1) {
printf("hello world! count %d \r\n", count++);
printf("add new component\n"); // 改动2,增加日志
printf("cjson version is %s\n", cJSON_Version()); // 通过串口日志打印cJSON版本号
aos_msleep(1000);
};
}
使用
aos make
命令编译,重新生成可执行程序,可以看到cJSON组件已被自动包含进来。
AOS MEMORY MAP
|=================================================================|
| MODULE | ROM | RAM |
|=================================================================|
| arch_armv7m | 292 | 0 |
| at | 4458 | 421 |
| board_developerkit | 5667 | 1519 |
| cjson | 45 | 15 |
| device_sal_bk7231 | 8252 | 317 |
| kernel_init | 94 | 0 |
| kv | 1753 | 24 |
| libc_nano | 14221 | 464 |
| libgcc | 3280 | 0 |
| mcu_stm32l4xx_cube | 23848 | 7709 |
| myapp | 154 | 0 |
| netmgr | 62 | 8 |
| newlib_stub | 306 | 0 |
| osal_aos | 698 | 0 |
| rhino | 11997 | 7910 |
| sal | 68 | 4 |
| ulog | 377 | 7 |
| vfs | 1160 | 1113 |
| yloop | 1514 | 32 |
| *fill* | 126 | 1581 |
|=================================================================|
| TOTAL (bytes) | 78372 | 21124 |
|=================================================================|
重新下载程序并运行后,可以从设备串口日志中看到组件的版本号。
Welcome to AliOS Things
nano entry here!
hello world! count 0
add new component
cjson version is 1.6.0
hello world! count 1
add new component
cjson version is 1.6.0
hello world! count 2
add new component
cjson version is 1.6.0
hello world! count 3
add new component
cjson version is 1.6.0
配置组件
更多的配置操作请参考《更多配置操作》。
视频演示

在文档使用中是否遇到以下问题
更多建议
匿名提交