# Generic OBD-II channels: SAE J1979 mode 01 ("show current data") PIDs.
#
# Read ONLY when settings.txt has ecu_protocol=obd2 (src\Obd.cs, 2026-11-12). With
# that line absent, or ecu_protocol=ssm2, this file is not opened and the car is
# read over Subaru SSM2 exactly as before.
#
# NOTHING HERE HAS MET A CAR. The formulas are J1979's own and are checked against
# its worked values on the bench (tests\ObdTest.cs); which PIDs a given car
# answers, and how fast, is found out by connecting to it.
#
#   pid | key | name | units | bytes | formula | tier | lo | hi
#
#   pid      the PID in hex. 00, 20, 40 ... are not channels: they are the lists
#            of supported PIDs, which the app asks for itself at CONNECT. A PID
#            the car does not list is not asked for, its tile stays dark and a
#            pull has no column for it.
#   key      the channel's key: tiles, pages, danger rules and logcolumns.txt
#            name it by this. Where the app already has the same quantity in the
#            same units, the row carries THAT key with that channel's own name
#            and units, so the tachometer, the tiles, the rules and the log
#            column are the ones the Subaru path uses (rpm, coolant, map ...).
#            The app checks it: a row that reuses a key under another name or
#            unit is left out and logs\app.log says so.
#   name     the tile's caption; "name (units)" is the pull's column heading.
#   units    the app is psi / F / mph. J1979 is kPa / C / km/h, so the formula
#            converts: kPa / 6.89475729 = psi, 32 + 9*C/5 = F, km/h * 0.621371192
#            = mph.
#   bytes    how many data bytes the car sends for this PID. This must be right:
#            several PIDs travel in one reply with nothing between them but
#            their known lengths. At CONNECT each PID is asked for once on its
#            own, and one that answers with another length is not read at all.
#            "4 AB" means four bytes are sent and this channel is the first two
#            (J1979 calls them A, B, C, D); "4 CD" the last two. A second row
#            can take the others.
#   formula  x is the channel's bytes as one unsigned number, first byte highest
#            (for two bytes, 256*A + B). Numbers, x, + - * / and brackets.
#            A PID whose bytes are a signed number (32, 54) cannot be written yet.
#   tier     slow = asked once every poll_slow_every cycles and carried between,
#            like a key in defs\poll-tiers.txt (which is honoured here too).
#            Empty or fast = every cycle. Six PIDs go in one request, so every
#            six on the fast tier cost one more round trip to the ECU per cycle:
#            keep on it only what moves.
#   lo, hi   optional: the span of the tile's bar or a page's dial.
#
# Two rows with the same key are alternatives: the first one this car supports
# is read (the wide-band front sensor is PID 24 on some cars and PID 34 on others).
#
# What a generic OBD-II session does NOT have, whatever the car: boost as its own
# channel (Boost (MAP - Baro) is worked out from PIDs 0B and 33 when both are
# there), knock correction, DAM, wastegate duty, injector pulse width, AVCS, TGV,
# SI-DRIVE. Those are Subaru SSM2 addresses. Calculated Load (g/rev), AF 1 Trims
# Total and the calculated gear are worked out from the PIDs below the same way
# they are from the SSM2 channels.

# ---- the same quantity the Subaru path reads: same key, same name, same units ----
#
# rpm: (256*A + B) / 4.
0C | rpm         | RPM                        | rpm     | 2    | x/4
# Vehicle speed: A km/h.
0D | speed       | Vehicle Speed              | mph     | 1    | x*0.621371192
# Manifold absolute pressure: A kPa.
0B | map         | Manifold Absolute Pressure | psi     | 1    | x/6.89475729
# Mass airflow: (256*A + B) / 100 g/s.
10 | maf         | Mass Airflow               | g/s     | 2    | x/100
# RELATIVE throttle position, PID 45, and not PID 11: on a drive-by-wire car PID
# 11 is the sensor's absolute reading, which idles around 15 % and never reaches
# 0, while the SSM2 throttle angle is relative. --verify compares the SSM2
# throttle against PID 45 for the same reason (src\Verify.cs).
45 | tps         | Throttle Plate             | %       | 1    | x*100/255
# Relative accelerator pedal. Taken as the twin of the SSM2 pedal angle because
# both run 0 to 100; the two have NOT been compared on a car.
5A | accel_pos   | Accel Pedal                | %       | 1    | x*100/255
# Timing advance: A/2 - 64 degrees, which is (A - 128) / 2.
0E | ign_timing  | Ignition Timing Total      | degrees | 1    | (x-128)/2
# Short-term and long-term fuel trim, bank 1: (A - 128) * 100 / 128.
06 | af_corr1    | AF Correction #1           | %       | 1    | (x-128)*100/128
07 | af_learn1   | AF Learning #1             | %       | 1    | (x-128)*100/128 | slow
# The front (wide-band) sensor's lambda, times 14.7 as the SSM2 channel has it:
# lambda = (256*A + B) * 2 / 65536. Some cars report it as PID 24 (with the
# sensor's voltage in C, D), others as PID 34 (with its current). (J1979 lets a
# car rescale PIDs 24, 34 and 44 through PID 4F. That is not read: on a car
# that uses it these three would read wrong, and nothing here would say so.)
24 | af_ratio1   | AF Sensor #1 Ratio         | AFR     | 4 AB | x*2/65536*14.7
34 | af_ratio1   | AF Sensor #1 Ratio         | AFR     | 4 AB | x*2/65536*14.7
# Coolant and intake air temperature: A - 40 C.
05 | coolant     | Coolant Temp               | F       | 1    | 32+9*(x-40)/5   | slow
0F | intake_temp | Intake Temp                | F       | 1    | 32+9*(x-40)/5   | slow
# Barometric pressure: A kPa.
33 | baro        | Barometric Pressure        | psi     | 1    | x/6.89475729    | slow
# Fuel pressure, gauge: 3*A kPa. The key is the standard Fuel Pressure's, the one
# that is read wherever COBB's own fuel pressure address is not.
0A | fuel_press  | Fuel Pressure              | psi     | 1    | x*3/6.89475729
# Ethanol content: A * 100 / 255 %. The tile and the column are the ones the
# flex-fuel hunt fills on the Subaru path.
52 | ethanol     | Ethanol Concentration      | %       | 1    | x*100/255       | slow

