From 9fa1b32e34e24a710b1badece7becaa44e83fb94 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 20 May 2022 15:13:25 +0200 Subject: [PATCH] cli: don't print signal quality unless modem is enabled We don't have a clear way to report "unknown" signal quality, so for now just skip printing it altogether in the mmcli human output if the modem is not yet enabled. --- cli/mmcli-modem.c | 2 +- cli/mmcli-output.c | 12 ++++++++---- cli/mmcli-output.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index f8fa6c1b..54ed3414 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -383,7 +383,7 @@ print_modem_info (void) mmcli_output_state (mm_modem_get_state (ctx->modem), mm_modem_get_state_failed_reason (ctx->modem)); mmcli_output_string (MMC_F_STATUS_POWER_STATE, mm_modem_power_state_get_string (mm_modem_get_power_state (ctx->modem))); mmcli_output_string_list (MMC_F_STATUS_ACCESS_TECH, access_technologies_string); - mmcli_output_signal_quality (signal_quality, signal_quality_recent); + mmcli_output_signal_quality (mm_modem_get_state (ctx->modem), signal_quality, signal_quality_recent); mmcli_output_string_multiline (MMC_F_MODES_SUPPORTED, supported_modes_string); mmcli_output_string_take (MMC_F_MODES_CURRENT, g_strdup_printf ("allowed: %s; preferred: %s", diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 14367bf5..ff0dd23a 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -594,13 +594,17 @@ mmcli_output_listitem (MmcF field, /* (Custom) Signal quality output */ void -mmcli_output_signal_quality (guint value, - gboolean recent) +mmcli_output_signal_quality (MMModemState state, + guint value, + gboolean recent) { /* Merge value and recent flag in a single item in human output */ if (selected_type == MMC_OUTPUT_TYPE_HUMAN) { - output_item_new_take_single (MMC_F_STATUS_SIGNAL_QUALITY_VALUE, - g_strdup_printf ("%u%% (%s)", value, recent ? "recent" : "cached")); + if (state >= MM_MODEM_STATE_ENABLED) + output_item_new_take_single (MMC_F_STATUS_SIGNAL_QUALITY_VALUE, + g_strdup_printf ("%u%% (%s)", value, recent ? "recent" : "cached")); + else + output_item_new_take_single (MMC_F_STATUS_SIGNAL_QUALITY_VALUE, NULL); return; } diff --git a/cli/mmcli-output.h b/cli/mmcli-output.h index 180debd4..309fc8e9 100644 --- a/cli/mmcli-output.h +++ b/cli/mmcli-output.h @@ -381,7 +381,8 @@ void mmcli_output_listitem (MmcF field, /******************************************************************************/ /* Custom output management */ -void mmcli_output_signal_quality (guint value, +void mmcli_output_signal_quality (MMModemState state, + guint value, gboolean recent); void mmcli_output_start_date (guint64 value); void mmcli_output_state (MMModemState state,