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).
This commit is contained in:
Jef Driesen 2010-03-06 11:48:22 +00:00
parent 1e7a1b8194
commit f8ff2852bf

View File

@ -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.