From 57c1824affca858023c65c84e188ea7dc6c0a5f2 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 12 Aug 2020 01:49:15 +0200 Subject: ussd service implemented urc --- fw/esp32/components/eos/cell_sms.c | 2 +- fw/esp32/components/eos/cell_ussd.c | 66 +++++++++++++++++++++++++++++++++- fw/esp32/components/eos/cell_voice.c | 4 --- fw/esp32/components/eos/include/cell.h | 3 +- 4 files changed, 68 insertions(+), 7 deletions(-) (limited to 'fw/esp32') diff --git a/fw/esp32/components/eos/cell_sms.c b/fw/esp32/components/eos/cell_sms.c index f9e7285..92c016e 100644 --- a/fw/esp32/components/eos/cell_sms.c +++ b/fw/esp32/components/eos/cell_sms.c @@ -243,7 +243,7 @@ void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t s static void sms_received_handler(char *urc, regmatch_t m[]) { int ref, rv; - sscanf(urc + m[1].rm_so, "%6d", &ref); + sscanf(urc + m[1].rm_so, "%d", &ref); snprintf(cmd, sizeof(cmd), "AT+CMGR=%d\r", ref); at_cmd(cmd); diff --git a/fw/esp32/components/eos/cell_ussd.c b/fw/esp32/components/eos/cell_ussd.c index 3113886..a4cf32b 100644 --- a/fw/esp32/components/eos/cell_ussd.c +++ b/fw/esp32/components/eos/cell_ussd.c @@ -1,12 +1,16 @@ #include +#include #include #include #include "eos.h" +#include "net.h" #include "at_cmd.h" #include "cell.h" +static const char *TAG = "EOS USSD"; + static char cmd[256]; static int cmd_len; @@ -30,10 +34,70 @@ void eos_cell_ussd_handler(unsigned char mtype, unsigned char *buffer, uint16_t rv = at_expect("^OK", "^ERROR", 1000); eos_modem_give(); + break; + + case EOS_CELL_MTYPE_USSD_CANCEL: + rv = eos_modem_take(1000); + if (rv) return; + at_cmd("AT+CUSD=2\r"); + rv = at_expect("^OK", "^ERROR", 1000); + + eos_modem_give(); break; } } -void eos_cell_ussd_init(void) {} \ No newline at end of file +static void ussd_reply_handler(char *urc, regmatch_t m[]) { + int rep, rv; + unsigned char *buf; + uint16_t len; + char *_buf; + size_t _len; + regex_t re; + regmatch_t match[2]; + + rv = regcomp(&re, ".*(\",[0-9]+)$", REG_EXTENDED); + if (rv) return; + + sscanf(urc + m[1].rm_so, "%1d", &rep); + + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_USSD | EOS_CELL_MTYPE_USSD_REPLY; + buf[1] = rep; + len = 2; + + rv = EOS_OK; + _buf = (char *)buf + len; + strcpy(_buf, urc + m[2].rm_so); + do { + if (regexec(&re, _buf, 2, match, 0) == 0) { + ESP_LOGI(TAG, "MATCH:%ld %s", match[1].rm_so, _buf); + _buf[match[1].rm_so] = '\0'; + _len = strlen(_buf); + len += _len + 1; + break; + } else { + _len = strlen(_buf); + _buf[_len] = '\n'; + _buf += _len + 1; + len += _len + 1; + } + rv = eos_modem_readln(_buf, EOS_NET_SIZE_BUF - len, 1000); + if (rv) break; + } while (1); + + if (rv) { + ESP_LOGE(TAG, "USSD error"); + eos_net_free(buf); + } else { + eos_net_send(EOS_NET_MTYPE_CELL, buf, len); + } + regfree(&re); +} + +void eos_cell_ussd_init(void) { + at_urc_insert("\\+CUSD: ([0-9]),\"(.*)", ussd_reply_handler, REG_EXTENDED); + +} \ No newline at end of file diff --git a/fw/esp32/components/eos/cell_voice.c b/fw/esp32/components/eos/cell_voice.c index 499458f..d28c38c 100644 --- a/fw/esp32/components/eos/cell_voice.c +++ b/fw/esp32/components/eos/cell_voice.c @@ -119,10 +119,6 @@ static void call_missed_handler(char *urc, regmatch_t m[]) { eos_net_send(EOS_NET_MTYPE_CELL, buf, len); } -// MISSED_CALL: 02:18AM +381641733314 -// +CLIP: "+381641733314",145,,,,0 -// "+CLIP: \"(\\+?[0-9]+)\"" - void eos_cell_voice_init(void) { at_urc_insert("^RING", ring_handler, REG_EXTENDED); at_urc_insert("^VOICE CALL: BEGIN", call_begin_handler, REG_EXTENDED); diff --git a/fw/esp32/components/eos/include/cell.h b/fw/esp32/components/eos/include/cell.h index 65b4b1a..89f3372 100644 --- a/fw/esp32/components/eos/include/cell.h +++ b/fw/esp32/components/eos/include/cell.h @@ -34,6 +34,7 @@ #define EOS_CELL_MTYPE_USSD_REQUEST 1 #define EOS_CELL_MTYPE_USSD_REPLY 2 +#define EOS_CELL_MTYPE_USSD_CANCEL 3 #define EOS_CELL_MTYPE_DATA_CONFIGURE 1 #define EOS_CELL_MTYPE_DATA_CONNECT 2 @@ -49,7 +50,7 @@ #define EOS_CELL_UART_MODE_RELAY 3 #define EOS_CELL_UART_MODE_UNDEF 0xff -#define EOS_CELL_UART_SIZE_BUF 128 +#define EOS_CELL_UART_SIZE_BUF 1024 void eos_cell_init(void); -- cgit v1.2.3