Add an option to switch between real and simulated dives.

This commit is contained in:
Jef Driesen 2011-02-27 22:30:48 +01:00
parent 5614aff3ee
commit c15b964b26
3 changed files with 25 additions and 1 deletions

View File

@ -48,6 +48,7 @@ typedef struct atomics_cobalt_device_t {
libusb_context *context;
libusb_device_handle *handle;
#endif
unsigned int simulation;
unsigned char fingerprint[6];
} atomics_cobalt_device_t;
@ -96,6 +97,7 @@ atomics_cobalt_device_open (device_t **out)
// Set the default values.
device->context = NULL;
device->handle = NULL;
device->simulation = 0;
memset (device->fingerprint, 0, sizeof (device->fingerprint));
int rc = libusb_init (&device->context);
@ -169,6 +171,20 @@ atomics_cobalt_device_set_fingerprint (device_t *abstract, const unsigned char d
}
device_status_t
atomics_cobalt_device_set_simulation (device_t *abstract, unsigned int simulation)
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (! device_is_atomics_cobalt (abstract))
return DEVICE_STATUS_TYPE_MISMATCH;
device->simulation = simulation;
return DEVICE_STATUS_SUCCESS;
}
static device_status_t
atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init)
{
@ -185,7 +201,11 @@ atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init)
}
// Send the command to the dive computer.
uint8_t bRequest = init ? 0x09 : 0x0A;
uint8_t bRequest = 0;
if (device->simulation)
bRequest = init ? 0x02 : 0x03;
else
bRequest = init ? 0x09 : 0x0A;
int rc = libusb_control_transfer (device->handle,
LIBUSB_RECIPIENT_DEVICE | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT,
bRequest, 0, 0, NULL, 0, TIMEOUT);

View File

@ -32,6 +32,9 @@ extern "C" {
device_status_t
atomics_cobalt_device_open (device_t **device);
device_status_t
atomics_cobalt_device_set_simulation (device_t *abstract, unsigned int simulation);
parser_status_t
atomics_cobalt_parser_create (parser_t **parser);

View File

@ -116,3 +116,4 @@ hw_ostc_device_open
hw_ostc_extract_dives
zeagle_n2ition3_device_open
atomics_cobalt_device_open
atomics_cobalt_device_set_simulation