From f8ff2852bf0b53ef74fef7a825b3e142e0e6ab91 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 6 Mar 2010 11:48:22 +0000 Subject: [PATCH] Fix the init sequence for Geo 2 devices. The Geo 2 appears to respond with a single NAK byte instead of three. The issue is fixed by expecting only a single byte, and flushing the serial line to discard all other bytes (if there are any). --- src/oceanic_atom2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index d6183ae..b18791a 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -165,7 +165,7 @@ oceanic_atom2_init (oceanic_atom2_device_t *device) } // Receive the answer of the dive computer. - unsigned char answer[3] = {0}; + unsigned char answer[1] = {0}; n = serial_read (device->port, answer, sizeof (answer)); if (n != sizeof (answer)) { WARNING ("Failed to receive the answer."); @@ -173,7 +173,7 @@ oceanic_atom2_init (oceanic_atom2_device_t *device) } // Verify the answer. - if (answer[0] != NAK || answer[1] != NAK || answer[2] != NAK) { + if (answer[0] != NAK) { WARNING ("Unexpected answer byte(s)."); return DEVICE_STATUS_PROTOCOL; } @@ -273,6 +273,9 @@ oceanic_atom2_device_open (device_t **out, const char* name) return status; } + // Make sure everything is in a sane state. + serial_flush (device->port, SERIAL_QUEUE_BOTH); + // Switch the device from surface mode into download mode. Before sending // this command, the device needs to be in PC mode (automatically activated // by connecting the device), or already in download mode.