Description
can_msg_recv_callback()
– call-back methode stub. Overwrite this methode in your own class to be notified when a new CAN message arrives.
class MY_CLASS : public SAMC21_CAN_RECEIVER
{
public:
void can_msg_recv_callback(const CANMessage & inMessage)
{ }
void can_routine_callback()
{ }
};
Syntax
void can_msg_recv_callback(const CANMessage & inMessage)
{ }
Parameters
CANMessage & inMessage – the new message that has arrived
Returns
nothing
Example Code
Definition of a derived class that overwrites the call-back methodes.
class MY_ENGINE_CLASS : public SAMC21_CAN_RECEIVER
{
public:
uint32_t u32_RPM;
uint8_t s8_Temperature;
void can_msg_recv_callback(const CANMessage & inMessage)
{
if(inMessage.id == 0x123)
u32_RPM = inMessage.data32[0];
if(inMessage.id == 0x124)
s8_Temperature= inMessage.data[0];
}
void can_routine_callback()
{
// do things regularly
}
};
Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> CAN_Bus -> ReceiverClassExample
Notes and Warnings
It is common practise to only do calculations and to set variables in call-back routines.
Do not use any functions like delay(), yields(), println() etc. that would cause the re-entrance of the call-backs.
See also
SAMC21_CAN_RECEIVER()
regReceiver
deRegister
SAMC21_CAN – Library
CAN operation background
users manual
BOOTLOADER SETTINGS – Library