mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
Executing a reset each time the modem is unbound is a bit too extreme: the modem sometimes recovers by itself and only needs a "soft" reset sequence (unbind/bind). This commit introduces a short timer (2s) so we the modem can settle in. If reset fails after this time, the modem is probably completely broken, or already rebooting, so we can safely issue a reset AT command.
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
/*
|
|
* Copyright (C) 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
#include "udev.h"
|
|
|
|
#include <string.h>
|
|
|
|
static void udev_event_cb(GUdevClient *client, gchar *action, GUdevDevice *device, gpointer data)
|
|
{
|
|
struct EG25Manager *manager = data;
|
|
|
|
if (strcmp(action, "unbind") != 0 ||
|
|
manager->modem_state == EG25_STATE_RESETTING ||
|
|
!manager->modem_usb_id) {
|
|
return;
|
|
}
|
|
|
|
if (strcmp(g_udev_device_get_name(device), manager->modem_usb_id) == 0 &&
|
|
manager->reset_timer == 0) {
|
|
g_message("Lost modem, resetting...");
|
|
g_timeout_add_seconds(2, G_SOURCE_FUNC(modem_reset), manager);
|
|
}
|
|
}
|
|
|
|
void udev_init (struct EG25Manager *manager, toml_table_t *config[])
|
|
{
|
|
const char * const subsystems[] = { "usb", NULL };
|
|
|
|
manager->udev = g_udev_client_new(subsystems);
|
|
g_signal_connect(manager->udev, "uevent", G_CALLBACK(udev_event_cb), manager);
|
|
|
|
return;
|
|
}
|
|
|
|
void udev_destroy (struct EG25Manager *manager)
|
|
{
|
|
if (manager->udev) {
|
|
g_object_unref(manager->udev);
|
|
manager->udev = NULL;
|
|
}
|
|
}
|