From c8b2d89354f5bbb18dec40bd829fd83199828583 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 3 Jul 2016 16:19:58 +0200 Subject: [PATCH] Set the default model number. When the device family is provided without an explicit model number, we simply choose the first available model. But since new models are being added all the time, this default model is not guaranteed to remain the same. That's not desirable because it can alter the behaviour of the application. The introduction of the Aeris 500AI is an example of this problem. The default model in the vtpro family used to be the Oceanic Versa Pro. But because the Aeris 500AI has a lower model number, it automatically became the new default model. Since both use a different protocol variant (MOD vs INTR) they are not interchangable. The default model is now hardcoded. The best option is of course to provide the model number explicitly! --- examples/common.c | 78 +++++++++++++++++++++++++++-------------------- examples/common.h | 3 ++ examples/dctool.c | 8 +++++ 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/examples/common.c b/examples/common.c index 0b4f95b..3c4561b 100644 --- a/examples/common.c +++ b/examples/common.c @@ -41,42 +41,43 @@ typedef struct backend_table_t { const char *name; dc_family_t type; + unsigned int model; } backend_table_t; static const backend_table_t g_backends[] = { - {"solution", DC_FAMILY_SUUNTO_SOLUTION}, - {"eon", DC_FAMILY_SUUNTO_EON}, - {"vyper", DC_FAMILY_SUUNTO_VYPER}, - {"vyper2", DC_FAMILY_SUUNTO_VYPER2}, - {"d9", DC_FAMILY_SUUNTO_D9}, - {"eonsteel", DC_FAMILY_SUUNTO_EONSTEEL}, - {"aladin", DC_FAMILY_UWATEC_ALADIN}, - {"memomouse", DC_FAMILY_UWATEC_MEMOMOUSE}, - {"smart", DC_FAMILY_UWATEC_SMART}, - {"meridian", DC_FAMILY_UWATEC_MERIDIAN}, - {"sensus", DC_FAMILY_REEFNET_SENSUS}, - {"sensuspro", DC_FAMILY_REEFNET_SENSUSPRO}, - {"sensusultra", DC_FAMILY_REEFNET_SENSUSULTRA}, - {"vtpro", DC_FAMILY_OCEANIC_VTPRO}, - {"veo250", DC_FAMILY_OCEANIC_VEO250}, - {"atom2", DC_FAMILY_OCEANIC_ATOM2}, - {"nemo", DC_FAMILY_MARES_NEMO}, - {"puck", DC_FAMILY_MARES_PUCK}, - {"darwin", DC_FAMILY_MARES_DARWIN}, - {"iconhd", DC_FAMILY_MARES_ICONHD}, - {"ostc", DC_FAMILY_HW_OSTC}, - {"frog", DC_FAMILY_HW_FROG}, - {"ostc3", DC_FAMILY_HW_OSTC3}, - {"edy", DC_FAMILY_CRESSI_EDY}, - {"leonardo", DC_FAMILY_CRESSI_LEONARDO}, - {"n2ition3", DC_FAMILY_ZEAGLE_N2ITION3}, - {"cobalt", DC_FAMILY_ATOMICS_COBALT}, - {"predator", DC_FAMILY_SHEARWATER_PREDATOR}, - {"petrel", DC_FAMILY_SHEARWATER_PETREL}, - {"nitekq", DC_FAMILY_DIVERITE_NITEKQ}, - {"aqualand", DC_FAMILY_CITIZEN_AQUALAND}, - {"idive", DC_FAMILY_DIVESYSTEM_IDIVE}, - {"cochran", DC_FAMILY_COCHRAN_COMMANDER}, + {"solution", DC_FAMILY_SUUNTO_SOLUTION, 0}, + {"eon", DC_FAMILY_SUUNTO_EON, 0}, + {"vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A}, + {"vyper2", DC_FAMILY_SUUNTO_VYPER2, 0x10}, + {"d9", DC_FAMILY_SUUNTO_D9, 0x0E}, + {"eonsteel", DC_FAMILY_SUUNTO_EONSTEEL, 0}, + {"aladin", DC_FAMILY_UWATEC_ALADIN, 0x3F}, + {"memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0}, + {"smart", DC_FAMILY_UWATEC_SMART, 0x10}, + {"meridian", DC_FAMILY_UWATEC_MERIDIAN, 0x20}, + {"sensus", DC_FAMILY_REEFNET_SENSUS, 1}, + {"sensuspro", DC_FAMILY_REEFNET_SENSUSPRO, 2}, + {"sensusultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3}, + {"vtpro", DC_FAMILY_OCEANIC_VTPRO, 0x4245}, + {"veo250", DC_FAMILY_OCEANIC_VEO250, 0x424C}, + {"atom2", DC_FAMILY_OCEANIC_ATOM2, 0x4342}, + {"nemo", DC_FAMILY_MARES_NEMO, 0}, + {"puck", DC_FAMILY_MARES_PUCK, 7}, + {"darwin", DC_FAMILY_MARES_DARWIN, 0}, + {"iconhd", DC_FAMILY_MARES_ICONHD, 0x14}, + {"ostc", DC_FAMILY_HW_OSTC, 0}, + {"frog", DC_FAMILY_HW_FROG, 0}, + {"ostc3", DC_FAMILY_HW_OSTC3, 0x0A}, + {"edy", DC_FAMILY_CRESSI_EDY, 0x08}, + {"leonardo", DC_FAMILY_CRESSI_LEONARDO, 1}, + {"n2ition3", DC_FAMILY_ZEAGLE_N2ITION3, 0}, + {"cobalt", DC_FAMILY_ATOMICS_COBALT, 0}, + {"predator", DC_FAMILY_SHEARWATER_PREDATOR, 2}, + {"petrel", DC_FAMILY_SHEARWATER_PETREL, 3}, + {"nitekq", DC_FAMILY_DIVERITE_NITEKQ, 0}, + {"aqualand", DC_FAMILY_CITIZEN_AQUALAND, 0}, + {"idive", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03}, + {"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0}, }; const char * @@ -132,6 +133,17 @@ dctool_family_name (dc_family_t type) return NULL; } +unsigned int +dctool_family_model (dc_family_t type) +{ + for (unsigned int i = 0; i < C_ARRAY_SIZE (g_backends); ++i) { + if (g_backends[i].type == type) + return g_backends[i].model; + } + + return 0; +} + void dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata) { diff --git a/examples/common.h b/examples/common.h index f17d578..edb7872 100644 --- a/examples/common.h +++ b/examples/common.h @@ -39,6 +39,9 @@ dctool_family_type (const char *name); const char * dctool_family_name (dc_family_t type); +unsigned int +dctool_family_model (dc_family_t type); + void dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata); diff --git a/examples/dctool.c b/examples/dctool.c index b1c9e0f..df7fe01 100644 --- a/examples/dctool.c +++ b/examples/dctool.c @@ -175,6 +175,7 @@ main (int argc, char *argv[]) const char *device = NULL; dc_family_t family = DC_FAMILY_NULL; unsigned int model = 0; + unsigned int have_family = 0, have_model = 0; // Parse the command-line options. int opt = 0; @@ -203,9 +204,11 @@ main (int argc, char *argv[]) break; case 'f': family = dctool_family_type (optarg); + have_family = 1; break; case 'm': model = strtoul (optarg, NULL, 0); + have_model = 1; break; case 'l': logfile = optarg; @@ -229,6 +232,11 @@ main (int argc, char *argv[]) optreset = 1; #endif + // Set the default model number. + if (have_family && !have_model) { + model = dctool_family_model (family); + } + // Translate the help option into a command. char *argv_help[] = {(char *) "help", NULL, NULL}; if (help || argv[0] == NULL) {