diff options
Diffstat (limited to 'fw/esp32/components/eos/cell_voice.c')
| -rw-r--r-- | fw/esp32/components/eos/cell_voice.c | 107 |
1 files changed, 65 insertions, 42 deletions
diff --git a/fw/esp32/components/eos/cell_voice.c b/fw/esp32/components/eos/cell_voice.c index 273b402..0ec543b 100644 --- a/fw/esp32/components/eos/cell_voice.c +++ b/fw/esp32/components/eos/cell_voice.c @@ -17,21 +17,26 @@ static const char *TAG = "EOS CELL VOICE"; extern char *at_cmd_buf; -void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t buf_len) { +void eos_cell_voice_handler(unsigned char _mtype, EOSMessage *msg, uint16_t len) { + unsigned char mtype; + unsigned char *buffer = msg->buffer; int rv; + if (len < 1) return; + + mtype = buffer[0] & ~EOS_CELL_MTYPE_MASK; buffer++; - buf_len--; + len--; + switch (mtype) { case EOS_CELL_MTYPE_VOICE_DIAL: { - if (buf_len > EOS_CELL_SIZE_PHNUM) return; + if (len > EOS_CELL_SIZE_PHNUM) break; - buffer[buf_len] = '\0'; - rv = snprintf(at_cmd_buf, AT_SIZE_CMD_BUF, "ATD%s;\r", buffer); - if ((rv < 0) || (rv >= AT_SIZE_CMD_BUF)) return; + rv = snprintf(at_cmd_buf, AT_SIZE_CMD_BUF, "ATD%.*s;\r", len, buffer); + if ((rv < 0) || (rv >= AT_SIZE_CMD_BUF)) break; rv = eos_modem_take(1000); - if (rv) return; + if (rv) break; at_cmd(at_cmd_buf); rv = at_expect("^OK", "^(ERROR|\\+CME ERROR: [0-9]+)", 1000); @@ -43,7 +48,7 @@ void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t case EOS_CELL_MTYPE_VOICE_ANSWER: { rv = eos_modem_take(1000); - if (rv) return; + if (rv) break; at_cmd("ATA\r"); // Response will be picked up by urc handler @@ -57,7 +62,7 @@ void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t eos_cell_pcm_stop(); rv = eos_modem_take(1000); - if (rv) return; + if (rv) break; at_cmd("AT+CHUP\r"); // Response will be picked up by urc handler @@ -67,70 +72,84 @@ void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t } case EOS_CELL_MTYPE_VOICE_PCM: { - eos_cell_pcm_push(buffer, buf_len); + eos_cell_pcm_push(buffer, len); break; } } } static void ring_handler(char *urc, regmatch_t m[]) { - unsigned char *buf; - char *ring_buf; + EOSMessage msg; uint16_t len; + char *buffer; regmatch_t match[2]; int rv = EOS_OK; - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_RING; + eos_net_alloc(&msg); + if (msg.size < EOS_CELL_SIZE_PHNUM + 1) { + eos_net_free(&msg); + return; + } + msg.buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_RING; len = 1; - rv = at_expect_match("^\\+CLIP: \"(\\+?[0-9]+)\"", NULL, &ring_buf, match, 2, REG_EXTENDED, 1000); + rv = at_expect_match("^\\+CLIP: \"(\\+?[0-9]+)\"", NULL, &buffer, match, 2, REG_EXTENDED, 1000); if (!rv) { regoff_t num_len; num_len = match[1].rm_eo - match[1].rm_so; if (num_len > EOS_CELL_SIZE_PHNUM) { - eos_net_free(buf); + eos_net_free(&msg); return; } - memcpy(buf + 1, ring_buf + match[1].rm_so, num_len); + memcpy(msg.buffer + 1, buffer + match[1].rm_so, num_len); len += num_len; } - rv = eos_net_send(EOS_NET_MTYPE_CELL, buf, len); + rv = eos_net_send(EOS_NET_MTYPE_CELL, &msg, len); if (rv) ESP_LOGE(TAG, "NET SEND ERR:%d", rv); } static void busy_handler(char *urc, regmatch_t m[]) { - unsigned char *buf; - uint16_t len; + EOSMessage msg; int rv; eos_cell_pcm_stop(); - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_BUSY; - len = 1; - rv = eos_net_send(EOS_NET_MTYPE_CELL, buf, len); + eos_net_alloc(&msg); + if (msg.size < 1) { + eos_net_free(&msg); + return; + } + msg.buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_BUSY; + rv = eos_net_send(EOS_NET_MTYPE_CELL, &msg, 1); if (rv) ESP_LOGE(TAG, "NET SEND ERR:%d", rv); } static void miss_handler(char *urc, regmatch_t m[]) { - unsigned char *buf; - uint16_t len; + EOSMessage msg; int rv; eos_cell_pcm_stop(); - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_MISS; - len = 1; - rv = eos_net_send(EOS_NET_MTYPE_CELL, buf, len); + eos_net_alloc(&msg); + if (msg.size < 1) { + eos_net_free(&msg); + return; + } + msg.buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_MISS; + rv = eos_net_send(EOS_NET_MTYPE_CELL, &msg, 1); if (rv) ESP_LOGE(TAG, "NET SEND ERR:%d", rv); } static void call_begin_handler(char *urc, regmatch_t m[]) { - unsigned char *buf; + EOSMessage msg; int rv; + eos_net_alloc(&msg); + if (msg.size < 1) { + eos_net_free(&msg); + return; + } + vTaskDelay(100 / portTICK_PERIOD_MS); at_cmd("AT+CECH=0x0000\r"); at_expect("^OK", "^ERROR", 1000); @@ -148,27 +167,31 @@ static void call_begin_handler(char *urc, regmatch_t m[]) { at_expect("^OK", "^ERROR", 1000); */ - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_BEGIN; - rv = eos_net_send(EOS_NET_MTYPE_CELL, buf, 1); + msg.buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_BEGIN; + rv = eos_net_send(EOS_NET_MTYPE_CELL, &msg, 1); if (rv) ESP_LOGE(TAG, "NET SEND ERR:%d", rv); } static void call_end_handler(char *urc, regmatch_t m[]) { - unsigned char *buf; + EOSMessage msg; int duration = 0; int rv; eos_cell_pcm_stop(); + eos_net_alloc(&msg); + if (msg.size < 5) { + eos_net_free(&msg); + return; + } + sscanf(urc + m[1].rm_so, "%6d", &duration); - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_END; - buf[1] = duration >> 24; - buf[2] = duration >> 16; - buf[3] = duration >> 8; - buf[4] = duration; - rv = eos_net_send(EOS_NET_MTYPE_CELL, buf, 5); + msg.buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_END; + msg.buffer[1] = duration >> 24; + msg.buffer[2] = duration >> 16; + msg.buffer[3] = duration >> 8; + msg.buffer[4] = duration; + rv = eos_net_send(EOS_NET_MTYPE_CELL, &msg, 5); if (rv) ESP_LOGE(TAG, "NET SEND ERR:%d", rv); } |
