Parsers
- class obdii.parsers.formula.Formula(expression: str)[source]
Bases:
objectRepresents a mathematical formula based on a string expression.
Example
# 11 (dec) -> A # 64 (dec) -> B unparsed = [11, 64] formula = Formula("(256*A+B)/4") result = formula(unparsed) # (256 * 11 + 64)/4 >>> result 720.0
- class obdii.parsers.formula.MultiFormula(*expressions: str)[source]
Bases:
objectRepresents multiple mathematical formulas based on string expressions.
Example
# 143 (dec) -> A # 125 (dec) -> B # 149 (dec) -> C # 128 (dec) -> D # 111 (dec) -> E unparsed = [143, 125, 149, 128, 111] engine_torque = MultiFormula("A-125", "B-125", "C-125", "D-125", "E-125") result = engine_torque(unparsed) >>> result [18, 0, 24, 3, -14]
- class obdii.parsers.pids.SupportedPIDS(base_pid: int)[source]
Bases:
objectParse supported PIDs from the response data.
Each bit in the 4 byte (32 bit) response represents support for one PID, starting from the Base PID. A bit set to 1 indicates the PID is supported, 0 means it is not. Bits are read from most-significant to least-significant.
Example
unparsed = [190, 31, 168, 19] # 190 31 168 19 # B E 1 F A 8 1 3 # 1011 1110 0001 1111 1010 1000 0001 0011 supported_pids = SupportedPIDS(0x01) result = supported_pids(unparsed) >>> result [0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, 0x1C, 0x1F, 0x20]
- class obdii.parsers.pids.EnumeratedPIDS(mapping: Dict[int | Iterable[int], Any])[source]
Bases:
objectMap parsed data bytes to enumerated values.
Example
unparsed = [0, 0] fuel_system_status = EnumeratedPIDS( { 0: "The motor is off", 1: "Open loop due to insufficient engine temperature", 2: "Closed loop, using oxygen sensor feedback to determine fuel mix", 4: "Open loop due to engine load OR fuel cut due to deceleration", 8: "Open loop due to system failure", 16: "Closed loop, using at least one oxygen sensor but there is a fault in the feedback system", } ) result = fuel_system_status(unparsed) >>> result [(0, "The motor is off"), (0, "The motor is off")]
- class obdii.parsers.dtc.DTC(raw: str)[source]
Bases:
objectDiagnostic Trouble Code (DTC) representation.
5 characters structured as follows:
U 0 1 5 8 | | | |____| | | | descriptor | | system | scope category- __init__(raw: str) None[source]
Initialize DTC object.
- Parameters:
*raw (str) – The raw DTC code string, e.g. “U0158”.
- code: str
Full DTC code, e.g. “U0158”.
- descriptor: str
DTC descriptor, e.g. “58”.
- classmethod from_bytes(high: int, low: int) DTC[source]
Parse two raw bytes into a DTC.
0xC1, 0x58 1100 0001 0101 1000 U 0 1 5 8
- static parse(unparsed: List[int]) List[DTC][source]
Parse a raw Mode 03 CAN payload into a list of DTCs.
[0x02, 0xC1, 0x58, 0x01, 0x96, 0x00, 0x00, 0x00] | |_____| |_____| |___________| count DTC #1 DTC #2 padding (ignored)- Parameters:
unparsed (List[int]) – The data to evaluate the formula against.