MX Foundation 4
ar717.c
/*****************************************************************************
//
// File:
// ar717.c
//
// Copyright (c) MAX Technologies Inc. 1988-2015, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the basic usage of ARINC 717 channel class
// for transmission and reception.
//
// Hardware requirements:
// - MAXT FlexMulti or 500 series carrier with IPM-MULTI with A717 option
// - Loopback between first TX and RX ARINC 717 channels if internal loopback is not used
//
*****************************************************************************/
#include "../../inc/example.h"
#define MAX_TX_SUBFRAMES_TO_TRANSMIT 4 //minimum 4 to have at least one full frame.
#define LOCAL
#define LOOPBACK
uint32 initHandler(HMXF_SERVER server, uint64 deviceIndex, uint64 moduleIndex, uint64 channelIndex, uint64 attrib, uint64* value);
int main(void)
{
uint32 rc;
HMXF_SERVER server=0;
HMXF_DEVICE device=0;
HMXF_CHANNEL rxChannel=0;
HMXF_CHANNEL txChannel=0;
HMXF_BUFFER rxBuffer=0;
HMXF_BUFFER txBuffer=0;
uint64 channelCount=0;
size_t txBufferSize=0;
size_t rxBufferSize=0;
MXF_A717_DATAREC* rxHostBuffer=0;
MXF_A717_DATAREC* txHostBuffer=0;
uint64 rxAcqStatus=0;
uint64 msgCount=0;
uint64 byteCount=0;
uint64 data;
uint64 word, subframeSize;
uint64 encoding;
// Connects to services and initialize environment
#ifdef LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", TRUE, &server);
#endif
if(rc!=MAXT_SUCCESS)
{
printf("Failed to connect; rc=0x%08x", rc);
getchar();
return 0;
}
// Initializes init callback handler to set first TX and RX channel to A717
if (!rc)
rc = mxfSystemInitAttributeUint64CallbackHandler(server, &initHandler);
// Initializes MX Foundation library
if (!rc)
{
printf("Starting ...\n");
rc = mxfSystemInit(server);
}
// Gets the device handle
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
// Gets handle of first A717 RX channel
if(!rc)
rc = mxfChannelAllGet(server, MXF_CLASS_A717, MXF_SCLASS_RX_CHANNEL, 0, 1, &channelCount, &rxChannel);
// Gets handle of first A717 TX channel
if (!rc && channelCount)
rc = mxfChannelAllGet(server, MXF_CLASS_A717, MXF_SCLASS_TX_CHANNEL, 0, 1, &channelCount, &txChannel);
// If channel not found, returns an error
if(!rc && !channelCount)
rc = MAXT_ERROR_NOT_FOUND;
// Enables loopback
#ifdef LOOPBACK
if(!rc)
rc = mxfAttributeUint64Set(rxChannel, KMXF_A717_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
#if (MAX_TX_SUBFRAMES_TO_TRANSMIT < 4)
if(!rc)
printf("Number of subframes to transmit less than 4: synchronization will not occur.\n");
#endif
// Allocates buffer for tx data
if(!rc)
{
txBufferSize = MAX_TX_SUBFRAMES_TO_TRANSMIT*sizeof(MXF_A717_DATAREC);
// Allocates TX Aperiodic static buffer for HIGH priority queue
rc=mxfTxAperiodicBufferAlloc(txChannel, MXF_TXAPERIODIC_PRIORITY_HIGH, txBufferSize, &txBuffer, NULL);
// Host buffer allocation
if(!rc)
{
txHostBuffer = (MXF_A717_DATAREC*) calloc(1, txBufferSize);
if(!txHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Allocates buffer for rx data
if(!rc)
{
rxBufferSize = MAX_TX_SUBFRAMES_TO_TRANSMIT*sizeof(MXF_A717_DATAREC);
// Allocates RX acquisition static buffer
rc=mxfRxAcqBufferAlloc(rxChannel, rxBufferSize, &rxBuffer, NULL);
// Host buffer allocation
if(!rc)
{
rxHostBuffer = (MXF_A717_DATAREC*) calloc(1, rxBufferSize);
if(!rxHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Sets timebase to RTC nsec
if(!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Sets RX & TX channels subframe size to 128 words
subframeSize = 128;
if(!rc)
rc=mxfAttributeUint64Set(rxChannel, KMXF_A717_SUBFRAME_SIZE, subframeSize);
if(!rc)
rc=mxfAttributeUint64Set(txChannel, KMXF_A717_SUBFRAME_SIZE, subframeSize);
encoding = VMXF_A717_BIT_ENCODING_HARVARDBIPHASE; // or VMXF_A717_BIT_ENCODING_BIPOLAR_RZ
// Sets RX & TX channels bit encoding
if(!rc)
rc=mxfAttributeUint64Set(rxChannel, KMXF_A717_BIT_ENCODING, encoding);
if(!rc)
rc=mxfAttributeUint64Set(txChannel, KMXF_A717_BIT_ENCODING, encoding);
// Starts acquisition
if(!rc)
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
if(!rc)
{
// Prepares string array
rec = txHostBuffer;
for(data=0; data<MAX_TX_SUBFRAMES_TO_TRANSMIT; data++)
{
rec->timeTag = 0;
rec->control = 0;
rec->dataSize = 2 * (uint32)subframeSize; // 16 bits per word in subframe
rec->repeatCount = 1;
rec->reserved = 0;
for(word=0; word < subframeSize ; word++)
{
if (word == 0)
{
//1st word of each subframe has to be a sync word
// sync words are:
// - 0x247 for subframe #0
// - 0x5B8 for subframe #1
// - 0xA47 for subframe #2
// - 0xDB8 for subframe #3
switch (data%4)
{
case 0:
rec->data[word] = 0x247;
break;
case 1:
rec->data[word] = 0x5B8;
break;
case 2:
rec->data[word] = 0xA47;
break;
case 3:
rec->data[word] = 0xDB8;
break;
default:
break;
}
}
else
rec->data[word] = (uint16)(0x11*word);
}
rc = mxfA717NextDataRecordPtrGet(rec, &rec);
}
}
if(!rc)
{
printf("Transmitting ...\n");
// Transmits records with default option
rc = mxfA717TxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, MAX_TX_SUBFRAMES_TO_TRANSMIT, txHostBuffer);
}
if(!rc)
mxfSleep((MAX_TX_SUBFRAMES_TO_TRANSMIT+1) * 1000); // 1 second per subframe + 1 second to be sure to exceed the minimum duration to wait.
if(!rc)
{
printf("Receiving ...\n");
// Reads rx buffer
rc = mxfA717RxAcqRead(rxBuffer, 0, rxBufferSize, &rxAcqStatus, &msgCount, &byteCount, rxHostBuffer);
}
if(!rc)
printf("String received count = %llu \n", msgCount);
if(!rc)
{
// Displays received strings
rec = rxHostBuffer;
for(data=0; data<msgCount && !rc; data++)
{
printf("\n%02llu: Timetag=%012llu, Size=%u words\n", data, rec->timeTag, (rec->dataSize)/2);
for(word=0; word < rec->dataSize/2; word++)
printf("%03X ", rec->data[word]);
printf("\n");
}
}
// Stops acquisition
if(!rc)
rc = mxfRxAcqStop(rxBuffer);
// Frees device and host buffers
if(rxBuffer)
mxfRxAcqBufferFree(rxBuffer);
if(txBuffer)
if(txHostBuffer)
free(txHostBuffer);
if(rxHostBuffer)
free(rxHostBuffer);
if(rc)
{
char errorString[200];
if(mxfSystemErrorStringGet(server, rc, sizeof(errorString), errorString))
sprintf (errorString,"ERROR # 0x%X", rc);
printf("%s\n\r", errorString);
}
printf("Terminating ...\n");
// Unloads MX Foundation library
// Disconnects from MX Foundation library
printf("\nPress a key to terminate\n");
getchar();
return rc;
}
uint32 initHandler(HMXF_SERVER server, uint64 deviceIndex, uint64 moduleIndex, uint64 channelIndex, uint64 attrib, uint64* value)
{
HMXF_DEVICE device;
MXF_DEVICE_INFO deviceInfo;
uint32 rc;
server=server;
deviceIndex=deviceIndex;
if(attrib == KMXF_CHANNEL_CLASS)
{
rc = mxfSystemDeviceGet(server, deviceIndex, &device);
if (!rc)
rc = mxfDeviceInfoGet(device, &deviceInfo);
if(!rc && (deviceInfo.modules[moduleIndex].type == MXF_MODULE_MULTI_EH || deviceInfo.modules[moduleIndex].type == MXF_MODULE_MULTI))
{
// Sets first TX and RX channels to A717
if ((channelIndex == 0) || (channelIndex == deviceInfo.modules[moduleIndex].txCount))
{
*value = MXF_CLASS_A717;
return TRUE;
}
}
}
return FALSE;
}
Updated 03/30/2022