├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── examples ├── ilopicaapp │ ├── app_event.c │ ├── app_prop.c │ ├── app_service.c │ ├── ilopmain.c │ ├── main.c │ └── main.h ├── iloprawapp │ ├── app_event.c │ ├── app_prop_light.c │ ├── app_prop_wifi.c │ ├── app_service.c │ ├── ilopmain.c │ ├── main.c │ └── main.h ├── qlinkapp │ ├── main.c │ └── user_qlink_include.h ├── sdsapp │ ├── sdsapp.c │ └── sdsapp.mk └── test │ └── test.c ├── platform ├── linux │ ├── mx_serial.c │ ├── mx_stdio.c │ ├── mx_tick.c │ └── mx_uart.c └── mx_hal.h ├── resource ├── common │ ├── 串口调试工具 │ │ └── SecureCRT.zip │ ├── 数据手册 │ │ ├── DS0021CN_EMW3031_V1.5.pdf │ │ ├── DS0069CN_EMW3080(AB)_V1.8.pdf │ │ ├── DS0089CN_EMW3060_V1.8.pdf │ │ └── DS0122CN_EMW3080V2_V1.2.pdf │ └── 烧录 │ │ ├── 3060 │ │ └── 3060固件烧录方法.docx │ │ ├── 3080 │ │ ├── EMW3080使用debug烧录方法.pdf │ │ └── MXCHIP_MP_TOOLS_V1.1 │ │ │ ├── MXCHIP_IMG_TOOL_RESET.exe │ │ │ ├── MXCHIP_MP_TOOLS.exe │ │ │ ├── MXCHIP_MP_TOOLS.lnk │ │ │ ├── README!!!.txt │ │ │ ├── horn@mx1290@moc.all.bin │ │ │ ├── mpate.dll │ │ │ └── mpimg.dll │ │ └── 3080.rar └── qlink │ ├── 1.本地网关 │ ├── 中国移动And-link协议规范(设备本地网关管理分册)v3.1.docx │ ├── 杭研入库测试工具 │ │ ├── AndlinkDiagnotorIL_64_20180620.exe │ │ ├── Californium.properties │ │ ├── conf │ │ │ ├── internetModelGWInfo.json │ │ │ └── log4j.properties │ │ ├── error.log │ │ └── logs │ │ │ └── log.log │ ├── 火狐浏览器coap工具OTA说明 │ │ ├── Firefox Setup 50.1.0.exe │ │ ├── copper_ota.txt │ │ ├── debug │ │ │ └── test_by_copper │ │ │ │ └── copper_ota.txt │ │ └── 火狐coap工具OTA说明.docx │ └── 虚拟开发环境 │ │ ├── app │ │ ├── Readme.txt │ │ └── andlinkdemo1.0.apk │ │ ├── virtual_gateway │ │ ├── Andlink模拟网关使用说明v2.2.pdf │ │ ├── Californium.properties │ │ ├── Temp │ │ │ └── 005056C00008-tcp112139620521883 │ │ │ │ └── .lck │ │ ├── andlink2.10-05.29-64bit.exe │ │ ├── andlinkPlugins.log │ │ ├── db │ │ │ ├── andlink.lck │ │ │ ├── andlink.log │ │ │ ├── andlink.properties │ │ │ └── andlink.script │ │ ├── jsonFiles │ │ │ ├── IfEncrypt.json │ │ │ ├── SyncCode.json │ │ │ ├── Version.json │ │ │ ├── WiFiParameterSync.json │ │ │ └── ssid.json │ │ ├── log.properties │ │ └── log4j.properties │ │ ├── ~$开发环境使用说明书.docx │ │ └── 虚拟开发环境使用说明书.docx │ ├── 2.云网关 │ ├── app │ │ ├── ios_app.jpg │ │ ├── readme.txt │ │ └── 和家亲99版本.png │ └── 中国移动And-link协议规范(设备云网关管理分册)v2.0.docx │ ├── 3.AT指令 │ ├── HOST端demo使用说明.pdf │ ├── at_qlink.bsp │ ├── qlink_AT_command.md │ ├── 固件 │ │ ├── EMW3080BP-0000.QLINK.A102.zip │ │ ├── MOC108_0000.QLINK.A212.zip │ │ ├── MOC108_0000.QLINK.A213.zip │ │ ├── MOC108_0000.QLINK.A214.zip │ │ ├── MOC108_0000.QLINK.A215.zip │ │ ├── MOC108_9600.QLINK.A215.zip │ │ ├── MX1290-0000.QLINK.A220.zip │ │ ├── MX1290-9600.QLINK.A220.zip │ │ ├── MX1290_9600.QLINK.A212.zip │ │ └── readme.txt │ └── 杭研AT指令使用说明.pdf │ ├── 4.其他 │ ├── code.txt │ └── 杭研AT固件分享交流.pptx │ ├── image │ ├── bind_ok.png │ ├── cli_uart.png │ ├── control_data.png │ ├── request_all_data.png │ ├── request_some_data.png │ ├── user_config.png │ ├── 产品资料.png │ └── 环境OK.png │ └── readme.txt └── src ├── alicloud_ilop ├── alicloud_ilop.c ├── alicloud_ilop.h ├── ica_protocol.c ├── ica_protocol.h ├── raw_protocol.c └── raw_protocol.h ├── alicloud_sds ├── alicloud_sds.c └── alicloud_sds.h ├── cloud_qlink ├── cloud_qlink.c └── cloud_qlink.h └── helper ├── cli ├── mx_cli.c └── mx_cli.h ├── emhost ├── ATCmdParser │ ├── ATCmdParser.c │ ├── ATCmdParser.h │ └── ATCmdParserTest.c ├── emh_alisds.c ├── emh_api.h ├── emh_arg.c ├── emh_arg.h ├── emh_ilop.c ├── emh_module.c ├── emh_qlink.c └── emh_wlan.c ├── jsmn ├── jsmn.c ├── jsmn.h ├── json_escape_str.c ├── json_escape_str.h ├── json_generator.c ├── json_generator.h ├── json_parser.h ├── json_utils.c ├── json_utils.h └── json_wrappers.c ├── mx_common.h ├── mx_debug.h ├── mx_opt.h ├── mx_toolchain.h └── mx_utils ├── mx_ringbuffer.c └── mx_ringbuffer.h /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ###################################### 2 | # target 3 | ###################################### 4 | .PHONY:test ilopicaapp iloprawapp sdsapp 5 | 6 | ###################################### 7 | # building variables 8 | ###################################### 9 | # debug build? 10 | DEBUG = 1 11 | # optimization 12 | OPT = -Og 13 | 14 | 15 | ####################################### 16 | # paths 17 | ####################################### 18 | # firmware library path 19 | PERIFLIB_PATH = 20 | 21 | # Build path 22 | BUILD_DIR = build 23 | 24 | ###################################### 25 | # source 26 | ###################################### 27 | # C sources 28 | C_SOURCES = \ 29 | platform/linux/mx_serial.c \ 30 | platform/linux/mx_stdio.c \ 31 | platform/linux/mx_tick.c \ 32 | platform/linux/mx_uart.c \ 33 | src/helper/cli/mx_cli.c \ 34 | src/helper/emhost/ATCmdParser/ATCmdParser.c \ 35 | src/helper/emhost/emh_alisds.c \ 36 | src/helper/emhost/emh_arg.c \ 37 | src/helper/emhost/emh_ilop.c \ 38 | src/helper/emhost/emh_qlink.c \ 39 | src/helper/emhost/emh_module.c \ 40 | src/helper/emhost/emh_wlan.c \ 41 | src/helper/mx_utils/mx_ringbuffer.c 42 | 43 | 44 | # ASM sources 45 | ASM_SOURCES = 46 | 47 | 48 | ###################################### 49 | # firmware library 50 | ###################################### 51 | PERIFLIB_SOURCES = 52 | 53 | 54 | ####################################### 55 | # binaries 56 | ####################################### 57 | BINPATH = 58 | PREFIX = 59 | CC = $(PREFIX)gcc 60 | AS = $(PREFIX)gcc -x assembler-with-cpp 61 | CP = $(PREFIX)objcopy 62 | AR = $(PREFIX)ar 63 | SZ = $(PREFIX)size 64 | HEX = $(CP) -O ihex 65 | BIN = $(CP) -O binary -S 66 | 67 | ####################################### 68 | # CFLAGS 69 | ####################################### 70 | # cpu 71 | CPU = 72 | 73 | # fpu 74 | FPU = 75 | 76 | # float-abi 77 | FLOAT-ABI = 78 | 79 | # mcu 80 | MCU = 81 | 82 | # macros for gcc 83 | # AS defines 84 | AS_DEFS = 85 | 86 | # C defines 87 | C_DEFS = -DMX_DEBUG -DMX_CLI_ENABLE 88 | 89 | # AS includes 90 | AS_INCLUDES = 91 | 92 | 93 | # C includes 94 | C_INCLUDES = \ 95 | -Iplatform \ 96 | -Isrc/helper/cli \ 97 | -Isrc/helper/emhost/ATCmdParser \ 98 | -Isrc/helper/emhost \ 99 | -Isrc/helper/mx_utils \ 100 | -Isrc/helper 101 | 102 | 103 | # compile gcc flags 104 | ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections 105 | 106 | CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections 107 | 108 | ifeq ($(DEBUG), 1) 109 | CFLAGS += -g -gdwarf-2 110 | endif 111 | 112 | # Generate dependency information 113 | CFLAGS += -MMD 114 | 115 | 116 | ####################################### 117 | # LDFLAGS 118 | ####################################### 119 | 120 | # libraries 121 | LIBS = 122 | LIBDIR = 123 | LDFLAGS = -lpthread -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections 124 | 125 | ####################################### 126 | # TARGET 127 | ####################################### 128 | ifeq (test,$(findstring test,$(MAKECMDGOALS))) 129 | TARGET = iot-test 130 | C_SOURCES += examples/test/test.c 131 | endif 132 | 133 | ifeq (ilopicaapp,$(findstring ilopicaapp,$(MAKECMDGOALS))) 134 | TARGET = iot-ilopicaapp 135 | C_SOURCES += examples/ilopicaapp/app_event.c \ 136 | examples/ilopicaapp/app_prop.c \ 137 | examples/ilopicaapp/app_service.c \ 138 | examples/ilopicaapp/ilopmain.c \ 139 | examples/ilopicaapp/main.c \ 140 | src/alicloud_ilop/alicloud_ilop.c \ 141 | src/alicloud_ilop/ica_protocol.c 142 | 143 | C_INCLUDES += -Iexamples/ilopicaapp -Isrc/alicloud_ilop 144 | 145 | CFLAGS += -DAT_SUPPORT_ILOP -DILOP_USE_ICA 146 | endif 147 | 148 | ifeq (iloprawapp,$(findstring iloprawapp,$(MAKECMDGOALS))) 149 | TARGET = iot-iloprawapp 150 | C_SOURCES += examples/iloprawapp/app_event.c \ 151 | examples/iloprawapp/app_prop_light.c \ 152 | examples/iloprawapp/app_prop_wifi.c \ 153 | examples/iloprawapp/app_service.c \ 154 | examples/iloprawapp/ilopmain.c \ 155 | examples/iloprawapp/main.c \ 156 | src/alicloud_ilop/alicloud_ilop.c \ 157 | src/alicloud_ilop/raw_protocol.c 158 | 159 | C_INCLUDES += -Iexamples/iloprawapp -Isrc/alicloud_ilop 160 | 161 | CFLAGS += -DAT_SUPPORT_ILOP -DILOP_USE_RAW 162 | endif 163 | 164 | ifeq (sdsapp,$(findstring sdsapp,$(MAKECMDGOALS))) 165 | TARGET = iot-sdsapp 166 | C_SOURCES += examples/sdsapp/sdsapp.c \ 167 | src/alicloud_sds/alicloud_sds.c \ 168 | src/helper/jsmn/jsmn.c \ 169 | src/helper/jsmn/json_escape_str.c \ 170 | src/helper/jsmn/json_generator.c \ 171 | src/helper/jsmn/json_utils.c \ 172 | src/helper/jsmn/json_wrappers.c 173 | 174 | C_INCLUDES += -Isrc/alicloud_sds -Isrc/helper/jsmn 175 | 176 | CFLAGS += -DAT_SUPPORT_ALISDS 177 | endif 178 | 179 | ifeq (qlinkapp,$(findstring qlinkapp,$(MAKECMDGOALS))) 180 | TARGET = iot-qlinkapp 181 | C_SOURCES += examples/qlinkapp/main.c \ 182 | src/cloud_qlink/cloud_qlink.c \ 183 | src/helper/jsmn/jsmn.c \ 184 | src/helper/jsmn/json_escape_str.c \ 185 | src/helper/jsmn/json_generator.c \ 186 | src/helper/jsmn/json_utils.c \ 187 | src/helper/jsmn/json_wrappers.c 188 | 189 | C_INCLUDES += -Iexamples/qlinkapp -Isrc/cloud_qlink -Isrc/helper/jsmn 190 | 191 | CFLAGS += -DAT_SUPPORT_QLINK -DQLINK_USE_JSON 192 | endif 193 | 194 | # default action: build all 195 | all test ilopicaapp iloprawapp sdsapp qlinkapp: $(BUILD_DIR)/$(TARGET).elf 196 | 197 | ####################################### 198 | # build the application 199 | ####################################### 200 | # list of objects 201 | OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) 202 | vpath %.c $(sort $(dir $(C_SOURCES))) 203 | # list of ASM program objects 204 | OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) 205 | vpath %.s $(sort $(dir $(ASM_SOURCES))) 206 | 207 | -include $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.d))) 208 | 209 | $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 210 | @echo compiling $< 211 | @$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ 212 | 213 | $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) 214 | @echo compiling $< 215 | @$(AS) -c $(CFLAGS) $< -o $@ 216 | 217 | $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile 218 | @echo generating $@ 219 | @$(CC) $(OBJECTS) $(LDFLAGS) -o $@ 220 | @$(SZ) $@ 221 | 222 | $(BUILD_DIR): 223 | mkdir $@ 224 | 225 | ####################################### 226 | # clean up 227 | ####################################### 228 | clean: 229 | @echo cleaning... 230 | @-rm -fR .dep $(BUILD_DIR) 231 | @echo done 232 | 233 | ####################################### 234 | # dependencies 235 | ####################################### 236 | # -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) 237 | 238 | # *** EOF *** 239 | -------------------------------------------------------------------------------- /examples/ilopicaapp/app_event.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_cli.h" 4 | #include "mx_common.h" 5 | #include "mx_debug.h" 6 | #include "mx_hal.h" 7 | 8 | static char* err_code = "0"; 9 | static int event_post = 0; 10 | 11 | static unsigned long long uptime_sec(void) 12 | { 13 | static unsigned long long start_time = 0; 14 | 15 | if (start_time == 0) { 16 | start_time = mx_hal_ms_ticker_read(); 17 | } 18 | 19 | return (mx_hal_ms_ticker_read() - start_time) / 1000; 20 | } 21 | 22 | static mx_status error_code_read_func(char** value) 23 | { 24 | (*value) = err_code; 25 | app_log("read value:%s", err_code); 26 | return kNoErr; 27 | } 28 | 29 | 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 }; 30 | 31 | #ifdef MX_CLI_ENABLE 32 | static void handle_event_cmd(char* pwbuf, int blen, int argc, char** argv) 33 | { 34 | if (argc != 2) 35 | return; 36 | 37 | if (strcmp(argv[1], "enable") == 0) { 38 | event_post = 1; 39 | } else if (strcmp(argv[1], "disable") == 0) { 40 | event_post = 0; 41 | } 42 | } 43 | 44 | static struct cli_command eventcmd = { "event", "event [enable|disable]", handle_event_cmd }; 45 | #endif 46 | 47 | void event_register(void) 48 | { 49 | ilop_ica_attr_register(&ErrorCode_event); 50 | #ifdef MX_CLI_ENABLE 51 | cli_register_command(&eventcmd); 52 | #endif 53 | } 54 | 55 | void event_task_loop(void) 56 | { 57 | if (event_post == 0) 58 | return; 59 | 60 | uint32_t now = uptime_sec(); 61 | static uint32_t pre_sec = 0; 62 | 63 | if (pre_sec == now) 64 | return; 65 | 66 | if ((now % 10) == 0) { 67 | app_log("time[%d]", now); 68 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_ErrorCode); 69 | } 70 | 71 | pre_sec = now; 72 | } 73 | -------------------------------------------------------------------------------- /examples/ilopicaapp/app_prop.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_common.h" 4 | #include "mx_debug.h" 5 | 6 | typedef struct _app_prop_t { 7 | char switch_status[2]; 8 | char color_temp[5]; 9 | char rgb_red[4]; 10 | char rgb_green[4]; 11 | char rgb_blue[4]; 12 | } app_prop_t; 13 | 14 | static app_prop_t prop; 15 | 16 | static mx_status light_switch_write_func(char* value) 17 | { 18 | strcpy(prop.switch_status, value); 19 | app_log("write LightSwitch:%s", prop.switch_status); 20 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_LightSwitch); 21 | return kNoErr; 22 | } 23 | 24 | static mx_status light_switch_read_func(char** value) 25 | { 26 | (*value) = prop.switch_status; 27 | app_log("read LightSwitch:%s", prop.switch_status); 28 | return kNoErr; 29 | } 30 | 31 | static mx_status color_temp_write_func(char* value) 32 | { 33 | strcpy(prop.color_temp, value); 34 | app_log("write ColorTemperature:%s", prop.color_temp); 35 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_ColorTemperature); 36 | return kNoErr; 37 | } 38 | 39 | static mx_status color_temp_read_func(char** value) 40 | { 41 | (*value) = prop.color_temp; 42 | app_log("read ColorTemperature:%s", prop.color_temp); 43 | return kNoErr; 44 | } 45 | 46 | static mx_status rgb_red_write_func(char* value) 47 | { 48 | strcpy(prop.rgb_red, value); 49 | app_log("write R:%s", prop.rgb_red); 50 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_RGBColor_Red); 51 | return kNoErr; 52 | } 53 | 54 | static mx_status rgb_red_read_func(char** value) 55 | { 56 | (*value) = prop.rgb_red; 57 | app_log("read R:%s", prop.rgb_red); 58 | return kNoErr; 59 | } 60 | 61 | static mx_status rgb_green_write_func(char* value) 62 | { 63 | strcpy(prop.rgb_green, value); 64 | app_log("write G:%s", prop.rgb_green); 65 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_RGBColor_Green); 66 | return kNoErr; 67 | } 68 | 69 | static mx_status rgb_green_read_func(char** value) 70 | { 71 | (*value) = prop.rgb_green; 72 | app_log("read G:%s", prop.rgb_green); 73 | return kNoErr; 74 | } 75 | 76 | static mx_status rgb_blue_write_func(char* value) 77 | { 78 | strcpy(prop.rgb_blue, value); 79 | app_log("write B:%s", prop.rgb_blue); 80 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_RGBColor_Blue); 81 | return kNoErr; 82 | } 83 | 84 | static mx_status rgb_blue_read_func(char** value) 85 | { 86 | (*value) = prop.rgb_blue; 87 | app_log("read B:%s", prop.rgb_blue); 88 | return kNoErr; 89 | } 90 | 91 | static const struct ilop_ica_attr_t LightSwitch_property = { ILOP_HANDLE_ATTR_LightSwitch, "LightSwitch", EMH_ARG_ILOP_VT_PROPERTY, light_switch_read_func, light_switch_write_func }; 92 | static const struct ilop_ica_attr_t ColorTemperature_property = { ILOP_HANDLE_ATTR_ColorTemperature, "ColorTemperature", EMH_ARG_ILOP_VT_PROPERTY, color_temp_read_func, color_temp_write_func }; 93 | static const struct ilop_ica_attr_t RGBColor_Red_property = { ILOP_HANDLE_ATTR_RGBColor_Red, "RGBColor.Red", EMH_ARG_ILOP_VT_PROPERTY, rgb_red_read_func, rgb_red_write_func }; 94 | static const struct ilop_ica_attr_t RGBColor_Green_property = { ILOP_HANDLE_ATTR_RGBColor_Green, "RGBColor.Green", EMH_ARG_ILOP_VT_PROPERTY, rgb_green_read_func, rgb_green_write_func }; 95 | static const struct ilop_ica_attr_t RGBColor_Blue_property = { ILOP_HANDLE_ATTR_RGBColor_Blue, "RGBColor.Blue", EMH_ARG_ILOP_VT_PROPERTY, rgb_blue_read_func, rgb_blue_write_func }; 96 | 97 | void property_register(void) 98 | { 99 | memset(&prop, 0x00, sizeof(app_prop_t)); 100 | strcpy(prop.switch_status, "0"); 101 | strcpy(prop.color_temp, "4000"); 102 | strcpy(prop.rgb_red, "0"); 103 | strcpy(prop.rgb_green, "2"); 104 | strcpy(prop.rgb_blue, "100"); 105 | 106 | ilop_ica_attr_register(&LightSwitch_property); 107 | ilop_ica_attr_register(&ColorTemperature_property); 108 | ilop_ica_attr_register(&RGBColor_Red_property); 109 | ilop_ica_attr_register(&RGBColor_Green_property); 110 | ilop_ica_attr_register(&RGBColor_Blue_property); 111 | 112 | //连上服务器后 上报状态 113 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_LightSwitch); 114 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_ColorTemperature); 115 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_RGBColor_Red); 116 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_RGBColor_Green); 117 | ilop_ica_attr_indicate_by_handle(ILOP_HANDLE_ATTR_RGBColor_Blue); 118 | } 119 | -------------------------------------------------------------------------------- /examples/ilopicaapp/app_service.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_common.h" 4 | #include "mx_debug.h" 5 | 6 | static mx_status timereset_write_func(char* value) 7 | { 8 | app_log("TimeReset:%s", value); 9 | return kNoErr; 10 | } 11 | 12 | static const struct ilop_ica_attr_t TimeReset_service = { ILOP_HANDLE_ATTR_TimeReset, "TimeReset", EMH_ARG_ILOP_VT_SERVICE, NULL, timereset_write_func }; 13 | 14 | void service_register(void) 15 | { 16 | ilop_ica_attr_register(&TimeReset_service); 17 | } 18 | -------------------------------------------------------------------------------- /examples/ilopicaapp/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief Main function 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include "main.h" 28 | #include "mx_common.h" 29 | #include "mx_hal.h" 30 | 31 | int main(int argc, char* argv[]) 32 | { 33 | if (argc != 2) { 34 | printf("Usage: \"%s /dev/ttyUSB0\"\n", argv[0]); 35 | return 0; 36 | } 37 | printf("dev[%s]\r\n", argv[1]); 38 | mx_hal_uart_dev_set(argv[1]); 39 | ilop_main(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /examples/ilopicaapp/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.h 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief Application API header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _MAIN_H_ 28 | #define _MAIN_H_ 29 | 30 | /****************************************************************************** 31 | * Macros 32 | ******************************************************************************/ 33 | 34 | #define APP_DEBUG MX_DEBUG_ON 35 | #define app_log(M, ...) MX_LOG(APP_DEBUG, "APP", M, ##__VA_ARGS__) 36 | 37 | /****************************************************************************** 38 | * Enumerations 39 | ******************************************************************************/ 40 | 41 | enum { 42 | ILOP_HANDLE_ATTR_LightSwitch, 43 | ILOP_HANDLE_ATTR_ColorTemperature, 44 | ILOP_HANDLE_ATTR_RGBColor_Red, 45 | ILOP_HANDLE_ATTR_RGBColor_Green, 46 | ILOP_HANDLE_ATTR_RGBColor_Blue, 47 | ILOP_HANDLE_ATTR_TimeReset, 48 | ILOP_HANDLE_ATTR_ErrorCode, 49 | ILOP_HANDLE_ATTR_MAX, 50 | }; 51 | 52 | /****************************************************************************** 53 | * Function Declarations 54 | ******************************************************************************/ 55 | 56 | void ilop_main(void); 57 | void property_register(void); 58 | void service_register(void); 59 | void event_register(void); 60 | void event_task_loop(void); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /examples/iloprawapp/app_event.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_cli.h" 4 | #include "mx_common.h" 5 | #include "mx_debug.h" 6 | #include "mx_hal.h" 7 | 8 | static int event_post = 0; 9 | 10 | static unsigned long long uptime_sec(void) 11 | { 12 | static unsigned long long start_time = 0; 13 | 14 | if (start_time == 0) { 15 | start_time = mx_hal_ms_ticker_read(); 16 | } 17 | 18 | return (mx_hal_ms_ticker_read() - start_time) / 1000; 19 | } 20 | 21 | static mx_status error_code_read_func(ilop_att_val_t* value, uint32_t* outlen) 22 | { 23 | (*value).boolValue = 0; 24 | (*outlen) = sizeof((*value).boolValue); 25 | app_log("read value:%d", (*value).boolValue); 26 | return kNoErr; 27 | } 28 | 29 | static const struct ilop_raw_attr_t ErrorCode_event = { ILOP_EVENT_ErrorCode, 0, TYPE_ID_BOOL, error_code_read_func, NULL }; 30 | 31 | #ifdef MX_CLI_ENABLE 32 | static void handle_event_cmd(char* pwbuf, int blen, int argc, char** argv) 33 | { 34 | if (argc != 2) 35 | return; 36 | 37 | if (strcmp(argv[1], "enable") == 0) { 38 | event_post = 1; 39 | } else if (strcmp(argv[1], "disable") == 0) { 40 | event_post = 0; 41 | } 42 | } 43 | 44 | static struct cli_command eventcmd = { "event", "event [enable|disable]", handle_event_cmd }; 45 | #endif 46 | 47 | void event_register(void) 48 | { 49 | ilop_raw_attr_register(ATTR_TYPE_EVENT, &ErrorCode_event); 50 | #ifdef MX_CLI_ENABLE 51 | cli_register_command(&eventcmd); 52 | #endif 53 | } 54 | 55 | void event_task_loop(void) 56 | { 57 | if (event_post == 0) 58 | return; 59 | 60 | uint32_t now = uptime_sec(); 61 | static uint32_t pre_sec = 0; 62 | 63 | if (pre_sec == now) 64 | return; 65 | 66 | if ((now % 10) == 0) { 67 | app_log("time[%d]", now); 68 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_EVENT, ILOP_EVENT_ErrorCode); 69 | } 70 | 71 | pre_sec = now; 72 | } 73 | -------------------------------------------------------------------------------- /examples/iloprawapp/app_prop_light.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_common.h" 4 | #include "mx_debug.h" 5 | 6 | static uint8_t switch_status = 0; 7 | static uint16_t color_temp = 3000; 8 | static uint8_t rgb_color[3] = { 0, 0, 0 }; 9 | 10 | static mx_status light_switch_write_func(ilop_att_val_t value, uint32_t inlen) 11 | { 12 | switch_status = value.boolValue; 13 | app_log("write value:%d", switch_status); 14 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_LightSwitch); 15 | return kNoErr; 16 | } 17 | 18 | static mx_status light_switch_read_func(ilop_att_val_t* value, uint32_t* outlen) 19 | { 20 | (*value).boolValue = switch_status; 21 | (*outlen) = sizeof(switch_status); 22 | app_log("read value:%d", switch_status); 23 | return kNoErr; 24 | } 25 | 26 | static mx_status color_temp_write_func(ilop_att_val_t value, uint32_t inlen) 27 | { 28 | color_temp = value.uint16Value; 29 | app_log("write value:%d", color_temp); 30 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_ColorTemperature); 31 | return kNoErr; 32 | } 33 | 34 | static mx_status color_temp_read_func(ilop_att_val_t* value, uint32_t* outlen) 35 | { 36 | (*value).uint16Value = color_temp; 37 | (*outlen) = sizeof(color_temp); 38 | app_log("read value:%d", color_temp); 39 | return kNoErr; 40 | } 41 | 42 | static mx_status rgb_color_write_func(ilop_att_val_t value, uint32_t inlen) 43 | { 44 | rgb_color[0] = value.dataValue[0]; 45 | rgb_color[1] = value.dataValue[1]; 46 | rgb_color[2] = value.dataValue[2]; 47 | app_log("write[%d] R[%d] G[%d] B[%d]", inlen, rgb_color[0], rgb_color[1], rgb_color[2]); 48 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_RGBColor); 49 | return kNoErr; 50 | } 51 | 52 | static mx_status rgb_color_read_func(ilop_att_val_t* value, uint32_t* outlen) 53 | { 54 | (*value).dataValue = rgb_color; 55 | (*outlen) = sizeof(rgb_color); 56 | app_log("read[%d] R[%d] G[%d] B[%d]", (*outlen), (*value).dataValue[0], (*value).dataValue[1], (*value).dataValue[2]); 57 | return kNoErr; 58 | } 59 | 60 | static const struct ilop_raw_attr_t LightSwitch_property = { ILOP_PROPERTY_LightSwitch, 0, TYPE_ID_BOOL, light_switch_read_func, light_switch_write_func }; 61 | static const struct ilop_raw_attr_t ColorTemperature_property = { ILOP_PROPERTY_ColorTemperature, 6, TYPE_ID_UINT16, color_temp_read_func, color_temp_write_func }; 62 | static const struct ilop_raw_attr_t RGBColor_property = { ILOP_PROPERTY_RGBColor, 7, 30, rgb_color_read_func, rgb_color_write_func }; 63 | 64 | void property_register_light(void) 65 | { 66 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &LightSwitch_property); 67 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &ColorTemperature_property); 68 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &RGBColor_property); 69 | 70 | //连上服务器后 上报状态 71 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_LightSwitch); 72 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_ColorTemperature); 73 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_RGBColor); 74 | } 75 | -------------------------------------------------------------------------------- /examples/iloprawapp/app_prop_wifi.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_common.h" 4 | #include "mx_debug.h" 5 | 6 | static char* wifi_band = "2.4G"; 7 | static int8_t wifi_rssi = -40; 8 | static char* wifi_bssid = "00:00:00:00:00:01"; 9 | static uint8_t wifi_channel = 6; 10 | static int8_t wifi_snr = 100; 11 | 12 | static mx_status wifi_band_read_func(ilop_att_val_t* value, uint32_t* outlen) 13 | { 14 | (*value).stringValue = wifi_band; 15 | (*outlen) = strlen(wifi_band); 16 | app_log("read value:%s", wifi_band); 17 | return kNoErr; 18 | } 19 | 20 | static mx_status wifi_band_write_func(ilop_att_val_t value, uint32_t inlen) 21 | { 22 | app_log("WIFI_BAND[%d]:%.*s", inlen, inlen, value.stringValue); 23 | return kNoErr; 24 | } 25 | 26 | static mx_status wifi_rssi_read_func(ilop_att_val_t* value, uint32_t* outlen) 27 | { 28 | (*value).int8Value = wifi_rssi; 29 | (*outlen) = sizeof(wifi_rssi); 30 | app_log("read value:%d", wifi_rssi); 31 | return kNoErr; 32 | } 33 | 34 | static mx_status wifi_rssi_write_func(ilop_att_val_t value, uint32_t inlen) 35 | { 36 | app_log("WIFI_RSSI[%d]", value.int8Value); 37 | return kNoErr; 38 | } 39 | 40 | static mx_status wifi_ap_bssid_read_func(ilop_att_val_t* value, uint32_t* outlen) 41 | { 42 | (*value).stringValue = wifi_bssid; 43 | (*outlen) = strlen(wifi_bssid); 44 | app_log("read value:%s", wifi_bssid); 45 | return kNoErr; 46 | } 47 | 48 | static mx_status wifi_ap_bssid_write_func(ilop_att_val_t value, uint32_t inlen) 49 | { 50 | app_log("WIFI_AP_BSSID[%d]:%.*s", inlen, inlen, value.stringValue); 51 | return kNoErr; 52 | } 53 | 54 | static mx_status wifi_channel_read_func(ilop_att_val_t* value, uint32_t* outlen) 55 | { 56 | (*value).uint8Value = wifi_channel; 57 | (*outlen) = sizeof(wifi_channel); 58 | app_log("read value:%d", wifi_channel); 59 | return kNoErr; 60 | } 61 | 62 | static mx_status wifi_channel_write_func(ilop_att_val_t value, uint32_t inlen) 63 | { 64 | app_log("WIFI_CHANNEL[%d]", value.uint8Value); 65 | return kNoErr; 66 | } 67 | 68 | static mx_status wifi_snr_read_func(ilop_att_val_t* value, uint32_t* outlen) 69 | { 70 | (*value).int8Value = wifi_snr; 71 | (*outlen) = sizeof(wifi_snr); 72 | app_log("read value:%d", wifi_snr); 73 | return kNoErr; 74 | } 75 | 76 | static mx_status wifi_snr_write_func(ilop_att_val_t value, uint32_t inlen) 77 | { 78 | app_log("WIFI_SNR[%d]", value.int8Value); 79 | return kNoErr; 80 | } 81 | 82 | static const struct ilop_raw_attr_t WIFI_Band_property = { ILOP_PROPERTY_WIFI_Band, 1, TYPE_ID_STRING, wifi_band_read_func, wifi_band_write_func }; 83 | static const struct ilop_raw_attr_t WiFI_RSSI_property = { ILOP_PROPERTY_WiFI_RSSI, 2, TYPE_ID_INT8, wifi_rssi_read_func, wifi_rssi_write_func }; 84 | static const struct ilop_raw_attr_t WIFI_AP_BSSID_property = { ILOP_PROPERTY_WIFI_AP_BSSID, 3, TYPE_ID_STRING, wifi_ap_bssid_read_func, wifi_ap_bssid_write_func }; 85 | static const struct ilop_raw_attr_t WIFI_Channel_property = { ILOP_PROPERTY_WIFI_Channel, 4, TYPE_ID_UINT8, wifi_channel_read_func, wifi_channel_write_func }; 86 | static const struct ilop_raw_attr_t WiFI_SNR_property = { ILOP_PROPERTY_WiFI_SNR, 5, TYPE_ID_INT8, wifi_snr_read_func, wifi_snr_write_func }; 87 | 88 | void property_register_wifi(void) 89 | { 90 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &WIFI_Band_property); 91 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &WiFI_RSSI_property); 92 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &WIFI_AP_BSSID_property); 93 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &WIFI_Channel_property); 94 | ilop_raw_attr_register(ATTR_TYPE_PROPERTY, &WiFI_SNR_property); 95 | 96 | //连上服务器后 上报状态 97 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_WIFI_Band); 98 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_WiFI_RSSI); 99 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_WIFI_AP_BSSID); 100 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_WIFI_Channel); 101 | ilop_raw_attr_indicate_by_handle(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_WiFI_SNR); 102 | } 103 | -------------------------------------------------------------------------------- /examples/iloprawapp/app_service.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "main.h" 3 | #include "mx_common.h" 4 | #include "mx_debug.h" 5 | 6 | static mx_status timereset_write_func(ilop_att_val_t value, uint32_t inlen) 7 | { 8 | app_log("TimeReset[%d]:%s", inlen, (char*)value.dataValue); 9 | return kNoErr; 10 | } 11 | 12 | static const struct ilop_raw_attr_t TimeReset_service = { ILOP_SERVICE_TimeReset, 0, TYPE_ID_STRING, NULL, timereset_write_func }; 13 | 14 | void service_register(void) 15 | { 16 | ilop_raw_attr_register(ATTR_TYPE_SERVICE, &TimeReset_service); 17 | } 18 | -------------------------------------------------------------------------------- /examples/iloprawapp/ilopmain.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_ilop.h" 2 | #include "emh_api.h" 3 | #include "main.h" 4 | #include "mx_cli.h" 5 | #include "mx_common.h" 6 | #include "mx_debug.h" 7 | #include "mx_hal.h" 8 | 9 | static int awss_start = 0; 10 | static int awss_press = 0; 11 | static int reset = 0; 12 | 13 | const emh_ilop_config_t ilop_config = { 14 | .tsl_thing = NULL, 15 | .tsl_len = 0, 16 | .dm = EMH_ARG_ILOP_DM_RAW, 17 | .domain = EMH_ARG_ILOP_DOMAIN_SHANGHAI, 18 | }; 19 | 20 | const ilop_device_key_t device_key = { 21 | .product_key = "b1CcQqrXoVR", 22 | .product_secret = "yOrZrmtDcHLgVOJc", 23 | .device_name = "sPhDWW7vvaSyUfNBOvM9", 24 | .device_secret = "R90glnJXJNAUsKGSRRudMdlhyvA12OEM", 25 | }; 26 | 27 | static void awss_tast_loop(void) 28 | { 29 | if (awss_start == 1) { 30 | ilop_awss_start(); 31 | awss_start = 0; 32 | } 33 | if (awss_press == 1) { 34 | ilop_awss_press(); 35 | awss_press = 0; 36 | } 37 | if( reset == 1 ) 38 | { 39 | ilop_restore(); 40 | reset = 0; 41 | } 42 | } 43 | 44 | #ifdef MX_CLI_ENABLE 45 | static void handle_aws_cmd(char* pwbuf, int blen, int argc, char** argv) 46 | { 47 | if (argc != 2) 48 | return; 49 | 50 | if (strcmp(argv[1], "start") == 0) { 51 | awss_start = 1; 52 | } else if (strcmp(argv[1], "press") == 0) { 53 | awss_press = 1; 54 | } 55 | } 56 | 57 | static void handle_reset_cmd(char* pwbuf, int blen, int argc, char** argv) 58 | { 59 | reset = 1; 60 | } 61 | 62 | static struct cli_command ilopcmds[] = { 63 | { "aws", "aws [start|press]", handle_aws_cmd }, 64 | { "reset", "clean wifi module and ilop service", handle_reset_cmd }, 65 | }; 66 | #endif 67 | 68 | void ilop_main(void) 69 | { 70 | mx_status err = kNoErr; 71 | 72 | /* System initialization, ticker, stdio */ 73 | mx_hal_ms_ticker_init(); 74 | mx_hal_stdio_init(); 75 | 76 | #ifdef MX_CLI_ENABLE 77 | cli_register_commands(ilopcmds, sizeof(ilopcmds) / sizeof(struct cli_command)); 78 | #endif 79 | 80 | /* ILOP service initialization */ 81 | err = ilop_init(&ilop_config); 82 | if (err != kNoErr) 83 | app_log("ilop init err"); 84 | 85 | /* Set the ILOP three tuple. If the module is pre burned, delete the function */ 86 | ilop_set_device_key(&device_key); 87 | 88 | /* database initialization */ 89 | ilop_raw_attr_init(ATTR_TYPE_PROPERTY, ILOP_PROPERTY_MAX); 90 | ilop_raw_attr_init(ATTR_TYPE_EVENT, ILOP_EVENT_MAX); 91 | ilop_raw_attr_init(ATTR_TYPE_SERVICE, ILOP_SERVICE_MAX); 92 | 93 | event_register(); 94 | property_register_light(); 95 | property_register_wifi(); 96 | service_register(); 97 | 98 | while (1) { 99 | ilop_runloop(); 100 | awss_tast_loop(); 101 | event_task_loop(); 102 | } 103 | 104 | return; 105 | } 106 | -------------------------------------------------------------------------------- /examples/iloprawapp/main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "mx_common.h" 3 | #include "mx_hal.h" 4 | 5 | int main(int argc, char* argv[]) 6 | { 7 | if (argc != 2) { 8 | printf("Usage: \"%s /dev/ttyUSB0\"\n", argv[0]); 9 | return 0; 10 | } 11 | printf("dev[%s]\r\n", argv[1]); 12 | mx_hal_uart_dev_set(argv[1]); 13 | ilop_main(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /examples/iloprawapp/main.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MAIN_H_ 3 | #define _MAIN_H_ 4 | 5 | #define APP_DEBUG MX_DEBUG_ON 6 | #define app_log(M, ...) MX_LOG(APP_DEBUG, "APP", M, ##__VA_ARGS__) 7 | 8 | //property 9 | enum { 10 | ILOP_PROPERTY_LightSwitch, 11 | ILOP_PROPERTY_WIFI_Band, 12 | ILOP_PROPERTY_WiFI_RSSI, 13 | ILOP_PROPERTY_WIFI_AP_BSSID, 14 | ILOP_PROPERTY_WIFI_Channel, 15 | ILOP_PROPERTY_WiFI_SNR, 16 | ILOP_PROPERTY_ColorTemperature, 17 | ILOP_PROPERTY_RGBColor, 18 | ILOP_PROPERTY_MAX, 19 | }; 20 | 21 | //event 22 | enum { 23 | ILOP_EVENT_ErrorCode, 24 | ILOP_EVENT_MAX, 25 | }; 26 | 27 | //sevice 28 | enum { 29 | ILOP_SERVICE_TimeReset, 30 | ILOP_SERVICE_MAX, 31 | }; 32 | 33 | void ilop_main(void); 34 | 35 | void event_register(void); 36 | void event_task_loop(void); 37 | 38 | void property_register_light(void); 39 | void property_register_wifi(void); 40 | 41 | void service_register(void); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /examples/qlinkapp/main.c: -------------------------------------------------------------------------------- 1 | #include "user_qlink_include.h" 2 | 3 | const emh_qlink_config_t config = { 4 | .product_info = { 5 | .product_id = "30531", 6 | .product_token = "PXmsE6kQmxEgc0e3", 7 | .andlink_token = "ZxMo0zJvvZMWP3Az", 8 | .format = EMH_ARG_QLINK_FORMAT_JSON, 9 | }, 10 | .version_info = { 11 | .firmware_version = "1.4.3", 12 | .software_version = "1.0.1", 13 | } 14 | }; 15 | // .product_info = { 16 | // .product_id = "30413", 17 | // .product_token = "38Szyd6i1240elbV", 18 | // .andlink_token = "wWppJIdROfQkcsMW", 19 | // .format = EMH_ARG_QLINK_FORMAT_JSON, 20 | // }, 21 | 22 | void qlink_event_handler(qlink_event_t event) 23 | { 24 | switch (event) { 25 | case QLINK_EVENT_WLAN_CONFIG_STARTED: { 26 | app_log("Wi-Fi config...."); 27 | break; 28 | } 29 | case QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE: { 30 | app_log("WiFi config in AP mode......"); 31 | break; 32 | } 33 | case QLINK_EVENT_WLAN_CONNECTED: { 34 | app_log("Wi-Fi connected"); 35 | break; 36 | } 37 | case QLINK_EVENT_WLAN_DISCONNECTED: { 38 | app_log("Wi-Fi disconnected"); 39 | break; 40 | } 41 | case QLINK_EVENT_CLOUD_CONNECTED: { 42 | app_log("Cloud connected"); 43 | break; 44 | } 45 | case QLINK_EVENT_CLOUD_DISCONNECTED: { 46 | app_log("Cloud disconnected"); 47 | break; 48 | } 49 | } 50 | } 51 | 52 | //cloud want to get data from device 53 | void emh_ev_qlink_get_local_attrs(emh_qlink_msg_t* msg) 54 | { 55 | app_log("get attrs"); 56 | app_log("data is :%s len is :%d", msg->data, msg->len); 57 | 58 | } 59 | 60 | int emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg) 61 | { 62 | app_log("set attrs"); 63 | 64 | //REBOOT, reboot device 65 | if( 0==strncmp(msg->data, "REBOOT", msg->len ) ) 66 | { 67 | app_log("please reboot device."); 68 | }else if( 0==strncmp(msg->data, "FACTORY", msg->len) ) //FACTOR, restore factory settings and clear all parameters of then system. 69 | { 70 | app_log("please restore device."); 71 | }else if( 0==strncmp(msg->data, "UNBIND", msg->len) ) //UNBIND 72 | { 73 | app_log("this device has already bend unbinded"); 74 | }else //set data, if this field also need to be upload, this function return 1, otherwise 0 will be returned. 75 | { 76 | app_log("data is :%s len is :%d", msg->data, msg->len); 77 | // return 1; 78 | } 79 | return 0; 80 | } 81 | 82 | #ifdef MX_CLI_ENABLE 83 | static void handle_raw_cmd(char* pwbuf, int blen, int argc, char** argv) 84 | { 85 | if (argc != 2) 86 | return; 87 | 88 | if (strcmp(argv[1], "start") == 0) { 89 | qlink_raw_start(); 90 | } else if (strcmp(argv[1], "stop") == 0) { 91 | 92 | } 93 | } 94 | 95 | static void handle_user_cmd(char* pwbuf, int blen, int argc, char** argv) 96 | { 97 | app_log("enter handle_user_cmd()!"); 98 | if (argc != 2) 99 | return; 100 | 101 | if (strcmp(argv[1], "start") == 0) { 102 | qlink_user_start(); 103 | } else if (strcmp(argv[1], "stop") == 0) { 104 | 105 | } 106 | } 107 | 108 | static void handle_reboot_cmd(char* pwbuf, int blen, int argc, char** argv) 109 | { 110 | 111 | if (argc != 1) 112 | { 113 | app_log("input param error!!!"); 114 | return; 115 | } 116 | 117 | emh_module_reset(); 118 | 119 | } 120 | 121 | // {"deviceId":"CMCC-30531-B0F89327CDF4","childDeviceId":"","eventType":"Inform","timestamp":0,"data":{"params":[{"paramCode":"permitJoining","paramValue":"0"},{"paramCode":"firmware","paramValue":"1.6.0"},{"paramCode":"softVersion","paramValue":"V1.0.6"}]}} 122 | static void handle_send_cmd(char* pwbuf, int blen, int argc, char** argv) 123 | { 124 | if (argc != 3) 125 | { 126 | app_log("input param error!!!"); 127 | return; 128 | } 129 | app_log("type is:%s\r\n data is:%s\r\ndata's length is:%d", argv[1], argv[2], strlen(argv[2]) ); 130 | 131 | qlink_send_data( argv[1], argv[2], strlen(argv[2]) ); 132 | } 133 | 134 | struct cli_command qlinkcmds[] = { 135 | { "raw", "raw [start|stop]", handle_raw_cmd }, 136 | { "user", "start|stop", handle_user_cmd }, 137 | { "reboot", "reboot", handle_reboot_cmd }, 138 | { "send", "send ", handle_send_cmd }, 139 | }; 140 | #endif 141 | 142 | void qlink_main(void) 143 | { 144 | mx_status err = kNoErr; 145 | int nums = 0; 146 | 147 | /* System initialization, ticker, stdio */ 148 | mx_hal_ms_ticker_init(); 149 | mx_hal_stdio_init(); 150 | 151 | #ifdef MX_CLI_ENABLE 152 | app_log("open cli function"); 153 | cli_register_commands(qlinkcmds, sizeof(qlinkcmds) / sizeof(struct cli_command)); 154 | #endif 155 | 156 | label_reinit: 157 | /* qlink service initialization */ 158 | err = qlink_init(&config); 159 | if (err != kNoErr){ 160 | app_log("qlink init err"); 161 | if( nums<3 ){ 162 | nums++; 163 | goto label_reinit; 164 | } 165 | } 166 | 167 | while (1) { 168 | qlink_runloop(); 169 | } 170 | 171 | return; 172 | } 173 | 174 | 175 | int main(int argc, char* argv[]) 176 | { 177 | if (argc != 2) { 178 | printf("Usage: \"%s /dev/ttyUSB0\"\n", argv[0]); 179 | return 0; 180 | } 181 | printf("dev[%s]\r\n", argv[1]); 182 | mx_hal_uart_dev_set(argv[1]); 183 | qlink_main(); 184 | return 0; 185 | } 186 | 187 | -------------------------------------------------------------------------------- /examples/qlinkapp/user_qlink_include.h: -------------------------------------------------------------------------------- 1 | #ifndef _USER_QLINK_INCLUDE_H_ 2 | #define _USER_QLINK_INCLUDE_H_ 3 | 4 | #include "emh_api.h" 5 | #include "mx_cli.h" 6 | #include "mx_common.h" 7 | #include "mx_debug.h" 8 | #include "mx_hal.h" 9 | #include "cloud_qlink.h" 10 | 11 | #define app_log(M, ...) MX_LOG(APP_DEBUG, "APP", M, ##__VA_ARGS__) 12 | 13 | #define APP_DEBUG MX_DEBUG_ON 14 | 15 | #define QLINK_EVENT_TYPE_INFORM "Inform" //send data initiate 16 | #define QLINK_EVENT_TYPE_FILE "File" 17 | #define QLINK_EVENT_TYPE_PARAMCHANGE "ParamChange" //send data after triggering by hand 18 | #define QLINK_EVENT_TYPE_DATA "Data" //send data as a response 19 | 20 | 21 | void qlink_main(void); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /examples/sdsapp/sdsapp.c: -------------------------------------------------------------------------------- 1 | #include "alicloud_sds.h" 2 | #include "mx_common.h" 3 | #include "mx_debug.h" 4 | 5 | #include "emh_api.h" 6 | #include "mx_hal.h" 7 | 8 | #define APP_DEBUG MX_DEBUG_ON 9 | #define app_log(M, ...) MX_LOG(APP_DEBUG, "APP", M, ##__VA_ARGS__) 10 | 11 | static int light_on = 0; 12 | 13 | enum { 14 | ALI_HANDLE_LIGHT_SWITCH, 15 | ALI_HANDLE_MAX, 16 | }; 17 | 18 | const emh_alisds_config_t alisds_config = { 19 | .product_info = { 20 | .name = "alink_product", 21 | .module = "ALINKTEST_LIVING_LIGHT_ALINK_TEST", 22 | .key = "5gPFl8G4GyFZ1fPWk20m", 23 | .secret = "ngthgTlZ65bX5LpViKIWNsDPhOf2As9ChnoL9gQb", 24 | .format = EMH_ARG_ALISDS_FORMAT_JSON, 25 | }, 26 | .dev_info = { 27 | .type = "LIGHT", 28 | .category = "LIVING", 29 | .manufacture = "ALINKTEST", 30 | } 31 | }; 32 | 33 | void emh_ev_alisds_get_local_atts(emh_alisds_msg* attrs) 34 | { 35 | alisds_attr_indicate_by_handle(ALI_HANDLE_LIGHT_SWITCH); 36 | } 37 | 38 | mx_status handle_read_cur_light_switch(alisds_att_val_t* value) 39 | { 40 | (*value).boolValue = light_on; 41 | app_log("read switch:%d\r\n", light_on); 42 | return kNoErr; 43 | } 44 | 45 | mx_status handle_write_cur_light_switch(alisds_att_val_t value) 46 | { 47 | light_on = value.boolValue; 48 | app_log("write switch:%d\r\n", light_on); 49 | return kNoErr; 50 | } 51 | 52 | void switch_task_init(void) 53 | { 54 | alisds_attr_t attr; 55 | 56 | attr.name = "Switch"; 57 | attr.type = ALI_ATT_TYPE_BOOL; 58 | attr.read_func = handle_read_cur_light_switch; 59 | attr.write_func = handle_write_cur_light_switch; 60 | alisds_attr_init(ALI_HANDLE_LIGHT_SWITCH, attr); 61 | } 62 | 63 | static void sds_task(void) 64 | { 65 | mx_status err = kNoErr; 66 | 67 | err = alisds_init(&alisds_config, 1); 68 | require_noerr(err, exit); 69 | 70 | switch_task_init(); 71 | 72 | while (1) { 73 | alisds_runloop(); 74 | } 75 | 76 | exit: 77 | return; 78 | } 79 | 80 | int main(int argc, char* argv[]) 81 | { 82 | if (argc != 2) { 83 | printf("Usage: \"%s /dev/ttyUSB0\"\n", argv[0]); 84 | return 0; 85 | } 86 | printf("dev[%s]\r\n", argv[1]); 87 | mx_hal_uart_dev_set(argv[1]); 88 | sds_task(); 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /examples/sdsapp/sdsapp.mk: -------------------------------------------------------------------------------- 1 | NAME := sdsapp 2 | 3 | # at_support_alisds := 1 4 | 5 | $(NAME)_SOURCES := sdsapp.c 6 | 7 | $(NAME)_COMPONENTS := yloop cli mxathost 8 | 9 | GLOBAL_DEFINES += AOS_NO_WIFI MX_DEBUG 10 | 11 | ifeq ($(at_support_alisds),1) 12 | GLOBAL_DEFINES += AT_SUPPORT_ALISDS 13 | endif 14 | -------------------------------------------------------------------------------- /examples/test/test.c: -------------------------------------------------------------------------------- 1 | #include "mx_common.h" 2 | #include "mx_debug.h" 3 | 4 | #include "emh_api.h" 5 | #include "mx_hal.h" 6 | 7 | #define APP_DEBUG MX_DEBUG_ON 8 | #define app_log(M, ...) MX_LOG(APP_DEBUG, "APP", M, ##__VA_ARGS__) 9 | 10 | static void at_task(void) 11 | { 12 | mx_status err = kNoErr; 13 | 14 | mx_hal_ms_ticker_init(); 15 | mx_hal_stdio_init(); 16 | 17 | err = emh_init(); 18 | if (err == kNoErr) { 19 | app_log("FW version: %s", emh_module_get_fw_version()); 20 | app_log("System tick: %d", (int)emh_module_get_tick()); 21 | } 22 | 23 | while (1) { 24 | emh_runloop(); 25 | } 26 | 27 | return; 28 | } 29 | 30 | int main(int argc, char* argv[]) 31 | { 32 | if (argc != 2) { 33 | printf("Usage: \"%s /dev/ttyUSB0\"\n", argv[0]); 34 | return 0; 35 | } 36 | printf("dev[%s]\r\n", argv[1]); 37 | mx_hal_uart_dev_set(argv[1]); 38 | at_task(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /platform/linux/mx_serial.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mx_serial.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief UART driver used for AT parser 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include 28 | #include "mx_common.h" 29 | #include "mx_hal.h" 30 | #include "mx_ringbuffer.h" 31 | 32 | /****************************************************************************** 33 | * Variable Definitions 34 | ******************************************************************************/ 35 | 36 | static int _timeout = 100; 37 | static uint8_t at_buffer[MX_SERIAL_RX_BUF_SIZE]; 38 | static struct ringbuffer at_rx; 39 | static pthread_mutex_t at_mtx; 40 | 41 | /****************************************************************************** 42 | * Type Definitions 43 | ******************************************************************************/ 44 | 45 | static uart_dev_t uart_dev = { 46 | AT_UART_PORT, 47 | { 48 | AT_UART_BAUDRATE, 49 | DATA_WIDTH_8BIT, 50 | NO_PARITY, 51 | STOP_BITS_1, 52 | FLOW_CONTROL_DISABLED, 53 | MODE_TX_RX, 54 | }, 55 | }; 56 | 57 | /****************************************************************************** 58 | * Function Definitions 59 | ******************************************************************************/ 60 | 61 | static void* uart_recv_task(void* arg) 62 | { 63 | int ret = 0; 64 | uint8_t RXData; 65 | uint32_t recv_len = 0; 66 | 67 | while (1) { 68 | ret = mx_hal_uart_recv(&uart_dev, &RXData, 1, &recv_len, _timeout); 69 | if ((ret == 0) && (recv_len == 1)) { 70 | // printf("%c\r\n", RXData); 71 | pthread_mutex_lock(&at_mtx); 72 | ringbuffer_put(&at_rx, RXData); 73 | pthread_mutex_unlock(&at_mtx); 74 | } 75 | } 76 | return NULL; 77 | } 78 | 79 | static int32_t at_async_read(uint8_t* const buf, const uint16_t length) 80 | { 81 | uint16_t was_read = 0; 82 | uint32_t num; 83 | 84 | if (buf == 0 || length == 0) 85 | return 0; 86 | 87 | pthread_mutex_lock(&at_mtx); 88 | num = ringbuffer_num(&at_rx); 89 | pthread_mutex_unlock(&at_mtx); 90 | 91 | while ((was_read < num) && (was_read < length)) { 92 | ringbuffer_get(&at_rx, &buf[was_read++]); 93 | } 94 | 95 | return (int32_t)was_read; 96 | } 97 | 98 | void mx_hal_serial_init(int timeout) 99 | { 100 | mx_status err; 101 | _timeout = timeout; 102 | pthread_t ntid; 103 | 104 | ringbuffer_init(&at_rx, at_buffer, MX_SERIAL_RX_BUF_SIZE); 105 | 106 | err = mx_hal_uart_init(&uart_dev); 107 | require_noerr(err, exit); 108 | 109 | pthread_mutex_init(&at_mtx, NULL); 110 | 111 | err = pthread_create(&ntid, NULL, uart_recv_task, NULL); 112 | require_noerr(err, exit); 113 | 114 | exit: 115 | return; 116 | } 117 | 118 | void mx_hal_serial_set_timeout(int timeout) 119 | { 120 | _timeout = timeout; 121 | } 122 | 123 | int mx_hal_serial_putc(char c) 124 | { 125 | return mx_hal_uart_send(&uart_dev, &c, 1, _timeout); 126 | } 127 | 128 | int mx_hal_serial_getc(void) 129 | { 130 | uint32_t current = mx_hal_ms_ticker_read(); 131 | uint8_t ch; 132 | 133 | do { 134 | if (at_async_read(&ch, 1) == 1) 135 | return ch; 136 | } while ((mx_hal_ms_ticker_read() - current) < _timeout); 137 | 138 | return -1; 139 | } 140 | 141 | bool mx_hal_serial_readable(void) 142 | { 143 | if (ringbuffer_num(&at_rx)) 144 | return true; 145 | return false; 146 | } 147 | 148 | void mx_hal_serial_flush(void) 149 | { 150 | uint32_t num; 151 | uint8_t tmp; 152 | 153 | pthread_mutex_lock(&at_mtx); 154 | for (num = ringbuffer_num(&at_rx); num > 0; num--) { 155 | ringbuffer_get(&at_rx, &tmp); 156 | } 157 | pthread_mutex_unlock(&at_mtx); 158 | } 159 | -------------------------------------------------------------------------------- /platform/linux/mx_stdio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mx_stdio.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief Initialize uart for printf output 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | #include 27 | 28 | #include "mx_common.h" 29 | #include "mx_hal.h" 30 | #include "mx_ringbuffer.h" 31 | 32 | /****************************************************************************** 33 | * Variable Definitions 34 | ******************************************************************************/ 35 | 36 | static uint8_t cli_buffer[MX_CLI_RX_BUF_SIZE]; 37 | static struct ringbuffer stdio_rx; 38 | static pthread_mutex_t stdio_mtx; 39 | extern int cli_init(void); 40 | 41 | /****************************************************************************** 42 | * Type Definitions 43 | ******************************************************************************/ 44 | 45 | static uart_dev_t cli_uart_dev = { 46 | STDIO_UART_PORT, 47 | { 48 | STDIO_UART_BAUDRATE, 49 | DATA_WIDTH_8BIT, 50 | NO_PARITY, 51 | STOP_BITS_1, 52 | FLOW_CONTROL_DISABLED, 53 | MODE_TX_RX, 54 | }, 55 | }; 56 | 57 | /****************************************************************************** 58 | * Function Definitions 59 | ******************************************************************************/ 60 | 61 | #ifdef MX_CLI_ENABLE 62 | static void* cli_recv_task(void* arg) 63 | { 64 | int ret = 0; 65 | uint8_t RXData; 66 | uint32_t recv_len = 0; 67 | 68 | while (1) { 69 | ret = mx_hal_uart_recv(&cli_uart_dev, &RXData, 1, &recv_len, 0); 70 | if ((ret == 0) && (recv_len == 1)) { 71 | pthread_mutex_lock(&stdio_mtx); 72 | ringbuffer_put(&stdio_rx, RXData); 73 | pthread_mutex_unlock(&stdio_mtx); 74 | } 75 | } 76 | return NULL; 77 | } 78 | 79 | static int32_t at_async_read(uint8_t* const buf, const uint16_t length) 80 | { 81 | uint16_t was_read = 0; 82 | uint32_t num; 83 | 84 | if (buf == 0 || length == 0) 85 | return 0; 86 | 87 | pthread_mutex_lock(&stdio_mtx); 88 | num = ringbuffer_num(&stdio_rx); 89 | pthread_mutex_unlock(&stdio_mtx); 90 | 91 | while ((was_read < num) && (was_read < length)) { 92 | ringbuffer_get(&stdio_rx, &buf[was_read++]); 93 | } 94 | 95 | return (int32_t)was_read; 96 | } 97 | #endif 98 | 99 | void mx_hal_stdio_init(void) 100 | { 101 | mx_status err; 102 | 103 | ringbuffer_init(&stdio_rx, cli_buffer, MX_CLI_RX_BUF_SIZE); 104 | 105 | err = mx_hal_uart_init(&cli_uart_dev); 106 | require_noerr(err, exit); 107 | 108 | #ifdef MX_CLI_ENABLE 109 | pthread_t ntid; 110 | 111 | pthread_mutex_init(&stdio_mtx, NULL); 112 | 113 | err = pthread_create(&ntid, NULL, cli_recv_task, NULL); 114 | require_noerr(err, exit); 115 | 116 | err = cli_init(); 117 | require_noerr(err, exit); 118 | #endif 119 | 120 | exit: 121 | return; 122 | } 123 | 124 | #ifdef MX_CLI_ENABLE 125 | int mx_hal_cli_putstr(const char* str, uint32_t strlen) 126 | { 127 | int ret = 0; 128 | ret = mx_hal_uart_send(&cli_uart_dev, str, strlen, 0); 129 | return ret; 130 | } 131 | 132 | int mx_hal_cli_getc(void) 133 | { 134 | uint8_t ch; 135 | 136 | if (at_async_read(&ch, 1) == 1) { 137 | return ch; 138 | } else { 139 | return -1; 140 | } 141 | } 142 | 143 | #endif 144 | 145 | -------------------------------------------------------------------------------- /platform/linux/mx_tick.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mx_tick.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief Tick for delay and timeout 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include "mx_common.h" 31 | 32 | /****************************************************************************** 33 | * Variable Definitions 34 | ******************************************************************************/ 35 | 36 | static struct timeval sys_start_time; 37 | 38 | /****************************************************************************** 39 | * Function Definitions 40 | ******************************************************************************/ 41 | 42 | void mx_hal_ms_ticker_init(void) 43 | { 44 | return; 45 | } 46 | 47 | uint32_t mx_hal_ms_ticker_read(void) 48 | { 49 | struct timeval tv; 50 | uint32_t ms; 51 | gettimeofday(&tv, NULL); 52 | timersub(&tv, &sys_start_time, &tv); 53 | ms = (uint32_t)(tv.tv_sec * 1000LL) + tv.tv_usec / 1000; 54 | return ms; 55 | } 56 | 57 | void mx_hal_delay_ms(volatile uint32_t delay) 58 | { 59 | usleep(delay * 1000); 60 | } 61 | -------------------------------------------------------------------------------- /platform/linux/mx_uart.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mx_uart.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief UART driver function 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #include "mx_common.h" 41 | #include "mx_hal.h" 42 | 43 | /****************************************************************************** 44 | * Variable Definitions 45 | ******************************************************************************/ 46 | 47 | #define LINUX_UART_LINUX_DEV "/dev/ttyUSB1" 48 | 49 | static char linux_dev[15] = { 0 }; 50 | static int at_uart_fd = -1; 51 | 52 | /****************************************************************************** 53 | * Function Definitions 54 | ******************************************************************************/ 55 | 56 | static int read_and_discard_all_data(const int fd) 57 | { 58 | int was_msg_already_printed = 0; 59 | 60 | while (1) { 61 | char buffer[1024]; 62 | const ssize_t read_count = read(fd, buffer, sizeof(buffer)); 63 | 64 | if (read_count == 0) { 65 | /* "EOF" or "connection closed at the other end"*/ 66 | return 0; 67 | } 68 | 69 | if (read_count > 0) { 70 | if (!was_msg_already_printed) { 71 | printf("Some stale data was discarded.\r\n"); 72 | was_msg_already_printed = 1; 73 | } 74 | 75 | continue; 76 | } 77 | 78 | assert(read_count == -1); /* According to the specification. */ 79 | 80 | const int errno_code = errno; 81 | 82 | if (errno_code == EINTR) 83 | continue; 84 | 85 | if (errno_code == EAGAIN || errno_code == EWOULDBLOCK) { 86 | /** 87 | * We know that the file descriptor has been opened with 88 | * O_NONBLOCK or O_NDELAY, and these codes mean that there 89 | * is no data to read at present. 90 | */ 91 | return 0; 92 | } 93 | 94 | /* Some other error has occurred. */ 95 | return -1; 96 | } 97 | } 98 | 99 | void mx_hal_uart_dev_set(char* dev) 100 | { 101 | strncpy(linux_dev, dev, 15); 102 | } 103 | 104 | int32_t mx_hal_uart_init(uart_dev_t* uart) 105 | { 106 | int fd; 107 | struct termios t_opt; 108 | speed_t baud; 109 | 110 | if (uart->port != AT_UART_PORT) 111 | return 0; 112 | 113 | if ((at_uart_fd = open(linux_dev, 114 | O_RDWR | O_NOCTTY | O_NDELAY)) 115 | == -1) { 116 | printf("open at uart failed\r\n"); 117 | return -1; 118 | } 119 | 120 | switch (uart->config.baud_rate) { 121 | case 115200: 122 | baud = B115200; 123 | break; 124 | default: 125 | baud = B115200; 126 | break; 127 | } 128 | 129 | fd = at_uart_fd; 130 | /* set the serial port parameters */ 131 | fcntl(fd, F_SETFL, 0); 132 | if (0 != tcgetattr(fd, &t_opt)) 133 | return -1; 134 | 135 | if (0 != cfsetispeed(&t_opt, baud)) 136 | return -1; 137 | 138 | if (0 != cfsetospeed(&t_opt, baud)) 139 | return -1; 140 | 141 | // 8N1, flow control, etc. 142 | t_opt.c_cflag |= (CLOCAL | CREAD); 143 | if (uart->config.parity == NO_PARITY) 144 | t_opt.c_cflag &= ~PARENB; 145 | if (uart->config.stop_bits == STOP_BITS_1) 146 | t_opt.c_cflag &= ~CSTOPB; 147 | else 148 | t_opt.c_cflag |= CSTOPB; 149 | t_opt.c_cflag &= ~CSIZE; 150 | switch (uart->config.data_width) { 151 | case DATA_WIDTH_5BIT: 152 | t_opt.c_cflag |= CS5; 153 | break; 154 | case DATA_WIDTH_6BIT: 155 | t_opt.c_cflag |= CS6; 156 | break; 157 | case DATA_WIDTH_7BIT: 158 | t_opt.c_cflag |= CS7; 159 | break; 160 | case DATA_WIDTH_8BIT: 161 | t_opt.c_cflag |= CS8; 162 | break; 163 | default: 164 | t_opt.c_cflag |= CS8; 165 | break; 166 | } 167 | t_opt.c_lflag &= ~(ECHO | ECHOE | ISIG | ICANON); 168 | if (uart->config.flow_control == FLOW_CONTROL_DISABLED) 169 | t_opt.c_cflag &= ~CRTSCTS; 170 | 171 | /** 172 | * AT is going to use a binary protocol, so make sure to 173 | * turn off any CR/LF translation and the like. 174 | */ 175 | t_opt.c_iflag &= ~(IXON | IXOFF | IXANY | INLCR | ICRNL); 176 | 177 | t_opt.c_oflag &= ~OPOST; 178 | t_opt.c_cc[VMIN] = 0; 179 | t_opt.c_cc[VTIME] = 5; 180 | 181 | if (0 != tcsetattr(fd, TCSANOW, &t_opt)) { 182 | return -1; 183 | } 184 | 185 | printf("open at uart succeed\r\n"); 186 | 187 | // clear uart buffer 188 | read_and_discard_all_data(fd); 189 | 190 | return 0; 191 | } 192 | 193 | int32_t mx_hal_uart_send(uart_dev_t* uart, const void* data, 194 | uint32_t size, uint32_t timeout) 195 | { 196 | uint32_t ret, rmd = size; 197 | 198 | if (uart->port == AT_UART_PORT) { 199 | while (rmd > 0) { 200 | ret = write(at_uart_fd, data + size - rmd, rmd); 201 | if (ret == -1) { 202 | printf("write uart fd failed on error: %d.\r\n", errno); 203 | return -1; 204 | } 205 | rmd -= ret; 206 | } 207 | } else 208 | ret = write(0, data, size); 209 | return 0; 210 | } 211 | 212 | int32_t mx_hal_uart_recv(uart_dev_t* uart, void* data, uint32_t expect_size, 213 | uint32_t* recv_size, uint32_t timeout) 214 | { 215 | int fd, n; 216 | 217 | if (uart->port == AT_UART_PORT) 218 | fd = at_uart_fd; 219 | else 220 | fd = 0; 221 | 222 | if ((n = read(fd, data, expect_size)) == -1) { 223 | // printf("read failed\r\n"); 224 | return -1; 225 | } 226 | 227 | if (uart->port != AT_UART_PORT && *(char*)data == '\n') 228 | *(char*)data = '\r'; 229 | if (recv_size) 230 | *recv_size = n; 231 | 232 | return 0; 233 | } 234 | 235 | int32_t mx_hal_uart_finalize(uart_dev_t* uart) 236 | { 237 | if (uart->port == AT_UART_PORT) 238 | close(at_uart_fd); 239 | return 0; 240 | } 241 | 242 | -------------------------------------------------------------------------------- /platform/mx_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mx_hal.h 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief MCU peripheral driver PI header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _MX_HAL_H_ 28 | #define _MX_HAL_H_ 29 | 30 | #include "mx_common.h" 31 | #include "mx_debug.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /****************************************************************************** 38 | * Macros 39 | ******************************************************************************/ 40 | 41 | #define AT_UART_PORT (0) 42 | #define AT_UART_BAUDRATE (115200) 43 | 44 | #define STDIO_UART_PORT (1) 45 | #define STDIO_UART_BAUDRATE (115200) 46 | 47 | /****************************************************************************** 48 | * UART Function 49 | ******************************************************************************/ 50 | 51 | /* 52 | * UART data width 53 | */ 54 | typedef enum { 55 | DATA_WIDTH_5BIT, 56 | DATA_WIDTH_6BIT, 57 | DATA_WIDTH_7BIT, 58 | DATA_WIDTH_8BIT, 59 | DATA_WIDTH_9BIT 60 | } mx_hal_uart_data_width_t; 61 | 62 | /* 63 | * UART stop bits 64 | */ 65 | typedef enum { 66 | STOP_BITS_1, 67 | STOP_BITS_2 68 | } mx_hal_uart_stop_bits_t; 69 | 70 | /* 71 | * UART flow control 72 | */ 73 | typedef enum { 74 | FLOW_CONTROL_DISABLED, 75 | FLOW_CONTROL_CTS, 76 | FLOW_CONTROL_RTS, 77 | FLOW_CONTROL_CTS_RTS 78 | } mx_hal_uart_flow_control_t; 79 | 80 | /* 81 | * UART parity 82 | */ 83 | typedef enum { 84 | NO_PARITY, 85 | ODD_PARITY, 86 | EVEN_PARITY 87 | } mx_hal_uart_parity_t; 88 | 89 | /* 90 | * UART mode 91 | */ 92 | typedef enum { 93 | MODE_TX, 94 | MODE_RX, 95 | MODE_TX_RX 96 | } mx_hal_uart_mode_t; 97 | 98 | /* 99 | * UART configuration 100 | */ 101 | typedef struct { 102 | uint32_t baud_rate; 103 | mx_hal_uart_data_width_t data_width; 104 | mx_hal_uart_parity_t parity; 105 | mx_hal_uart_stop_bits_t stop_bits; 106 | mx_hal_uart_flow_control_t flow_control; 107 | mx_hal_uart_mode_t mode; 108 | } uart_config_t; 109 | 110 | typedef struct { 111 | uint8_t port; /* uart port */ 112 | uart_config_t config; /* uart config */ 113 | } uart_dev_t; 114 | 115 | /** 116 | * 117 | * @brief Set up serial port device description 118 | * @note only linux platform 119 | * 120 | * param[in] dev: device description, like '/dev/ttyUSB0' 121 | * 122 | * @return none 123 | * 124 | */ 125 | void mx_hal_uart_dev_set(char* dev); 126 | 127 | /** 128 | * 129 | * @brief Initialises a UART interface 130 | * 131 | * param[in] uart: the interface which should be initialised 132 | * 133 | * @return status 134 | * 135 | */ 136 | int32_t mx_hal_uart_init(uart_dev_t* uart); 137 | 138 | /** 139 | * 140 | * @brief Deinitialises a UART interface 141 | * 142 | * param[in] uart: the interface which should be deinitialised 143 | * 144 | * @return status 145 | * 146 | */ 147 | int32_t mx_hal_uart_finalize(uart_dev_t* uart); 148 | 149 | /** 150 | * 151 | * @brief Transmit data on a UART interface 152 | * 153 | * param[in] uart : the UART interface 154 | * param[in] data : pointer to the start of data 155 | * param[in] size : number of bytes to transmit 156 | * param[in] timeout : timeout in milisecond 157 | * 158 | * @return status 159 | * 160 | */ 161 | int32_t mx_hal_uart_send(uart_dev_t* uart, const void* data, uint32_t size, uint32_t timeout); 162 | 163 | /** 164 | * 165 | * @brief Receive data on a UART interface 166 | * 167 | * param[in] uart : the UART interface 168 | * param[in] data : pointer to the buffer which will store incoming data 169 | * param[in] expect_size : number of bytes to Expected data received 170 | * param[out] recv_size : number of bytes to Actual data received 171 | * param[in] timeout : timeout in milisecond 172 | * 173 | * @return status 174 | * 175 | */ 176 | int32_t mx_hal_uart_recv(uart_dev_t* uart, void* data, uint32_t expect_size, uint32_t* recv_size, uint32_t timeout); 177 | 178 | /****************************************************************************** 179 | * Serial Function 180 | * Serial port driver used for AT parser 181 | ******************************************************************************/ 182 | 183 | /** 184 | * 185 | * @brief Initialises AT instruction port 186 | * 187 | * param[in] timeout: timeout in milisecond 188 | * 189 | * @return status 190 | * 191 | */ 192 | void mx_hal_serial_init(int timeout); 193 | 194 | /** 195 | * 196 | * @brief AT instruction port receiving timeout time 197 | * 198 | * param[in] timeout : timeout in milisecond 199 | * 200 | * @return status 201 | * 202 | */ 203 | void mx_hal_serial_set_timeout(int timeout); 204 | 205 | /** 206 | * 207 | * @brief AT instruction port output 208 | * 209 | * param[in] c : Output one byte 210 | * 211 | * @return status 212 | * 213 | */ 214 | int mx_hal_serial_putc(char c); 215 | 216 | /** 217 | * 218 | * @brief AT instruction port input 219 | * 220 | * @return byte 221 | * 222 | */ 223 | int mx_hal_serial_getc(void); 224 | 225 | /** 226 | * 227 | * @brief AT instruction port status 228 | * 229 | * @return status 230 | * 231 | */ 232 | bool mx_hal_serial_readable(void); 233 | 234 | /** 235 | * 236 | * @brief AT instruction port flush 237 | * 238 | * @return none 239 | * 240 | */ 241 | void mx_hal_serial_flush(void); 242 | 243 | /****************************************************************************** 244 | * Stdio Function 245 | * For debug info 246 | ******************************************************************************/ 247 | 248 | /** 249 | * 250 | * @brief Initialises Debug port 251 | * 252 | * @return none 253 | * 254 | */ 255 | void mx_hal_stdio_init(void); 256 | 257 | /** 258 | * 259 | * @brief Command line output 260 | * 261 | * param[in] c : Output one byte 262 | * 263 | * @return status 264 | * 265 | */ 266 | int mx_hal_cli_putstr(const char* str, uint32_t strlen); 267 | 268 | /** 269 | * 270 | * @brief Command line intput 271 | * 272 | * @return byte 273 | * 274 | */ 275 | int mx_hal_cli_getc(void); 276 | 277 | /****************************************************************************** 278 | * Ticker Function 279 | * Tick used for delay and timeout mechanism 280 | ******************************************************************************/ 281 | 282 | /** 283 | * 284 | * @brief System clock initialization 285 | * 286 | * @return none 287 | * 288 | */ 289 | void mx_hal_ms_ticker_init(void); 290 | 291 | /** 292 | * 293 | * @brief Get system clock 294 | * 295 | * @return system time 296 | * 297 | */ 298 | uint32_t mx_hal_ms_ticker_read(void); 299 | 300 | /** 301 | * 302 | * @brief Suspend current thread for a specific time 303 | * 304 | * param[in] delay : A time interval (Unit: millisecond) 305 | * 306 | * @return none 307 | * 308 | */ 309 | void mx_hal_delay_ms(volatile uint32_t delay); 310 | 311 | #ifdef __cplusplus 312 | } /* extern "C" */ 313 | #endif 314 | 315 | #endif 316 | -------------------------------------------------------------------------------- /resource/common/串口调试工具/SecureCRT.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/串口调试工具/SecureCRT.zip -------------------------------------------------------------------------------- /resource/common/数据手册/DS0021CN_EMW3031_V1.5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/数据手册/DS0021CN_EMW3031_V1.5.pdf -------------------------------------------------------------------------------- /resource/common/数据手册/DS0069CN_EMW3080(AB)_V1.8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/数据手册/DS0069CN_EMW3080(AB)_V1.8.pdf -------------------------------------------------------------------------------- /resource/common/数据手册/DS0089CN_EMW3060_V1.8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/数据手册/DS0089CN_EMW3060_V1.8.pdf -------------------------------------------------------------------------------- /resource/common/数据手册/DS0122CN_EMW3080V2_V1.2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/数据手册/DS0122CN_EMW3080V2_V1.2.pdf -------------------------------------------------------------------------------- /resource/common/烧录/3060/3060固件烧录方法.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3060/3060固件烧录方法.docx -------------------------------------------------------------------------------- /resource/common/烧录/3080.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080.rar -------------------------------------------------------------------------------- /resource/common/烧录/3080/EMW3080使用debug烧录方法.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/EMW3080使用debug烧录方法.pdf -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/MXCHIP_IMG_TOOL_RESET.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/MXCHIP_IMG_TOOL_RESET.exe -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/MXCHIP_MP_TOOLS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/MXCHIP_MP_TOOLS.exe -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/MXCHIP_MP_TOOLS.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/MXCHIP_MP_TOOLS.lnk -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/README!!!.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/README!!!.txt -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/horn@mx1290@moc.all.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/horn@mx1290@moc.all.bin -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/mpate.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/mpate.dll -------------------------------------------------------------------------------- /resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/mpimg.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/common/烧录/3080/MXCHIP_MP_TOOLS_V1.1/mpimg.dll -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/中国移动And-link协议规范(设备本地网关管理分册)v3.1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/中国移动And-link协议规范(设备本地网关管理分册)v3.1.docx -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/杭研入库测试工具/AndlinkDiagnotorIL_64_20180620.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/杭研入库测试工具/AndlinkDiagnotorIL_64_20180620.exe -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/杭研入库测试工具/Californium.properties: -------------------------------------------------------------------------------- 1 | #Californium CoAP Properties file 2 | #Thu Jun 28 11:25:11 CST 2018 3 | HTTP_SERVER_SOCKET_BUFFER_SIZE=8192 4 | UDP_CONNECTOR_OUT_CAPACITY=2147483647 5 | CONGESTION_CONTROL_ALGORITHM=Cocoa 6 | USE_CONGESTION_CONTROL=false 7 | ACK_TIMEOUT=2000 8 | MAX_ACTIVE_PEERS=150000 9 | TCP_CONNECT_TIMEOUT=10000 10 | NOTIFICATION_CHECK_INTERVAL_COUNT=100 11 | MAX_MESSAGE_SIZE=1024 12 | DEDUPLICATOR=DEDUPLICATOR_MARK_AND_SWEEP 13 | TCP_CONNECTION_IDLE_TIMEOUT=10 14 | COAP_PORT=5683 15 | ACK_TIMEOUT_SCALE=2.0 16 | PREFERRED_BLOCK_SIZE=512 17 | NETWORK_STAGE_RECEIVER_THREAD_COUNT=4 18 | PROTOCOL_STAGE_THREAD_COUNT=4 19 | MAX_TRANSMIT_WAIT=93000 20 | USE_STRICT_RESPONSE_MATCHING=false 21 | UDP_CONNECTOR_RECEIVE_BUFFER=0 22 | EXCHANGE_LIFETIME=247000 23 | HTTP_SERVER_SOCKET_TIMEOUT=100000 24 | CROP_ROTATION_PERIOD=2000 25 | UDP_CONNECTOR_DATAGRAM_SIZE=2048 26 | MAX_RETRANSMIT=4 27 | MAX_PEER_INACTIVITY_PERIOD=600 28 | MAX_RESOURCE_BODY_SIZE=8192 29 | NOTIFICATION_CHECK_INTERVAL=86400000 30 | LEISURE=5000 31 | HTTP_CACHE_RESPONSE_MAX_AGE=86400 32 | BLOCKWISE_STATUS_LIFETIME=300000 33 | UDP_CONNECTOR_SEND_BUFFER=0 34 | TCP_WORKER_THREADS=1 35 | HEALTH_STATUS_PRINT_LEVEL=FINEST 36 | NETWORK_STAGE_SENDER_THREAD_COUNT=4 37 | NON_LIFETIME=145000 38 | TOKEN_SIZE_LIMIT=8 39 | HTTP_PORT=8080 40 | MARK_AND_SWEEP_INTERVAL=10000 41 | HEALTH_STATUS_INTERVAL=60 42 | ACK_RANDOM_FACTOR=1.5 43 | NSTART=1 44 | USE_RANDOM_MID_START=true 45 | HTTP_CACHE_SIZE=32 46 | PROBING_RATE=1.0 47 | NOTIFICATION_REREGISTRATION_BACKOFF=2000 48 | COAP_SECURE_PORT=5684 49 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/杭研入库测试工具/conf/internetModelGWInfo.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/杭研入库测试工具/conf/internetModelGWInfo.json -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/杭研入库测试工具/conf/log4j.properties: -------------------------------------------------------------------------------- 1 | #My customized log properties 2 | #Thu Jun 28 11:25:11 CST 2018 3 | log4j.appender.Console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.File.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH\:mm\:ss,SSS} %l%n%m%n%n 5 | log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH\:mm\:ss,SSS} %l%n%m%n%n 6 | log4j.appender.File=org.apache.log4j.DailyRollingFileAppender 7 | log4j.rootLogger=INFO,Console,File 8 | log4j.appender.File.File=D\:\\Work\\project\\factory\\onenet_hangzhou\\debug\\gateay_tool\\logs\\log.log 9 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.File.Append=true 11 | log4j.appender.File.Threshold=DEBUG 12 | log4j.appender.Console.Target=System.out 13 | log4j.appender.File.layout=org.apache.log4j.PatternLayout 14 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/杭研入库测试工具/error.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/杭研入库测试工具/error.log -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/杭研入库测试工具/logs/log.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/杭研入库测试工具/logs/log.log -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/Firefox Setup 50.1.0.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/Firefox Setup 50.1.0.exe -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/copper_ota.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/copper_ota.txt -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/debug/test_by_copper/copper_ota.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/debug/test_by_copper/copper_ota.txt -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/火狐coap工具OTA说明.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/火狐浏览器coap工具OTA说明/火狐coap工具OTA说明.docx -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/app/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/app/Readme.txt -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/app/andlinkdemo1.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/app/andlinkdemo1.0.apk -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/Andlink模拟网关使用说明v2.2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/Andlink模拟网关使用说明v2.2.pdf -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/Californium.properties: -------------------------------------------------------------------------------- 1 | #Californium CoAP Properties file 2 | #Fri Aug 24 09:28:49 CST 2018 3 | HTTP_SERVER_SOCKET_BUFFER_SIZE=8192 4 | UDP_CONNECTOR_OUT_CAPACITY=2147483647 5 | CONGESTION_CONTROL_ALGORITHM=Cocoa 6 | USE_CONGESTION_CONTROL=false 7 | ACK_TIMEOUT=2000 8 | MAX_ACTIVE_PEERS=150000 9 | TCP_CONNECT_TIMEOUT=10000 10 | NOTIFICATION_CHECK_INTERVAL_COUNT=100 11 | MAX_MESSAGE_SIZE=1024 12 | DEDUPLICATOR=DEDUPLICATOR_MARK_AND_SWEEP 13 | TCP_CONNECTION_IDLE_TIMEOUT=10 14 | COAP_PORT=5683 15 | ACK_TIMEOUT_SCALE=2.0 16 | PREFERRED_BLOCK_SIZE=512 17 | NETWORK_STAGE_RECEIVER_THREAD_COUNT=4 18 | PROTOCOL_STAGE_THREAD_COUNT=4 19 | MAX_TRANSMIT_WAIT=93000 20 | USE_STRICT_RESPONSE_MATCHING=false 21 | UDP_CONNECTOR_RECEIVE_BUFFER=0 22 | EXCHANGE_LIFETIME=247000 23 | HTTP_SERVER_SOCKET_TIMEOUT=100000 24 | CROP_ROTATION_PERIOD=2000 25 | UDP_CONNECTOR_DATAGRAM_SIZE=2048 26 | MAX_RETRANSMIT=4 27 | MAX_PEER_INACTIVITY_PERIOD=600 28 | MAX_RESOURCE_BODY_SIZE=4096 29 | NOTIFICATION_CHECK_INTERVAL=86400000 30 | LEISURE=5000 31 | HTTP_CACHE_RESPONSE_MAX_AGE=86400 32 | BLOCKWISE_STATUS_LIFETIME=300000 33 | UDP_CONNECTOR_SEND_BUFFER=0 34 | TCP_WORKER_THREADS=1 35 | HEALTH_STATUS_PRINT_LEVEL=FINEST 36 | NETWORK_STAGE_SENDER_THREAD_COUNT=4 37 | NON_LIFETIME=145000 38 | TOKEN_SIZE_LIMIT=8 39 | HTTP_PORT=8080 40 | MARK_AND_SWEEP_INTERVAL=10000 41 | HEALTH_STATUS_INTERVAL=60 42 | ACK_RANDOM_FACTOR=1.5 43 | NSTART=1 44 | USE_RANDOM_MID_START=true 45 | HTTP_CACHE_SIZE=32 46 | PROBING_RATE=1.0 47 | NOTIFICATION_REREGISTRATION_BACKOFF=2000 48 | COAP_SECURE_PORT=5684 49 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/Temp/005056C00008-tcp112139620521883/.lck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/Temp/005056C00008-tcp112139620521883/.lck -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/andlink2.10-05.29-64bit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/andlink2.10-05.29-64bit.exe -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/andlinkPlugins.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/andlinkPlugins.log -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/db/andlink.lck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/db/andlink.lck -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/db/andlink.log: -------------------------------------------------------------------------------- 1 | /*C2*/SET SCHEMA PUBLIC 2 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540452025499,1540452025499,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'null','null','null','PXmsE6kQmxEgc0e3') 3 | COMMIT 4 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 5 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540452025499,1540452029482,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 6 | COMMIT 7 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 8 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540452025499,1540452115663,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 9 | COMMIT 10 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 11 | COMMIT 12 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540452245433,1540452245433,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'null','null','null','PXmsE6kQmxEgc0e3') 13 | COMMIT 14 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 15 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540452245433,1540452247309,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 16 | COMMIT 17 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 18 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540452245433,1540453198760,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 19 | COMMIT 20 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 21 | COMMIT 22 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453225072,1540453225072,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'null','null','null','PXmsE6kQmxEgc0e3') 23 | COMMIT 24 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 25 | COMMIT 26 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453241560,1540453241560,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'null','null','null','PXmsE6kQmxEgc0e3') 27 | COMMIT 28 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 29 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453241560,1540453242353,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 30 | COMMIT 31 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 32 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453241560,1540453418246,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 33 | COMMIT 34 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 35 | COMMIT 36 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453443687,1540453443687,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'null','null','null','PXmsE6kQmxEgc0e3') 37 | COMMIT 38 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 39 | COMMIT 40 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453459525,1540453459525,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'null','null','null','PXmsE6kQmxEgc0e3') 41 | COMMIT 42 | DELETE FROM DEVICE WHERE DEVICEID='CMCC-30531-B0F89330F997' 43 | INSERT INTO DEVICE VALUES('CMCC-30531-B0F89330F997','B0F89330F997','null','30531','192.168.1.102',1540453459525,1540453459911,'',1,'FatherDevice','Nsjq8T7L9PjitA1/',1,'1.4.3','1.0.1','null','PXmsE6kQmxEgc0e3') 44 | COMMIT 45 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/db/andlink.properties: -------------------------------------------------------------------------------- 1 | #HSQL Database Engine 2.2.6 2 | #Thu Oct 25 15:18:52 CST 2018 3 | version=2.2.6 4 | modified=yes 5 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/db/andlink.script: -------------------------------------------------------------------------------- 1 | SET DATABASE UNIQUE NAME HSQLDB65698C5B06 2 | SET DATABASE GC 0 3 | SET DATABASE DEFAULT RESULT MEMORY ROWS 0 4 | SET DATABASE EVENT LOG LEVEL 0 5 | SET DATABASE SQL NAMES FALSE 6 | SET DATABASE SQL REFERENCES FALSE 7 | SET DATABASE SQL SIZE TRUE 8 | SET DATABASE SQL TYPES FALSE 9 | SET DATABASE SQL TDC DELETE TRUE 10 | SET DATABASE SQL TDC UPDATE TRUE 11 | SET DATABASE SQL TRANSLATE TTI TYPES TRUE 12 | SET DATABASE SQL CONCAT NULLS TRUE 13 | SET DATABASE SQL UNIQUE NULLS TRUE 14 | SET DATABASE SQL CONVERT TRUNCATE TRUE 15 | SET DATABASE SQL AVG SCALE 0 16 | SET DATABASE SQL DOUBLE NAN TRUE 17 | SET DATABASE SQL LONGVAR IS LOB FALSE 18 | SET DATABASE TRANSACTION CONTROL LOCKS 19 | SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED 20 | SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE 21 | SET DATABASE TEXT TABLE DEFAULTS '' 22 | SET FILES WRITE DELAY 500 MILLIS 23 | SET FILES BACKUP INCREMENT TRUE 24 | SET FILES CACHE SIZE 10000 25 | SET FILES CACHE ROWS 50000 26 | SET FILES SCALE 8 27 | SET FILES LOB SCALE 32 28 | SET FILES DEFRAG 0 29 | SET FILES NIO TRUE 30 | SET FILES NIO SIZE 256 31 | SET FILES LOG TRUE 32 | SET FILES LOG SIZE 50 33 | CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e' 34 | ALTER USER SA SET LOCAL TRUE 35 | CREATE SCHEMA PUBLIC AUTHORIZATION DBA 36 | SET SCHEMA PUBLIC 37 | CREATE MEMORY TABLE PUBLIC.DEVICE(DEVICEID VARCHAR(32) NOT NULL PRIMARY KEY,MAC VARCHAR(17),PARENTDEVICEID VARCHAR(32),DEVICETYPE VARCHAR(24),IP VARCHAR(16),REGTIME BIGINT,LASTTIME BIGINT,PARAMDETAIL VARCHAR(256),STATUS INTEGER,DEVICECLASS VARCHAR(20),DEVICETOKEN VARCHAR(100),ISSYNC INTEGER,FIRMWAREVERSION VARCHAR(32),SOFTWAREVERSION VARCHAR(32),XDATA VARCHAR(1000),PRODUCTTOKEN VARCHAR(16)) 38 | ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1 39 | SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC 40 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC 41 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC 42 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC 43 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC 44 | GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC 45 | GRANT DBA TO SA 46 | SET SCHEMA SYSTEM_LOBS 47 | INSERT INTO BLOCKS VALUES(0,2147483647,0) 48 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/jsonFiles/IfEncrypt.json: -------------------------------------------------------------------------------- 1 | {"encrypt":0} 2 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/jsonFiles/SyncCode.json: -------------------------------------------------------------------------------- 1 | {"SyncCode":"1"} 2 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/jsonFiles/Version.json: -------------------------------------------------------------------------------- 1 | {"Version":"2.10y"} 2 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/jsonFiles/WiFiParameterSync.json: -------------------------------------------------------------------------------- 1 | {"deviceId": "CMCC-30103-AP1","data": {"SyncCode": "1","Configurations": [{"Radio": "2.4G","Index": 1,"Enable": 1,"SSID": "CMCC-2341","SecurityMode": "WPA-WPA2-Personal","Pwd":"12345678","MaxAssociateNum": 10,"SSIDAdvertisementEnabled": 1},{"Radio": "5G","Index": 1,"Enable": 1,"SSID": "CMCC-2341","SecurityMode": "WPA-WPA2-Personal","Pwd":"12345678","MaxAssociateNum": 10,"SSIDAdvertisementEnabled": 1}]}} 2 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/jsonFiles/ssid.json: -------------------------------------------------------------------------------- 1 | {"SSID":"LB_023","password":"12345678","encrypt":"WPAPSK"} 2 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/log.properties: -------------------------------------------------------------------------------- 1 | #JDK logger Properties file 2 | #Fri Aug 24 09:28:49 CST 2018 3 | .level=CONFIG 4 | java.util.logging.FileHandler.limit=50000 5 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 6 | handlers=java.util.logging.FileHandler,java.util.logging.ConsoleHandler 7 | java.util.logging.FileHandler.count=1 8 | com.xyz.foo.level=SEVERE 9 | java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter 10 | java.util.logging.ConsoleHandler.level=CONFIG 11 | java.util.logging.FileHandler.pattern=./andlinkPlugins.log 12 | java.util.logging.FileHandler.append=true 13 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/virtual_gateway/log4j.properties: -------------------------------------------------------------------------------- 1 | #My customized log properties 2 | #Fri Aug 24 09:28:49 CST 2018 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.D.MaxFileSize=1MB 5 | log4j.appender.D.BufferSize=1024 6 | log4j.rootLogger=info,stdout,D 7 | log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss,SSS} [%p]-[%C] %m%n 8 | log4j.appender.D.BufferedIO=true 9 | log4j.appender.D.MaxBackupIndex=1 10 | log4j.appender.D=com.chinamobile.smartgateway.andlink.util.MyAppender 11 | log4j.appender.D.Threshold=INFO 12 | log4j.appender.D.Append=true 13 | log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss,SSS} [%p]-[%C] %m%n 14 | log4j.appender.D.layout=org.apache.log4j.PatternLayout 15 | log4j.appender.D.ImmediateFlush=false 16 | log4j.appender.D.File=./andlinkPlugins.log 17 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.stdout.Target=System.out 19 | -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/~$开发环境使用说明书.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/~$开发环境使用说明书.docx -------------------------------------------------------------------------------- /resource/qlink/1.本地网关/虚拟开发环境/虚拟开发环境使用说明书.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/1.本地网关/虚拟开发环境/虚拟开发环境使用说明书.docx -------------------------------------------------------------------------------- /resource/qlink/2.云网关/app/ios_app.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/2.云网关/app/ios_app.jpg -------------------------------------------------------------------------------- /resource/qlink/2.云网关/app/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/2.云网关/app/readme.txt -------------------------------------------------------------------------------- /resource/qlink/2.云网关/app/和家亲99版本.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/2.云网关/app/和家亲99版本.png -------------------------------------------------------------------------------- /resource/qlink/2.云网关/中国移动And-link协议规范(设备云网关管理分册)v2.0.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/2.云网关/中国移动And-link协议规范(设备云网关管理分册)v2.0.docx -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/HOST端demo使用说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/HOST端demo使用说明.pdf -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/qlink_AT_command.md: -------------------------------------------------------------------------------- 1 | 2 | ## QLINK指令 3 | 4 | |序号|指令|描述| 5 | |---|---|---| 6 | |1|AT+QLINKPRODUCT|设置/读取QLINK产品参数| 7 | |2|AT+QLINKVERSION|查询QLINK版本参数| 8 | |3|AT+QLINKDM|设置/查询DM参数| 9 | |4|AT+QLINKRAWSTART|启动QLINK一键配网| 10 | |5|AT+QLINKUSERSTART|启动QLINK用户配网| 11 | |6|AT+QLINKSTART|启动QLINK服务| 12 | |7|AT+QLINKSTATUS|查询QLINK服务状态| 13 | |8|AT+QLINKSEND|设备发送数据| 14 | |9|AT+QLINKPARAM|设备收到平台设置指令后返回给WIFI模块| 15 | 16 | ### AT+QLINKPRODUCT 17 | 功能:查询/设置QLINK product info 18 | 19 | |查询指令:|`AT+QLINKPRODUCT?`| 20 | |---|:---| 21 | |响应:|`+QLINKPRODUCT:,,`| 22 | ||`OK`| 23 | 24 | |设置指令:|`AT+QLINKPRODUCT=,,,`| 25 | |---|:---| 26 | |响应:|`OK`| 27 | |参数:|`product_id`:产品ID| 28 | ||`product_token`:product token| 29 | ||`andlink_token`:andlink token| 30 | 31 | 32 | ### AT+QLINKVERSION 33 | 功能:查询QLINK product version info 34 | 35 | |查询指令:|`AT+QLINKVERSION?`| 36 | |---|:---| 37 | |响应:|`+QLINKVERSION:,`| 38 | ||`OK`| 39 | |参数:|`firmware_version`:WIFI固件版本信息| 40 | ||`software_version`:系统软件版本信息| 41 | 42 | ### AT+QLINKDM 43 | 功能:查询/设置QLINK DM info 44 | 45 | |查询指令:|`AT+QLINKDM?`| 46 | |---|:---| 47 | |响应:|`+QLINKDM:,,,,,,`| 48 | ||`OK`| 49 | 50 | |设置指令:|`AT+QLINKDEV=,,,,,,`| 51 | |---|:---| 52 | |响应:|`OK`| 53 | |参数:|`enable`:1:开启DM 0:关闭DM| 54 | ||`envir`:1:测试环境 0正式环境| 55 | ||`cmei`: 从移动终端公司获取| 56 | ||`version`:从移动终端公司获取| 57 | ||`appkey`:从移动终端公司获取| 58 | ||`secret`:从移动终端公司获取| 59 | ||`dmtime`:未用到| 60 | 61 | ### AT+QLINKRAWSTART 62 | 功能:开始QLINK一键配网,如果一键配网超时,自动进入用户配网模式 63 | 64 | |执行指令:|`AT+QLINKRAWSTART`| 65 | |---|:---| 66 | |响应:|`OK`| 67 | 68 | ### AT+QLINKUSERSTART 69 | 功能:开始QLINK用户配网,绑定成功前,系统默认进入此模式 70 | 71 | |执行指令:|`AT+QLINKRAWSTART`| 72 | |---|:---| 73 | |响应:|`OK`| 74 | 75 | ### AT+QLINKSTART 76 | 功能:启动QLINK服务 77 | 78 | |执行指令:|`AT+QLINKSTART`| 79 | |---|:---| 80 | |响应:|`OK`| 81 | 82 | 83 | ### AT+QLINKSTATUS 84 | 功能:查询QLINK服务状态 85 | 86 | |查询指令:|`AT+QLINKSTATUS?`| 87 | |---|:---| 88 | |响应:|`+QLINKSTATUS:`| 89 | ||`OK`| 90 | |参数:|`status`:NONE:未初始化;INIT:启动QLINK,开始连接服务器;CONNECT:连接到服务器;DISCONNECT:断开服务器| 91 | 92 | ### AT+QLINKSEND 93 | 功能:向服务器发送数据 94 | 95 | |设置指令:|`AT+QLINKSEND=`| 96 | |---|:---| 97 | |响应|`>`| 98 | |响应:|`OK`| 99 | |参数:|`msg_type`:Inform,File,ParamChange,Data| 100 | ||`data_len`:数据长度| 101 | 102 | ### AT+QLINKPARAM 103 | 功能:设备收到平台设置指令后返回给WIFI模块 104 | 105 | |设置指令:|`AT+QLINKSEND=`| 106 | |---|:---| 107 | |响应|`>`| 108 | |响应:|`OK`| 109 | |参数:|`type`:1:当前字段仅有配置功能,0:当前字段既有配置功能又有控制功能,每次收到服务器下发字段都需要发送给WIFI模块| 110 | 111 | 112 | ## QLINK事件通知 113 | |序号|指令|指令说明| 114 | |---|:---|:---| 115 | |1|`+QLINKEVENT=QLINK,`|连接服务器状态。status:CONNECT:连接;DISCONNECT:断开| 116 | |2|`+QLINKEVENT=GET`|服务器请求设备状态| 117 | |3|`+QLINKEVENT=SET,,`|data_len:数据长度;data:透传数据| 118 | |4|`+QLINKEVENT=SET,6,UNBIND`|解绑设备| 119 | |5|`+QLINKEVENT=SET,6,REBOOT`|重启设备| 120 | |6|`+QLINKEVENT=SET,7,FACTORY`|恢复出厂设置| 121 | 122 | # QLINK AT demo 123 | 124 | 125 | ``` 126 | /*说明: 127 | *该测试例程是杭研生产环境99版本应用 128 | */ 129 | 130 | /*设置QLINK 产品信息*/ 131 | AT+QLINKPRODUCT=501575,wS9OqT3wLIwkkOH1,JBuFCnhe66RiuSjJ\r 132 | 133 | /*设置QLINK DM参数*/ 134 | AT+QLINKDM=0,0,111001330000010, , , ,3600\r 135 | 136 | /*查询QLINK 产品信息*/ 137 | AT+QLINKPRODUCT? 138 | 139 | /*查询QLINK DM参数*/ 140 | AT+QLINKDM?\r 141 | 142 | /*开启本地网关一键配网模式*/ 143 | AT+QLINKRAWSTART 144 | 145 | /*开启云网关网关配网模式,默认优先云网关配网*/ 146 | AT+QLINKUSERSTART 147 | 148 | /*当模块连接连上路由器后,模块主动下发*/ 149 | +WEVENT:WIFI,CONNECT 150 | 151 | /*当连上路由器后,启动 QLINK 服务*/ 152 | AT+QLINKSTART\r 153 | 154 | /*当 QLINK 连接服务器成功后会主动下发*/ 155 | +EVENT:QLINK,CONNECT 156 | 157 | /*当 QLINK 与服务器断开 会主动下发*/ 158 | +EVENT:QLINK,DISCONNECT 159 | 160 | /*查询 QLINK 连接状态*/ 161 | AT+QLINKSTATUS? 162 | 163 | /*当APP调用请求接口后,会主动请求设备状态,此时模块主动下发*/ 164 | +QLINKEVENT:GET 165 | 166 | /*发送所有数据*/ 167 | AT+QLINKSEND=Inform,59\r 168 | {"params":[{"paramCode":"permitJoining","paramValue":"1"}]} 169 | 170 | /*当APP调用控制接口后,会主动下发指令控制设备状态,此时模块主动下发,MCU需要返回AT+QLINKPARAM指令*/ 171 | +QLINKEVENT:SET,, 172 | 173 | /*当APP调用重启接口,此时模块主动下发*/ 174 | +QLINKEVENT:SET,6,REBOOT 175 | 176 | /*当APP调用复位接口,此时模块主动下发,用户需要清除保存的参数,回复出厂设置*/ 177 | +QLINKEVENT:SET,7,FACTORY 178 | 179 | /*当APP调用解绑接口,此时模块主动下发,通知用户设备已经解绑*/ 180 | +QLINKEVENT:SET,6,UNBIND 181 | 182 | ``` 183 | 184 | -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/EMW3080BP-0000.QLINK.A102.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/EMW3080BP-0000.QLINK.A102.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A212.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A212.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A213.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A213.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A214.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A214.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A215.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MOC108_0000.QLINK.A215.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MOC108_9600.QLINK.A215.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MOC108_9600.QLINK.A215.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MX1290-0000.QLINK.A220.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MX1290-0000.QLINK.A220.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MX1290-9600.QLINK.A220.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MX1290-9600.QLINK.A220.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/MX1290_9600.QLINK.A212.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/MX1290_9600.QLINK.A212.zip -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/固件/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/固件/readme.txt -------------------------------------------------------------------------------- /resource/qlink/3.AT指令/杭研AT指令使用说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/3.AT指令/杭研AT指令使用说明.pdf -------------------------------------------------------------------------------- /resource/qlink/4.其他/code.txt: -------------------------------------------------------------------------------- 1 | https://github.com/MXCHIP/iot-host-sdk -------------------------------------------------------------------------------- /resource/qlink/4.其他/杭研AT固件分享交流.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/4.其他/杭研AT固件分享交流.pptx -------------------------------------------------------------------------------- /resource/qlink/image/bind_ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/bind_ok.png -------------------------------------------------------------------------------- /resource/qlink/image/cli_uart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/cli_uart.png -------------------------------------------------------------------------------- /resource/qlink/image/control_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/control_data.png -------------------------------------------------------------------------------- /resource/qlink/image/request_all_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/request_all_data.png -------------------------------------------------------------------------------- /resource/qlink/image/request_some_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/request_some_data.png -------------------------------------------------------------------------------- /resource/qlink/image/user_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/user_config.png -------------------------------------------------------------------------------- /resource/qlink/image/产品资料.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/产品资料.png -------------------------------------------------------------------------------- /resource/qlink/image/环境OK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/image/环境OK.png -------------------------------------------------------------------------------- /resource/qlink/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MXCHIP/iot-host-sdk/1af610659b0f00738d9aab1444e22f92b72177ac/resource/qlink/readme.txt -------------------------------------------------------------------------------- /src/alicloud_ilop/ica_protocol.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ica_protocol.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Step-2018 7 | * @brief AliCloud ILOP service functions and ica data parser 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include "ica_protocol.h" 28 | #include "alicloud_ilop.h" 29 | 30 | /****************************************************************************** 31 | * Macros 32 | ******************************************************************************/ 33 | 34 | #define MAX_ATTR 20 /**< attribute max value */ 35 | 36 | /****************************************************************************** 37 | * Type Definitions 38 | ******************************************************************************/ 39 | 40 | typedef struct _ilop_ica_attr_t { 41 | const struct ilop_ica_attr_t* attr_db[MAX_ATTR]; /**< attribute db */ 42 | int changed_handle[MAX_ATTR]; /**< ILOP characteristics numbers registered on cloud */ 43 | int num_handles; /**< MAX, ILOP characteristics numbers registered on cloud */ 44 | } ilop_ica_context_t; 45 | 46 | /****************************************************************************** 47 | * Variable Definitions 48 | ******************************************************************************/ 49 | 50 | static ilop_ica_context_t ica_db; 51 | 52 | /****************************************************************************** 53 | * Function Definitions 54 | ******************************************************************************/ 55 | 56 | void ica_protocol_format_handler(char* type, char* value, char* key) 57 | { 58 | int i, handle = 0; 59 | 60 | for (i = 0; i < ica_db.num_handles; i++) { 61 | if (ica_db.attr_db[i] == NULL) 62 | continue; 63 | handle = ica_db.attr_db[i]->index; 64 | 65 | if (strcmp(value, ica_db.attr_db[handle]->name) == 0) { 66 | if (emh_arg_for_arg(EMH_ARG_ILOP_VT, type) == ica_db.attr_db[handle]->type) { 67 | if (ica_db.attr_db[handle]->write_func != NULL) { 68 | ica_db.attr_db[handle]->write_func(key); 69 | } 70 | break; 71 | } 72 | } 73 | } 74 | } 75 | 76 | void ilop_ica_indicate_local_atts(void) 77 | { 78 | mx_status err = kNoErr; 79 | int i, handle = 0; 80 | 81 | if (ica_db.num_handles == 0) 82 | return; 83 | 84 | for (i = 0; i < ica_db.num_handles; i++) { 85 | if (ica_db.changed_handle[i] != ILOP_INVALID_HANDLE) { 86 | handle = ica_db.changed_handle[i]; 87 | break; 88 | } 89 | } 90 | if (i >= ica_db.num_handles) 91 | return; 92 | 93 | char prop_buff[512] = { 0 }; 94 | char event_buff[100] = { 0 }; 95 | const char* type; 96 | char* value; 97 | int prop_index = 0, event_index = 0; 98 | 99 | for (i = 0; i < ica_db.num_handles; i++) { 100 | if (ica_db.changed_handle[i] == ILOP_INVALID_HANDLE) 101 | continue; 102 | 103 | handle = ica_db.changed_handle[i]; 104 | 105 | if (ica_db.attr_db[handle]->read_func == NULL) 106 | continue; 107 | 108 | if (ica_db.attr_db[handle]->type == EMH_ARG_ILOP_VT_PROPERTY) { 109 | err = ica_db.attr_db[handle]->read_func(&value); 110 | require_noerr(err, exit); 111 | prop_index += sprintf(prop_buff + prop_index, "%s,%s,", ica_db.attr_db[handle]->name, value); 112 | } 113 | 114 | if (ica_db.attr_db[handle]->type == EMH_ARG_ILOP_VT_EVENT) { 115 | err = ica_db.attr_db[handle]->read_func(&value); 116 | require_noerr(err, exit); 117 | event_index += sprintf(event_buff + event_index, "%s,%s,", ica_db.attr_db[handle]->name, value); 118 | } 119 | } 120 | 121 | if (prop_index > 0) { 122 | prop_buff[prop_index - 1] = '\0'; 123 | ilop_log("Send Property to cloud %d bytes > %s", prop_index - 1, prop_buff); 124 | type = emh_arg_for_type(EMH_ARG_ILOP_VT, EMH_ARG_ILOP_VT_PROPERTY); 125 | err = emh_ilop_send_ica_to_cloud(type, prop_buff); 126 | require_noerr(err, exit); 127 | } 128 | 129 | if (event_index > 0) { 130 | event_buff[event_index - 1] = '\0'; 131 | ilop_log("Send Event to cloud %d bytes > %s", event_index - 1, event_buff); 132 | type = emh_arg_for_type(EMH_ARG_ILOP_VT, EMH_ARG_ILOP_VT_EVENT); 133 | err = emh_ilop_send_ica_to_cloud(type, event_buff); 134 | require_noerr(err, exit); 135 | } 136 | 137 | exit: 138 | 139 | for (i = 0; i < ica_db.num_handles; i++) { 140 | ica_db.changed_handle[i] = ILOP_INVALID_HANDLE; 141 | } 142 | return; 143 | } 144 | 145 | mx_status ilop_ica_attr_init(uint8_t attr_num_handls) 146 | { 147 | int i; 148 | 149 | for (i = 0; i < MAX_ATTR; i++) { 150 | ica_db.attr_db[i] = NULL; 151 | } 152 | 153 | for (i = 0; i < MAX_ATTR; i++) { 154 | ica_db.changed_handle[i] = ILOP_INVALID_HANDLE; 155 | } 156 | 157 | ica_db.num_handles = attr_num_handls; 158 | 159 | return kNoErr; 160 | } 161 | 162 | mx_status ilop_ica_attr_register(const struct ilop_ica_attr_t* attr) 163 | { 164 | int handle = 0; 165 | 166 | if (ica_db.num_handles > MAX_ATTR) 167 | return kRangeErr; 168 | 169 | handle = attr->index; 170 | ica_db.attr_db[handle] = attr; 171 | return kNoErr; 172 | } 173 | 174 | void ilop_ica_attr_indicate_by_handle(int handle) 175 | { 176 | if (ica_db.attr_db[handle] == NULL) 177 | return; 178 | if (ica_db.attr_db[handle]->index == handle) { 179 | if (ica_db.changed_handle[handle] == handle) 180 | return; 181 | ica_db.changed_handle[handle] = handle; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/alicloud_ilop/ica_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ica_protocol.h 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Step-2018 7 | * @brief AliCloud ILOP ICA Data parser header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __ICA_PROTOCOL_H__ 28 | #define __ICA_PROTOCOL_H__ 29 | 30 | #include "emh_api.h" 31 | 32 | /** \addtogroup protocols */ 33 | /** @{*/ 34 | 35 | /** \addtogroup Alicloud_ILOP_Service */ 36 | /** @{*/ 37 | 38 | /** 39 | * Cloud read attribute handler 40 | * 41 | * @param value[out] : point to attribute value buffer, application should write the correct value 42 | * 43 | * @return mx_status 44 | */ 45 | typedef mx_status (*ilop_ica_read_attr)(char** value); 46 | 47 | /** 48 | * Cloud write attribute handler 49 | * 50 | * @param[in] value : New attribute vale sent from the ilop cloud 51 | * 52 | * @return mx_status 53 | */ 54 | typedef mx_status (*ilop_ica_write_attr)(char* value); 55 | 56 | /** Alicloud ilop attribute description */ 57 | struct ilop_ica_attr_t { 58 | uint8_t index; /**< characteristics numbers registered on cloud */ 59 | char* name; /**< Attribute name */ 60 | emh_arg_ilop_vt_t type; /**< Attribute value type */ 61 | ilop_ica_read_attr read_func; /**< Attribute value read handler, optional if the value is readable*/ 62 | ilop_ica_write_attr write_func; /**< Attribute value write handler, optional if the value is writable */ 63 | }; 64 | 65 | #endif 66 | 67 | /** @}*/ 68 | /** @}*/ 69 | -------------------------------------------------------------------------------- /src/alicloud_ilop/raw_protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file raw_protocol.h 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Step-2018 7 | * @brief AliCloud ILOP Raw Data parser header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __RAW_PROTOCOL_H__ 28 | #define __RAW_PROTOCOL_H__ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif /* __cplusplus */ 33 | 34 | #include "mx_common.h" 35 | 36 | /****************************************************************************** 37 | * Enumerations 38 | ******************************************************************************/ 39 | 40 | typedef enum{ 41 | ATTR_TYPE_PROPERTY, 42 | ATTR_TYPE_EVENT, 43 | ATTR_TYPE_SERVICE, 44 | }attr_type_t; 45 | 46 | typedef enum { 47 | /* Basic data type */ 48 | TYPE_ID_BOOL = 0, /* Boolean: 0 or 1 */ 49 | TYPE_ID_INT8 = 1, /* Integer: -128 ~ 127 */ 50 | TYPE_ID_UINT8 = 2, /* Integer: 0 ~ 255 */ 51 | TYPE_ID_INT16 = 3, /* Integer: -32768 ~ 32767 */ 52 | TYPE_ID_UINT16 = 4, /* Integer 0 ~ 65535 */ 53 | TYPE_ID_INT32 = 5, /* Integer */ 54 | TYPE_ID_UINT32 = 6, 55 | TYPE_ID_INT64 = 7, 56 | TYPE_ID_UINT64 = 8, 57 | TYPE_ID_FLOAT32 = 9, /* Float */ 58 | TYPE_ID_FLOAT64 = 10, 59 | TYPE_ID_STRING = 11, /* String */ 60 | TYPE_ID_DATE = 12, /* DATE */ 61 | 62 | /* Extended data type */ 63 | TYPE_ID_ARRAY_BOOL = 16, 64 | TYPE_ID_ARRAY_INT8 = 17, 65 | TYPE_ID_ARRAY_UINT8 = 18, 66 | TYPE_ID_ARRAY_INT16 = 19, 67 | TYPE_ID_ARRAY_UINT16 = 20, 68 | TYPE_ID_ARRAY_INT32 = 21, 69 | TYPE_ID_ARRAY_UINT32 = 22, 70 | TYPE_ID_ARRAY_INT64 = 23, 71 | TYPE_ID_ARRAY_UINT64 = 24, 72 | TYPE_ID_ARRAY_FLOAT32 = 25, 73 | TYPE_ID_ARRAY_FLOAT64 = 26, 74 | TYPE_ID_ARRAY_STRING = 27, 75 | 76 | NUM_TYPE_ID 77 | } data_type_t; 78 | 79 | typedef union { 80 | bool boolValue; 81 | uint8_t uint8Value; 82 | int8_t int8Value; 83 | uint16_t uint16Value; 84 | int16_t int16Value; 85 | uint32_t uint32Value; 86 | int32_t int32Value; 87 | float floatValue; 88 | double doubleValue; 89 | uint64_t uint64Value; 90 | int64_t int64Value; 91 | char* stringValue; 92 | uint8_t* dataValue; 93 | } ilop_att_val_t; 94 | 95 | /** 96 | * Cloud read attribute handler 97 | * 98 | * @param value[out] : point to attribute value buffer, application should write the correct value 99 | * 100 | * @return status 101 | */ 102 | typedef mx_status (*ilop_raw_read_attr)(ilop_att_val_t* value, uint32_t* outlen); 103 | 104 | /** 105 | * Cloud write attribute handler 106 | * 107 | * @param[in] value : New attribute vale sent from the ILOP cloud 108 | * 109 | * @return status 110 | */ 111 | typedef mx_status (*ilop_raw_write_attr)(ilop_att_val_t value, uint32_t inlen); 112 | 113 | struct ilop_raw_attr_t { 114 | uint8_t index; 115 | uint8_t attr_id; 116 | uint8_t type_id; 117 | ilop_raw_read_attr read_func; 118 | ilop_raw_write_attr write_func; 119 | }; 120 | 121 | /* ============================================================================================== */ 122 | /* MACRO & TYPE DEFINITION REGION */ 123 | /* ============================================================================================== */ 124 | /* 125 | * 帧结构定义如下: 126 | * ---------------------------------------------------------------- 127 | * | HEAD | LENGTH | VER | CMD | PAYLOAD | CHKSUM | 128 | * ---------------------------------------------------------------- 129 | * 1Byte 2Byte 1Byte 1Byte n Byte 1Byte 130 | */ 131 | 132 | /* 133 | * PAYLOAD 帧结构定义如下: 134 | * ----------------------------- 135 | * | method | id | data | 136 | * ----------------------------- 137 | * 1Byte 4Byte n Byte 138 | */ 139 | 140 | /* 141 | * set/report 的 data 帧结构定义如下:(len 仅在类型为数组和文本(text)的情况下需要,表示长度) 142 | * ------------------------------------------- 143 | * | typeid | attrid | [len] | value | 144 | * ------------------------------------------- 145 | * 1Byte 1Byte 2Byte n Byte 146 | */ 147 | 148 | #define RAW_PROTOCOL_HEAD 0xAA 149 | #define RAW_PROTOCOL_REGION_HEAD_LEN 5 /* HEAD + LENGTH + VER + CMD */ 150 | #define RAW_PROTOCOL_REGION_LENGTH_FIXED 3 /* LENGTH(VER+CMD+CHKSUM) */ 151 | #define RAW_PROTOCOL_FRAME_LEN_FIXED (RAW_PROTOCOL_REGION_HEAD_LEN + 1) /* Fixed length in frames (except for other fields in DATA domain) */ 152 | #define RAW_PROTOCOL_VER 0x01 153 | 154 | #define CONFIG_MAX_PKG_SIZE 256 155 | 156 | typedef enum { 157 | RAW_UP_DATA = 0x00, 158 | RAW_DOWN_DATA = 0x80, 159 | } raw_elem_cmd_t; 160 | 161 | typedef enum { 162 | /* Downlink method */ 163 | RAW_METHOD_GET = 0x00, 164 | RAW_METHOD_SET = 0x01, 165 | RAW_METHOD_SERVICE = 0x02, 166 | 167 | /* Uplink method */ 168 | RAW_METHOD_REPORT = 0x80, 169 | RAW_METHOD_EVENT = 0x81, 170 | 171 | /* General response */ 172 | RAW_METHOD_ACK = 0xFF 173 | } raw_data_method_t; 174 | 175 | /* ============================================================================================== */ 176 | /* DATA STRUCTURE DEFINITION REGION */ 177 | /* ============================================================================================== */ 178 | 179 | /* 一般缓冲区 */ 180 | typedef struct { 181 | uint8_t buffer[CONFIG_MAX_PKG_SIZE]; 182 | uint16_t size; /* Cache size */ 183 | uint16_t length; /* Cache length */ 184 | } data_buffer_t; 185 | 186 | #pragma pack(1) /* 1 byte alignment */ 187 | 188 | typedef struct 189 | { 190 | uint8_t head; 191 | uint16_t length; 192 | uint8_t ver; 193 | uint8_t cmd; 194 | } raw_protocol_head_t; 195 | 196 | /* Transparent (Passthrough) frame payload domain header */ 197 | typedef struct 198 | { 199 | uint8_t method; 200 | uint32_t id; 201 | uint8_t data; 202 | } raw_payload_data_head_t; 203 | 204 | typedef struct 205 | { 206 | uint8_t type_id; 207 | uint8_t attr_id; 208 | uint8_t value; 209 | } raw_body_format_t; 210 | 211 | typedef struct 212 | { 213 | uint8_t service_id; 214 | uint8_t data; 215 | } raw_service_body_format_t; 216 | 217 | #pragma pack() /* Cancel custom byte alignment */ 218 | 219 | #ifdef __cplusplus 220 | } 221 | #endif /* __cplusplus */ 222 | 223 | #endif 224 | -------------------------------------------------------------------------------- /src/alicloud_sds/alicloud_sds.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file alicloud_sds.h 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 9-Apr-2018 7 | * @brief AliCloud SDS service functions and framework header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _ALICLOUD_SDS_H_ 28 | #define _ALICLOUD_SDS_H_ 29 | 30 | #include "emh_api.h" 31 | 32 | /** \addtogroup protocols */ 33 | /** @{*/ 34 | 35 | /** \addtogroup Alicloud_SDS_Service */ 36 | /** @{*/ 37 | 38 | /****************************************************************************** 39 | * Constants 40 | ******************************************************************************/ 41 | 42 | #define ALISDS_INVALID_HANDLE (-1) 43 | 44 | /****************************************************************************** 45 | * Enumerations 46 | ******************************************************************************/ 47 | 48 | /** Alicloud sds service events */ 49 | enum alisds_event_e { 50 | ALISDS_EVENT_WLAN_CONFIG_STARTED, /**< AWS service is started to set wlan and cloud. */ 51 | ALISDS_EVENT_WLAN_CONNECTED, /**< Device is connected to Wi-Fi access point. */ 52 | ALISDS_EVENT_WLAN_DISCONNECTED, /**< Device is disconnected from Wi-Fi access point. */ 53 | ALISDS_EVENT_CLOUD_CONNECTED, /**< Alicloud sds service is connected */ 54 | ALISDS_EVENT_CLOUD_DISCONNECTED, /**< Alicloud sds service is disconnected. */ 55 | }; 56 | typedef uint8_t alisds_event_t; /**< Alicloud sds service events (see #alisds_event_e) */ 57 | 58 | /** Alicloud sds attribute types, protocol will convert values to SDS JSON packet according to these types */ 59 | enum alisds_att_type_e { 60 | ALI_ATT_TYPE_BOOL, /**< Boolean value. convert to "0 or "1" */ 61 | ALI_ATT_TYPE_INT, /**< Integer value. convet to "123" */ 62 | ALI_ATT_TYPE_FLOAT, /**< Float value. convet to "123.3" */ 63 | ALI_ATT_TYPE_STRING, /**< String value. no need to convert */ 64 | ALI_ATT_TYPE_DATA, /**< Raw data. convert to string with base64*/ 65 | ALI_ATT_TYPE_NULL, 66 | }; 67 | typedef uint8_t alisds_att_type_t; /**< Alicloud sds attribute types (see #alisds_att_type_e) */ 68 | 69 | /****************************************************************************** 70 | * Type Definitions 71 | ******************************************************************************/ 72 | 73 | typedef int alisds_attr_handle_t; 74 | 75 | /** Alicloud sds attribute value */ 76 | typedef union { 77 | bool boolValue; 78 | int intValue; 79 | double floatValue; 80 | char* stringValue; 81 | char* dateValue; 82 | } alisds_att_val_t; 83 | 84 | /****************************************************************************** 85 | * Function Declarations 86 | ******************************************************************************/ 87 | 88 | /** 89 | * Cloud read attribute handler 90 | * 91 | * @param value[out] : point to attribute value buffer, application should write the correct value 92 | * 93 | * @return status 94 | */ 95 | typedef mx_status (*alisds_read_attr)(alisds_att_val_t* value); 96 | 97 | /** 98 | * Cloud write attribute handler 99 | * 100 | * @param[in] value : New attribute vale sent from the SDS cloud 101 | * 102 | * @return status 103 | */ 104 | typedef mx_status (*alisds_write_attr)(alisds_att_val_t value); 105 | 106 | /** Alicloud sds attribute description */ 107 | typedef struct { 108 | char* name; /**< Attribute name */ 109 | alisds_att_type_t type; /**< Attribute value type */ 110 | alisds_read_attr read_func; /**< Attribute value read handler, optional if the value is readable*/ 111 | alisds_write_attr write_func; /**< Attribute value write handler, optional if the value is writable */ 112 | } alisds_attr_t; 113 | 114 | /****************************************************************************** 115 | * Function Declarations 116 | ******************************************************************************/ 117 | 118 | /** 119 | * @brief Initialize EMW module with product info registered on cloud 120 | * console, allocate memory for SDS attr handle database. 121 | * Should be called before attr initialize see #alisds_attr_init 122 | * 123 | * @param[in] config : SDS product info registered on cloud console 124 | * @param[in] num_handles : The max. attribute numbers, required to allocate 125 | * memory for attr database 126 | * 127 | * @return status 128 | * 129 | */ 130 | mx_status alisds_init(const emh_alisds_config_t* config, int num_handles); 131 | 132 | /** 133 | * @brief SDS Attribute initialization, add the attribute to database 134 | * 135 | * @param[in] handle : attribute handle 136 | * @param[in] attr : Alicloud sds attribute description 137 | * @return status 138 | * 139 | */ 140 | mx_status alisds_attr_init(alisds_attr_handle_t handle, alisds_attr_t attr); 141 | 142 | /** 143 | * 144 | * @brief Alicould sds service runloop, application should called 145 | * periodically to handle events and transfer data. 146 | * To save power, also can be called when uart data is ready 147 | * to receive or sensor data is ready to send to cloud 148 | * @note Never call this function in event handler 149 | * 150 | * @return status 151 | * 152 | */ 153 | mx_status alisds_runloop(void); 154 | 155 | /** 156 | * 157 | * @brief Prepare to send attribute to cloud, attribute value will 158 | * be read and send in SDS runloop alisds_runloop 159 | * @note This function do not send data use AT command, so it can 160 | * be called inside the event handler. #alisds_runloop will 161 | * do the actually read and send function. 162 | * 163 | * @param[in] handle : attribute handle 164 | * @param[in] attr : Alicloud sds attribute description 165 | * @return status 166 | * 167 | */ 168 | void alisds_attr_indicate_by_handle(int handle); 169 | 170 | /** 171 | * 172 | * @brief Send provision data to SDS cloud, this usually called after AWS 173 | * Wi-Fi config to prove APP is bound to a correct device. provision 174 | * data is defined on SDS cloud console. 175 | * 176 | * @return none 177 | * 178 | */ 179 | void alisds_provision(void); 180 | 181 | /** 182 | * 183 | * @brief Try to procedure an unbound operation on cloud if connected and 184 | * restore module settings to default. 185 | * 186 | * @return none 187 | * 188 | */ 189 | void alisds_restore(void); 190 | 191 | /** 192 | * 193 | * @brief Alicloud SDS service event handler accomplished by application 194 | * 195 | * @return none 196 | * 197 | */ 198 | MX_WEAK void alisds_event_handler(alisds_event_t event); 199 | 200 | #endif //_ALICLOUD_SDS_H_ 201 | 202 | /** @}*/ 203 | /** @}*/ 204 | -------------------------------------------------------------------------------- /src/cloud_qlink/cloud_qlink.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file alicloud_qlink.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Step-2018 7 | * @brief AliCloud qlink service functions and framework 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include "cloud_qlink.h" 28 | #include "ATCmdParser/ATCmdParser.h" 29 | #include "mx_hal.h" 30 | 31 | /****************************************************************************** 32 | * Enumerations 33 | ******************************************************************************/ 34 | 35 | typedef enum { 36 | eState_M1_initialize = 1, /**< State machine: Reset and initialize module */ 37 | eState_M2_provision = 2, /**< State machine: Waiting for WiFi config */ 38 | eState_M2_provision_ap = 3,/** connect to WiFi successfully, waiting for cloud connection */ 39 | eState_M3_normal = 4, /**< State machine: Connected to cloud, application running */ 40 | eState_M4_disconnected = 5, /**< State machine: Disconnect to cloud, all data transmission should stop */ 41 | eState_M5_fault = 6, /**< State machine: Drop in an unexpected error */ 42 | } qlink_device_state_e; 43 | 44 | /****************************************************************************** 45 | * Type Definitions 46 | ******************************************************************************/ 47 | 48 | typedef struct { 49 | qlink_device_state_e device_state; /**< Device state machine. */ 50 | emh_arg_qlink_conn_t cloud_state; /**< QLINK service connection state. */ 51 | } qlink_context_t; 52 | 53 | /****************************************************************************** 54 | * Variable Definitions 55 | ******************************************************************************/ 56 | 57 | static emh_qlink_config_t* qlink_config = NULL; 58 | static qlink_context_t qlink_context; 59 | 60 | 61 | /****************************************************************************** 62 | * Static Function Declarations 63 | ******************************************************************************/ 64 | 65 | /****************************************************************************** 66 | * Function Definitions 67 | ******************************************************************************/ 68 | 69 | MX_WEAK void qlink_event_handler(qlink_event_t event) 70 | { 71 | switch (event) { 72 | case QLINK_EVENT_WLAN_CONFIG_STARTED: { 73 | qlink_log("Wi-Fi config...."); 74 | break; 75 | } 76 | case QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE: { 77 | qlink_log("WiFi config in AP mode......"); 78 | break; 79 | } 80 | case QLINK_EVENT_WLAN_CONNECTED: { 81 | qlink_log("Wi-Fi connected"); 82 | break; 83 | } 84 | case QLINK_EVENT_WLAN_DISCONNECTED: { 85 | qlink_log("Wi-Fi disconnected"); 86 | break; 87 | } 88 | case QLINK_EVENT_CLOUD_CONNECTED: { 89 | qlink_log("Cloud connected"); 90 | break; 91 | } 92 | case QLINK_EVENT_CLOUD_DISCONNECTED: { 93 | qlink_log("Cloud disconnected"); 94 | break; 95 | } 96 | } 97 | } 98 | 99 | mx_status qlink_init(emh_qlink_config_t *config) 100 | { 101 | mx_status err = kNoErr; 102 | 103 | qlink_context.device_state = eState_M1_initialize; 104 | qlink_context.cloud_state = EMH_ARG_QLINK_CONN_CLOUD_DISCONNECTED; 105 | 106 | qlink_config = config; 107 | 108 | err = emh_init(); 109 | require_noerr(err, exit); 110 | 111 | exit: 112 | return err; 113 | } 114 | 115 | static mx_status _handle_state_initialize(void) 116 | { 117 | mx_status err = kNoErr; 118 | 119 | qlink_log("FW version: %s", emh_module_get_fw_version()); 120 | 121 | err = emh_qlink_config(qlink_config, true); 122 | require_noerr(err, exit); 123 | 124 | qlink_context.device_state = eState_M2_provision; 125 | 126 | exit: 127 | return err; 128 | } 129 | 130 | mx_status qlink_runloop(void) 131 | { 132 | mx_status err = kNoErr; 133 | 134 | switch (qlink_context.device_state) { 135 | case eState_M1_initialize: { 136 | err = _handle_state_initialize(); 137 | require_noerr_action(err, exit, qlink_context.device_state = eState_M5_fault); 138 | break; 139 | } 140 | 141 | case eState_M2_provision: {//waitint for connect to ap 142 | break; 143 | } 144 | 145 | case eState_M2_provision_ap:{ //connect to ap successfully, buf fail to connect to cloud 146 | qlink_context.device_state = eState_M4_disconnected; 147 | emh_qlink_service_start(); 148 | break; 149 | } 150 | 151 | case eState_M3_normal: 152 | case eState_M4_disconnected: { 153 | break; 154 | } 155 | 156 | case eState_M5_fault: { 157 | break; 158 | } 159 | 160 | default: 161 | qlink_log("STATE ERROR"); 162 | err = kNoErr; 163 | } 164 | 165 | emh_runloop(); 166 | exit: 167 | return err; 168 | } 169 | 170 | void emh_ev_wlan(emh_arg_wlan_ev_t event) 171 | { 172 | qlink_debug_log("Wlan event: %s", emh_arg_for_type(EMH_ARG_WLAN_EV, event)); 173 | if (event == EMH_ARG_WLAN_EV_STA_CONNECTED) { 174 | qlink_event_handler(QLINK_EVENT_WLAN_CONNECTED); 175 | qlink_context.device_state = eState_M2_provision_ap; 176 | } else if (event == EMH_ARG_WLAN_EV_STA_DISCONNECTED) { 177 | qlink_event_handler(QLINK_EVENT_WLAN_DISCONNECTED); 178 | } else if (event == EMH_ARG_WLAN_EV_UAP_ESTABLISHED) { 179 | qlink_event_handler(QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE); 180 | } 181 | } 182 | 183 | void emh_ev_qlink_connection(emh_arg_qlink_conn_t conn) 184 | { 185 | qlink_debug_log("AliCloud event: %s", emh_arg_for_type(EMH_ARG_QLINK_CONN, conn)); 186 | 187 | qlink_context.cloud_state = conn; 188 | 189 | if (conn == EMH_ARG_QLINK_CONN_CLOUD_CONNECTED) { 190 | 191 | /* EMW3080 has unexpected uart data lost after cloud connection, should fix in future */ 192 | mx_hal_delay_ms(1000); 193 | qlink_event_handler(QLINK_EVENT_CLOUD_CONNECTED); 194 | 195 | qlink_context.device_state = eState_M3_normal; 196 | } 197 | 198 | if (conn == EMH_ARG_QLINK_CONN_CLOUD_DISCONNECTED) { 199 | qlink_event_handler(QLINK_EVENT_CLOUD_DISCONNECTED); 200 | qlink_context.device_state = eState_M4_disconnected; 201 | } 202 | } 203 | 204 | MX_WEAK void emh_ev_qlink_get_local_attrs(emh_qlink_msg_t* msg) 205 | { 206 | qlink_log("please redeclare this function in application!!!"); 207 | } 208 | 209 | MX_WEAK int emh_ev_qlink_set_local_attrs(emh_qlink_msg_t* msg) 210 | { 211 | return 0; 212 | } 213 | 214 | mx_status qlink_raw_start(void) 215 | { 216 | return emh_qlink_raw_start(); 217 | } 218 | 219 | mx_status qlink_user_start(void) 220 | { 221 | return emh_qlink_user_start(); 222 | } 223 | 224 | mx_status qlink_send_data( char *type, uint8_t *data, uint32_t len ) 225 | { 226 | return emh_qlink_send_json_to_cloud( type, data, len ); 227 | } -------------------------------------------------------------------------------- /src/cloud_qlink/cloud_qlink.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file alicloud_qlink.h 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Step-2018 7 | * @brief AliCloud QLINK service functions and framework header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _CLOUD_QLINK_H_ 28 | #define _CLOUD_QLINK_H_ 29 | 30 | #include "emh_api.h" 31 | 32 | /** \addtogroup protocols */ 33 | /** @{*/ 34 | 35 | /** \addtogroup Alicloud_QLINK_Service */ 36 | /** @{*/ 37 | 38 | /****************************************************************************** 39 | * Macros 40 | ******************************************************************************/ 41 | 42 | #define qlink_log(M, ...) MX_LOG(CONFIG_CLOUD_DEBUG, "QLINK", M, ##__VA_ARGS__) 43 | #define qlink_debug_log(M, ...) //MX_LOG(CONFIG_CLOUD_DEBUG, "QLINK_DEBUG", M, ##__VA_ARGS__) 44 | 45 | /****************************************************************************** 46 | * Constants 47 | ******************************************************************************/ 48 | 49 | #define QLINK_INVALID_HANDLE (-1) 50 | 51 | /****************************************************************************** 52 | * Enumerations 53 | ******************************************************************************/ 54 | 55 | /** Alicloud QLINK service events */ 56 | enum qlink_event_e { 57 | QLINK_EVENT_WLAN_CONFIG_STARTED, /**< AWS service is started to set wlan and cloud. */ 58 | QLINK_EVENT_WLAN_CONFIG_STARTED_IN_AP_MODE, 59 | QLINK_EVENT_WLAN_CONNECTED, /**< Device is connected to Wi-Fi access point. */ 60 | QLINK_EVENT_WLAN_DISCONNECTED, /**< Device is disconnected from Wi-Fi access point. */ 61 | QLINK_EVENT_CLOUD_CONNECTED, /**< Alicloud QLINK service is connected */ 62 | QLINK_EVENT_CLOUD_DISCONNECTED, /**< Alicloud QLINK service is disconnected. */ 63 | }; 64 | typedef uint8_t qlink_event_t; /**< Alicloud QLINK service events */ 65 | 66 | /** Alicloud sds attribute types, protocol will convert values to SDS JSON packet according to these types */ 67 | enum qlink_att_type_e { 68 | QLINK_ATT_TYPE_BOOL, /**< Boolean value. convert to "0 or "1" */ 69 | QLINK_ATT_TYPE_INT, /**< Integer value. convet to "123" */ 70 | QLINK_ATT_TYPE_FLOAT, /**< Float value. convet to "123.3" */ 71 | QLINK_ATT_TYPE_STRING, /**< String value. no need to convert */ 72 | QLINK_ATT_TYPE_DATA, /**< Raw data. convert to string with base64*/ 73 | QLINK_ATT_TYPE_NULL, 74 | }; 75 | typedef uint8_t qlink_att_type_t; /**< Alicloud sds attribute types (see #qlink_att_type_e) */ 76 | 77 | /****************************************************************************** 78 | * Type Definitions 79 | ******************************************************************************/ 80 | 81 | typedef int qlink_attr_handle_t; 82 | 83 | /** Alicloud sds attribute value */ 84 | typedef union { 85 | bool boolValue; 86 | int intValue; 87 | double floatValue; 88 | char* stringValue; 89 | char* dateValue; 90 | } qlink_att_val_t; 91 | 92 | /****************************************************************************** 93 | * Function Declarations 94 | ******************************************************************************/ 95 | 96 | /** 97 | * Cloud read attribute handler 98 | * 99 | * @param value[out] : point to attribute value buffer, application should write the correct value 100 | * 101 | * @return status 102 | */ 103 | typedef mx_status (*qlink_read_attr)(qlink_att_val_t* value); 104 | 105 | /** 106 | * Cloud write attribute handler 107 | * 108 | * @param[in] value : New attribute vale sent from the SDS cloud 109 | * 110 | * @return status 111 | */ 112 | typedef mx_status (*qlink_write_attr)(qlink_att_val_t value); 113 | 114 | /****************************************************************************** 115 | * Type Definitions 116 | ******************************************************************************/ 117 | /** Cloud qlink attribute description */ 118 | typedef struct { 119 | char* name; /**< Attribute name */ 120 | qlink_att_type_t type; /**< Attribute value type */ 121 | qlink_read_attr read_func; /**< Attribute value read handler, optional if the value is readable*/ 122 | qlink_write_attr write_func; /**< Attribute value write handler, optional if the value is writable */ 123 | } qlink_attr_t; 124 | 125 | /****************************************************************************** 126 | * Function Declarations 127 | ******************************************************************************/ 128 | 129 | /** 130 | * @brief Initialize EMW module with product info registered on cloud 131 | * console. 132 | * 133 | * @param[in] config : qlink product info registered on cloud console 134 | * 135 | * @return mx_status 136 | * 137 | */ 138 | mx_status qlink_init(emh_qlink_config_t *config); 139 | 140 | /** 141 | * @brief Cloud qlink service runloop, application should called 142 | * periodically to handle events and transfer data. 143 | * To save power, also can be called when uart data is ready 144 | * to receive or sensor data is ready to send to cloud 145 | * @note Never call this function in event handler 146 | * 147 | * @return mx_status 148 | * 149 | */ 150 | mx_status qlink_runloop(void); 151 | 152 | /** 153 | * @brief Start one key Wi-Fi configuration. EMW module start monitor mode 154 | * 155 | * @return mx_status 156 | * 157 | */ 158 | mx_status qlink_raw_start(void); 159 | 160 | /** 161 | * @brief Start user Wi-Fi configuration. 162 | * @note In the monitor mode, parsing the air package, connecting the server, binding the phone 163 | * 164 | * 165 | * @return mx_status 166 | */ 167 | mx_status qlink_user_start(void); 168 | 169 | /** 170 | * @brief 171 | * 172 | * 173 | */ 174 | mx_status qlink_send_data( char *type, uint8_t *data, uint32_t len ); 175 | 176 | #endif //_CLOUD_QLINK_H_ 177 | 178 | /** @}*/ 179 | /** @}*/ 180 | -------------------------------------------------------------------------------- /src/helper/cli/mx_cli.h: -------------------------------------------------------------------------------- 1 | /** 2 | * UNPUBLISHED PROPRIETARY SOURCE CODE 3 | * Copyright (c) 2016 MXCHIP Inc. 4 | * 5 | * The contents of this file may not be disclosed to third parties, copied or 6 | * duplicated in any form, in whole or in part, without the prior written 7 | * permission of MXCHIP Corporation. 8 | * 9 | */ 10 | 11 | #ifndef __MX_CLI_H__ 12 | #define __MX_CLI_H__ 13 | /** Structure for registering CLI commands */ 14 | struct cli_command { 15 | /** The name of the CLI command */ 16 | const char* name; 17 | /** The help text associated with the command */ 18 | const char* help; 19 | /** The function that should be invoked for this command. */ 20 | void (*function)(char* pcWriteBuffer, int xWriteBufferLen, int argc, char** argv); 21 | }; 22 | 23 | #define cmd_printf(...) \ 24 | do { \ 25 | if (xWriteBufferLen > 0) { \ 26 | snprintf(pcWriteBuffer, xWriteBufferLen, __VA_ARGS__); \ 27 | xWriteBufferLen -= strlen(pcWriteBuffer); \ 28 | pcWriteBuffer += strlen(pcWriteBuffer); \ 29 | } \ 30 | } while (0) 31 | 32 | #define CLI_ARGS char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv 33 | 34 | /** Register a CLI command 35 | * 36 | * This function registers a command with the command-line interface. 37 | * 38 | * \param[in] command The structure to register one CLI command 39 | * \return 0 on success 40 | * \return 1 on failure 41 | */ 42 | int cli_register_command(const struct cli_command* command); 43 | 44 | /** Unregister a CLI command 45 | * 46 | * This function unregisters a command from the command-line interface. 47 | * 48 | * \param[in] command The structure to unregister one CLI command 49 | * \return 0 on success 50 | * \return 1 on failure 51 | */ 52 | int cli_unregister_command(const struct cli_command* command); 53 | 54 | /** Stop the CLI thread and carry out the cleanup 55 | * 56 | * \return kNoErr on success 57 | * \return error code otherwise. 58 | * 59 | */ 60 | int cli_stop(void); 61 | 62 | /** Register a batch of CLI commands 63 | * 64 | * Often, a module will want to register several commands. 65 | * 66 | * \param[in] commands Pointer to an array of commands. 67 | * \param[in] num_commands Number of commands in the array. 68 | * \return 0 on success 69 | * \return 1 on failure 70 | */ 71 | int cli_register_commands(const struct cli_command* commands, int num_commands); 72 | 73 | /** Unregister a batch of CLI commands 74 | * 75 | * \param[in] commands Pointer to an array of commands. 76 | * \param[in] num_commands Number of commands in the array. 77 | * \return 0 on success 78 | * \return 1 on failure 79 | */ 80 | int cli_unregister_commands(const struct cli_command* commands, 81 | int num_commands); 82 | 83 | /* Get a CLI msg 84 | * 85 | * If an external input task wants to use the CLI, it can use 86 | * cli_get_cmd_buffer() to get a command buffer that it can then 87 | * submit to the CLI later using cli_submit_cmd_buffer(). 88 | * 89 | * \param buff Pointer to a char * to place the buffer pointer in. 90 | * \return 0 on success 91 | * \return error code otherwise. 92 | */ 93 | int cli_getchar(char* inbuf); 94 | 95 | /* Send CLI output msg 96 | * 97 | * \param buff Pointer to a char * buffer. 98 | * \return 0 on success 99 | * \return error code otherwise. 100 | */ 101 | int cli_printf(const char* buff, ...); 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/helper/emhost/ATCmdParser/ATCmdParser.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ATCmdParser.h 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 9-Apr-2018 7 | * @brief EMW module AT command parser function header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _AT_CMD_PARSER_H_ 28 | #define _AT_CMD_PARSER_H_ 29 | 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** \addtogroup emhost */ 38 | /** @{*/ 39 | 40 | /** \addtogroup AT_parser */ 41 | /** @{*/ 42 | 43 | /****************************************************************************** 44 | * Constants 45 | ******************************************************************************/ 46 | 47 | /****************************************************************************** 48 | * Type Definitions 49 | ******************************************************************************/ 50 | 51 | /** 52 | * Incomming AT out-of-band packet handler 53 | */ 54 | typedef void (*oob_callback)(void); 55 | 56 | /** 57 | * Incomming AT out-of-band packet format link node 58 | */ 59 | struct oob { 60 | unsigned len; 61 | const char* prefix; 62 | oob_callback cb; 63 | void* next; 64 | }; 65 | 66 | /****************************************************************************** 67 | * Function Declarations 68 | ******************************************************************************/ 69 | 70 | /** 71 | * @brief Enable debug mode 72 | * 73 | * @return none 74 | */ 75 | void ATCmdParser_debug(bool on); 76 | 77 | /** 78 | * @brief AT command parser initialize 79 | * 80 | * @param[in] output_delimiter: AT output command delimiter chars, "\r", "\r\n", "\n", etc 81 | * @param[in] input_delimiter: AT input respond and event delimiter chars, "\r", "\r\n", "\n", etc 82 | * @param[in] timeout: AT receive timeout, also changable by #ATCmdParser_set_timeout 83 | * @param[in] debug: Enable debug mode or not 84 | * 85 | * @return none 86 | */ 87 | void ATCmdParser_init(const char* output_delimiter, const char* input_delimiter, int timeout, bool debug); 88 | 89 | /** 90 | * @brief Recv AT command respont, and parse AT parameters to variables 91 | * 92 | * @param[in] Incomming respond format, refer to printf 93 | * 94 | * @return true: Success, false: Timeout or format not match 95 | */ 96 | bool ATCmdParser_recv(const char* response, ...); 97 | 98 | /** 99 | * @brief Send AT command 100 | * 101 | * @param[in] AT command format, refer to scanf 102 | * 103 | * @return true: Success, false: Serial port send error 104 | */ 105 | bool ATCmdParser_send(const char* command, ...); 106 | 107 | /** 108 | * @brief Add a handler to an incomming out-of-band packet type, 109 | * example: oob format: "\r\n+:[para-1,para-2,para-2,...,para-n]\r\n", 110 | * "+" is the prefix 111 | * @note Never send a AT command in the handler 112 | * 113 | * @param[in] prefix: incomming oob packet prefix. 114 | * 115 | * @return none 116 | */ 117 | void ATCmdParser_add_oob(const char* prefix, oob_callback cb); 118 | 119 | /** 120 | * @brief Read raw data from AT command serial port 121 | * 122 | * @param[out] data: Buffer to store the incomming data 123 | * @param[in] size: Buffer size 124 | * 125 | * @return size of the actually received data 126 | */ 127 | int ATCmdParser_read(char* data, int size); 128 | 129 | /** 130 | * @brief Send raw data to AT command serial port 131 | * 132 | * @param[in] data: Point to the data buffer ready to send 133 | *@param[in] size: Buffer size 134 | * 135 | * @return size of the actually sent data 136 | */ 137 | int ATCmdParser_write(const char* data, int size); 138 | 139 | /** 140 | * @brief Set AT parser timeout 141 | * 142 | * @param[in] timeout: new timeout value 143 | * 144 | * @return none 145 | */ 146 | void ATCmdParser_set_timeout(int timeout); 147 | 148 | /** 149 | * @brief Receive and parse incomming out-of-band packet 150 | * 151 | * @return true: proccessed a packet, false: no packet to process 152 | */ 153 | bool ATCmdParser_process_oob(void); 154 | 155 | /** 156 | * @brief Analyse string parameters form AT command respond, 157 | * Respond format: "[\r\n][+CMD:][para-1,para-2,para-3,......]<\r\n><\r\n>" 158 | * First, read para list "para-1,para-2,para-3,......" from respond to string by #ATCmdParser_recv 159 | * second, use this function to parse every string para into an array 160 | * example: "111,222,333\,33,444" to "111", "222", "333,33", "444" 161 | * 162 | * @param[in] args: parameters string, like para-1,para-2,para-3,...... 163 | * @param[out] arg_list: point to parameters list array 164 | * @param[in] list_size: parameters list array size 165 | * 166 | * @return true: proccessed a packet, false: no packet to process 167 | */ 168 | int ATCmdParser_analyse_args(char args[], char* arg_list[], int list_size); 169 | 170 | /** @}*/ 171 | /** @}*/ 172 | 173 | #ifdef __cplusplus 174 | } /* extern "C" */ 175 | #endif 176 | 177 | #endif //_AT_CMD_PARSER_H_ 178 | -------------------------------------------------------------------------------- /src/helper/emhost/ATCmdParser/ATCmdParserTest.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "emh_api.h" 5 | #include "mx_hal.h" 6 | 7 | char* return_str; 8 | 9 | void ATCmdParser_test(void) 10 | { 11 | mx_status ret = kNoErr; 12 | 13 | mx_hal_ms_ticker_init(); 14 | 15 | ret = emh_init(); 16 | if (ret == kNoErr) 17 | printf("module init success\r\n"); 18 | 19 | printf("FW version: %s\r\n", emh_module_get_fw_version()); 20 | printf("System tick: %d\r\n", (int)emh_module_get_tick()); 21 | 22 | while (1) 23 | ; 24 | } 25 | -------------------------------------------------------------------------------- /src/helper/emhost/emh_alisds.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file emh_alisds.c 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 9-Apr-2018 7 | * @brief Alicloud SDS service AT commands API 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | 28 | #include 29 | #include 30 | 31 | #include "emh_api.h" 32 | #include "ATCmdParser/ATCmdParser.h" 33 | 34 | /****************************************************************************** 35 | * Function Definitions 36 | ******************************************************************************/ 37 | 38 | MX_WEAK void emh_ev_alisds_get_local_atts(emh_alisds_msg *attrs) 39 | { 40 | return; 41 | } 42 | 43 | mx_status emh_alisds_config(const emh_alisds_config_t* config) 44 | { 45 | char args[200], *arg_list[5]; 46 | const char* format_arg = emh_arg_for_type(EMH_ARG_ALISDS_FORMAT, config->product_info.format); 47 | 48 | /* Check product info*/ 49 | if (!(ATCmdParser_send("AT+ALINKPRODUCT?") 50 | && ATCmdParser_recv("+ALINKPRODUCT:%200[^\r]\r\n",args) 51 | && ATCmdParser_recv("OK\r\n"))) { 52 | return kReadErr; 53 | } 54 | 55 | if (4 != ATCmdParser_analyse_args(args, arg_list, 4)) { 56 | return kMalformedErr; 57 | } 58 | 59 | if (strcmp(arg_list[0], config->product_info.name) 60 | || strcmp(arg_list[1], config->product_info.module) 61 | || strcmp(arg_list[2], config->product_info.key) 62 | || strcmp(arg_list[3], config->product_info.secret) ){ 63 | 64 | if (!(ATCmdParser_send("AT+ALINKPRODUCT=%s,%s,%s,%s,%s", 65 | config->product_info.name, config->product_info.module, 66 | config->product_info.key, config->product_info.secret, format_arg ) 67 | && ATCmdParser_recv("OK\r\n"))) { 68 | return kGeneralErr; 69 | } 70 | } 71 | 72 | /* Check device info*/ 73 | if (!(ATCmdParser_send("AT+ALINKDEV?") 74 | && ATCmdParser_recv("+ALINKDEV:%40[^\r]\r\n",args) 75 | && ATCmdParser_recv("OK\r\n"))) { 76 | return kReadErr; 77 | } 78 | 79 | if (3 != ATCmdParser_analyse_args(args, arg_list, 3)) { 80 | return kMalformedErr; 81 | } 82 | 83 | if ((strcmp(arg_list[0], config->dev_info.type) 84 | || strcmp(arg_list[1], config->dev_info.category) 85 | || strcmp(arg_list[2], config->dev_info.manufacture))){ 86 | 87 | if (!(ATCmdParser_send("AT+ALINKDEV=%s,%s,%s", 88 | config->dev_info.type, config->dev_info.category, 89 | config->dev_info.manufacture ) 90 | && ATCmdParser_recv("OK\r\n"))) { 91 | return kGeneralErr; 92 | } 93 | } 94 | 95 | return kNoErr; 96 | } 97 | 98 | mx_status emh_alisds_set_key (const char *dev_key, const char *dev_sec) 99 | { 100 | if (ATCmdParser_send("AT+ALINKSDS=%s,%s", dev_key, dev_sec) 101 | && ATCmdParser_recv("OK\r\n")) { 102 | return kNoErr; 103 | } 104 | return kGeneralErr; 105 | } 106 | 107 | mx_status emh_alisds_start_service(void) 108 | { 109 | if (ATCmdParser_send("AT+ALINKSTART") 110 | && ATCmdParser_recv("OK\r\n")) { 111 | return kNoErr; 112 | } 113 | return kGeneralErr; 114 | } 115 | 116 | emh_arg_alisds_status_t emh_alisds_get_status(void) 117 | { 118 | char arg[20]; 119 | 120 | if (!(ATCmdParser_send("AT+ALINKSTATUS?") 121 | && ATCmdParser_recv("+ALINKSTATUS:%20[^\r]\r\n",arg) 122 | && ATCmdParser_recv("OK\r\n"))) { 123 | return EMH_ARG_ERR; 124 | } 125 | 126 | return emh_arg_for_arg( EMH_ARG_ALISDS_STATUS, arg); 127 | } 128 | 129 | mx_status emh_alisds_provision(bool on) 130 | { 131 | if ((on? ATCmdParser_send("AT+ALINKAWSSTART"): 132 | ATCmdParser_send("AT+ALINKAWSSTOP")) 133 | && ATCmdParser_recv("OK\r\n")) { 134 | return kNoErr; 135 | } 136 | return kGeneralErr; 137 | } 138 | 139 | mx_status emh_ali_start_provision(void) 140 | { 141 | if (ATCmdParser_send("AT+ALINKAWSSTART") 142 | && ATCmdParser_recv("OK\r\n")) { 143 | return kNoErr; 144 | } 145 | return kGeneralErr; 146 | } 147 | 148 | mx_status emh_alisds_unbound(void) 149 | { 150 | if (ATCmdParser_send("AT+ALINKUNBIND") 151 | && ATCmdParser_recv("OK\r\n")) { 152 | return kNoErr; 153 | } 154 | return kGeneralErr; 155 | } 156 | 157 | mx_status emh_ali_stop_provision(void) 158 | { 159 | if (ATCmdParser_send("AT+ALINKAWSSTOP") 160 | && ATCmdParser_recv("OK\r\n")) { 161 | return kNoErr; 162 | } 163 | return kGeneralErr; 164 | } 165 | 166 | mx_status emh_alisds_set_cloud_atts(emh_arg_alisds_format_t format, uint8_t *data, int32_t len) 167 | { 168 | if (ATCmdParser_send("AT+ALINKSEND=%d", len) 169 | && ATCmdParser_recv(">") 170 | && ATCmdParser_write((char *)data, len) == len 171 | && ATCmdParser_recv("OK\r\n")) { 172 | return kNoErr; 173 | } 174 | return kGeneralErr; 175 | } 176 | 177 | void emh_alisds_event_handler(void) 178 | { 179 | mx_status err = kNoErr; 180 | char arg1[10], arg2[10]; 181 | emh_arg_alisds_format_t format; 182 | emh_arg_alisds_conn_t conn; 183 | emh_alisds_msg attrs; 184 | 185 | // parse out the packet 186 | require_action(ATCmdParser_recv("%10[^,],", arg1), exit, err = kMalformedErr); 187 | 188 | emh_arg_alisds_ev_t event = emh_arg_for_arg(EMH_ARG_ALISDS_EV, arg1); 189 | require_action(event != EMH_ARG_ERR, exit, err = kMalformedErr); 190 | 191 | /* ALINK Server connection event */ 192 | if (event == EMH_ARG_ALISDS_EV_ALINK) { 193 | require_action(ATCmdParser_recv("%10[^\r]\r\n", arg2), exit, err = kMalformedErr); 194 | conn = emh_arg_for_arg(EMH_ARG_ALISDS_CONN, arg2); 195 | require_action(conn != EMH_ARG_ERR, exit, err = kMalformedErr); 196 | emh_ev_alisds_connection(conn); 197 | } 198 | /* ALINK server <=== attribute value=== device */ 199 | else if (event == EMH_ARG_ALISDS_EV_GET) { 200 | require_action(ATCmdParser_recv("%10[^\r]\r\n", arg2), exit, err = kMalformedErr); 201 | format = emh_arg_for_arg(EMH_ARG_ALISDS_FORMAT, arg2); 202 | require_action(format != EMH_ARG_ERR, exit, err = kMalformedErr); 203 | 204 | attrs.format = format; 205 | attrs.data = NULL; 206 | attrs.len = 0; 207 | emh_ev_alisds_get_local_atts(&attrs); 208 | } 209 | /* ALINK server === attribute value===> device */ 210 | else if (event == EMH_ARG_ALISDS_EV_SET) { 211 | require_action(ATCmdParser_recv("%10[^,],", arg2), exit, err = kMalformedErr); 212 | format = emh_arg_for_arg(EMH_ARG_ALISDS_FORMAT, arg2); 213 | require_action(format != EMH_ARG_ERR, exit, err = kMalformedErr); 214 | 215 | /* Read package data */ 216 | int32_t count; 217 | require_action(ATCmdParser_recv("%d,", &count), exit, err = kMalformedErr); 218 | 219 | uint8_t *data = malloc(count); 220 | require_action(data, exit, err = kNoMemoryErr); 221 | require_action(ATCmdParser_read((char *)data, count) == count, exit, err = kTimeoutErr); 222 | 223 | attrs.data = data; 224 | attrs.format = format; 225 | attrs.len = count; 226 | emh_ev_alisds_set_local_atts(&attrs); 227 | free(data); 228 | } 229 | 230 | exit: 231 | if (err == kMalformedErr) emh_ev_unknown(); 232 | return; 233 | } 234 | 235 | -------------------------------------------------------------------------------- /src/helper/emhost/emh_arg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file emh_arg.c 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 9-Apr-2018 7 | * @brief AT command arguments to enum type convert 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #include "emh_arg.h" 28 | 29 | /****************************************************************************** 30 | * Constants 31 | ******************************************************************************/ 32 | 33 | /****************************************************************************** 34 | * Alicoud SDS service 35 | ******************************************************************************/ 36 | 37 | #ifdef AT_SUPPORT_ALISDS 38 | const char* EMH_ARG_ALISDS_FORMAT[] = 39 | { 40 | [EMH_ARG_ALISDS_FORMAT_JSON] = "JSON", 41 | [EMH_ARG_ALISDS_FORMAT_RAW] = "RAW", 42 | [EMH_ARG_ALISDS_FORMAT_MAX] = "\0", 43 | }; 44 | 45 | const char* EMH_ARG_ALISDS_CONN[] = 46 | { 47 | [EMH_ARG_ALISDS_CONN_CONNECTED] = "CONNECT", 48 | [EMH_ARG_ALISDS_CONN_DISCONNECTED] = "DISCONNECT", 49 | [EMH_ARG_ALISDS_CONN_MAX] = "\0", 50 | }; 51 | 52 | const char* EMH_ARG_ALISDS_STATUS[] = 53 | { 54 | [EMH_ARG_ALISDS_STATUS_UNINITIALIZED] = "NONE", 55 | [EMH_ARG_ALISDS_STATUS_INITIALIZED] = "INIT", 56 | [EMH_ARG_ALISDS_STATUS_CONNECTED] = "CONNECT", 57 | [EMH_ARG_ALISDS_STATUS_DISCONNECTED] = "DISCONNECT", 58 | [EMH_ARG_ALISDS_STATUS_MAX] = "\0", 59 | }; 60 | 61 | const char* EMH_ARG_ALISDS_EV[] = 62 | { 63 | [EMH_ARG_ALISDS_EV_ALINK] = "ALINK", 64 | [EMH_ARG_ALISDS_EV_GET] = "GET", 65 | [EMH_ARG_ALISDS_EV_SET] = "SET", 66 | [EMH_ARG_ALISDS_EV_MAX] = "\0", 67 | }; 68 | #endif 69 | 70 | /****************************************************************************** 71 | * WiFi service 72 | ******************************************************************************/ 73 | 74 | const char* EMH_ARG_WLAN_EV[] = 75 | { 76 | [EMH_ARG_WLAN_EV_UAP_ESTABLISHED] = "AP_UP", 77 | [EMH_ARG_WLAN_EV_UAP_DESTROYED] = "AP_DOWN", 78 | [EMH_ARG_WLAN_EV_STA_CONNECTED] = "STATION_UP", 79 | [EMH_ARG_WLAN_EV_STA_DISCONNECTED] = "STATION_DOWN", 80 | [EMH_ARG_WLAN_EV_MAX] = "\0", 81 | }; 82 | 83 | const char* EMH_ARG_WLAN_STA[] = 84 | { 85 | [EMH_ARG_WLAN_STA_CONNECTED] = "STATION_UP", 86 | [EMH_ARG_WLAN_STA_DISCONNECTED] = "STATION_DOWN", 87 | [EMH_ARG_WLAN_STA_DISCONNECTED] = "CONNECTING", 88 | [EMH_ARG_WLAN_STA_MAX] = "\0", 89 | }; 90 | 91 | /****************************************************************************** 92 | * Alicoud ILOP service 93 | ******************************************************************************/ 94 | 95 | #ifdef AT_SUPPORT_ILOP 96 | const char* EMH_ARG_ILOP_DM[] = 97 | { 98 | [EMH_ARG_ILOP_DM_RAW] = "0", 99 | [EMH_ARG_ILOP_DM_ICA_BY_CLOUD] = "1", 100 | [EMH_ARG_ILOP_DM_ICA_BY_LOCAL] = "2", 101 | [EMH_ARG_ILOP_DM_MAX] = "\0", 102 | }; 103 | 104 | const char* EMH_ARG_ILOP_DOMAIN[] = 105 | { 106 | [EMH_ARG_ILOP_DOMAIN_SHANGHAI] = "0", 107 | [EMH_ARG_ILOP_DOMAIN_SINGAPORE] = "1", 108 | [EMH_ARG_ILOP_DOMAIN_JAPAN] = "2", 109 | [EMH_ARG_ILOP_DOMAIN_AMERICA] = "3", 110 | [EMH_ARG_ILOP_DOMAIN_GERMANY] = "4", 111 | [EMH_ARG_ILOP_DOMAIN_MAX] = "\0", 112 | }; 113 | 114 | const char* EMH_ARG_ILOP_CONFIG[] = 115 | { 116 | [EMH_ARG_ILOP_CONFIG_NONE] = "NONE", 117 | [EMH_ARG_ILOP_CONFIG_TLS] = "CONFIG", 118 | [EMH_ARG_ILOP_CONFIG_MAX] = "\0", 119 | }; 120 | 121 | const char* EMH_ARG_ILOP_STATUS[] = 122 | { 123 | [EMH_ARG_ILOP_STATUS_UNINITIALIZED] = "NONE", 124 | [EMH_ARG_ILOP_STATUS_INITIALIZED] = "INIT", 125 | [EMH_ARG_ILOP_STATUS_CONNECTED] = "CONNECT", 126 | [EMH_ARG_ILOP_STATUS_DISCONNECTED] = "DISCONNECT", 127 | [EMH_ARG_ILOP_STATUS_MAX] = "\0", 128 | }; 129 | 130 | const char* EMH_ARG_ILOP_CONN[] = 131 | { 132 | [EMH_ARG_ILOP_CONN_CLOUD_CONNECTED] = "CLOUD_CONNECT", 133 | [EMH_ARG_ILOP_CONN_CLOUD_DISCONNECTED] = "CLOUD_DISCONNECT", 134 | [EMH_ARG_ILOP_CONN_LOCAL_CONNECTED] = "LOCAL_CONNECT", 135 | [EMH_ARG_ILOP_CONN_LOCAL_DISCONNECTED] = "LOCAL_DISCONNECT", 136 | [EMH_ARG_ILOP_CONN_MAX] = "\0", 137 | }; 138 | 139 | const char* EMH_ARG_ILOP_EV[] = 140 | { 141 | [EMH_ARG_ILOP_EV_ILOP] = "ILOP", 142 | [EMH_ARG_ILOP_EV_SETICA] = "SETICA", 143 | [EMH_ARG_ILOP_EV_SETRAW] = "SETRAW", 144 | [EMH_ARG_ILOP_EV_MAX] = "\0", 145 | }; 146 | 147 | const char *EMH_ARG_ILOP_VT[] = 148 | { 149 | [EMH_ARG_ILOP_VT_PROPERTY] = "property", 150 | [EMH_ARG_ILOP_VT_EVENT] = "event", 151 | [EMH_ARG_ILOP_VT_SERVICE] = "service", 152 | [EMH_ARG_ILOP_VT_MAX] = "\0", 153 | }; 154 | #endif 155 | 156 | /****************************************************************************** 157 | * Coud QLINK service 158 | ******************************************************************************/ 159 | 160 | #ifdef AT_SUPPORT_QLINK 161 | 162 | const char* EMH_ARG_QLINK_FORMAT[] = 163 | { 164 | [EMH_ARG_QLINK_FORMAT_JSON] = "JSON", 165 | [EMH_ARG_QLINK_FORMAT_MAX] = "\0", 166 | }; 167 | 168 | const char* EMH_ARG_QLINK_STATUS[] = 169 | { 170 | [EMH_ARG_QLINK_STATUS_UNINITIALIZED] = "NONE", 171 | [EMH_ARG_QLINK_STATUS_INITIALIZED] = "INIT", 172 | [EMH_ARG_QLINK_STATUS_CONNECTED] = "CONNECT", 173 | [EMH_ARG_QLINK_STATUS_DISCONNECTED] = "DISCONNECT", 174 | [EMH_ARG_QLINK_STATUS_MAX] = "\0", 175 | }; 176 | 177 | const char* EMH_ARG_QLINK_CONN[] = 178 | { 179 | [EMH_ARG_QLINK_CONN_CLOUD_CONNECTED] = "CONNECT", 180 | [EMH_ARG_QLINK_CONN_CLOUD_DISCONNECTED] = "DISCONNECT", 181 | [EMH_ARG_QLINK_CONN_LOCAL_CONNECTED] = "LOCAL_CONNECT", 182 | [EMH_ARG_QLINK_CONN_LOCAL_DISCONNECTED] = "LOCAL_DISCONNECT", 183 | [EMH_ARG_QLINK_CONN_MAX] = "\0", 184 | }; 185 | 186 | const char* EMH_ARG_QLINK_EV[] = 187 | { 188 | [EMH_ARG_QLINK_EV_QLINK] = "QLINK", 189 | [EMH_ARG_QLINK_EV_GET] = "GET", 190 | [EMH_ARG_QLINK_EV_SET] = "SET", 191 | [EMH_ARG_QLINK_EV_MAX] = "\0", 192 | }; 193 | 194 | #endif 195 | 196 | /****************************************************************************** 197 | * Function Definitions 198 | ******************************************************************************/ 199 | 200 | const char* emh_arg_for_type(const char* emh_arg[], uint8_t type) 201 | { 202 | return emh_arg[type]; 203 | } 204 | 205 | uint8_t emh_arg_for_arg(const char* emh_arg[], char *arg) 206 | { 207 | for (uint8_t i = 0; i < EMH_ARG_ERR; i++) { 208 | if (*emh_arg[i] == 0x0) break; 209 | if (memcmp(emh_arg[i], arg, strlen(emh_arg[i])) == 0) { 210 | return i; 211 | } 212 | 213 | } 214 | return EMH_ARG_ERR; 215 | } 216 | 217 | 218 | -------------------------------------------------------------------------------- /src/helper/emhost/emh_arg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file emh_arg.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief AT command arguments to enum type convert header file 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _EMH_ARG_H_ 28 | #define _EMH_ARG_H_ 29 | 30 | #include "mx_common.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" 34 | { 35 | #endif 36 | 37 | /** \addtogroup emhost */ 38 | /** @{*/ 39 | 40 | /****************************************************************************** 41 | * Constants 42 | ******************************************************************************/ 43 | 44 | #define EMH_ARG_ERR 0xFF 45 | 46 | /****************************************************************************** 47 | * Alicoud SDS service 48 | ******************************************************************************/ 49 | 50 | /** \addtogroup alicloud_sds */ 51 | /** @{*/ 52 | enum{ 53 | EMH_ARG_ALISDS_CONN_DISCONNECTED, 54 | EMH_ARG_ALISDS_CONN_CONNECTED, 55 | EMH_ARG_ALISDS_CONN_MAX, 56 | }; 57 | typedef uint8_t emh_arg_alisds_conn_t; 58 | extern const char* EMH_ARG_ALISDS_CONN[]; 59 | 60 | enum{ 61 | EMH_ARG_ALISDS_STATUS_UNINITIALIZED, 62 | EMH_ARG_ALISDS_STATUS_INITIALIZED, 63 | EMH_ARG_ALISDS_STATUS_CONNECTED, 64 | EMH_ARG_ALISDS_STATUS_DISCONNECTED, 65 | EMH_ARG_ALISDS_STATUS_MAX, 66 | }; 67 | typedef uint8_t emh_arg_alisds_status_t; 68 | extern const char* EMH_ARG_ALISDS_STATUS[]; 69 | 70 | enum{ 71 | EMH_ARG_ALISDS_FORMAT_JSON, 72 | EMH_ARG_ALISDS_FORMAT_RAW, 73 | EMH_ARG_ALISDS_FORMAT_MAX, 74 | }; 75 | typedef uint8_t emh_arg_alisds_format_t; 76 | extern const char* EMH_ARG_ALISDS_FORMAT[]; 77 | 78 | enum{ 79 | EMH_ARG_ALISDS_EV_ALINK, 80 | EMH_ARG_ALISDS_EV_SET, 81 | EMH_ARG_ALISDS_EV_GET, 82 | EMH_ARG_ALISDS_EV_MAX, 83 | }; 84 | typedef uint8_t emh_arg_alisds_ev_t; 85 | extern const char* EMH_ARG_ALISDS_EV[]; 86 | /** @}*/ 87 | 88 | /****************************************************************************** 89 | * WiFi service 90 | ******************************************************************************/ 91 | /** \addtogroup wlan */ 92 | /** @{*/ 93 | enum{ 94 | EMH_ARG_WLAN_EV_UAP_ESTABLISHED, 95 | EMH_ARG_WLAN_EV_UAP_DESTROYED, 96 | EMH_ARG_WLAN_EV_STA_CONNECTED, 97 | EMH_ARG_WLAN_EV_STA_DISCONNECTED, 98 | EMH_ARG_WLAN_EV_MAX, 99 | }; 100 | typedef uint8_t emh_arg_wlan_ev_t; 101 | extern const char* EMH_ARG_WLAN_EV[]; 102 | 103 | enum{ 104 | EMH_ARG_WLAN_STA_CONNECTED, 105 | EMH_ARG_WLAN_STA_DISCONNECTED, 106 | EMH_ARG_WLAN_STA_CONNECTING, 107 | EMH_ARG_WLAN_STA_MAX, 108 | }; 109 | typedef uint8_t emh_arg_wlan_sta_t; /**< wlan connection status under station mode */ 110 | extern const char* EMH_ARG_WLAN_STA[]; 111 | /** @}*/ 112 | 113 | /****************************************************************************** 114 | * Alicoud ILOP service 115 | ******************************************************************************/ 116 | /** \addtogroup ilop */ 117 | /** @{*/ 118 | enum{ 119 | EMH_ARG_ILOP_DM_RAW, 120 | EMH_ARG_ILOP_DM_ICA_BY_CLOUD, 121 | EMH_ARG_ILOP_DM_ICA_BY_LOCAL, 122 | EMH_ARG_ILOP_DM_MAX, 123 | }; 124 | typedef uint8_t emh_arg_ilop_dm_t; 125 | extern const char* EMH_ARG_ILOP_DM[]; 126 | 127 | enum{ 128 | EMH_ARG_ILOP_DOMAIN_SHANGHAI, 129 | EMH_ARG_ILOP_DOMAIN_SINGAPORE, 130 | EMH_ARG_ILOP_DOMAIN_JAPAN, 131 | EMH_ARG_ILOP_DOMAIN_AMERICA, 132 | EMH_ARG_ILOP_DOMAIN_GERMANY, 133 | EMH_ARG_ILOP_DOMAIN_MAX, 134 | }; 135 | typedef uint8_t emh_arg_ilop_domain_t; 136 | extern const char* EMH_ARG_ILOP_DOMAIN[]; 137 | 138 | enum{ 139 | EMH_ARG_ILOP_CONFIG_NONE, 140 | EMH_ARG_ILOP_CONFIG_TLS, 141 | EMH_ARG_ILOP_CONFIG_MAX, 142 | }; 143 | typedef uint8_t emh_arg_ilop_config_t; 144 | extern const char* EMH_ARG_ILOP_CONFIG[]; 145 | 146 | enum{ 147 | EMH_ARG_ILOP_STATUS_UNINITIALIZED, 148 | EMH_ARG_ILOP_STATUS_INITIALIZED, 149 | EMH_ARG_ILOP_STATUS_CONNECTED, 150 | EMH_ARG_ILOP_STATUS_DISCONNECTED, 151 | EMH_ARG_ILOP_STATUS_MAX, 152 | }; 153 | typedef uint8_t emh_arg_ilop_status_t; 154 | extern const char* EMH_ARG_ILOP_STATUS[]; 155 | 156 | enum{ 157 | EMH_ARG_ILOP_CONN_CLOUD_CONNECTED, 158 | EMH_ARG_ILOP_CONN_CLOUD_DISCONNECTED, 159 | EMH_ARG_ILOP_CONN_LOCAL_CONNECTED, 160 | EMH_ARG_ILOP_CONN_LOCAL_DISCONNECTED, 161 | EMH_ARG_ILOP_CONN_MAX, 162 | }; 163 | typedef uint8_t emh_arg_ilop_conn_t; 164 | extern const char* EMH_ARG_ILOP_CONN[]; 165 | 166 | enum{ 167 | EMH_ARG_ILOP_EV_ILOP, 168 | EMH_ARG_ILOP_EV_SETICA, 169 | EMH_ARG_ILOP_EV_SETRAW, 170 | EMH_ARG_ILOP_EV_MAX, 171 | }; 172 | typedef uint8_t emh_arg_ilop_ev_t; 173 | extern const char* EMH_ARG_ILOP_EV[]; 174 | 175 | enum{ 176 | EMH_ARG_ILOP_FORMAT_ICA, 177 | EMH_ARG_ILOP_FORMAT_RAW, 178 | EMH_ARG_ILOP_FORMAT_MAX, 179 | }; 180 | typedef uint8_t emh_arg_ilop_format_t; 181 | 182 | enum{ 183 | EMH_ARG_ILOP_VT_PROPERTY, 184 | EMH_ARG_ILOP_VT_EVENT, 185 | EMH_ARG_ILOP_VT_SERVICE, 186 | EMH_ARG_ILOP_VT_MAX, 187 | }; 188 | typedef uint8_t emh_arg_ilop_vt_t; 189 | extern const char *EMH_ARG_ILOP_VT[]; 190 | 191 | 192 | /****************************************************************************** 193 | * Cloud QLINK service 194 | ******************************************************************************/ 195 | /** \addtogroup qlink */ 196 | /** @{*/ 197 | enum{ 198 | EMH_ARG_QLINK_FORMAT_JSON, 199 | EMH_ARG_QLINK_FORMAT_MAX, 200 | }; 201 | typedef uint8_t emh_arg_qlink_format_t; 202 | extern const char* EMH_ARG_QLINK_FORMAT[]; 203 | 204 | enum{ 205 | EMH_ARG_QLINK_STATUS_UNINITIALIZED, 206 | EMH_ARG_QLINK_STATUS_INITIALIZED, 207 | EMH_ARG_QLINK_STATUS_CONNECTED, 208 | EMH_ARG_QLINK_STATUS_DISCONNECTED, 209 | EMH_ARG_QLINK_STATUS_MAX, 210 | }; 211 | typedef uint8_t emh_arg_qlink_status_t; 212 | extern const char* EMH_ARG_QLINK_STATUS[]; 213 | 214 | enum{ 215 | EMH_ARG_QLINK_CONN_CLOUD_CONNECTED, 216 | EMH_ARG_QLINK_CONN_CLOUD_DISCONNECTED, 217 | EMH_ARG_QLINK_CONN_LOCAL_CONNECTED, 218 | EMH_ARG_QLINK_CONN_LOCAL_DISCONNECTED, 219 | EMH_ARG_QLINK_CONN_MAX, 220 | }; 221 | typedef uint8_t emh_arg_qlink_conn_t; 222 | extern const char* EMH_ARG_QLINK_CONN[]; 223 | 224 | enum{ 225 | EMH_ARG_QLINK_EV_QLINK, 226 | EMH_ARG_QLINK_EV_SET, 227 | EMH_ARG_QLINK_EV_GET, 228 | EMH_ARG_QLINK_EV_MAX, 229 | }; 230 | typedef uint8_t emh_arg_qlink_ev_t; 231 | extern const char* EMH_ARG_QLINK_EV[]; 232 | 233 | /** @}*/ 234 | 235 | /****************************************************************************** 236 | * Function Declarations 237 | ******************************************************************************/ 238 | 239 | /** 240 | * @brief Find string type argument from enum 241 | * 242 | * @param[in] emh_arg: Arg convert list array 243 | * @param[in] type: enum argument type 244 | * 245 | * @return Argument string type 246 | */ 247 | const char* emh_arg_for_type(const char* emh_arg[], uint8_t type); 248 | 249 | /** 250 | * @brief Find enum type argument from string 251 | * 252 | * @param[in] emh_arg: Arg convert list array 253 | * @param[in] type: string argument read from AT command 254 | * 255 | * @return Argument enum type 256 | */ 257 | uint8_t emh_arg_for_arg(const char* emh_arg[], char *arg); 258 | 259 | /** @}*/ 260 | /** @}*/ 261 | 262 | #ifdef __cplusplus 263 | } /* extern "C" */ 264 | #endif 265 | 266 | #endif 267 | -------------------------------------------------------------------------------- /src/helper/emhost/emh_module.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file emh_module.c 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 9-Apr-2018 7 | * @brief EMW module operation AT commands 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | 28 | #include "ATCmdParser/ATCmdParser.h" 29 | #include "emh_api.h" 30 | 31 | /****************************************************************************** 32 | * Variable Definitions 33 | ******************************************************************************/ 34 | 35 | static char _fw_version[32]; 36 | 37 | /****************************************************************************** 38 | * Function Declarations 39 | ******************************************************************************/ 40 | 41 | extern void emh_alisds_event_handler(void); 42 | extern void emh_wlan_event_handler(void); 43 | 44 | /****************************************************************************** 45 | * Function Definitions 46 | ******************************************************************************/ 47 | MX_WEAK void emh_ev_unknown(void) 48 | { 49 | return; 50 | } 51 | 52 | mx_status emh_module_reset(void) 53 | { 54 | if (!(ATCmdParser_send("AT+REBOOT") 55 | && ATCmdParser_recv("OK\r\n"))) { 56 | return kGeneralErr; 57 | } 58 | for (int i = 0; i < 5; i++) { 59 | if (ATCmdParser_send("AT") 60 | && ATCmdParser_recv("OK\r\n") 61 | && ATCmdParser_send("AT+UARTE=OFF") 62 | && ATCmdParser_recv("OK\r\n")) { 63 | return kNoErr; 64 | } 65 | } 66 | return kGeneralErr; 67 | } 68 | 69 | mx_status emh_module_restore_settings(void) 70 | { 71 | if (!(ATCmdParser_send("AT+FACTORY") 72 | && ATCmdParser_recv("OK\r\n"))) { 73 | return kGeneralErr; 74 | } 75 | 76 | for (int i = 0; i < 5; i++) { 77 | if (ATCmdParser_send("AT") 78 | && ATCmdParser_recv("OK\r\n") 79 | && ATCmdParser_send("AT+UARTE=OFF") 80 | && ATCmdParser_recv("OK\r\n")) { 81 | return kNoErr; 82 | } 83 | } 84 | 85 | return kGeneralErr; 86 | } 87 | 88 | mx_status emh_init(void) 89 | { 90 | ATCmdParser_init("\r","\r\n", 1000, false); 91 | 92 | for (int i = 0; i < 2; i++) { 93 | if ( kNoErr == emh_module_reset()) { 94 | #ifdef AT_SUPPORT_ILOP 95 | ATCmdParser_add_oob("+ILOPEVENT:", emh_ilop_event_handler); 96 | #endif 97 | #ifdef AT_SUPPORT_ALISDS 98 | ATCmdParser_add_oob("+ALINKEVENT:", emh_alisds_event_handler); 99 | #endif 100 | #ifdef AT_SUPPORT_QLINK 101 | ATCmdParser_add_oob("+QLINKEVENT:", emh_qlink_event_handler); 102 | #endif 103 | ATCmdParser_add_oob("+WEVENT:", emh_wlan_event_handler); 104 | return kNoErr; 105 | } 106 | } 107 | 108 | return kGeneralErr; 109 | } 110 | 111 | mx_status emh_module_check_ready( void ) 112 | { 113 | if ( ATCmdParser_send("AT") 114 | && ATCmdParser_recv("OK\r\n")) { 115 | return kNoErr; 116 | } 117 | return kGeneralErr; 118 | } 119 | 120 | const char *emh_module_get_fw_version(void) 121 | { 122 | if (!(ATCmdParser_send("AT+FWVER?") 123 | && ATCmdParser_recv("+FWVER:%32[^\r]\r\nOK\r\n", _fw_version))) { 124 | return NULL; 125 | } 126 | return _fw_version; 127 | } 128 | 129 | uint32_t emh_module_get_tick(void) 130 | { 131 | uint32_t tick; 132 | if (!(ATCmdParser_send("AT+SYSTIME?") 133 | && ATCmdParser_recv("+SYSTIME:%d\r\nOK\r\n", &tick))) { 134 | return 0; 135 | } 136 | return tick; 137 | } 138 | 139 | extern void cli_loop( void ); 140 | void emh_runloop(void) { 141 | while (ATCmdParser_process_oob()); 142 | 143 | #ifdef MX_CLI_ENABLE 144 | cli_loop(); 145 | #endif 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/helper/emhost/emh_qlink.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file emh_qlink.c 4 | * @author QQ Ding 5 | * @version V1.0.0 6 | * @date 3-Sept-2018 7 | * @brief Alicloud qlink service AT commands API 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | 28 | #include 29 | #include 30 | 31 | #include "emh_api.h" 32 | #include "ATCmdParser/ATCmdParser.h" 33 | 34 | 35 | 36 | /****************************************************************************** 37 | * Function Definitions 38 | ******************************************************************************/ 39 | 40 | mx_status emh_qlink_config(const emh_qlink_config_t* config, bool force) 41 | { 42 | char args[200], *arg_list[5]; 43 | // const char* format_arg = emh_arg_for_type(EMH_ARG_QLINK_FORMAT, config->product_info.format); //JSON or RAW 44 | 45 | if( false==force ) 46 | { 47 | /* Check product info*/ 48 | if (ATCmdParser_send("AT+QLINKPRODUCT?") 49 | && ATCmdParser_recv("+QLINKPRODUCT:%200[^\r]\r\n",args) 50 | && ATCmdParser_recv("OK\r\n")) { 51 | if (3 == ATCmdParser_analyse_args(args, arg_list, 3)) { 52 | if ( strcmp(arg_list[0], config->product_info.product_id) 53 | ||!(strcmp(arg_list[1], config->product_info.product_token) 54 | || strcmp(arg_list[2], config->product_info.andlink_token)) ){ 55 | goto label_version; 56 | } 57 | } 58 | } 59 | } 60 | 61 | if (!(ATCmdParser_send("AT+QLINKPRODUCT=%s,%s,%s", config->product_info.product_id, 62 | config->product_info.product_token, config->product_info.andlink_token ) 63 | && ATCmdParser_recv("OK\r\n"))) { 64 | return kGeneralErr; 65 | } 66 | 67 | label_version: 68 | if( false==force ) 69 | { 70 | /* Check version info*/ 71 | if (ATCmdParser_send("AT+QLINKVERSION?") 72 | && ATCmdParser_recv("+QLINKVERSION:%40[^\r]\r\n",args) 73 | && ATCmdParser_recv("OK\r\n")) { 74 | if (2 == ATCmdParser_analyse_args(args, arg_list, 2)) { 75 | if (!(strcmp(arg_list[0], config->version_info.firmware_version) 76 | || strcmp(arg_list[1], config->version_info.software_version))){ 77 | return kNoErr; 78 | } 79 | } 80 | } 81 | } 82 | 83 | if (!(ATCmdParser_send("AT+QLINKVERSION=%s,%s", 84 | config->version_info.firmware_version, config->version_info.software_version ) 85 | && ATCmdParser_recv("OK\r\n"))) { 86 | return kGeneralErr; 87 | } 88 | 89 | return kNoErr; 90 | } 91 | 92 | mx_status emh_qlink_raw_start( void ) 93 | { 94 | if (ATCmdParser_send("AT+QLINKRAWSTART") 95 | && ATCmdParser_recv("OK\r\n")) { 96 | return kNoErr; 97 | } 98 | return kGeneralErr; 99 | } 100 | 101 | mx_status emh_qlink_user_start( void ) 102 | { 103 | if (ATCmdParser_send("AT+QLINKUSERSTART") 104 | && ATCmdParser_recv("OK\r\n")) { 105 | return kNoErr; 106 | } 107 | return kGeneralErr; 108 | } 109 | 110 | mx_status emh_qlink_service_start( void ) 111 | { 112 | if (ATCmdParser_send("AT+QLINKSTART") 113 | && ATCmdParser_recv("OK\r\n")) { 114 | return kNoErr; 115 | } 116 | return kGeneralErr; 117 | } 118 | 119 | emh_arg_qlink_status_t emh_qlink_get_stauts( void ) 120 | { 121 | char arg[20]; 122 | 123 | if (!(ATCmdParser_send("AT+QLINKSTATUS?") 124 | && ATCmdParser_recv("+QLINKSTATUS:%20[^\r]\r\n",arg) 125 | && ATCmdParser_recv("OK\r\n"))) { 126 | return EMH_ARG_ERR; 127 | } 128 | 129 | return emh_arg_for_arg( EMH_ARG_QLINK_STATUS, arg); 130 | } 131 | 132 | mx_status emh_qlink_service_stop( void ) 133 | { 134 | if (ATCmdParser_send("AT+QLINKSTOP") 135 | && ATCmdParser_recv("OK\r\n")) { 136 | return kNoErr; 137 | } 138 | return kGeneralErr; 139 | } 140 | 141 | mx_status emh_qlink_send_json_to_cloud( char *type, uint8_t *data, uint32_t len ) 142 | { 143 | if (ATCmdParser_send("AT+QLINKSEND=%s,%d", type, len) 144 | && ATCmdParser_recv(">") 145 | && ATCmdParser_write((char *)data, len) == len 146 | && ATCmdParser_recv("OK\r\n")) { 147 | return kNoErr; 148 | } 149 | return kGeneralErr; 150 | } 151 | 152 | mx_status emh_qlink_send_data_to_uart( int res ) 153 | { 154 | if ( ATCmdParser_send("AT+QLINKPARAM=%d", res) 155 | && ATCmdParser_recv("OK\r\n")) { 156 | return kNoErr; 157 | } 158 | return kGeneralErr; 159 | } 160 | 161 | void emh_qlink_event_handler(void) 162 | { 163 | mx_status err = kNoErr; 164 | char arg1[10], arg2[256]; 165 | emh_arg_qlink_conn_t conn; 166 | emh_qlink_msg_t msg; 167 | 168 | require_action(ATCmdParser_recv("%10[^,],", arg1), exit, err = kMalformedErr); 169 | 170 | emh_arg_qlink_ev_t event = emh_arg_for_arg(EMH_ARG_QLINK_EV, arg1); 171 | require_action(event != EMH_ARG_ERR, exit, err = kMalformedErr); 172 | 173 | /* qlink Server connection event */ 174 | if (event == EMH_ARG_QLINK_EV_QLINK) { 175 | require_action(ATCmdParser_recv("%20[^\r]\r\n", arg2), exit, err = kMalformedErr); 176 | conn = emh_arg_for_arg(EMH_ARG_QLINK_CONN, arg2); 177 | require_action(conn != EMH_ARG_ERR, exit, err = kMalformedErr); 178 | emh_ev_qlink_connection(conn); 179 | } 180 | /* QLINK server === json value===> device */ 181 | else if(event == EMH_ARG_QLINK_EV_SET) 182 | { 183 | /* Read package data */ 184 | int32_t count; 185 | require_action(ATCmdParser_recv("%d,", &count), exit, err = kMalformedErr); 186 | 187 | uint8_t *data = malloc(count+1); 188 | require_action(data, exit, err = kNoMemoryErr); 189 | require_action(ATCmdParser_read((char *)data, count) == count, exit, err = kTimeoutErr); 190 | 191 | *(data+count) = 0x00; 192 | msg.data = data; 193 | msg.format = EMH_ARG_QLINK_FORMAT_JSON; 194 | msg.len = count; 195 | 196 | int res = 0; 197 | res = emh_ev_qlink_set_local_attrs(&msg); 198 | if( NULL!=strstr((char *)msg.data, "data") ) 199 | { 200 | // printf("ready to send back data\r\n"); 201 | emh_qlink_send_data_to_uart(res); 202 | } 203 | // printf("after sending back data\r\n"); 204 | free(data); 205 | } 206 | /* QLINK device === json value===> server */ 207 | else if(event == EMH_ARG_QLINK_EV_GET) 208 | { 209 | /* Read package data */ 210 | int32_t count; 211 | require_action(ATCmdParser_recv("%d,", &count), exit, err = kMalformedErr); 212 | 213 | uint8_t *data = malloc(count+1); 214 | require_action(data, exit, err = kNoMemoryErr); 215 | require_action(ATCmdParser_read((char *)data, count) == count, exit, err = kTimeoutErr); 216 | 217 | *(data+count) = 0x00; 218 | msg.data = data; 219 | msg.format = EMH_ARG_QLINK_FORMAT_JSON; 220 | msg.len = count; 221 | emh_ev_qlink_get_local_attrs(&msg); 222 | free(data); 223 | } 224 | 225 | exit: 226 | if (err == kMalformedErr) emh_ev_unknown(); 227 | return; 228 | } 229 | -------------------------------------------------------------------------------- /src/helper/emhost/emh_wlan.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file emh_wlan.c 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 9-Apr-2018 7 | * @brief wlan management AT commands 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | 28 | #include "ATCmdParser/ATCmdParser.h" 29 | #include "emh_api.h" 30 | 31 | /****************************************************************************** 32 | * Function Definitions 33 | ******************************************************************************/ 34 | 35 | mx_status emh_wlan_get_para(char ssid[33], char pwd[33]) 36 | { 37 | char args[100], *arg_list[2]; 38 | 39 | if (!(ATCmdParser_send("AT+WJAP=?") 40 | && ATCmdParser_recv("+WJAP:%100[^\r]\r\n",args) 41 | && ATCmdParser_recv("OK\r\n"))) { 42 | return kReadErr; 43 | } 44 | 45 | if (2 != ATCmdParser_analyse_args(args, arg_list, 2)) { 46 | return kMalformedErr; 47 | }; 48 | if (ssid) strcpy(ssid, arg_list[0]); 49 | if (pwd) strcpy(pwd, arg_list[1]); 50 | 51 | return kNoErr; 52 | } 53 | 54 | emh_arg_wlan_sta_t emh_wlan_get_sta_status(void) 55 | { 56 | char arg[20]; 57 | 58 | if (!(ATCmdParser_send("AT+WJAPS") 59 | && ATCmdParser_recv("+WJAPS:%20[^\r]\r\n",arg) 60 | && ATCmdParser_recv("OK\r\n"))) { 61 | return EMH_ARG_ERR; 62 | } 63 | 64 | return emh_arg_for_arg( EMH_ARG_WLAN_STA, arg); 65 | } 66 | 67 | void emh_wlan_event_handler(void) 68 | { 69 | mx_status err = kNoErr; 70 | char arg[15]; 71 | 72 | // parse out the packet 73 | require_action(ATCmdParser_recv("%100[^\r]\r\n", arg), exit, err = kMalformedErr); 74 | 75 | emh_arg_wlan_ev_t event = emh_arg_for_arg(EMH_ARG_WLAN_EV, arg); 76 | require_action(event != EMH_ARG_ERR, exit, err = kMalformedErr); 77 | 78 | emh_ev_wlan(event); 79 | 80 | exit: 81 | if (err == kMalformedErr) emh_ev_unknown(); 82 | return; 83 | } 84 | -------------------------------------------------------------------------------- /src/helper/jsmn/jsmn.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | /** 6 | * Allocates a fresh unused token from the token pull. 7 | */ 8 | static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, 9 | jsmntok_t *tokens, size_t num_tokens) { 10 | jsmntok_t *tok; 11 | if (parser->toknext >= num_tokens) { 12 | return NULL; 13 | } 14 | tok = &tokens[parser->toknext++]; 15 | tok->start = tok->end = -1; 16 | tok->size = 0; 17 | #ifdef JSMN_PARENT_LINKS 18 | tok->parent = -1; 19 | #endif 20 | return tok; 21 | } 22 | 23 | /** 24 | * Fills token type and boundaries. 25 | */ 26 | static void jsmn_fill_token(jsmntok_t *token, uint8_t type, 27 | int start, int end) { 28 | token->type = type; 29 | token->start = start; 30 | token->end = end; 31 | token->size = 0; 32 | } 33 | 34 | /** 35 | * Fills next available token with JSON primitive. 36 | */ 37 | static jsmnerr_t jsmn_parse_primitive(jsmn_parser *parser, const char *js, 38 | size_t len, jsmntok_t *tokens, size_t num_tokens) { 39 | jsmntok_t *token; 40 | int16_t start; 41 | 42 | start = parser->pos; 43 | 44 | for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { 45 | switch (js[parser->pos]) { 46 | #ifndef JSMN_STRICT 47 | /* In strict mode primitive must be followed by "," or "}" or "]" */ 48 | case ':': 49 | #endif 50 | case '\t' : case '\r' : case '\n' : case ' ' : 51 | case ',' : case ']' : case '}' : 52 | goto found; 53 | } 54 | if (js[parser->pos] < 32 || js[parser->pos] >= 127) { 55 | parser->pos = start; 56 | return JSMN_ERROR_INVAL; 57 | } 58 | } 59 | #ifdef JSMN_STRICT 60 | /* In strict mode primitive must be followed by a comma/object/array */ 61 | parser->pos = start; 62 | return JSMN_ERROR_PART; 63 | #endif 64 | 65 | found: 66 | if (tokens == NULL) { 67 | parser->pos--; 68 | return 0; 69 | } 70 | token = jsmn_alloc_token(parser, tokens, num_tokens); 71 | if (token == NULL) { 72 | parser->pos = start; 73 | return JSMN_ERROR_NOMEM; 74 | } 75 | jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); 76 | #ifdef JSMN_PARENT_LINKS 77 | token->parent = parser->toksuper; 78 | #endif 79 | parser->pos--; 80 | return 0; 81 | } 82 | 83 | /** 84 | * Filsl next token with JSON string. 85 | */ 86 | static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js, 87 | size_t len, jsmntok_t *tokens, size_t num_tokens) { 88 | jsmntok_t *token; 89 | 90 | int start = parser->pos; 91 | int i = 0; 92 | 93 | parser->pos++; 94 | 95 | /* Skip starting quote */ 96 | for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { 97 | char c = js[parser->pos]; 98 | 99 | /* Quote: end of string */ 100 | if (c == '\"') { 101 | if (tokens == NULL) { 102 | return 0; 103 | } 104 | token = jsmn_alloc_token(parser, tokens, num_tokens); 105 | if (token == NULL) { 106 | parser->pos = start; 107 | return JSMN_ERROR_NOMEM; 108 | } 109 | jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos); 110 | #ifdef JSMN_PARENT_LINKS 111 | token->parent = parser->toksuper; 112 | #endif 113 | return 0; 114 | } 115 | 116 | /* Backslash: Quoted symbol expected */ 117 | if (c == '\\') { 118 | parser->pos++; 119 | switch (js[parser->pos]) { 120 | /* Allowed escaped symbols */ 121 | case '\"': case '/' : case '\\' : case 'b' : 122 | case 'f' : case 'r' : case 'n' : case 't' : 123 | break; 124 | /* Allows escaped symbol \uXXXX */ 125 | case 'u': 126 | parser->pos++; 127 | 128 | for(; i < 4 && js[parser->pos] != '\0'; i++) { 129 | /* If it isn't a hex character we have an error */ 130 | if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ 131 | (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ 132 | (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ 133 | parser->pos = start; 134 | return JSMN_ERROR_INVAL; 135 | } 136 | parser->pos++; 137 | } 138 | parser->pos--; 139 | break; 140 | /* Unexpected symbol */ 141 | default: 142 | parser->pos = start; 143 | return JSMN_ERROR_INVAL; 144 | } 145 | } 146 | } 147 | parser->pos = start; 148 | return JSMN_ERROR_PART; 149 | } 150 | 151 | /** 152 | * Parse JSON string and fill tokens. 153 | */ 154 | int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, 155 | jsmntok_t *tokens, unsigned int num_tokens) { 156 | jsmnerr_t r; 157 | int i; 158 | jsmntok_t *token; 159 | int count = 0; 160 | 161 | for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { 162 | char c; 163 | uint8_t type; 164 | 165 | c = js[parser->pos]; 166 | switch (c) { 167 | case '{': case '[': 168 | count++; 169 | if (tokens == NULL) { 170 | break; 171 | } 172 | token = jsmn_alloc_token(parser, tokens, num_tokens); 173 | if (token == NULL) 174 | return JSMN_ERROR_NOMEM; 175 | if (parser->toksuper != -1) { 176 | tokens[parser->toksuper].size++; 177 | #ifdef JSMN_PARENT_LINKS 178 | token->parent = parser->toksuper; 179 | #endif 180 | } 181 | token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); 182 | token->start = parser->pos; 183 | parser->toksuper = parser->toknext - 1; 184 | break; 185 | case '}': case ']': 186 | if (tokens == NULL) 187 | break; 188 | type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); 189 | #ifdef JSMN_PARENT_LINKS 190 | if (parser->toknext < 1) { 191 | return JSMN_ERROR_INVAL; 192 | } 193 | token = &tokens[parser->toknext - 1]; 194 | for (;;) { 195 | if (token->start != -1 && token->end == -1) { 196 | if (token->type != type) { 197 | return JSMN_ERROR_INVAL; 198 | } 199 | token->end = parser->pos + 1; 200 | parser->toksuper = token->parent; 201 | break; 202 | } 203 | if (token->parent == -1) { 204 | break; 205 | } 206 | token = &tokens[token->parent]; 207 | } 208 | #else 209 | for (i = parser->toknext - 1; i >= 0; i--) { 210 | token = &tokens[i]; 211 | if (token->start != -1 && token->end == -1) { 212 | if (token->type != type) { 213 | return JSMN_ERROR_INVAL; 214 | } 215 | parser->toksuper = -1; 216 | token->end = parser->pos + 1; 217 | break; 218 | } 219 | } 220 | /* Error if unmatched closing bracket */ 221 | if (i == -1) return JSMN_ERROR_INVAL; 222 | for (; i >= 0; i--) { 223 | token = &tokens[i]; 224 | if (token->start != -1 && token->end == -1) { 225 | parser->toksuper = i; 226 | break; 227 | } 228 | } 229 | #endif 230 | break; 231 | case '\"': 232 | r = jsmn_parse_string(parser, js, len, tokens, num_tokens); 233 | if (r < 0) return r; 234 | count++; 235 | if (parser->toksuper != -1 && tokens != NULL) 236 | tokens[parser->toksuper].size++; 237 | break; 238 | case '\t' : case '\r' : case '\n' : case ':' : case ',': case ' ': 239 | break; 240 | #ifdef JSMN_STRICT 241 | /* In strict mode primitives are: numbers and booleans */ 242 | case '-': case '0': case '1' : case '2': case '3' : case '4': 243 | case '5': case '6': case '7' : case '8': case '9': 244 | case 't': case 'f': case 'n' : 245 | #else 246 | /* In non-strict mode every unquoted value is a primitive */ 247 | default: 248 | #endif 249 | r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); 250 | if (r < 0) return r; 251 | count++; 252 | if (parser->toksuper != -1 && tokens != NULL) 253 | tokens[parser->toksuper].size++; 254 | break; 255 | 256 | #ifdef JSMN_STRICT 257 | /* Unexpected char in strict mode */ 258 | default: 259 | return JSMN_ERROR_INVAL; 260 | #endif 261 | } 262 | } 263 | 264 | for (i = parser->toknext - 1; i >= 0; i--) { 265 | /* Unmatched opened object or array */ 266 | if (tokens[i].start != -1 && tokens[i].end == -1) { 267 | return JSMN_ERROR_PART; 268 | } 269 | } 270 | return count; 271 | } 272 | 273 | /** 274 | * Creates a new parser based over a given buffer with an array of tokens 275 | * available. 276 | */ 277 | void jsmn_init(jsmn_parser *parser) { 278 | parser->pos = 0; 279 | parser->toknext = 0; 280 | parser->toksuper = -1; 281 | } 282 | 283 | -------------------------------------------------------------------------------- /src/helper/jsmn/jsmn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Serge A. Zaitsev 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | * Note: struct jsontok_t is modified to reduce it's memory impact 25 | */ 26 | 27 | #ifndef __JSMN_PRIV_H__ 28 | #define __JSMN_PRIV_H__ 29 | 30 | #include "json_parser.h" 31 | 32 | #define JSMN_STRICT 1 33 | #define JSMN_PARENT_LINKS 1 34 | /** 35 | * JSON type identifier. Basic types are: 36 | * o Object 37 | * o Array 38 | * o String 39 | * o Other primitive: number, boolean (true/false) or null 40 | */ 41 | typedef enum { 42 | JSMN_PRIMITIVE = 0, 43 | JSMN_OBJECT = 1, 44 | JSMN_ARRAY = 2, 45 | JSMN_STRING = 3 46 | } jsmntype_t; 47 | 48 | typedef enum { 49 | /* Not enough tokens were provided */ 50 | JSMN_ERROR_NOMEM = -1, 51 | /* Invalid character inside JSON string */ 52 | JSMN_ERROR_INVAL = -2, 53 | /* The string is not a full JSON packet, more bytes expected */ 54 | JSMN_ERROR_PART = -3, 55 | } jsmnerr_t; 56 | 57 | typedef json_parser_t jsmn_parser; 58 | typedef jsontok_t jsmntok_t; 59 | 60 | /** 61 | * Create JSON parser over an array of tokens 62 | */ 63 | void jsmn_init(jsmn_parser *parser); 64 | 65 | /** 66 | * Run JSON parser. It parses a JSON data string into and array of tokens, 67 | * each describing a single JSON object. 68 | */ 69 | int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, 70 | jsmntok_t *tokens, unsigned int num_tokens); 71 | 72 | #endif /* __JSMN_PRIV_H__ */ 73 | -------------------------------------------------------------------------------- /src/helper/jsmn/json_escape_str.c: -------------------------------------------------------------------------------- 1 | #include "mx_common.h" 2 | #include "json_escape_str.h" 3 | 4 | int json_escape_str(struct json_printbuf *pb, const char *str, int len); 5 | struct json_printbuf* json_printbuf_new(void); 6 | void json_printbuf_reset(struct json_printbuf *p); 7 | void json_printbuf_free(struct json_printbuf *p); 8 | 9 | struct json_printbuf* json_printbuf_new(void) 10 | { 11 | struct json_printbuf *p; 12 | 13 | p = (struct json_printbuf*)calloc(1, sizeof(struct json_printbuf)); 14 | if(!p) return NULL; 15 | p->size = 4; 16 | p->bpos = 0; 17 | if(!(p->buf = (char*)malloc(p->size))) { 18 | free(p); 19 | return NULL; 20 | } 21 | return p; 22 | } 23 | 24 | void json_printbuf_reset(struct json_printbuf *p) 25 | { 26 | p->buf[0] = '\0'; 27 | p->bpos = 0; 28 | } 29 | 30 | void json_printbuf_free(struct json_printbuf *p) 31 | { 32 | if(p) { 33 | free(p->buf); 34 | free(p); 35 | } 36 | } 37 | 38 | static int json_printbuf_memappend(struct json_printbuf *p, const char *buf, int size) 39 | { 40 | char *t; 41 | if(p->size - p->bpos <= size) { 42 | int new_size = JSON_MAX(p->size * 2, p->bpos + size + 8); 43 | //#ifdef json_printbuf_DEBUG 44 | // MC_DEBUG("json_printbuf_memappend: realloc " 45 | // "bpos=%d wrsize=%d old_size=%d new_size=%d\n", 46 | // p->bpos, size, p->size, new_size); 47 | //#endif /* json_printbuf_DEBUG */ 48 | if(!(t = (char*)realloc(p->buf, new_size))) return -1; 49 | p->size = new_size; 50 | p->buf = t; 51 | } 52 | memcpy(p->buf + p->bpos, buf, size); 53 | p->bpos += size; 54 | p->buf[p->bpos]= '\0'; 55 | return size; 56 | } 57 | 58 | /* string escaping */ 59 | int json_escape_str(struct json_printbuf *pb, const char *str, int len) 60 | { 61 | int pos = 0, start_offset = 0; 62 | const char *json_hex_chars = "0123456789abcdef"; 63 | 64 | unsigned char c; 65 | 66 | if(len == 0) { 67 | json_printbuf_memappend(pb, str, pos); 68 | return 0; 69 | } 70 | 71 | while (len--) { 72 | c = str[pos]; 73 | switch(c) { 74 | case '\b': 75 | case '\n': 76 | case '\r': 77 | case '\t': 78 | case '"': 79 | case '\\': 80 | case '/': 81 | if(pos - start_offset > 0) 82 | json_printbuf_memappend(pb, str + start_offset, pos - start_offset); 83 | if(c == '\b') json_printbuf_memappend(pb, "\\b", 2); 84 | else if(c == '\n') json_printbuf_memappend(pb, "\\n", 2); 85 | else if(c == '\r') json_printbuf_memappend(pb, "\\r", 2); 86 | else if(c == '\t') json_printbuf_memappend(pb, "\\t", 2); 87 | else if(c == '"') json_printbuf_memappend(pb, "\\\"", 2); 88 | else if(c == '\\') json_printbuf_memappend(pb, "\\\\", 2); 89 | else if(c == '/') json_printbuf_memappend(pb, "\\/", 2); 90 | start_offset = ++pos; 91 | break; 92 | default: 93 | if(c < ' ') { 94 | if(pos - start_offset > 0) 95 | json_printbuf_memappend(pb, str + start_offset, pos - start_offset); 96 | sprintf((char *)pb, "\\u00%c%c", 97 | json_hex_chars[c >> 4], 98 | json_hex_chars[c & 0xf]); 99 | start_offset = ++pos; 100 | } else pos++; 101 | } 102 | } 103 | if(pos - start_offset > 0) 104 | json_printbuf_memappend(pb, str + start_offset, pos - start_offset); 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /src/helper/jsmn/json_escape_str.h: -------------------------------------------------------------------------------- 1 | #ifndef _JSON_ESCAPE_STR_H 2 | #define _JSON_ESCAPE_STR_H 3 | 4 | #ifndef JSON_MIN 5 | #define JSON_MIN(a,b) ((a) < (b) ? (a) : (b)) 6 | #endif 7 | 8 | #ifndef JSON_MAX 9 | #define JSON_MAX(a,b) ((a) > (b) ? (a) : (b)) 10 | #endif 11 | 12 | struct json_printbuf { 13 | char *buf; 14 | int bpos; 15 | int size; 16 | }; 17 | 18 | extern int json_escape_str(struct json_printbuf *pb, const char *str, int len); 19 | extern struct json_printbuf* json_printbuf_new(void); 20 | extern void json_printbuf_reset(struct json_printbuf *p); 21 | extern void json_printbuf_free(struct json_printbuf *p); 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/helper/jsmn/json_utils.c: -------------------------------------------------------------------------------- 1 | #include "mx_common.h" 2 | 3 | #define mico_int_part_of(x) ((int)(x)) 4 | 5 | static inline int mico_frac_part_of(float x, short precision) 6 | { 7 | int scale = 1; 8 | 9 | while (precision--) 10 | scale *= 10; 11 | 12 | return (x < 0 ? (int)(((int)x - x) * scale) : (int)((x - (int)x) * scale)); 13 | } 14 | 15 | /* Function to convert a string to float. 16 | * \param[in] str Pointer to a string to be addressed 17 | * \param[out] endptr Pointer pointing to next character in a string */ 18 | float mico_strtof(const char *str, char **endptr) 19 | { 20 | char *start_ptr = (char *)str; 21 | int sign = 1; 22 | 23 | if (endptr == NULL) { 24 | char *end_ptr; 25 | endptr = &end_ptr; 26 | } 27 | 28 | if (*start_ptr == '-') { 29 | sign = -1; 30 | start_ptr++; 31 | } 32 | int dec_val = 0; 33 | int powten = 1; 34 | 35 | int int_val = strtoul(start_ptr, endptr, 10); 36 | if (**endptr == '.') { 37 | start_ptr = *endptr + 1; 38 | dec_val = strtoul(start_ptr, endptr, 10); 39 | while (start_ptr++ != *endptr) 40 | powten *= 10; 41 | } else 42 | return sign * (float)int_val; 43 | 44 | float dec_frac = (float)dec_val/powten; 45 | float result = (float)(int_val + dec_frac); 46 | 47 | /* Below part is done in order to improve the accuracy of the result. 48 | * Since addition above results in float value being drifted from 49 | * the actual value by narrow margin. e.g 50.10 results in float 50 | * equivalent of 50.09.*/ 51 | /* TODO: Visit again to see if the below code really helps. 52 | * Sometimes, reporting values differently is a result of the 53 | * way float values are stored in memory. In that case, the below 54 | * code will not improve anything. Eg. If 50.1 is stored as 50.09 55 | * in memory, we cannot do much about it. 56 | */ 57 | int result_int_value = mico_int_part_of(result); 58 | float result_frac_value = (float)(result) - result_int_value; 59 | 60 | /* Generally difference between two float values comes out to be in 61 | * the order of 1/powten. e.g 0.10-0.09 comes out to be 0.00...1. 62 | * Hence we multiply the result of subtraction to achieve the accuracy 63 | * within desired float precision. */ 64 | if (mico_frac_part_of(dec_frac, powten/10) > 65 | mico_frac_part_of(result_frac_value, powten/10)) 66 | result += ((dec_frac - result_frac_value) * powten); 67 | if (mico_frac_part_of(result_frac_value, powten/10) > 68 | mico_frac_part_of(dec_frac, powten/10)) 69 | result += ((result_frac_value - dec_frac) * powten); 70 | 71 | return sign * result; 72 | } 73 | -------------------------------------------------------------------------------- /src/helper/jsmn/json_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _JSON_UTILS_H_ 2 | #define _JSON_UTILS_H_ 3 | 4 | float mico_strtof(const char *str, char **endptr); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/helper/mx_opt.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mico_opt.h 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 18-Apr-2018 7 | * @brief This file provide default configurations. 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __MX_OPT_H__ 28 | #define __MX_OPT_H__ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /****************************************************************************** 35 | * AliCloud SDS service 36 | ******************************************************************************/ 37 | 38 | #if !defined ALISDS_ATTR_VAL_MAX_LEN 39 | #define ALISDS_ATTR_VAL_MAX_LEN (1024) /**< Max possible attr value length, reduce to save memory */ 40 | #endif 41 | 42 | #if !defined ALISDS_ATTR_NAME_MAX_LEN 43 | #define ALISDS_ATTR_NAME_MAX_LEN (64) /**< Max possible attr name length, reduce to save memory */ 44 | #endif 45 | 46 | /****************************************************************************** 47 | * AliCloud SDS service 48 | ******************************************************************************/ 49 | 50 | 51 | /****************************************************************************** 52 | * AT command parser 53 | ******************************************************************************/ 54 | 55 | #if !defined AT_BUFFER_SIZE 56 | #define AT_BUFFER_SIZE (512) /**< Max buffer used for AT command analyser, no used for recv raw data */ 57 | #endif 58 | 59 | /****************************************************************************** 60 | * MX HAL 61 | ******************************************************************************/ 62 | 63 | #if !defined MX_SERIAL_RX_BUF_SIZE 64 | #define MX_SERIAL_RX_BUF_SIZE (1024) /**< AT command receiver serial port input buffer size */ 65 | #endif 66 | 67 | #if !defined MX_CLI_RX_BUF_SIZE 68 | #define MX_CLI_RX_BUF_SIZE (1024) /**< Cli command receiver serial port input buffer size */ 69 | #endif 70 | 71 | /****************************************************************************** 72 | * MX Debug Enabler 73 | ******************************************************************************/ 74 | 75 | #if !defined MX_DEBUG_MIN_LEVEL 76 | #define MX_DEBUG_MIN_LEVEL MX_DEBUG_LEVEL_ALL 77 | #endif 78 | 79 | #if !defined MX_DEBUG_TYPES_ON 80 | #define MX_DEBUG_TYPES_ON MX_DEBUG_ON 81 | #endif 82 | 83 | 84 | /****************************************************************************** 85 | * Debug and Log 86 | ******************************************************************************/ 87 | 88 | #if !defined CONFIG_APP_DEBUG 89 | #define CONFIG_APP_DEBUG MX_DEBUG_ON 90 | #endif 91 | 92 | #if !defined CONFIG_CLOUD_DEBUG 93 | #define CONFIG_CLOUD_DEBUG MX_DEBUG_ON 94 | #endif 95 | 96 | 97 | #ifdef __cplusplus 98 | } /*extern "C" */ 99 | #endif 100 | 101 | #endif //__MX_OPT_H 102 | -------------------------------------------------------------------------------- /src/helper/mx_utils/mx_ringbuffer.c: -------------------------------------------------------------------------------- 1 | #include "mx_ringbuffer.h" 2 | 3 | /** 4 | * \brief Ringbuffer init 5 | */ 6 | int32_t ringbuffer_init(struct ringbuffer* const rb, void* buf, uint32_t size) 7 | { 8 | mx_status err = kNoErr; 9 | require_action(rb && buf && size, exit, err = kParamErr); 10 | 11 | /* 12 | * buf size must be aligned to power of 2 13 | */ 14 | require_action((size & (size - 1)) == 0, exit, err = kParamErr); 15 | 16 | /* size - 1 is faster in calculation */ 17 | rb->size = size - 1; 18 | rb->read_index = 0; 19 | rb->write_index = rb->read_index; 20 | rb->buf = (uint8_t*)buf; 21 | 22 | exit: 23 | return err; 24 | } 25 | 26 | /** 27 | * \brief Get one byte from ringbuffer 28 | * 29 | */ 30 | int32_t ringbuffer_get(struct ringbuffer* const rb, uint8_t* data) 31 | { 32 | mx_status err = kNotFoundErr; 33 | require_action(rb && data, exit, err = kParamErr); 34 | 35 | if (rb->write_index != rb->read_index) { 36 | *data = rb->buf[rb->read_index & rb->size]; 37 | rb->read_index++; 38 | return kNoErr; 39 | } 40 | 41 | exit: 42 | return err; 43 | } 44 | 45 | /** 46 | * \brief Put one byte to ringbuffer 47 | * 48 | */ 49 | int32_t ringbuffer_put(struct ringbuffer* const rb, uint8_t data) 50 | { 51 | mx_status err = kNoErr; 52 | require_action(rb, exit, err = kParamErr); 53 | 54 | rb->buf[rb->write_index & rb->size] = data; 55 | 56 | /* 57 | * buffer full strategy: new data will overwrite the oldest data in 58 | * the buffer 59 | */ 60 | if ((rb->write_index - rb->read_index) > rb->size) { 61 | rb->read_index = rb->write_index - rb->size; 62 | } 63 | 64 | rb->write_index++; 65 | 66 | exit: 67 | return err; 68 | } 69 | 70 | /** 71 | * \brief Return the element number of ringbuffer 72 | */ 73 | uint32_t ringbuffer_num(const struct ringbuffer* const rb) 74 | { 75 | return rb->write_index - rb->read_index; 76 | } 77 | 78 | /** 79 | * \brief Flush ringbuffer 80 | */ 81 | uint32_t ringbuffer_flush(struct ringbuffer* const rb) 82 | { 83 | rb->read_index = rb->write_index; 84 | return kNoErr; 85 | } 86 | -------------------------------------------------------------------------------- /src/helper/mx_utils/mx_ringbuffer.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mx_ringbuffer.c 4 | * @author William Xu 5 | * @version V1.0.0 6 | * @date 18-Apr-2018 7 | * @brief Ringbuffer utils used for UART data receive 8 | ****************************************************************************** 9 | * 10 | * Copyright (c) 2009-2018 MXCHIP Co.,Ltd. 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef _MX_RINGBUFFER_H_ 28 | #define _MX_RINGBUFFER_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #include "mx_common.h" 35 | #include "mx_debug.h" 36 | 37 | /** \addtogroup utils */ 38 | /** @{*/ 39 | 40 | /** 41 | * \brief Ring buffer element type 42 | */ 43 | struct ringbuffer { 44 | uint8_t* buf; /** Buffer base address */ 45 | uint32_t size; /** Buffer size */ 46 | uint32_t read_index; /** Buffer read index */ 47 | uint32_t write_index; /** Buffer write index */ 48 | }; 49 | 50 | /** 51 | * \brief Ring buffer init 52 | * 53 | * \param[in] rb The pointer to a ring buffer structure instance 54 | * \param[in] buf Space to store the data 55 | * \param[in] size The buffer length, must be aligned with power of 2 56 | * 57 | * \return ERR_NONE on success, or an error code on failure. 58 | */ 59 | int32_t ringbuffer_init(struct ringbuffer* const rb, void* buf, uint32_t size); 60 | 61 | /** 62 | * \brief Get one byte from ring buffer, the user needs to handle the concurrent 63 | * access on buffer via put/get/flush 64 | * 65 | * \param[in] rb The pointer to a ring buffer structure instance 66 | * \param[in] data One byte space to store the read data 67 | * 68 | * \return ERR_NONE on success, or an error code on failure. 69 | */ 70 | int32_t ringbuffer_get(struct ringbuffer* const rb, uint8_t* data); 71 | 72 | /** 73 | * \brief Put one byte to ring buffer, the user needs to handle the concurrent access 74 | * on buffer via put/get/flush 75 | * 76 | * \param[in] rb The pointer to a ring buffer structure instance 77 | * \param[in] data One byte data to be put into ring buffer 78 | * 79 | * \return ERR_NONE on success, or an error code on failure. 80 | */ 81 | int32_t ringbuffer_put(struct ringbuffer* const rb, uint8_t data); 82 | 83 | /** 84 | * \brief Return the element number of ring buffer 85 | * 86 | * \param[in] rb The pointer to a ring buffer structure instance 87 | * 88 | * \return The number of elements in ring buffer [0, rb->size] 89 | */ 90 | uint32_t ringbuffer_num(const struct ringbuffer* const rb); 91 | 92 | /** 93 | * \brief Flush ring buffer, the user needs to handle the concurrent access on buffer 94 | * via put/get/flush 95 | * 96 | * \param[in] rb The pointer to a ring buffer structure instance 97 | * 98 | * \return ERR_NONE on success, or an error code on failure. 99 | */ 100 | uint32_t ringbuffer_flush(struct ringbuffer* const rb); 101 | 102 | /**@}*/ 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | #endif /* _MX_RINGBUFFER_H_ */ 108 | --------------------------------------------------------------------------------