Merge branch 'ostc'
This commit is contained in:
commit
90ba491c6d
@ -40,6 +40,9 @@ hw_ostc3_device_open (dc_device_t **device, dc_context_t *context, const char *n
|
|||||||
dc_status_t
|
dc_status_t
|
||||||
hw_ostc3_device_version (dc_device_t *device, unsigned char data[], unsigned int size);
|
hw_ostc3_device_version (dc_device_t *device, unsigned char data[], unsigned int size);
|
||||||
|
|
||||||
|
dc_status_t
|
||||||
|
hw_ostc3_device_hardware (dc_device_t *device, unsigned char data[], unsigned int size);
|
||||||
|
|
||||||
dc_status_t
|
dc_status_t
|
||||||
hw_ostc3_device_clock (dc_device_t *device, const dc_datetime_t *datetime);
|
hw_ostc3_device_clock (dc_device_t *device, const dc_datetime_t *datetime);
|
||||||
|
|
||||||
|
|||||||
@ -210,9 +210,9 @@ static const dc_descriptor_t g_descriptors[] = {
|
|||||||
{"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2},
|
{"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2},
|
||||||
{"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3},
|
{"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3},
|
||||||
{"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0},
|
{"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0},
|
||||||
{"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0},
|
{"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0x0A},
|
||||||
{"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0},
|
{"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x05},
|
||||||
{"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 1},
|
{"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x12},
|
||||||
/* Cressi Edy */
|
/* Cressi Edy */
|
||||||
{"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0},
|
{"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0},
|
||||||
/* Cressi Leonardo */
|
/* Cressi Leonardo */
|
||||||
|
|||||||
@ -46,6 +46,7 @@
|
|||||||
#define SZ_DISPLAY 16
|
#define SZ_DISPLAY 16
|
||||||
#define SZ_CUSTOMTEXT 60
|
#define SZ_CUSTOMTEXT 60
|
||||||
#define SZ_VERSION (SZ_CUSTOMTEXT + 4)
|
#define SZ_VERSION (SZ_CUSTOMTEXT + 4)
|
||||||
|
#define SZ_HARDWARE 1
|
||||||
#define SZ_MEMORY 0x200000
|
#define SZ_MEMORY 0x200000
|
||||||
#define SZ_CONFIG 4
|
#define SZ_CONFIG 4
|
||||||
#define SZ_FIRMWARE 0x01E000 // 120KB
|
#define SZ_FIRMWARE 0x01E000 // 120KB
|
||||||
@ -66,6 +67,7 @@
|
|||||||
#define CUSTOMTEXT 0x63
|
#define CUSTOMTEXT 0x63
|
||||||
#define DIVE 0x66
|
#define DIVE 0x66
|
||||||
#define IDENTITY 0x69
|
#define IDENTITY 0x69
|
||||||
|
#define HARDWARE 0x6A
|
||||||
#define DISPLAY 0x6E
|
#define DISPLAY 0x6E
|
||||||
#define READ 0x72
|
#define READ 0x72
|
||||||
#define WRITE 0x77
|
#define WRITE 0x77
|
||||||
@ -73,6 +75,10 @@
|
|||||||
#define INIT 0xBB
|
#define INIT 0xBB
|
||||||
#define EXIT 0xFF
|
#define EXIT 0xFF
|
||||||
|
|
||||||
|
#define OSTC3 0x0A
|
||||||
|
#define SPORT 0x12
|
||||||
|
#define CR 0x05
|
||||||
|
|
||||||
typedef enum hw_ostc3_state_t {
|
typedef enum hw_ostc3_state_t {
|
||||||
OPEN,
|
OPEN,
|
||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
@ -151,6 +157,9 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
|
|||||||
if (device_is_cancelled (abstract))
|
if (device_is_cancelled (abstract))
|
||||||
return DC_STATUS_CANCELLED;
|
return DC_STATUS_CANCELLED;
|
||||||
|
|
||||||
|
// Get the correct ready byte for the current state.
|
||||||
|
const unsigned char ready = (device->state == SERVICE ? S_READY : READY);
|
||||||
|
|
||||||
// Send the command.
|
// Send the command.
|
||||||
unsigned char command[1] = {cmd};
|
unsigned char command[1] = {cmd};
|
||||||
int n = serial_write (device->port, command, sizeof (command));
|
int n = serial_write (device->port, command, sizeof (command));
|
||||||
@ -169,8 +178,13 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
|
|||||||
|
|
||||||
// Verify the echo.
|
// Verify the echo.
|
||||||
if (memcmp (echo, command, sizeof (command)) != 0) {
|
if (memcmp (echo, command, sizeof (command)) != 0) {
|
||||||
ERROR (abstract->context, "Unexpected echo.");
|
if (echo[0] == ready) {
|
||||||
return DC_STATUS_PROTOCOL;
|
ERROR (abstract->context, "Unsupported command.");
|
||||||
|
return DC_STATUS_UNSUPPORTED;
|
||||||
|
} else {
|
||||||
|
ERROR (abstract->context, "Unexpected echo.");
|
||||||
|
return DC_STATUS_PROTOCOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
@ -216,16 +230,15 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
|
|||||||
|
|
||||||
if (cmd != EXIT) {
|
if (cmd != EXIT) {
|
||||||
// Read the ready byte.
|
// Read the ready byte.
|
||||||
unsigned char ready[1] = {0};
|
unsigned char answer[1] = {0};
|
||||||
unsigned char expected = (device->state == SERVICE ? S_READY : READY);
|
n = serial_read (device->port, answer, sizeof (answer));
|
||||||
n = serial_read (device->port, ready, sizeof (ready));
|
if (n != sizeof (answer)) {
|
||||||
if (n != sizeof (ready)) {
|
|
||||||
ERROR (abstract->context, "Failed to receive the ready byte.");
|
ERROR (abstract->context, "Failed to receive the ready byte.");
|
||||||
return EXITCODE (n);
|
return EXITCODE (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the ready byte.
|
// Verify the ready byte.
|
||||||
if (ready[0] != expected) {
|
if (answer[0] != ready) {
|
||||||
ERROR (abstract->context, "Unexpected ready byte.");
|
ERROR (abstract->context, "Unexpected ready byte.");
|
||||||
return DC_STATUS_PROTOCOL;
|
return DC_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -454,6 +467,30 @@ hw_ostc3_device_version (dc_device_t *abstract, unsigned char data[], unsigned i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dc_status_t
|
||||||
|
hw_ostc3_device_hardware (dc_device_t *abstract, unsigned char data[], unsigned int size)
|
||||||
|
{
|
||||||
|
hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
|
||||||
|
|
||||||
|
if (!ISINSTANCE (abstract))
|
||||||
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
|
if (size != SZ_HARDWARE)
|
||||||
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
|
dc_status_t rc = hw_ostc3_device_init (device, DOWNLOAD);
|
||||||
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// Send the command.
|
||||||
|
rc = hw_ostc3_transfer (device, NULL, HARDWARE, NULL, 0, data, size);
|
||||||
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
return DC_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static dc_status_t
|
static dc_status_t
|
||||||
hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
|
hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
|
||||||
{
|
{
|
||||||
@ -476,14 +513,26 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Download the hardware descriptor.
|
||||||
|
unsigned char hardware[SZ_HARDWARE] = {0};
|
||||||
|
rc = hw_ostc3_device_hardware (abstract, hardware, sizeof (hardware));
|
||||||
|
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||||
|
ERROR (abstract->context, "Failed to read the hardware descriptor.");
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
// Emit a device info event.
|
// Emit a device info event.
|
||||||
dc_event_devinfo_t devinfo;
|
dc_event_devinfo_t devinfo;
|
||||||
devinfo.firmware = array_uint16_be (id + 2);
|
devinfo.firmware = array_uint16_be (id + 2);
|
||||||
devinfo.serial = array_uint16_le (id + 0);
|
devinfo.serial = array_uint16_le (id + 0);
|
||||||
if (devinfo.serial > 10000)
|
devinfo.model = hardware[0];
|
||||||
devinfo.model = 1; // OSTC Sport
|
if (devinfo.model == 0) {
|
||||||
else
|
// Fallback to the serial number.
|
||||||
devinfo.model = 0; // OSTC3
|
if (devinfo.serial > 10000)
|
||||||
|
devinfo.model = SPORT;
|
||||||
|
else
|
||||||
|
devinfo.model = OSTC3;
|
||||||
|
}
|
||||||
device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo);
|
device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo);
|
||||||
|
|
||||||
// Allocate memory.
|
// Allocate memory.
|
||||||
|
|||||||
@ -155,6 +155,7 @@ hw_frog_device_display
|
|||||||
hw_frog_device_customtext
|
hw_frog_device_customtext
|
||||||
hw_ostc3_device_open
|
hw_ostc3_device_open
|
||||||
hw_ostc3_device_version
|
hw_ostc3_device_version
|
||||||
|
hw_ostc3_device_hardware
|
||||||
hw_ostc3_device_clock
|
hw_ostc3_device_clock
|
||||||
hw_ostc3_device_display
|
hw_ostc3_device_display
|
||||||
hw_ostc3_device_customtext
|
hw_ostc3_device_customtext
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user