diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-10-24 19:59:27 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-10-24 19:59:27 +0200 |
commit | b74b1c08b76e448df27b6fff50cca6fed3e4e7a7 (patch) | |
tree | 763f116e381e1b7442dbee63cafa9a14cdd8a7da /fw/esp32/components/eos | |
parent | a5a94dea7043fa6b65693cf0cc11d426d49c637d (diff) |
fixed cell voice and sms driver
Diffstat (limited to 'fw/esp32/components/eos')
-rw-r--r-- | fw/esp32/components/eos/cell_modem.c | 2 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_sms.c | 17 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_voice.c | 54 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/cell.h | 9 |
4 files changed, 50 insertions, 32 deletions
diff --git a/fw/esp32/components/eos/cell_modem.c b/fw/esp32/components/eos/cell_modem.c index ec81111..26be56e 100644 --- a/fw/esp32/components/eos/cell_modem.c +++ b/fw/esp32/components/eos/cell_modem.c @@ -608,7 +608,7 @@ static int ppp_setup(void) { } at_cmd(cmd); - r = at_expect("^OK", "^ERROR", 1000); + r = at_expect("^OK", "^(ERROR|NO CARRIER)", 1000); if (r) { uart_change_mode(uart_mode); xSemaphoreGive(uart_mutex); diff --git a/fw/esp32/components/eos/cell_sms.c b/fw/esp32/components/eos/cell_sms.c index 56e282a..ac710f9 100644 --- a/fw/esp32/components/eos/cell_sms.c +++ b/fw/esp32/components/eos/cell_sms.c @@ -210,20 +210,21 @@ void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t b pdu_len = strlen(pdu); buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG_ITEM; + buf[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_LIST_ITEM; rv = sms_decode(buf + 1, &len); if (rv) { eos_net_free(buf); - } else { - eos_net_send(EOS_NET_MTYPE_CELL, buf, len + 1); + continue; } + + eos_net_send(EOS_NET_MTYPE_CELL, buf, len + 1); } while (1); eos_modem_give(); break; } - case EOS_CELL_MTYPE_SMS_SEND: { + case EOS_CELL_MTYPE_SMS_MSG: { char b[4]; rv = sms_encode(buffer, buf_len); @@ -271,14 +272,14 @@ static void sms_received_handler(char *urc, regmatch_t m[]) { rv = at_expect("^OK", NULL, 1000); buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG_NEW; + buf[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG; rv = sms_decode(buf + 1, &len); if (rv) { eos_net_free(buf); - } else { - len++; - eos_net_send(EOS_NET_MTYPE_CELL, buf, len); + return; } + + eos_net_send(EOS_NET_MTYPE_CELL, buf, len + 1); } void eos_cell_sms_init(void) { diff --git a/fw/esp32/components/eos/cell_voice.c b/fw/esp32/components/eos/cell_voice.c index 89233f0..7a9b823 100644 --- a/fw/esp32/components/eos/cell_voice.c +++ b/fw/esp32/components/eos/cell_voice.c @@ -84,13 +84,43 @@ static void ring_handler(char *urc, regmatch_t m[]) { len = 1; rv = at_expect_match("^\\+CLIP: \"(\\+?[0-9]+)\"", NULL, &ring_buf, match, 2, REG_EXTENDED, 1000); if (!rv) { - ring_buf[match[1].rm_eo] = '\0'; - strcpy((char *)buf + 1, ring_buf + match[1].rm_so); - len += 1 + match[1].rm_eo - match[1].rm_so; + regoff_t num_len; + + num_len = match[1].rm_eo - match[1].rm_so; + if (num_len > EOS_CELL_MAX_DIAL_STR) { + eos_net_free(buf); + return; + } + memcpy(buf + 1, ring_buf + match[1].rm_so, num_len); + len += num_len; } eos_net_send(EOS_NET_MTYPE_CELL, buf, len); } +static void busy_handler(char *urc, regmatch_t m[]) { + unsigned char *buf; + uint16_t len; + + eos_cell_pcm_stop(); + + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_BUSY; + len = 1; + eos_net_send(EOS_NET_MTYPE_CELL, buf, len); +} + +static void miss_handler(char *urc, regmatch_t m[]) { + unsigned char *buf; + uint16_t len; + + eos_cell_pcm_stop(); + + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_MISS; + len = 1; + eos_net_send(EOS_NET_MTYPE_CELL, buf, len); +} + static void call_begin_handler(char *urc, regmatch_t m[]) { unsigned char *buf; @@ -132,23 +162,11 @@ static void call_end_handler(char *urc, regmatch_t m[]) { eos_net_send(EOS_NET_MTYPE_CELL, buf, 5); } -static void call_missed_handler(char *urc, regmatch_t m[]) { - unsigned char *buf; - uint16_t len; - - eos_cell_pcm_stop(); - - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_MISS; - urc[m[1].rm_eo] = '\0'; - strcpy((char *)buf + 1, urc + m[1].rm_so); - len = 2 + m[1].rm_eo - m[1].rm_so; - eos_net_send(EOS_NET_MTYPE_CELL, buf, len); -} - void eos_cell_voice_init(void) { at_urc_insert("^RING", ring_handler, REG_EXTENDED); + at_urc_insert("^BUSY", busy_handler, REG_EXTENDED); + at_urc_insert("^NO CARRIER", miss_handler, REG_EXTENDED); + at_urc_insert("^MISSED.CALL: [^ ]+ (\\+?[0-9]+)$", miss_handler, REG_EXTENDED); at_urc_insert("^VOICE CALL: BEGIN", call_begin_handler, REG_EXTENDED); at_urc_insert("^VOICE CALL: END: ([0-9]{6}$)$", call_end_handler, REG_EXTENDED); - at_urc_insert("^MISSED.CALL: [^ ]+ (\\+?[0-9]+)$", call_missed_handler, REG_EXTENDED); }
\ No newline at end of file diff --git a/fw/esp32/components/eos/include/cell.h b/fw/esp32/components/eos/include/cell.h index 3ed2646..af2dda8 100644 --- a/fw/esp32/components/eos/include/cell.h +++ b/fw/esp32/components/eos/include/cell.h @@ -29,10 +29,9 @@ #define EOS_CELL_MTYPE_VOICE_BUSY 9 #define EOS_CELL_MTYPE_VOICE_ERR 10 -#define EOS_CELL_MTYPE_SMS_LIST 1 -#define EOS_CELL_MTYPE_SMS_SEND 2 -#define EOS_CELL_MTYPE_SMS_MSG_NEW 3 -#define EOS_CELL_MTYPE_SMS_MSG_ITEM 4 +#define EOS_CELL_MTYPE_SMS_MSG 1 +#define EOS_CELL_MTYPE_SMS_LIST 2 +#define EOS_CELL_MTYPE_SMS_LIST_ITEM 3 #define EOS_CELL_MTYPE_USSD_REQUEST 1 #define EOS_CELL_MTYPE_USSD_REPLY 2 @@ -67,7 +66,7 @@ #define EOS_CELL_UART_MODE_RELAY 3 #define EOS_CELL_MAX_USSD_STR 128 -#define EOS_CELL_MAX_DIAL_STR 128 +#define EOS_CELL_MAX_DIAL_STR 16 #define EOS_CELL_UART_SIZE_BUF 1024 |