mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-30 07:42:23 +02:00
manager: parse config file
The need to use libusb to check for the modem state on startup now depends on a config option, instead of the device type. The USB PID and VID are moved to config as well.
This commit is contained in:
@@ -19,8 +19,6 @@
|
|||||||
#include <glib-unix.h>
|
#include <glib-unix.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
#define EG25_USB_VID 0x2c7c
|
|
||||||
#define EG25_USB_PID 0x0125
|
|
||||||
#ifndef EG25_CONFDIR
|
#ifndef EG25_CONFDIR
|
||||||
#define EG25_CONFDIR "/etc/eg25-manager"
|
#define EG25_CONFDIR "/etc/eg25-manager"
|
||||||
#endif
|
#endif
|
||||||
@@ -65,14 +63,14 @@ static gboolean modem_start(struct EG25Manager *manager)
|
|||||||
libusb_device **devices = NULL;
|
libusb_device **devices = NULL;
|
||||||
struct libusb_device_descriptor desc;
|
struct libusb_device_descriptor desc;
|
||||||
|
|
||||||
if (manager->braveheart) {
|
if (manager->use_libusb) {
|
||||||
// BH don't have the STATUS line connected, so check if USB device is present
|
// BH don't have the STATUS line connected, so check if USB device is present
|
||||||
libusb_init(&ctx);
|
libusb_init(&ctx);
|
||||||
|
|
||||||
count = libusb_get_device_list(ctx, &devices);
|
count = libusb_get_device_list(ctx, &devices);
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
libusb_get_device_descriptor(devices[i], &desc);
|
libusb_get_device_descriptor(devices[i], &desc);
|
||||||
if (desc.idVendor == EG25_USB_VID && desc.idProduct == EG25_USB_PID) {
|
if (desc.idVendor == manager->usb_vid && desc.idProduct == manager->usb_pid) {
|
||||||
g_message("Found corresponding USB device, modem already powered");
|
g_message("Found corresponding USB device, modem already powered");
|
||||||
should_boot = FALSE;
|
should_boot = FALSE;
|
||||||
break;
|
break;
|
||||||
@@ -266,6 +264,7 @@ int main(int argc, char *argv[])
|
|||||||
struct EG25Manager manager;
|
struct EG25Manager manager;
|
||||||
gchar *config_file = NULL;
|
gchar *config_file = NULL;
|
||||||
toml_table_t *toml_config;
|
toml_table_t *toml_config;
|
||||||
|
toml_table_t *toml_manager;
|
||||||
toml_datum_t toml_value;
|
toml_datum_t toml_value;
|
||||||
const GOptionEntry options[] = {
|
const GOptionEntry options[] = {
|
||||||
{ "gnss", 'g', 0, G_OPTION_ARG_NONE, &manager.manage_gnss, "Manage the GNSS feature.", NULL },
|
{ "gnss", 'g', 0, G_OPTION_ARG_NONE, &manager.manage_gnss, "Manage the GNSS feature.", NULL },
|
||||||
@@ -289,6 +288,21 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
toml_config = parse_config_file(config_file);
|
toml_config = parse_config_file(config_file);
|
||||||
|
|
||||||
|
toml_manager = toml_table_in(toml_config, "manager");
|
||||||
|
if (toml_manager) {
|
||||||
|
toml_value = toml_bool_in(toml_manager, "need_libusb");
|
||||||
|
if (toml_value.ok)
|
||||||
|
manager.use_libusb = toml_value.u.b;
|
||||||
|
|
||||||
|
toml_value = toml_int_in(toml_manager, "usb_vid");
|
||||||
|
if (toml_value.ok)
|
||||||
|
manager.usb_vid = toml_value.u.i;
|
||||||
|
|
||||||
|
toml_value = toml_int_in(toml_manager, "usb_pid");
|
||||||
|
if (toml_value.ok)
|
||||||
|
manager.usb_pid = toml_value.u.i;
|
||||||
|
}
|
||||||
|
|
||||||
at_init(&manager, toml_table_in(toml_config, "at"));
|
at_init(&manager, toml_table_in(toml_config, "at"));
|
||||||
gpio_init(&manager, toml_table_in(toml_config, "gpio"));
|
gpio_init(&manager, toml_table_in(toml_config, "gpio"));
|
||||||
mm_iface_init(&manager, toml_table_in(toml_config, "mm-iface"));
|
mm_iface_init(&manager, toml_table_in(toml_config, "mm-iface"));
|
||||||
|
@@ -31,6 +31,9 @@ struct EG25Manager {
|
|||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
guint reset_timer;
|
guint reset_timer;
|
||||||
gboolean manage_gnss;
|
gboolean manage_gnss;
|
||||||
|
gboolean use_libusb;
|
||||||
|
guint usb_vid;
|
||||||
|
guint usb_pid;
|
||||||
|
|
||||||
int at_fd;
|
int at_fd;
|
||||||
guint at_source;
|
guint at_source;
|
||||||
@@ -38,7 +41,6 @@ struct EG25Manager {
|
|||||||
|
|
||||||
enum EG25State modem_state;
|
enum EG25State modem_state;
|
||||||
gchar *modem_usb_id;
|
gchar *modem_usb_id;
|
||||||
gboolean braveheart;
|
|
||||||
|
|
||||||
guint mm_watch;
|
guint mm_watch;
|
||||||
MMManager *mm_manager;
|
MMManager *mm_manager;
|
||||||
|
Reference in New Issue
Block a user