Grab PID from response without dereffing a type punned pointer.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Tue, 7 Jan 2014 04:48:50 +0000 (23:48 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Tue, 7 Jan 2014 04:48:50 +0000 (23:48 -0500)
deps/isotp-c
src/obd2/obd2.c

index 8922abb..513d8c8 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 8922abb7ff8c30e1fa5af078284eb6aebf0052e5
+Subproject commit 513d8c8d7089960618a1fa00a71442dc39294588
index c780fd8..93cb888 100644 (file)
@@ -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];
             }