The basic logic to send periodic messages is as follows:
- First, allocate the necessary buffers that will hold the CAN data using mxfTxPeriodicUpdateMsgBufferAlloc(). Usually, one buffer is allocated for each message id to be sent. The buffer index can be any number between 0 and 255.
- Second, create a schedule instance for a given channel using mxfTxPeriodicScheduleNew().
- The simplest CAN message consists of a single list containing a single buffer. When working with such a simple message the function mxfTxPeriodicScheduleSingleMsgAdd() can be used. This function creates a message that contains a single list with a single buffer.
- Before adding the CAN records to the message, one buffer list must be added using mxfTxPeriodicScheduleBufferListAdd(). The function includes an argument to specify how many buffers (CAN data) the list contains. If the list includes more than one buffer, one CAN data for each buffer included in the list is sent back-to-back at the message update rate.
- Set the CAN data value(s) in the
MXF_CANBUS_DATAREC
for a given record using mxfCanBusTxPeriodicUpdateMsgWrite().
- Start the schedule using mxfTxPeriodicScheduleRun().
canbus_periodic.c
The example below illustrates how to put it together:
#define BUFFER_SIZE 4096 // 4KB
HMXF_CHANNEL channel;
HMXF_BUFFER txBuffer;
HMXF_SCHED schedule;
HMXF_SCHED_MSG msg=0;
uint32 rc;
...
if(!rc)
if (!rc)
{
if (!rec)
rc = MAXT_ERROR_MEM;
}
if(!rc)
if(!rc)
if (!rc)
{
rec->reserved = 0;
rec->
info = MXF_CANBUS_REC_INFO_EXTENDED | 8;
}
if(!rc)
{
printf("Running periodic transmission, please wait...\n\r");
}
if(!rc)
{
}
if(rec)
free(rec)
...