Skip to content

Commit e29f5d9

Browse files
jefdriesenmikeller
authored andcommitted
Read the model number for diagnostics purposes
The model number isn't strictly needed anymore, because libdivecomputer uses the information in the version packet to the detect the dive computer model. However, since the internal lookup table is still based on the model number, having easy access to the model number in the debug logs is very convenient when adding support for new devices.
1 parent 043face commit e29f5d9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/mares_iconhd.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#define CMD_OBJ_ODD 0xFE
9292

9393
#define OBJ_DEVICE 0x2000
94+
#define OBJ_DEVICE_MODEL 0x02
9495
#define OBJ_DEVICE_SERIAL 0x04
9596
#define OBJ_LOGBOOK 0x2008
9697
#define OBJ_LOGBOOK_COUNT 0x01
@@ -1033,6 +1034,26 @@ mares_iconhd_device_foreach_object (dc_device_t *abstract, dc_dive_callback_t ca
10331034
return DC_STATUS_NOMEMORY;
10341035
}
10351036

1037+
// Read the model number.
1038+
rc = mares_iconhd_read_object (device, NULL, buffer, OBJ_DEVICE, OBJ_DEVICE_MODEL);
1039+
if (rc != DC_STATUS_SUCCESS) {
1040+
ERROR (abstract->context, "Failed to read the model number.");
1041+
dc_buffer_free (buffer);
1042+
return rc;
1043+
}
1044+
1045+
if (dc_buffer_get_size (buffer) < 4) {
1046+
ERROR (abstract->context, "Unexpected number of bytes received (" DC_PRINTF_SIZE ").",
1047+
dc_buffer_get_size (buffer));
1048+
dc_buffer_free (buffer);
1049+
return DC_STATUS_PROTOCOL;
1050+
}
1051+
1052+
unsigned int DC_ATTR_UNUSED model = array_uint32_le (dc_buffer_get_data (buffer));
1053+
1054+
// Erase the buffer.
1055+
dc_buffer_clear (buffer);
1056+
10361057
// Read the serial number.
10371058
rc = mares_iconhd_read_object (device, NULL, buffer, OBJ_DEVICE, OBJ_DEVICE_SERIAL);
10381059
if (rc != DC_STATUS_SUCCESS) {

0 commit comments

Comments
 (0)