-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lizhibo
committed
Sep 21, 2018
1 parent
9d1922d
commit 5296c91
Showing
57 changed files
with
9,007 additions
and
8,016 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
build/* | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,94 @@ | ||
# How to use iot-sdk | ||
|
||
|
||
## 1. 简介 | ||
本 sdk 提供一个基于 Linux,通过与 Wi-Fi 模块进行 AT 指令串口通信,实现与阿里云 ILOP 和 sds 直连的 IoT 物联网典型开发应用示例源代码。 | ||
|
||
## 2. 目录结构 | ||
|
||
```c | ||
|---example | ||
| |---ilopicaapp /*ilop平台 ica标准数据格式的demo*/ | ||
| |---iloprawapp /*ilop平台 自定义数据格式的demo*/ | ||
| |---sdsapp /*sds平台的demo*/ | ||
| |---test /*测试demo*/ | ||
| | ||
|---platform | ||
| |---linux /*linux平台相关的接口实现*/ | ||
| |---mx_hal.h | ||
| | ||
|---src | ||
|---alicloud_ilop /*ilop平台的实现*/ | ||
|---alicloud_sds /*sds平台的实现*/ | ||
|---helper /*at指令解析内核*/ | ||
``` | ||
|
||
## 3. Linux 平台开发 | ||
|
||
### 3.1 准备 | ||
|
||
- 串口接入PC,并查询设备,命令:`ls -l /dev/ttyUSB*` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ ls -l /dev/ttyUSB* | ||
crw-rw---- 1 root dialout 188, 0 Sep 3 16:15 /dev/ttyUSB0 | ||
``` | ||
|
||
### 3.2 编译 | ||
iot-sdk 提供四个demo,编译demo的命令格式 `make <demo>` | ||
|
||
- 清除上次的make命令所产生的build文件,命令:`make clean` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ make clean | ||
cleaning... | ||
done | ||
``` | ||
|
||
- 编译测试demo,命令:`make test` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ make test | ||
mkdir build | ||
compiling platform/linux/mx_serial.c | ||
compiling platform/linux/mx_stdio.c | ||
compiling platform/linux/mx_tick.c | ||
compiling platform/linux/mx_uart.c | ||
compiling src/helper/cli/mx_cli.c | ||
compiling src/helper/emhost/ATCmdParser/ATCmdParser.c | ||
compiling src/helper/emhost/emh_alisds.c | ||
compiling src/helper/emhost/emh_arg.c | ||
compiling src/helper/emhost/emh_ilop.c | ||
compiling src/helper/emhost/emh_module.c | ||
compiling src/helper/emhost/emh_wlan.c | ||
compiling src/helper/mx_utils/mx_ringbuffer.c | ||
compiling examples/test/test.c | ||
generating build/iot-test.elf | ||
text data bss dec hex filename | ||
16294 928 3680 20902 51a6 build/iot-test.elf | ||
``` | ||
|
||
- 编译完成后,在build目录下生成 `iot-test.elf` 文件 | ||
|
||
### 3.3 运行 | ||
|
||
- 运行build目录下的elf文件,命令:`./build/iot-test.elf <dev>` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ sudo ./build/iot-test.elf /dev/ttyUSB0 | ||
[sudo] password for parallels: | ||
dev[/dev/ttyUSB0] | ||
open at uart succeed | ||
[APP: test.c: 19] FW version: ilop_AT_v2.1.4 | ||
[APP: test.c: 20] System tick: 757 | ||
``` | ||
|
||
## 4. IoT示例 | ||
|
||
### 4.1 阿里 ilop 平台的标准数据格式demo | ||
|
||
### 4.2 阿里 ilop 平台的透传demo | ||
|
||
## 4. 移植SDK | ||
|
||
- 只需要实现platform/mx_hal.h文件中的函数即可 | ||
# How to use iot-sdk | ||
|
||
|
||
## 1. 简介 | ||
本 sdk 提供一个基于 Linux,通过与 Wi-Fi 模块进行 AT 指令串口通信,实现与阿里云 ILOP 和 sds 直连的 IoT 物联网典型开发应用示例源代码。 | ||
|
||
## 2. 目录结构 | ||
|
||
```c | ||
|---example | ||
| |---ilopicaapp /*ilop平台 ica标准数据格式的demo*/ | ||
| |---iloprawapp /*ilop平台 自定义数据格式的demo*/ | ||
| |---sdsapp /*sds平台的demo*/ | ||
| |---test /*测试demo*/ | ||
| | ||
|---platform | ||
| |---linux /*linux平台相关的接口实现*/ | ||
| |---mx_hal.h | ||
| | ||
|---src | ||
|---alicloud_ilop /*ilop平台的实现*/ | ||
|---alicloud_sds /*sds平台的实现*/ | ||
|---helper /*at指令解析内核*/ | ||
``` | ||
|
||
## 3. Linux 平台开发 | ||
|
||
### 3.1 准备 | ||
|
||
- 串口接入PC,并查询设备,命令:`ls -l /dev/ttyUSB*` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ ls -l /dev/ttyUSB* | ||
crw-rw---- 1 root dialout 188, 0 Sep 3 16:15 /dev/ttyUSB0 | ||
``` | ||
|
||
### 3.2 编译 | ||
iot-sdk 提供四个demo,编译demo的命令格式 `make <demo>` | ||
|
||
- 清除上次的make命令所产生的build文件,命令:`make clean` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ make clean | ||
cleaning... | ||
done | ||
``` | ||
|
||
- 编译测试demo,命令:`make test` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ make test | ||
mkdir build | ||
compiling platform/linux/mx_serial.c | ||
compiling platform/linux/mx_stdio.c | ||
compiling platform/linux/mx_tick.c | ||
compiling platform/linux/mx_uart.c | ||
compiling src/helper/cli/mx_cli.c | ||
compiling src/helper/emhost/ATCmdParser/ATCmdParser.c | ||
compiling src/helper/emhost/emh_alisds.c | ||
compiling src/helper/emhost/emh_arg.c | ||
compiling src/helper/emhost/emh_ilop.c | ||
compiling src/helper/emhost/emh_module.c | ||
compiling src/helper/emhost/emh_wlan.c | ||
compiling src/helper/mx_utils/mx_ringbuffer.c | ||
compiling examples/test/test.c | ||
generating build/iot-test.elf | ||
text data bss dec hex filename | ||
16294 928 3680 20902 51a6 build/iot-test.elf | ||
``` | ||
|
||
- 编译完成后,在build目录下生成 `iot-test.elf` 文件 | ||
|
||
### 3.3 运行 | ||
|
||
- 运行build目录下的elf文件,命令:`./build/iot-test.elf <dev>` | ||
|
||
``` | ||
parallels@parallels-vm:~/iot-sdk$ sudo ./build/iot-test.elf /dev/ttyUSB0 | ||
[sudo] password for parallels: | ||
dev[/dev/ttyUSB0] | ||
open at uart succeed | ||
[APP: test.c: 19] FW version: ilop_AT_v2.1.4 | ||
[APP: test.c: 20] System tick: 757 | ||
``` | ||
|
||
## 4. IoT示例 | ||
|
||
### 4.1 阿里 ilop 平台的标准数据格式demo | ||
|
||
### 4.2 阿里 ilop 平台的透传demo | ||
|
||
## 4. 移植SDK | ||
|
||
- 只需要实现platform/mx_hal.h文件中的函数即可 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
#include "alicloud_ilop.h" | ||
#include "main.h" | ||
#include "mx_cli.h" | ||
#include "mx_common.h" | ||
#include "mx_debug.h" | ||
#include "mx_hal.h" | ||
|
||
static char* err_code = "0"; | ||
static int event_post = 0; | ||
|
||
static unsigned long long uptime_sec(void) | ||
{ | ||
static unsigned long long start_time = 0; | ||
|
||
if (start_time == 0) { | ||
start_time = mx_hal_ms_ticker_read(); | ||
} | ||
|
||
return (mx_hal_ms_ticker_read() - start_time) / 1000; | ||
} | ||
|
||
static mx_status error_code_read_func(char** value) | ||
{ | ||
(*value) = err_code; | ||
app_log("read value:%s", err_code); | ||
return kNoErr; | ||
} | ||
|
||
static const struct ilop_ica_attr_t ErrorCode_event = { ILOP_HANDLE_ATTR_ErrorCode, "Error.ErrorCode", EMH_ARG_ILOP_VT_EVENT, error_code_read_func, NULL }; | ||
|
||
#ifdef MX_CLI_ENABLE | ||
static void handle_event_cmd(char* pwbuf, int blen, int argc, char** argv) | ||
{ | ||
if (argc != 2) | ||
return; | ||
|
||
if (strcmp(argv[1], "enable") == 0) { | ||
event_post = 1; | ||
} else if (strcmp(argv[1], "disable") == 0) { | ||
event_post = 0; | ||
} | ||
} | ||
|
||
static struct cli_command eventcmd = { "event", "event [enable|disable]", handle_event_cmd }; | ||
#endif | ||
|
||
void event_register(void) | ||
{ | ||
ilop_ica_attr_register(&ErrorCode_event); | ||
#ifdef MX_CLI_ENABLE | ||
cli_register_command(&eventcmd); | ||
#endif | ||
} | ||
|
||
void event_task_loop(void) | ||
{ | ||
if (event_post == 0) | ||
return; | ||
|
||
uint32_t now = uptime_sec(); | ||
static uint32_t pre_sec = 0; | ||
|
||
if (pre_sec == now) | ||
return; | ||
|
||
if ((now % 10) == 0) { | ||
app_log("time[%d]", now); | ||
ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_ErrorCode); | ||
} | ||
|
||
pre_sec = now; | ||
} | ||
#include "alicloud_ilop.h" | ||
#include "main.h" | ||
#include "mx_cli.h" | ||
#include "mx_common.h" | ||
#include "mx_debug.h" | ||
#include "mx_hal.h" | ||
|
||
static char* err_code = "0"; | ||
static int event_post = 0; | ||
|
||
static unsigned long long uptime_sec(void) | ||
{ | ||
static unsigned long long start_time = 0; | ||
|
||
if (start_time == 0) { | ||
start_time = mx_hal_ms_ticker_read(); | ||
} | ||
|
||
return (mx_hal_ms_ticker_read() - start_time) / 1000; | ||
} | ||
|
||
static mx_status error_code_read_func(char** value) | ||
{ | ||
(*value) = err_code; | ||
app_log("read value:%s", err_code); | ||
return kNoErr; | ||
} | ||
|
||
static const struct ilop_ica_attr_t ErrorCode_event = { ILOP_HANDLE_ATTR_ErrorCode, "Error.ErrorCode", EMH_ARG_ILOP_VT_EVENT, error_code_read_func, NULL }; | ||
|
||
#ifdef MX_CLI_ENABLE | ||
static void handle_event_cmd(char* pwbuf, int blen, int argc, char** argv) | ||
{ | ||
if (argc != 2) | ||
return; | ||
|
||
if (strcmp(argv[1], "enable") == 0) { | ||
event_post = 1; | ||
} else if (strcmp(argv[1], "disable") == 0) { | ||
event_post = 0; | ||
} | ||
} | ||
|
||
static struct cli_command eventcmd = { "event", "event [enable|disable]", handle_event_cmd }; | ||
#endif | ||
|
||
void event_register(void) | ||
{ | ||
ilop_ica_attr_register(&ErrorCode_event); | ||
#ifdef MX_CLI_ENABLE | ||
cli_register_command(&eventcmd); | ||
#endif | ||
} | ||
|
||
void event_task_loop(void) | ||
{ | ||
if (event_post == 0) | ||
return; | ||
|
||
uint32_t now = uptime_sec(); | ||
static uint32_t pre_sec = 0; | ||
|
||
if (pre_sec == now) | ||
return; | ||
|
||
if ((now % 10) == 0) { | ||
app_log("time[%d]", now); | ||
ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_ErrorCode); | ||
} | ||
|
||
pre_sec = now; | ||
} |
Oops, something went wrong.