# ---- channels the Subaru path has no twin for: their own keys and headings ----
#
# J1979's "calculated load value", a percentage. It is NOT the app's Calculated
# Load, which is grams per revolution and is still worked out from PIDs 10 and 0C.
04 | load_pct      | Engine Load                       | %      | 1    | x*100/255
43 | load_abs      | Engine Load (absolute)            | %      | 2    | x*100/255        | slow | 0 | 200
# Commanded equivalence ratio: (256*A + B) * 2 / 65536. What the ECU is asking
# for, beside what the front sensor and the wideband say it got.
44 | lambda_cmd    | Commanded Lambda                  | lambda | 2    | x*2/65536
# The absolute throttle sensor (see PID 45 above for why it is not "tps").
11 | tps_abs       | Throttle Position (absolute)      | %      | 1    | x*100/255
4C | tps_cmd       | Throttle (commanded)              | %      | 1    | x*100/255        | slow
49 | pedal_d       | Accel Pedal Position D            | %      | 1    | x*100/255
# Fuel rail pressure, gauge: 10 * (256*A + B) kPa - a direct-injection or diesel
# rail. And relative to manifold vacuum: 0.079 * (256*A + B) kPa.
23 | fuel_rail     | Fuel Rail Pressure                | psi    | 2    | x*10/6.89475729  |      | 0 | 3000
22 | fuel_rail_rel | Fuel Rail Pressure (manifold ref) | psi    | 2    | x*0.079/6.89475729
# The other half of PID 24 and PID 34: the front sensor's voltage, (256*C + D) *
# 8 / 65536 V, or its pumping current, (256*C + D) / 256 - 128 mA.
24 | af_volts1     | AF Sensor #1 Voltage              | V      | 4 CD | x*8/65536
34 | af_ma1        | AF Sensor #1 Current              | mA     | 4 CD | x/256-128
# Narrow-band oxygen sensors, bank 1: A / 200 V. (B is a trim, not read here.)
14 | o2_b1s1       | O2 Sensor B1S1                    | V      | 2 A  | x/200
15 | o2_b1s2       | O2 Sensor B1S2                    | V      | 2 A  | x/200            | slow
# Bank 2 trims, for an engine the ECU fuels as two banks.
08 | af_corr2      | AF Correction #2                  | %      | 1    | (x-128)*100/128  |      | -25 | 25
09 | af_learn2     | AF Learning #2                    | %      | 1    | (x-128)*100/128  | slow | -25 | 25
# Torque as the ECU reckons it: A - 125 % of the reference torque, (256*A + B) Nm.
61 | torque_dmd    | Torque (driver demand)            | %      | 1    | x-125            | slow | 0 | 100
62 | torque_act    | Torque (actual)                   | %      | 1    | x-125            | slow | 0 | 100
63 | torque_ref    | Reference Torque                  | lb-ft  | 2    | x*0.737562149    | slow | 0 | 600
# Fuel rate: (256*A + B) / 20 litres an hour.
5E | fuel_rate     | Fuel Rate                         | gal/h  | 2    | x/20*0.264172052 | slow | 0 | 30
# Engine oil temperature from the ECU: A - 40 C. Its own key, not oil_temp:
# that one is the oil gauge's (defs\aux-gauge.txt), a different sensor.
5C | oil_temp_ecu  | Engine Oil Temp                   | F      | 1    | 32+9*(x-40)/5    | slow | 100 | 300
46 | ambient_temp  | Ambient Air Temp                  | F      | 1    | 32+9*(x-40)/5    | slow | 0 | 120
# Catalyst temperature, bank 1 sensor 1: (256*A + B) / 10 - 40 C.
3C | cat_temp1     | Catalyst Temp B1S1                | F      | 2    | 32+9*(x/10-40)/5 | slow | 0 | 1800
# Control module voltage: (256*A + B) / 1000 V.
42 | ecu_volts     | Control Module Voltage            | V      | 2    | x/1000           | slow | 8 | 16
2F | fuel_level    | Fuel Level                        | %      | 1    | x*100/255        | slow
2C | egr_cmd       | EGR (commanded)                   | %      | 1    | x*100/255        | slow
2E | purge_cmd     | Evap Purge (commanded)            | %      | 1    | x*100/255        | slow
47 | tps_abs_b     | Throttle Position B (absolute)    | %      | 1    | x*100/255        | slow
4A | pedal_e       | Accel Pedal Position E            | %      | 1    | x*100/255        | slow
# Seconds since the engine started: 256*A + B. (Not run_s: that key is the app's
# own clock, worked out from rpm, which the oil rule waits on.)
1F | run_time      | Engine Run Time                   | s      | 2    | x                | slow | 0 | 3600
# Distances: 256*A + B km.
21 | mil_dist      | Distance With MIL On              | mi     | 2    | x*0.621371192    | slow
31 | clear_dist    | Distance Since Codes Cleared      | mi     | 2    | x*0.621371192    | slow
