Skip to content

Commit b7aa89b

Browse files
jefdriesenmikeller
authored andcommitted
Add support for time synchronization
The Suunto d9/vyper2 protocol supports a command to synchronize the clock.
1 parent 6944956 commit b7aa89b

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/suunto_common2.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,32 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
397397

398398
return status;
399399
}
400+
401+
dc_status_t
402+
suunto_common2_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime)
403+
{
404+
dc_status_t status = DC_STATUS_SUCCESS;
405+
406+
unsigned char answer[5] = {0};
407+
unsigned char command[11] = {0x10, 0x00, 0x07,
408+
(datetime->year >> 8) & 0xFF,
409+
(datetime->year ) & 0xFF,
410+
datetime->month,
411+
datetime->day,
412+
datetime->hour,
413+
datetime->minute,
414+
datetime->second,
415+
0}; // CRC
416+
command[10] = checksum_xor_uint8 (command, 10, 0x00);
417+
418+
status = suunto_common2_transfer (abstract, command, sizeof (command), answer, sizeof (answer), 1);
419+
if (status != DC_STATUS_SUCCESS)
420+
return status;
421+
422+
if (answer[3] != 1) {
423+
ERROR (abstract->context, "Unexpected response code (%u).", answer[3]);
424+
return DC_STATUS_PROTOCOL;
425+
}
426+
427+
return status;
428+
}

src/suunto_common2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ suunto_common2_device_dump (dc_device_t *device, dc_buffer_t *buffer);
7373
dc_status_t
7474
suunto_common2_device_foreach (dc_device_t *device, dc_dive_callback_t callback, void *userdata);
7575

76+
dc_status_t
77+
suunto_common2_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime);
78+
7679
dc_status_t
7780
suunto_common2_device_reset_maxdepth (dc_device_t *device);
7881

src/suunto_d9.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static const suunto_common2_device_vtable_t suunto_d9_device_vtable = {
5656
suunto_common2_device_write, /* write */
5757
suunto_common2_device_dump, /* dump */
5858
suunto_common2_device_foreach, /* foreach */
59-
NULL, /* timesync */
59+
suunto_common2_device_timesync, /* timesync */
6060
NULL /* close */
6161
},
6262
suunto_d9_device_packet

src/suunto_vyper2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static const suunto_common2_device_vtable_t suunto_vyper2_device_vtable = {
5151
suunto_common2_device_write, /* write */
5252
suunto_common2_device_dump, /* dump */
5353
suunto_common2_device_foreach, /* foreach */
54-
NULL, /* timesync */
54+
suunto_common2_device_timesync, /* timesync */
5555
suunto_vyper2_device_close /* close */
5656
},
5757
suunto_vyper2_device_packet

0 commit comments

Comments
 (0)