summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-06 23:48:50 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-06 23:48:50 -0500
commit871b3cb04aaa24637a3b2bfae7082dfacf34f7d2 (patch)
treef4160b62374e54c9f24c0dac31e0132cacb4acc7 /src
parentb2705b3ec209311506af2034e021285daf3c9649 (diff)
Grab PID from response without dereffing a type punned pointer.
Diffstat (limited to 'src')
-rw-r--r--src/obd2/obd2.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c
index c780fd8c..93cb8883 100644
--- a/src/obd2/obd2.c
+++ b/src/obd2/obd2.c
@@ -140,10 +140,8 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle,
response->mode = handle->request.mode;
if(handle->request.pid_length > 0 && message->size > 1) {
if(handle->request.pid_length == 2) {
- response->pid = *(uint16_t*)&message->payload[PID_BYTE_INDEX];
- if(BYTE_ORDER == LITTLE_ENDIAN) {
- response->pid = __builtin_bswap32(response->pid << 16);
- }
+ response->pid = get_bitfield(message->payload, message->size,
+ PID_BYTE_INDEX * CHAR_BIT, sizeof(uint16_t) * CHAR_BIT);
} else {
response->pid = message->payload[PID_BYTE_INDEX];
}