+ if(!handle->isotp_send_handle.completed) {
+ isotp_continue_send(&handle->isotp_shims,
+ &handle->isotp_send_handle, arbitration_id, data, size);
+ } else if(!handle->isotp_receive_handle.completed) {
+ IsoTpMessage message = isotp_continue_receive(&handle->isotp_shims,
+ &handle->isotp_receive_handle, arbitration_id, data, size);
+
+ if(message.completed) {
+ if(message.size > 0) {
+ response.mode = message.payload[0];
+ if(handle_negative_response(&message, &response, shims)) {
+ shims->log("Received a negative response to mode %d on arb ID 0x%x",
+ response.mode, response.arbitration_id);
+
+ // TODO clarify what it means for a handle to be successful (we made
+ // a good request+response) vs a request itself being
+ // successfully
+ // (the other node didn't return a negative response).
+ handle->success = true;
+ handle->completed = true;
+ } else if(handle_positive_response(handle, &message, &response,
+ shims)) {
+ shims->log("Received a positive mode %d response on arb ID 0x%x",
+ response.mode, response.arbitration_id);
+ handle->success = true;
+ handle->completed = true;
+ } else {
+ shims->log("Response was for a mode 0x%x request, not our mode 0x%x request",
+ response.mode - MODE_RESPONSE_OFFSET,
+ handle->request.mode);
+ }
+ }
+
+ if(handle->completed && handle->callback != NULL) {
+ handle->callback(&response);
+ }
+ }