MX Foundation 4
Sending Periodic Messages

The basic logic to send periodic messages is as follows:

The example below illustrates how to put it together:

csdb_periodic.c

#define BUFFER_SIZE 4096 // 4KB
#define TX_MSG_LABEL 5
#define TX_MSG_SI 0
#define BLOCKCOUNT 6
HMXF_CHANNEL txChannel;
HMXF_BUFFER txBuffer[2];
MXF_CSDB_DATAREC *recCsdb=NULL;
HMXF_SCHED schedule;
HMXF_SCHED_MSG msg=0;
HMXF_SCHED_MSG_BUFFER msgBuf=0;
uint32 rc;
...
// Allocate TX Periodic Update buffer
if(!rc)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(txChannel, 0xA5, BUFFER_SIZE, &txBuffer[0], NULL);
if(!rc)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(txChannel, TX_MSG_LABEL, BUFFER_SIZE, &txBuffer[1], NULL);
// Allocate host buffer
if (!rc)
{
recCsdb = (MXF_CSDB_DATAREC*)malloc(BUFFER_SIZE);
if (!recCsdb)
rc = MAXT_ERROR_MEM;
}
// Create the periodic scheduler
rc = mxfTxPeriodicScheduleNew(txChannel, &schedule);
// Set scheduling values: Rate=100 ms (.1sec), Phase=0 us
if(!rc)
rc = mxfTxPeriodicScheduleMsgAdd(schedule, 100000LL, 0, &msg);
// Define the number of buffer for the list and link to it
if(!rc)
rc = mxfTxPeriodicScheduleBufferListAdd(msg, 2, 0, txBuffer);
// Set record for the buffers
// Set the sync block
if(!rc)
{
recCsdb->timeTag = 0;
recCsdb->control = 0;
recCsdb->repeatCount = 1;
recCsdb->reserved = 0;
for (i=0; i<BLOCKCOUNT; i++)
recCsdb->data[i] = 0xa5;
rc = mxfCSDBTxPeriodicUpdateMsgWrite(txBuffer[0], 1, recCsdb);
}
// Set the message block
if(!rc)
{
recCsdb->timeTag = 0;
recCsdb->control = 0;
recCsdb->repeatCount = 1;
recCsdb->data[0] = TX_MSG_LABEL;
recCsdb->data[1] = TX_MSG_SI;
for (i=2; i<BLOCKCOUNT; i++)
recCsdb->data[i]= (uint8)i;
recCsdb->reserved=0;
rc = mxfCSDBTxPeriodicUpdateMsgWrite(txBuffer[1], 1, recCsdb);
}
// Run the scheduler, update records
if(!rc)
{
printf("Running periodic transmission, please wait...\n\r");
// Runs the schedule now
rc = mxfTxPeriodicScheduleRun(schedule);
}
// Wait 10 seconds
if(!rc)
{
mxfSleep(10000);
rc = mxfTxPeriodicScheduleFree(schedule);
}
if(recCsdb)
free(recCsdb)
...
Updated 10/23/2023