diff --git a/suunto_vyper.c b/suunto_vyper.c index 31b300f..c521ff9 100644 --- a/suunto_vyper.c +++ b/suunto_vyper.c @@ -26,6 +26,7 @@ struct vyper { int extraanswertime; int ifacealwaysechos; int breakprofreadearly; + unsigned int delay; }; @@ -47,6 +48,7 @@ suunto_vyper_open (vyper **out, const char* name) device->extraanswertime = 0; device->ifacealwaysechos = 0; device->breakprofreadearly = 0; + device->delay = 500; // Open the device. int rc = serial_open (&device->port, name); @@ -206,10 +208,21 @@ suunto_vyper_detect_interface (vyper *device) } +int +suunto_vyper_set_delay (vyper *device, unsigned int delay) +{ + if (device == NULL) + return SUUNTO_ERROR; + + device->delay = delay; + + return SUUNTO_SUCCESS; +} + static int suunto_vyper_send (vyper *device, const unsigned char command[], unsigned int csize) { - serial_sleep (500); + serial_sleep (device->delay); // Set RTS to send the command. serial_set_rts (device->port, 1); diff --git a/suunto_vyper.h b/suunto_vyper.h index 7778b56..744539a 100644 --- a/suunto_vyper.h +++ b/suunto_vyper.h @@ -14,6 +14,8 @@ int suunto_vyper_open (vyper **device, const char* name); int suunto_vyper_close (vyper *device); +int suunto_vyper_set_delay (vyper *device, unsigned int delay); + int suunto_vyper_detect_interface (vyper *device); int suunto_vyper_read_dive (vyper *device, unsigned char data[], unsigned int size, int init); @@ -22,7 +24,6 @@ int suunto_vyper_read_memory (vyper *device, unsigned int address, unsigned char int suunto_vyper_write_memory (vyper *device, unsigned int address, const unsigned char data[], unsigned int size); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/suunto_vyper_test.c b/suunto_vyper_test.c index ec15175..1d3ac90 100644 --- a/suunto_vyper_test.c +++ b/suunto_vyper_test.c @@ -1,4 +1,5 @@ -#include // fopen, fwrite, fclose +#include // fopen, fwrite, fclose +#include // atoi #include "suunto.h" #include "serial.h" @@ -9,7 +10,7 @@ message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \ } -int test_dump_sdm16 (const char* name, const char* filename) +int test_dump_sdm16 (const char* name, unsigned int delay, const char* filename) { unsigned char data[SUUNTO_VYPER_MEMORY_SIZE] = {0}; vyper *device = NULL; @@ -21,6 +22,8 @@ int test_dump_sdm16 (const char* name, const char* filename) return rc; } + suunto_vyper_set_delay (device, delay); + message ("suunto_vyper_detect_interface\n"); rc = suunto_vyper_detect_interface (device); if (rc != SUUNTO_SUCCESS) { @@ -88,7 +91,7 @@ int test_dump_sdm16 (const char* name, const char* filename) return SUUNTO_SUCCESS; } -int test_dump_memory (const char* name, const char* filename) +int test_dump_memory (const char* name, unsigned int delay, const char* filename) { unsigned char data[SUUNTO_VYPER_MEMORY_SIZE] = {0}; vyper *device = NULL; @@ -100,6 +103,8 @@ int test_dump_memory (const char* name, const char* filename) return rc; } + suunto_vyper_set_delay (device, delay); + message ("suunto_vyper_detect_interface\n"); rc = suunto_vyper_detect_interface (device); if (rc != SUUNTO_SUCCESS) { @@ -162,13 +167,18 @@ int main(int argc, char *argv[]) #else const char* name = "/dev/ttyS0"; #endif + + unsigned int delay = 500; - if (argc > 1) { + if (argc > 2) { + name = argv[1]; + delay = atoi (argv[2]); + } else if (argc > 1) { name = argv[1]; } - int a = test_dump_sdm16 (name, "VYPER.SDM"); - int b = test_dump_memory (name, "VYPER.DMP"); + int a = test_dump_sdm16 (name, delay, "VYPER.SDM"); + int b = test_dump_memory (name, delay, "VYPER.DMP"); message ("\nSUMMARY\n"); message ("-------\n");