-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathELMduino.cpp
2923 lines (2404 loc) · 67.4 KB
/
ELMduino.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "ELMduino.h"
/*
bool ELM327::begin(Stream &stream, const bool& debug, const uint16_t& timeout, const char& protocol, const uint16_t& payloadLen, const byte& dataTimeout)
Description:
------------
* Constructor for the ELM327 Class; initializes ELM327
Inputs:
-------
* Stream &stream - Reference to Serial port connected to ELM327
* bool debug - Specify whether or not to print debug statements to "Serial"
* uint16_t timeout - Time in ms to wait for a query response
* char protocol - Protocol ID to specify the ELM327 to communicate with the ECU over
* uint16_t payloadLen - Maximum number of bytes expected to be returned by the ELM327 after a query
* byte dataTimeout - Number of ms to wait after receiving data before the ELM327 will
return the data - see https://www.elmelectronics.com/help/obd/tips/#UnderstandingOBD
Return:
-------
* bool - Whether or not the ELM327 was properly initialized
*/
bool ELM327::begin(Stream &stream, const bool &debug, const uint16_t &timeout, const char &protocol, const uint16_t &payloadLen, const byte &dataTimeout)
{
elm_port = &stream;
PAYLOAD_LEN = payloadLen;
debugMode = debug;
timeout_ms = timeout;
payload = (char *)malloc(PAYLOAD_LEN + 1); // allow for terminating '\0'
// test if serial port is connected
if (!elm_port)
return false;
// try to connect
if (!initializeELM(protocol, dataTimeout))
return false;
return true;
}
/*
bool ELM327::initializeELM(const char& protocol, const byte& dataTimeout)
Description:
------------
* Initializes ELM327
Inputs:
-------
* char protocol - Protocol ID to specify the ELM327 to communicate with the ECU over
* byte dataTimeout - Number of ms to wait after receiving data before the ELM327 will
return the data - see https://www.elmelectronics.com/help/obd/tips/#UnderstandingOBD
Return:
-------
* bool - Whether or not the ELM327 was propperly initialized
Notes:
------
* Protocol - Description
* 0 - Automatic
* 1 - SAE J1850 PWM (41.6 kbaud)
* 2 - SAE J1850 PWM (10.4 kbaud)
* 3 - ISO 9141-2 (5 baud init)
* 4 - ISO 14230-4 KWP (5 baud init)
* 5 - ISO 14230-4 KWP (fast init)
* 6 - ISO 15765-4 CAN (11 bit ID, 500 kbaud)
* 7 - ISO 15765-4 CAN (29 bit ID, 500 kbaud)
* 8 - ISO 15765-4 CAN (11 bit ID, 250 kbaud)
* 9 - ISO 15765-4 CAN (29 bit ID, 250 kbaud)
* A - SAE J1939 CAN (29 bit ID, 250* kbaud)
* B - User1 CAN (11* bit ID, 125* kbaud)
* C - User2 CAN (11* bit ID, 50* kbaud)
* --> *user adjustable
*/
bool ELM327::initializeELM(const char &protocol, const byte &dataTimeout)
{
char command[10] = {'\0'};
connected = false;
sendCommand_Blocking(SET_ALL_TO_DEFAULTS);
delay(100);
sendCommand_Blocking(RESET_ALL);
delay(100);
sendCommand_Blocking(ECHO_OFF);
delay(100);
sendCommand_Blocking(PRINTING_SPACES_OFF);
delay(100);
sendCommand_Blocking(ALLOW_LONG_MESSAGES);
delay(100);
// // Set data timeout
sprintf(command, SET_TIMEOUT_TO_H_X_4MS, dataTimeout / 4);
sendCommand_Blocking(command);
delay(100);
// Automatic searching for protocol requires setting the protocol to AUTO and then
// sending an OBD command to initiate the protocol search. The OBD command "0100"
// requests a list of supported PIDs 0x00 - 0x20 and is guaranteed to work
if ((String)protocol == "0")
{
// Tell the ELM327 to do an auto protocol search. If a valid protocol is found, it will be saved to memory.
// Some ELM clones may not have memory enabled and thus will perform the search every time.
sprintf(command, SET_PROTOCOL_TO_AUTO_H_SAVE, protocol);
if (sendCommand_Blocking(command) == ELM_SUCCESS)
{
if (strstr(payload, RESPONSE_OK) != NULL)
{
// Protocol search can take a comparatively long time. Temporarily set
// the timeout value to 30 seconds, then restore the previous value.
uint16_t prevTimeout = timeout_ms;
timeout_ms = 30000;
int8_t state = sendCommand_Blocking("0100");
if (state == ELM_SUCCESS)
{
timeout_ms = prevTimeout;
connected = true;
return connected;
}
else if (state == ELM_BUFFER_OVERFLOW)
{
while (elm_port->available())
elm_port->read();
}
timeout_ms = prevTimeout;
}
}
}
else
{
// Set protocol
sprintf(command, TRY_PROT_H_AUTO_SEARCH, protocol);
if (sendCommand_Blocking(command) == ELM_SUCCESS)
{
if (strstr(payload, RESPONSE_OK) != NULL)
{
connected = true;
return connected;
}
}
}
if (debugMode)
{
Serial.print(F("Setting protocol via "));
Serial.print(TRY_PROT_H_AUTO_SEARCH);
Serial.print(F(" did not work - trying via "));
Serial.println(SET_PROTOCOL_TO_H_SAVE);
}
// Set protocol and save
sprintf(command, SET_PROTOCOL_TO_H_SAVE, protocol);
if (sendCommand_Blocking(command) == ELM_SUCCESS)
{
if (strstr(payload, RESPONSE_OK) != NULL)
{
connected = true;
return connected;
}
}
if (debugMode)
{
Serial.print(F("Setting protocol via "));
Serial.print(SET_PROTOCOL_TO_H_SAVE);
Serial.println(F(" did not work"));
}
return connected;
}
/*
void ELM327::formatQueryArray(uint8_t service, uint16_t pid, uint8_t num_responses)
Description:
------------
* Creates a query stack to be sent to ELM327
Inputs:
-------
* uint16_t service - Service number of the queried PID
* uint32_t pid - PID number of the queried PID
* uint8_t num_responses - see function header for "queryPID()"
Return:
-------
* void
*/
void ELM327::formatQueryArray(uint8_t service, uint16_t pid, uint8_t num_responses)
{
if (debugMode)
{
Serial.print(F("Service: "));
Serial.println(service);
Serial.print(F("PID: "));
Serial.println(pid);
}
isMode0x22Query = (service == 0x22 && pid <= 0xFF); // mode 0x22 responses always zero-pad the pid to 4 chars, even for a 2-char pid
query[0] = ((service >> 4) & 0xF) + '0';
query[1] = (service & 0xF) + '0';
// determine PID length (standard queries have 16-bit PIDs,
// but some custom queries have PIDs with 32-bit values)
if (pid & 0xFF00)
{
if (debugMode)
Serial.println(F("Long query detected"));
longQuery = true;
query[2] = ((pid >> 12) & 0xF) + '0';
query[3] = ((pid >> 8) & 0xF) + '0';
query[4] = ((pid >> 4) & 0xF) + '0';
query[5] = (pid & 0xF) + '0';
if (specifyNumResponses)
{
if (num_responses > 0xF)
{
query[6] = ((num_responses >> 4) & 0xF) + '0';
query[7] = (num_responses & 0xF) + '0';
query[8] = '\0';
upper(query, 8);
}
else
{
query[6] = (num_responses & 0xF) + '0';
query[7] = '\0';
query[8] = '\0';
upper(query, 7);
}
}
else
{
query[6] = '\0';
query[7] = '\0';
query[8] = '\0';
upper(query, 6);
}
}
else
{
if (debugMode)
Serial.println(F("Normal length query detected"));
longQuery = false;
query[2] = ((pid >> 4) & 0xF) + '0';
query[3] = (pid & 0xF) + '0';
if (specifyNumResponses)
{
if (num_responses > 0xF)
{
query[4] = ((num_responses >> 4) & 0xF) + '0';
query[5] = (num_responses & 0xF) + '0';
query[6] = '\0';
query[7] = '\0';
query[8] = '\0';
upper(query, 6);
}
else
{
query[4] = (num_responses & 0xF) + '0';
query[5] = '\0';
query[6] = '\0';
query[7] = '\0';
query[8] = '\0';
upper(query, 5);
}
}
else
{
query[4] = '\0';
query[5] = '\0';
query[6] = '\0';
query[7] = '\0';
query[8] = '\0';
upper(query, 4);
}
}
if (debugMode)
{
Serial.print(F("Query string: "));
Serial.println(query);
}
}
/*
void ELM327::upper(char string[], uint8_t buflen)
Description:
------------
* Converts all elements of char array string[] to
uppercase ascii
Inputs:
-------
* uint8_t string[] - Char array
* uint8_t buflen - Length of char array
Return:
-------
* void
*/
void ELM327::upper(char string[], uint8_t buflen)
{
for (uint8_t i = 0; i < buflen; i++)
{
if (string[i] > 'Z')
string[i] -= 32;
else if ((string[i] > '9') && (string[i] < 'A'))
string[i] += 7;
}
}
/*
bool ELM327::timeout()
Description:
------------
* Determines if a time-out has occurred
Inputs:
-------
* void
Return:
-------
* bool - whether or not a time-out has occurred
*/
bool ELM327::timeout()
{
currentTime = millis();
if ((currentTime - previousTime) >= timeout_ms)
return true;
return false;
}
/*
uint8_t ELM327::ctoi(uint8_t value)
Description:
------------
* converts a decimal or hex char to an int
Inputs:
-------
* uint8_t value - char to be converted
Return:
-------
* uint8_t - int value of parameter "value"
*/
uint8_t ELM327::ctoi(uint8_t value)
{
if (value >= 'A')
return value - 'A' + 10;
else
return value - '0';
}
/*
int8_t ELM327::nextIndex(char const *str,
char const *target,
uint8_t numOccur)
Description:
------------
* Finds and returns the first char index of
numOccur'th instance of target in str
Inputs:
-------
* char const *str - string to search target within
* char const *target - String to search for in str
* uint8_t numOccur - Which instance of target in str
Return:
-------
* int8_t - First char index of numOccur'th
instance of target in str. -1 if there is no
numOccur'th instance of target in str
*/
int8_t ELM327::nextIndex(char const *str,
char const *target,
uint8_t numOccur = 1)
{
char const *p = str;
char const *r = str;
uint8_t count;
for (count = 0;; ++count)
{
p = strstr(p, target);
if (count == (numOccur - 1))
break;
if (!p)
break;
p++;
}
if (!p)
return -1;
return p - r;
}
/*
double ELM327::conditionResponse(const uint8_t &numExpectedBytes, const float &scaleFactor, const float &bias)
Description:
------------
* Converts the ELM327's response into it's correct, numerical value. Returns 0 if numExpectedBytes > numPayChars
Inputs:
-------
* uint64_t response - ELM327's response
* uint8_t numExpectedBytes - Number of valid bytes from the response to process
* float scaleFactor - Amount to scale the response by
* float bias - Amount to bias the response by
Return:
-------
* double - Converted numerical value
*/
double ELM327::conditionResponse(const uint8_t &numExpectedBytes, const double &scaleFactor, const float &bias)
{
uint8_t numExpectedPayChars = numExpectedBytes * 2;
uint8_t payCharDiff = numPayChars - numExpectedPayChars;
if (numExpectedBytes > 8)
{
if (debugMode)
Serial.println(F("WARNING: Number of expected response bytes is greater than 8 - returning 0"));
return 0;
}
if (numPayChars < numExpectedPayChars)
{
if (debugMode)
Serial.println(F("WARNING: Number of payload chars is less than the number of expected response chars returned by ELM327 - returning 0"));
return 0;
}
else if (numPayChars & 0x1)
{
if (debugMode)
Serial.println(F("WARNING: Number of payload chars returned by ELM327 is an odd value - returning 0"));
return 0;
}
else if (numExpectedPayChars == numPayChars)
{
if (scaleFactor == 1 && bias == 0) // No scale/bias needed
{
return response;
}
else
{
return (response * scaleFactor) + bias;
}
}
// If there were more payload bytes returned than we expected, test the first and last bytes in the
// returned payload and see which gives us a higher value. Sometimes ELM327's return leading zeros
// and others return trailing zeros. The following approach gives us the best chance at determining
// where the real data is. Note that if the payload returns BOTH leading and trailing zeros, this
// will not give accurate results!
if (debugMode)
Serial.println(F("Looking for lagging zeros"));
uint16_t numExpectedBits = numExpectedBytes * 8;
uint64_t laggingZerosMask = 0;
for (uint16_t i = 0; i < numExpectedBits; i++)
laggingZerosMask |= (1 << i);
if (!(laggingZerosMask & response)) // Detect all lagging zeros in `response`
{
if (debugMode)
Serial.println(F("Lagging zeros found"));
if (scaleFactor == 1 && bias == 0) // No scale/bias needed
{
return (response >> (4 * payCharDiff));
}
else
{
return ((response >> (4 * payCharDiff)) * scaleFactor) + bias;
}
}
else
{
if (debugMode)
Serial.println(F("Lagging zeros not found - assuming leading zeros"));
if (scaleFactor == 1 && bias == 0) // No scale/bias needed
{
return response;
}
else
{
return (response * scaleFactor) + bias;
}
}
}
/*
void ELM327::flushInputBuff()
Description:
------------
* Flushes input serial buffer
Inputs:
-------
* void
Return:
-------
* void
*/
void ELM327::flushInputBuff()
{
if (debugMode)
Serial.println(F("Clearing input serial buffer"));
while (elm_port->available())
elm_port->read();
}
/*
bool ELM327::queryPID(const uint8_t& service, const uint16_t& pid, const uint8_t& num_responses)
Description:
------------
* create a PID query command string and send the command
Inputs:
-------
* uint8_t service - The diagnostic service ID. 01 is "Show current data"
* uint16_t pid - The Parameter ID (PID) from the service
* uint8_t num_responses - Number of lines of data to receive - see ELM datasheet "Talking to the vehicle".
This can speed up retrieval of information if you know how many responses will be sent.
Basically the OBD scanner will not wait for more responses if it does not need to go through
final timeout. Also prevents OBD scanners from sending mulitple of the same response.
Return:
-------
* bool - Whether or not the query was submitted successfully
*/
bool ELM327::queryPID(const uint8_t &service, const uint16_t &pid, const uint8_t &num_responses)
{
formatQueryArray(service, pid, num_responses);
sendCommand(query);
return connected;
}
/*
bool ELM327::queryPID(char queryStr[])
Description:
------------
* Queries ELM327 for a specific type of vehicle telemetry data
Inputs:
-------
* char queryStr[] - Query string (service and PID)
Return:
-------
* bool - Whether or not the query was submitted successfully
*/
bool ELM327::queryPID(char queryStr[])
{
if (strlen(queryStr) <= 4)
longQuery = false;
else
longQuery = true;
sendCommand(queryStr);
return connected;
}
/*
double ELM327::processPID(const uint8_t& service, const uint16_t& pid, const uint8_t& num_responses, const uint8_t& numExpectedBytes, const float& scaleFactor, const float& bias)
Description:
------------
* Queries ELM327 for a specific type of vehicle telemetry data
Inputs:
-------
* uint8_t service - The diagnostic service ID. 01 is "Show current data"
* uint16_t pid - The Parameter ID (PID) from the service
* uint8_t num_responses - Number of lines of data to receive - see ELM datasheet "Talking to the vehicle".
This can speed up retrieval of information if you know how many responses will be sent.
Basically the OBD scanner will not wait for more responses if it does not need to go through
final timeout. Also prevents OBD scanners from sending mulitple of the same response.
* uint8_t numExpectedBytes - Number of valid bytes from the response to process
* float scaleFactor - Amount to scale the response by
* float bias - Amount to bias the response by
Return:
-------
* float - The PID value if successfully received, else 0.0
*/
double ELM327::processPID(const uint8_t &service, const uint16_t &pid, const uint8_t &num_responses, const uint8_t &numExpectedBytes, const double &scaleFactor, const float &bias)
{
if (nb_query_state == SEND_COMMAND)
{
queryPID(service, pid, num_responses);
nb_query_state = WAITING_RESP;
}
else if (nb_query_state == WAITING_RESP)
{
get_response();
if (nb_rx_state == ELM_SUCCESS)
{
nb_query_state = SEND_COMMAND; // Reset the query state machine for next command
findResponse(service, pid);
return conditionResponse(numExpectedBytes, scaleFactor, bias);
}
else if (nb_rx_state != ELM_GETTING_MSG)
nb_query_state = SEND_COMMAND; // Error or timeout, so reset the query state machine for next command
}
return 0.0;
}
/*
uint32_t ELM327::supportedPIDs_1_20()
Description:
------------
* Determine which of PIDs 0x1 through 0x20 are supported (bit encoded)
Inputs:
-------
* void
Return:
-------
* uint32_t - Bit encoded booleans of supported PIDs 0x1-0x20
*/
uint32_t ELM327::supportedPIDs_1_20()
{
return (uint32_t)processPID(SERVICE_01, SUPPORTED_PIDS_1_20, 1, 4);
}
/*
uint32_t ELM327::monitorStatus()
Description:
------------
* Monitor status since DTCs cleared (Includes malfunction indicator
lamp (MIL) status and number of DTCs). See https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01_PID_01
for more info
Inputs:
-------
* void
Return:
-------
* uint32_t - Bit encoded status (https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01_PID_01)
*/
uint32_t ELM327::monitorStatus()
{
return (uint32_t)processPID(SERVICE_01, MONITOR_STATUS_SINCE_DTC_CLEARED, 1, 4);
}
/*
uint16_t ELM327::freezeDTC()
Description:
------------
* Freeze DTC - see https://www.samarins.com/diagnose/freeze-frame.html for more info
Inputs:
-------
* void
Return:
-------
* uint16_t - Various vehicle information (https://www.samarins.com/diagnose/freeze-frame.html)
*/
uint16_t ELM327::freezeDTC()
{
return (uint16_t)processPID(SERVICE_01, FREEZE_DTC, 1, 2);
}
/*
uint16_t ELM327::fuelSystemStatus()
Description:
------------
* Freeze DTC - see https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01_PID_03 for more info
Inputs:
-------
* void
Return:
-------
* uint16_t - Bit encoded status (https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01_PID_03)
*/
uint16_t ELM327::fuelSystemStatus()
{
return (uint16_t)processPID(SERVICE_01, FUEL_SYSTEM_STATUS, 1, 2);
}
/*
float ELM327::engineLoad()
Description:
------------
* Find the current engine load in %
Inputs:
-------
* void
Return:
-------
* float - Engine load %
*/
float ELM327::engineLoad()
{
return processPID(SERVICE_01, ENGINE_LOAD, 1, 1, 100.0 / 255.0);
}
/*
float ELM327::engineCoolantTemp()
Description:
------------
* Find the current engine coolant temp in C
Inputs:
-------
* void
Return:
-------
* float - Engine load %
*/
float ELM327::engineCoolantTemp()
{
return processPID(SERVICE_01, ENGINE_COOLANT_TEMP, 1, 1, 1, -40.0);
}
/*
float ELM327::shortTermFuelTrimBank_1()
Description:
------------
* Find fuel trim %
Inputs:
-------
* void
Return:
-------
* float - Fuel trim %
*/
float ELM327::shortTermFuelTrimBank_1()
{
return processPID(SERVICE_01, SHORT_TERM_FUEL_TRIM_BANK_1, 1, 1, 100.0 / 128.0, -100.0);
}
/*
float ELM327::longTermFuelTrimBank_1()
Description:
------------
* Find fuel trim %
Inputs:
-------
* void
Return:
-------
* float - Fuel trim %
*/
float ELM327::longTermFuelTrimBank_1()
{
return processPID(SERVICE_01, LONG_TERM_FUEL_TRIM_BANK_1, 1, 1, 100.0 / 128.0, -100.0);
}
/*
float ELM327::shortTermFuelTrimBank_2()
Description:
------------
* Find fuel trim %
Inputs:
-------
* void
Return:
-------
* float - Fuel trim %
*/
float ELM327::shortTermFuelTrimBank_2()
{
return processPID(SERVICE_01, SHORT_TERM_FUEL_TRIM_BANK_2, 1, 1, 100.0 / 128.0, -100.0);
}
/*
float ELM327::longTermFuelTrimBank_2()
Description:
------------
* Find fuel trim %
Inputs:
-------
* void
Return:
-------
* float - Fuel trim %
*/
float ELM327::longTermFuelTrimBank_2()
{
return processPID(SERVICE_01, LONG_TERM_FUEL_TRIM_BANK_2, 1, 1, 100.0 / 128.0, -100.0);
}
/*
float ELM327::fuelPressure()
Description:
------------
* Find fuel pressure in kPa
Inputs:
-------
* void
Return:
-------
* float - Fuel pressure in kPa
*/
float ELM327::fuelPressure()
{
return processPID(SERVICE_01, FUEL_PRESSURE, 1, 1, 3.0);
}
/*
uint8_t ELM327::manifoldPressure()
Description:
------------
* Find intake manifold absolute pressure in kPa
Inputs:
-------
* void
Return:
-------
* uint8_t - Intake manifold absolute pressure in kPa
*/
uint8_t ELM327::manifoldPressure()
{
return (uint8_t)processPID(SERVICE_01, INTAKE_MANIFOLD_ABS_PRESSURE, 1, 1);
}
/*
float ELM327::rpm()
Description:
------------
* Queries and parses received message for/returns vehicle RMP data
Inputs:
-------
* void
Return:
-------
* float - Vehicle RPM
*/
float ELM327::rpm()
{
return processPID(SERVICE_01, ENGINE_RPM, 1, 2, 1.0 / 4.0);
}
/*
int32_t ELM327::kph()
Description:
------------
* Queries and parses received message for/returns vehicle speed data (kph)
Inputs:
-------
* void
Return:
-------
* int32_t - Vehicle speed in kph
*/
int32_t ELM327::kph()
{
return (int32_t)processPID(SERVICE_01, VEHICLE_SPEED, 1, 1);
}
/*
float ELM327::mph()
Description:
------------
* Queries and parses received message for/returns vehicle speed data (mph)
Inputs:
-------
* void
Return:
-------
* float - Vehicle speed in mph
*/
float ELM327::mph()
{
return kph() * KPH_MPH_CONVERT;
}
/*
float ELM327::timingAdvance()
Description:
------------
* Find timing advance in degrees before Top Dead Center (TDC)
Inputs:
-------
* void
Return:
-------
* float - Timing advance in degrees before Top Dead Center (TDC)
*/
float ELM327::timingAdvance()
{
return processPID(SERVICE_01, TIMING_ADVANCE, 1, 1, 1.0 / 2.0, -64.0);
}
/*
float ELM327::intakeAirTemp()
Description:
------------
* Find intake air temperature in C
Inputs:
-------
* void
Return:
-------
* float - Intake air temperature in C
*/
float ELM327::intakeAirTemp()
{
return processPID(SERVICE_01, INTAKE_AIR_TEMP, 1, 1, 1, -40.0);