Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data modification issues #47

Open
pat-cahill opened this issue May 12, 2020 · 1 comment
Open

Data modification issues #47

pat-cahill opened this issue May 12, 2020 · 1 comment

Comments

@pat-cahill
Copy link

pat-cahill commented May 12, 2020

I've got this working really well as a gateway using a DUE board and a home built shield using two MCP2562's. My problem is when I try to modify vertain bytes in a particular id, I get all of the bytes in every id modified.

I started with the example CAN_TrafficModifier but I can either get no modification or I get the correct modification but also the same bytes modified in every ID.

I've currently got an if statement set up to pick the address I want out. However, it doesn't seem to acknowledge the address.

Also, I don't think I'm understanding the watchFor or watchForRange at all. I ahve not been able to get them to work in any format.

Offending code attached. This one does nothing but it does gateway perfectly. Just no mods.

The commented lines are failed attempts

<
if (Can0.available() > 0) {
Can0.read(incoming);
if (incoming.id == 0x740) {
// incoming.id == 0x740;
incoming.data.bytes[1] *= 1.1;
incoming.data.bytes[3] *= 1.1;
incoming.data.bytes[5] *= 1.1;
incoming.data.bytes[7] *= 1.1;
Can1.sendFrame(incoming);
}
else {
// incoming.data.bytes[1] = incoming.data.bytes[1];
// incoming.data.bytes[3] = incoming.data.bytes[3];
// incoming.data.bytes[5] = incoming.data.bytes[5];
// incoming.data.bytes[7] = incoming.data.bytes[7];
Can1.sendFrame(incoming);
}
}

@collin80
Copy link
Owner

That is a weird outcome. I copied your code and only very slightly edited things. My testing seems to indicate it is working properly. However, and this could be significant, I was using only one CAN port as I didn't have enough hardware handy to do full passthrough between two ports and monitor it all. But, it is copying all the frames coming in and modifying only the proper bytes. I'll see if I can dig up enough hardware to do a full pass-through test with two ports.

Here is the complete test code I used:

`
#include <due_can.h>

void setup() {
delay(4000);
Can0.begin(500000);
Can0.watchFor();
SerialUSB.println("Starting up!");
}

void loop() {
CAN_FRAME incoming;
CAN_FRAME gearpos;
CAN_FRAME speedzero;
CAN_FRAME carspeed;

if (Can0.available() > 0)
{
Can0.read(incoming);
SerialUSB.println(incoming.id);
if (incoming.id == 0x0AA)
{
incoming.data.bytes[1] *= 1.1;
incoming.data.bytes[3] *= 1.1;
incoming.data.bytes[5] *= 1.1;
incoming.data.bytes[7] *= 1.1;
Can0.sendFrame(incoming);
}
else
{
Can0.sendFrame(incoming);
}
}

delay(100);
SerialUSB.write('.');
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants