Skip to content

Commit

Permalink
Draft of accepting responses from any arbitration ID.
Browse files Browse the repository at this point in the history
See #5.
  • Loading branch information
peplin committed Oct 7, 2014
1 parent b2033dd commit e33a1c0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 48 deletions.
2 changes: 1 addition & 1 deletion deps/isotp-c
Submodule isotp-c updated 2 files
+0 −3 .travis.yml
+2 −1 src/isotp/isotp.c
72 changes: 31 additions & 41 deletions src/uds/uds.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ DiagnosticShims diagnostic_init_shims(LogShim log,

static void setup_receive_handle(DiagnosticRequestHandle* handle) {
if(handle->request.arbitration_id == OBD2_FUNCTIONAL_BROADCAST_ID) {
uint32_t response_id;
for(response_id = 0;
response_id < OBD2_FUNCTIONAL_RESPONSE_COUNT; ++response_id) {
handle->isotp_receive_handles[response_id] = isotp_receive(
&handle->isotp_shims,
OBD2_FUNCTIONAL_RESPONSE_START + response_id,
NULL);
}
handle->isotp_receive_handle_count = OBD2_FUNCTIONAL_RESPONSE_COUNT;
handle->isotp_receive_handle = isotp_receive(
&handle->isotp_shims,
// TODO need to setup a single wildcard receive handle that accepts any
// ID matching the mode and pid, if set.
0xff,
NULL);
} else {
handle->isotp_receive_handle_count = 1;
handle->isotp_receive_handles[0] = isotp_receive(&handle->isotp_shims,
handle->isotp_receive_handle = isotp_receive(&handle->isotp_shims,
handle->request.arbitration_id + ARBITRATION_ID_OFFSET,
NULL);
}
Expand Down Expand Up @@ -241,41 +237,35 @@ DiagnosticResponse diagnostic_receive_can_frame(DiagnosticShims* shims,
isotp_continue_send(&handle->isotp_shims,
&handle->isotp_send_handle, arbitration_id, data, size);
} else {
uint8_t i;
for(i = 0; i < handle->isotp_receive_handle_count; ++i) {
IsoTpMessage message = isotp_continue_receive(&handle->isotp_shims,
&handle->isotp_receive_handles[i], arbitration_id, data,
size);

if(message.completed) {
if(message.size > 0) {
response.mode = message.payload[0];
if(handle_negative_response(&message, &response, shims) ||
handle_positive_response(handle, &message,
&response, shims)) {
if(shims->log != NULL) {
char response_string[128] = {0};
diagnostic_response_to_string(&response,
response_string, sizeof(response_string));
shims->log("Diagnostic response received: %s",
response_string);
}

handle->success = true;
handle->completed = true;
}
} else {
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) ||
handle_positive_response(handle, &message,
&response, shims)) {
if(shims->log != NULL) {
shims->log("Received an empty response on arb ID 0x%x",
response.arbitration_id);
char response_string[128] = {0};
diagnostic_response_to_string(&response,
response_string, sizeof(response_string));
shims->log("Diagnostic response received: %s",
response_string);
}
}

if(handle->completed && handle->callback != NULL) {
handle->callback(&response);
handle->success = true;
handle->completed = true;
}
} else {
if(shims->log != NULL) {
shims->log("Received an empty response on arb ID 0x%x",
response.arbitration_id);
}
}

break;
if(handle->completed && handle->callback != NULL) {
handle->callback(&response);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/uds/uds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#define OBD2_FUNCTIONAL_BROADCAST_ID 0x7df
#define OBD2_FUNCTIONAL_RESPONSE_START 0x7e8
#define OBD2_FUNCTIONAL_RESPONSE_COUNT 8

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 1 addition & 3 deletions src/uds/uds_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern "C" {
// TODO This isn't true for multi frame messages - we may need to dynamically
// allocate this in the future
#define MAX_UDS_PAYLOAD_LENGTH 7
#define MAX_RESPONDING_ECU_COUNT 8
#define VIN_LENGTH 17

/* Private: The four main types of diagnositc requests that determine how the
Expand Down Expand Up @@ -162,8 +161,7 @@ typedef struct {
// Private
IsoTpShims isotp_shims;
IsoTpSendHandle isotp_send_handle;
IsoTpReceiveHandle isotp_receive_handles[MAX_RESPONDING_ECU_COUNT];
uint8_t isotp_receive_handle_count;
IsoTpReceiveHandle isotp_receive_handle;
DiagnosticResponseReceived callback;
// DiagnosticMilStatusReceived mil_status_callback;
// DiagnosticVinReceived vin_callback;
Expand Down
3 changes: 1 addition & 2 deletions tests/test_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ START_TEST (test_send_functional_request)
fail_if(last_response_was_received);
const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23};
for(uint16_t filter = OBD2_FUNCTIONAL_RESPONSE_START; filter <
OBD2_FUNCTIONAL_RESPONSE_START + OBD2_FUNCTIONAL_RESPONSE_COUNT;
filter++) {
OBD2_FUNCTIONAL_RESPONSE_START + 20; filter++) {
DiagnosticResponse response = diagnostic_receive_can_frame(&SHIMS,
&handle, filter, can_data, sizeof(can_data));
fail_unless(response.success);
Expand Down

0 comments on commit e33a1c0

Please sign in to comment.