using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace ar429_example
{
class ar429_embedded_timer
{
const int BUFFER_SIZE = 4096;
const int USER_COMMAND_ID_START_TIMER = 0;
const int USER_COMMAND_ID_STOP_TIMER = 1;
static void Main(string[] args)
{
UInt32 rc;
UInt64 server;
UInt64 device = 0;
var module = new UInt64[1];
UInt64 count = 0;
var hTx429 = new UInt64[1];
var hRx429 = new UInt64[1];
UInt64 tx429Buffer = 0;
UInt64 rx429Buffer = 0;
UInt64 dev, mod = 0, port = 0;
var parameters = new UInt32[3];
UInt64 stopTime;
IntPtr rec429 = IntPtr.Zero;
UInt64 deviceType = 0;
UInt64 moduleType = 0;
#if LOCAL
#else
#endif
if (rc != MAXT_SUCCESS)
{
Console.Write("Failed to connect; rc=0x{0:x8}", rc);
Console.Write("\nPress a key to terminate\n");
Console.ReadKey();
return;
}
Console.Write("\nStarting\n");
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if ((rc == MAXT_SUCCESS) && (count == 0))
}
if (rc == MAXT_SUCCESS && count > 0)
if (rc == MAXT_SUCCESS && count > 0)
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
#if LOOPBACK
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
try
{
rec429 = Marshal.AllocHGlobal(BUFFER_SIZE);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.Write("Acquisition started\n\r");
}
if (rc == MAXT_SUCCESS)
{
if((moduleType == MXF_MODULE_FLEX429) || (deviceType == MXF_DEVICE_FMOB429_PLUS))
else
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
parameters[0] = (UInt32)mod;
parameters[1] = (UInt32)port;
parameters[2] = (uint)MXF_TXAPERIODIC_PRIORITY_HIGH;
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.Write("Acquisition stopped at {0}\n\r", stopTime);
}
if (rc == MAXT_SUCCESS)
rc = RX429ReadAcquisitionData(rx429Buffer, rec429);
if (rc != MAXT_SUCCESS)
{
StringBuilder buffer = new StringBuilder(256);
{
buffer.Clear();
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
}
Console.Write(buffer + "\n\r");
}
if (rx429Buffer > 0)
if (tx429Buffer > 0)
Console.Write("Stopping\n");
if (rec429 != IntPtr.Zero)
Marshal.FreeHGlobal(rec429);
Console.Write("\nPress enter to terminate\n");
Console.ReadKey();
return;
}
private static UInt32 EmbeddedMemoryAllocationHandler(UInt64 server, UInt64 cardIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
UInt64 embedded_memory_size = 65536;
if (attrib == KMXF_DEVICE_EMBEDDED_CODEANDDATA_SIZE)
{
Console.Write("Reserving {0}K of memory for embedded application\n", embedded_memory_size / 1024);
value = embedded_memory_size;
return 1;
}
return MAXT_SUCCESS;
}
private static UInt32 RX429ReadAcquisitionData(UInt64 rxBuffer, IntPtr recPtr429)
{
IntPtr recPtr = recPtr429;
UInt64 status, msgsCount, bytesCount;
UInt64 label, sdi, data, ssm, parity;
UInt64 j;
UInt32 rc;
rc =
mxfA429RxAcqRead(rxBuffer, 0, BUFFER_SIZE, out status, out msgsCount, out bytesCount, recPtr429);
recPtr = recPtr429;
for (j = 0; j < msgsCount && rc == MAXT_SUCCESS; j++)
{
Console.Write("{0:00}: Timetag {1} - ARINC word=[{2},{3},{4:X5},{5},{6:000}]\n",
j, rec.
timeTag, parity, ssm, data, sdi, label);
}
return rc;
}
}
}