diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-07 19:26:12 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-07 19:26:12 +0200 |
commit | 3af816f20b94326b05a6dde21d7f734df14b61d3 (patch) | |
tree | a4bbdb6e22c670b7231d9d909dc6b75fe9c5433e /fw/esp32/components/eos/at_cmd.c | |
parent | a35636fc4a55e6b0cfbb5772f7274ee749059836 (diff) |
net driver: removed obsolete flags; urc process simplefied; pcm: added active flag; tested cell voice/data
Diffstat (limited to 'fw/esp32/components/eos/at_cmd.c')
-rw-r--r-- | fw/esp32/components/eos/at_cmd.c | 55 |
1 files changed, 18 insertions, 37 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); } |