add support for multi at device
This commit is contained in:
@@ -31,8 +31,12 @@ typedef struct ip_addr_st {
|
||||
uint8_t seg4;
|
||||
}ip_addr_t;
|
||||
|
||||
at_agent_t ec600s_agent;
|
||||
static ip_addr_t domain_parser_addr = {0};
|
||||
static k_sem_t domain_parser_sem;
|
||||
static k_stack_t ec600s_at_parse_task_stk[AT_PARSER_TASK_STACK_SIZE];
|
||||
|
||||
#define AT_AGENT ((at_agent_t *)&ec600s_agent)
|
||||
|
||||
static int ec600s_check_ready(void)
|
||||
{
|
||||
@@ -41,7 +45,7 @@ static int ec600s_check_ready(void)
|
||||
|
||||
while (try++ < 10) {
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -58,7 +62,7 @@ static int ec600s_echo_close(void)
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "ATE0\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -74,7 +78,7 @@ static int ec600s_sim_card_check(void)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CPIN?\r\n");
|
||||
if (strstr(echo_buffer, "READY")) {
|
||||
return 0;
|
||||
}
|
||||
@@ -93,7 +97,7 @@ static int ec600s_signal_quality_check(void)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CSQ\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -121,7 +125,7 @@ static int ec600s_gsm_network_check(void)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -149,8 +153,7 @@ static int ec600s_gprs_network_check(void)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10) {
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CGREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -174,7 +177,7 @@ static int ec600s_close_apn(void)
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 3000, "AT+QIDEACT=1\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 3000, "AT+QIDEACT=1\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -187,12 +190,12 @@ static int ec600s_set_apn(void)
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICSGP=1,1,\"CMNET\"\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+QICSGP=1,1,\"CMNET\"\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_cmd_exec(&echo, 3000, "AT+QIACT=1\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 3000, "AT+QIACT=1\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -258,7 +261,7 @@ static int ec600s_connect_establish(int id, sal_proto_t proto)
|
||||
char *remote_port = NULL;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QISTATE=1,%d\r\n", id);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+QISTATE=1,%d\r\n", id);
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
printf("query socket %d state fail\r\n", id);
|
||||
return -1;
|
||||
@@ -269,20 +272,20 @@ static int ec600s_connect_establish(int id, sal_proto_t proto)
|
||||
if (query_result_str) {
|
||||
printf("socket %d established on module already\r\n", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
}
|
||||
|
||||
memset(except_str, 0, sizeof(except_str));
|
||||
sprintf(except_str, "+QIOPEN: %d,0", id);
|
||||
|
||||
remote_ip = (char*)tos_at_channel_ip_get(id);
|
||||
remote_port = (char*)tos_at_channel_port_get(id);
|
||||
remote_ip = (char*)tos_at_channel_ip_get(AT_AGENT, id);
|
||||
remote_port = (char*)tos_at_channel_port_get(AT_AGENT, id);
|
||||
if (!remote_ip || !remote_port) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, except_str);
|
||||
tos_at_cmd_exec_until(&echo, 4000, "AT+QIOPEN=1,%d,\"%s\",\"%s\",%d,0,1\r\n",
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 4000, "AT+QIOPEN=1,%d,\"%s\",\"%s\",%d,0,1\r\n",
|
||||
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", remote_ip, atoi(remote_port));
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
printf("establish socket %d on module fail\r\n", id);
|
||||
@@ -296,14 +299,14 @@ static int ec600s_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
{
|
||||
int id;
|
||||
|
||||
id = tos_at_channel_alloc(ip, port);
|
||||
id = tos_at_channel_alloc(AT_AGENT, ip, port);
|
||||
if (id == -1) {
|
||||
printf("at channel alloc fail\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ec600s_connect_establish(id, proto) < 0) {
|
||||
tos_at_channel_free(id);
|
||||
tos_at_channel_free(AT_AGENT, id);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@@ -314,14 +317,14 @@ static int ec600s_connect_with_size(const char *ip, const char *port, sal_proto_
|
||||
{
|
||||
int id;
|
||||
|
||||
id = tos_at_channel_alloc_with_size(ip, port, socket_buffer_size);
|
||||
id = tos_at_channel_alloc_with_size(AT_AGENT, ip, port, socket_buffer_size);
|
||||
if (id == -1) {
|
||||
printf("at channel alloc fail\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ec600s_connect_establish(id, proto) < 0) {
|
||||
tos_at_channel_free(id);
|
||||
tos_at_channel_free(AT_AGENT, id);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@@ -330,7 +333,7 @@ static int ec600s_connect_with_size(const char *ip, const char *port, sal_proto_
|
||||
|
||||
static int ec600s_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return tos_at_channel_read_timed(id, buf, len, timeout);
|
||||
return tos_at_channel_read_timed(AT_AGENT, id, buf, len, timeout);
|
||||
}
|
||||
|
||||
static int ec600s_recv(int id, void *buf, size_t len)
|
||||
@@ -342,38 +345,38 @@ int ec600s_send(int id, const void *buf, size_t len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
if (!tos_at_channel_is_working(id)) {
|
||||
if (!tos_at_channel_is_working(AT_AGENT, id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
if (tos_at_global_lock_pend(AT_AGENT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
|
||||
tos_at_raw_data_send_until(AT_AGENT, &echo, 10000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int ec600s_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return tos_at_channel_read_timed(id, buf, len, timeout);
|
||||
return tos_at_channel_read_timed(AT_AGENT, id, buf, len, timeout);
|
||||
}
|
||||
|
||||
int ec600s_recvfrom(int id, void *buf, size_t len)
|
||||
@@ -385,26 +388,26 @@ int ec600s_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
if (tos_at_global_lock_pend(AT_AGENT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
|
||||
tos_at_raw_data_send(AT_AGENT, &echo, 1000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
|
||||
return len;
|
||||
}
|
||||
@@ -414,7 +417,7 @@ static void ec600s_transparent_mode_exit(void)
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 500, "+++");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 500, "+++");
|
||||
}
|
||||
|
||||
static int ec600s_close(int id)
|
||||
@@ -424,9 +427,9 @@ static int ec600s_close(int id)
|
||||
ec600s_transparent_mode_exit();
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
|
||||
tos_at_channel_free(id);
|
||||
tos_at_channel_free(AT_AGENT, id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -439,7 +442,7 @@ static int ec600s_parse_domain(const char *host_name, char *host_ip, size_t host
|
||||
tos_sem_create_max(&domain_parser_sem, 0, 1);
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+QIDNSGIP=1,\"%s\"\r\n", host_name);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 2000, "AT+QIDNSGIP=1,\"%s\"\r\n", host_name);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
@@ -466,7 +469,7 @@ __STATIC__ void ec600s_incoming_data_process(void)
|
||||
*/
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ',') {
|
||||
@@ -476,7 +479,7 @@ __STATIC__ void ec600s_incoming_data_process(void)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -486,7 +489,7 @@ __STATIC__ void ec600s_incoming_data_process(void)
|
||||
data_len = data_len * 10 + (data - '0');
|
||||
}
|
||||
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -495,11 +498,11 @@ __STATIC__ void ec600s_incoming_data_process(void)
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
read_len = MIN(data_len, sizeof(buffer));
|
||||
if (tos_at_uart_read(buffer, read_len) != read_len) {
|
||||
if (tos_at_uart_read(AT_AGENT, buffer, read_len) != read_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tos_at_channel_write(channel_id, buffer, read_len) <= 0) {
|
||||
if (tos_at_channel_write(AT_AGENT, channel_id, buffer, read_len) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -519,7 +522,7 @@ __STATIC__ void ec600s_domain_data_process(void)
|
||||
+QIURC: "dnsgip","xxx.xxx.xxx.xxx"
|
||||
*/
|
||||
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -530,7 +533,7 @@ __STATIC__ void ec600s_domain_data_process(void)
|
||||
if (data == '\"') {
|
||||
/* start parser domain */
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == '.') {
|
||||
@@ -539,7 +542,7 @@ __STATIC__ void ec600s_domain_data_process(void)
|
||||
domain_parser_addr.seg1 = domain_parser_addr.seg1 *10 + (data-'0');
|
||||
}
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == '.') {
|
||||
@@ -548,7 +551,7 @@ __STATIC__ void ec600s_domain_data_process(void)
|
||||
domain_parser_addr.seg2 = domain_parser_addr.seg2 *10 + (data-'0');
|
||||
}
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == '.') {
|
||||
@@ -557,7 +560,7 @@ __STATIC__ void ec600s_domain_data_process(void)
|
||||
domain_parser_addr.seg3 = domain_parser_addr.seg3 *10 + (data-'0');
|
||||
}
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == '\"') {
|
||||
@@ -593,7 +596,8 @@ sal_module_t sal_module_ec600s = {
|
||||
int ec600s_sal_init(hal_uart_port_t uart_port)
|
||||
{
|
||||
|
||||
if (tos_at_init(uart_port, ec600s_at_event,
|
||||
if (tos_at_init(AT_AGENT, "ec600s_at", ec600s_at_parse_task_stk,
|
||||
uart_port, ec600s_at_event,
|
||||
sizeof(ec600s_at_event) / sizeof(ec600s_at_event[0])) != 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -618,7 +622,7 @@ int ec600s_sal_deinit()
|
||||
|
||||
tos_sal_module_register_default();
|
||||
|
||||
tos_at_deinit();
|
||||
tos_at_deinit(AT_AGENT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,13 +1,17 @@
|
||||
#include "tos_at.h"
|
||||
#include "esp8266.h"
|
||||
#include "sal_module_wrapper.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include "stdbool.h"
|
||||
#include "ctype.h"
|
||||
|
||||
#define TOS_CFG_MODULE_SINGLE_LINK_EN 0u
|
||||
|
||||
at_agent_t esp8266_agent;
|
||||
static k_stack_t esp8266_at_parse_task_stk[AT_PARSER_TASK_STACK_SIZE];
|
||||
|
||||
#define AT_AGENT ((at_agent_t *)&esp8266_agent)
|
||||
|
||||
static int esp8266_restore(void)
|
||||
{
|
||||
int try = 0;
|
||||
@@ -15,7 +19,7 @@ static int esp8266_restore(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "ready");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec_until(&echo, 5000, "AT+RESTORE\r\n");
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 5000, "AT+RESTORE\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -28,7 +32,7 @@ static int esp8266_echo_close(void)
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "ATE0\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -57,7 +61,7 @@ static int esp8266_net_mode_set(esp8266_net_mode_t mode)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, cmd);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -72,7 +76,7 @@ static int esp8266_send_mode_set(esp8266_send_mode_t mode)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPMODE=%d\r\n", mode == ESP8266_SEND_MODE_NORMAL ? 0 : 1);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CIPMODE=%d\r\n", mode == ESP8266_SEND_MODE_NORMAL ? 0 : 1);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -87,7 +91,7 @@ static int esp8266_multilink_set(esp8266_multilink_state_t state)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 500, "AT+CIPMUX=%d\r\n", state == ESP8266_MULTILINK_STATE_ENABLE ? 1 : 0);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 500, "AT+CIPMUX=%d\r\n", state == ESP8266_MULTILINK_STATE_ENABLE ? 1 : 0);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
} else if (echo.status == AT_ECHO_STATUS_ERROR) {
|
||||
@@ -104,7 +108,7 @@ int esp8266_join_ap(const char *ssid, const char *pwd)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -143,7 +147,7 @@ static int esp8266_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
int id;
|
||||
at_echo_t echo;
|
||||
|
||||
id = tos_at_channel_alloc(ip, port);
|
||||
id = tos_at_channel_alloc(AT_AGENT, ip, port);
|
||||
if (id == -1) {
|
||||
return -1;
|
||||
}
|
||||
@@ -154,7 +158,7 @@ static int esp8266_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
"AT+CIPSTART=\"%s\",\"%s\",%s\r\n",
|
||||
proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port);
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 10000,
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 10000,
|
||||
"AT+CIPSTART=%d,\"%s\",\"%s\",%s\r\n",
|
||||
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port);
|
||||
#endif
|
||||
@@ -162,19 +166,19 @@ static int esp8266_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
return id;
|
||||
}
|
||||
|
||||
tos_at_channel_free(id);
|
||||
tos_at_channel_free(AT_AGENT, id);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int esp8266_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return tos_at_channel_read_timed(id, buf, len, timeout);
|
||||
return tos_at_channel_read_timed(AT_AGENT, id, buf, len, timeout);
|
||||
}
|
||||
|
||||
static int esp8266_recv(int id, void *buf, size_t len)
|
||||
{
|
||||
return tos_at_channel_read(id, buf, len);
|
||||
return tos_at_channel_read(AT_AGENT, id, buf, len);
|
||||
}
|
||||
|
||||
static int esp8266_is_link_broken(const char *echo_buffer)
|
||||
@@ -192,11 +196,11 @@ static int esp8266_send(int id, const void *buf, size_t len)
|
||||
at_echo_t echo;
|
||||
char echo_buffer[64];
|
||||
|
||||
if (!tos_at_channel_is_working(id)) {
|
||||
if (!tos_at_channel_is_working(AT_AGENT, id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
if (tos_at_global_lock_pend(AT_AGENT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -205,16 +209,16 @@ static int esp8266_send(int id, const void *buf, size_t len)
|
||||
tos_at_cmd_exec_until(&echo, 5000,
|
||||
"AT+CIPSEND=%d\r\n", len);
|
||||
#else
|
||||
tos_at_cmd_exec_until(&echo, 5000,
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 5000,
|
||||
"AT+CIPSEND=%d,%d\r\n",
|
||||
id, len);
|
||||
#endif
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (esp8266_is_link_broken((const char *)echo.buffer)) {
|
||||
tos_at_channel_set_broken(id);
|
||||
tos_at_channel_set_broken(AT_AGENT, id);
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -224,17 +228,17 @@ static int esp8266_send(int id, const void *buf, size_t len)
|
||||
ATTENTION: we should wait util "SEND OK" is echoed, otherwise the next
|
||||
time we execute at command, the esp8266 maybe in a "busy s ..." state.
|
||||
*/
|
||||
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
|
||||
tos_at_raw_data_send_until(AT_AGENT, &echo, 10000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (esp8266_is_link_broken((const char *)echo.buffer)) {
|
||||
tos_at_channel_set_broken(id);
|
||||
tos_at_channel_set_broken(AT_AGENT, id);
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -243,11 +247,11 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t
|
||||
at_echo_t echo;
|
||||
char echo_buffer[64];
|
||||
|
||||
if (!tos_at_channel_is_working(id)) {
|
||||
if (!tos_at_channel_is_working(AT_AGENT, id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
if (tos_at_global_lock_pend(AT_AGENT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -258,7 +262,7 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d,\"%s\",%s\r\n", len, ip, port);
|
||||
#else
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 1000,
|
||||
"AT+CIPSEND=%d,%d,\"%s\",%s\r\n", id, len, ip, port);
|
||||
#endif
|
||||
} else {
|
||||
@@ -266,17 +270,17 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d\r\n", len);
|
||||
#else
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 1000,
|
||||
"AT+CIPSEND=%d,%d\r\n", id, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (esp8266_is_link_broken((const char *)echo.buffer)) {
|
||||
tos_at_channel_set_broken(id);
|
||||
tos_at_channel_set_broken(AT_AGENT, id);
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -286,23 +290,23 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t
|
||||
ATTENTION: we should wait util "SEND OK" is echoed, otherwise the next
|
||||
time we execute at command, the esp8266 maybe in a "busy s ..." state.
|
||||
*/
|
||||
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
|
||||
tos_at_raw_data_send_until(AT_AGENT, &echo, 10000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (esp8266_is_link_broken((const char *)echo.buffer)) {
|
||||
tos_at_channel_set_broken(id);
|
||||
tos_at_channel_set_broken(AT_AGENT, id);
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_global_lock_post();
|
||||
tos_at_global_lock_post(AT_AGENT);
|
||||
return len;
|
||||
}
|
||||
|
||||
static int esp8266_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
{
|
||||
return tos_at_channel_read_timed(id, buf, len, timeout);
|
||||
return tos_at_channel_read_timed(AT_AGENT, id, buf, len, timeout);
|
||||
}
|
||||
|
||||
static int esp8266_recvfrom(int id, void *buf, size_t len)
|
||||
@@ -317,11 +321,11 @@ static int esp8266_close(int id)
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPCLOSE\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CIPCLOSE\r\n");
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPCLOSE=%d\r\n", id);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CIPCLOSE=%d\r\n", id);
|
||||
#endif
|
||||
tos_at_channel_free(id);
|
||||
tos_at_channel_free(AT_AGENT, id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -334,7 +338,7 @@ static int esp8266_parse_domain(const char *host_name, char *host_ip, size_t hos
|
||||
esp8266_reconnect_init();
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+CIPDOMAIN=\"%s\"\r\n", host_name);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 2000, "AT+CIPDOMAIN=\"%s\"\r\n", host_name);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
@@ -409,7 +413,7 @@ __STATIC__ void esp8266_incoming_data_process(void)
|
||||
*/
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN == 0u
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ',') {
|
||||
@@ -420,7 +424,7 @@ __STATIC__ void esp8266_incoming_data_process(void)
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ':') {
|
||||
@@ -434,14 +438,14 @@ __STATIC__ void esp8266_incoming_data_process(void)
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
read_len = MIN(data_len, sizeof(buffer));
|
||||
if (tos_at_uart_read(buffer, read_len) != read_len) {
|
||||
if (tos_at_uart_read(AT_AGENT, buffer, read_len) != read_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
//delay has two reason, wait for the data to be cached and untrigger scheduling
|
||||
tos_stopwatch_delay(200);
|
||||
|
||||
if (tos_at_channel_write(channel_id, buffer, read_len) <= 0) {
|
||||
if (tos_at_channel_write(AT_AGENT, channel_id, buffer, read_len) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -469,7 +473,8 @@ sal_module_t sal_module_esp8266 = {
|
||||
|
||||
int esp8266_sal_init(hal_uart_port_t uart_port)
|
||||
{
|
||||
if (tos_at_init(uart_port, esp8266_at_event,
|
||||
if (tos_at_init(AT_AGENT, "esp8266_at", esp8266_at_parse_task_stk,
|
||||
uart_port, esp8266_at_event,
|
||||
sizeof(esp8266_at_event) / sizeof(esp8266_at_event[0])) != 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -495,7 +500,7 @@ int esp8266_sal_deinit()
|
||||
|
||||
tos_sal_module_register_default();
|
||||
|
||||
tos_at_deinit();
|
||||
tos_at_deinit(AT_AGENT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -6,6 +6,11 @@
|
||||
#include "tencent_firmware_module_wrapper.h"
|
||||
#include "esp8266_tencent_firmware.h"
|
||||
|
||||
at_agent_t esp8266_tf_agent;
|
||||
static k_stack_t esp8266_tf_at_parse_task_stk[AT_PARSER_TASK_STACK_SIZE];
|
||||
|
||||
#define AT_AGENT ((at_agent_t *)&esp8266_tf_agent)
|
||||
|
||||
/*
|
||||
* config dev info to module, do this operate only once in factroy is suggested
|
||||
*/
|
||||
@@ -15,7 +20,7 @@ int esp8266_tencent_firmware_module_info_set(device_info_t *info, tls_mode_t mod
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCDEVINFOSET:OK");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
mode, info->product_id, info->device_name, info->device_serc);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
@@ -31,7 +36,7 @@ int esp8266_tencent_firmware_module_mqtt_conn(mqtt_param_t init_params)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTCONN:OK");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
init_params.command_timeout, init_params.keep_alive_interval_ms,
|
||||
init_params.clean_session, init_params.auto_connect_enable);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
@@ -48,7 +53,7 @@ int esp8266_tencent_firmware_module_mqtt_discon(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTDISCONN\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+TCMQTTDISCONN\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -63,13 +68,13 @@ int esp8266_tencent_firmware_module_mqtt_publ(const char *topic, qos_t qos, char
|
||||
|
||||
strcat(payload, "\r\n");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUBL:OK");
|
||||
tos_at_raw_data_send_until(&echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
tos_at_raw_data_send_until(AT_AGENT, &echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
@@ -84,7 +89,7 @@ int esp8266_tencent_firmware_module_mqtt_pub(const char *topic, qos_t qos, char
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -97,7 +102,7 @@ int esp8266_tencent_firmware_module_mqtt_sub(char *topic, qos_t qos)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTSUB:OK");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -110,7 +115,7 @@ int esp8266_tencent_firmware_module_mqtt_unsub(const char *topic)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTUNSUB:OK");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -126,7 +131,7 @@ int esp8266_tencent_firmware_module_mqtt_state_get(mqtt_state_t *state)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTSTATE?\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+TCMQTTSTATE?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -153,7 +158,7 @@ int esp8266_tencent_firmware_module_debug_level_set(int log_level)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCTEMLOG=%d\r\n", log_level);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+TCTEMLOG=%d\r\n", log_level);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -167,7 +172,7 @@ int esp8266_tencent_firmware_join_ap(const char *ssid, const char *pwd)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 30000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 30000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -183,7 +188,7 @@ static int esp8266_tencent_firmware_restore(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "ready");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec_until(&echo, 5000, "AT+RESTORE\r\n");
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 5000, "AT+RESTORE\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -196,7 +201,7 @@ static int esp8266_tencent_firmware_echo_close(void)
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "ATE0\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -225,7 +230,7 @@ static int esp8266_tencent_firmware_net_mode_set(sal_net_mode_t mode)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, cmd);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -240,7 +245,7 @@ static int esp8266_tencent_firmware_send_mode_set(sal_send_mode_t mode)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPMODE=%d\r\n", mode == SAL_SEND_MODE_NORMAL ? 0 : 1);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CIPMODE=%d\r\n", mode == SAL_SEND_MODE_NORMAL ? 0 : 1);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -283,7 +288,7 @@ int esp8266_tencent_firmware_ota_set(ota_mode_t mode, char *version)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCOTASET:OK");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
@@ -306,7 +311,7 @@ int esp8266_tencent_firmware_ota_read_fwinfo(ota_fw_info_t *ota_fw_info)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), "+TCFWINFO:");
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
tos_at_cmd_exec_until(AT_AGENT, &echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
|
||||
sscanf(echo_buffer, "%*[^\"]%*c%[^\"]%*[^,]%*c%[^,]%*[^\"]%*c%[^\"]", ota_fw_info->fw_version, FileSize, ota_fw_info->fw_md5);
|
||||
@@ -341,7 +346,7 @@ static int esp8266_tencent_firmware_ota_read_fwdata(uint8_t *ota_fw_data_buffer,
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 300, "AT+TCREADFWDATA=%d\r\n", read_len);
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 300, "AT+TCREADFWDATA=%d\r\n", read_len);
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -365,7 +370,7 @@ void esp8266_tencent_firmware_recvpub(void)
|
||||
memset(&mqtt_message, 0, sizeof(mqtt_message));
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == '"') {
|
||||
@@ -384,7 +389,7 @@ void esp8266_tencent_firmware_recvpub(void)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ',') {
|
||||
@@ -397,7 +402,7 @@ void esp8266_tencent_firmware_recvpub(void)
|
||||
payload_len = sizeof(mqtt_message.payload);
|
||||
}
|
||||
|
||||
read_len = tos_at_uart_read((uint8_t*)mqtt_message.payload, payload_len + 2);
|
||||
read_len = tos_at_uart_read(AT_AGENT, (uint8_t*)mqtt_message.payload, payload_len + 2);
|
||||
if (read_len != payload_len + 2) {
|
||||
return;
|
||||
}
|
||||
@@ -414,7 +419,7 @@ void esp8266_tencent_firmware_recvcmd(void)
|
||||
uint8_t buffer[20];
|
||||
int read_len = 13;
|
||||
|
||||
if (tos_at_uart_read(buffer, read_len) != read_len) {
|
||||
if (tos_at_uart_read(AT_AGENT, buffer, read_len) != read_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -437,7 +442,7 @@ void esp8266_tencent_firmware_recvfwdata(void)
|
||||
static uint8_t buffer[128];
|
||||
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
if (data == ',') {
|
||||
@@ -449,7 +454,7 @@ void esp8266_tencent_firmware_recvfwdata(void)
|
||||
do {
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
read_len = MIN(data_len, sizeof(buffer));
|
||||
if (tos_at_uart_read(buffer, read_len) != read_len) {
|
||||
if (tos_at_uart_read(AT_AGENT, buffer, read_len) != read_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -481,7 +486,7 @@ int esp8266_tencent_firmware_start_smartconfig(void)
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCSTARTSMART\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 2000, "AT+TCSTARTSMART\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -508,7 +513,7 @@ int esp8266_tencent_firmware_stop_smartconfig(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCSTOPSMART\r\n");
|
||||
tos_at_cmd_exec(AT_AGENT, &echo, 2000, "AT+TCSTOPSMART\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
@@ -523,7 +528,7 @@ void esp8266_tencent_firmware_recvscstatus(void)
|
||||
*/
|
||||
static char buffer[40];
|
||||
|
||||
if (tos_at_uart_read((uint8_t*)buffer, sizeof(buffer) - 1) != (sizeof(buffer) - 1)) {
|
||||
if (tos_at_uart_read(AT_AGENT, (uint8_t*)buffer, sizeof(buffer) - 1) != (sizeof(buffer) - 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -568,7 +573,8 @@ int esp8266_tencent_firmware_sal_init(hal_uart_port_t uart_port)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (tos_at_init(uart_port, esp8266_tencent_firmware_at_event,
|
||||
if (tos_at_init(AT_AGENT, "esp8266_tf_at", esp8266_tf_at_parse_task_stk,
|
||||
uart_port, esp8266_tencent_firmware_at_event,
|
||||
sizeof(esp8266_tencent_firmware_at_event) /
|
||||
sizeof(esp8266_tencent_firmware_at_event[0])) != 0) {
|
||||
return -1;
|
||||
@@ -585,3 +591,9 @@ int esp8266_tencent_firmware_sal_init(hal_uart_port_t uart_port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int esp8266_tencent_firmware_sal_deinit()
|
||||
{
|
||||
tos_at_deinit(AT_AGENT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ typedef enum sal_send_mode {
|
||||
} sal_send_mode_t;
|
||||
|
||||
int esp8266_tencent_firmware_sal_init(hal_uart_port_t uart_port);
|
||||
int esp8266_tencent_firmware_sal_deinit(void);
|
||||
int esp8266_tencent_firmware_join_ap(const char *ssid, const char *pwd);
|
||||
|
||||
#endif /* __ESP8266_TENCENT_FIRMWARE_H__ */
|
||||
|
Reference in New Issue
Block a user