Move the model number mapping to a function

This commit is contained in:
Jef Driesen 2023-06-22 20:18:26 +02:00
parent 9b7aa813e0
commit ee147afceb
3 changed files with 65 additions and 53 deletions

View File

@ -548,3 +548,64 @@ shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *b
return rc; 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;
}

View File

@ -67,6 +67,9 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf
dc_status_t dc_status_t
shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int id); 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 #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -210,59 +210,7 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
// Convert and map to the model number. // 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 hardware = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
unsigned int model = 0; unsigned int model = shearwater_common_get_model (&device->base, hardware);
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);
}
// Emit a device info event. // Emit a device info event.
dc_event_devinfo_t devinfo; dc_event_devinfo_t devinfo;