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..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 @@ -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 *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..134f24ac79 100644 --- a/examples/protocols/pppos_client/components/modem/src/bg96.c +++ b/examples/protocols/pppos_client/components/modem/src/bg96.c @@ -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,9 @@ static esp_err_t bg96_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; @@ -416,14 +419,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 +474,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; @@ -484,7 +489,7 @@ modem_dce_t *bg96_init(modem_dte_t *dte) /* 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); + 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.