Im doing a prototype with an UNO and RS232 Shiled (Max232 shield). Hooked it up to an aftemarket car ECU and i could successfully read the HEX data from the ECU and print in CoolTerm, so hardware i'm all good.
But im not really sure on how to address my current issue.
The ECU sends out data according to the following protocol:
A packet is sent out every 10ms, each packet consists of 5 byte.
1 byte = Channel Number
2 byte = Is always A3 (163)
3 & 4 byte = Is the channel value
5 byte = Checksum, preceding sum of the 4 bytes.
15 different channels are specified in the documentation. I did some checks on the data i got from from the ECU, and all 15 channels are not sent out every time. Channel 1 (RPM) repeats most frequently (every 7-8 loop) while some other channels repeats less frequently.
A typical packet would look something like this:
11 A3 04 BA 72
To calculate the sum of the 1-4 bytes it would look this:
11 + A3 + 04 + BA = 172
But the first digit in the result would be dropped since it can hold one byte. So 72 then, which matches the 5 byte in the example.
The value of the channel would be:
04BA, converted to dec: 1210 . This is the Water temperature, but it will require another calculation, specified for each channel. For water: 1210/10-100=21
Back to my actual problem then. Im not really sure on how to identify my 5 byte packet. I guess it would be easier if each packet would start with A3, instead being the second byte in the packet. I guess i would need to look for A3 and its preceding 1 byte and then byte 3,4,5. do the checksum calculation, then calculate the decimal value of byte 3,4. Then finally calculate the actual value based on the documentation and store the value in a pre-defined variable (wTemp), based on the channel number of the packet.
Any ideas on how?