### KLineKWP1281Lib Constructor Example Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/3.-The-Arduino-side-of-things Instantiates the KLineKWP1281Lib object. Requires communication functions, TX pin, and optionally duplex mode and a debug port. ```cpp KLineKWP1281Lib diag(beginFunction, endFunction, sendFunction, receiveFunction, TX_pin, is_full_duplex, &Serial); ``` -------------------------------- ### Get Measurement Decimals Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the recommended decimal places for a measurement. This is a static function and does not require an instance. ```cpp getMeasurementDecimals(uint8_t formula) ``` -------------------------------- ### Custom 5-Baud Wait Function Setup Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Attaches a custom function to be executed during the 5-baud-init procedure. This function should introduce a 200ms delay per call. ```cpp custom5baudWaitFunction(custom5baudWaitFunction_type function) ``` -------------------------------- ### Get Measurement Units from Header/Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the units for a measurement of type VALUE. The units are copied into the provided character array. ```cpp getMeasurementUnitsFromHeaderBody(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size, uint8_t amount_of_measurements_in_body, uint8_t body_buffer[], size_t body_buffer_size, char str[], size_t string_size) ``` -------------------------------- ### Get Measurement Decimals Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the recommended decimal places of a measurement from a buffer filled by readGroup(). ```cpp getMeasurementDecimals(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size) ``` -------------------------------- ### Get Basic Setting Value from Buffer Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves a specific measured value from a buffer that was previously filled by the basicSetting() function. This is a static function and does not require an instance. ```cpp getBasicSettingValue(uint8_t value_index, uint8_t amount_of_values, uint8_t basic_setting_buffer[] , size_t basic_setting_buffer_size) ``` -------------------------------- ### Get Module Workshop Code Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the Workshop Code (WSC) of the control module. ```cpp getWorkshopCode() ``` -------------------------------- ### Get Measurement Units (Formula) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the units for a measurement based on its formula. This is a static function. ```cpp getMeasurementUnits(uint8_t formula, uint8_t measurement_data[], uint8_t measurement_data_length, char str[], size_t string_size) ``` -------------------------------- ### Get Module Coding Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the coding value of the control module. ```cpp getCoding() ``` -------------------------------- ### Get Measurement Text (Formula) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the text for a measurement of type TEXT based on its formula. This is a static function. ```cpp getMeasurementText(uint8_t formula, uint8_t measurement_data[], uint8_t measurement_data_length, char str[], size_t string_size) ``` -------------------------------- ### Get NWb From Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves byte A (NWb) for a measurement from a header buffer. This is a static function. ```cpp getNWbFromHeader(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size) ``` -------------------------------- ### Get Measurement Text (Index) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the text for a measurement of type TEXT using its index. This is a static function. ```cpp getMeasurementText(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size, char str[], size_t string_size) ``` -------------------------------- ### Custom Error Function Setup Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Attaches a custom function to be executed when a connection error occurs. The function receives the module and baud rate, allowing for reconnection logic. ```cpp customErrorFunction(customErrorFunction_type function) ``` -------------------------------- ### Get Measurement Units (NWb, MWb) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the units for a measurement using NWb and MWb values. This is a static function. ```cpp getMeasurementUnits(uint8_t formula, uint8_t NWb, uint8_t MWb, char str[], size_t string_size) ``` -------------------------------- ### Get Module Part Number Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the VAG part number of the control module as a character array. ```cpp getPartNumber() ``` -------------------------------- ### KWP1281debugFunction Setup Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Attaches a custom function to be called for debugging KWP1281 messages. The function should accept direction, sequence, type, data, and length parameters. ```cpp KWP1281debugFunction(KWP1281debugFunction_type debug_function) ``` -------------------------------- ### Get Fault Elaboration (from buffer) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides a fault elaboration string from a buffer filled by readFaults(). This static function requires the fault code index and buffer details. The output is copied into a provided character array. ```cpp getFaultElaboration(bool &is_intermittent, uint8_t fault_code_index, uint8_t amount_of_fault_codes, uint8_t fault_code_buffer[], size_t fault_code_buffer_size, char str[], size_t string_size) ``` -------------------------------- ### Get Measurement Text from Header/Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the text for a measurement of type TEXT. This function is used for measurements where the textual representation is primary. ```cpp getMeasurementTextFromHeaderBody(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size, uint8_t amount_of_measurements_in_body, uint8_t body_buffer[], size_t body_buffer_size) ``` -------------------------------- ### Get Measurement Text Length (Index) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the length of the text for a measurement of type TEXT using its index. This is a static function. ```cpp getMeasurementTextLength(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size) ``` -------------------------------- ### Get Measurement Text Length (Formula) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the length of the text for a measurement of type TEXT based on its formula. This is a static function. ```cpp getMeasurementTextLength(uint8_t formula, uint8_t measurement_data[], uint8_t measurement_data_length) ``` -------------------------------- ### Get Output Test Description Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the description string for a given output test ID. Use this function when you need the textual description of a specific output test. It requires a buffer to store the description and its size. ```cpp getOutputTestDescription(uint16_t output_test, char str[], size_t string_size) ``` -------------------------------- ### Get Output Test Description Length Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the length of the description string for a specified output test ID. Use this function to pre-allocate buffer space if needed before calling getOutputTestDescription. It is a static function. ```cpp getOutputTestDescriptionLength(uint16_t output_test) ``` -------------------------------- ### Get Measurement Decimals from Header Buffer Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the recommended number of decimal places for a measurement from a header buffer populated by readGroup(). Use this to format numerical measurements appropriately. ```cpp getMeasurementDecimalsFromHeader(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size) ``` -------------------------------- ### Get Formula From Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the formula byte for a measurement from a header buffer. Use only if readGroup() returned GROUP_HEADER. This is a static function. ```cpp getFormulaFromHeader(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size) ``` -------------------------------- ### Get Measurement Units (C++) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides a string containing the proper units for a measurement of type VALUE. This function populates a provided character array. ```cpp getMeasurementUnits(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size, char str[], size_t string_size) ``` -------------------------------- ### Get Fault Elaboration Code Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves a fault elaboration code from a buffer populated by readFaults(). This is a static function and does not require an instance. ```cpp getFaultElaborationCode(uint8_t fault_code_index, uint8_t amount_of_fault_codes, uint8_t fault_code_buffer[], size_t fault_code_buffer_size) ``` -------------------------------- ### Get Measurement Data Length (C++) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the data length for a specific measurement from a buffer. This is a static function and does not require an instance. ```cpp getMeasurementDataLength(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size) ``` -------------------------------- ### Get Measurement Text from Header and Body Buffers Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the text for a specific measurement from header and body buffers populated by readGroup(). Use this when you need the string representation of a measurement's text. ```c getMeasurementTextFromHeaderBody(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size, uint8_t amount_of_measurements_in_body, uint8_t body_buffer[], size_t body_buffer_size, char str[], size_t string_size) ``` -------------------------------- ### Get Fault Elaboration (from code) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides a fault elaboration string based on a given elaboration code. This static function is useful when the code is already known. The output is copied into a provided character array. ```cpp getFaultElaboration(bool &is_intermittent, uint8_t elaboration_code, char str[], size_t string_size) ``` -------------------------------- ### Get Fault Elaboration Length (from code) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the length of the fault elaboration string given an elaboration code. This static function is efficient when the code is already known. ```cpp getFaultElaborationLength(uint8_t elaboration_code) ``` -------------------------------- ### Get Formula Byte from Measurement Buffer Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the formula byte for a specific measurement from a buffer. This is a static function and requires the measurement index, total amount of measurements, the buffer itself, and its size. ```cpp getFormula(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size) ``` -------------------------------- ### Get Measurement Text Length from Header and Body Buffers Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the length of the text for a TEXT-type measurement using data from header and body buffers filled by readGroup(). Use this to pre-allocate buffer space for measurement text. ```cpp getMeasurementTextLengthFromHeaderBody(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size, uint8_t amount_of_measurements_in_body, uint8_t body_buffer[], size_t body_buffer_size) ``` -------------------------------- ### Get fault description string Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves a description string for a fault code from a buffer filled by readFaults() or directly from a fault code. For standard OBD fault codes, the description may include an elaboration string after a colon. ```cpp getFaultDescription(uint8_t fault_code_index, uint8_t amount_of_fault_codes, uint8_t fault_code_buffer[], size_t fault_code_buffer_size, char str[], size_t string_size) ``` ```cpp getFaultDescription(uint16_t fault_code, char str[], size_t string_size) ``` -------------------------------- ### Get Measurement Data Buffer Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves a pointer to the measurement data buffer. This static function is useful for accessing the raw data bytes of a measurement, especially when the data length varies. It requires the measurement index, total measurements, the buffer, and its size. ```cpp getMeasurementData(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size) ``` -------------------------------- ### basicSetting Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Performs a basic setting operation, reading values into a buffer. ```APIDOC ## basicSetting ### Description Performs a basic setting. ### Method ```cpp basicSetting(uint8_t &amount_of_values, uint8_t group, uint8_t basic_setting_buffer[], size_t basic_setting_buffer_size) ``` ### Parameters #### Path Parameters - **amount_of_values** (uint8_t &) - Required - will contain the total number of values read from the basic setting group - **group** (uint8_t) - Required - basic setting group to activate/read - **basic_setting_buffer** (uint8_t[]) - Required - array into which to store the values read - **basic_setting_buffer_size** (size_t) - Required - total (maximum) length of the given array ### Returns #### Success Response - **executionStatus** (enum) - whether or not the operation executed successfully (*SUCCESS, *FAIL, *ERROR) ### Response Example ``` { "executionStatus": "SUCCESS" } ``` ``` -------------------------------- ### Get Module Identification Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the model name of the control module as a character array. ```cpp getIdentification() ``` -------------------------------- ### Get Measurement Type From Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the type of a measurement from a header buffer. This is a static function. ```cpp getMeasurementTypeFromHeader(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size) ``` -------------------------------- ### KLineKWP1281Lib Constructor Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Creates an instance of the K-Line KW P1281 library. Requires callback functions for communication and pin configurations. ```cpp KLineKWP1281Lib(beginFunction, endFunction, sendFunction, receiveFunction, tx_pin, full_duplex, (debug_port)) ``` -------------------------------- ### connect Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Connects to a module, running until a successful connection is established. ```APIDOC ## connect ### Description Connects to a module. This function will run until a successful connection is established. ### Method connect ### Notes - This is a blocking function that retries until connection is successful. If a non-blocking attempt is preferred, use `attemptConnect()`. ``` -------------------------------- ### KLineKWP1281Lib Constructor Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Creates an instance of the KLineKWP1281Lib library, setting up communication parameters. ```APIDOC ## KLineKWP1281Lib Constructor ### Description Creates an instance of the library, initializing communication with the specified functions and pins. ### Method Constructor ### Parameters #### Constructor Parameters - **beginFunction** (void (*)(unsigned long)) - Function to begin communication on the serial port. - **endFunction** (void (*)()) - Function to end communication on the serial port. - **sendFunction** (void (*)(uint8_t)) - Function to write a byte to the serial port. - **receiveFunction** (bool (*)(uint8_t *)) - Function to receive a byte from the serial port. Returns true if a byte is available, false otherwise. The received byte is stored in the pointer. - **tx_pin** (int) - Digital pin corresponding to the selected serial port's transmit pin. - **full_duplex** (bool) - Flag indicating if the serial interface can read while sending. - **debug_port** (Stream *) - Optional pointer to a Stream object for sending debug information. ### Notes - The `receiveFunction` must return `false` if no byte is available. If a byte is available, it is stored in the byte passed by pointer and the function returns `true`. - If the serial interface cannot receive while sending, `full_duplex` should be set to `false`. - If the K-line does not echo back bytes, even if the serial interface is capable of receiving while sending, `full_duplex` should be set to `false`. ``` -------------------------------- ### Connect to Module Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Connects to a module, running until successful. Use when a blocking delay is acceptable. ```cpp connect() ``` -------------------------------- ### Connect to a Control Module Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Establishes a connection to a specified module. Includes options for requesting extra identification and handles connection failures with a retry delay. Be aware of potential indefinite blocking if the module is unavailable. ```cpp connect(uint8_t module, unsigned long baud_rate, bool request_extra_identification) ``` -------------------------------- ### Custom Wait Function for Initialization Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/3.-The-Arduino-side-of-things Define a function to execute during the 5-baud initialization phase. Ensure this function takes exactly 200ms to maintain connection stability. ```c void waitFunction() ``` ```c++ diag.custom5baudWaitFunction(waitFunction); ``` -------------------------------- ### Get Data Table From Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the data table buffer for a measurement from a header buffer. This is a static function. ```cpp getDataTableFromHeader(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size) ``` -------------------------------- ### connect Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Establishes a connection to a specified control module with configurable baud rate and identification request options. It includes retry logic and can block indefinitely if the module is unavailable. ```APIDOC ## connect ### Description Establishes a connection to a specified control module with configurable baud rate and identification request options. It includes retry logic and can block indefinitely if the module is unavailable. ### Method ```cpp connect(uint8_t module, unsigned long baud_rate, bool request_extra_identification) ``` ### Parameters #### Path Parameters - **module** (uint8_t) - Required - Logical ID of the target module (e.g., engine-0x01, cluster-0x17). - **baud_rate** (unsigned long) - Required - Communication speed (e.g., 10400, 9600, 4800). - **request_extra_identification** (bool) - Required - Whether or not to request extra identification if it is available. ### Notes * If establishing the connection fails, this function waits one second before retrying (blocking). * To avoid the blocking delay, use attemptConnect() and check its return value in order to execute custom code in case of failure. * If the connection cannot be established (i.e. the target module is unavailable), it will run indefinitely. * If the module contains "extra identification", and request_extra_identification is set to false, that identification string will not be requested. The getExtraIdentification() function will return an empty string, but connection will be almost 1 second faster. So, if you are not interested in the extra identification string, always set this parameter false. ``` -------------------------------- ### Configure SoftwareSerial for Arduino UNO (Half-Duplex) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/3.-The-Arduino-side-of-things When using SoftwareSerial on Arduino UNO, set `is_full_duplex` to false because the library is half-duplex. ```cpp #define is_full_duplex false ``` -------------------------------- ### custom5baudWaitFunction Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Attaches a custom function to be executed during the 5-baud initialization procedure, allowing for custom timing control. ```APIDOC ## custom5baudWaitFunction ### Description Attaches a custom function to be executed while initializing the control module. This function is called after sending each bit during the 5-baud-init procedure. ### Method custom5baudWaitFunction ### Parameters #### function - **function** (custom5baudWaitFunction_type) - The custom routine to execute. ### Notes - To achieve a baud rate of 5, the custom function must take 200 milliseconds. - This function will be called a total of 10 times during initialization. - If no custom function is defined, a regular delay of 200ms will be used. ``` -------------------------------- ### Get Data Table Length From Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves the data table length for a measurement from a header buffer. This is a static function. ```cpp getDataTableLengthFromHeader(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size) ``` -------------------------------- ### getOutputTestDescription Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the description string for an output test ID. This is a static function and does not require an instance. ```APIDOC ## getOutputTestDescription ### Description Provides the description string for an output test ID given by outputTests(). ### Method Static function (no instance required) ### Signature ```cpp getOutputTestDescription(uint16_t output_test, char str[], size_t string_size) ``` ### Parameters #### Input Parameters - **output_test** (uint16_t) - Required - The output test ID, given by outputTests(). - **str** (char[]) - Required - The character array into which to copy the description string. - **string_size** (size_t) - Required - The total size of the given array (provided with the sizeof() operator). ### Returns - **char*** - The same character array provided (str). ### Notes - It is a static function so it does not require an instance to be used. ``` -------------------------------- ### Basic Setting Operation Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Performs a basic setting operation, which can involve activating or reading a group of basic settings. The results are stored in a provided buffer. ```cpp basicSetting(uint8_t &amount_of_values, uint8_t group, uint8_t basic_setting_buffer[], size_t basic_setting_buffer_size) ``` -------------------------------- ### Enable Debugging Information Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/3.-The-Arduino-side-of-things Enable `debug_info` in `configuration.h` to view errors and information during communication. Ensure `KWP1281_DEBUG_LEVEL` is also increased in `KLineKWP1281Lib.h` for this to have an effect. ```cpp #define debug_info true ``` -------------------------------- ### Get Measurement Value from Header/Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Calculates the actual value of a measurement from header and body buffers. Returns NaN for invalid indices. ```cpp getMeasurementValueFromHeaderBody(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t header_buffer[], size_t header_buffer_size, uint8_t amount_of_measurements_in_body, uint8_t body_buffer[], size_t body_buffer_size) ``` -------------------------------- ### Get Measurement Type from Header/Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the type of a measurement based on its index and data buffers. Returns UNKNOWN for invalid indices. ```cpp measurementType getMeasurementTypeFromHeaderBody(uint8_t measurement_index, uint8_t amount_of_measurements, uint8_t measurement_buffer[], size_t measurement_buffer_size) ``` -------------------------------- ### Attempt Module Connection Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Attempts to connect to a specified module with a given baud rate. Optionally requests extra identification information. ```cpp attemptConnect(uint8_t module, unsigned long baud_rate, bool request_extra_identification) ``` -------------------------------- ### attemptConnect Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Attempts to establish a connection to a specified module with a given baud rate, with an option to request extra identification. ```APIDOC ## attemptConnect ### Description Attempts to connect to a specified module at a given baud rate. It can optionally request extra identification information from the module. ### Method attemptConnect ### Parameters #### Path Parameters - **module** (uint8_t) - Required - The logical ID of the target module (e.g., engine-0x01, cluster-0x17). - **baud_rate** (unsigned long) - Required - The communication speed (e.g., 10400, 9600, 4800). - **request_extra_identification** (bool) - Required - Set to `true` to request extra identification if available, `false` otherwise. ### Returns - **executionStatus** (enum) - Indicates the success of the operation. Possible values are `SUCCESS`, `FAIL`, `ERROR`. ### Notes - The module's baud rate must be known beforehand; attempting to connect at an incorrect speed will always fail. - If `request_extra_identification` is `false` and the module has extra identification, that string will not be requested. `getExtraIdentification()` will return an empty string, but the connection will be almost 1 second faster. Set this to `false` if you are not interested in the extra identification string. ``` -------------------------------- ### login Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Performs a login operation using a provided login code and the current workshop code. ```APIDOC ## login ### Description Performs a login operation. ### Method ```cpp login(uint16_t login_code, uint32_t workshop_code) ``` ### Parameters #### Path Parameters - **login_code** (uint16_t) - Required - the login code - **workshop_code** (uint32_t) - Required - the CURRENT workshop code ### Returns #### Success Response - **executionStatus** (enum) - whether or not the operation executed successfully (*SUCCESS, *FAIL, *ERROR) ### Response Example ``` { "executionStatus": "SUCCESS" } ``` ``` -------------------------------- ### Configure Hardware Serial Port (Arduino MEGA) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/3.-The-Arduino-side-of-things Uncomment the appropriate line in `configuration.h` to select the hardware serial port for Arduino MEGA when using Serial2. ```cpp #define KLINE_SERIAL_PORT Serial2 ``` -------------------------------- ### Perform Output Tests Sequentially Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Executes the next test in a predefined sequence of output tests. Call this function repeatedly until it returns FAIL to run all tests. ```cpp outputTests(uint16_t ¤t_output_test) ``` -------------------------------- ### Login Function Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Performs a login operation to authenticate with the ECU. Requires a login code and the current workshop code. ```cpp login(uint16_t login_code, uint32_t workshop_code) ``` -------------------------------- ### adapt Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Changes the value of an adaptation channel. It is recommended to use testAdaptation first. ```APIDOC ## adapt ### Description Changes the value of an adaptation channel. ### Method ```cpp adapt(uint8_t channel, uint16_t value, uint32_t workshop_code) ``` ### Parameters #### Path Parameters - **channel** (uint8_t) - Required - adaptation channel to modify - **value** (uint16_t) - Required - value to store in the channel - **workshop_code** (uint32_t) - Required - WSC to use ### Notes - Use testAdaptation() before adapt(), to ensure it's possible to use the value on the channel. ### Returns #### Success Response - **executionStatus** (enum) - whether or not the operation executed successfully (*SUCCESS, *FAIL, *ERROR) ### Response Example ``` { "executionStatus": "SUCCESS" } ``` ``` -------------------------------- ### Get Measurement Type from Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/5.-KWP1281-procedures Retrieves the measurement type using only the header message. This function is part of the KWP1281 library for processing sensor data. ```c getMeasurementTypeFromHeader() ``` -------------------------------- ### getFaultElaboration Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides a fault elaboration string or its length. This function can be called with either a fault code index or an elaboration code. It is a static function. ```APIDOC ## getFaultElaboration (overload 1) ### Description Provides a fault elaboration string from a buffer filled by readFaults(). ### Method Static function call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **is_intermittent** (bool&) - Description: whether or not the elaboration code indicated that the fault is "Intermittent" - **fault_code_index** (uint8_t) - Description: index of the fault code whose elaboration needs to be retrieved - **amount_of_fault_codes** (uint8_t) - Description: total number of fault codes stored in the array (value passed as reference to readFaults()) - **fault_code_buffer** (uint8_t[]) - Description: array in which fault codes have been stored by readFaults() - **fault_code_buffer_size** (size_t) - Description: total size of the given array (provided with the sizeof() operator) - **str** (char[]) - Description: string (character array) into which to copy the elaboration string - **string_size** (size_t) - Description: total size of the given array (provided with the sizeof() operator) ### Request Example ```cpp getFaultElaboration(is_intermittent, fault_code_index, amount_of_fault_codes, fault_code_buffer, fault_code_buffer_size, str, string_size) ``` ### Response #### Success Response - **return value** (char*) - Description: the same character array provided (str) ### Response Example ```cpp // Example response would be the 'str' character array populated with the elaboration string ``` ### Notes * The fault elaboration may not be correct if the fault code is of standard OBD type. * Use the isOBDFaultCode() function to check the type of fault code. * If it is of standard OBD type, the elaboration will be contained in the description string, after the ':' character. * It is a static function so it does not require an instance to be used. ``` ```APIDOC ## getFaultElaboration (overload 2) ### Description Provides a fault elaboration string from an elaboration code. ### Method Static function call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **is_intermittent** (bool&) - Description: whether or not the elaboration code indicated that the fault is "Intermittent" - **elaboration_code** (uint8_t) - Description: elaboration code given by getFaultElaborationCode() - **str** (char[]) - Description: string (character array) into which to copy the elaboration string - **string_size** (size_t) - Description: total size of the given array (provided with the sizeof() operator) ### Request Example ```cpp getFaultElaboration(is_intermittent, elaboration_code, str, string_size) ``` ### Response #### Success Response - **return value** (char*) - Description: the same character array provided (str) ### Response Example ```cpp // Example response would be the 'str' character array populated with the elaboration string ``` ### Notes * The fault elaboration may not be correct if the fault code is of standard OBD type. * Use the isOBDFaultCode() function to check the type of fault code. * If it is of standard OBD type, the elaboration will be contained in the description string, after the ':' character. * It is a static function so it does not require an instance to be used. ``` -------------------------------- ### Get Specific Fault Code from Buffer Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves a specific fault code from a buffer previously populated by the readFaults() function. This is a static function and does not require an instance. ```cpp getFaultCode(uint8_t fault_code_index, uint8_t amount_of_fault_codes, uint8_t fault_code_buffer[], size_t fault_code_buffer_size) ``` -------------------------------- ### outputTests Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Executes the next output test in the sequence. Call repeatedly until FAIL is returned to run all tests. This is a static function. ```APIDOC ## outputTests ### Description Performs an output test. Output tests are executed sequentially, and this function should be called repeatedly until it returns `FAIL` to complete all tests. ### Method Static function call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **current_output_test** (uint16_t &) - Required - A reference to a variable that will store the ID of the currently running output test. ### Returns - **executionStatus** - An enum indicating the result of the operation: `SUCCESS`, `FAIL`, or `ERROR`. ### Notes - Output tests run in a fixed, unchangeable sequence. - To cycle through all tests, call `outputTests()` multiple times until `FAIL` is returned. - The ID of the current test is updated in `current_output_test`. - Use `getOutputTestDescription()` to get a description of the currently running test. ``` -------------------------------- ### getOutputTestDescriptionLength Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the length of the description string for an output test ID. This is a static function and does not require an instance. ```APIDOC ## getOutputTestDescriptionLength ### Description Provides the length of the description string for an output test ID given by outputTests(). ### Method Static function (no instance required) ### Signature ```cpp getOutputTestDescriptionLength(uint16_t output_test) ``` ### Parameters #### Input Parameters - **output_test** (uint16_t) - Required - The output test ID, given by outputTests(). ### Returns - **size_t** - The string length. ### Notes - It is a static function so it does not require an instance to be used. ``` -------------------------------- ### getBasicSettingValue Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves a specific measured value from a buffer previously filled by the basicSetting() function. ```APIDOC ## getBasicSettingValue ### Description Provides a measured value from a buffer filled by basicSetting(). ### Method ```cpp getBasicSettingValue(uint8_t value_index, uint8_t amount_of_values, uint8_t basic_setting_buffer[] , size_t basic_setting_buffer_size) ``` ### Parameters #### Path Parameters - **value_index** (uint8_t) - Required - index of the value that needs to be retrieved - **amount_of_values** (uint8_t) - Required - total number of values stored in the array (value passed as reference to basicSetting()) - **basic_setting_buffer** (uint8_t[]) - Required - array in which fault codes have been stored by basicSetting() - **basic_setting_buffer_size** (size_t) - Required - total size of the given array (provided with the sizeof() operator) ### Returns #### Success Response - **uint8_t** - value ### Notes - It is a static function so it does not require an instance to be used. ### Response Example ``` { "value": 123 } ``` ``` -------------------------------- ### Get Measurement Decimals from Header Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/5.-KWP1281-procedures Retrieves the number of decimal places for a measurement using only the header message. This function is part of the KWP1281 library for processing sensor data. ```c getMeasurementDecimalsFromHeader() ``` -------------------------------- ### Get Module Extra Identification Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Retrieves additional identification information, such as the VIN, from the module. Returns an empty string if no extra identification is available. This operation can be skipped to speed up connection. ```cpp getExtraIdentification() ``` -------------------------------- ### Custom Error Function for Connection Issues Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/3.-The-Arduino-side-of-things Implement a function to handle connection errors, receiving module and baud rate information. This function should only use `connect()` or `attemptConnect()` and avoid sending requests. ```c void errorFunction(uint8_t module, unsigned long baud) ``` ```c++ diag.customErrorFunction(errorFunction); ``` -------------------------------- ### getFaultElaborationCode Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides a fault elaboration code from a buffer filled by readFaults(). This is a static function and does not require an instance. ```APIDOC ## getFaultElaborationCode ### Description Provides a fault elaboration code from a buffer filled by readFaults(). ### Method Static function call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **fault_code_index** (uint8_t) - Description: index of the fault code whose elaboration code needs to be retrieved - **amount_of_fault_codes** (uint8_t) - Description: total number of fault codes stored in the array (value passed as reference to readFaults()) - **fault_code_buffer** (uint8_t[]) - Description: array in which fault codes have been stored by readFaults() - **fault_code_buffer_size** (size_t) - Description: total size of the given array (provided with the sizeof() operator) ### Request Example ```cpp getFaultElaborationCode(fault_code_index, amount_of_fault_codes, fault_code_buffer, fault_code_buffer_size) ``` ### Response #### Success Response - **return value** (uint8_t) - Description: fault elaboration code ### Response Example ```cpp // Example response would be a uint8_t value representing the elaboration code ``` ### Notes * It is a static function so it does not require an instance to be used. ``` -------------------------------- ### Get Measurement Text from Header and Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/5.-KWP1281-procedures Retrieves the measurement text using both the header and body messages. This function is part of the KWP1281 library for processing live sensor data. ```c getMeasurementTextFromHeaderBody() ``` -------------------------------- ### Get Measurement Units from Header and Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/5.-KWP1281-procedures Retrieves the measurement units using both the header and body messages. This function is part of the KWP1281 library for processing live sensor data. ```c getMeasurementUnitsFromHeaderBody() ``` -------------------------------- ### Get Measurement Value from Header and Body Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/5.-KWP1281-procedures Retrieves the measurement value using both the header and body messages. This function is part of the KWP1281 library for processing live sensor data. ```c getMeasurementValueFromHeaderBody() ``` -------------------------------- ### testAdaptation Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Tests whether a given value would be suitable for a specific adaptation channel. ```APIDOC ## testAdaptation ### Description Tests whether or not a value would work for an adaptation channel. ### Method ```cpp testAdaptation(uint8_t channel, uint16_t value) ``` ### Parameters #### Path Parameters - **channel** (uint8_t) - Required - adaptation channel to test the value on - **value** (uint16_t) - Required - value to test ### Returns #### Success Response - **executionStatus** (enum) - whether or not the operation executed successfully (*SUCCESS, *FAIL, *ERROR) ### Response Example ``` { "executionStatus": "SUCCESS" } ``` ``` -------------------------------- ### Get Fault Elaboration Length (from buffer) Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Determines the length of the fault elaboration string from a buffer populated by readFaults(). This static function requires the fault code index and buffer details. ```cpp getFaultElaborationLength(uint8_t fault_code_index, uint8_t amount_of_fault_codes, uint8_t fault_code_buffer[], size_t fault_code_buffer_size) ``` -------------------------------- ### Get fault description length Source: https://github.com/domnulvlad/klinekwp1281lib/wiki/4.-Library-reference Provides the length of the fault description string for a given fault code. This function can operate on fault codes from a buffer or directly provided fault codes. ```cpp getFaultDescriptionLength(uint8_t fault_code_index, uint8_t amount_of_fault_codes, uint8_t fault_code_buffer[], size_t fault_code_buffer_size) ``` ```cpp getFaultDescriptionLength(uint16_t fault_code) ```