#include "example.h"
#include <stdlib.h>
#define ar717_TX_SUBFRAMES_TO_TRANSMIT 8 //minimum 4 to have at least one full frame.
#define SUBFRAMESIZE 64
#define BNR 0
#define BCD 1
#define REAL 2
#define ar429_TX_RECORDS_TO_TRANSMIT 8
typedef struct
{
uint32 encoding429;
uint32 encoding717;
double dataRange;
uint64 bitRange429;
uint64 bitRange717;
}
strucEncoding;
uint32 ARINC717DataDefinition (uint64 label, uint64 *NbOfSubframes, uint64 *subframes, uint64 *NbOfWords, uint64 *words, strucEncoding *encoding);
uint32 changeBitEncoding(uint32 originBitEncoding, uint32 destinationBitEncoding, double dataRange, uint64 originBitRange, uint64 destinationBitRange, uint32 originData, uint32 *destinationData);
uint32 read717Acquisition(HMXF_BUFFER rxBuffer,
MXF_A717_DATAREC *rx717HostBuffer);
uint32 read429Acquisition(HMXF_BUFFER rxBuffer, uint64 *msgsCount429,
MXF_A429_DATAREC *rec429);
uint32 initHandler(HMXF_SERVER server, uint64 deviceIndex, uint64 moduleIndex, uint64 channelIndex, uint64 attrib, uint64* value);
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
HMXF_CHANNEL tx717=0, rx717=0;
HMXF_CHANNEL tx429=0, rx429=0;
HMXF_BUFFER txBuffer717=0, rxBuffer717=0;
HMXF_BUFFER txBuffer429=0, rxBuffer429=0;
uint64 count=0, msgsCount429=0;
#ifdef LOCAL
#else
#endif
if(rc!=MAXT_SUCCESS)
{
printf("Failed to connect; rc=0x%08x", rc);
printf("\nPress a key to terminate\n");
getchar();
return 0;
}
printf("Starting\n");
if (!rc)
if(!rc && count)
if (!rc && count)
if (!rc && count)
if (!rc && count)
if (!rc && count)
if(!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
if (!rc)
if(!rc)
{
if(!tx717HostBuffer)
rc = MAXT_ERROR_MEM;
}
if (!rc)
if(!rc)
{
if(!tx429HostBuffer)
rc = MAXT_ERROR_MEM;
}
if (!rc)
{
if(!rc)
{
if(!rx717HostBuffer)
rc = MAXT_ERROR_MEM;
}
}
if (!rc)
{
if(!rc)
{
if(!rx429HostBuffer)
rc = MAXT_ERROR_MEM;
}
}
if(!rc)
#ifdef LOOPBACK
if (!rc)
if (!rc)
#endif
#if (ar717_TX_SUBFRAMES_TO_TRANSMIT < 4)
if(!rc)
printf("\nNumber of subframes to transmit less than 4: synchronization will not occur.\n\n");
#endif
if(!rc)
if(!rc)
if(!rc)
if(!rc)
if(!rc)
if(!rc)
if (!rc)
{
if (!rc)
printf("\nA429 Acquisition started\n\r");
}
if (!rc)
{
if (!rc)
printf("\nA717 Acquisition started\n\r");
}
if(!rc)
rc = write429Msgs(txBuffer429, tx429HostBuffer);
if (!rc)
rc = read429Acquisition(rxBuffer429, &msgsCount429, rx429HostBuffer);
if (!msgsCount429)
{
rc = MAXT_ERROR_COUNT;
}
if(!rc)
rc = write717Msgs(txBuffer717, rx429HostBuffer, msgsCount429, tx717HostBuffer);
if (!rc)
rc = read717Acquisition(rxBuffer717, rx717HostBuffer);
if (!rc)
rc = writeEng(rx429HostBuffer, msgsCount429, rx717HostBuffer);
if(rc)
{
char buffer[256];
sprintf (buffer,"ERROR # 0x%08X", rc);
printf("%s\n\r", buffer);
}
if (rxBuffer429)
if (rxBuffer717)
if(txBuffer429)
if(txBuffer717)
printf("\nPress enter to terminate\n");
getchar();
return rc;
}
uint32 changeBitEncoding(uint32 originBitEncoding, uint32 destinationBitEncoding, double dataRange, uint64 originBitRange, uint64 destinationBitRange, uint32 originData, uint32 *destinationData)
{
double realData =0;
uint32 rc = MAXT_SUCCESS;
switch (originBitEncoding)
{
case BNR:
originData <<= 10;
break;
case BCD:
rc = MAXT_ERROR_NOT_SUPPORTED;
break;
case REAL:
realData = (double)originData;
break;
default:
rc = MAXT_ERROR_PARAM;
break;
}
switch (destinationBitEncoding)
{
case BNR:
*destinationData >>= 10;
break;
case BCD:
rc = MAXT_ERROR_NOT_SUPPORTED;
break;
case REAL:
*destinationData = (uint32)realData;
break;
default:
rc = MAXT_ERROR_PARAM;
break;
}
return rc;
}
{
uint64 label=0, sdi, data=0, ssm, parity;
uint32 rc = MAXT_SUCCESS, dataTemp=0;
uint64 iSubframe, iMsgs429, i, iWord;
uint64 NbOfSubframes=0, subframes[4] = {0}, NbOfWords=0, words[10] = {0};
strucEncoding encoding;
for (iMsgs429 = 0; iMsgs429 < msgsCount429 && !rc; iMsgs429++)
{
recPtr717 = rec717;
if (!rc)
if (!rc)
{
ARINC717DataDefinition (label, &NbOfSubframes, subframes, &NbOfWords, words, &encoding);
if (encoding.bitRange429 != encoding.bitRange717 || encoding.encoding429 != encoding.encoding717)
{
changeBitEncoding(encoding.encoding429, encoding.encoding717, encoding.dataRange, encoding.bitRange429, encoding.bitRange717, (uint32)data, &dataTemp);
data = dataTemp;
}
data >>= 7;
}
for(iSubframe=0; !rc && iSubframe<ar717_TX_SUBFRAMES_TO_TRANSMIT; iSubframe++)
{
recPtr717->
dataSize = 2 * (uint32)SUBFRAMESIZE;
for (i = 0; i < NbOfSubframes; i++)
{
if (iSubframe%4 == subframes[i]-1)
{
for (iWord = 0; iWord < NbOfWords; iWord++)
{
recPtr717->
data[words[iWord]-1] = (uint16)data;
}
}
}
switch (iSubframe%4)
{
case 0:
recPtr717->
data[0] = 0x247;
break;
case 1:
recPtr717->
data[0] = 0x5B8;
break;
case 2:
recPtr717->
data[0] = 0xA47;
break;
case 3:
recPtr717->
data[0] = 0xDB8;
break;
default:
break;
}
if(!rc)
}
}
return rc;
}
uint32 ARINC717DataDefinition (uint64 label, uint64 *NbOfSubframes, uint64 *subframes, uint64 *NbOfWords, uint64 *words, strucEncoding *encoding)
{
switch (label)
{
case 0101:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 19;
*NbOfSubframes = 4;
*NbOfWords = 1;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 180;
encoding->bitRange429 = 12;
encoding->bitRange717=12;
}
break;
case 0102:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 17;
*NbOfSubframes = 4;
*NbOfWords = 1;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 65536;
encoding->bitRange429 = 16;
encoding->bitRange717=12;
}
break;
case 0103:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 32;
*NbOfSubframes = 4;
*NbOfWords = 1;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 512;
encoding->bitRange429 = 11;
encoding->bitRange717=12;
}
break;
case 0104:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 11;
*NbOfSubframes = 4;
*NbOfWords = 1;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 16384;
encoding->bitRange429 = 10;
encoding->bitRange717=12;
}
break;
case 0320:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 9;
*NbOfSubframes = 4;
*NbOfWords = 1;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 180;
encoding->bitRange429 = 15;
encoding->bitRange717=12;
}
break;
case 0325:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 14;
words[1] = 46;
*NbOfSubframes = 4;
*NbOfWords = 2;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 180;
encoding->bitRange429 = 14;
encoding->bitRange717=12;
}
break;
case 0331:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 5;
words[1] = 21;
words[2] = 37;
words[3] = 53;
*NbOfSubframes = 4;
*NbOfWords = 4;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 2;
encoding->bitRange429 = 12;
encoding->bitRange717=12;
}
break;
case 0332:
{
subframes[0] = 1;
subframes[1] = 2;
subframes[2] = 3;
subframes[3] = 4;
words[0] = 6;
words[1] = 22;
words[2] = 38;
words[3] = 54;
*NbOfSubframes = 4;
*NbOfWords = 4;
encoding->encoding429 = BNR;
encoding->encoding717 = BNR;
encoding->dataRange = 2;
encoding->bitRange429 = 12;
encoding->bitRange717=12;
}
break;
default:
break;
}
return MAXT_SUCCESS;
}
{
uint32 rc=0;
printf("\nA717 Aperiodic transmission\n");
rc = Ar429ToAr717Bridge(rec429 , msgsCount429 , tx717HostBuffer);
if(!rc)
rc =
mxfA717TxAperiodicWrite(buffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, ar717_TX_SUBFRAMES_TO_TRANSMIT, tx717HostBuffer);
if (!rc)
mxfSleep((ar717_TX_SUBFRAMES_TO_TRANSMIT+1) * 1000);
if(rc)
printf("A717 transmit failed; rc=0x%08x\n", rc);
else
printf("\nWriting A717-records\n");
return rc;
}
{
uint32 label, sdi, data, ssm, parity;
double value;
uint32 record;
uint64 delay100ms = 100000;
uint32 rc;
uint64 msgCount, usedBytes, freeBytes;
printf("\nA429 Aperiodic transmission\n");
rec = rec429;
for (record=0; record<ar429_TX_RECORDS_TO_TRANSMIT; record++)
{
data = 0;
sdi = 1;
ssm = 0;
parity = VMXF_A429_PARITY_ODD;
switch (record)
{
case 0:
label = 0331;
value = 0.6501;
data >>= 10;
break;
case 1:
label = 0332;
value = -0.0141;
data >>= 10;
break;
case 2:
label = 0320;
value = 45.342;
data >>= 10;
break;
case 3:
label = 0104;
value = 231;
data >>= 10;
break;
case 4:
label = 0325;
value = 3.67;
data >>= 10;
break;
case 5:
label = 0102;
value = 13400;
data >>= 10;
break;
case 6:
label = 0101;
value = 48;
data >>= 10;
break;
case 7:
label = 0103;
value = 435.54;
data >>= 10;
break;
default:
label = 0001;
data = 0;
break;
}
}
rc =
mxfA429TxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, delay100ms, ar429_TX_RECORDS_TO_TRANSMIT, rec429);
do
{
if (rc)
return rc;
}while (msgCount!=0);
return rc;
}
uint32 read717Acquisition(HMXF_BUFFER rxBuffer,
MXF_A717_DATAREC *rx717HostBuffer)
{
uint64 status, msgsCount, bytesCount;
uint64 word, data;
uint32 rc;
printf("\nA717 reading\n");
rc =
mxfA717RxAcqRead(rxBuffer, 0, BUFFER_SIZE, &status, &msgsCount, &bytesCount, rx717HostBuffer);
if(!rc)
printf("String received count = %llu \n", msgsCount);
if(!rc)
{
recPtr = rx717HostBuffer;
for(data=0; data<msgsCount && !rc; data++)
{
printf(
"\n%02llu: Timetag=%012llu, Size=%u words\n", data, recPtr->
timeTag, (recPtr->
dataSize)/2);
for(word=0; word < SUBFRAMESIZE ; word++)
{
printf(
"%03X ", recPtr->
data[word]);
else
printf("--- ");
}
printf("\n");
}
}
if(rc)
printf("A717 acquisition read failed; rc=0x%08x\n", rc);
return rc;
}
uint32 read429Acquisition(HMXF_BUFFER rxBuffer, uint64 *msgsCount429,
MXF_A429_DATAREC *rec429)
{
uint64 status, bytesCount;
uint64 label, sdi, data, ssm, parity;
uint64 j;
uint32 rc;
printf("\nA429 reading\n");
rc =
mxfA429RxAcqRead(rxBuffer, 0, BUFFER_SIZE, &status, msgsCount429, &bytesCount, rec429);
for (j=0; j < (*msgsCount429) && !rc; j++)
{
if(!rc)
{
printf("%02llu: Timetag %llu - ARINC429 word=[%03llo,%lld,%05llX,%lld,%s]\n",
j, recPtr->
timeTag, label, sdi, data, ssm, (parity==VMXF_A429_PARITY_ODD)?
"ODD":
"EVEN");
if(!rc)
}
}
if(rc)
printf("A429 acquisition read failed; rc=0x%08x\n", rc);
return rc;
}
{
uint32 rc=MAXT_SUCCESS;
uint64 label, sdi, data429, ssm, parity;
uint64 iMsgCount, iSubframe;
uint64 data717, NbOfSubframes=0, subframes[4] = {0}, NbOfWords=0, words[10] = {0};
strucEncoding encoding;
double real429, real717;
int digits;
memset(&encoding, 0, sizeof(encoding));
printf("\n\n"
"---------------------------------------------------------------------\n"
"| Label | Value received in A429 | Value received in A717 |\n"
"---------------------------------------------------------------------\n");
for (iMsgCount = 0; iMsgCount < msgsCount429; iMsgCount++)
{
real429 = 0;
real717 = 0;
recPtr717 = rec717;
if (!rc)
ARINC717DataDefinition(label, &NbOfSubframes, subframes, &NbOfWords, words, &encoding);
if (!rc)
{
data429 <<= 10;
}
if (!rc)
{
for (iSubframe = 0; iSubframe < 4; iSubframe++)
{
if (iSubframe == subframes[0])
{
data717 = recPtr717->
data[words[0]-1];
data717 <<= 17;
if (!rc)
}
else
{
}
}
}
if (!rc)
if(fabs(real429)>=100000)
digits = 0;
else if(fabs(real429)>=10000)
digits = 1;
else if(fabs(real429)>=100)
digits = 2;
else
digits = 3;
printf("| %03llo | % 8.*f | % 8.*f |\n", label, digits, real429, digits, real717);
}
printf("---------------------------------------------------------------------\n");
return rc;
}
uint32 initHandler(HMXF_SERVER server, uint64 deviceIndex, uint64 moduleIndex, uint64 channelIndex, uint64 attrib, uint64* value)
{
HMXF_DEVICE device;
uint32 rc;
server=server;
deviceIndex=deviceIndex;
if(attrib == KMXF_CHANNEL_CLASS)
{
if (!rc)
if(!rc && (deviceInfo.
modules[moduleIndex].
type == MXF_MODULE_MULTI_EH))
{
if ((channelIndex == 0) || (channelIndex == deviceInfo.
modules[moduleIndex].
txCount))
{
*value = MXF_CLASS_A717;
return TRUE;
}
}
}
return FALSE;
}