diff --git a/src/shearwater_common.c b/src/shearwater_common.c index a7f67f6..2dfb34a 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -548,3 +548,64 @@ shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *b return rc; } + +unsigned int +shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware) +{ + unsigned int model = 0; + + switch (hardware) { + case 0x0101: + case 0x0202: + model = PREDATOR; + break; + case 0x0404: + case 0x0909: + model = PETREL; + break; + case 0x0505: + case 0x0808: + case 0x0838: + case 0x08A5: + case 0x0B0B: + case 0x7828: + case 0x7B2C: + case 0x8838: + model = PETREL2; + break; + case 0xB407: + model = PETREL3; + break; + case 0x0606: + case 0x0A0A: + model = NERD; + break; + case 0x0E0D: + case 0x7E2D: + model = NERD2; + break; + case 0x0707: + model = PERDIX; + break; + case 0x0C0D: + case 0x7C2D: + case 0x8D6C: + model = PERDIXAI; + break; + case 0xC407: + model = PERDIX2; + break; + case 0x0F0F: + case 0x1F0A: + case 0x1F0F: + model = TERIC; + break; + case 0x1512: + model = PEREGRINE; + break; + default: + WARNING (device->base.context, "Unknown hardware type 0x%04x.", hardware); + } + + return model; +} diff --git a/src/shearwater_common.h b/src/shearwater_common.h index b1f8c3b..dd6b180 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -67,6 +67,9 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf dc_status_t shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int id); +unsigned int +shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index c047cca..1e32c17 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -210,59 +210,7 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call // 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 0x0101: - case 0x0202: - model = PREDATOR; - break; - case 0x0404: - case 0x0909: - model = PETREL; - break; - case 0x0505: - case 0x0808: - case 0x0838: - case 0x08A5: - case 0x0B0B: - case 0x7828: - case 0x7B2C: - case 0x8838: - model = PETREL2; - break; - case 0xB407: - model = PETREL3; - break; - case 0x0606: - case 0x0A0A: - model = NERD; - break; - case 0x0E0D: - case 0x7E2D: - model = NERD2; - break; - case 0x0707: - model = PERDIX; - break; - case 0x0C0D: - case 0x7C2D: - case 0x8D6C: - model = PERDIXAI; - break; - case 0xC407: - model = PERDIX2; - break; - case 0x0F0F: - case 0x1F0A: - case 0x1F0F: - model = TERIC; - break; - case 0x1512: - model = PEREGRINE; - break; - default: - WARNING (abstract->context, "Unknown hardware type %04x.", hardware); - } + unsigned int model = shearwater_common_get_model (&device->base, hardware); // Emit a device info event. dc_event_devinfo_t devinfo;