MX Foundation 4
ar629_block_mode.c
/*****************************************************************************
//
// File:
// ar629_block_mode.c
//
// Copyright (c) MAX Technologies Inc. 1988-2015, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This demo shows how to set a basic periodic transmission in block
// mode and set the ARINC 629 data. 3 messages for a total of 6 wordstrings
// are transmitted. Two wordstrings have CRC and FC enabled.
// Acquisition is also performed with CRC verification enabled for two labels.
//
// Hardware Requirements:
// - MAXT FlexMulti-629.
//
*****************************************************************************/
#include "example.h"
//#define TTL
//#define LOCAL
#define MAX_RX_RECORDS_TO_RECEIVE 1000
#define RX_BUFFER_SIZE MAX_RX_RECORDS_TO_RECEIVE*sizeof(MXF_A629_DATAREC)
#define MAX_TX_RECORDS_TO_TRANSMIT 1
#define TX_BUFFER_SIZE MAX_TX_RECORDS_TO_TRANSMIT*sizeof(MXF_A629_DATAREC)
//***************************************************************************
//
// Main()
//
//***************************************************************************
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
uint64 count=0;
HMXF_CHANNEL rxChannel=0;
HMXF_CHANNEL txChannel=0;
HMXF_BUFFER rxBuffer=0;
HMXF_BUFFER txBuffer[6]={0,0,0,0,0,0};
MXF_A629_DATAREC *hostBuffer=NULL;
MXF_A629_DATAREC *rec629=NULL;
uint64 dev, mod, port;
uint64 index, word;
uint64 status, msgsCount, bytesCount, indexBuffer;
// Connect to services local or remote
#ifdef LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
#endif
if (rc)
{
printf("Failed to connect; rc=0x%08x", rc);
printf("\nPress a key to terminate\n");
getchar();
return 0;
}
// Initialize the server
printf("\nStarting\n");
rc = mxfSystemInit(server);
// Get the first device handle
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
if (!rc)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_A629MRT_EH, 1, &count, &module);
// Obtain the first ARINC 629 Protocol RX channel (RX logical #0)
if (!rc && count)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_A629, MXF_SCLASS_RX_CHANNEL, 1, &count, &rxChannel);
// Obtain the first ARINC 629 Protocol TX channel (TX logical #0)
if (!rc && count)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_A629, MXF_SCLASS_TX_CHANNEL, 1, &count, &txChannel);
// If module or channel not found, return an error
if(!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
// Set timebase to 64-bit nanoseconds
if (!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Get the physical port location
if (!rc)
{
rc = mxfChannelLocationGet(rxChannel, &dev, &mod, &port);
if (!rc)
printf("Acquisition Channel (RX) location=%llu.%llu.%llu\n", dev, mod, port);
}
if (!rc)
{
rc = mxfChannelLocationGet(txChannel, &dev, &mod, &port);
if (!rc)
printf("Transmitter Channel (TX) location=%llu.%llu.%llu\n", dev, mod, port);
}
// Set interface to SIM or TTL
#ifdef TTL
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_INTERFACE, VMXF_A629_MODULE_INTERFACE_TTL);
#else
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_INTERFACE, VMXF_A629_MODULE_INTERFACE_SIM);
#endif
// Allocate RX acquisition buffer
if (!rc)
rc = mxfRxAcqBufferAlloc(rxChannel, RX_BUFFER_SIZE, &rxBuffer, NULL);
// Allocate six TX Periodic Update Message buffer
for(index=0; index<6 && !rc; index++)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(txChannel, index, TX_BUFFER_SIZE, &txBuffer[index], NULL);
// Allocate host buffer
if (!rc)
{
hostBuffer = (MXF_A629_DATAREC*)malloc(max(RX_BUFFER_SIZE, TX_BUFFER_SIZE));
if (!hostBuffer)
rc = MAXT_ERROR_MEM;
}
// Add CRC verification for label 0x4 and 0x5
if(!rc)
{
rc = mxfA629RxMsgCrcEnableSet(rxChannel, 0x4, 4, TRUE);
if(!rc)
rc = mxfA629RxMsgCrcEnableSet(rxChannel, 0x5, 4, TRUE);
}
// Start the acquisition process
if (!rc)
rc = mxfRxAcqModeSet(rxBuffer, MXF_RXACQ_MODE_LINEAR);
if (!rc)
{
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
if (!rc)
printf("\nAcquisition started\n\r");
}
//Disable the CID in XPP
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_XPP_CID_ENABLE, FALSE);
//Set the TI to 25 msec
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_TI, 25000000);
//Set the SG to 16
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_SG, VMXF_A629_MODULE_SG_16);
//Set the TG to 4
if(!rc)
rc = mxfAttributeUint64Set(txChannel, KMXF_A629_RT_TG, 4);
//Set the CID to 4
if(!rc)
rc = mxfAttributeUint64Set(txChannel, KMXF_A629_RT_CID, 4);
//Clear the major frame
if(!rc)
rc = mxfTxPeriodicMajorFrameClear(txChannel, 0);
//--- Set the minor frame #0 with 3 WordStrings --//
if(!rc)
{
memset(minorFrame, 0, sizeof(minorFrame));
//WordString #0 : Label 0x1, CID 0x4
minorFrame[0].buffer = txBuffer[0];
minorFrame[0].label = 0x1;
minorFrame[0].cid = 0;
minorFrame[0].length = 1;
//WordString #1 : Label 0x2, CID 0x4
minorFrame[1].buffer = txBuffer[1];
minorFrame[1].label = 0x2;
minorFrame[1].cid = 0;
minorFrame[1].length = 2;
//WordString #2 : Label 0x3, CID 0x4
minorFrame[2].buffer = txBuffer[2];
minorFrame[2].label = 0x3;
minorFrame[2].cid = 0;
minorFrame[2].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(txChannel, 0, 0, 3, minorFrame);
}
//------------------------------------------------//
//--- Set the minor frame #1 with 2 WordStrings --//
if(!rc)
{
//WordString #0 : Label 0x4, CID 0x4
minorFrame[0].buffer = txBuffer[3];
minorFrame[0].label = 0x4;
minorFrame[0].cid = 0;
minorFrame[0].length = 4;
minorFrame[0].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_CRC_ENABLE;
//WordString #1 : Label 0x5, CID 0x4
minorFrame[1].buffer = txBuffer[4];
minorFrame[1].label = 0x5;
minorFrame[1].cid = 0;
minorFrame[1].length = 5;
minorFrame[1].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_CRC_ENABLE;
rc = mxfA629TxPeriodicMajorFrameSet(txChannel, 0, 1, 2, minorFrame);
// Add a FC to label 0x4 and 0x5
if(!rc)
{
fc.enable = TRUE;
fc.position = 1;
fc.mask = 0x00f0;
fc.modulo = 1;
rc = mxfA629MsgFreshnessCounterSet(txBuffer[3], &fc);
if(!rc)
rc = mxfA629MsgFreshnessCounterSet(txBuffer[4], &fc);
}
}
//------------------------------------------------//
//--- Set the minor frame #2 with 1 WordString --//
if(!rc)
{
//WordString #0 : Label 0x6, CID 0x4
minorFrame[0].buffer = txBuffer[5];
minorFrame[0].label = 0x6;
minorFrame[0].cid = 0;
minorFrame[0].length = 6;
minorFrame[0].options = 0;
rc = mxfA629TxPeriodicMajorFrameSet(txChannel, 0, 2, 1, minorFrame);
}
//--- Set default data for label 0x1, CID 0x4 ---//
if(!rc)
{
memset(&txRec629, 0, sizeof(txRec629));
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 514;
txRec629.data[0] = 0;
txRec629.data[1] = 0x1111;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[0], 1, &txRec629);
}
//------------------------------------------------//
//--- Set default data for label 0x2, CID 0x4 ---//
if(!rc)
{
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 6;
txRec629.data[0] = 0;
txRec629.data[1] = 0x2222;
txRec629.data[2] = 0x2222;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[1], 1, &txRec629);
}
//------------------------------------------------//
//--- Set default data for label 0x3, CID 0x4 ---//
if(!rc)
{
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 8;
txRec629.data[0] = 0;
txRec629.data[1] = 0x3333;
txRec629.data[2] = 0x3333;
txRec629.data[3] = 0x3333;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[2], 1, &txRec629);
}
//------------------------------------------------//
//--- Set default data for label 0x4, CID 0x4 ---//
if(!rc)
{
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 10;
txRec629.data[0] = 0;
txRec629.data[1] = 0x4444;
txRec629.data[2] = 0x4444;
txRec629.data[3] = 0x4444;
txRec629.data[4] = 0x4444;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[3], 1, &txRec629);
}
//------------------------------------------------//
//--- Set default data for label 0x5, CID 0x4 ---//
if(!rc)
{
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 12;
txRec629.data[0] = 0;
txRec629.data[1] = 0x5555;
txRec629.data[2] = 0x5555;
txRec629.data[3] = 0x5555;
txRec629.data[4] = 0x5555;
txRec629.data[5] = 0x5555;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[4], 1, &txRec629);
}
//------------------------------------------------//
//--- Set default data for label 0x6, CID 0x4 ---//
if(!rc)
{
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 14;
txRec629.data[0] = 0;
txRec629.data[1] = 0x6666;
txRec629.data[2] = 0x6666;
txRec629.data[3] = 0x6666;
txRec629.data[4] = 0x6666;
txRec629.data[5] = 0x6666;
txRec629.data[6] = 0x6666;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[5], 1, &txRec629);
}
//------------------------------------------------//
//Start the major frame in the Block mode
if(!rc)
{
majorProperties.mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_BLOCK;
majorProperties.reserved = 0;
rc = mxfA629TxPeriodicMajorFrameStart(txChannel, 0, &majorProperties);
}
//Waiting 2 seconds. Allow major frame to run a little bit.
if(!rc)
mxfSleep(2000);
//Stop the major frame
if(!rc)
rc = mxfTxPeriodicMajorFrameStop(txChannel, 0, 0);
// Stop acquisition and read data
if (!rc)
rc = mxfRxAcqStop(rxBuffer);
if (!rc)
{
rc = mxfA629RxAcqRead(rxBuffer, 0, RX_BUFFER_SIZE, &status, &msgsCount, &bytesCount, hostBuffer);
if (!rc)
{
// Display received messages
rec629 = hostBuffer;
for(index=0; index<msgsCount && !rc; index++)
{
printf(" %02llu: Timetag=%012llu, Size=%u", index, rec629->timeTag, rec629->dataSize);
if(rec629->control & MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR)
printf(" CRC error");
if(rec629->control & MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR)
printf(" Data sync error");
if(rec629->control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR|MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR))
printf(" Manchester error");
if(rec629->control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR|MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR))
printf(" Parity error");
if(rec629->control & MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR)
printf(" End of String error");
printf("\n Data=");
for(word=0; word<rec629->dataSize/2; word++)
printf("%04X ", rec629->data[word]);
printf("\n");
mxfA629NextDataRecordPtrGet(rec629, &rec629);
}
}
}
// Catch any previous error
if (rc)
{
char buffer[256];
rc = mxfSystemErrorStringGet(server, rc, sizeof(buffer), buffer);
printf("%s\n", buffer);
}
printf("\nTerminating\n");
// Free all buffers and terminate
if (rxBuffer)
mxfRxAcqBufferFree(rxBuffer);
for (indexBuffer = 0; indexBuffer < 6; indexBuffer++)
{
if (txBuffer[indexBuffer])
mxfTxPeriodicUpdateMsgBufferFree(txBuffer[indexBuffer]);
}
if (hostBuffer)
free(hostBuffer);
printf("\nPress enter to terminate\n");
getchar();
return rc;
}
Updated 10/23/2023