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.
This commit is contained in:
Aleksander Morgado
2013-02-18 13:47:34 +01:00
parent 263be58465
commit 30639606d3
7 changed files with 299 additions and 252 deletions
+10 -71
View File
@@ -46,14 +46,6 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemIridium, mm_broadband_modem_iridium, MM_
/*****************************************************************************/
/* Initializing the modem (Modem interface) */
static gboolean
modem_init_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error)
{
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
}
static const MMBaseModemAtCommand modem_init_sequence[] = {
/* Init command */
{ "E0 V1", 3, FALSE, NULL },
@@ -61,58 +53,12 @@ static const MMBaseModemAtCommand modem_init_sequence[] = {
{ NULL }
};
static void
init_sequence_ready (MMBroadbandModem *self,
GAsyncResult *res,
GSimpleAsyncResult *simple)
{
GError *error = NULL;
mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, &error);
if (error)
g_simple_async_result_take_error (simple, error);
else
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
static gboolean
after_atz_sleep_cb (GSimpleAsyncResult *simple)
modem_init_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error)
{
MMBaseModem *self;
self = MM_BASE_MODEM (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
/* Now, run the remaining sequence */
mm_base_modem_at_sequence (self,
modem_init_sequence,
NULL, /* response_processor_context */
NULL, /* response_processor_context_free */
(GAsyncReadyCallback)init_sequence_ready,
simple);
g_object_unref (self);
return FALSE;
}
static void
atz_ready (MMBroadbandModem *self,
GAsyncResult *res,
GSimpleAsyncResult *simple)
{
GError *error = NULL;
mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
return;
}
/* Once ATZ reply is received, we need to wait a bit before going on,
* otherwise, the next commands given will receive garbage as reply
* (500ms should be enough) */
g_timeout_add (500, (GSourceFunc)after_atz_sleep_cb, simple);
return !!mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error);
}
static void
@@ -120,19 +66,12 @@ modem_init (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *result;
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_init);
/* First, send ATZ alone */
mm_base_modem_at_command (MM_BASE_MODEM (self),
"Z",
3,
TRUE,
(GAsyncReadyCallback)atz_ready,
result);
mm_base_modem_at_sequence (MM_BASE_MODEM (self),
modem_init_sequence,
NULL, /* response_processor_context */
NULL, /* response_processor_context_free */
callback,
user_data);
}
/*****************************************************************************/