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.
This commit is contained in:
Jonas Bonn 2019-03-12 12:09:58 +01:00 committed by Denis Kenzior
parent 55bec598b6
commit d7844183c0
2 changed files with 71 additions and 0 deletions

View File

@ -23,6 +23,8 @@
#include <config.h>
#endif
#include <string.h>
#include <glib.h>
#include <gatchat.h>
@ -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();

View File

@ -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);