Simplify the version matching logic.
The hardcoded version strings are now grouped into arrays, according to their corresponding layout descriptor. The main advantage of using arrays is that new versions strings can now easily be added, without having to modify any code.
This commit is contained in:
parent
ccaa93a164
commit
0ae6274939
@ -62,31 +62,65 @@ static const device_backend_t oceanic_atom2_device_backend = {
|
||||
oceanic_atom2_device_close /* close */
|
||||
};
|
||||
|
||||
static const unsigned char aeris_manta_version[] = "MANTA R\0\0 512K";
|
||||
static const unsigned char aeris_atmosai_version[] = "ATMOSAI R\0\0 512K";
|
||||
static const unsigned char aeris_epica_version[] = "2M EPIC r\0\0 512K";
|
||||
static const unsigned char aeris_epicb_version[] = "EPIC1 R\0\0 512K";
|
||||
static const unsigned char aeris_f10_version[] = "FREEWAER \0\0 512K";
|
||||
static const unsigned char aeris_a300ai_version[] = "AERISAIR \0\0 1024";
|
||||
static const unsigned char oceanic_proplus2_version[] = "PROPLUS2 \0\0 512K";
|
||||
static const unsigned char oceanic_atom1_version[] = "ATOM rev\0\0 256K";
|
||||
static const unsigned char oceanic_atom2_version[] = "2M ATOM r\0\0 512K";
|
||||
static const unsigned char oceanic_atom3_version[] = "OCEATOM3 \0\0 1024";
|
||||
static const unsigned char oceanic_atom31_version[] = "ATOM31 \0\0 1024";
|
||||
static const unsigned char oceanic_vt4_version[] = "OCEANVT4 \0\0 1024";
|
||||
static const unsigned char oceanic_vt41_version[] = "OCEAVT41 \0\0 1024";
|
||||
static const unsigned char oceanic_geo2_version[] = "OCEGEO20 \0\0 512K";
|
||||
static const unsigned char oceanic_oc1a_version[] = "OCWATCH R\0\0 1024";
|
||||
static const unsigned char oceanic_oc1b_version[] = "OC1WATCH \0\0 1024";
|
||||
static const unsigned char oceanic_ocs_version[] = "OCSWATCH \0\0 1024";
|
||||
static const unsigned char oceanic_veo1_version[] = "OCEVEO10 \0\0 8K";
|
||||
static const unsigned char oceanic_veo2_version[] = "OCEVEO20 \0\0 512K";
|
||||
static const unsigned char oceanic_veo3_version[] = "OCEVEO30 \0\0 512K";
|
||||
static const unsigned char sherwood_insight_version[] = "INSIGHT2 \0\0 512K";
|
||||
static const unsigned char sherwood_wisdom2_version[] = "WISDOM R\0\0 512K";
|
||||
static const unsigned char tusa_element2_version[] = "ELEMENT2 \0\0 512K";
|
||||
static const unsigned char tusa_zen_version[] = "TUSAZEN \0\0 512K";
|
||||
static const unsigned char tusa_zenair_version[] = "TUZENAIR \0\0 512K";
|
||||
static const oceanic_common_version_t aeris_f10_version[] = {
|
||||
{"FREEWAER \0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_atom1_version[] = {
|
||||
{"ATOM rev\0\0 256K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_atom2_version[] = {
|
||||
{"2M ATOM r\0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_atom2a_version[] = {
|
||||
{"MANTA R\0\0 512K"},
|
||||
{"WISDOM R\0\0 512K"},
|
||||
{"INSIGHT2 \0\0 512K"},
|
||||
{"OCEVEO30 \0\0 512K"},
|
||||
{"ATMOSAI R\0\0 512K"},
|
||||
{"PROPLUS2 \0\0 512K"},
|
||||
{"OCEGEO20 \0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_atom2b_version[] = {
|
||||
{"ELEMENT2 \0\0 512K"},
|
||||
{"OCEVEO20 \0\0 512K"},
|
||||
{"TUSAZEN \0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_atom2c_version[] = {
|
||||
{"2M EPIC r\0\0 512K"},
|
||||
{"EPIC1 R\0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_default_version[] = {
|
||||
{"OCE VT3 R\0\0 512K"},
|
||||
{"ELITET3 R\0\0 512K"},
|
||||
{"DATAMASK \0\0 512K"},
|
||||
{"COMPMASK \0\0 512K"},
|
||||
{"HOLLDG03 \0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t tusa_zenair_version[] = {
|
||||
{"TUZENAIR \0\0 512K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_oc1_version[] = {
|
||||
{"OCWATCH R\0\0 1024"},
|
||||
{"OCEANVT4 \0\0 1024"},
|
||||
{"OC1WATCH \0\0 1024"},
|
||||
{"OCEATOM3 \0\0 1024"},
|
||||
{"OCSWATCH \0\0 1024"},
|
||||
{"OCEAVT41 \0\0 1024"},
|
||||
{"ATOM31 \0\0 1024"},
|
||||
{"AERISAIR \0\0 1024"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_veo1_version[] = {
|
||||
{"OCEVEO10 \0\0 8K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_layout_t aeris_f10_layout = {
|
||||
0x10000, /* memsize */
|
||||
@ -371,43 +405,31 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
}
|
||||
|
||||
// Override the base class values.
|
||||
if (oceanic_common_match (oceanic_oc1a_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_oc1b_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_ocs_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_atom3_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_atom31_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_vt4_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_vt41_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (aeris_a300ai_version, device->version, sizeof (device->version)))
|
||||
device->base.layout = &oceanic_oc1_layout;
|
||||
else if (oceanic_common_match (aeris_f10_version, device->version, sizeof (device->version)))
|
||||
if (OCEANIC_COMMON_MATCH (device->version, aeris_f10_version)) {
|
||||
device->base.layout = &aeris_f10_layout;
|
||||
else if (oceanic_common_match (tusa_zenair_version, device->version, sizeof (device->version)))
|
||||
device->base.layout = &tusa_zenair_layout;
|
||||
else if (oceanic_common_match (oceanic_atom1_version, device->version, sizeof (device->version)))
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_atom1_version)) {
|
||||
device->base.layout = &oceanic_atom1_layout;
|
||||
else if (oceanic_common_match (sherwood_insight_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (sherwood_wisdom2_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (aeris_manta_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (aeris_atmosai_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_geo2_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_veo3_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_proplus2_version, device->version, sizeof (device->version)) ||
|
||||
(oceanic_common_match (oceanic_atom2_version, device->version, sizeof (device->version)) &&
|
||||
array_uint16_be (device->version + 0x09) >= 0x3349))
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_atom2_version)) {
|
||||
if (array_uint16_be (device->version + 0x09) >= 0x3349) {
|
||||
device->base.layout = &oceanic_atom2a_layout;
|
||||
} else {
|
||||
device->base.layout = &oceanic_atom2c_layout;
|
||||
}
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_atom2a_version)) {
|
||||
device->base.layout = &oceanic_atom2a_layout;
|
||||
else if (oceanic_common_match (oceanic_veo2_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (tusa_element2_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (tusa_zen_version, device->version, sizeof (device->version)))
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_atom2b_version)) {
|
||||
device->base.layout = &oceanic_atom2b_layout;
|
||||
else if (oceanic_common_match (aeris_epica_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (aeris_epicb_version, device->version, sizeof (device->version)) ||
|
||||
oceanic_common_match (oceanic_atom2_version, device->version, sizeof (device->version)))
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_atom2c_version)) {
|
||||
device->base.layout = &oceanic_atom2c_layout;
|
||||
else if (oceanic_common_match (oceanic_veo1_version, device->version, sizeof (device->version)))
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, tusa_zenair_version)) {
|
||||
device->base.layout = &tusa_zenair_layout;
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_oc1_version)) {
|
||||
device->base.layout = &oceanic_oc1_layout;
|
||||
} else if (OCEANIC_COMMON_MATCH (device->version, oceanic_veo1_version)) {
|
||||
device->base.layout = &oceanic_veo1_layout;
|
||||
else
|
||||
} else {
|
||||
device->base.layout = &oceanic_default_layout;
|
||||
}
|
||||
|
||||
*out = (dc_device_t*) device;
|
||||
|
||||
|
||||
@ -92,10 +92,10 @@ get_profile_last (const unsigned char data[], const oceanic_common_layout_t *lay
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
oceanic_common_match (const unsigned char *pattern, const unsigned char *string, unsigned int n)
|
||||
static int
|
||||
oceanic_common_match_pattern (const unsigned char *string, const unsigned char *pattern)
|
||||
{
|
||||
for (unsigned int i = 0; i < n; ++i, ++pattern, ++string) {
|
||||
for (unsigned int i = 0; i < PAGESIZE; ++i, ++pattern, ++string) {
|
||||
if (*pattern != '\0' && *pattern != *string)
|
||||
return 0;
|
||||
}
|
||||
@ -104,6 +104,18 @@ oceanic_common_match (const unsigned char *pattern, const unsigned char *string,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
oceanic_common_match (const unsigned char *version, const oceanic_common_version_t patterns[], unsigned int n)
|
||||
{
|
||||
for (unsigned int i = 0; i < n; ++i) {
|
||||
if (oceanic_common_match_pattern (version, patterns[i]))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
oceanic_common_device_init (oceanic_common_device_t *device, dc_context_t *context, const device_backend_t *backend)
|
||||
{
|
||||
|
||||
@ -31,6 +31,10 @@ extern "C" {
|
||||
#define PAGESIZE 0x10
|
||||
#define FPMAXSIZE 0x20
|
||||
|
||||
#define OCEANIC_COMMON_MATCH(version,patterns) \
|
||||
oceanic_common_match ((version), (patterns), \
|
||||
sizeof (patterns) / sizeof *(patterns))
|
||||
|
||||
typedef struct oceanic_common_layout_t {
|
||||
// Memory size.
|
||||
unsigned int memsize;
|
||||
@ -60,8 +64,10 @@ typedef struct oceanic_common_device_t {
|
||||
unsigned int multipage;
|
||||
} oceanic_common_device_t;
|
||||
|
||||
typedef unsigned char oceanic_common_version_t[PAGESIZE + 1];
|
||||
|
||||
int
|
||||
oceanic_common_match (const unsigned char *pattern, const unsigned char *string, unsigned int n);
|
||||
oceanic_common_match (const unsigned char *version, const oceanic_common_version_t patterns[], unsigned int n);
|
||||
|
||||
void
|
||||
oceanic_common_device_init (oceanic_common_device_t *device, dc_context_t *context, const device_backend_t *backend);
|
||||
|
||||
@ -62,6 +62,15 @@ static const device_backend_t oceanic_veo250_device_backend = {
|
||||
oceanic_veo250_device_close /* close */
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_vtpro_version[] = {
|
||||
{"GENREACT \0\0 256K"},
|
||||
{"VEO 200 R\0\0 256K"},
|
||||
{"VEO 250 R\0\0 256K"},
|
||||
{"VEO 180 R\0\0 256K"},
|
||||
{"AERISXR2 \0\0 256K"},
|
||||
{"INSIGHT R\0\0 256K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_layout_t oceanic_veo250_layout = {
|
||||
0x8000, /* memsize */
|
||||
0x0000, /* cf_devinfo */
|
||||
|
||||
@ -62,8 +62,16 @@ static const device_backend_t oceanic_vtpro_device_backend = {
|
||||
oceanic_vtpro_device_close /* close */
|
||||
};
|
||||
|
||||
static const unsigned char oceanic_vtpro_version[] = "VTPRO r\0\0 256K";
|
||||
static const unsigned char oceanic_wisdom_version[] = "WISDOM r\0\0 256K";
|
||||
static const oceanic_common_version_t oceanic_vtpro_version[] = {
|
||||
{"VERSAPRO \0\0 256K"},
|
||||
{"PROPLUS2 \0\0 256K"},
|
||||
{"ATMOSAIR \0\0 256K"},
|
||||
{"VTPRO r\0\0 256K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_version_t oceanic_wisdom_version[] = {
|
||||
{"WISDOM r\0\0 256K"},
|
||||
};
|
||||
|
||||
static const oceanic_common_layout_t oceanic_vtpro_layout = {
|
||||
0x8000, /* memsize */
|
||||
@ -341,10 +349,11 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
}
|
||||
|
||||
// Override the base class values.
|
||||
if (oceanic_common_match (oceanic_wisdom_version, device->version, sizeof (device->version)))
|
||||
if (OCEANIC_COMMON_MATCH (device->version, oceanic_wisdom_version)) {
|
||||
device->base.layout = &oceanic_wisdom_layout;
|
||||
else
|
||||
} else {
|
||||
device->base.layout = &oceanic_vtpro_layout;
|
||||
}
|
||||
|
||||
*out = (dc_device_t*) device;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user