Skip to content

Commit 74ee966

Browse files
committed
2.1.0
1 parent 31bbc96 commit 74ee966

36 files changed

Lines changed: 31071 additions & 2023 deletions

KEYWORDS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ recode KEYWORD2
3636

3737
readFaults KEYWORD2
3838
getFaultCode KEYWORD2
39+
getFaultDescription KEYWORD2
40+
getFaultDescriptionLength KEYWORD2
3941
getFaultElaborationCode KEYWORD2
4042
getFaultElaboration KEYWORD2
43+
getFaultElaborationLength KEYWORD2
4144
clearFaults KEYWORD2
4245

4346
readAdaptation KEYWORD2

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
- Reading the module's part number + extra fields, coding, WSC
99
- Recoding
1010
- Performing a login operation
11-
- Reading stored fault codes and their elaboration
11+
- **Reading stored fault codes and their elaboration codes**
12+
- **Converting fault/elaboration codes to strings** (available in a few different languages)
1213
- Clearing stored fault codes
1314
- Reading, testing and saving an adaptation value
14-
- Reading measuring blocks, calculating a measurement's value and providing its units (or text from a table, where applicable)
15+
- **Reading measuring blocks, calculating a measurement's value and providing its units, or displaying text from a table where applicable** (available in a few different languages)
1516
- Reading ROM / EEPROM (firmware)
1617
- Performing actuator tests
1718
- Performing basic settings
1819

1920
## Currently unsupported features:
20-
- Measurement / DTC labels or descriptions
21+
- Multi-instance support for managing multiple K-lines at the same time
2122

