modem-helpers: setup common RSSI to signal quality converter

This commit is contained in:
Aleksander Morgado
2021-10-17 21:58:54 +02:00
parent e1bc4b0999
commit c01f22804e
4 changed files with 14 additions and 16 deletions

View File

@@ -767,10 +767,8 @@ get_one_quality (const gchar *reply,
} }
} }
if (success) { if (success)
dbm = CLAMP (dbm, -113, -51); quality = MM_RSSI_TO_QUALITY (dbm);
quality = 100 - ((dbm + 51) * 100 / (-113 + 51));
}
g_free (temp); g_free (temp);
return quality; return quality;

View File

@@ -1297,10 +1297,6 @@ modem_load_supported_ip_families (MMIfaceModem *self,
/*****************************************************************************/ /*****************************************************************************/
/* Load signal quality (Modem interface) */ /* Load signal quality (Modem interface) */
/* Limit the value betweeen [-113,-51] and scale it to a percentage */
#define STRENGTH_TO_QUALITY(strength) \
(guint8)(100 - ((CLAMP (strength, -113, -51) + 51) * 100 / (-113 + 51)))
static gboolean static gboolean
qmi_dbm_valid (gint8 dbm, QmiNasRadioInterface radio_interface) qmi_dbm_valid (gint8 dbm, QmiNasRadioInterface radio_interface)
{ {
@@ -1407,7 +1403,7 @@ common_signal_info_get_quality (MMBroadbandModemQmi *self,
if (rssi_max < 0 && rssi_max > -125) { if (rssi_max < 0 && rssi_max > -125) {
/* This RSSI comes as negative dBms */ /* This RSSI comes as negative dBms */
*out_quality = STRENGTH_TO_QUALITY (rssi_max); *out_quality = MM_RSSI_TO_QUALITY (rssi_max);
*out_act = mm_modem_access_technology_from_qmi_radio_interface (signal_info_radio_interface); *out_act = mm_modem_access_technology_from_qmi_radio_interface (signal_info_radio_interface);
mm_obj_dbg (self, "RSSI: %d dBm --> %u%%", rssi_max, *out_quality); mm_obj_dbg (self, "RSSI: %d dBm --> %u%%", rssi_max, *out_quality);
@@ -1538,7 +1534,7 @@ signal_strength_get_quality_and_access_tech (MMBroadbandModemQmi *self,
if (signal_max < 0) { if (signal_max < 0) {
/* This signal strength comes as negative dBms */ /* This signal strength comes as negative dBms */
*o_quality = STRENGTH_TO_QUALITY (signal_max); *o_quality = MM_RSSI_TO_QUALITY (signal_max);
*o_act = act; *o_act = act;
mm_obj_dbg (self, "signal strength: %d dBm --> %u%%", signal_max, *o_quality); mm_obj_dbg (self, "signal strength: %d dBm --> %u%%", signal_max, *o_quality);
@@ -5064,7 +5060,7 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task)
/* The device doesn't really like to have many threshold values, so don't /* The device doesn't really like to have many threshold values, so don't
* grow this array without checking first * grow this array without checking first
* The values are chosen towards their results through STRENGTH_TO_QUALITY * The values are chosen towards their results through MM_RSSI_TO_QUALITY
* -106 dBm gives 11% * -106 dBm gives 11%
* -94 dBm gives 30% * -94 dBm gives 30%
* -82 dBm gives 50% * -82 dBm gives 50%
@@ -5377,7 +5373,7 @@ nas_event_report_indication_cb (QmiClientNas *client,
guint8 quality; guint8 quality;
/* This signal strength comes as negative dBms */ /* This signal strength comes as negative dBms */
quality = STRENGTH_TO_QUALITY (signal_strength); quality = MM_RSSI_TO_QUALITY (signal_strength);
mm_obj_dbg (self, "signal strength indication (%s): %d dBm --> %u%%", mm_obj_dbg (self, "signal strength indication (%s): %d dBm --> %u%%",
qmi_nas_radio_interface_get_string (signal_strength_radio_interface), qmi_nas_radio_interface_get_string (signal_strength_radio_interface),

View File

@@ -2068,16 +2068,13 @@ modem_load_signal_quality_finish (MMIfaceModem *self,
static guint static guint
signal_quality_evdo_pilot_sets (MMBroadbandModem *self) signal_quality_evdo_pilot_sets (MMBroadbandModem *self)
{ {
gint dbm;
if (self->priv->modem_cdma_evdo_registration_state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) if (self->priv->modem_cdma_evdo_registration_state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN)
return 0; return 0;
if (self->priv->evdo_pilot_rssi >= 0) if (self->priv->evdo_pilot_rssi >= 0)
return 0; return 0;
dbm = CLAMP (self->priv->evdo_pilot_rssi, -113, -51); return MM_RSSI_TO_QUALITY (self->priv->evdo_pilot_rssi);
return 100 - ((dbm + 51) * 100 / (-113 + 51));
} }
static void static void

View File

@@ -569,6 +569,13 @@ gboolean mm_sim_parse_cpol_test_response (const gchar *response,
* and in order to avoid -Wtype-limits warnings. */ * and in order to avoid -Wtype-limits warnings. */
#define MM_CLAMP_HIGH(x, high) (((x) > (high)) ? (high) : (x)) #define MM_CLAMP_HIGH(x, high) (((x) > (high)) ? (high) : (x))
/*****************************************************************************/
/* Signal quality percentage from different sources */
/* Limit the value betweeen [-113,-51] and scale it to a percentage */
#define MM_RSSI_TO_QUALITY(rssi) \
(guint8)(100 - ((CLAMP (rssi, -113, -51) + 51) * 100 / (-113 + 51)))
/*****************************************************************************/ /*****************************************************************************/
/* Helper function to decode eid read from esim */ /* Helper function to decode eid read from esim */