// hide the "response" version of the mode from the user
// if it matched
response->mode = handle->request.mode;
- bool has_pid = false;
+ response->has_pid = false;
if(handle->request.pid_length > 0 && message->size > 1) {
- has_pid = true;
+ response->has_pid = true;
if(handle->request.pid_length == 2) {
response->pid = get_bitfield(message->payload, message->size,
PID_BYTE_INDEX * CHAR_BIT, sizeof(uint16_t) * CHAR_BIT);
response->payload_length);
}
- if((handle->request.pid_length == 0 && !has_pid)
+ if((handle->request.pid_length == 0 && !response->has_pid)
|| response->pid == handle->request.pid) {
response->success = true;
response->completed = true;
* the negative_response_code field for the reason.
* arbitration_id - The arbitration ID the response was received on.
* mode - The OBD-II mode for the original request.
- * pid - If the request was for a PID, this is the PID echo.
+ * has_pid - If this is a response to a PID request, this will be true and the
+ * 'pid' field will be valid.
+ * pid - If the request was for a PID, this is the PID echo. Only valid if
+ * 'has_pid' is true.
* negative_response_code - If the request was not successful, 'success' will be
* false and this will be set to a DiagnosticNegativeResponseCode returned
* by the other node.
bool success;
uint16_t arbitration_id;
uint8_t mode;
+ bool has_pid;
uint16_t pid;
DiagnosticNegativeResponseCode negative_response_code;
uint8_t payload[MAX_OBD2_PAYLOAD_LENGTH];
ck_assert_int_eq(last_response_received.arbitration_id,
filter);
ck_assert_int_eq(last_response_received.mode, request.mode);
- ck_assert_int_eq(last_response_received.pid, 0);
+ fail_if(last_response_received.has_pid);
ck_assert_int_eq(last_response_received.payload_length, 1);
ck_assert_int_eq(last_response_received.payload[0], can_data[2]);
}
ck_assert_int_eq(last_response_received.arbitration_id,
request.arbitration_id + 0x8);
ck_assert_int_eq(last_response_received.mode, request.mode);
- ck_assert_int_eq(last_response_received.pid, 0);
+ fail_if(last_response_received.has_pid);
ck_assert_int_eq(last_response_received.payload_length, 1);
ck_assert_int_eq(last_response_received.payload[0], can_data[2]);
}
ck_assert_int_eq(last_response_received.arbitration_id,
arb_id + 0x8);
ck_assert_int_eq(last_response_received.mode, 0x1);
+ fail_unless(last_response_received.has_pid);
ck_assert_int_eq(last_response_received.pid, 0x2);
ck_assert_int_eq(last_response_received.payload_length, 1);
ck_assert_int_eq(last_response_received.payload[0], can_data[3]);
ck_assert_int_eq(last_response_received.arbitration_id,
arb_id + 0x8);
ck_assert_int_eq(last_response_received.mode, 0x22);
+ fail_unless(last_response_received.has_pid);
ck_assert_int_eq(last_response_received.pid, 0x2);
ck_assert_int_eq(last_response_received.payload_length, 1);
ck_assert_int_eq(last_response_received.payload[0], can_data[4]);