drivers: modem: improve modem context RSSI member
The previous bf68b67
commit incorrectly passes minfo.mdm_rssi
value to the modem context data_rssi member during the driver
initialization which causes the `modem info` shell command
to return 0 as RSSI value. Fix that by changing data_rssi
modem ctx member to a pointer that is assigned to the RSSI
variable stored within the modem driver context structure.
Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
This commit is contained in:
parent
69f1236657
commit
ee7cd10563
|
@ -1115,7 +1115,7 @@ static int gsm_init(const struct device *dev)
|
|||
gsm->context.data_imsi = minfo.mdm_imsi;
|
||||
gsm->context.data_iccid = minfo.mdm_iccid;
|
||||
#endif /* CONFIG_MODEM_SIM_NUMBERS */
|
||||
gsm->context.data_rssi = minfo.mdm_rssi;
|
||||
gsm->context.data_rssi = &minfo.mdm_rssi;
|
||||
#endif /* CONFIG_MODEM_SHELL */
|
||||
|
||||
gsm->context.is_automatic_oper = false;
|
||||
|
|
|
@ -519,6 +519,7 @@ struct hl7800_iface_ctx {
|
|||
char mdm_active_bands_string[MDM_HL7800_LTE_BAND_STR_SIZE];
|
||||
char mdm_bands_string[MDM_HL7800_LTE_BAND_STR_SIZE];
|
||||
char mdm_imsi[MDM_HL7800_IMSI_MAX_STR_SIZE];
|
||||
int mdm_rssi;
|
||||
uint16_t mdm_bands_top;
|
||||
uint32_t mdm_bands_middle;
|
||||
uint32_t mdm_bands_bottom;
|
||||
|
@ -860,7 +861,7 @@ static void event_handler(enum mdm_hl7800_event event, void *event_data)
|
|||
|
||||
void mdm_hl7800_get_signal_quality(int *rsrp, int *sinr)
|
||||
{
|
||||
*rsrp = ictx.mdm_ctx.data_rssi;
|
||||
*rsrp = ictx.mdm_rssi;
|
||||
*sinr = ictx.mdm_sinr;
|
||||
}
|
||||
|
||||
|
@ -1243,7 +1244,7 @@ void mdm_hl7800_generate_status_events(void)
|
|||
#ifdef CONFIG_MODEM_HL7800_FW_UPDATE
|
||||
generate_fota_state_event();
|
||||
#endif
|
||||
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_ctx.data_rssi);
|
||||
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_rssi);
|
||||
event_handler(HL7800_EVENT_SINR, &ictx.mdm_sinr);
|
||||
event_handler(HL7800_EVENT_APN_UPDATE, &ictx.mdm_apn);
|
||||
event_handler(HL7800_EVENT_RAT, &ictx.mdm_rat);
|
||||
|
@ -3385,7 +3386,7 @@ static bool on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
|
|||
search_start = delims[i] + 1;
|
||||
}
|
||||
/* the first value in the message is the RSRP */
|
||||
ictx.mdm_ctx.data_rssi = strtol(value, NULL, 10);
|
||||
ictx.mdm_rssi = strtol(value, NULL, 10);
|
||||
/* the 4th ',' (last in the msg) is the start of the SINR */
|
||||
ictx.mdm_sinr = strtol(delims[3] + 1, NULL, 10);
|
||||
if ((delims[1] - delims[0]) == 1) {
|
||||
|
@ -3394,9 +3395,9 @@ static bool on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
|
|||
*/
|
||||
LOG_INF("RSSI (RSRP): UNKNOWN");
|
||||
} else {
|
||||
LOG_INF("RSSI (RSRP): %d SINR: %d", ictx.mdm_ctx.data_rssi,
|
||||
LOG_INF("RSSI (RSRP): %d SINR: %d", ictx.mdm_rssi,
|
||||
ictx.mdm_sinr);
|
||||
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_ctx.data_rssi);
|
||||
event_handler(HL7800_EVENT_RSSI, &ictx.mdm_rssi);
|
||||
event_handler(HL7800_EVENT_SINR, &ictx.mdm_sinr);
|
||||
}
|
||||
done:
|
||||
|
@ -5854,6 +5855,7 @@ static int hl7800_init(const struct device *dev)
|
|||
#ifdef CONFIG_MODEM_SIM_NUMBERS
|
||||
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
|
||||
#endif
|
||||
ictx.mdm_ctx.data_rssi = &ictx.mdm_rssi;
|
||||
|
||||
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
|
||||
mdm_recv_buf, sizeof(mdm_recv_buf));
|
||||
|
|
|
@ -71,7 +71,7 @@ struct modem_context {
|
|||
int data_lac;
|
||||
int data_cellid;
|
||||
#endif
|
||||
int data_rssi;
|
||||
int *data_rssi;
|
||||
bool is_automatic_oper;
|
||||
/* pin config */
|
||||
struct modem_pin *pins;
|
||||
|
|
|
@ -37,7 +37,7 @@ struct mdm_receiver_context {
|
|||
char *data_imsi;
|
||||
#endif
|
||||
char *data_iccid;
|
||||
int data_rssi;
|
||||
int *data_rssi;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,7 +88,7 @@ static int cmd_modem_list(const struct shell *shell, size_t argc,
|
|||
mdm_ctx->data_lac,
|
||||
mdm_ctx->data_cellid,
|
||||
#endif
|
||||
mdm_ctx->data_rssi);
|
||||
mdm_ctx->data_rssi ? *mdm_ctx->data_rssi : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ static int cmd_modem_info(const struct shell *shell, size_t argc, char *argv[])
|
|||
mdm_ctx->data_model,
|
||||
mdm_ctx->data_revision,
|
||||
mdm_ctx->data_imei,
|
||||
mdm_ctx->data_rssi);
|
||||
mdm_ctx->data_rssi ? *mdm_ctx->data_rssi : 0);
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL,
|
||||
"GSM 07.10 muxing : %s\n",
|
||||
|
|
|
@ -231,14 +231,14 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_csq)
|
|||
|
||||
/* Check the RSSI value. */
|
||||
if (rssi == 31) {
|
||||
mctx.data_rssi = -51;
|
||||
mdata.mdm_rssi = -51;
|
||||
} else if (rssi >= 0 && rssi <= 31) {
|
||||
mctx.data_rssi = -114 + ((rssi * 2) + 1);
|
||||
mdata.mdm_rssi = -114 + ((rssi * 2) + 1);
|
||||
} else {
|
||||
mctx.data_rssi = -1000;
|
||||
mdata.mdm_rssi = -1000;
|
||||
}
|
||||
|
||||
LOG_INF("RSSI: %d", mctx.data_rssi);
|
||||
LOG_INF("RSSI: %d", mdata.mdm_rssi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1035,13 +1035,13 @@ restart_rssi:
|
|||
|
||||
/* Keep trying to read RSSI until we get a valid value - Eventually, exit. */
|
||||
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
|
||||
(mctx.data_rssi >= 0 || mctx.data_rssi <= -1000)) {
|
||||
(mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000)) {
|
||||
modem_rssi_query_work(NULL);
|
||||
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
|
||||
}
|
||||
|
||||
/* Is the RSSI invalid ? */
|
||||
if (mctx.data_rssi >= 0 || mctx.data_rssi <= -1000) {
|
||||
if (mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000) {
|
||||
rssi_retry_count++;
|
||||
|
||||
if (rssi_retry_count >= MDM_NETWORK_RETRY_COUNT) {
|
||||
|
@ -1180,6 +1180,7 @@ static int modem_init(const struct device *dev)
|
|||
mctx.data_imsi = mdata.mdm_imsi;
|
||||
mctx.data_iccid = mdata.mdm_iccid;
|
||||
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
||||
mctx.data_rssi = &mdata.mdm_rssi;
|
||||
|
||||
/* pin setup */
|
||||
mctx.pins = modem_pins;
|
||||
|
|
|
@ -100,6 +100,7 @@ struct modem_data {
|
|||
char mdm_imsi[MDM_IMSI_LENGTH];
|
||||
char mdm_iccid[MDM_ICCID_LENGTH];
|
||||
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
||||
int mdm_rssi;
|
||||
|
||||
/* bytes written to socket in last transaction */
|
||||
int sock_written;
|
||||
|
|
|
@ -161,6 +161,7 @@ struct modem_data {
|
|||
char mdm_revision[MDM_REVISION_LENGTH];
|
||||
char mdm_imei[MDM_IMEI_LENGTH];
|
||||
char mdm_imsi[MDM_IMSI_LENGTH];
|
||||
int mdm_rssi;
|
||||
|
||||
#if defined(CONFIG_MODEM_UBLOX_SARA_AUTODETECT_VARIANT)
|
||||
/* modem variant */
|
||||
|
@ -658,13 +659,13 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_cesq)
|
|||
rsrp = ATOI(argv[5], 0, "rsrp");
|
||||
rxlev = ATOI(argv[0], 0, "rxlev");
|
||||
if (rsrp >= 0 && rsrp <= 97) {
|
||||
mctx.data_rssi = -140 + (rsrp - 1);
|
||||
LOG_INF("RSRP: %d", mctx.data_rssi);
|
||||
mdata.mdm_rssi = -140 + (rsrp - 1);
|
||||
LOG_INF("RSRP: %d", mdata.mdm_rssi);
|
||||
} else if (rxlev >= 0 && rxlev <= 63) {
|
||||
mctx.data_rssi = -110 + (rxlev - 1);
|
||||
LOG_INF("RSSI: %d", mctx.data_rssi);
|
||||
mdata.mdm_rssi = -110 + (rxlev - 1);
|
||||
LOG_INF("RSSI: %d", mdata.mdm_rssi);
|
||||
} else {
|
||||
mctx.data_rssi = -1000;
|
||||
mdata.mdm_rssi = -1000;
|
||||
LOG_INF("RSRP/RSSI not known");
|
||||
}
|
||||
|
||||
|
@ -681,15 +682,15 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_csq)
|
|||
|
||||
rssi = ATOI(argv[0], 0, "signal_power");
|
||||
if (rssi == 31) {
|
||||
mctx.data_rssi = -46;
|
||||
mdata.mdm_rssi = -46;
|
||||
} else if (rssi >= 0 && rssi <= 31) {
|
||||
/* FIXME: This value depends on the RAT */
|
||||
mctx.data_rssi = -110 + ((rssi * 2) + 1);
|
||||
mdata.mdm_rssi = -110 + ((rssi * 2) + 1);
|
||||
} else {
|
||||
mctx.data_rssi = -1000;
|
||||
mdata.mdm_rssi = -1000;
|
||||
}
|
||||
|
||||
LOG_INF("RSSI: %d", mctx.data_rssi);
|
||||
LOG_INF("RSSI: %d", mdata.mdm_rssi);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -1320,13 +1321,13 @@ restart:
|
|||
counter = 0;
|
||||
/* wait for RSSI < 0 and > -1000 */
|
||||
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
|
||||
(mctx.data_rssi >= 0 ||
|
||||
mctx.data_rssi <= -1000)) {
|
||||
(mdata.mdm_rssi >= 0 ||
|
||||
mdata.mdm_rssi <= -1000)) {
|
||||
modem_rssi_query_work(NULL);
|
||||
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
|
||||
}
|
||||
|
||||
if (mctx.data_rssi >= 0 || mctx.data_rssi <= -1000) {
|
||||
if (mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000) {
|
||||
retry_count++;
|
||||
if (retry_count >= MDM_NETWORK_RETRY_COUNT) {
|
||||
LOG_ERR("Failed network init. Too many attempts!");
|
||||
|
@ -2195,6 +2196,7 @@ static int modem_init(const struct device *dev)
|
|||
mctx.data_model = mdata.mdm_model;
|
||||
mctx.data_revision = mdata.mdm_revision;
|
||||
mctx.data_imei = mdata.mdm_imei;
|
||||
mctx.data_rssi = &mdata.mdm_rssi;
|
||||
|
||||
/* pin setup */
|
||||
mctx.pins = modem_pins;
|
||||
|
|
|
@ -204,6 +204,7 @@ struct wncm14a2a_iface_ctx {
|
|||
char mdm_model[MDM_MODEL_LENGTH];
|
||||
char mdm_revision[MDM_REVISION_LENGTH];
|
||||
char mdm_imei[MDM_IMEI_LENGTH];
|
||||
int mdm_rssi;
|
||||
|
||||
/* modem state */
|
||||
int ev_csps;
|
||||
|
@ -663,8 +664,8 @@ static void on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
|
|||
}
|
||||
|
||||
if (i > 0) {
|
||||
ictx.mdm_ctx.data_rssi = atoi(value);
|
||||
LOG_INF("RSSI: %d", ictx.mdm_ctx.data_rssi);
|
||||
ictx.mdm_rssi = atoi(value);
|
||||
LOG_INF("RSSI: %d", ictx.mdm_rssi);
|
||||
} else {
|
||||
LOG_WRN("Bad format found for RSSI");
|
||||
}
|
||||
|
@ -1398,15 +1399,15 @@ restart:
|
|||
counter = 0;
|
||||
/* wait for RSSI > -1000 and != 0 */
|
||||
while (counter++ < 15 &&
|
||||
(ictx.mdm_ctx.data_rssi <= -1000 ||
|
||||
ictx.mdm_ctx.data_rssi == 0)) {
|
||||
(ictx.mdm_rssi <= -1000 ||
|
||||
ictx.mdm_rssi == 0)) {
|
||||
/* stop RSSI delay work */
|
||||
k_work_cancel_delayable(&ictx.rssi_query_work);
|
||||
wncm14a2a_rssi_query_work(NULL);
|
||||
k_sleep(K_SECONDS(2));
|
||||
}
|
||||
|
||||
if (ictx.mdm_ctx.data_rssi <= -1000 || ictx.mdm_ctx.data_rssi == 0) {
|
||||
if (ictx.mdm_rssi <= -1000 || ictx.mdm_rssi == 0) {
|
||||
retry_count++;
|
||||
if (retry_count > 3) {
|
||||
LOG_ERR("Failed network init. Too many attempts!");
|
||||
|
@ -1486,6 +1487,7 @@ static int wncm14a2a_init(const struct device *dev)
|
|||
#ifdef CONFIG_MODEM_SIM_NUMBERS
|
||||
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
|
||||
#endif
|
||||
ictx.mdm_ctx.data_rssi = &ictx.mdm_rssi;
|
||||
|
||||
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
|
||||
mdm_recv_buf, sizeof(mdm_recv_buf));
|
||||
|
|
Loading…
Reference in a new issue