Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
domnulvlad committed May 14, 2024
1 parent 31bbc96 commit 74ee966
Show file tree
Hide file tree
Showing 36 changed files with 31,071 additions and 2,023 deletions.
3 changes: 3 additions & 0 deletions KEYWORDS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ recode KEYWORD2

readFaults KEYWORD2
getFaultCode KEYWORD2
getFaultDescription KEYWORD2
getFaultDescriptionLength KEYWORD2
getFaultElaborationCode KEYWORD2
getFaultElaboration KEYWORD2
getFaultElaborationLength KEYWORD2
clearFaults KEYWORD2

readAdaptation KEYWORD2
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
- Reading the module's part number + extra fields, coding, WSC
- Recoding
- Performing a login operation
- Reading stored fault codes and their elaboration
- **Reading stored fault codes and their elaboration codes**
- **Converting fault/elaboration codes to strings** (available in a few different languages)
- Clearing stored fault codes
- Reading, testing and saving an adaptation value
- Reading measuring blocks, calculating a measurement's value and providing its units (or text from a table, where applicable)
- **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)
- Reading ROM / EEPROM (firmware)
- Performing actuator tests
- Performing basic settings

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

## Getting started
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).
Expand All @@ -31,4 +32,4 @@ Thanks go out to these people for their efforts:
* [Mike Naberezny](https://github.com/mnaberez/vwradio/blob/main/kwp1281_tool/firmware/kwp1281.h), for more insight about the commands and parameters

## Contact
For any inquiries, you can contact me at [ne555timer@yahoo.com](mailto:ne555timer@yahoo.com).
For any inquiries, you can open an issue or contact me at [ne555timer@yahoo.com](mailto:ne555timer@yahoo.com).
File renamed without changes
20 changes: 7 additions & 13 deletions examples/01.Connection_test/01.Connection_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
*K-line TX -> Serial1 - RX pin 19 / Serial2 - RX pin 17 / Serial3 - RX pin 15
*K-line RX -> Serial1 - TX pin 18 / Serial2 - TX pin 16 / Serial3 - TX pin 14
ESP32
ESP32 / ESP32-C6
*has one additional serial port
*pins:
*pins (they can be remapped, this is what they are configured to in these examples):
*K-line TX -> RX pin 16
*K-line RX -> TX pin 17
Expand Down Expand Up @@ -98,10 +98,6 @@ void KWP1281debugFunction(bool type, uint8_t sequence, uint8_t command, uint8_t*
}
#endif

//You can increase the value below if you get "Too many faults for the given buffer size" during the DTC test.
#define DTC_BUFFER_MAX_FAULT_CODES 16
uint8_t faults[3 * DTC_BUFFER_MAX_FAULT_CODES]; //buffer to store the fault codes; each code takes 3 bytes

void setup() {
//Initialize the Serial Monitor.
Serial.begin(115200);
Expand Down Expand Up @@ -132,15 +128,13 @@ void setup() {

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

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

//Leave an empty line.
Serial.println();
Expand All @@ -162,4 +156,4 @@ void setup() {
void loop() {
//Maintain the connection.
diag.update();
}
}
6 changes: 6 additions & 0 deletions examples/01.Connection_test/communication.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//Initializes the serial port
void beginFunction(unsigned long baud) {
#ifdef RX_pin
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
#else
// For other boards (if RX_pin is not defined), use the standard function.
K_line.begin(baud);
#endif
}

//Stops communication on the serial port
Expand Down
8 changes: 8 additions & 0 deletions examples/01.Connection_test/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
/*
#define K_line Serial2
#define TX_pin 17
#define RX_pin 16
*/

//ESP32-C6 (can use Serial1)
/*
#define K_line Serial1
#define TX_pin 17
#define RX_pin 16
*/

//ESP8266 (no additional hardware serial ports, must use software serial)
Expand Down
79 changes: 64 additions & 15 deletions examples/02.Fault_code_test/02.Fault_code_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
Notes:
*The connection will be stopped after the fault codes are read.
*If you are using the ESP32 platform, feel free to uncomment the line "#define KWP1281_FAULT_CODE_DESCRIPTION_SUPPORTED" in "KLineKWP1281Lib.h",
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
the "fault_code_description_xx.h" files if you need these descriptions.
*If you have descriptions enabled, you can choose from a few different languages a bit further below in "KLineKWP1281Lib.h". Please only choose
one option.
*If you have manually disabled elaborations by commenting out the line "#define KWP1281_FAULT_CODE_ELABORATION_SUPPORTED" in "KLineKWP1281Lib.h",
the elaborations will be replaced by "EN_elb".
*If you have elaborations enabled, you can choose from a few different languages a bit further below in "KLineKWP1281Lib.h". Please only choose
one option.
*/

/*
Expand All @@ -29,9 +38,9 @@
*K-line TX -> Serial1 - RX pin 19 / Serial2 - RX pin 17 / Serial3 - RX pin 15
*K-line RX -> Serial1 - TX pin 18 / Serial2 - TX pin 16 / Serial3 - TX pin 14
ESP32
ESP32 / ESP32-C6
*has one additional serial port
*pins:
*pins (they can be remapped, this is what they are configured to in these examples):
*K-line TX -> RX pin 16
*K-line RX -> TX pin 17
Expand Down Expand Up @@ -161,29 +170,69 @@ void showDTCs() {
//Store the fault code in a string.
char dtc_str[8];
sprintf(dtc_str, "%05u", dtc);

//Print the fault code.
Serial.print(" ");
Serial.print(dtc_str);

// If fault code descriptions are enabled, display the description along with the fault code.
#ifdef KWP1281_FAULT_CODE_DESCRIPTION_SUPPORTED
//Declare a character array and use it to store the description string.
char description_string[32];
KLineKWP1281Lib::getFaultDescription(i, available_DTCs, faults, sizeof(faults), description_string, sizeof(description_string));

//Print the description string.
Serial.print(" - ");
Serial.print(description_string);

//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.
size_t description_string_length = KLineKWP1281Lib::getFaultDescriptionLength(i, available_DTCs, faults, sizeof(faults));

//If the buffer was too small, display an ellipsis and indicate how many characters would have been needed for the entire string.
if (description_string_length > (sizeof(description_string) - 1))
{
Serial.print("... (");
Serial.print(sizeof(description_string) - 1);
Serial.print("/");
Serial.print(description_string_length);
Serial.print(")");
}
#endif
Serial.println();

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

//Print the fault code and its elaboration code.
Serial.print(" ");
Serial.print(dtc_str);
Serial.print(" - ");
Serial.println(dtc_status_str);

//Declare a character array and use it to store the elaboration string.
char elaboration_string[32];

//Declare a bool that indicates whether or not the fault is intermittent.
//Declare a bool that indicates whether or not the fault is intermittent, which will be changed accordingly by the getFaultElaboration() function.
bool is_intermittent;

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

//Print the elaboration string.
//Print the fault elaboration code.
Serial.print(" ");
Serial.print(dtc_status_str);

//Print the elaboration string.
Serial.print(" ");
Serial.print(elaboration_string);

//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.
size_t elaboration_string_length = KLineKWP1281Lib::getFaultElaborationLength(i, available_DTCs, faults, sizeof(faults));

//If the buffer was too small, display an ellipsis and indicate how many characters would have been needed for the entire string.
if (elaboration_string_length > (sizeof(elaboration_string) - 1))
{
Serial.print("... (");
Serial.print(sizeof(elaboration_string) - 1);
Serial.print("/");
Serial.print(elaboration_string_length);
Serial.print(")");
}

// If the fault is intermittent, display this info.
if (is_intermittent) {
Serial.print(" - Intermittent");
}
Expand All @@ -194,4 +243,4 @@ void showDTCs() {
else {
Serial.println("Error reading DTCs");
}
}
}
6 changes: 6 additions & 0 deletions examples/02.Fault_code_test/communication.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//Initializes the serial port
void beginFunction(unsigned long baud) {
#ifdef RX_pin
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
#else
// For other boards (if RX_pin is not defined), use the standard function.
K_line.begin(baud);
#endif
}

//Stops communication on the serial port
Expand Down
8 changes: 8 additions & 0 deletions examples/02.Fault_code_test/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
/*
#define K_line Serial2
#define TX_pin 17
#define RX_pin 16
*/

//ESP32-C6 (can use Serial1)
/*
#define K_line Serial1
#define TX_pin 17
#define RX_pin 16
*/

//ESP8266 (no additional hardware serial ports, must use software serial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Notes:
*Measuring blocks 0-255 will be read, after which the connection will be stopped.
*If you have manually disabled the text table by commenting out the line "#define KWP1281_TEXT_TABLE_SUPPORTED" in "KLineKWP1281Lib.h", the value
for some parameters will be displayed as "EN_f25".
*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
one option.
*/

/*
Expand Down Expand Up @@ -196,4 +200,4 @@ void showMeasurements(uint8_t block) {
Serial.println();
break;
}
}
}
6 changes: 6 additions & 0 deletions examples/03.Full_measurement_test/communication.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//Initializes the serial port
void beginFunction(unsigned long baud) {
#ifdef RX_pin
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
#else
// For other boards (if RX_pin is not defined), use the standard function.
K_line.begin(baud);
#endif
}

//Stops communication on the serial port
Expand Down
8 changes: 8 additions & 0 deletions examples/03.Full_measurement_test/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
/*
#define K_line Serial2
#define TX_pin 17
#define RX_pin 16
*/

//ESP32-C6 (can use Serial1)
/*
#define K_line Serial1
#define TX_pin 17
#define RX_pin 16
*/

//ESP8266 (no additional hardware serial ports, must use software serial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
Notes:
*You can change which block to read by modifying the #define below.
*This block will be read continuously while the sketch is running.
*It is not necessary to maintain the connection with "diag.update();" in the loop, because any request will have the same effect (update() must be used in
periods of inactivity).
*It is not necessary to maintain the connection with "diag.update();" in the loop, because any request will have the same effect (update() must
be used in periods of inactivity).
*If you have manually disabled the text table by commenting out the line "#define KWP1281_TEXT_TABLE_SUPPORTED" in "KLineKWP1281Lib.h", the value
for some parameters will be displayed as "EN_f25".
*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
one option.
*/

//Change which block to read.
Expand Down Expand Up @@ -194,4 +198,4 @@ void showMeasurements(uint8_t block) {
Serial.println();
break;
}
}
}
6 changes: 6 additions & 0 deletions examples/04.Continuous_measurement_test/communication.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//Initializes the serial port
void beginFunction(unsigned long baud) {
#ifdef RX_pin
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
#else
// For other boards (if RX_pin is not defined), use the standard function.
K_line.begin(baud);
#endif
}

//Stops communication on the serial port
Expand Down
8 changes: 8 additions & 0 deletions examples/04.Continuous_measurement_test/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
/*
#define K_line Serial2
#define TX_pin 17
#define RX_pin 16
*/

//ESP32-C6 (can use Serial1)
/*
#define K_line Serial1
#define TX_pin 17
#define RX_pin 16
*/

//ESP8266 (no additional hardware serial ports, must use software serial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
Notes:
*You can change which block and which measurement to read by modifying the #defines below.
*This measurement will be read continuously while the sketch is running.
*It is not necessary to maintain the connection with "diag.update();" in the loop, because any request will have the same effect (update() must be used in
periods of inactivity).
*It is not necessary to maintain the connection with "diag.update();" in the loop, because any request will have the same effect (update() must
be used in periods of inactivity).
*If you have manually disabled the text table by commenting out the line "#define KWP1281_TEXT_TABLE_SUPPORTED" in "KLineKWP1281Lib.h", the value
for some parameters will be displayed as "EN_f25".
*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
one option.
*/

//Change which measurement to read, from which block.
Expand Down Expand Up @@ -186,4 +190,4 @@ void showSingleMeasurement(uint8_t block, uint8_t measurement_index) {
}
break;
}
}
}
6 changes: 6 additions & 0 deletions examples/05.Single_measurement_test/communication.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//Initializes the serial port
void beginFunction(unsigned long baud) {
#ifdef RX_pin
// The configuration for the ESP32 has both the RX and TX pins defined (for consistency), since they can be mapped to any pins.
K_line.begin(baud, SERIAL_8N1, RX_pin, TX_pin);
#else
// For other boards (if RX_pin is not defined), use the standard function.
K_line.begin(baud);
#endif
}

//Stops communication on the serial port
Expand Down
Loading

0 comments on commit 74ee966

Please sign in to comment.