Skip to content

Commit

Permalink
samples: cellular: modem_shell: Fix errors when printing link status
Browse files Browse the repository at this point in the history
When registration had already been dropped, a couple of errors
were shown when trying to print registration and PDN status.
AT response parsing has been improved to handle also this
situation.

MOSH-640

Signed-off-by: Tommi Kangas <[email protected]>
  • Loading branch information
tokangas committed Feb 13, 2025
1 parent 859caae commit a831f65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion samples/cellular/modem_shell/src/link/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void link_registered_work(struct k_work *unused)
/* PDN activation may take some time. Thus, let modem have some time
* before reading the PDN information.
*/
k_sleep(K_MSEC(2000));
k_sleep(K_MSEC(1500));

link_api_modem_info_get_for_shell(true);
}
Expand Down
8 changes: 7 additions & 1 deletion samples/cellular/modem_shell/src/link/link_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ int link_api_xmonitor_read(struct lte_xmonitor_resp_t *resp)
{
int ret = 0;
int len;
uint32_t reg_status;
char tmp_cell_id_str[OP_CELL_ID_STR_MAX_LEN + 1] = { 0 };
char tmp_tac_str[OP_TAC_STR_MAX_LEN + 1] = { 0 };

Expand All @@ -243,7 +244,7 @@ int link_api_xmonitor_read(struct lte_xmonitor_resp_t *resp)

ret = nrf_modem_at_scanf("AT%XMONITOR",
"%%XMONITOR: "
"%*u," /* <reg_status>: ignored */
"%u," /* <reg_status> */
"%"L(OP_FULL_NAME_STR_MAX_LEN)"[^,]," /* <full_name> with quotes */
"%"L(OP_SHORT_NAME_STR_MAX_LEN)"[^,],"/* <short_name> with quotes*/
"%"L(OP_PLMN_STR_MAX_LEN)"[^,]," /* <plmn> */
Expand All @@ -255,6 +256,7 @@ int link_api_xmonitor_read(struct lte_xmonitor_resp_t *resp)
"%*u," /* <EARFCN>: ignored */
"%d," /* <rsrp> */
"%d", /* <snr> */
&reg_status,
resp->full_name_str,
resp->short_name_str,
resp->plmn_str,
Expand Down Expand Up @@ -404,6 +406,10 @@ int link_api_pdp_contexts_read(struct pdp_context_info_array *pdp_info)
pdp_info->array = calloc(pdp_cnt, sizeof(struct pdp_context_info));
pdp_info->size = pdp_cnt;

if (pdp_cnt == 0) {
goto clean_exit;
}

/* Parse the response */
ret = at_parser_init(&parser, at_ptr);
if (ret) {
Expand Down

0 comments on commit a831f65

Please sign in to comment.