diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/obd2/extras.c | 10 | ||||
-rw-r--r-- | src/obd2/obd2.c | 13 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/obd2/extras.c b/src/obd2/extras.c index 905ef89d..37a55fe2 100644 --- a/src/obd2/extras.c +++ b/src/obd2/extras.c @@ -1,4 +1,5 @@ #include <obd2/extras.h> +#include <obd2/obd2.h> // TODO everything below here is for future work...not critical for now. @@ -7,18 +8,25 @@ DiagnosticRequestHandle diagnostic_request_malfunction_indicator_status( DiagnosticMilStatusReceived callback) { // TODO request malfunction indicator light (MIL) status - request mode 1 // pid 1, parse first bit + DiagnosticRequestHandle handle; + return handle; } DiagnosticRequestHandle diagnostic_request_vin(DiagnosticShims* shims, DiagnosticVinReceived callback) { + DiagnosticRequestHandle handle; + return handle; } DiagnosticRequestHandle diagnostic_request_dtc(DiagnosticShims* shims, DiagnosticTroubleCodeType dtc_type, DiagnosticTroubleCodesReceived callback) { + DiagnosticRequestHandle handle; + return handle; } bool diagnostic_clear_dtc(DiagnosticShims* shims) { + return false; } DiagnosticRequestHandle diagnostic_enumerate_pids(DiagnosticShims* shims, @@ -26,4 +34,6 @@ DiagnosticRequestHandle diagnostic_enumerate_pids(DiagnosticShims* shims, // before calling the callback, split up the received bytes into 1 or 2 byte // chunks depending on the mode so the final pid list is actual 1 or 2 byte PIDs // TODO request supported PIDs - request PID 0 and parse 4 bytes in response + DiagnosticRequestHandle handle; + return handle; } diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c index 8a80da64..83aa1fda 100644 --- a/src/obd2/obd2.c +++ b/src/obd2/obd2.c @@ -1,5 +1,9 @@ #include <obd2/obd2.h> -#include <arpa/inet.h> +#include <bitfield/bitfield.h> +#include <string.h> +#include <limits.h> +#include <stddef.h> +#include <sys/param.h> #define ARBITRATION_ID_OFFSET 0x8 #define MODE_RESPONSE_OFFSET 0x40 @@ -33,7 +37,8 @@ DiagnosticRequestHandle diagnostic_request(DiagnosticShims* shims, uint8_t payload[MAX_DIAGNOSTIC_PAYLOAD_SIZE]; payload[MODE_BYTE_INDEX] = request->mode; if(request->pid_length > 0) { - copy_bytes_right_aligned(&request->pid, sizeof(request->pid), + // TODO may need to flip the byte order + copy_bytes_right_aligned((uint8_t*)&request->pid, sizeof(request->pid), PID_BYTE_INDEX, request->pid_length, payload, sizeof(payload)); } if(request->payload_length > 0) { @@ -117,7 +122,9 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle, if(handle->request.pid_length > 0 && message->size > 1) { if(handle->request.pid_length == 2) { response->pid = *(uint16_t*)&message->payload[PID_BYTE_INDEX]; - response->pid = ntohs(response->pid); + if(BYTE_ORDER == LITTLE_ENDIAN) { + response->pid = __builtin_bswap32(response->pid << 16); + } } else { response->pid = message->payload[PID_BYTE_INDEX]; } |