2223
## Getting started
2324
Download [the latest release (.zip)](https://github.com/domnulvlad/KLineKWP1281Lib/releases/latest) and [add it to your Arduino IDE](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries#importing-a-zip-library).
@@ -31,4 +32,4 @@ Thanks go out to these people for their efforts:
3132
* [Mike Naberezny](https://github.com/mnaberez/vwradio/blob/main/kwp1281_tool/firmware/kwp1281.h), for more insight about the commands and parameters
3233

3334
## Contact
34-
For any inquiries, you can contact me at [ne555timer@yahoo.com](mailto:ne555timer@yahoo.com).
35+
For any inquiries, you can open an issue or contact me at [ne555timer@yahoo.com](mailto:ne555timer@yahoo.com).
File renamed without changes.

examples/01.Connection_test/01.Connection_test.ino

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
*K-line TX -> Serial1 - RX pin 19 / Serial2 - RX pin 17 / Serial3 - RX pin 15
3030
*K-line RX -> Serial1 - TX pin 18 / Serial2 - TX pin 16 / Serial3 - TX pin 14
3131
32-
ESP32
32+
ESP32 / ESP32-C6
3333
*has one additional serial port
34-
*pins:
34+
*pins (they can be remapped, this is what they are configured to in these examples):
3535
*K-line TX -> RX pin 16
3636
*K-line RX -> TX pin 17
3737
@@ -98,10 +98,6 @@ void KWP1281debugFunction(bool type, uint8_t sequence, uint8_t command, uint8_t*
9898
}
9999
#endif
100100

101-
//You can increase the value below if you get "Too many faults for the given buffer size" during the DTC test.
102-
#define DTC_BUFFER_MAX_FAULT_CODES 16
103-
uint8_t faults[3 * DTC_BUFFER_MAX_FAULT_CODES]; //buffer to store the fault codes; each code takes 3 bytes
104-
105101
void setup() {
106102
//Initialize the Serial Monitor.
107103
Serial.begin(115200);
@@ -132,15 +128,13 @@ void setup() {
132128

133129
//Put the module's coding value into a string and pad with 0s to show 5 characters.
134130
char coding_str[6];
135-
sprintf(coding_str, "%05u", diag.getCoding());
131+
unsigned int coding = diag.getCoding();
132+
sprintf(coding_str, "%05u", coding);
136133

137134
//Put the module's wokshop code into a string and pad with 0s to show 5 characters.
138135
char WSC_str[6];
139-
#if defined(__AVR__)
140-
sprintf(WSC_str, "%05lu", diag.getWorkshopCode());
141-
#else
142-
sprintf(WSC_str, "%05u", diag.getWorkshopCode()); //uint32_t is not a "long" on the ESP platform
143-
#endif
136+
unsigned long WSC = diag.getWorkshopCode();
137+
sprintf(WSC_str, "%05lu", WSC);
144138

145139
//Leave an empty line.
146140
Serial.println();
@@ -162,4 +156,4 @@ void setup() {
162156
void loop() {
163157
//Maintain the connection.
164158
diag.update();
165-
}
159+
}

examples/01.Connection_test/communication.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//Initializes the serial port
22
void beginFunction(unsigned long baud) {
3+
#ifdef RX_pin
4+
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
5+
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
6+
#else
7+
// For other boards (if RX_pin is not defined), use the standard function.
38
K_line.begin(baud);
9+
#endif
410
}
511

612
//Stops communication on the serial port

examples/01.Connection_test/configuration.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
/*
4242
#define K_line Serial2
4343
#define TX_pin 17
44+
#define RX_pin 16
45+
*/
46+
47+
//ESP32-C6 (can use Serial1)
48+
/*
49+
#define K_line Serial1
50+
#define TX_pin 17
51+
#define RX_pin 16
4452
*/
4553

4654
//ESP8266 (no additional hardware serial ports, must use software serial)

examples/02.Fault_code_test/02.Fault_code_test.ino

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
88
Notes:
99
*The connection will be stopped after the fault codes are read.
10+
*If you are using the ESP32 platform, feel free to uncomment the line "#define KWP1281_FAULT_CODE_DESCRIPTION_SUPPORTED" in "KLineKWP1281Lib.h",
11+
in order to get descriptive names associated with each fault code. This feature doesn't yet work on the AVR platform, but you can take a look at
12+
the "fault_code_description_xx.h" files if you need these descriptions.
13+
*If you have descriptions enabled, you can choose from a few different languages a bit further below in "KLineKWP1281Lib.h". Please only choose
14+
one option.
15+
*If you have manually disabled elaborations by commenting out the line "#define KWP1281_FAULT_CODE_ELABORATION_SUPPORTED" in "KLineKWP1281Lib.h",
16+
the elaborations will be replaced by "EN_elb".
17+
*If you have elaborations enabled, you can choose from a few different languages a bit further below in "KLineKWP1281Lib.h". Please only choose
18+
one option.
1019
*/
1120

1221
/*
@@ -29,9 +38,9 @@
2938
*K-line TX -> Serial1 - RX pin 19 / Serial2 - RX pin 17 / Serial3 - RX pin 15
3039
*K-line RX -> Serial1 - TX pin 18 / Serial2 - TX pin 16 / Serial3 - TX pin 14
3140
32-
ESP32
41+
ESP32 / ESP32-C6
3342
*has one additional serial port
34-
*pins:
43+
*pins (they can be remapped, this is what they are configured to in these examples):
3544
*K-line TX -> RX pin 16
3645
*K-line RX -> TX pin 17
3746
@@ -161,29 +170,69 @@ void showDTCs() {
161170
//Store the fault code in a string.
162171
char dtc_str[8];
163172
sprintf(dtc_str, "%05u", dtc);
173+
174+
//Print the fault code.
175+
Serial.print(" ");
176+
Serial.print(dtc_str);
177+
178+
// If fault code descriptions are enabled, display the description along with the fault code.
179+
#ifdef KWP1281_FAULT_CODE_DESCRIPTION_SUPPORTED
180+
//Declare a character array and use it to store the description string.
181+
char description_string[32];
182+
KLineKWP1281Lib::getFaultDescription(i, available_DTCs, faults, sizeof(faults), description_string, sizeof(description_string));
183+
184+
//Print the description string.
185+
Serial.print(" - ");
186+
Serial.print(description_string);
187+
188+
//Get the full length of the description string, to warn the user if the provided buffer wasn't large enough to store the entire string.
189+
size_t description_string_length = KLineKWP1281Lib::getFaultDescriptionLength(i, available_DTCs, faults, sizeof(faults));
190+
191+
//If the buffer was too small, display an ellipsis and indicate how many characters would have been needed for the entire string.
192+
if (description_string_length > (sizeof(description_string) - 1))
193+
{
194+
Serial.print("... (");
195+
Serial.print(sizeof(description_string) - 1);
196+
Serial.print("/");
197+
Serial.print(description_string_length);
198+
Serial.print(")");
199+
}
200+
#endif
201+
Serial.println();
164202

165203
//Store the elaboration code (without the high bit) in a string.
166204
char dtc_status_str[8];
167205
sprintf(dtc_status_str, "%02u-%02u", dtc_elaboration_code & ~0x80, ((dtc_elaboration_code & 0x80) ? 10 : 0));
168206

169-
//Print the fault code and its elaboration code.
170-
Serial.print(" ");
171-
Serial.print(dtc_str);
172-
Serial.print(" - ");
173-
Serial.println(dtc_status_str);
174-
175-
//Declare a character array and use it to store the elaboration string.
176-
char elaboration_string[32];
177-
178-
//Declare a bool that indicates whether or not the fault is intermittent.
207+
//Declare a bool that indicates whether or not the fault is intermittent, which will be changed accordingly by the getFaultElaboration() function.
179208
bool is_intermittent;
180209

181-
//Get the elaboration string.
210+
//Declare a character array and use it to store the elaboration string.
211+
char elaboration_string[32];
182212
KLineKWP1281Lib::getFaultElaboration(is_intermittent, i, available_DTCs, faults, sizeof(faults), elaboration_string, sizeof(elaboration_string));
183213

184-
//Print the elaboration string.
214+
//Print the fault elaboration code.
185215
Serial.print(" ");
216+
Serial.print(dtc_status_str);
217+
218+
//Print the elaboration string.
219+
Serial.print(" ");
186220
Serial.print(elaboration_string);
221+
222+
//Get the full length of the elaboration string, to warn the user if the provided buffer wasn't large enough to store the entire string.
223+
size_t elaboration_string_length = KLineKWP1281Lib::getFaultElaborationLength(i, available_DTCs, faults, sizeof(faults));
224+
225+
//If the buffer was too small, display an ellipsis and indicate how many characters would have been needed for the entire string.
226+
if (elaboration_string_length > (sizeof(elaboration_string) - 1))
227+
{
228+
Serial.print("... (");
229+
Serial.print(sizeof(elaboration_string) - 1);
230+
Serial.print("/");
231+
Serial.print(elaboration_string_length);
232+
Serial.print(")");
233+
}
234+
235+
// If the fault is intermittent, display this info.
187236
if (is_intermittent) {
188237
Serial.print(" - Intermittent");
189238
}
@@ -194,4 +243,4 @@ void showDTCs() {
194243
else {
195244
Serial.println("Error reading DTCs");
196245
}
197-
}
246+
}

examples/02.Fault_code_test/communication.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//Initializes the serial port
22
void beginFunction(unsigned long baud) {
3+
#ifdef RX_pin
4+
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
5+
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
6+
#else
7+
// For other boards (if RX_pin is not defined), use the standard function.
38
K_line.begin(baud);
9+
#endif
410
}
511

612
//Stops communication on the serial port

examples/02.Fault_code_test/configuration.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
/*
4242
#define K_line Serial2
4343
#define TX_pin 17
44+
#define RX_pin 16
45+
*/
46+
47+
//ESP32-C6 (can use Serial1)
48+
/*
49+
#define K_line Serial1
50+
#define TX_pin 17
51+
#define RX_pin 16
4452
*/
4553

4654
//ESP8266 (no additional hardware serial ports, must use software serial)

examples/03.Full_measurement_test/03.Full_measurement_test.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
88
Notes:
99
*Measuring blocks 0-255 will be read, after which the connection will be stopped.
10+
*If you have manually disabled the text table by commenting out the line "#define KWP1281_TEXT_TABLE_SUPPORTED" in "KLineKWP1281Lib.h", the value
11+
for some parameters will be displayed as "EN_f25".
12+
*If you have the text table enabled, you can choose from a few different languages a bit further below in "KLineKWP1281Lib.h". Please only choose
13+
one option.
1014
*/
1115

1216
/*
@@ -196,4 +200,4 @@ void showMeasurements(uint8_t block) {
196200
Serial.println();
197201
break;
198202
}
199-
}
203+
}

0 commit comments

Comments
 (0)