Hi, I don't really code, need help with the code. Code is based on Can_TrafficModifier example from due_can library, I am running it on the DUE. The code works as man in the middle where it passes CAN traffic both ways but allows to modify some frames before passing the traffic through. I have added my messages with if statements and it works well. The example of the code I need help with below. Basically I don't know what sort of code to put in there so when DUE receives a certain message it changes the bytes indicated but on byte[0] I need it to send it as 0x8B once, then change it again to 0x88 and keep sending 0x88 as long as the condition is met - DUE receives that specific message. It might be something very simple but I have no idea how to do it. Anybody could help? Thanks
void loop() {
CAN_FRAME frame;
while (true)
{
if (Can0.available() > 0) {//read Can0 and then send on Can1
Can0.read(frame);
if (frame.id == 0x481 && frame.data.bytes[0] == 0x02 & frame.data.bytes[1] == 0xFD) {
frame.id = 0x620;
frame.data.bytes[0] = 0x08;
frame.data.bytes[1] = 0x51;
frame.data.bytes[5] = 0x03;
}
else if (frame.id == 0x481 && frame.data.bytes[0] == 0x04 & frame.data.bytes[1] == 0xFB) {
frame.id = 0x620;
frame.data.bytes[0] = 0x8B; // I need to send 0x8B only once and after that I need this byte to keep sending as 0x88
frame.data.bytes[1] = 0x50;
frame.data.bytes[2] = 0x20;
frame.data.bytes[5] = 0x03;
}