Detect the model number using the hardware type
The model number is stored in the final block of each dive. But for an efficient implementation of the fingerprint feature, the devinfo event should be emitted before downloading the manifests or the dives. Thus reporting the correct model number is problematic. Currently the model number is simply hardcoded to the value of the Petrel. This is sufficient for the parser, because there the model number is only used to distinguish the Predator from all the other models. Now, because the petrel backend doesn't support the Predator, and the predator backend (which supports both the Predator and Petrel) can obtain the correct model number from the final block, the hardcoded value works fine. Except of course for identifying the actual model! Allthough there doesn't seems to be a command to retrieve the model number directly, we can retrieve the hardware type and map that to the model number.
This commit is contained in:
parent
63d6af8c41
commit
2d7d5152b4
@ -287,10 +287,12 @@ static const dc_descriptor_t g_descriptors[] = {
|
||||
/* Shearwater Predator */
|
||||
{"Shearwater", "Predator", DC_FAMILY_SHEARWATER_PREDATOR, 2},
|
||||
/* Shearwater Petrel */
|
||||
{"Shearwater", "Petrel", DC_FAMILY_SHEARWATER_PETREL, 3},
|
||||
{"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3},
|
||||
{"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 3},
|
||||
{"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 3},
|
||||
{"Shearwater", "Petrel", DC_FAMILY_SHEARWATER_PETREL, 3},
|
||||
{"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3},
|
||||
{"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 4},
|
||||
{"Shearwater", "Nerd 2", DC_FAMILY_SHEARWATER_PETREL, 4},
|
||||
{"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 5},
|
||||
{"Shearwater", "Perdix AI", DC_FAMILY_SHEARWATER_PETREL, 6},
|
||||
/* Dive Rite NiTek Q */
|
||||
{"Dive Rite", "NiTek Q", DC_FAMILY_DIVERITE_NITEKQ, 0},
|
||||
/* Citizen Hyper Aqualand */
|
||||
|
||||
@ -31,6 +31,13 @@ extern "C" {
|
||||
|
||||
#define ID_SERIAL 0x8010
|
||||
#define ID_FIRMWARE 0x8011
|
||||
#define ID_HARDWARE 0x8050
|
||||
|
||||
#define PREDATOR 2
|
||||
#define PETREL 3
|
||||
#define NERD 4
|
||||
#define PERDIX 5
|
||||
#define PERDIXAI 6
|
||||
|
||||
typedef struct shearwater_common_device_t {
|
||||
dc_device_t base;
|
||||
|
||||
@ -200,9 +200,41 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
|
||||
// Convert to a number.
|
||||
unsigned int firmware = str2num (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), 1);
|
||||
|
||||
// Read the hardware type.
|
||||
rc = shearwater_common_identifier (&device->base, buffer, ID_HARDWARE);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR (abstract->context, "Failed to read the hardware type.");
|
||||
dc_buffer_free (buffer);
|
||||
dc_buffer_free (manifests);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Convert and map to the model number.
|
||||
unsigned int hardware = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
||||
unsigned int model = 0;
|
||||
switch (hardware) {
|
||||
case 0x0808: // Petrel 2
|
||||
case 0x0909: // Petrel 1
|
||||
case 0x0B0B: // Petrel 1 (newer hardware)
|
||||
model = PETREL;
|
||||
break;
|
||||
case 0x0A0A: // Nerd 1
|
||||
case 0x0E0D: // Nerd 2
|
||||
model = NERD;
|
||||
break;
|
||||
case 0x0707:
|
||||
model = PERDIX;
|
||||
break;
|
||||
case 0x0C0D:
|
||||
model = PERDIXAI;
|
||||
break;
|
||||
default:
|
||||
WARNING (abstract->context, "Unknown hardware type %04x.", hardware);
|
||||
}
|
||||
|
||||
// Emit a device info event.
|
||||
dc_event_devinfo_t devinfo;
|
||||
devinfo.model = 3;
|
||||
devinfo.model = model;
|
||||
devinfo.firmware = firmware;
|
||||
devinfo.serial = array_uint32_be (serial);
|
||||
device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo);
|
||||
|
||||
@ -30,9 +30,6 @@
|
||||
|
||||
#define ISINSTANCE(device) dc_device_isinstance((device), &shearwater_predator_device_vtable)
|
||||
|
||||
#define PREDATOR 2
|
||||
#define PETREL 3
|
||||
|
||||
#define SZ_BLOCK 0x80
|
||||
#define SZ_MEMORY 0x20080
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user