Added a function to change the delay between two commands.

Some dive computers do not work well with the default delay. But 
increasing the default delay would make the transfer unnecessary longer 
for all others.
This commit is contained in:
Jef Driesen 2008-02-03 06:29:07 +00:00
parent fa20dbb87d
commit 331ecf1a09
3 changed files with 32 additions and 8 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -1,4 +1,5 @@
#include <stdio.h> // fopen, fwrite, fclose
#include <stdio.h> // fopen, fwrite, fclose
#include <stdlib.h> // 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");