diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-18 12:13:46 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-18 13:47:34 +0100 |
commit | 30639606d35dcc323cb13a29b6e0627aad87dd8d (patch) | |
tree | c4801df654a93406a4d6dcbe3be7440f97101892 /plugins/mbm | |
parent | 263be58465ba0e449d73b65fd69d5dc10423a78f (diff) |
broadband-modem: new step during 'enabling_started' to initialize the modem
We previously had the modem initialization command merged with some other port
setup commands in the 'modem_init' step of the 'Modem' interface. Instead of
doing this, we now split the logic into two separate steps:
A first 'enabling_modem_init' modem initialization step is to be run just after
the ports have been opened, but only during the first enabling operation, and
only if the modem was not hotplugged. A hotplugged modem is assumed to be
properly initialized already, so no need to ATZ-it. Also, we will now wait 500ms
by default after the modem initialization command has been sent, to let it
settle down.
The second 'modem_init' step will be run during the 'Modem' interface
initialization, and it currently only holds specific setup of the primary and
secondary serial ports. We'll be modifying this logic a bit in the next commits,
so no big deal to have that step name unchanged.
Diffstat (limited to 'plugins/mbm')
-rw-r--r-- | plugins/mbm/mm-broadband-modem-mbm.c | 96 |
1 files changed, 64 insertions, 32 deletions
diff --git a/plugins/mbm/mm-broadband-modem-mbm.c b/plugins/mbm/mm-broadband-modem-mbm.c index a5738761..39648cf6 100644 --- a/plugins/mbm/mm-broadband-modem-mbm.c +++ b/plugins/mbm/mm-broadband-modem-mbm.c @@ -307,63 +307,93 @@ set_allowed_modes (MMIfaceModem *_self, /*****************************************************************************/ /* Initializing the modem (Modem interface) */ +static gboolean +modem_init_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + /* Ignore errors */ + mm_base_modem_at_command_full_finish (MM_BASE_MODEM (self), res, NULL); + return TRUE; +} + +static void +modem_init (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + mm_base_modem_at_command_full (MM_BASE_MODEM (self), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), + "E0 V1 X4 &C1 +CMEE=1", + 3, + FALSE, + FALSE, + NULL, /* cancellable */ + callback, + user_data); +} + +/*****************************************************************************/ +/* Initializing the modem (during first enabling) */ + typedef struct { GSimpleAsyncResult *result; MMBroadbandModemMbm *self; -} ModemInitContext; +} EnablingModemInitContext; static void -modem_init_context_complete_and_free (ModemInitContext *ctx) +enabling_modem_init_context_complete_and_free (EnablingModemInitContext *ctx) { g_simple_async_result_complete (ctx->result); g_object_unref (ctx->result); g_object_unref (ctx->self); - g_slice_free (ModemInitContext, ctx); + g_slice_free (EnablingModemInitContext, ctx); } static gboolean -modem_init_finish (MMIfaceModem *self, - GAsyncResult *res, - GError **error) +enabling_modem_init_finish (MMBroadbandModem *self, + GAsyncResult *res, + GError **error) { - /* Ignore errors */ - mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, NULL); - return TRUE; + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); } static void -init_sequence_ready (MMBaseModem *self, - GAsyncResult *res, - ModemInitContext *ctx) +enabling_init_sequence_ready (MMBaseModem *self, + GAsyncResult *res, + EnablingModemInitContext *ctx) { - mm_base_modem_at_sequence_finish (self, res, NULL, NULL); + /* Ignore errors */ + mm_base_modem_at_sequence_full_finish (self, res, NULL, NULL); g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); - modem_init_context_complete_and_free (ctx); + enabling_modem_init_context_complete_and_free (ctx); } -static const MMBaseModemAtCommand modem_init_sequence[] = { +static const MMBaseModemAtCommand enabling_modem_init_sequence[] = { /* Init command */ - { "&F E0 V1 X4 &C1 +CMEE=1", 3, FALSE, NULL }, + { "&F", 3, FALSE, NULL }, /* Ensure disconnected */ { "*ENAP=0", 3, FALSE, NULL }, { NULL } }; static void -run_init_sequence (ModemInitContext *ctx) +run_enabling_init_sequence (EnablingModemInitContext *ctx) { - mm_base_modem_at_sequence (MM_BASE_MODEM (ctx->self), - modem_init_sequence, - NULL, /* response_processor_context */ - NULL, /* response_processor_context_free */ - (GAsyncReadyCallback)init_sequence_ready, - ctx); + mm_base_modem_at_sequence_full (MM_BASE_MODEM (ctx->self), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (ctx->self)), + enabling_modem_init_sequence, + NULL, /* response_processor_context */ + NULL, /* response_processor_context_free */ + NULL, /* cancellable */ + (GAsyncReadyCallback)enabling_init_sequence_ready, + ctx); } static void emrdy_ready (MMBaseModem *self, GAsyncResult *res, - ModemInitContext *ctx) + EnablingModemInitContext *ctx) { GError *error = NULL; @@ -386,26 +416,26 @@ emrdy_ready (MMBaseModem *self, g_error_free (error); } - run_init_sequence (ctx); + run_enabling_init_sequence (ctx); } static void -modem_init (MMIfaceModem *self, - GAsyncReadyCallback callback, - gpointer user_data) +enabling_modem_init (MMBroadbandModem *self, + GAsyncReadyCallback callback, + gpointer user_data) { - ModemInitContext *ctx; + EnablingModemInitContext *ctx; - ctx = g_slice_new0 (ModemInitContext); + ctx = g_slice_new0 (EnablingModemInitContext); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - modem_init); + enabling_modem_init); ctx->self = g_object_ref (self); /* Modem is ready?, no need to check EMRDY */ if (ctx->self->priv->have_emrdy) { - run_init_sequence (ctx); + run_enabling_init_sequence (ctx); return; } @@ -1143,4 +1173,6 @@ mm_broadband_modem_mbm_class_init (MMBroadbandModemMbmClass *klass) object_class->finalize = finalize; broadband_modem_class->setup_ports = setup_ports; + broadband_modem_class->enabling_modem_init = enabling_modem_init; + broadband_modem_class->enabling_modem_init_finish = enabling_modem_init_finish; } |