diff options
Diffstat (limited to 'fw/esp32/components/eos')
-rw-r--r-- | fw/esp32/components/eos/at_cmd.c | 55 | ||||
-rw-r--r-- | fw/esp32/components/eos/bq25895.c | 2 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_data.c | 23 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_modem.c | 171 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_pcm.c | 31 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_sms.c | 2 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_ussd.c | 4 | ||||
-rw-r--r-- | fw/esp32/components/eos/cell_voice.c | 121 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/at_cmd.h | 5 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/cell.h | 66 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/msgq.h | 5 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/net.h | 5 | ||||
-rw-r--r-- | fw/esp32/components/eos/msgq.c | 7 | ||||
-rw-r--r-- | fw/esp32/components/eos/net.c | 30 | ||||
-rw-r--r-- | fw/esp32/components/eos/power.c | 8 | ||||
-rw-r--r-- | fw/esp32/components/eos/sock.c | 5 | ||||
-rwxr-xr-x | fw/esp32/components/eos/wifi.c | 12 |
17 files changed, 347 insertions, 205 deletions
diff --git a/fw/esp32/components/eos/at_cmd.c b/fw/esp32/components/eos/at_cmd.c index 4712ad7..dd2c9ea 100644 --- a/fw/esp32/components/eos/at_cmd.c +++ b/fw/esp32/components/eos/at_cmd.c @@ -3,6 +3,7 @@ #include <freertos/FreeRTOS.h> #include <freertos/semphr.h> +#include <esp_timer.h> #include <esp_log.h> #include "eos.h" @@ -24,7 +25,6 @@ typedef struct ATURCList { } ATURCList; static ATURCList urc_list; -static ATURCItem *urc_curr; static SemaphoreHandle_t mutex; static char at_buf[EOS_CELL_UART_SIZE_BUF]; @@ -39,38 +39,28 @@ void at_init(void) { int at_urc_process(char *urc) { regmatch_t match[AT_SIZE_NMATCH]; at_urc_cb_t cb = NULL; - regmatch_t *m = NULL; + int i; - xSemaphoreTake(mutex, portMAX_DELAY); + if (urc[0] == '\0') return 0; - if (urc_curr == NULL) { - int i; + xSemaphoreTake(mutex, portMAX_DELAY); - for (i=0; i<urc_list.len; i++) { - if (regexec(&urc_list.item[i].re, urc, AT_SIZE_NMATCH, match, 0) == 0) { - urc_curr = &urc_list.item[i]; - m = match; - break; - } + for (i=0; i<urc_list.len; i++) { + if (regexec(&urc_list.item[i].re, urc, AT_SIZE_NMATCH, match, 0) == 0) { + cb = urc_list.item[i].cb; + break; } } - if (urc_curr) cb = urc_curr->cb; xSemaphoreGive(mutex); if (cb) { - int r = cb(urc, m); - - if (r != AT_URC_MORE) { - xSemaphoreTake(mutex, portMAX_DELAY); - urc_curr = NULL; - xSemaphoreGive(mutex); - } - ESP_LOGD(TAG, "URC Processed: %s", urc); + cb(urc, match); + ESP_LOGI(TAG, "URC Processed: %s", urc); return 1; } - ESP_LOGD(TAG, "URC NOT Processed: %s", urc); + ESP_LOGI(TAG, "URC NOT Processed: %d %d %d %d", urc[0], urc[1], urc[0] == '\r', strlen(urc)); return 0; } @@ -108,13 +98,6 @@ int at_urc_delete(char *pattern) { if (i != urc_list.len - 1) memmove(&urc_list.item[i], &urc_list.item[i + 1], (urc_list.len - i - 1) * sizeof(ATURCItem)); urc_list.len--; memset(&urc_list.item[urc_list.len], 0, sizeof(ATURCItem)); - if (urc_curr) { - if (urc_curr == &urc_list.item[i]) { - urc_curr = NULL; - } else if (urc_curr > &urc_list.item[i]) { - urc_curr--; - } - } rv = EOS_OK; break; } @@ -127,7 +110,7 @@ int at_urc_delete(char *pattern) { void at_cmd(char *cmd) { eos_modem_write(cmd, strlen(cmd)); - ESP_LOGD(TAG, "Cmd: %s", cmd); + ESP_LOGI(TAG, "Cmd: %s", cmd); } int at_expect(char *str_ok, char *str_err, uint32_t timeout) { @@ -148,17 +131,15 @@ int at_expect(char *str_ok, char *str_err, uint32_t timeout) { } do { - rv = eos_modem_readln(at_buf, sizeof(at_buf), timeout - e); - ESP_LOGD(TAG, "Expect: %s", at_buf); + rv = eos_modem_readln(at_buf, sizeof(at_buf), timeout ? timeout - e : 0); + ESP_LOGI(TAG, "Expect: %s", at_buf); - if (at_buf[0] != '\0') { - if (!rv && str_ok && (regexec(&re_ok, at_buf, 0, NULL, 0) == 0)) return 1; - if (!rv && str_err && (regexec(&re_err, at_buf, 0, NULL, 0) == 0)) return 0; + if (!rv && str_ok && (regexec(&re_ok, at_buf, 0, NULL, 0) == 0)) return 1; + if (!rv && str_err && (regexec(&re_err, at_buf, 0, NULL, 0) == 0)) return 0; - at_urc_process(at_buf); - } + at_urc_process(at_buf); e = (uint32_t)(esp_timer_get_time() - t_start) / 1000; - if (e > timeout) return EOS_ERR_TIMEOUT; + if (timeout && (e > timeout)) return EOS_ERR_TIMEOUT; } while (1); } diff --git a/fw/esp32/components/eos/bq25895.c b/fw/esp32/components/eos/bq25895.c index 0d1bb8d..4501888 100644 --- a/fw/esp32/components/eos/bq25895.c +++ b/fw/esp32/components/eos/bq25895.c @@ -11,7 +11,7 @@ static const char *TAG = "EOS BQ25895"; void eos_bq25895_set_ilim(void) { uint8_t data = 0; - eos_i2c_write8(BQ25895_ADDR, 0, 0x1c); + eos_i2c_write8(BQ25895_ADDR, 0, 0x26); // input current: 2.0 A eos_i2c_write8(BQ25895_ADDR, 2, 0x28); eos_i2c_write8(BQ25895_ADDR, 7, 0x8d); diff --git a/fw/esp32/components/eos/cell_data.c b/fw/esp32/components/eos/cell_data.c index 6732346..f9a755f 100644 --- a/fw/esp32/components/eos/cell_data.c +++ b/fw/esp32/components/eos/cell_data.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include <esp_log.h> @@ -6,15 +7,25 @@ #include "cell.h" void eos_cell_data_handler(unsigned char mtype, unsigned char *buffer, uint16_t size) { - int rv; - - rv = eos_modem_take(1000); - if (rv) return; + char *apn, *user, *pass; buffer += 1; size -= 1; switch (mtype) { - } + case EOS_CELL_MTYPE_DATA_CONFIGURE: + apn = (char *)buffer; + user = apn + strlen(apn) + 1; + pass = user + strlen(user) + 1; + eos_ppp_set_apn(apn); + eos_ppp_set_auth(user, pass); + break; - eos_modem_give(); + case EOS_CELL_MTYPE_DATA_CONNECT: + eos_ppp_connect(); + break; + + case EOS_CELL_MTYPE_DATA_DISCONNECT: + eos_ppp_disconnect(); + break; + } } diff --git a/fw/esp32/components/eos/cell_modem.c b/fw/esp32/components/eos/cell_modem.c index c6d718f..537bbbe 100644 --- a/fw/esp32/components/eos/cell_modem.c +++ b/fw/esp32/components/eos/cell_modem.c @@ -9,6 +9,7 @@ #include <netif/ppp/pppapi.h> #include <driver/uart.h> #include <driver/gpio.h> +#include <esp_timer.h> #include <esp_sleep.h> #include <esp_log.h> @@ -31,7 +32,7 @@ #define MODEM_ETYPE_INIT 1 #define MODEM_ETYPE_RI 2 -#define AT_CMD_INIT_SIZE 3 +#define AT_CMD_INIT_SIZE 4 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) @@ -41,6 +42,7 @@ static const char *TAG = "EOS MODEM"; static char *at_cmd_init[AT_CMD_INIT_SIZE] = { "AT+CFGRI=1\r", "AT+CSCLK=1\r", + "AT+CLIP=1\r", "AT+CMGF=0\r" }; @@ -54,6 +56,7 @@ static char uart_buf[EOS_CELL_UART_SIZE_BUF]; static size_t uart_buf_len; static uint8_t uart_mode = EOS_CELL_UART_MODE_ATCMD; +static uint8_t _uart_mode = EOS_CELL_UART_MODE_UNDEF; static SemaphoreHandle_t uart_mutex; static char ppp_apn[64]; @@ -90,7 +93,7 @@ static void uart_data_read(uint8_t mode) { do { int _rd = eos_modem_read(uart_buf, MIN(bsize - rd, sizeof(uart_buf)), 100); - pppos_input_tcpip(ppp_handle, (uint8_t *)uart_buf, _rd); + if (ppp_handle) pppos_input_tcpip(ppp_handle, (uint8_t *)uart_buf, _rd); rd += _rd; } while (rd != bsize); break; @@ -104,7 +107,7 @@ static void uart_data_read(uint8_t mode) { buf = eos_net_alloc(); buf[0] = EOS_CELL_MTYPE_UART_DATA; _rd = eos_modem_read(buf + 1, MIN(bsize - rd, EOS_NET_SIZE_BUF - 1), 100); - eos_net_send(EOS_NET_MTYPE_CELL, buf, _rd + 1, 0); + eos_net_send(EOS_NET_MTYPE_CELL, buf, _rd + 1); rd += _rd; } while (rd != bsize); break; @@ -213,7 +216,7 @@ static int modem_atcmd_init(void) { buf = eos_net_alloc(); buf[0] = EOS_CELL_MTYPE_READY; - eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0); + eos_net_send(EOS_NET_MTYPE_CELL, buf, 1); eos_modem_give(); @@ -232,18 +235,18 @@ static void modem_atcmd_read(size_t bsize) { uart_buf_len += _rd; uart_buf[uart_buf_len] = '\0'; while ((ln_end = strchr(uart_curr, '\n'))) { - size_t urc_buf_len = ln_end - uart_buf; + char *_ln_end = ln_end; - if ((ln_end > uart_buf) && (*(ln_end - 1) == '\r')) urc_buf_len--; - memcpy(urc_buf, uart_buf, urc_buf_len); - urc_buf[urc_buf_len] = '\0'; + while ((_ln_end > uart_buf) && (*(_ln_end - 1) == '\r')) _ln_end--; + memcpy(urc_buf, uart_buf, _ln_end - uart_buf); + urc_buf[_ln_end - uart_buf] = '\0'; uart_buf_len -= ln_end - uart_buf + 1; if (uart_buf_len) memmove(uart_buf, ln_end + 1, uart_buf_len); + at_urc_process(urc_buf); + uart_curr = uart_buf; uart_buf[uart_buf_len] = '\0'; - - at_urc_process(urc_buf); } if (uart_buf_len == sizeof(uart_buf) - 1) { uart_buf_len = 0; @@ -253,13 +256,11 @@ static void modem_atcmd_read(size_t bsize) { } while (rd != bsize); } -int modem_urc_init_handler(char *urc, regmatch_t *m) { +static void modem_urc_init_handler(char *urc, regmatch_t m[]) { modem_event_t evt; evt.type = MODEM_ETYPE_INIT; xQueueSend(modem_queue, &evt, portMAX_DELAY); - - return AT_URC_OK; } static void modem_set_mode(uint8_t mode) { @@ -337,13 +338,16 @@ static uint32_t ppp_output_cb(ppp_pcb *pcb, uint8_t *data, uint32_t len, void *c /* PPP status callback */ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) { - // struct netif *pppif = ppp_netif(pcb); - // LWIP_UNUSED_ARG(ctx); + struct netif *pppif = ppp_netif(pcb); + LWIP_UNUSED_ARG(ctx); switch(err_code) { case PPPERR_NONE: { - ESP_LOGE(TAG, "status_cb: Connect"); - break; + ESP_LOGI(TAG, "status_cb: Connect"); + ESP_LOGI(TAG," our_ipaddr = %s\n", ipaddr_ntoa(&pppif->ip_addr)); + ESP_LOGI(TAG," his_ipaddr = %s\n", ipaddr_ntoa(&pppif->gw)); + ESP_LOGI(TAG," netmask = %s\n", ipaddr_ntoa(&pppif->netmask)); + return; } case PPPERR_PARAM: { ESP_LOGE(TAG, "status_cb: Invalid parameter"); @@ -362,7 +366,7 @@ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) { break; } case PPPERR_USER: { - ESP_LOGE(TAG, "status_cb: User interrupt"); + ESP_LOGI(TAG, "status_cb: Disconnect"); break; } case PPPERR_CONNECT: { @@ -398,57 +402,90 @@ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) { break; } } + + xSemaphoreTake(mutex, portMAX_DELAY); + + if (_uart_mode == EOS_CELL_UART_MODE_UNDEF) _uart_mode = EOS_CELL_UART_MODE_ATCMD; + uart_mode = _uart_mode; + _uart_mode = EOS_CELL_UART_MODE_UNDEF; + + modem_set_mode(EOS_CELL_UART_MODE_NONE); + xSemaphoreTake(uart_mutex, portMAX_DELAY); + + ppp_handle = NULL; + modem_set_mode(uart_mode); + + xSemaphoreGive(uart_mutex); + xSemaphoreGive(mutex); + + ppp_free(pcb); } -static int ppp_pause(uint32_t timeout, uint8_t retries) { +static int ppp_pause(uint32_t timeout) { int done = 0; int len = 0; int rv = EOS_OK; + int start = 0; + int r; + char *ok_str = NULL; uint64_t t_start; + uint32_t dt, _dt; - timeout += 1000; - xSemaphoreTake(ppp_mutex, portMAX_DELAY); - eos_modem_flush(); - vTaskDelay(1000 / portTICK_PERIOD_MS); modem_set_mode(EOS_CELL_UART_MODE_NONE); - xSemaphoreTake(uart_mutex, portMAX_DELAY); - at_cmd("+++"); + t_start = esp_timer_get_time(); + r = xSemaphoreTake(uart_mutex, timeout ? timeout / portTICK_PERIOD_MS : portMAX_DELAY); + if (r == pdFALSE) return EOS_ERR_TIMEOUT; + if (timeout) { + dt = ((esp_timer_get_time() - t_start) / 1000); + if (dt >= timeout) { + modem_set_mode(EOS_CELL_UART_MODE_PPP); + xSemaphoreGive(uart_mutex); + return EOS_ERR_TIMEOUT; + } + } + r = xSemaphoreTake(ppp_mutex, timeout ? (timeout - dt) / portTICK_PERIOD_MS : portMAX_DELAY); + if (r == pdFALSE) { + modem_set_mode(EOS_CELL_UART_MODE_PPP); + xSemaphoreGive(uart_mutex); + return EOS_ERR_TIMEOUT; + } + eos_modem_flush(); + _dt = ((esp_timer_get_time() - t_start) / 1000); do { len = eos_modem_read(uart_buf + uart_buf_len, sizeof(uart_buf) - uart_buf_len, 10); - if (len > 0) { + dt = ((esp_timer_get_time() - t_start) / 1000); + if ((dt - _dt) >= 1000) { + _dt =dt; + at_cmd("+++"); + start = 1; + } + if (start && (len > 0)) { if (uart_buf_len > 5) { ok_str = memstr(uart_buf + uart_buf_len - 5, len + 5, "\r\nOK\r\n"); } else { - ok_str = memstr(uart_buf, len + uart_buf_len, "\r\nOK\r\n"); + ok_str = memstr(uart_buf, uart_buf_len + len, "\r\nOK\r\n"); } uart_buf_len += len; } if (ok_str) { - pppos_input_tcpip(ppp_handle, (uint8_t *)uart_buf, ok_str - uart_buf); + if (ppp_handle) pppos_input_tcpip(ppp_handle, (uint8_t *)uart_buf, ok_str - uart_buf); ok_str += 6; uart_buf_len -= ok_str - uart_buf; if (uart_buf_len) memmove(uart_buf, ok_str, uart_buf_len); done = 1; } else if (uart_buf_len == sizeof(uart_buf)) { - pppos_input_tcpip(ppp_handle, (uint8_t *)uart_buf, sizeof(uart_buf) / 2); + if (ppp_handle) pppos_input_tcpip(ppp_handle, (uint8_t *)uart_buf, sizeof(uart_buf) / 2); memcpy(uart_buf, uart_buf + sizeof(uart_buf) / 2, sizeof(uart_buf) / 2); uart_buf_len = sizeof(uart_buf) / 2; } - if (timeout && !done && ((uint32_t)((esp_timer_get_time() - t_start) / 1000) > timeout)) { - if (!retries) { - modem_set_mode(EOS_CELL_UART_MODE_PPP); - xSemaphoreGive(uart_mutex); - xSemaphoreGive(ppp_mutex); - rv = EOS_ERR_TIMEOUT; - done = 1; - } else { - retries--; - at_cmd("+++"); - t_start = esp_timer_get_time(); - } + if (!done && timeout && (dt >= timeout)) { + modem_set_mode(EOS_CELL_UART_MODE_PPP); + xSemaphoreGive(uart_mutex); + xSemaphoreGive(ppp_mutex); + return EOS_ERR_TIMEOUT; } } while (!done); @@ -493,7 +530,7 @@ static int ppp_setup(void) { } at_cmd("AT+CGDATA=\"PPP\",1\r"); - r = at_expect("^CONNECT", "^(ERROR|\\+CME ERROR|NO CARRIER)", 1000); + r = at_expect("^CONNECT", "^NO CARRIER", 1000); if (r <= 0) { modem_set_mode(uart_mode); xSemaphoreGive(uart_mutex); @@ -502,9 +539,9 @@ static int ppp_setup(void) { ppp_handle = pppapi_pppos_create(&ppp_netif, ppp_output_cb, ppp_status_cb, NULL); ppp_set_usepeerdns(ppp_handle, 1); - pppapi_set_default(ppp_handle); - pppapi_set_auth(ppp_handle, PPPAUTHTYPE_PAP, ppp_user, ppp_pass); - pppapi_connect(ppp_handle, 0); + ppp_set_default(ppp_handle); + ppp_set_auth(ppp_handle, PPPAUTHTYPE_ANY, ppp_user, ppp_pass); + ppp_connect(ppp_handle, 0); modem_set_mode(EOS_CELL_UART_MODE_PPP); xSemaphoreGive(uart_mutex); @@ -512,24 +549,6 @@ static int ppp_setup(void) { return EOS_OK; } -static int ppp_disconnect(void) { - int rv; - - pppapi_close(ppp_handle, 0); - - rv = ppp_pause(1000, 2); - if (rv) return rv; - - at_cmd("ATH\r"); - at_expect("^OK", NULL, 1000); - - xSemaphoreGive(uart_mutex); - xSemaphoreGive(ppp_mutex); - ppp_handle = NULL; - - return EOS_OK; -} - void eos_modem_init(void) { /* Configure parameters of an UART driver, * communication pins and install the driver */ @@ -581,6 +600,9 @@ void eos_modem_init(void) { at_urc_insert("^PB DONE", modem_urc_init_handler, REG_EXTENDED); eos_modem_set_mode(EOS_CELL_UART_MODE_ATCMD); + eos_cell_voice_init(); + eos_cell_sms_init(); + eos_cell_ussd_init(); ESP_LOGI(TAG, "INIT"); } @@ -632,7 +654,7 @@ int eos_modem_readln(char *buf, size_t buf_size, uint32_t timeout) { uart_buf_len += buf_len; } - if ((ln_end > buf) && (*(ln_end - 1) == '\r')) ln_end--; + while ((ln_end > buf) && (*(ln_end - 1) == '\r')) ln_end--; *ln_end = '\0'; return EOS_OK; @@ -653,8 +675,10 @@ int eos_modem_set_mode(uint8_t mode) { xSemaphoreTake(mutex, portMAX_DELAY); if (mode != uart_mode) { - if (uart_mode == EOS_CELL_UART_MODE_PPP) rv = ppp_disconnect(); - if (!rv) { + if ((uart_mode == EOS_CELL_UART_MODE_PPP) && ppp_handle) { + _uart_mode = mode; + pppapi_close(ppp_handle, 0); + } else { if (mode == EOS_CELL_UART_MODE_PPP) { rv = ppp_setup(); } else { @@ -672,8 +696,9 @@ int eos_modem_take(uint32_t timeout) { int rv = EOS_OK; xSemaphoreTake(mutex, portMAX_DELAY); + if (uart_mode == EOS_CELL_UART_MODE_PPP) { - rv = ppp_pause(timeout, 0); + rv = ppp_pause(timeout); } else { int r; @@ -754,14 +779,6 @@ int eos_ppp_connect(void) { return eos_modem_set_mode(EOS_CELL_UART_MODE_PPP); } -int eos_ppp_disconnect(void) { - int rv = eos_modem_set_mode(EOS_CELL_UART_MODE_ATCMD); - - xSemaphoreTake(mutex, portMAX_DELAY); - memset(ppp_apn, 0, sizeof(ppp_apn)); - memset(ppp_user, 0, sizeof(ppp_user)); - memset(ppp_pass, 0, sizeof(ppp_pass)); - xSemaphoreGive(mutex); - - return rv; +void eos_ppp_disconnect(void) { + eos_modem_set_mode(EOS_CELL_UART_MODE_ATCMD); }
\ No newline at end of file diff --git a/fw/esp32/components/eos/cell_pcm.c b/fw/esp32/components/eos/cell_pcm.c index 5c59643..f8d41b8 100644 --- a/fw/esp32/components/eos/cell_pcm.c +++ b/fw/esp32/components/eos/cell_pcm.c @@ -33,6 +33,7 @@ static unsigned char *pcm_bufq_array[PCM_SIZE_BUFQ]; static EOSMsgQ pcm_evt_q; static EOSMsgItem pcm_evtq_array[PCM_SIZE_BUFQ]; static char pcm_hold_tx; +static char pcm_active = 0; static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1}; @@ -62,7 +63,7 @@ static void i2s_event_task(void *pvParameters) { buf = eos_net_alloc(); buf[0] = EOS_CELL_MTYPE_PCM_DATA; bytes_r = eos_cell_pcm_read(buf + 1, PCM_MIC_WM); - eos_net_send(EOS_NET_MTYPE_CELL, buf, bytes_r + 1, 0); + eos_net_send(EOS_NET_MTYPE_CELL, buf, bytes_r + 1); } else { hold_cnt--; if (hold_buf == NULL) { @@ -71,7 +72,7 @@ static void i2s_event_task(void *pvParameters) { } if (1 + hold_bytes_r + PCM_MIC_WM <= EOS_NET_SIZE_BUF) hold_bytes_r += eos_cell_pcm_read(hold_buf + 1 + hold_bytes_r, PCM_MIC_WM); if (hold_cnt == 0) { - eos_net_send(EOS_NET_MTYPE_CELL, hold_buf, hold_bytes_r + 1, 0); + eos_net_send(EOS_NET_MTYPE_CELL, hold_buf, hold_bytes_r + 1); hold_bytes_r = 0; hold_buf = NULL; } @@ -80,7 +81,7 @@ static void i2s_event_task(void *pvParameters) { buf = NULL; xSemaphoreTake(mutex, portMAX_DELAY); if (pcm_hold_tx && (eos_msgq_len(&pcm_evt_q) == PCM_HOLD_CNT_TX)) pcm_hold_tx = 0; - if (!pcm_hold_tx) eos_msgq_pop(&pcm_evt_q, &_type, &buf, &bytes_e, NULL); + if (!pcm_hold_tx) eos_msgq_pop(&pcm_evt_q, &_type, &buf, &bytes_e); xSemaphoreGive(mutex); if (buf) { @@ -200,11 +201,15 @@ int eos_cell_pcm_push(unsigned char *data, size_t size) { if (size > PCM_MIC_WM) return EOS_ERR; xSemaphoreTake(mutex, portMAX_DELAY); + if (!pcm_active) { + xSemaphoreGive(mutex); + return EOS_ERR; + } if (pcm_hold_tx && (eos_msgq_len(&pcm_evt_q) == PCM_HOLD_CNT_TX)) { unsigned char _type; uint16_t _len; - eos_msgq_pop(&pcm_evt_q, &_type, &buf, &_len, NULL); + eos_msgq_pop(&pcm_evt_q, &_type, &buf, &_len); } else { buf = eos_bufq_pop(&pcm_buf_q); } @@ -221,7 +226,7 @@ int eos_cell_pcm_push(unsigned char *data, size_t size) { } xSemaphoreTake(mutex, portMAX_DELAY); - rv = eos_msgq_push(&pcm_evt_q, PCM_ETYPE_WRITE, buf, esize, 0); + rv = eos_msgq_push(&pcm_evt_q, PCM_ETYPE_WRITE, buf, esize); if (rv) eos_bufq_push(&pcm_buf_q, buf); xSemaphoreGive(mutex); @@ -232,18 +237,23 @@ void eos_cell_pcm_start(void) { i2s_event_t evt; xSemaphoreTake(mutex, portMAX_DELAY); + if (pcm_active) { + xSemaphoreGive(mutex); + return; + } while (1) { unsigned char _type; unsigned char *buf; uint16_t len; - eos_msgq_pop(&pcm_evt_q, &_type, &buf, &len, NULL); + eos_msgq_pop(&pcm_evt_q, &_type, &buf, &len); if (buf) { eos_bufq_push(&pcm_buf_q, buf); } else { break; } } + pcm_active = 1; pcm_hold_tx = 1; xSemaphoreGive(mutex); @@ -254,5 +264,12 @@ void eos_cell_pcm_start(void) { } void eos_cell_pcm_stop(void) { - i2s_stop(I2S_NUM_0); + char active; + + xSemaphoreTake(mutex, portMAX_DELAY); + active = pcm_active; + pcm_active = 0; + xSemaphoreGive(mutex); + + if (active) i2s_stop(I2S_NUM_0); } diff --git a/fw/esp32/components/eos/cell_sms.c b/fw/esp32/components/eos/cell_sms.c index 05acc50..ef8a8c9 100644 --- a/fw/esp32/components/eos/cell_sms.c +++ b/fw/esp32/components/eos/cell_sms.c @@ -20,3 +20,5 @@ void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t s eos_modem_give(); } + +void eos_cell_sms_init(void) {} diff --git a/fw/esp32/components/eos/cell_ussd.c b/fw/esp32/components/eos/cell_ussd.c index 2daa00f..3f5ea3b 100644 --- a/fw/esp32/components/eos/cell_ussd.c +++ b/fw/esp32/components/eos/cell_ussd.c @@ -3,9 +3,9 @@ #include <esp_log.h> +#include "eos.h" #include "at_cmd.h" #include "cell.h" -#include "gsm.h" static char cmd[256]; @@ -25,6 +25,7 @@ void eos_cell_ussd_handler(unsigned char mtype, unsigned char *buffer, uint16_t cmd_len = snprintf(cmd, sizeof(cmd), "AT+CUSD=1,\"%s\",15\r", buffer); if ((cmd_len < 0) || (cmd_len >= sizeof(cmd))) return; at_cmd(cmd); + rv = at_expect("^OK", "^ERROR", 1000); break; } @@ -32,3 +33,4 @@ void eos_cell_ussd_handler(unsigned char mtype, unsigned char *buffer, uint16_t eos_modem_give(); } +void eos_cell_ussd_init(void) {}
\ 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 3f6a2a5..8162690 100644 --- a/fw/esp32/components/eos/cell_voice.c +++ b/fw/esp32/components/eos/cell_voice.c @@ -1,12 +1,22 @@ #include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <esp_timer.h> #include <esp_log.h> #include "eos.h" +#include "net.h" +#include "at_cmd.h" #include "cell.h" +static const char *TAG = "EOS VOICE"; + +static char cmd[256]; +static char ring_buf[256]; + void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t size) { - int rv; + int cmd_len, rv; rv = eos_modem_take(1000); if (rv) return; @@ -14,7 +24,116 @@ void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t buffer += 1; size -= 1; switch (mtype) { + case EOS_CELL_MTYPE_VOICE_DIAL: + if (size == 0) return; + + buffer[size] = '\0'; + cmd_len = snprintf(cmd, sizeof(cmd), "ATD%s;\r", buffer); + if ((cmd_len < 0) || (cmd_len >= sizeof(cmd))) return; + at_cmd(cmd); + rv = at_expect("^OK", "^ERROR", 1000); + eos_cell_pcm_start(); + break; + + case EOS_CELL_MTYPE_VOICE_ANSWER: + at_cmd("ATA\r"); + rv = at_expect("^OK", "^ERROR", 1000); + eos_cell_pcm_start(); + break; + + case EOS_CELL_MTYPE_VOICE_HANGUP: + eos_cell_pcm_stop(); + at_cmd("AT+CHUP\r"); + rv = at_expect("^OK", "^ERROR", 1000); + break; } eos_modem_give(); } + +static void ring_handler(char *urc, regmatch_t m[]) { + unsigned char *buf; + uint16_t len; + uint32_t timeout = 1000, e = 0; + uint64_t t_start = esp_timer_get_time(); + int rv = EOS_OK; + + ring_buf[0] = '\0'; + while (ring_buf[0] == '\0') { + rv = eos_modem_readln(ring_buf, sizeof(ring_buf), timeout - e); + if (rv) break; + + e = (uint32_t)(esp_timer_get_time() - t_start) / 1000; + if (timeout && (e > timeout)) { + rv = EOS_ERR_TIMEOUT; + break; + } + } + + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_RING; + len = 1; + if (!rv) { + regex_t re; + regmatch_t match[2]; + + regcomp(&re, "^\\+CLIP: \"(\\+?[0-9]+)\"", REG_EXTENDED); + if (regexec(&re, ring_buf, 2, match, 0) == 0) { + 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; + } + } + eos_net_send(EOS_NET_MTYPE_CELL, buf, len); +} + +static void call_begin_handler(char *urc, regmatch_t m[]) { + unsigned char *buf; + + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_BEGIN; + eos_net_send(EOS_NET_MTYPE_CELL, buf, 1); +} + +static void call_end_handler(char *urc, regmatch_t m[]) { + unsigned char *buf; + int duration = 0; + + eos_cell_pcm_stop(); + + 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; + 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; + int duration = 0; + + eos_cell_pcm_stop(); + + sscanf(urc + m[1].rm_so, "%6d", &duration); + buf = eos_net_alloc(); + buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_MISSED; + 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); +} + +// 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); + 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/at_cmd.h b/fw/esp32/components/eos/include/at_cmd.h index 615a1c1..2fdd159 100644 --- a/fw/esp32/components/eos/include/at_cmd.h +++ b/fw/esp32/components/eos/include/at_cmd.h @@ -7,10 +7,7 @@ #define AT_SIZE_URC_LIST 16 -#define AT_URC_OK 0 -#define AT_URC_MORE 1 - -typedef int (*at_urc_cb_t) (char *, regmatch_t[]); +typedef void (*at_urc_cb_t) (char *, regmatch_t[]); void at_init(void); int at_urc_process(char *urc); diff --git a/fw/esp32/components/eos/include/cell.h b/fw/esp32/components/eos/include/cell.h index 3bf6b32..abba977 100644 --- a/fw/esp32/components/eos/include/cell.h +++ b/fw/esp32/components/eos/include/cell.h @@ -1,38 +1,44 @@ #include <sys/types.h> #include <stdint.h> -#define EOS_CELL_MTYPE_DEV 0x00 -#define EOS_CELL_MTYPE_VOICE 0x10 -#define EOS_CELL_MTYPE_SMS 0x20 -#define EOS_CELL_MTYPE_CBS 0x30 -#define EOS_CELL_MTYPE_USSD 0x40 -#define EOS_CELL_MTYPE_DATA 0x70 +#define EOS_CELL_MTYPE_DEV 0x00 +#define EOS_CELL_MTYPE_VOICE 0x10 +#define EOS_CELL_MTYPE_SMS 0x20 +#define EOS_CELL_MTYPE_CBS 0x30 +#define EOS_CELL_MTYPE_USSD 0x40 +#define EOS_CELL_MTYPE_DATA 0x70 -#define EOS_CELL_MTYPE_MASK 0xf0 -#define EOS_CELL_MAX_MTYPE 8 +#define EOS_CELL_MTYPE_MASK 0xf0 +#define EOS_CELL_MAX_MTYPE 8 -#define EOS_CELL_MTYPE_READY 0 -#define EOS_CELL_MTYPE_UART_DATA 1 -#define EOS_CELL_MTYPE_UART_TAKE 2 -#define EOS_CELL_MTYPE_UART_GIVE 3 -#define EOS_CELL_MTYPE_PCM_DATA 4 -#define EOS_CELL_MTYPE_PCM_START 5 -#define EOS_CELL_MTYPE_PCM_STOP 6 +#define EOS_CELL_MTYPE_READY 0 +#define EOS_CELL_MTYPE_UART_DATA 1 +#define EOS_CELL_MTYPE_UART_TAKE 2 +#define EOS_CELL_MTYPE_UART_GIVE 3 +#define EOS_CELL_MTYPE_PCM_DATA 4 +#define EOS_CELL_MTYPE_PCM_START 5 +#define EOS_CELL_MTYPE_PCM_STOP 6 -#define EOS_CELL_MTYPE_VOICE_DIAL 1 -#define EOS_CELL_MTYPE_VOICE_RING 2 -#define EOS_CELL_MTYPE_VOICE_ANSWER 3 -#define EOS_CELL_MTYPE_VOICE_HANGUP 4 -#define EOS_CELL_MTYPE_VOICE_BEGIN 5 -#define EOS_CELL_MTYPE_VOICE_END 6 +#define EOS_CELL_MTYPE_VOICE_DIAL 1 +#define EOS_CELL_MTYPE_VOICE_RING 2 +#define EOS_CELL_MTYPE_VOICE_ANSWER 3 +#define EOS_CELL_MTYPE_VOICE_HANGUP 4 +#define EOS_CELL_MTYPE_VOICE_BEGIN 5 +#define EOS_CELL_MTYPE_VOICE_END 6 +#define EOS_CELL_MTYPE_VOICE_MISSED 7 -#define EOS_CELL_MTYPE_USSD_REQUEST 1 -#define EOS_CELL_MTYPE_USSD_REPLY 2 +#define EOS_CELL_MTYPE_USSD_REQUEST 1 +#define EOS_CELL_MTYPE_USSD_REPLY 2 -#define EOS_CELL_UART_MODE_NONE 0 -#define EOS_CELL_UART_MODE_ATCMD 1 -#define EOS_CELL_UART_MODE_PPP 2 -#define EOS_CELL_UART_MODE_RELAY 3 +#define EOS_CELL_MTYPE_DATA_CONFIGURE 1 +#define EOS_CELL_MTYPE_DATA_CONNECT 2 +#define EOS_CELL_MTYPE_DATA_DISCONNECT 3 + +#define EOS_CELL_UART_MODE_NONE 0 +#define EOS_CELL_UART_MODE_ATCMD 1 +#define EOS_CELL_UART_MODE_PPP 2 +#define EOS_CELL_UART_MODE_RELAY 3 +#define EOS_CELL_UART_MODE_UNDEF 0xff #define EOS_CELL_UART_SIZE_BUF 128 @@ -54,7 +60,7 @@ void eos_modem_wake(uint8_t source, uint8_t mode); void eos_ppp_set_apn(char *apn); void eos_ppp_set_auth(char *user, char *pass); int eos_ppp_connect(void); -int eos_ppp_disconnect(void); +void eos_ppp_disconnect(void); void eos_cell_pcm_init(void); ssize_t eos_cell_pcm_read(unsigned char *data, size_t size); @@ -66,3 +72,7 @@ void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t size); void eos_cell_ussd_handler(unsigned char mtype, unsigned char *buffer, uint16_t size); void eos_cell_data_handler(unsigned char mtype, unsigned char *buffer, uint16_t size); + +void eos_cell_voice_init(void); +void eos_cell_sms_init(void); +void eos_cell_ussd_init(void); diff --git a/fw/esp32/components/eos/include/msgq.h b/fw/esp32/components/eos/include/msgq.h index 86bb067..bbfe041 100644 --- a/fw/esp32/components/eos/include/msgq.h +++ b/fw/esp32/components/eos/include/msgq.h @@ -4,7 +4,6 @@ typedef struct EOSMsgItem { unsigned char type; unsigned char *buffer; uint16_t len; - uint8_t flags; } EOSMsgItem; typedef struct EOSMsgQ { @@ -15,8 +14,8 @@ typedef struct EOSMsgQ { } EOSMsgQ; void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size); -int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len, uint8_t flags); -void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len, uint8_t *flags); +int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len); +void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len); uint8_t eos_msgq_len(EOSMsgQ *msgq); typedef struct EOSBufQ { diff --git a/fw/esp32/components/eos/include/net.h b/fw/esp32/components/eos/include/net.h index 54bad6d..f71d07d 100644 --- a/fw/esp32/components/eos/include/net.h +++ b/fw/esp32/components/eos/include/net.h @@ -19,16 +19,13 @@ #define EOS_NET_SIZE_BUFQ 4 #define EOS_NET_SIZE_SNDQ 4 -#define EOS_NET_FLAG_BFREE 0x1 -#define EOS_NET_FLAG_BCOPY 0x2 - typedef void (*eos_net_fptr_t) (unsigned char, unsigned char *, uint16_t); void eos_net_init(void); unsigned char *eos_net_alloc(void); void eos_net_free(unsigned char *buf); -int eos_net_send(unsigned char mtype, unsigned char *buffer, uint16_t len, uint8_t flags); +int eos_net_send(unsigned char mtype, unsigned char *buffer, uint16_t len); void eos_net_set_handler(unsigned char mtype, eos_net_fptr_t handler); void eos_net_sleep_done(uint8_t mode); void eos_net_wake(uint8_t source, uint8_t mode); diff --git a/fw/esp32/components/eos/msgq.c b/fw/esp32/components/eos/msgq.c index c704399..c200f7c 100644 --- a/fw/esp32/components/eos/msgq.c +++ b/fw/esp32/components/eos/msgq.c @@ -12,30 +12,27 @@ void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size) { msgq->array = array; } -int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len, uint8_t flags) { +int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len) { if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_FULL; uint8_t idx = IDX_MASK(msgq->idx_w, msgq->size); msgq->array[idx].type = type; msgq->array[idx].buffer = buffer; msgq->array[idx].len = len; - msgq->array[idx].flags = flags; msgq->idx_w++; return EOS_OK; } -void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len, uint8_t *flags) { +void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len) { if (msgq->idx_r == msgq->idx_w) { *type = 0; *buffer = NULL; *len = 0; - if (flags) *flags = 0; } else { uint8_t idx = IDX_MASK(msgq->idx_r, msgq->size); *type = msgq->array[idx].type; *buffer = msgq->array[idx].buffer; *len = msgq->array[idx].len; - if (flags) *flags = msgq->array[idx].flags; msgq->idx_r++; } } diff --git a/fw/esp32/components/eos/net.c b/fw/esp32/components/eos/net.c index 9a4a024..59b0c4e 100644 --- a/fw/esp32/components/eos/net.c +++ b/fw/esp32/components/eos/net.c @@ -62,7 +62,6 @@ static void net_xchg_task(void *pvParameters) { unsigned char mtype = 0; unsigned char *buffer; uint16_t len; - uint8_t flags; unsigned char *buf_send = heap_caps_malloc(SPI_SIZE_BUF, MALLOC_CAP_DMA); unsigned char *buf_recv = heap_caps_malloc(SPI_SIZE_BUF, MALLOC_CAP_DMA); esp_err_t ret; @@ -104,19 +103,15 @@ static void net_xchg_task(void *pvParameters) { if (!repeat) { xSemaphoreTake(mutex, portMAX_DELAY); - eos_msgq_pop(&net_send_q, &mtype, &buffer, &len, &flags); + eos_msgq_pop(&net_send_q, &mtype, &buffer, &len); if (mtype) { buf_send[0] = mtype; buf_send[1] = len >> 8; buf_send[2] = len & 0xFF; if (buffer) { memcpy(buf_send + 3, buffer, len); - if (flags & EOS_NET_FLAG_BFREE) { - free(buffer); - } else { - eos_bufq_push(&net_buf_q, buffer); - xSemaphoreGive(semaph); - } + eos_bufq_push(&net_buf_q, buffer); + xSemaphoreGive(semaph); } } else { gpio_set_level(SPI_GPIO_RTS, 0); @@ -133,7 +128,7 @@ static void net_xchg_task(void *pvParameters) { buf_recv[1] = 0; buf_recv[2] = 0; spi_slave_transmit(VSPI_HOST, &spi_tr, portMAX_DELAY); - ESP_LOGD(TAG, "RECV:%d", buf_recv[0]); + // ESP_LOGI(TAG, "RECV:%d", buf_recv[0]); if (wake) { eos_power_net_ready(); @@ -174,7 +169,7 @@ static void net_xchg_task(void *pvParameters) { mtype &= ~EOS_NET_MTYPE_FLAG_ONEW; if (buf_send[0]) repeat = 1; } - if (mtype <= EOS_NET_MAX_MTYPE) { + if ((mtype <= EOS_NET_MAX_MTYPE) && (len <= EOS_NET_SIZE_BUF)) { mtype_handler[mtype-1](mtype, buffer, len); } else { bad_handler(mtype, buffer, len); @@ -240,21 +235,18 @@ void eos_net_free(unsigned char *buf) { xSemaphoreGive(mutex); } -int eos_net_send(unsigned char mtype, unsigned char *buffer, uint16_t len, uint8_t flags) { - int rv, sleep; +int eos_net_send(unsigned char mtype, unsigned char *buffer, uint16_t len) { + int rv = EOS_OK; + int sleep; - if (flags & EOS_NET_FLAG_BCOPY) xSemaphoreTake(semaph, portMAX_DELAY); xSemaphoreTake(mutex, portMAX_DELAY); sleep = net_sleep; gpio_set_level(SPI_GPIO_RTS, 1); - if (flags & EOS_NET_FLAG_BCOPY) { - unsigned char *b = eos_bufq_pop(&net_buf_q); - memcpy(b, buffer, len); - buffer = b; - } - rv = eos_msgq_push(&net_send_q, mtype, buffer, len, flags); + rv = eos_msgq_push(&net_send_q, mtype, buffer, len); xSemaphoreGive(mutex); + if (rv) eos_net_free(buffer); + if (sleep) eos_power_wake(EOS_PWR_WAKE_MSG); return rv; diff --git a/fw/esp32/components/eos/power.c b/fw/esp32/components/eos/power.c index f07e67b..83304c2 100644 --- a/fw/esp32/components/eos/power.c +++ b/fw/esp32/components/eos/power.c @@ -103,7 +103,7 @@ void power_sleep(uint8_t mode) { gpio_wakeup_enable(POWER_GPIO_NET, GPIO_INTR_LOW_LEVEL); gpio_wakeup_enable(POWER_GPIO_UART, GPIO_INTR_LOW_LEVEL); - ESP_LOGD(TAG, "SLEEP"); + ESP_LOGI(TAG, "SLEEP"); esp_pm_lock_release(power_lock_apb_freq); esp_pm_lock_release(power_lock_no_sleep); @@ -115,7 +115,7 @@ void power_sleep(uint8_t mode) { esp_sleep_enable_ext0_wakeup(POWER_GPIO_BTN, 0); esp_sleep_enable_ext1_wakeup((uint64_t)1 << POWER_GPIO_UART, ESP_EXT1_WAKEUP_ALL_LOW); - ESP_LOGD(TAG, "SLEEP"); + ESP_LOGI(TAG, "SLEEP"); esp_deep_sleep_start(); break; @@ -162,7 +162,7 @@ void power_wake_stage2(uint8_t source, uint8_t mode) { gpio_set_intr_type(POWER_GPIO_BTN, GPIO_INTR_ANYEDGE); gpio_isr_handler_add(POWER_GPIO_BTN, btn_handler, NULL); - ESP_LOGD(TAG, "WAKE"); + ESP_LOGI(TAG, "WAKE"); } static void power_event_task(void *pvParameters) { @@ -213,7 +213,7 @@ static void power_event_task(void *pvParameters) { buf = eos_net_alloc(); buf[0] = EOS_PWR_MTYPE_BUTTON; buf[1] = evt.level; - eos_net_send(EOS_NET_MTYPE_POWER, buf, 2, 0); + eos_net_send(EOS_NET_MTYPE_POWER, buf, 2); break; default: diff --git a/fw/esp32/components/eos/sock.c b/fw/esp32/components/eos/sock.c index 17357e4..2691a67 100644 --- a/fw/esp32/components/eos/sock.c +++ b/fw/esp32/components/eos/sock.c @@ -91,6 +91,7 @@ static void udp_rcvr_task(void *pvParameters) { rv = t_recvfrom(sock, buf+EOS_SOCK_SIZE_UDP_HDR, EOS_NET_SIZE_BUF-EOS_SOCK_SIZE_UDP_HDR, &addr); if (rv < 0) { sock = 0; + eos_net_free(buf); ESP_LOGE(TAG, "UDP RECV ERR:%d", rv); continue; } @@ -98,7 +99,7 @@ static void udp_rcvr_task(void *pvParameters) { buf[1] = esock; memcpy(buf+2, addr.host, sizeof(addr.host)); memcpy(buf+2+sizeof(addr.host), &addr.port, sizeof(addr.port)); - eos_net_send(EOS_NET_MTYPE_SOCK, buf, rv+EOS_SOCK_SIZE_UDP_HDR, 0); + eos_net_send(EOS_NET_MTYPE_SOCK, buf, rv+EOS_SOCK_SIZE_UDP_HDR); } while(sock); xSemaphoreTake(mutex, portMAX_DELAY); _socks[esock-1] = 0; @@ -141,7 +142,7 @@ static void sock_handler(unsigned char type, unsigned char *buffer, uint16_t siz rbuf = eos_net_alloc(); rbuf[0] = EOS_SOCK_MTYPE_OPEN_DGRAM; rbuf[1] = esock; - eos_net_send(EOS_NET_MTYPE_SOCK, rbuf, 2, 0); + eos_net_send(EOS_NET_MTYPE_SOCK, rbuf, 2); break; case EOS_SOCK_MTYPE_CLOSE: diff --git a/fw/esp32/components/eos/wifi.c b/fw/esp32/components/eos/wifi.c index 3dd90ba..03e3ab4 100755 --- a/fw/esp32/components/eos/wifi.c +++ b/fw/esp32/components/eos/wifi.c @@ -112,10 +112,10 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { if (_action == WIFI_ACTION_CONNECT) { rbuf[0] = EOS_WIFI_MTYPE_CONNECT; rbuf[1] = EOS_ERR; - eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 2, 0); + eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 2); } else { rbuf[0] = EOS_WIFI_MTYPE_DISCONNECT; - eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 1, 0); + eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 1); } if (!_action) ret = esp_wifi_stop(); } else { @@ -124,21 +124,21 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { break; case IP_EVENT_STA_GOT_IP: - ESP_LOGD(TAG, "IP address: " IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip)); + ESP_LOGI(TAG, "IP address: " IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip)); if (event->event_info.got_ip.ip_changed) { // send wifi reconnect } else { rbuf = eos_net_alloc(); rbuf[0] = EOS_WIFI_MTYPE_CONNECT; rbuf[1] = EOS_OK; - eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 2, 0); + eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 2); } break; default: // Ignore the other event types break; } - if (ret != ESP_OK) ESP_LOGD(TAG, "ESP WIFI ERR: %d", ret); + if (ret != ESP_OK) ESP_LOGE(TAG, "EVT HANDLER ERR:%d EVT:%d", ret, event->event_id); return ESP_OK; } @@ -164,7 +164,7 @@ static void wifi_handler(unsigned char _mtype, unsigned char *buffer, uint16_t s rv = eos_wifi_disconnect(); break; } - if (rv) ESP_LOGD(TAG, "WIFI HANDLER ERR: %d", rv); + if (rv) ESP_LOGE(TAG, "MSG HANDLER ERR:%d MSG:%d", rv, mtype); } void eos_wifi_init(void) { |