#include "example.h"
#define TEST_DATASIZE 64
#define DATARECS_BUFFER_SIZE_MAX 64*1024
#define LOOPBACK_MODE
#define SRC_IP_ADRS "10.0.0.111"
#define SRC_UDP_PORT 1234
#define DST_IP_ADRS "10.0.0.222"
#define DST_UDP_PORT 5678
uint32 asyncEventHandler(HMXF_ASYNCEVENT asyncEvent, void *param);
int main(void)
{
HMXF_SERVER server = 0;
HMXF_PORT portTx = 0;
HMXF_PORT portRx = 0;
HMXF_VL vlTx = 0, vlRx = 0;
HMXF_BUFFER rxBuffer = 0, rxBufferRaw=0;
HMXF_MODULE module = 0;
HMXF_DEVICE device = 0;
HMXF_CHANNEL phyChn = 0;
HMXF_ASYNCEVENT asyncEvent = 0;
uint32 srcIpAdrs = 0, dstIpAdrs = 0;
uint64 status;
uint64 usedBytes, freeBytes;
uint64 msgCount = 0;
uint64 acqStopTime;
uint32 recordIdx, dataIdx;
uint32 maxTxRecords = 4;
uint32 vlid = 100;
uint32 rc;
uint64 count = 0;
#ifndef LOCAL
char szAddress[20];
#endif
printf("\nARINC664 Error Injection / Detection Demo\n\n");
#ifdef LOCAL
#else
printf("Enter address of remote MXF4 server (IP or USB)\n\n");
printf(" xxx.xxx.xxx.xxx or usb\n\n");
fgets(szAddress, sizeof(szAddress), stdin);
szAddress[strcspn(szAddress, "\n")] = '\0';
if (!strcmp(szAddress, "usb"))
{
if (!rc && count)
if (!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
if (rc)
printf("No USB device detected; rc=0x%08x\n", rc);
}
else
{
if (rc)
printf("Error connecting to %s; rc=0x%08x\n", szAddress, rc);
}
#endif
if (rc)
{
printf("Failed to connect; rc=0x%08x\n", rc);
printf("\nPress a key to terminate\n");
getchar();
return 0;
}
if (!rc)
if (!rc)
if (!rc && count)
if (!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
#ifdef LOOPBACK
if (!rc)
#endif
if (!rc)
if (!rc)
if (!rc)
{
vlParam.
frameType = MXF_A664_FRAME_TYPE_ARINC664;
}
if (!rc)
{
inet_pton(AF_INET, SRC_IP_ADRS, &srcIpAdrs);
srcIpAdrs = ntohl(srcIpAdrs);
inet_pton(AF_INET, DST_IP_ADRS, &dstIpAdrs);
dstIpAdrs = ntohl(dstIpAdrs);
portParam.
portType = MXF_A664_PORT_TYPE_COM;
portParam.
family = MXF_A664_PORT_FAMILY_IPV4;
portParam.
mode = MXF_A664_PORT_MODE_QUEUING;
}
if (!rc)
{
txRec = malloc(DATARECS_BUFFER_SIZE_MAX);
memset(txRec, 0, DATARECS_BUFFER_SIZE_MAX);
if (!txRec)
rc = MAXT_ERROR_MEM;
}
if (!rc)
{
vlParam.
frameType = MXF_A664_FRAME_TYPE_ARINC664;
}
if (!rc)
{
portParam.
portType = MXF_A664_PORT_TYPE_COM;
portParam.
family = MXF_A664_PORT_FAMILY_IPV4;
portParam.
mode = MXF_A664_PORT_MODE_QUEUING;
}
if (!rc)
if (!rc)
{
rxRec = malloc(DATARECS_BUFFER_SIZE_MAX);
memset(rxRec, 0, DATARECS_BUFFER_SIZE_MAX);
if (!rxRec)
rc = MAXT_ERROR_MEM;
}
if (!rc)
if (!rc)
{
memset(&errorInjectionTx, 0, sizeof(errorInjectionTx));
errorInjectionTx.
port = MXF_A664_NETSELECT_ALL;
errorInjectionTx.
error[0].
id = MXF_A664_ERRORID_VL_FRAME_MASK_AND;
errorInjectionTx.
error[0].
offset = MXF_A664_FRAME_HEADER_OFFSET_IP;
}
if (!rc)
if (!rc)
{
memset(&asyncEventInfoRx, 0, sizeof(asyncEventInfoRx));
asyncEventInfoRx.
condID = MXF_ASYNCEVENT_COND_RX_ERROR;
}
if (!rc)
if (!rc)
if (!rc)
if (!rc)
{
if (!rc && (status & MXF_RXACQ_STATUS_RUNNING))
printf("Acquisition Running\n\n");
}
for (recordIdx = 0, data = txRec; recordIdx < maxTxRecords && !rc; recordIdx++)
{
data->
control = recordIdx % 2 ? 0 : MXF_A664_TX_REC_CTRL_ERROR_INJ;
for (dataIdx = 0; dataIdx < TEST_DATASIZE; dataIdx++)
data->
data[dataIdx] = (uint8)((dataIdx + ((recordIdx*TEST_DATASIZE) & 0xff)));
}
if (!rc)
{
printf("%llu frames transmitted\n\n", count);
}
if (!rc)
rc = readAcquisitionData(rxBuffer, rxRec);
if (!rc)
rc = readAcquisitionData(rxBufferRaw, rxRec);
if (!rc)
if (!rc)
if (!rc)
if (!rc)
if (!rc)
{
if (!rc && status & MXF_RXACQ_STATUS_STOPPED)
{
if (!rc)
printf("\nAcquisition stopped at %llu\n", acqStopTime);
}
}
if (!rc)
if (!rc)
if (!rc)
if (!rc)
if (!rc)
if (txRec)
free(txRec);
if (rxRec)
free(rxRec);
printf("\n\nPress a key to terminate rc=0x%08x\n", rc);
getchar();
return rc;
}
uint32 asyncEventHandler(HMXF_ASYNCEVENT asyncEvent, void *param)
{
HMXF_HANDLE handle;
uint64 status;
uint64 index, pendingCnt;
uint32 rc = MAXT_SUCCESS;
( void )param;
for (index = 0; index<pendingCnt && !rc; index++)
{
switch (pendingList[index].condID)
{
case MXF_ASYNCEVENT_COND_RX_ERROR:
{
printf("RX ERR -> status (0x%llx)\n", status);
printf(" PORT Handle=0x%llx\n\n", handle);
break;
}
default:
printf("Unexpected Event Condition received\n");
break;
}
}
fflush(stdout);
return rc;
}
{
uint64 recordIdx, dataIdx;
uint64 status, msgsCount, bytesCount;
uint32 dataSize;
uint32 rc;
rc =
mxfA664RxAcqRead(rxBuffer, 0, DATARECS_BUFFER_SIZE_MAX, &status, &msgsCount, &bytesCount, rec664);
if (!rc)
printf("%lld records received\n\n", msgsCount);
for (recordIdx = 0; recordIdx < msgsCount && !rc; recordIdx++)
{
printf(
" %03llu: timeTag=%012llu, Size=%u", recordIdx, recPtr->
timeTag, recPtr->
dataSize);
printf("\n data=");
for (dataIdx = 0; dataIdx < dataSize; dataIdx++)
{
printf(
"%02X ", recPtr->
data[dataIdx]);
if (!((dataIdx + 1) % 8) && (dataIdx + 1 < recPtr->
dataSize))
printf("\n ");
}
printf("\n\n");
}
return rc;
}