aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2024-02-13 10:39:43 -0600
committerAleksander Morgado <aleksander@aleksander.es>2024-02-19 11:24:27 +0000
commitded76a0abbc7c97281d380e5431861fd16c23aa0 (patch)
treeb3d558e1e6a3d89ed410cde1fd644bf0dbc060ee /src
parentb3708636b190f98b8c0f4877981cb850d90d6845 (diff)
base-modem-at: add optional wait before sending command in a sequence
Can be used for easier command retries where the generic sequence code handles the GTimeout source. Signed-off-by: Dan Williams <dcbw@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/mm-base-modem-at.c44
-rw-r--r--src/mm-base-modem-at.h3
2 files changed, 37 insertions, 10 deletions
diff --git a/src/mm-base-modem-at.c b/src/mm-base-modem-at.c
index ed354063..cc2bc5a0 100644
--- a/src/mm-base-modem-at.c
+++ b/src/mm-base-modem-at.c
@@ -91,8 +91,13 @@ typedef struct {
gpointer response_processor_context;
GDestroyNotify response_processor_context_free;
GVariant *result;
+ guint next_command_wait_id;
} AtSequenceContext;
+static void at_sequence_parse_response (MMPortSerialAt *port,
+ GAsyncResult *res,
+ GTask *task);
+
static void
at_sequence_context_free (AtSequenceContext *ctx)
{
@@ -109,6 +114,11 @@ at_sequence_context_free (AtSequenceContext *ctx)
g_object_unref (ctx->parent_cancellable);
}
+ if (ctx->next_command_wait_id > 0) {
+ g_source_remove (ctx->next_command_wait_id);
+ ctx->next_command_wait_id = 0;
+ }
+
if (ctx->result)
g_variant_unref (ctx->result);
g_free (ctx);
@@ -140,6 +150,28 @@ mm_base_modem_at_sequence_full_finish (MMBaseModem *self,
return result;
}
+static gboolean
+at_sequence_next_command (GTask *task)
+{
+ AtSequenceContext *ctx;
+
+ ctx = g_task_get_task_data (task);
+ ctx->next_command_wait_id = 0;
+
+ /* Schedule the next command in the probing group */
+ mm_port_serial_at_command (
+ ctx->port,
+ ctx->current->command,
+ ctx->current->timeout,
+ FALSE,
+ ctx->current->allow_cached,
+ g_task_get_cancellable (task),
+ (GAsyncReadyCallback)at_sequence_parse_response,
+ task);
+
+ return G_SOURCE_REMOVE;
+}
+
static void
at_sequence_parse_response (MMPortSerialAt *port,
GAsyncResult *res,
@@ -201,16 +233,8 @@ at_sequence_parse_response (MMPortSerialAt *port,
if (processor_result == MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE) {
ctx->current++;
if (ctx->current->command) {
- /* Schedule the next command in the probing group */
- mm_port_serial_at_command (
- ctx->port,
- ctx->current->command,
- ctx->current->timeout,
- FALSE,
- ctx->current->allow_cached,
- g_task_get_cancellable (task),
- (GAsyncReadyCallback)at_sequence_parse_response,
- task);
+ g_assert (!ctx->next_command_wait_id);
+ ctx->next_command_wait_id = g_timeout_add_seconds (ctx->current->wait_seconds, (GSourceFunc) at_sequence_next_command, task);
return;
}
/* On last command, end. */
diff --git a/src/mm-base-modem-at.h b/src/mm-base-modem-at.h
index 770c0e4b..ae9b0be7 100644
--- a/src/mm-base-modem-at.h
+++ b/src/mm-base-modem-at.h
@@ -67,6 +67,8 @@ typedef struct {
gboolean allow_cached;
/* The response processor */
MMBaseModemAtResponseProcessor response_processor;
+ /* Time to wait before sending this command (in seconds) */
+ guint wait_seconds;
} MMBaseModemAtCommand;
/* Generic AT sequence handling, using the best AT port available and without
@@ -220,6 +222,7 @@ typedef struct {
guint timeout;
gboolean allow_cached;
MMBaseModemAtResponseProcessor response_processor;
+ guint wait_seconds;
} MMBaseModemAtCommandAlloc;
G_STATIC_ASSERT (sizeof (MMBaseModemAtCommandAlloc) == sizeof (MMBaseModemAtCommand));