ca13734bf0
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers, middleware (CAN stack, diagnostics, safety), applications, board support, build/test tooling, and documentation.
92 lines
3.0 KiB
C
92 lines
3.0 KiB
C
/**
|
|
* @file obd_ii.h
|
|
* @brief OBD-II (On-Board Diagnostics) implementation
|
|
*/
|
|
|
|
#ifndef OBD_II_H
|
|
#define OBD_II_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "kernel.h"
|
|
#include "can_driver.h"
|
|
|
|
/* OBD-II Configuration */
|
|
#define OBD_II_MAX_PIDS 0xFF
|
|
#define OBD_II_CAN_ID_REQUEST 0x7DF
|
|
#define OBD_II_CAN_ID_RESPONSE 0x7E8
|
|
#define OBD_II_CAN_ID_RESPONSE_2 0x7E9
|
|
|
|
/* OBD-II Service Modes */
|
|
typedef enum {
|
|
OBD_II_SERVICE_SHOW_CURRENT_DATA = 0x01,
|
|
OBD_II_SERVICE_SHOW_FREEZE_FRAME = 0x02,
|
|
OBD_II_SERVICE_SHOW_STORED_DTCS = 0x03,
|
|
OBD_II_SERVICE_CLEAR_DTCS = 0x04,
|
|
OBD_II_SERVICE_TEST_RESULTS_OXYGEN = 0x05,
|
|
OBD_II_SERVICE_TEST_RESULTS_NON_CONTINUOUS = 0x06,
|
|
OBD_II_SERVICE_SHOW_PENDING_DTCS = 0x07,
|
|
OBD_II_SERVICE_CONTROL_ONBOARD_SYSTEM = 0x08,
|
|
OBD_II_SERVICE_REQUEST_VEHICLE_INFO = 0x09,
|
|
OBD_II_SERVICE_PERMANENT_DTCS = 0x0A
|
|
} ObdIIServiceMode_t;
|
|
|
|
/* OBD-II PID Definitions */
|
|
typedef enum {
|
|
OBD_II_PID_SUPPORTED_00_20 = 0x00,
|
|
OBD_II_PID_MONITOR_STATUS = 0x01,
|
|
OBD_II_PID_FREEZE_DTC = 0x02,
|
|
OBD_II_PID_FUEL_SYSTEM_STATUS = 0x03,
|
|
OBD_II_PID_CALCULATED_ENGINE_LOAD = 0x04,
|
|
OBD_II_PID_ENGINE_COOLANT_TEMP = 0x05,
|
|
OBD_II_PID_SHORT_TERM_FUEL_TRIM_BANK1 = 0x06,
|
|
OBD_II_PID_LONG_TERM_FUEL_TRIM_BANK1 = 0x07,
|
|
OBD_II_PID_INTAKE_MANIFOLD_PRESSURE = 0x0B,
|
|
OBD_II_PID_ENGINE_RPM = 0x0C,
|
|
OBD_II_PID_VEHICLE_SPEED = 0x0D,
|
|
OBD_II_PID_TIMING_ADVANCE = 0x0E,
|
|
OBD_II_PID_INTAKE_AIR_TEMP = 0x0F,
|
|
OBD_II_PID_MAF_AIR_FLOW_RATE = 0x10,
|
|
OBD_II_PID_THROTTLE_POSITION = 0x11,
|
|
OBD_II_PID_OXYGEN_SENSOR_PRESENT = 0x13,
|
|
OBD_II_PID_OXYGEN_SENSOR_1 = 0x14,
|
|
OBD_II_PID_OXYGEN_SENSOR_2 = 0x15,
|
|
OBD_II_PID_RUN_TIME_SINCE_START = 0x1F,
|
|
OBD_II_PID_SUPPORTED_21_40 = 0x20,
|
|
OBD_II_PID_DISTANCE_WITH_MIL = 0x21,
|
|
OBD_II_PID_FUEL_RAIL_PRESSURE = 0x22,
|
|
OBD_II_PID_FUEL_RAIL_GAUGE_PRESSURE = 0x23,
|
|
OBD_II_PID_OXYGEN_SENSOR_3 = 0x24,
|
|
OBD_II_PID_OXYGEN_SENSOR_4 = 0x25,
|
|
OBD_II_PID_SUPPORTED_41_60 = 0x40,
|
|
OBD_II_PID_CONTROL_MODULE_VOLTAGE = 0x42,
|
|
OBD_II_PID_ABSOLUTE_LOAD_VALUE = 0x43,
|
|
OBD_II_PID_AMBIENT_AIR_TEMP = 0x46,
|
|
OBD_II_PID_THROTTLE_POSITION_B = 0x47,
|
|
OBD_II_PID_ACCELERATOR_PEDAL_POSITION_D = 0x49,
|
|
OBD_II_PID_ACCELERATOR_PEDAL_POSITION_E = 0x4A
|
|
} ObdIIPid_t;
|
|
|
|
/* OBD-II PID Value */
|
|
typedef struct {
|
|
ObdIIPid_t pid;
|
|
uint8_t data[4];
|
|
uint8_t length;
|
|
bool is_supported;
|
|
} ObdIIPidValue_t;
|
|
|
|
/* OBD-II Callbacks */
|
|
typedef bool (*ObdIIPidRequestCallback_t)(ObdIIPid_t pid, uint8_t* data,
|
|
uint8_t* length);
|
|
typedef void (*ObdIIDtcRequestCallback_t)(uint8_t* dtc_data, uint16_t* length);
|
|
|
|
/* OBD-II Functions */
|
|
KernelStatus_t obd_ii_init(void);
|
|
KernelStatus_t obd_ii_deinit(void);
|
|
KernelStatus_t obd_ii_register_pid_callback(ObdIIPidRequestCallback_t callback);
|
|
KernelStatus_t obd_ii_register_dtc_callback(ObdIIDtcRequestCallback_t callback);
|
|
void obd_ii_process_request(const CanMessage_t* message);
|
|
void obd_ii_main_function(void);
|
|
|
|
#endif /* OBD_II_H */
|