From d7844183c0592783fac7f08a13a3aa6d0382ff5c Mon Sep 17 00:00:00 2001 From: Jonas Bonn Date: Tue, 12 Mar 2019 12:09:58 +0100 Subject: [PATCH] ublox: create model data structures This sets up some device model data structures and adds some helpers for manipulating them. These data structures are a first step to trying to support the large number of devices that ublox produces with a common driver structure. --- drivers/ubloxmodem/ubloxmodem.c | 57 +++++++++++++++++++++++++++++++++ drivers/ubloxmodem/ubloxmodem.h | 14 ++++++++ 2 files changed, 71 insertions(+) diff --git a/drivers/ubloxmodem/ubloxmodem.c b/drivers/ubloxmodem/ubloxmodem.c index a325b1f0..c60b6d3f 100644 --- a/drivers/ubloxmodem/ubloxmodem.c +++ b/drivers/ubloxmodem/ubloxmodem.c @@ -23,6 +23,8 @@ #include #endif +#include + #include #include @@ -33,6 +35,61 @@ #include "ubloxmodem.h" +const struct ublox_model ublox_models[] = { + { + .name = "SARA-G270", + }, + /* TOBY L2 series */ + { + .name = "TOBY-L200", + .flags = UBLOX_F_TOBY_L2, + }, + { + .name = "TOBY-L201", + .flags = UBLOX_F_TOBY_L2, + }, + { + .name = "TOBY-L210", + .flags = UBLOX_F_TOBY_L2, + }, + { + .name = "TOBY-L220", + .flags = UBLOX_F_TOBY_L2, + }, + { + .name = "TOBY-L280", + .flags = UBLOX_F_TOBY_L2, + }, + { /* sentinel */ }, +}; + +const struct ublox_model *ublox_model_from_name(const char *name) +{ + const struct ublox_model *m; + + for (m = ublox_models; m->name; m++) { + if (!strcmp(name, m->name)) + return m; + } + + return NULL; +} + +const struct ublox_model *ublox_model_from_id(int id) +{ + return ublox_models + id; +} + +int ublox_model_to_id(const struct ublox_model *model) +{ + return model - ublox_models; +} + +int ublox_is_toby_l2(const struct ublox_model *model) +{ + return model->flags & UBLOX_F_TOBY_L2; +} + static int ubloxmodem_init(void) { ublox_gprs_context_init(); diff --git a/drivers/ubloxmodem/ubloxmodem.h b/drivers/ubloxmodem/ubloxmodem.h index bfb01064..7c7b159a 100644 --- a/drivers/ubloxmodem/ubloxmodem.h +++ b/drivers/ubloxmodem/ubloxmodem.h @@ -23,6 +23,20 @@ #define UBLOXMODEM "ubloxmodem" +enum ublox_flags { + UBLOX_F_TOBY_L2 = (1 << 0), +}; + +struct ublox_model { + char *name; + int flags; +}; + +const struct ublox_model *ublox_model_from_name(const char *name); +const struct ublox_model *ublox_model_from_id(int id); +int ublox_model_to_id(const struct ublox_model *model); +int ublox_is_toby_l2(const struct ublox_model *model); + extern void ublox_gprs_context_init(void); extern void ublox_gprs_context_exit(void);