[PATCH 5/6] Cochran: Dump of Commander TM devices is now supported
John Van Ostrand
john at vanostrand.com
Sat Jul 15 13:39:40 PDT 2017
- TM doesn't support high-speed transfer so
- Use 0x05 read command
- Don't change to higher baud rate
- Still reset to 9600 so we wait for heartbeat
- TM has a different config command (one byte)
- TM has only one config page
- Alter cochran_commander_read_config function
- Assume 512 config pages, because it seems standard
- Remove size parameter to function since we assume 512
- Alter progress maximum calculation to reflect single page
---
src/cochran_commander.c | 69 ++++++++++++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 21 deletions(-)
diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index 9655522..a77eabb 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -357,7 +357,7 @@ cochran_commander_packet (cochran_commander_device_t *device, dc_event_progress_
}
}
- if (high_speed) {
+ if (high_speed && device->layout->baudrate != 9600) {
// Give the DC time to process the command.
dc_serial_sleep(device->port, 45);
@@ -421,23 +421,31 @@ cochran_commander_read_id (cochran_commander_device_t *device, unsigned char id[
static dc_status_t
-cochran_commander_read_config (cochran_commander_device_t *device, dc_event_progress_t *progress, unsigned char data[], unsigned int size)
+cochran_commander_read_config (cochran_commander_device_t *device, dc_event_progress_t *progress, unsigned char data[])
{
dc_device_t *abstract = (dc_device_t *) device;
dc_status_t rc = DC_STATUS_SUCCESS;
+ unsigned int pages = 2;
+
+ if (device->layout->model == COCHRAN_MODEL_COMMANDER_TM)
+ pages = 1;
+
// Read two 512 byte blocks into one 1024 byte buffer
- for (unsigned int i = 0; i < 2; i++) {
- const unsigned int len = size / 2;
+ for (unsigned int i = 0; i < pages; i++) {
unsigned char command[2] = {0x96, i};
- rc = cochran_commander_packet(device, progress, command, sizeof(command), data + i * len, len, 0);
+ unsigned int command_size = 2;
+ if (device->layout->model == COCHRAN_MODEL_COMMANDER_TM)
+ command_size = 1;
+
+ rc = cochran_commander_packet(device, progress, command, command_size, data + i * 512, 512, 0);
if (rc != DC_STATUS_SUCCESS)
return rc;
dc_event_vendor_t vendor;
- vendor.data = data + i * len;
- vendor.size = len;
+ vendor.data = data + i * 512;
+ vendor.size = 512;
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
}
@@ -471,15 +479,27 @@ cochran_commander_read (cochran_commander_device_t *device, dc_event_progress_t
break;
case 24:
// Commander uses 24 byte addressing
- command[0] = 0x15;
- command[1] = (address ) & 0xff;
- command[2] = (address >> 8) & 0xff;
- command[3] = (address >> 16) & 0xff;
- command[4] = (size ) & 0xff;
- command[5] = (size >> 8 ) & 0xff;
- command[6] = (size >> 16 ) & 0xff;
- command[7] = 0x04;
- command_size = 8;
+ if (device->layout->baudrate == 9600) {
+ // Older commander, use low-speed read command
+ command[0] = 0x05;
+ command[1] = (address ) & 0xff;
+ command[2] = (address >> 8) & 0xff;
+ command[3] = (address >> 16) & 0xff;
+ command[4] = (size ) & 0xff;
+ command[5] = (size >> 8 ) & 0xff;
+ command_size = 6;
+ } else {
+ // Newer commander with high-speed read command
+ command[0] = 0x15;
+ command[1] = (address ) & 0xff;
+ command[2] = (address >> 8) & 0xff;
+ command[3] = (address >> 16) & 0xff;
+ command[4] = (size ) & 0xff;
+ command[5] = (size >> 8 ) & 0xff;
+ command[6] = (size >> 16 ) & 0xff;
+ command[7] = 0x04;
+ command_size = 8;
+ }
break;
default:
return DC_STATUS_UNSUPPORTED;
@@ -754,6 +774,7 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
cochran_commander_device_t *device = (cochran_commander_device_t *) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
unsigned char config[1024];
+ unsigned int config_size = 1024;
unsigned int size = device->layout->rb_profile_end - device->layout->rb_logbook_begin;
// Make sure buffer is good.
@@ -768,9 +789,12 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return DC_STATUS_NOMEMORY;
}
+ if (device->layout->model == COCHRAN_MODEL_COMMANDER_TM)
+ config_size = 512;
+
// Determine size for progress
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
- progress.maximum = sizeof(config) + size;
+ progress.maximum = config_size + size;
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit ID block
@@ -779,12 +803,12 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
vendor.size = sizeof (device->id);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
- rc = cochran_commander_read_config (device, &progress, config, sizeof(config));
+ rc = cochran_commander_read_config (device, &progress, config);
if (rc != DC_STATUS_SUCCESS)
return rc;
- // Read the sample data, from 0 to sample end will include logbook
- rc = cochran_commander_read (device, &progress, device->layout->rb_logbook_begin, dc_buffer_get_data(buffer), device->layout->rb_profile_end);
+ // Read the sample data, logbook and sample data are contiguous
+ rc = cochran_commander_read (device, &progress, device->layout->rb_logbook_begin, dc_buffer_get_data(buffer), size);
if (rc != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to read the sample data.");
return rc;
@@ -813,6 +837,9 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
unsigned int max_logbook = layout->rb_logbook_end - layout->rb_logbook_begin;
unsigned int max_sample = layout->rb_profile_end - layout->rb_profile_begin;
+ if (device->layout->model == COCHRAN_MODEL_COMMANDER_TM)
+ max_config = 512;
+
// setup progress indication
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
progress.maximum = max_config + max_logbook + max_sample;
@@ -826,7 +853,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
// Read config
dc_status_t rc = DC_STATUS_SUCCESS;
- rc = cochran_commander_read_config(device, &progress, data.config, sizeof(data.config));
+ rc = cochran_commander_read_config(device, &progress, data.config);
if (rc != DC_STATUS_SUCCESS)
return rc;
--
2.4.11
More information about the devel
mailing list