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_imsi = minfo.mdm_imsi;
|
||||||
gsm->context.data_iccid = minfo.mdm_iccid;
|
gsm->context.data_iccid = minfo.mdm_iccid;
|
||||||
#endif /* CONFIG_MODEM_SIM_NUMBERS */
|
#endif /* CONFIG_MODEM_SIM_NUMBERS */
|
||||||
gsm->context.data_rssi = minfo.mdm_rssi;
|
gsm->context.data_rssi = &minfo.mdm_rssi;
|
||||||
#endif /* CONFIG_MODEM_SHELL */
|
#endif /* CONFIG_MODEM_SHELL */
|
||||||
|
|
||||||
gsm->context.is_automatic_oper = false;
|
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_active_bands_string[MDM_HL7800_LTE_BAND_STR_SIZE];
|
||||||
char mdm_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];
|
char mdm_imsi[MDM_HL7800_IMSI_MAX_STR_SIZE];
|
||||||
|
int mdm_rssi;
|
||||||
uint16_t mdm_bands_top;
|
uint16_t mdm_bands_top;
|
||||||
uint32_t mdm_bands_middle;
|
uint32_t mdm_bands_middle;
|
||||||
uint32_t mdm_bands_bottom;
|
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)
|
void mdm_hl7800_get_signal_quality(int *rsrp, int *sinr)
|
||||||
{
|
{
|
||||||
*rsrp = ictx.mdm_ctx.data_rssi;
|
*rsrp = ictx.mdm_rssi;
|
||||||
*sinr = ictx.mdm_sinr;
|
*sinr = ictx.mdm_sinr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1243,7 +1244,7 @@ void mdm_hl7800_generate_status_events(void)
|
||||||
#ifdef CONFIG_MODEM_HL7800_FW_UPDATE
|
#ifdef CONFIG_MODEM_HL7800_FW_UPDATE
|
||||||
generate_fota_state_event();
|
generate_fota_state_event();
|
||||||
#endif
|
#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_SINR, &ictx.mdm_sinr);
|
||||||
event_handler(HL7800_EVENT_APN_UPDATE, &ictx.mdm_apn);
|
event_handler(HL7800_EVENT_APN_UPDATE, &ictx.mdm_apn);
|
||||||
event_handler(HL7800_EVENT_RAT, &ictx.mdm_rat);
|
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;
|
search_start = delims[i] + 1;
|
||||||
}
|
}
|
||||||
/* the first value in the message is the RSRP */
|
/* 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 */
|
/* the 4th ',' (last in the msg) is the start of the SINR */
|
||||||
ictx.mdm_sinr = strtol(delims[3] + 1, NULL, 10);
|
ictx.mdm_sinr = strtol(delims[3] + 1, NULL, 10);
|
||||||
if ((delims[1] - delims[0]) == 1) {
|
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");
|
LOG_INF("RSSI (RSRP): UNKNOWN");
|
||||||
} else {
|
} 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);
|
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);
|
event_handler(HL7800_EVENT_SINR, &ictx.mdm_sinr);
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
|
@ -5854,6 +5855,7 @@ static int hl7800_init(const struct device *dev)
|
||||||
#ifdef CONFIG_MODEM_SIM_NUMBERS
|
#ifdef CONFIG_MODEM_SIM_NUMBERS
|
||||||
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
|
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
|
||||||
#endif
|
#endif
|
||||||
|
ictx.mdm_ctx.data_rssi = &ictx.mdm_rssi;
|
||||||
|
|
||||||
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
|
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
|
||||||
mdm_recv_buf, sizeof(mdm_recv_buf));
|
mdm_recv_buf, sizeof(mdm_recv_buf));
|
||||||
|
|
|
@ -71,7 +71,7 @@ struct modem_context {
|
||||||
int data_lac;
|
int data_lac;
|
||||||
int data_cellid;
|
int data_cellid;
|
||||||
#endif
|
#endif
|
||||||
int data_rssi;
|
int *data_rssi;
|
||||||
bool is_automatic_oper;
|
bool is_automatic_oper;
|
||||||
/* pin config */
|
/* pin config */
|
||||||
struct modem_pin *pins;
|
struct modem_pin *pins;
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct mdm_receiver_context {
|
||||||
char *data_imsi;
|
char *data_imsi;
|
||||||
#endif
|
#endif
|
||||||
char *data_iccid;
|
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_lac,
|
||||||
mdm_ctx->data_cellid,
|
mdm_ctx->data_cellid,
|
||||||
#endif
|
#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_model,
|
||||||
mdm_ctx->data_revision,
|
mdm_ctx->data_revision,
|
||||||
mdm_ctx->data_imei,
|
mdm_ctx->data_imei,
|
||||||
mdm_ctx->data_rssi);
|
mdm_ctx->data_rssi ? *mdm_ctx->data_rssi : 0);
|
||||||
|
|
||||||
shell_fprintf(shell, SHELL_NORMAL,
|
shell_fprintf(shell, SHELL_NORMAL,
|
||||||
"GSM 07.10 muxing : %s\n",
|
"GSM 07.10 muxing : %s\n",
|
||||||
|
|
|
@ -231,14 +231,14 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_csq)
|
||||||
|
|
||||||
/* Check the RSSI value. */
|
/* Check the RSSI value. */
|
||||||
if (rssi == 31) {
|
if (rssi == 31) {
|
||||||
mctx.data_rssi = -51;
|
mdata.mdm_rssi = -51;
|
||||||
} else if (rssi >= 0 && rssi <= 31) {
|
} else if (rssi >= 0 && rssi <= 31) {
|
||||||
mctx.data_rssi = -114 + ((rssi * 2) + 1);
|
mdata.mdm_rssi = -114 + ((rssi * 2) + 1);
|
||||||
} else {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1035,13 +1035,13 @@ restart_rssi:
|
||||||
|
|
||||||
/* Keep trying to read RSSI until we get a valid value - Eventually, exit. */
|
/* Keep trying to read RSSI until we get a valid value - Eventually, exit. */
|
||||||
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
|
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);
|
modem_rssi_query_work(NULL);
|
||||||
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
|
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is the RSSI invalid ? */
|
/* 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++;
|
rssi_retry_count++;
|
||||||
|
|
||||||
if (rssi_retry_count >= MDM_NETWORK_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_imsi = mdata.mdm_imsi;
|
||||||
mctx.data_iccid = mdata.mdm_iccid;
|
mctx.data_iccid = mdata.mdm_iccid;
|
||||||
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
||||||
|
mctx.data_rssi = &mdata.mdm_rssi;
|
||||||
|
|
||||||
/* pin setup */
|
/* pin setup */
|
||||||
mctx.pins = modem_pins;
|
mctx.pins = modem_pins;
|
||||||
|
|
|
@ -100,6 +100,7 @@ struct modem_data {
|
||||||
char mdm_imsi[MDM_IMSI_LENGTH];
|
char mdm_imsi[MDM_IMSI_LENGTH];
|
||||||
char mdm_iccid[MDM_ICCID_LENGTH];
|
char mdm_iccid[MDM_ICCID_LENGTH];
|
||||||
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
#endif /* #if defined(CONFIG_MODEM_SIM_NUMBERS) */
|
||||||
|
int mdm_rssi;
|
||||||
|
|
||||||
/* bytes written to socket in last transaction */
|
/* bytes written to socket in last transaction */
|
||||||
int sock_written;
|
int sock_written;
|
||||||
|
|
|
@ -161,6 +161,7 @@ struct modem_data {
|
||||||
char mdm_revision[MDM_REVISION_LENGTH];
|
char mdm_revision[MDM_REVISION_LENGTH];
|
||||||
char mdm_imei[MDM_IMEI_LENGTH];
|
char mdm_imei[MDM_IMEI_LENGTH];
|
||||||
char mdm_imsi[MDM_IMSI_LENGTH];
|
char mdm_imsi[MDM_IMSI_LENGTH];
|
||||||
|
int mdm_rssi;
|
||||||
|
|
||||||
#if defined(CONFIG_MODEM_UBLOX_SARA_AUTODETECT_VARIANT)
|
#if defined(CONFIG_MODEM_UBLOX_SARA_AUTODETECT_VARIANT)
|
||||||
/* modem variant */
|
/* modem variant */
|
||||||
|
@ -658,13 +659,13 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_cesq)
|
||||||
rsrp = ATOI(argv[5], 0, "rsrp");
|
rsrp = ATOI(argv[5], 0, "rsrp");
|
||||||
rxlev = ATOI(argv[0], 0, "rxlev");
|
rxlev = ATOI(argv[0], 0, "rxlev");
|
||||||
if (rsrp >= 0 && rsrp <= 97) {
|
if (rsrp >= 0 && rsrp <= 97) {
|
||||||
mctx.data_rssi = -140 + (rsrp - 1);
|
mdata.mdm_rssi = -140 + (rsrp - 1);
|
||||||
LOG_INF("RSRP: %d", mctx.data_rssi);
|
LOG_INF("RSRP: %d", mdata.mdm_rssi);
|
||||||
} else if (rxlev >= 0 && rxlev <= 63) {
|
} else if (rxlev >= 0 && rxlev <= 63) {
|
||||||
mctx.data_rssi = -110 + (rxlev - 1);
|
mdata.mdm_rssi = -110 + (rxlev - 1);
|
||||||
LOG_INF("RSSI: %d", mctx.data_rssi);
|
LOG_INF("RSSI: %d", mdata.mdm_rssi);
|
||||||
} else {
|
} else {
|
||||||
mctx.data_rssi = -1000;
|
mdata.mdm_rssi = -1000;
|
||||||
LOG_INF("RSRP/RSSI not known");
|
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");
|
rssi = ATOI(argv[0], 0, "signal_power");
|
||||||
if (rssi == 31) {
|
if (rssi == 31) {
|
||||||
mctx.data_rssi = -46;
|
mdata.mdm_rssi = -46;
|
||||||
} else if (rssi >= 0 && rssi <= 31) {
|
} else if (rssi >= 0 && rssi <= 31) {
|
||||||
/* FIXME: This value depends on the RAT */
|
/* FIXME: This value depends on the RAT */
|
||||||
mctx.data_rssi = -110 + ((rssi * 2) + 1);
|
mdata.mdm_rssi = -110 + ((rssi * 2) + 1);
|
||||||
} else {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1320,13 +1321,13 @@ restart:
|
||||||
counter = 0;
|
counter = 0;
|
||||||
/* wait for RSSI < 0 and > -1000 */
|
/* wait for RSSI < 0 and > -1000 */
|
||||||
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
|
while (counter++ < MDM_WAIT_FOR_RSSI_COUNT &&
|
||||||
(mctx.data_rssi >= 0 ||
|
(mdata.mdm_rssi >= 0 ||
|
||||||
mctx.data_rssi <= -1000)) {
|
mdata.mdm_rssi <= -1000)) {
|
||||||
modem_rssi_query_work(NULL);
|
modem_rssi_query_work(NULL);
|
||||||
k_sleep(MDM_WAIT_FOR_RSSI_DELAY);
|
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++;
|
retry_count++;
|
||||||
if (retry_count >= MDM_NETWORK_RETRY_COUNT) {
|
if (retry_count >= MDM_NETWORK_RETRY_COUNT) {
|
||||||
LOG_ERR("Failed network init. Too many attempts!");
|
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_model = mdata.mdm_model;
|
||||||
mctx.data_revision = mdata.mdm_revision;
|
mctx.data_revision = mdata.mdm_revision;
|
||||||
mctx.data_imei = mdata.mdm_imei;
|
mctx.data_imei = mdata.mdm_imei;
|
||||||
|
mctx.data_rssi = &mdata.mdm_rssi;
|
||||||
|
|
||||||
/* pin setup */
|
/* pin setup */
|
||||||
mctx.pins = modem_pins;
|
mctx.pins = modem_pins;
|
||||||
|
|
|
@ -204,6 +204,7 @@ struct wncm14a2a_iface_ctx {
|
||||||
char mdm_model[MDM_MODEL_LENGTH];
|
char mdm_model[MDM_MODEL_LENGTH];
|
||||||
char mdm_revision[MDM_REVISION_LENGTH];
|
char mdm_revision[MDM_REVISION_LENGTH];
|
||||||
char mdm_imei[MDM_IMEI_LENGTH];
|
char mdm_imei[MDM_IMEI_LENGTH];
|
||||||
|
int mdm_rssi;
|
||||||
|
|
||||||
/* modem state */
|
/* modem state */
|
||||||
int ev_csps;
|
int ev_csps;
|
||||||
|
@ -663,8 +664,8 @@ static void on_cmd_atcmdinfo_rssi(struct net_buf **buf, uint16_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
ictx.mdm_ctx.data_rssi = atoi(value);
|
ictx.mdm_rssi = atoi(value);
|
||||||
LOG_INF("RSSI: %d", ictx.mdm_ctx.data_rssi);
|
LOG_INF("RSSI: %d", ictx.mdm_rssi);
|
||||||
} else {
|
} else {
|
||||||
LOG_WRN("Bad format found for RSSI");
|
LOG_WRN("Bad format found for RSSI");
|
||||||
}
|
}
|
||||||
|
@ -1398,15 +1399,15 @@ restart:
|
||||||
counter = 0;
|
counter = 0;
|
||||||
/* wait for RSSI > -1000 and != 0 */
|
/* wait for RSSI > -1000 and != 0 */
|
||||||
while (counter++ < 15 &&
|
while (counter++ < 15 &&
|
||||||
(ictx.mdm_ctx.data_rssi <= -1000 ||
|
(ictx.mdm_rssi <= -1000 ||
|
||||||
ictx.mdm_ctx.data_rssi == 0)) {
|
ictx.mdm_rssi == 0)) {
|
||||||
/* stop RSSI delay work */
|
/* stop RSSI delay work */
|
||||||
k_work_cancel_delayable(&ictx.rssi_query_work);
|
k_work_cancel_delayable(&ictx.rssi_query_work);
|
||||||
wncm14a2a_rssi_query_work(NULL);
|
wncm14a2a_rssi_query_work(NULL);
|
||||||
k_sleep(K_SECONDS(2));
|
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++;
|
retry_count++;
|
||||||
if (retry_count > 3) {
|
if (retry_count > 3) {
|
||||||
LOG_ERR("Failed network init. Too many attempts!");
|
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
|
#ifdef CONFIG_MODEM_SIM_NUMBERS
|
||||||
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
|
ictx.mdm_ctx.data_imei = ictx.mdm_imei;
|
||||||
#endif
|
#endif
|
||||||
|
ictx.mdm_ctx.data_rssi = &ictx.mdm_rssi;
|
||||||
|
|
||||||
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
|
ret = mdm_receiver_register(&ictx.mdm_ctx, MDM_UART_DEV,
|
||||||
mdm_recv_buf, sizeof(mdm_recv_buf));
|
mdm_recv_buf, sizeof(mdm_recv_buf));
|
||||||
|
|
Loading…
Reference in a new issue