Hi all,
Had a little experience with arduino, however I’m getting stuck on something Ive not done before.
Can anyone help me out?
I have a struct like this:
typedef struct {
unsigned long address; // CAN address
byte data[7]; // Data array
unsigned int length; // Length of data
unsigned long repetition; // Repetition time in ms
unsigned long lastmessage; // Millis time of last message
boolean active; // Whether message is active
} CANMsg;
Then I want to create a function that uses the type above. Something like this:
void changeCANBit(CANMsg canMessage, int BytePosition, int BitPosition, int NewBit) {
switch ((canMessage.data[BytePosition] & (1 << BitPosition)) >> BitPosition) {
case 0:
switch (NewBit) {
case 0:
// No change - already set as wanted
break;
case 1:
canMessage.data[BytePosition] = (canMessage.data[BytePosition] + (1 << BitPosition));
break;
}
break;
case 1:
switch (NewBit) {
case 0:
canMessage.data[BytePosition] = (canMessage.data[BytePosition] - (1 << BitPosition));
break;
case 1:
// No change - already set as wanted
break;
}
}
}
I am getting complile errors like this:
Compiling 'TestINO' for 'Arduino/Genuino Zero (Native USB Port)'
TestINO.ino: 35:19: error: variable or field 'changeCANBit' declared void
unsigned int length; \\ Length of data
TestINO.ino: 35:19: error: 'CANMsg' was not declared in this scope
TestINO.ino: 35:38: error: expected primary-expression before 'int
unsigned int length; \\ Length of data
TestINO.ino: 35:56: error: expected primary-expression before 'int
unsigned int length; \\ Length of data
Error compiling project sources
TestINO.ino: 35:73: error: expected primary-expression before 'int
unsigned int length; \\ Length of data
TestINO.ino: In function void mainProg()
TestINO.ino: 459:33: error: 'changeCANBit' was not declared in this scope
changeCANBit(canOut1, 0, 4, 1)
TestINO.ino: 469:33: error: 'changeCANBit' was not declared in this scope
changeCANBit(canOut1, 0, 4, 0)
TestINO.ino: 482:33: error: 'changeCANBit' was not declared in this scope
changeCANBit(canOut1, 0, 4, 1)
TestINO.ino: 491:33: error: 'changeCANBit' was not declared in this scope
changeCANBit(canOut1, 0, 4, 0)
Build failed for project 'TestINO'
In my sketch I have the following:
Declarations:
CANMsg canOut1;
In setup:
canOut1.address = 0x1CCC0101;
canOut1.repetition = 100;
canOut1.length = 8;
canOut1.active = true;
Then using the function:
changeCANBit(canOut1, 0, 4, 1);
Thanks!