at: clear command queue before configuring modem

In some cases, there might be an issue with `eg25-manager` trying to
reset the modem while it's being configured. This leads to infinite boot
loops where the modem is constantly reset soon after it booted.

Fixes #24
This commit is contained in:
Arnaud Ferraris
2021-10-04 18:20:46 +02:00
parent 8ae79fa34c
commit 0f3e51cd06

View File

@@ -47,6 +47,21 @@ static int configure_serial(const char *tty)
return fd; return fd;
} }
static void at_free_command(struct AtCommand *at_cmd, struct EG25Manager *manager)
{
if (!at_cmd)
return;
g_free(at_cmd->cmd);
g_free(at_cmd->subcmd);
g_free(at_cmd->value);
g_free(at_cmd->expected);
g_free(at_cmd);
if (manager && manager->at_cmds)
manager->at_cmds = g_list_remove(manager->at_cmds, at_cmd);
}
gboolean at_send_command(struct EG25Manager *manager) gboolean at_send_command(struct EG25Manager *manager)
{ {
char command[256]; char command[256];
@@ -139,16 +154,7 @@ void at_next_command(struct EG25Manager *manager)
{ {
struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL; struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL;
if (!at_cmd) at_free_command(at_cmd, manager);
return;
g_free(at_cmd->cmd);
g_free(at_cmd->subcmd);
g_free(at_cmd->value);
g_free(at_cmd->expected);
g_free(at_cmd);
manager->at_cmds = g_list_remove(manager->at_cmds, at_cmd);
at_send_command(manager); at_send_command(manager);
} }
@@ -388,6 +394,13 @@ void at_destroy(struct EG25Manager *manager)
void at_sequence_configure(struct EG25Manager *manager) void at_sequence_configure(struct EG25Manager *manager)
{ {
/*
* When configuring a new modem we should avoid processing an old
* command queue, so let's first clear the whole list
*/
if (manager->at_cmds)
g_list_foreach(manager->at_cmds, at_free_command, manager);
for (guint i = 0; i < configure_commands->len; i++) { for (guint i = 0; i < configure_commands->len; i++) {
struct AtCommand *cmd = &g_array_index(configure_commands, struct AtCommand, i); struct AtCommand *cmd = &g_array_index(configure_commands, struct AtCommand, i);
at_append_command(manager, cmd->cmd, cmd->subcmd, cmd->value, cmd->expected, at_process_result); at_append_command(manager, cmd->cmd, cmd->subcmd, cmd->value, cmd->expected, at_process_result);