diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index ad15ae5..a83543c 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -41,6 +41,7 @@ oceanic_vtpro_device_open oceanic_vtpro_device_keepalive oceanic_vtpro_device_calibrate reefnet_sensus_device_open +reefnet_sensus_device_set_timestamp reefnet_sensus_extract_dives reefnet_sensuspro_device_open reefnet_sensuspro_device_set_timestamp diff --git a/src/reefnet_sensus.c b/src/reefnet_sensus.c index 44b135e..8ed078d 100644 --- a/src/reefnet_sensus.c +++ b/src/reefnet_sensus.c @@ -46,6 +46,7 @@ struct reefnet_sensus_device_t { device_t base; struct serial *port; unsigned int waiting; + unsigned int timestamp; }; static device_status_t reefnet_sensus_device_handshake (device_t *abstract, unsigned char *data, unsigned int size); @@ -111,6 +112,7 @@ reefnet_sensus_device_open (device_t **out, const char* name) // Set the default values. device->port = NULL; device->waiting = 0; + device->timestamp = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -172,6 +174,20 @@ reefnet_sensus_device_close (device_t *abstract) } +device_status_t +reefnet_sensus_device_set_timestamp (device_t *abstract, unsigned int timestamp) +{ + reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract; + + if (! device_is_reefnet_sensus (abstract)) + return DEVICE_STATUS_TYPE_MISMATCH; + + device->timestamp = timestamp; + + return DEVICE_STATUS_SUCCESS; +} + + static device_status_t reefnet_sensus_device_handshake (device_t *abstract, unsigned char *data, unsigned int size) { @@ -324,12 +340,12 @@ reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, voi if (rc != DEVICE_STATUS_SUCCESS) return rc; - return reefnet_sensus_extract_dives (data, sizeof (data), callback, userdata); + return reefnet_sensus_extract_dives (data, sizeof (data), callback, userdata, device->timestamp); } device_status_t -reefnet_sensus_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata) +reefnet_sensus_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata, unsigned int timestamp) { // Search the entire data stream for start markers. unsigned int previous = size; @@ -375,6 +391,12 @@ reefnet_sensus_extract_dives (const unsigned char data[], unsigned int size, div return DEVICE_STATUS_ERROR; } + // Automatically abort when a dive is older than the provided timestamp. + unsigned int datetime = data[current + 2] + (data[current + 3] << 8) + + (data[current + 4] << 16) + (data[current + 5] << 24); + if (datetime <= timestamp) + return DEVICE_STATUS_SUCCESS; + if (callback && !callback (data + current, offset - current, userdata)) return DEVICE_STATUS_SUCCESS; diff --git a/src/reefnet_sensus.h b/src/reefnet_sensus.h index 42577c1..4010cad 100644 --- a/src/reefnet_sensus.h +++ b/src/reefnet_sensus.h @@ -36,7 +36,10 @@ device_status_t reefnet_sensus_device_open (device_t **device, const char* name); device_status_t -reefnet_sensus_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata); +reefnet_sensus_device_set_timestamp (device_t *device, unsigned int timestamp); + +device_status_t +reefnet_sensus_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata, unsigned int timestamp); parser_status_t reefnet_sensus_parser_create (parser_t **parser);