summaryrefslogtreecommitdiffstats
path: root/src/uds/uds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uds/uds.c')
-rw-r--r--src/uds/uds.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/uds/uds.c b/src/uds/uds.c
index 6a4ce45..ff35b24 100644
--- a/src/uds/uds.c
+++ b/src/uds/uds.c
@@ -262,3 +262,40 @@ float diagnostic_payload_to_float(const DiagnosticResponse* response) {
response->payload_length, 0,
response->payload_length * CHAR_BIT, 1.0, 0);
}
+
+/* Public:
+ *
+ * Functions pulled from http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01
+ */
+float diagnostic_decode_obd2_pid(const DiagnosticResponse* response) {
+ // handles on the single number values, not the bit encoded ones
+ switch(response->pid) {
+ case 0xa:
+ return response->payload[0] * 3;
+ case 0xc:
+ return (response->payload[0] * 256 + response->payload[1]) / 4.0;
+ case 0xd:
+ case 0x33:
+ case 0xb:
+ return response->payload[0];
+ case 0x10:
+ return (response->payload[0] * 256 + response->payload[1]) / 100.0;
+ case 0x11:
+ case 0x2f:
+ case 0x45:
+ case 0x4c:
+ case 0x52:
+ case 0x5a:
+ case 0x4:
+ return response->payload[0] * 100.0 / 255.0;
+ case 0x46:
+ case 0x5c:
+ case 0xf:
+ case 0x5:
+ return response->payload[0] - 40;
+ case 0x62:
+ return response->payload[0] - 125;
+ default:
+ return 0;
+ }
+}