diff --git a/devices/ec20/ec20.c b/devices/ec20/ec20.c index b5bb7e9c..b8ec6112 100644 --- a/devices/ec20/ec20.c +++ b/devices/ec20/ec20.c @@ -274,6 +274,48 @@ int ec20_send(int id, const void *buf, size_t len) return len; } +int ec20_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout) +{ + return tos_at_channel_read_timed(id, buf, len, timeout); +} + +int ec20_recvfrom(int id, void *buf, size_t len) +{ + return ec20_recvfrom_timeout(id, buf, len, (uint32_t)4000); +} + +int ec20_sendto(int id, char *ip, char *port, const void *buf, size_t len) +{ + at_echo_t echo; + + if (tos_at_global_lock_pend() != 0) + { + return -1; + } + + tos_at_echo_create(&echo, NULL, 0, ">"); + + tos_at_cmd_exec(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len); + + if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) + { + tos_at_global_lock_post(); + return -1; + } + + tos_at_echo_create(&echo, NULL, 0, "SEND OK"); + tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len); + if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) + { + tos_at_global_lock_post(); + return -1; + } + + tos_at_global_lock_post(); + + return len; +} + static void ec20_transparent_mode_exit(void) { tos_at_cmd_exec(NULL, 500, "+++"); @@ -423,6 +465,9 @@ sal_module_t sal_module_ec20 = { .send = ec20_send, .recv_timeout = ec20_recv_timeout, .recv = ec20_recv, + .sendto = ec20_sendto, + .recvfrom = ec20_recvfrom, + .recvfrom_timeout = ec20_recvfrom_timeout, .close = ec20_close, .parse_domain = ec20_parse_domain, };