Innovate Motorsports OT-2 SDK User Manual

Page 76

Advertising
background image

76

Appendix B – Determining Normalized PID Availability


Although it is possible to use the ‘a’ command in Setup Mode to determine if a
normalized PID is available, asking 100+ times before presenting a list is a bit inefficient.
An alternate approach is to check for the availability of the associated ECU PID yourself,
using the ‘PID Masks’ returned in the Setup Mode ‘j’ (connection status) command.

The PID masks are 8, 32 bit ‘bit fields’. The MSB represents the lowest PID for that
field, the LSB the highest. So, in the first 32 bit mask, bit 31 = ECU PID 1, bit 0 = ECU
PID 0x20.

In the previous appendix we have a table of ECU pids and normalized PID names
(EcuPidMap). So, with the 8 PID masks returned from Connection Status (‘j’), we can
determine if a normalized PID is available without using the ‘a’ command, which tests
only one normalized PID at a time.

The routines would look something like this:

// Test an ECU pid against the ObdiPidMask
// 1 2 3 4 5 6 7 8....0x20
// 0x21 0x22..........0x40
int TestEcuPid(U8 ecupid)
{

U8 index;

U8 bit;


ecupid--;

index = ecupid / 0x20;

bit = ecupid % 0x20;


if (PidMask[index] & (0x80000000 >> bit))

return 1;

return 0;

}

int TestNormPid(U16 normpid)
{

// ‘none’ is always available

if (! normpid)

return 1;


// Out of range?

if (normpid & 0xFF00)

return 0;


return (TestEcuPid(EcuPidMap[normpid].ecuPid));

}

Advertising