Hi everyone,
I'm working on a project for my car. It's a little above my experience so I'm learning as I go.
Currently I'm facing the following issue:
The program I use compares incoming packets (from the car's canbus) to packets I defined in code.
This works great.
Here I have an example of a packet which is always the same:
const byte UNLOCK_PRESSED [6] PROGMEM = {
0x00 , 0x04 , 0xBF , 0x72 , 0x22 , 0xEB
}; // Unlock Pressed
void packet_Handler(byte *packet) // callback function
{
if (memcmp_P(packet, UNLOCK_PRESSED, 6) == 0){
// Unlock was pressed. Do something
}
However now I need the program to compare a specific value in a packet. This value changes as it shows the car's speed and RPM.
The packet looks like this:
0x80 0x05 0xBF 0x18 0x00 0x00 0xCK 0kmh 0 rpm
0x80 0x05 0xBF 0x18 0x01 0x01 0xCK 2kmh 100rpm
0x80 0x05 0xBF 0x18 0x02 0x02 0xCK 4kmh 200rpm
0x80 0x05 0xBF 0x18 0x03 0x03 0xCK 6kmh 300rpm
etc...
CK indicated the Checksum of course. So the problem is the last 3 bytes, speed, RPM and CK will be different as the car drives.
What would be a good approach to extract the speed and RPM?
I think the least thing I need to do is check the first 4 bytes. This way I can make sure that the packet IS the one indicating speed, RPM and CK.
So sender (1st byte), length (2nd byte), receiver (3rd byte), and 0x18 I assume indicates that this is the message that shows speed and RPM. If these 4 match then i could assume that the 5th byte indicates the speed and the sixth byte indicates RPM.
I found this: avr-libc: <avr/pgmspace.h>: Program Space Utilities
But as I said I'm afraid it's a bit too complicated for me to understand at this point.
What would be the easiest way to solve my problem?
Any help is very much appreciated!
Best regards,
Luck Hermsen