Help with an OBD Simulator

Hi there,

I'm trying to build an OBD simulator based on some example code I have. It's all working ok, but I'm trying to add one more PID simulator and I'm struggling to see how its built.

As an example, the RPM PID for engine speed as listed here: OBD-II PIDs - Wikipedia is decoded on the reader end like this:

(256A+B)/4

and the simulator code I have generates the message to be read by that formula as:

               case ENGINE_RPM:              //   ((A*256)+B)/4    [RPM]
                    can_MsgTx.buf[0] = 0x01;  
                    can_MsgTx.buf[2] = ENGINE_RPM; 
                    can_MsgTx.buf[3] = (ecu.engine_rpm & 0xff00) >> 8;
                    can_MsgTx.buf[4] = ecu.engine_rpm & 0x00ff;
                    Can0.write(can_MsgTx);
                    break;

So buffer 3 is A, buffer 4 is B.

so now I would like to make a simulator for engine fuel flow. The reader formula for this PID is very similar:

(256A+B)/20

I don't understand how the RPM one has been built though, so I'm unable to modify it for this PID. Does anyone understand how the RPM message is generated to be able to adapt the message buffers for the fuel flow PID type?

Thanks!

Nick

Two bytes are being put together into one 16-bit unsigned integer. An unsigned integer can hold a value up to 65535 which is far higher then needed. It looks like the value being sent is RPM*4 so the value can be up to over 16000 RPM in 1/4 RPM increments. When 'ecu.engine_rpm' is 2000, does the OBD II reader say 500 RPM, 2000 RPM or 8000 RPM? I would guess 500.

It looks like the fuel rate is similar but in 20ths of a unit of volume per unit of time. Does the documentation say what the units of measure are? Liters per Hour? Milliliters per minute?