Hi List, R3876 is committed to add 'lgsm_oper_n_get()' to retrieve the current network country code. Thanks for Sean Chiang.
Regards, Erin
=== include/gsmd/usock.h ================================================================== --- include/gsmd/usock.h (revision 191) +++ include/gsmd/usock.h (local) @@ -153,14 +153,15 @@ GSMD_NETWORK_VMAIL_GET = 3, GSMD_NETWORK_VMAIL_SET = 4, GSMD_NETWORK_OPER_GET = 5, - GSMD_NETWORK_OPER_LIST = 6, - GSMD_NETWORK_CIND_GET = 7, - GSMD_NETWORK_DEREGISTER = 8, - GSMD_NETWORK_GET_NUMBER = 9, - GSMD_NETWORK_PREF_LIST = 10, - GSMD_NETWORK_PREF_DEL = 11, - GSMD_NETWORK_PREF_ADD = 12, - GSMD_NETWORK_PREF_SPACE = 13, + GSMD_NETWORK_OPER_N_GET = 6, + GSMD_NETWORK_OPER_LIST = 7, + GSMD_NETWORK_CIND_GET = 8, + GSMD_NETWORK_DEREGISTER = 9, + GSMD_NETWORK_GET_NUMBER = 10, + GSMD_NETWORK_PREF_LIST = 11, + GSMD_NETWORK_PREF_DEL = 12, + GSMD_NETWORK_PREF_ADD = 13, + GSMD_NETWORK_PREF_SPACE = 14, }; enum gsmd_msg_sms { === src/gsmd/usock.c ================================================================== --- src/gsmd/usock.c (revision 191) +++ src/gsmd/usock.c (local) @@ -767,6 +767,46 @@ return ret; } +static int network_oper_n_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) +{ + struct gsmd_user *gu = ctx; + int format, s, ret; + char buf[16+1] = {'\0'}; + struct gsm_extrsp *er; + + er = extrsp_parse(cmd, resp); + + if ( !er ) + return -ENOMEM; + + //extrsp_dump(er); + + /* Format: <mode>[,<format>,<oper>] */ + if ( er->num_tokens == 1 && + er->tokens[0].type == GSMD_ECMD_RTT_NUMERIC ) { + + /* In case we're not registered, return an empty string */ + buf[0] = '\0'; + } + else if ( er->num_tokens == 3 && + er->tokens[0].type == GSMD_ECMD_RTT_NUMERIC && + er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC && + er->tokens[2].type == GSMD_ECMD_RTT_STRING ) { + + + strcpy(buf, er->tokens[2].u.string); + } + else { + DEBUGP("Invalid Input : Parse error\n"); + return -EINVAL; + } + + talloc_free(er); + + return gsmd_ucmd_submit(gu, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_N_GET, + cmd->id, sizeof(buf), buf); +} + static int network_opers_parse(const char *str, struct gsmd_msg_oper **out) { int len = 0; @@ -980,6 +1020,12 @@ &null_cmd_cb, gu, 0, NULL)); cmd = atcmd_fill("AT+COPS?", 8+1, &network_oper_cb, gu, 0, NULL); break; + case GSMD_NETWORK_OPER_N_GET: + /* Set numeric format */ + atcmd_submit(gu->gsmd, atcmd_fill("AT+COPS=3,2", 11+1, + &null_cmd_cb, gu, 0, NULL)); + cmd = atcmd_fill("AT+COPS?", 8+1, &network_oper_n_cb, gu, 0, NULL); + break; case GSMD_NETWORK_OPER_LIST: cmd = atcmd_fill("AT+COPS=?", 9+1, &network_opers_cb, gu, 0, NULL); break; === src/libgsmd/libgsmd_network.c ================================================================== --- src/libgsmd/libgsmd_network.c (revision 191) +++ src/libgsmd/libgsmd_network.c (local) @@ -46,6 +46,11 @@ return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_GET); } +int lgsm_oper_n_get(struct lgsm_handle *lh) +{ + return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_N_GET); +} + int lgsm_opers_get(struct lgsm_handle *lh) { return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_LIST); === src/util/shell.c ================================================================== --- src/util/shell.c (revision 191) +++ src/util/shell.c (local) @@ -320,6 +320,7 @@ pending_responses --; break; case GSMD_NETWORK_OPER_GET: + case GSMD_NETWORK_OPER_N_GET: if (oper[0]) printf("Our current operator is %s\n", oper); else @@ -500,6 +501,7 @@ "\tR\tRegister to given operator (R=number)\n" "\tU\tUnregister from netowrk\n" "\tP\tPrint current operator\n" + "\tN\tPrint current operator in numeric\n" "\tL\tList available operators\n" "\tQ\tRead signal quality\n" "\tS\tSleep (S[=second], default 5)\n" @@ -634,6 +636,10 @@ printf("Read current opername\n"); lgsm_oper_get(lgsmh); pending_responses ++; + } else if (!strcmp(buf, "N")) { + printf("Read current opername in numeric format\n"); + lgsm_oper_n_get(lgsmh); + pending_responses ++; } else if (!strcmp(buf, "L")) { printf("List operators\n"); lgsm_opers_get(lgsmh);