diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index f950744..892b073 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -85,18 +85,6 @@ device_is_oceanic_atom2 (device_t *abstract) } -static device_status_t -oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[], unsigned int csize) -{ - // Send the command to the dive computer and - // wait until all data has been transmitted. - serial_write (device->port, command, csize); - serial_drain (device->port); - - return DEVICE_STATUS_SUCCESS; -} - - static device_status_t oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) { @@ -110,14 +98,14 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm unsigned char response = NAK; while (response == NAK) { // Send the command to the dive computer. - device_status_t rc = oceanic_atom2_send (device, command, csize); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, csize); + if (n != csize) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the response (ACK/NAK) of the dive computer. - int n = serial_read (device->port, &response, 1); + n = serial_read (device->port, &response, 1); if (n != 1) { WARNING ("Failed to receive the answer."); return EXITCODE (n); @@ -165,15 +153,15 @@ oceanic_atom2_init (oceanic_atom2_device_t *device) { // Send the command to the dive computer. unsigned char command[3] = {0xA8, 0x99, 0x00}; - device_status_t rc = oceanic_atom2_send (device, command, sizeof (command)); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, sizeof (command)); + if (n != sizeof (command)) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the answer of the dive computer. unsigned char answer[3] = {0}; - int n = serial_read (device->port, answer, sizeof (answer)); + n = serial_read (device->port, answer, sizeof (answer)); if (n != sizeof (answer)) { WARNING ("Failed to receive the answer."); return EXITCODE (n); @@ -194,15 +182,15 @@ oceanic_atom2_quit (oceanic_atom2_device_t *device) { // Send the command to the dive computer. unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00}; - device_status_t rc = oceanic_atom2_send (device, command, sizeof (command)); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, sizeof (command)); + if (n != sizeof (command)) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the answer of the dive computer. unsigned char answer[1] = {0}; - int n = serial_read (device->port, answer, sizeof (answer)); + n = serial_read (device->port, answer, sizeof (answer)); if (n != sizeof (answer)) { WARNING ("Failed to receive the answer."); return EXITCODE (n); diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index a4428d8..bbc83d6 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -86,21 +86,6 @@ device_is_oceanic_veo250 (device_t *abstract) } -static device_status_t -oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize) -{ - // Discard garbage bytes. - serial_flush (device->port, SERIAL_QUEUE_INPUT); - - // Send the command to the dive computer and - // wait until all data has been transmitted. - serial_write (device->port, command, csize); - serial_drain (device->port); - - return DEVICE_STATUS_SUCCESS; -} - - static device_status_t oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) { @@ -113,15 +98,18 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co unsigned int nretries = 0; unsigned char response = NAK; while (response == NAK) { + // Discard garbage bytes. + serial_flush (device->port, SERIAL_QUEUE_INPUT); + // Send the command to the dive computer. - device_status_t rc = oceanic_veo250_send (device, command, csize); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, csize); + if (n != csize) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the response (ACK/NAK) of the dive computer. - int n = serial_read (device->port, &response, 1); + n = serial_read (device->port, &response, 1); if (n != 1) { WARNING ("Failed to receive the answer."); return EXITCODE (n); @@ -165,15 +153,15 @@ oceanic_veo250_init (oceanic_veo250_device_t *device) { // Send the command to the dive computer. unsigned char command[2] = {0x55, 0x00}; - device_status_t rc = oceanic_veo250_send (device, command, sizeof (command)); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, sizeof (command)); + if (n != sizeof (command)) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the answer of the dive computer. unsigned char answer[14] = {0}; - int n = serial_read (device->port, answer, sizeof (answer)); + n = serial_read (device->port, answer, sizeof (answer)); if (n != sizeof (answer)) { WARNING ("Failed to receive the answer."); return EXITCODE (n); @@ -197,10 +185,10 @@ oceanic_veo250_quit (oceanic_veo250_device_t *device) { // Send the command to the dive computer. unsigned char command[2] = {0x98, 0x00}; - device_status_t rc = oceanic_veo250_send (device, command, sizeof (command)); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, sizeof (command)); + if (n != sizeof (command)) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } return DEVICE_STATUS_SUCCESS; diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index eaa8b88..019182c 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -86,18 +86,6 @@ device_is_oceanic_vtpro (device_t *abstract) } -static device_status_t -oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[], unsigned int csize) -{ - // Send the command to the dive computer and - // wait until all data has been transmitted. - serial_write (device->port, command, csize); - serial_drain (device->port); - - return DEVICE_STATUS_SUCCESS; -} - - static device_status_t oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) { @@ -111,14 +99,14 @@ oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char comm unsigned char response = NAK; while (response == NAK) { // Send the command to the dive computer. - device_status_t rc = oceanic_vtpro_send (device, command, csize); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, csize); + if (n != csize) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the response (ACK/NAK) of the dive computer. - int n = serial_read (device->port, &response, 1); + n = serial_read (device->port, &response, 1); if (n != 1) { WARNING ("Failed to receive the answer."); return EXITCODE (n); @@ -156,15 +144,15 @@ oceanic_vtpro_init (oceanic_vtpro_device_t *device) { // Send the command to the dive computer. unsigned char command[2] = {0xAA, 0x00}; - device_status_t rc = oceanic_vtpro_send (device, command, sizeof (command)); - if (rc != DEVICE_STATUS_SUCCESS) { + int n = serial_write (device->port, command, sizeof (command)); + if (n != sizeof (command)) { WARNING ("Failed to send the command."); - return rc; + return EXITCODE (n); } // Receive the answer of the dive computer. unsigned char answer[13] = {0}; - int n = serial_read (device->port, answer, sizeof (answer)); + n = serial_read (device->port, answer, sizeof (answer)); if (n != sizeof (answer)) { WARNING ("Failed to receive the answer."); return EXITCODE (n); diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 14cda3f..5b6c197 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -195,22 +195,6 @@ uwatec_memomouse_device_set_fingerprint (device_t *abstract, const unsigned char } -static device_status_t -uwatec_memomouse_confirm (uwatec_memomouse_device_t *device, unsigned char value) -{ - // Send the value to the device. - int rc = serial_write (device->port, &value, 1); - if (rc != 1) { - WARNING ("Failed to send the value."); - return EXITCODE (rc); - } - - serial_drain (device->port); - - return DEVICE_STATUS_SUCCESS; -} - - static device_status_t uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size, unsigned int *result) { @@ -271,9 +255,12 @@ uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned serial_flush (device->port, SERIAL_QUEUE_INPUT); // Reject the packet. - rc = uwatec_memomouse_confirm (device, NAK); - if (rc != DEVICE_STATUS_SUCCESS) - return rc; + unsigned char value = NAK; + int n = serial_write (device->port, &value, 1); + if (n != 1) { + WARNING ("Failed to reject the packet."); + return EXITCODE (n); + } } return DEVICE_STATUS_SUCCESS; @@ -304,9 +291,12 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer return rc; // Accept the packet. - rc = uwatec_memomouse_confirm (device, ACK); - if (rc != DEVICE_STATUS_SUCCESS) - return rc; + unsigned char value = ACK; + int n = serial_write (device->port, &value, 1); + if (n != 1) { + WARNING ("Failed to accept the packet."); + return EXITCODE (n); + } if (nbytes == 0) { // The first packet should contain at least @@ -370,9 +360,12 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t * serial_flush (device->port, SERIAL_QUEUE_INPUT); // Reject the packet. - device_status_t rc = uwatec_memomouse_confirm (device, NAK); - if (rc != DEVICE_STATUS_SUCCESS) - return rc; + unsigned char value = NAK; + int n = serial_write (device->port, &value, 1); + if (n != 1) { + WARNING ("Failed to reject the packet."); + return EXITCODE (n); + } serial_sleep (300); } @@ -413,8 +406,6 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t * return EXITCODE (n); } - serial_drain (device->port); - // Wait for the answer (ACK). n = serial_read (device->port, &answer, 1); if (n != 1) {