From 1d50bcf732e5e90024aa3b19c801db9921b54f39 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 23 May 2008 20:31:21 +0000 Subject: [PATCH] Added a public API function to set the oldest timestamp. --- uwatec_memomouse.c | 19 ++++++++++++++++++- uwatec_memomouse.h | 2 ++ uwatec_smart.c | 30 ++++++++++++++++++++++-------- uwatec_smart.h | 2 ++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/uwatec_memomouse.c b/uwatec_memomouse.c index 5a1d8e6..293b5c1 100644 --- a/uwatec_memomouse.c +++ b/uwatec_memomouse.c @@ -21,6 +21,7 @@ struct memomouse { struct serial *port; + unsigned int timestamp; }; @@ -39,6 +40,7 @@ uwatec_memomouse_open (memomouse **out, const char* name) // Set the default values. device->port = NULL; + device->timestamp = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -102,6 +104,18 @@ uwatec_memomouse_close (memomouse *device) } +int +uwatec_memomouse_set_timestamp (memomouse *device, unsigned int timestamp) +{ + if (device == NULL) + return UWATEC_ERROR; + + device->timestamp = timestamp; + + return UWATEC_SUCCESS; +} + + static void uwatec_memomouse_reverse (unsigned char data[], unsigned int size) { @@ -332,7 +346,10 @@ uwatec_memomouse_read (memomouse *device, unsigned char data[], unsigned int siz 0x07, // Outer packet size. 0x05, 0x00, // Inner packet size. 0x55, // Command byte. - 0x00, 0x00, 0x00, 0x00, // Timestamp. + (device->timestamp ) & 0xFF, + (device->timestamp >> 8) & 0xFF, + (device->timestamp >> 16) & 0xFF, + (device->timestamp >> 24) & 0xFF, 0x00}; // Outer packet checksum. command[8] = uwatec_memomouse_checksum (command, 8, 0x00); uwatec_memomouse_reverse (command, sizeof (command)); diff --git a/uwatec_memomouse.h b/uwatec_memomouse.h index ec492a2..3b701d4 100644 --- a/uwatec_memomouse.h +++ b/uwatec_memomouse.h @@ -11,6 +11,8 @@ int uwatec_memomouse_open (memomouse **device, const char* name); int uwatec_memomouse_close (memomouse *device); +int uwatec_memomouse_set_timestamp (memomouse *device, unsigned int timestamp); + int uwatec_memomouse_read (memomouse *device, unsigned char data[], unsigned int size); int uwatec_memomouse_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata); diff --git a/uwatec_smart.c b/uwatec_smart.c index 63d7de4..7bba158 100644 --- a/uwatec_smart.c +++ b/uwatec_smart.c @@ -20,6 +20,7 @@ struct smart { struct irda *socket; unsigned int address; + unsigned int timestamp; }; @@ -63,6 +64,7 @@ uwatec_smart_open (smart **out) // Set the default values. device->socket = NULL; device->address = 0; + device->timestamp = 0; irda_init (); @@ -131,6 +133,18 @@ uwatec_smart_close (smart *device) } +int +uwatec_smart_set_timestamp (smart *device, unsigned int timestamp) +{ + if (device == NULL) + return UWATEC_ERROR; + + device->timestamp = timestamp; + + return UWATEC_SUCCESS; +} + + static int uwatec_smart_transfer (smart *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) { @@ -238,10 +252,10 @@ uwatec_smart_read (smart *device, unsigned char data[], unsigned int msize) // Data Length. command[0] = 0xC6; - command[1] = (timestamp ) & 0xFF; - command[2] = (timestamp >> 8 ) & 0xFF; - command[3] = (timestamp >> 16) & 0xFF; - command[4] = (timestamp >> 24) & 0xFF; + command[1] = (device->timestamp ) & 0xFF; + command[2] = (device->timestamp >> 8 ) & 0xFF; + command[3] = (device->timestamp >> 16) & 0xFF; + command[4] = (device->timestamp >> 24) & 0xFF; command[5] = 0x10; command[6] = 0x27; command[7] = 0; @@ -267,10 +281,10 @@ uwatec_smart_read (smart *device, unsigned char data[], unsigned int msize) // Data. command[0] = 0xC4; - command[1] = (timestamp ) & 0xFF; - command[2] = (timestamp >> 8 ) & 0xFF; - command[3] = (timestamp >> 16) & 0xFF; - command[4] = (timestamp >> 24) & 0xFF; + command[1] = (device->timestamp ) & 0xFF; + command[2] = (device->timestamp >> 8 ) & 0xFF; + command[3] = (device->timestamp >> 16) & 0xFF; + command[4] = (device->timestamp >> 24) & 0xFF; command[5] = 0x10; command[6] = 0x27; command[7] = 0; diff --git a/uwatec_smart.h b/uwatec_smart.h index cacc3ed..0724766 100644 --- a/uwatec_smart.h +++ b/uwatec_smart.h @@ -11,6 +11,8 @@ int uwatec_smart_open (smart **device); int uwatec_smart_close (smart *device); +int uwatec_smart_set_timestamp (smart *device, unsigned int timestamp); + int uwatec_smart_read (smart *device, unsigned char data[], unsigned int size); int uwatec_smart_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);