MX Foundation 4
Updating Periodic Messages

While a schedule runs, the ARINC 708 data can be updated asynchronously by the main application using the mxfA708TxPeriodicUpdateMsgWrite() function.

The next example shows how to use some functions for updating a transmission buffer.

Scheduling a Message

The program below shows how to define a single message with mxfTxPeriodicScheduleSingleMsgAdd() for scheduling that will be later updated while the schedule runs.

The example in the next section shows how to update the records dynamically.

ar708_buffer_threshold.c

uint32 rc;
HMXF_SCHED schedule=0;
HMXF_SCHED_MSG msgSched;
HMXF_CHANNEL txChannel;
HMXF_BUFFER txBuffer=0;
MXF_A708_DATAREC *txHostBuffer=NULL;
size_t txBufferSize;
...
// Allocates buffer for tx data
if(!rc)
{
txBufferSize = 720*sizeof(MXF_A708_DATAREC);
// Allocate TX Periodic Update buffer
rc = mxfTxPeriodicUpdateMsgBufferAlloc(txChannel, 0, txBufferSize, &txBuffer, NULL);
// Host buffer allocation
if(!rc)
{
txHostBuffer = (MXF_A708_DATAREC*)calloc(1, txBufferSize);
if(!txHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Sets the Periodic Scheduler
if(!rc)
rc = mxfTxPeriodicScheduleNew(txChannel, &schedule);
// Sets scheduling values: Rate=5 ms, Phase=0 us
if(!rc)
rc = mxfTxPeriodicScheduleSingleMsgAdd(schedule, 5000000, 0, txBuffer, &msgSched);
// Runs the schedule
if(!rc)
rc = mxfTxPeriodicScheduleRun(schedule);
// Sends messages for 2 seconds
if(!rc)
{
printf("Running periodic transmission...\n\r");
mxfSleep(2000);
rc = mxfTxPeriodicScheduleFree(schedule);
}
if(txHostBuffer)
free(txHostBuffer)
...

Updating the buffer

The value of the ARINC 708 data sent can be updated while a background schedule runs.

The example below shows how the mxfA708TxPeriodicUpdateMsgWrite() function can be used to perform the update operation.

The update loop changes every 5ms and stops after two seconds.

ar708_buffer_threshold.c

#define TXALMOSTFULL 100
uint32 rc=0;
uint16 i, bin;
MXF_A708_DATAREC *recPtr=txHostBuffer;
static uint32 TXAsyncEvents=0;
static uint16 scanAngle=0;
static uint16 binValue=0;
...
// Refills the FIFO
for(i=0; !rc && i<TXALMOSTFULL; i++, scanAngle++)
{
if(scanAngle > 720)
{
scanAngle = 0;
binValue++;
}
recPtr->timeTag=0;
recPtr->control=0;
recPtr->dataSize = 200; //200 bytes corresponds to 1600 bits (see ARINC 708 specification)
recPtr->repeatCount=1;
recPtr->manchesterBitErr = 0;
recPtr->data[0] = 0;
recPtr->data[1] = 0;
recPtr->data[2] = 0;
recPtr->data[3] = 0;
setLabel(recPtr, 055); // Bits 0-7 : Label 055
setCtrlAccept(recPtr, 0x3); // Bits 8-9 : Cntrol Accept
setMode(recPtr, 1); // Mode Set 1
setTilt(recPtr, 0);
setGain(recPtr, -16);
setRange(recPtr, 80);
setDataAccept(recPtr, 3);
setScanAngle(recPtr, ((double)scanAngle*0.25)+270);
for(bin=1; bin<=512; bin++)
{
setBin(recPtr, bin, binValue);
}
if(!rc)
rc = mxfA708NextDataRecordPtrGet(recPtr, &recPtr);
}
// Add more data to the buffer
if(!rc)
rc = mxfA708TxPeriodicUpdateMsgWrite(buffer, TXALMOSTFULL, txHostBuffer);
if(rc)
printf("Periodic Update failed; rc=0x%08x\n", rc);
else
printf("\nAsync Event %d - Writing %d records\n", ++TXAsyncEvents, i);
...
Updated 10/23/2023