From 3d0eef5fcccfd932abc541d22760eabbc97a7dd1 Mon Sep 17 00:00:00 2001 From: Robert Nuttall Date: Tue, 18 Aug 2020 15:34:58 +0100 Subject: [PATCH 1/3] Expose get operator name command. Add get access tech Signed-off-by: Liu Han --- .../components/modem/include/esp_modem_dce.h | 2 ++ .../pppos_client/components/modem/src/bg96.c | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h b/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h index 7c180b4214..edd1fe414d 100644 --- a/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h +++ b/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h @@ -75,6 +75,7 @@ struct modem_dce { char imsi[MODEM_IMSI_LENGTH + 1]; /*!< IMSI number */ char name[MODEM_MAX_NAME_LENGTH]; /*!< Module name */ char oper[MODEM_MAX_OPERATOR_LENGTH]; /*!< Operator name */ + uint8_t act; /*!< Access technology */ modem_state_t state; /*!< Modem working state */ modem_mode_t mode; /*!< Working mode */ modem_dte_t *dte; /*!< DTE which connect to DCE */ @@ -86,6 +87,7 @@ struct modem_dce { esp_err_t (*get_signal_quality)(modem_dce_t *dce, uint32_t *rssi, uint32_t *ber); /*!< Get signal quality */ esp_err_t (*get_battery_status)(modem_dce_t *dce, uint32_t *bcs, uint32_t *bcl, uint32_t *voltage); /*!< Get battery status */ + esp_err_t (*get_operator_name)(modem_dce_t *bg96_dce); /*!< Get operator name */ esp_err_t (*define_pdp_context)(modem_dce_t *dce, uint32_t cid, const char *type, const char *apn); /*!< Set PDP Contex */ esp_err_t (*set_working_mode)(modem_dce_t *dce, modem_mode_t mode); /*!< Set working mode */ diff --git a/examples/protocols/pppos_client/components/modem/src/bg96.c b/examples/protocols/pppos_client/components/modem/src/bg96.c index 4aa82ae884..9f06c0a07b 100644 --- a/examples/protocols/pppos_client/components/modem/src/bg96.c +++ b/examples/protocols/pppos_client/components/modem/src/bg96.c @@ -181,7 +181,7 @@ static esp_err_t bg96_handle_cimi(modem_dce_t *dce, const char *line) * @brief Handle response from AT+COPS? */ static esp_err_t bg96_handle_cops(modem_dce_t *dce, const char *line) -{ +{ esp_err_t err = ESP_FAIL; if (strstr(line, MODEM_RESULT_CODE_SUCCESS)) { err = esp_modem_process_command_done(dce, MODEM_STATE_SUCCESS); @@ -193,9 +193,9 @@ static esp_err_t bg96_handle_cops(modem_dce_t *dce, const char *line) size_t len = strlen(line); char *line_copy = malloc(len + 1); strcpy(line_copy, line); - /* +COPS: [, [, ]] */ + /* +COPS: [, [, ][, ]] */ char *str_ptr = NULL; - char *p[3]; + char *p[5]; uint8_t i = 0; /* strtok will broke string by replacing delimiter with '\0' */ p[i] = strtok_r(line_copy, ",", &str_ptr); @@ -210,6 +210,11 @@ static esp_err_t bg96_handle_cops(modem_dce_t *dce, const char *line) err = ESP_OK; } } + if (i >= 4) { + char act_str[3] = {0}; + int len = snprintf(act_str, 3, "%s", p[3]); + dce->act = (uint8_t)atoi(act_str); + } free(line_copy); } return err; @@ -416,14 +421,15 @@ err: /** * @brief Get Operator's name * - * @param bg96_dce bg96 object + * @param dce Modem DCE object * @return esp_err_t * - ESP_OK on success * - ESP_FAIL on error */ -static esp_err_t bg96_get_operator_name(bg96_modem_dce_t *bg96_dce) +static esp_err_t bg96_get_operator_name(modem_dce_t *dce) { - modem_dte_t *dte = bg96_dce->parent.dte; + modem_dte_t *dte = dce->dte; + bg96_modem_dce_t *bg96_dce = __containerof(dce, bg96_modem_dce_t, parent); bg96_dce->parent.handle_line = bg96_handle_cops; DCE_CHECK(dte->send_cmd(dte, "AT+COPS?\r", MODEM_COMMAND_TIMEOUT_OPERATOR) == ESP_OK, "send command failed", err); DCE_CHECK(bg96_dce->parent.state == MODEM_STATE_SUCCESS, "get network operator failed", err); @@ -470,6 +476,7 @@ modem_dce_t *bg96_init(modem_dte_t *dte) bg96_dce->parent.hang_up = esp_modem_dce_hang_up; bg96_dce->parent.get_signal_quality = bg96_get_signal_quality; bg96_dce->parent.get_battery_status = bg96_get_battery_status; + bg96_dce->parent.get_operator_name = bg96_get_operator_name; bg96_dce->parent.set_working_mode = bg96_set_working_mode; bg96_dce->parent.power_down = bg96_power_down; bg96_dce->parent.deinit = bg96_deinit; @@ -483,8 +490,6 @@ modem_dce_t *bg96_init(modem_dte_t *dte) DCE_CHECK(bg96_get_imei_number(bg96_dce) == ESP_OK, "get imei failed", err_io); /* Get IMSI number */ DCE_CHECK(bg96_get_imsi_number(bg96_dce) == ESP_OK, "get imsi failed", err_io); - /* Get operator name */ - DCE_CHECK(bg96_get_operator_name(bg96_dce) == ESP_OK, "get operator name failed", err_io); return &(bg96_dce->parent); err_io: free(bg96_dce); From a313f37b2db22dda059f7b5966dd74a48ed9fe89 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 18 Aug 2020 16:16:42 +0100 Subject: [PATCH 2/3] rename dce parameter Merges https://github.com/espressif/esp-idf/pull/5750 Signed-off-by: Liu Han --- .../pppos_client/components/modem/include/esp_modem_dce.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h b/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h index edd1fe414d..6a88de0c36 100644 --- a/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h +++ b/examples/protocols/pppos_client/components/modem/include/esp_modem_dce.h @@ -87,7 +87,7 @@ struct modem_dce { esp_err_t (*get_signal_quality)(modem_dce_t *dce, uint32_t *rssi, uint32_t *ber); /*!< Get signal quality */ esp_err_t (*get_battery_status)(modem_dce_t *dce, uint32_t *bcs, uint32_t *bcl, uint32_t *voltage); /*!< Get battery status */ - esp_err_t (*get_operator_name)(modem_dce_t *bg96_dce); /*!< Get operator name */ + esp_err_t (*get_operator_name)(modem_dce_t *dce); /*!< Get operator name */ esp_err_t (*define_pdp_context)(modem_dce_t *dce, uint32_t cid, const char *type, const char *apn); /*!< Set PDP Contex */ esp_err_t (*set_working_mode)(modem_dce_t *dce, modem_mode_t mode); /*!< Set working mode */ From 4c30995b88c8da86094ed47a07115fa1b2eed335 Mon Sep 17 00:00:00 2001 From: Liu Han Date: Tue, 22 Dec 2020 20:22:27 +0800 Subject: [PATCH 3/3] esp-modem: prefix the crash issue both bg96 and sim800l in OVERALL mode --- .../pppos_client/components/modem/src/bg96.c | 10 +++++----- .../pppos_client/components/modem/src/sim800.c | 17 +++++++++++------ .../pppos_client/main/Kconfig.projbuild | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/examples/protocols/pppos_client/components/modem/src/bg96.c b/examples/protocols/pppos_client/components/modem/src/bg96.c index 9f06c0a07b..134f24ac79 100644 --- a/examples/protocols/pppos_client/components/modem/src/bg96.c +++ b/examples/protocols/pppos_client/components/modem/src/bg96.c @@ -181,7 +181,7 @@ static esp_err_t bg96_handle_cimi(modem_dce_t *dce, const char *line) * @brief Handle response from AT+COPS? */ static esp_err_t bg96_handle_cops(modem_dce_t *dce, const char *line) -{ +{ esp_err_t err = ESP_FAIL; if (strstr(line, MODEM_RESULT_CODE_SUCCESS)) { err = esp_modem_process_command_done(dce, MODEM_STATE_SUCCESS); @@ -193,7 +193,7 @@ static esp_err_t bg96_handle_cops(modem_dce_t *dce, const char *line) size_t len = strlen(line); char *line_copy = malloc(len + 1); strcpy(line_copy, line); - /* +COPS: [, [, ][, ]] */ + /* +COPS: [, [, [, ]]] */ char *str_ptr = NULL; char *p[5]; uint8_t i = 0; @@ -211,9 +211,7 @@ static esp_err_t bg96_handle_cops(modem_dce_t *dce, const char *line) } } if (i >= 4) { - char act_str[3] = {0}; - int len = snprintf(act_str, 3, "%s", p[3]); - dce->act = (uint8_t)atoi(act_str); + dce->act = (uint8_t)strtol(p[3], NULL, 0); } free(line_copy); } @@ -490,6 +488,8 @@ modem_dce_t *bg96_init(modem_dte_t *dte) DCE_CHECK(bg96_get_imei_number(bg96_dce) == ESP_OK, "get imei failed", err_io); /* Get IMSI number */ DCE_CHECK(bg96_get_imsi_number(bg96_dce) == ESP_OK, "get imsi failed", err_io); + /* Get operator name */ + DCE_CHECK(bg96_get_operator_name(&(bg96_dce->parent)) == ESP_OK, "get operator name failed", err_io); return &(bg96_dce->parent); err_io: free(bg96_dce); diff --git a/examples/protocols/pppos_client/components/modem/src/sim800.c b/examples/protocols/pppos_client/components/modem/src/sim800.c index d2ced136a9..177a288e88 100644 --- a/examples/protocols/pppos_client/components/modem/src/sim800.c +++ b/examples/protocols/pppos_client/components/modem/src/sim800.c @@ -194,9 +194,9 @@ static esp_err_t sim800_handle_cops(modem_dce_t *dce, const char *line) size_t len = strlen(line); char *line_copy = malloc(len + 1); strcpy(line_copy, line); - /* +COPS: [, [, ]] */ + /* +COPS: [, [, [, ]]] */ char *str_ptr = NULL; - char *p[3]; + char *p[5]; uint8_t i = 0; /* strtok will broke string by replacing delimiter with '\0' */ p[i] = strtok_r(line_copy, ",", &str_ptr); @@ -211,6 +211,9 @@ static esp_err_t sim800_handle_cops(modem_dce_t *dce, const char *line) err = ESP_OK; } } + if (i >= 4) { + dce->act = (uint8_t)strtol(p[3], NULL, 0); + } free(line_copy); } return err; @@ -415,14 +418,15 @@ err: /** * @brief Get Operator's name * - * @param sim800_dce sim800 object + * @param dce Modem DCE object * @return esp_err_t * - ESP_OK on success * - ESP_FAIL on error */ -static esp_err_t sim800_get_operator_name(sim800_modem_dce_t *sim800_dce) +static esp_err_t sim800_get_operator_name(modem_dce_t *dce) { - modem_dte_t *dte = sim800_dce->parent.dte; + modem_dte_t *dte = dce->dte; + sim800_modem_dce_t *sim800_dce = __containerof(dce, sim800_modem_dce_t, parent); sim800_dce->parent.handle_line = sim800_handle_cops; DCE_CHECK(dte->send_cmd(dte, "AT+COPS?\r", MODEM_COMMAND_TIMEOUT_OPERATOR) == ESP_OK, "send command failed", err); DCE_CHECK(sim800_dce->parent.state == MODEM_STATE_SUCCESS, "get network operator failed", err); @@ -469,6 +473,7 @@ modem_dce_t *sim800_init(modem_dte_t *dte) sim800_dce->parent.hang_up = esp_modem_dce_hang_up; sim800_dce->parent.get_signal_quality = sim800_get_signal_quality; sim800_dce->parent.get_battery_status = sim800_get_battery_status; + sim800_dce->parent.get_operator_name = sim800_get_operator_name; sim800_dce->parent.set_working_mode = sim800_set_working_mode; sim800_dce->parent.power_down = sim800_power_down; sim800_dce->parent.deinit = sim800_deinit; @@ -483,7 +488,7 @@ modem_dce_t *sim800_init(modem_dte_t *dte) /* Get IMSI number */ DCE_CHECK(sim800_get_imsi_number(sim800_dce) == ESP_OK, "get imsi failed", err_io); /* Get operator name */ - DCE_CHECK(sim800_get_operator_name(sim800_dce) == ESP_OK, "get operator name failed", err_io); + DCE_CHECK(sim800_get_operator_name(&(sim800_dce->parent)) == ESP_OK, "get operator name failed", err_io); return &(sim800_dce->parent); err_io: free(sim800_dce); diff --git a/examples/protocols/pppos_client/main/Kconfig.projbuild b/examples/protocols/pppos_client/main/Kconfig.projbuild index 7d84465642..96e71658cc 100644 --- a/examples/protocols/pppos_client/main/Kconfig.projbuild +++ b/examples/protocols/pppos_client/main/Kconfig.projbuild @@ -80,7 +80,7 @@ menu "Example Configuration" config EXAMPLE_UART_EVENT_TASK_STACK_SIZE int "UART Event Task Stack Size" range 2000 6000 - default 2048 + default 3072 help Stack size of UART event task.