MX Foundation 4
multi.cs
/*****************************************************************************
//
## File:
## multi.cs
//
// Copyright (c) MAX Technologies Inc. 1988-2019, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the basic usage of MIL-STD-1553, ARINC 429,
// ASYNC, CSDB, Discrete and HDLC for transmission and reception at the same time.
//
// Hardware requirements:
// - MAXT FlexMulti-1553, FlexMulti-629-4, FlexMulti-429 or FlexMulti-664
//
*****************************************************************************/
#define MIL1553
#define A429
#define CSDB
#define ASYNC
#define DISCRETE
#define HDLC
#define LOOPBACK
//#define LOCAL
using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace multi_example
{
class multi
{
const int ADDRESS = 5;
const int SUBADDRESS = 3;
const int ALMOST_FULL = 10;
const int ALMOST_EMPTY = 5;
const int MIL1553_IDX = 0;
const int A429_IDX = 1;
const int CSDB_IDX = 2;
const int ASYNC_IDX = 3;
const int DISCRETE_IDX = 4;
const int HDLC_IDX = 5;
const int BUFFER_SIZE = 1 * 1024 * 1024;// 1MB
const int RATE = 250 * 1000 * 1000; // 250msec
public static UInt64 discreteTimer = 0;
public struct EVENT_INFO_CHANNEL
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public UInt64[] txChannel;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public UInt64[] rxChannel;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public UInt64[] txBuffer;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public UInt64[] rxBuffer;
public UInt64 sched;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public MXF_ASYNCEVENT_CONDITION[] txCondition;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public MXF_ASYNCEVENT_CONDITION[] rxCondition;
}
public struct EVENT_INFO
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public EVENT_INFO_CHANNEL[] channel;
public IntPtr hostBuffer;
}
public static EVENT_INFO eventInfo = new EVENT_INFO();
/***************************************************************************************************************/
// Main
/***************************************************************************************************************/
static void Main(string[] args)
{
UInt32 rc;
UInt64 deviceCount = 0;
UInt64 server;
var device = new UInt64[1];
MXF_DEVICE_INFO deviceInfo;
UInt64 asyncEvent = 0;
eventInfo.channel = new EVENT_INFO_CHANNEL[6];
for (int i = 0; i < 6; i++)
{
eventInfo.channel[i].rxBuffer = new UInt64[1];
eventInfo.channel[i].rxChannel = new UInt64[1];
eventInfo.channel[i].txBuffer = new UInt64[1];
eventInfo.channel[i].txChannel = new UInt64[1];
eventInfo.channel[i].rxCondition = new MXF_ASYNCEVENT_CONDITION[1];
eventInfo.channel[i].txCondition = new MXF_ASYNCEVENT_CONDITION[1];
}
// Connect to MX Foundation library
#if LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", VMXF_DISABLE, out server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", 0, out server);
//rc = mxfServerConnect("10.10.10.140", "admin", "admin", 0, out server);
#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;
}
// Initialize the server
Console.Write("\nStarting\n");
// Get handle of first device
if (rc == MAXT_SUCCESS)
{
rc = mxfSystemDeviceAllGet(server, MXF_DEVICE_ALL, 1, out deviceCount, device);
if (rc == MAXT_SUCCESS && (deviceCount == 0))
rc = MAXT_ERROR_DEVICE_NOT_DETECTED;
}
// Get the device info to be used in init handler
if (rc == MAXT_SUCCESS)
rc = mxfDeviceInfoGet(device[0], out deviceInfo);
// initialize init callback handler to set IPM-ASYNC-EH first TX and RX channel to CSDB
// and IPM-MULTI-EH first TX and RX channel to HDLC
// Initialize MX Foundation library
if (rc == MAXT_SUCCESS)
rc = mxfSystemInit(server);
// Set timebase to RTC nsec
if (rc == MAXT_SUCCESS)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Host allocation
if (rc == MAXT_SUCCESS)
{
try
{
eventInfo.hostBuffer = Marshal.AllocHGlobal(BUFFER_SIZE);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
// Set asynchronous event handler
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventHandlerInit(server, eventHandler, IntPtr.Zero, out asyncEvent);
// Start transmission and acquisition 0;
#if MIL1553
if (rc == MAXT_SUCCESS)
{
rc = startMil1553(device[0], asyncEvent, ref eventInfo.channel[MIL1553_IDX]);
}
#endif
#if A429
if (rc == MAXT_SUCCESS)
rc = startA429(device[0], asyncEvent, ref eventInfo.channel[A429_IDX]);
#endif
#if CSDB
if (rc == MAXT_SUCCESS)
rc = startCSDB(device[0], asyncEvent, ref eventInfo.channel[CSDB_IDX]);
#endif
#if ASYNC
if (rc == MAXT_SUCCESS)
rc = startASYNC(device[0], asyncEvent, ref eventInfo.channel[ASYNC_IDX]);
#endif
#if DISCRETE
if (rc == MAXT_SUCCESS)
rc = startDiscrete(device[0], asyncEvent, ref eventInfo.channel[DISCRETE_IDX]);
#endif
#if HDLC
if (rc == MAXT_SUCCESS)
rc = startHDLC(device[0], asyncEvent, ref eventInfo.channel[HDLC_IDX]);
#endif
if (rc == MAXT_SUCCESS)
mxfSleep(10000);
#if MIL1553
// Stop transmission and acquisition
if (rc == MAXT_SUCCESS)
rc = stopMil1553(asyncEvent, eventInfo.channel[MIL1553_IDX]);
#endif
#if A429
if (rc == MAXT_SUCCESS)
rc = stopA429(asyncEvent, eventInfo.channel[A429_IDX]);
#endif
#if CSDB
if (rc == MAXT_SUCCESS)
rc = stopCSDB(asyncEvent, eventInfo.channel[CSDB_IDX]);
#endif
#if ASYNC
if (rc == MAXT_SUCCESS)
rc = stopASYNC(asyncEvent, eventInfo.channel[ASYNC_IDX]);
#endif
#if DISCRETE
if (rc == MAXT_SUCCESS)
rc = stopDiscrete(asyncEvent, eventInfo.channel[DISCRETE_IDX]);
#endif
#if HDLC
if (rc == MAXT_SUCCESS)
rc = stopHDLC(asyncEvent, eventInfo.channel[HDLC_IDX]);
#endif
// Terminate asynchronous event handler
if (asyncEvent > 0)
if (rc != MAXT_SUCCESS)
{
StringBuilder buffer = new StringBuilder(256);
rc = mxfSystemErrorStringGet(server, rc, (UInt32)buffer.Capacity, buffer);
Console.WriteLine(buffer + "\n");
}
// Free buffer
if (eventInfo.hostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(eventInfo.hostBuffer);
Console.Write("\n\rPress a key to terminate\n\r");
Console.ReadKey();
return;
}
private static UInt32 initHandler(UInt64 server, UInt64 deviceIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
UInt64 device;
MXF_DEVICE_INFO deviceInfo;
UInt32 rc;
deviceInfo.modules = new MXF_DEVICE_MODULE_INFO[32];
if (attrib == KMXF_CHANNEL_CLASS)
{
rc = mxfSystemDeviceGet(server, deviceIndex, out device);
if (rc == MAXT_SUCCESS)
rc = mxfDeviceInfoGet(device, out deviceInfo);
if (rc == MAXT_SUCCESS && (deviceInfo.modules[moduleIndex].type == MXF_MODULE_ASYNC_EH))
{
// Set IPM-ASYNC-EH first TX and RX channel to CSDB
if ((channelIndex == 0) || (channelIndex == deviceInfo.modules[moduleIndex].txCount))
{
value = MXF_CLASS_CSDB;
return 1;
}
}
else
{
// Set IPM-MULTI-EH first TX and RX channel to HDLC
if ((channelIndex == 0) || (channelIndex == 8))
{
value = MXF_CLASS_HDLC;
return 1;
}
else if ((channelIndex == 4) || (channelIndex == 12))
{
value = MXF_CLASS_CLOCK;
return 1;
}
}
}
return 0;
}
private static UInt32 startMil1553(UInt64 device, UInt64 asyncEvent, ref EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
var module = new UInt64[1];
UInt64 count;
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_MIL1553MRT_EH, 1, out count, module);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
// Get handle of first MIL1553 Bus controller channel
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 1, out eventInfoChn.txChannel[0]);
// Get handle of first MIL1553 Bus monitor channel
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 0, out eventInfoChn.rxChannel[0]);
# if LOOPBACK
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.rxChannel[0], KMXF_MIL1553_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Flex allocation for MIL1553 BC
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(eventInfoChn.txChannel[0], 0, BUFFER_SIZE, out eventInfoChn.txBuffer[0], IntPtr.Zero);
// Flex allocation for MIL1553 BM
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(eventInfoChn.rxChannel[0], BUFFER_SIZE, out eventInfoChn.rxBuffer[0], IntPtr.Zero);
// Set the minor frame #0 using 1 command
if (rc == MAXT_SUCCESS)
{
minorFrame[0] = new MXF_MIL1553_TXPERIODIC_MJRFRAME_MSG();
// Command #0 : Address 5, Subaddress 3, RX, 4 words
rc = mxfMIL1553CommandCompose(ADDRESS, SUBADDRESS, MXF_MIL1553_COMMAND_DIR_RX, 4, out minorFrame[0].command);
minorFrame[0].modulo = 1;
minorFrame[0].buffer = eventInfoChn.txBuffer[0];
}
if (rc == MAXT_SUCCESS)
rc = mxfMIL1553TxPeriodicMajorFrameSet(eventInfoChn.txChannel[0], 0, 0, 1, minorFrame, IntPtr.Zero);
// Start message queue
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting MIL1553\n\r");
}
// set event condition on TX periodic update message threshold for RT5
if (rc == MAXT_SUCCESS)
{
eventInfoChn.txCondition = new MXF_ASYNCEVENT_CONDITION[1];
eventInfoChn.txCondition[0].condID = MXF_ASYNCEVENT_COND_TXPERIODIC_UPDATEMSG_BUFFER_THRESHOLD;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.channel = eventInfoChn.txChannel[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.txCondition);
}
// Select BC buffer for async event
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventTxPeriodicUpdateMsgSelectSet(asyncEvent, eventInfoChn.txChannel[0], MXF_MSG_SELECT_ONLY, 1, eventInfoChn.txBuffer);
// set event condition on RX acquisition buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.rxCondition = new MXF_ASYNCEVENT_CONDITION[1];
eventInfoChn.rxCondition[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.buffer = eventInfoChn.rxBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.rxCondition);
}
// Start acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStart(eventInfoChn.rxBuffer[0], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
// Start the major frame with 250 msec rate
if (rc == MAXT_SUCCESS)
rc = mxfMIL1553TxPeriodicMajorFrameStart(eventInfoChn.txChannel[0], 0, RATE, IntPtr.Zero);
return rc;
}
private static UInt32 startA429(UInt64 device, UInt64 asyncEvent, ref EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
var module = new UInt64[1];
UInt64 msgSched = 0;
UInt64 count;
// Get handle of first A429 TX and RX channel
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_A429_EH, 1, out count, module);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 0, out eventInfoChn.txChannel[0]);
if (rc == MAXT_SUCCESS)
{
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_A429, MXF_SCLASS_RX_CHANNEL, 1, out count, eventInfoChn.rxChannel);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
}
# if LOOPBACK
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.rxChannel[0], KMXF_A429_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Flex allocation for A429 TX
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(eventInfoChn.txChannel[0], 0, BUFFER_SIZE, out eventInfoChn.txBuffer[0], IntPtr.Zero);
// Flex allocation for A429 RX
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(eventInfoChn.rxChannel[0], BUFFER_SIZE, out eventInfoChn.rxBuffer[0], IntPtr.Zero);
// Start message queue
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting A429\n\r");
}
// set event condition on TX periodic update message threshold for label 5
if (rc == MAXT_SUCCESS)
{
eventInfoChn.txCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.txCondition[0].condID = MXF_ASYNCEVENT_COND_TXPERIODIC_UPDATEMSG_BUFFER_THRESHOLD;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.channel = eventInfoChn.txChannel[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.txCondition);
}
// Select buffer for async event
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventTxPeriodicUpdateMsgSelectSet(asyncEvent, eventInfoChn.txChannel[0], MXF_MSG_SELECT_ONLY, 1, eventInfoChn.txBuffer);
// set event condition on RX acquisition buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.rxCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.rxCondition[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.buffer = eventInfoChn.rxBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.rxCondition);
}
// Set the Periodic Scheduler
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleNew(eventInfoChn.txChannel[0], out eventInfoChn.sched);
// Set scheduling values: Rate=250 ms, Phase=0 us
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleMsgAdd(eventInfoChn.sched, RATE, 0, out msgSched);
// Define the number of buffer for the list and link to it
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleBufferListAdd(msgSched, 1, 0, eventInfoChn.txBuffer);
// Start acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStart(eventInfoChn.rxBuffer[0], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
// Run the schedule
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleRun(eventInfoChn.sched);
return rc;
}
private static UInt32 startCSDB(UInt64 device, UInt64 asyncEvent, ref EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
var module = new UInt64[1];
UInt64 msgSched = 0;
var recTXCsdb = new MXF_CSDB_DATAREC[1];
recTXCsdb[0].data = new byte[12];
UInt64 txSyncBuffer = 0;
var txBuffer = new UInt64[2];
UInt64 count;
IntPtr recPtr = IntPtr.Zero;
// Get handle of first CSDB TX and RX channel
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_ASYNC_EH, 1, out count, module);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 0, out eventInfoChn.txChannel[0]);
if (rc == MAXT_SUCCESS)
{
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_CSDB, MXF_SCLASS_RX_CHANNEL, 1, out count, eventInfoChn.rxChannel);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
}
# if LOOPBACK
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.rxChannel[0], KMXF_CSDB_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Flex allocation for CSDB TX
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(eventInfoChn.txChannel[0], 0, BUFFER_SIZE, out eventInfoChn.txBuffer[0], IntPtr.Zero);
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(eventInfoChn.txChannel[0], 1, BUFFER_SIZE, out txSyncBuffer, IntPtr.Zero);
// Flex allocation for CSDB RX
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(eventInfoChn.rxChannel[0], BUFFER_SIZE, out eventInfoChn.rxBuffer[0], IntPtr.Zero);
// Start message queue
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting CSDB\n\r");
}
// set event condition on TX periodic update message threshold for label 5
if (rc == MAXT_SUCCESS)
{
eventInfoChn.txCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.txCondition[0].condID = MXF_ASYNCEVENT_COND_TXPERIODIC_UPDATEMSG_BUFFER_THRESHOLD;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.txCondition[0].condition.txPeriodicUpdateMsgBufferThreshold.channel = eventInfoChn.txChannel[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.txCondition);
}
// Select buffer for async event
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventTxPeriodicUpdateMsgSelectSet(asyncEvent, eventInfoChn.txChannel[0], MXF_MSG_SELECT_ONLY, 1, eventInfoChn.txBuffer);
// set event condition on RX acquisition buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.rxCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.rxCondition[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.buffer = eventInfoChn.rxBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.rxCondition);
}
// Set the Periodic Scheduler
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleNew(eventInfoChn.txChannel[0], out eventInfoChn.sched);
// Add one message to scheduler, Rate=250 ms, Phase=0 us
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleMsgAdd(eventInfoChn.sched, RATE, 0, out msgSched);
// Add two records to the message
if (rc == MAXT_SUCCESS)
{
txBuffer[0] = txSyncBuffer;
txBuffer[1] = eventInfoChn.txBuffer[0];
rc = mxfTxPeriodicScheduleBufferListAdd(msgSched, 2, 0, txBuffer);
}
// Set default data for sync block
try
{
recPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MXF_CSDB_DATAREC)));
}
catch(OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
if (rc == MAXT_SUCCESS)
{
// SYNC block
recTXCsdb[0].timeTag = 0;
recTXCsdb[0].control = 0;
recTXCsdb[0].repeatCount = 1;
recTXCsdb[0].reserved = 0;
recTXCsdb[0].data[0] = 0xA5;
recTXCsdb[0].data[1] = 0xA5;
recTXCsdb[0].data[2] = 0xA5;
recTXCsdb[0].data[3] = 0xA5;
recTXCsdb[0].data[4] = 0xA5;
recTXCsdb[0].data[5] = 0xA5;
}
Marshal.StructureToPtr(recTXCsdb[0], recPtr, true);
if (rc == MAXT_SUCCESS)
rc = mxfCSDBTxPeriodicUpdateMsgWrite(txSyncBuffer, 1, recPtr);
// Start acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStart(eventInfoChn.rxBuffer[0], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
// Run the schedule
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicScheduleRun(eventInfoChn.sched);
Marshal.FreeHGlobal(recPtr);
return rc;
}
private static UInt32 startASYNC(UInt64 device, UInt64 asyncEvent, ref EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
var module = new UInt64[1];
UInt64 count;
// Get handle of first ASYNC TX and RX channel
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_ASYNC_EH, 1, out count, module);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 1, out eventInfoChn.txChannel[0]);
if (rc == MAXT_SUCCESS)
{
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_ASYNC_ENHANCED, MXF_SCLASS_RX_CHANNEL, 1, out count, eventInfoChn.rxChannel);
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
}
# if LOOPBACK
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.rxChannel[0], KMXF_ASYNCEH_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Set TX minimum string gap to 4 bit
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.txChannel[0], KMXF_ASYNCEH_TX_STRING_GAP, 4 * 4);
// Flex allocation for ASYNC TX
if (rc == MAXT_SUCCESS)
rc = mxfTxAperiodicBufferAlloc(eventInfoChn.txChannel[0], MXF_TXAPERIODIC_PRIORITY_NORMAL, BUFFER_SIZE, out eventInfoChn.txBuffer[0], IntPtr.Zero);
// Flex allocation for ASYNC RX
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(eventInfoChn.rxChannel[0], BUFFER_SIZE, out eventInfoChn.rxBuffer[0], IntPtr.Zero);
// set event condition on RX acquisition buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.rxCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.rxCondition[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.buffer = eventInfoChn.rxBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.rxCondition);
}
// Start acquisition
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting ASYNC\n\r");
rc = mxfRxAcqStart(eventInfoChn.rxBuffer[0], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
}
// set event condition on TX aperiodic buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.txCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.txCondition[0].condID = MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.buffer = eventInfoChn.txBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.txCondition);
}
return rc;
}
private static UInt32 startDiscrete(UInt64 device, UInt64 asyncEvent, ref EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
var module = new UInt64[1];
UInt64 moduleCount;
// Get handle of first Discrete TX and RX channel
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_DIOFIFO_EH, 1, out moduleCount, module);
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 0, out eventInfoChn.txChannel[0]);
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelGet(module[0], 1, out eventInfoChn.rxChannel[0]);
# if LOOPBACK
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.rxChannel[0], KMXF_DISCRETE_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Flex allocation for Discrete TX
if (rc == MAXT_SUCCESS)
rc = mxfTxAperiodicBufferAlloc(eventInfoChn.txChannel[0], MXF_TXAPERIODIC_PRIORITY_NORMAL, BUFFER_SIZE, out eventInfoChn.txBuffer[0], IntPtr.Zero);
// Flex allocation for Discrete RX
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(eventInfoChn.rxChannel[0], BUFFER_SIZE, out eventInfoChn.rxBuffer[0], IntPtr.Zero);
// set event condition on RX acquisition buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.rxCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.rxCondition[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.buffer = eventInfoChn.rxBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.rxCondition);
}
// Start acquisition
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting Discrete\n\r");
rc = mxfRxAcqStart(eventInfoChn.rxBuffer[0], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
}
// set event condition on TX aperiodic buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.txCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.txCondition[0].condID = MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.buffer = eventInfoChn.txBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.txCondition);
}
return rc;
}
private static UInt32 startHDLC(UInt64 device, UInt64 asyncEvent, ref EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
var module = new UInt64[1];
UInt64 count;
// Get handle of first Discrete TX and RX channel
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_MULTI_EH, 1, out count, module);
if (rc == MAXT_SUCCESS && count > 0)
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_HDLC, MXF_SCLASS_TX_CHANNEL, 1, out count, eventInfoChn.txChannel);
if (rc == MAXT_SUCCESS && count > 0)
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_HDLC, MXF_SCLASS_RX_CHANNEL, 1, out count, eventInfoChn.rxChannel);
// If module or channel not found, return an error
if (rc == MAXT_SUCCESS && count == 0)
rc = MAXT_ERROR_NOT_FOUND;
# if LOOPBACK
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(eventInfoChn.rxChannel[0], KMXF_HDLC_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Flex allocation for HDLC TX
if (rc == MAXT_SUCCESS)
rc = mxfTxAperiodicBufferAlloc(eventInfoChn.txChannel[0], MXF_TXAPERIODIC_PRIORITY_NORMAL, BUFFER_SIZE, out eventInfoChn.txBuffer[0], IntPtr.Zero);
// Flex allocation for HDLC RX
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(eventInfoChn.rxChannel[0], BUFFER_SIZE, out eventInfoChn.rxBuffer[0], IntPtr.Zero);
// set event condition on RX acquisition buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.rxCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.rxCondition[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.rxCondition[0].condition.rxAcqBufferThreshold.buffer = eventInfoChn.rxBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.rxCondition);
}
// Start acquisition
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting HDLC\n\r");
rc = mxfRxAcqStart(eventInfoChn.rxBuffer[0], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
}
// set event condition on TX aperiodic buffer threshold
if (rc == MAXT_SUCCESS)
{
eventInfoChn.txCondition[0] = new MXF_ASYNCEVENT_CONDITION();
eventInfoChn.txCondition[0].condID = MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.almostEmpty = ALMOST_EMPTY;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.almostFull = ALMOST_FULL;
eventInfoChn.txCondition[0].condition.txAperiodicBufferThreshold.buffer = eventInfoChn.txBuffer[0];
rc = mxfAsyncEventConditionsSet(asyncEvent, 1, 1, eventInfoChn.txCondition);
}
return rc;
}
private static UInt32 stopMil1553(UInt64 asyncEvent, EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
Console.Write("Stopping MIL1553\n\r");
// Stop the major frame
rc = mxfTxPeriodicMajorFrameStop(eventInfoChn.txChannel[0], 0, 0);
// Stop acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(eventInfoChn.rxBuffer[0]);
// disable event condition
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.txCondition);
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.rxCondition);
return rc;
}
private static UInt32 stopA429(UInt64 asyncEvent, EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
Console.Write("Stopping A429\n\r");
// Stop the schedule
rc = mxfTxPeriodicScheduleFree(eventInfoChn.sched);
// Stop acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(eventInfoChn.rxBuffer[0]);
// disable event condition
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.txCondition);
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.rxCondition);
return rc;
}
private static UInt32 stopCSDB(UInt64 asyncEvent, EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
Console.Write("Stopping CSDB\n\r");
// Stop the schedule
rc = mxfTxPeriodicScheduleFree(eventInfoChn.sched);
// Stop acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(eventInfoChn.rxBuffer[0]);
// disable event condition
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.txCondition);
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.rxCondition);
return rc;
}
private static UInt32 stopASYNC(UInt64 asyncEvent, EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
Console.Write("Stopping ASYNC\n\r");
// disable event condition
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.txCondition);
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.rxCondition);
// Stop acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(eventInfoChn.rxBuffer[0]);
return rc;
}
private static UInt32 stopDiscrete(UInt64 asyncEvent, EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
Console.Write("Stopping Discrete\n\r");
// disable event condition
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.txCondition);
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.rxCondition);
// Stop acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(eventInfoChn.rxBuffer[0]);
return rc;
}
private static UInt32 stopHDLC(UInt64 asyncEvent, EVENT_INFO_CHANNEL eventInfoChn)
{
UInt32 rc;
Console.Write("Stopping HDLC\n\r");
// disable event condition
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.txCondition);
if (rc == MAXT_SUCCESS)
rc = mxfAsyncEventConditionsSet(asyncEvent, VMXF_DISABLE, 1, eventInfoChn.rxCondition);
// Stop acquisition
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(eventInfoChn.rxBuffer[0]);
return rc;
}
private static UInt32 eventHandler(UInt64 asyncEvent, IntPtr pParam)
{
UInt32 rc = 0;
UInt64 eventCount;
UInt64 rec;
IntPtr recPtr = IntPtr.Zero;
// Get pending event
rc = mxfAsyncEventPendingGet(asyncEvent, 1, out eventCount, pendingList);
if (rc == MAXT_SUCCESS)
{
switch (pendingList[0].condID)
{
case MXF_ASYNCEVENT_COND_TXPERIODIC_UPDATEMSG_BUFFER_THRESHOLD:
{
// Set data for MIL1553 BC buffer
if (pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer == eventInfo.channel[MIL1553_IDX].txBuffer[0])
{
txRec.data = new UInt16[36];
recPtr = eventInfo.hostBuffer;
for (rec = 0; rec < pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.almostFull; rec++)
{
txRec.repeatCount = 1;
txRec.dataSize = 10; //10 bytes (command + 4 words)
txRec.data[0] = 0x0000; //Not used
txRec.data[1] = (UInt16)rec;
txRec.data[2] = (UInt16)rec;
txRec.data[3] = (UInt16)rec;
txRec.data[4] = (UInt16)rec;
Marshal.StructureToPtr(txRec, recPtr, true);
mxfMIL1553NextDataRecordPtrGet(recPtr, out recPtr);
}
rc = mxfTxPeriodicUpdateMsgWrite(pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer, rec, eventInfo.hostBuffer);
}
else if (pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer == eventInfo.channel[A429_IDX].txBuffer[0]) // Set data for A429 TX buffer
{
recPtr = eventInfo.hostBuffer;
for (rec = 0; rec < pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.almostFull; rec++)
{
txRec.repeatCount = 1;
mxfA429ArwCompose(ADDRESS, SUBADDRESS, rec, 0, VMXF_A429_PARITY_ODD, out txRec.data);
Marshal.StructureToPtr(txRec, recPtr, true);
mxfA429NextDataRecordPtrGet(recPtr, out recPtr);
}
rc = mxfTxPeriodicUpdateMsgWrite(pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer, rec, eventInfo.hostBuffer);
}
else if (pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer == eventInfo.channel[CSDB_IDX].txBuffer[0]) // Set data for CSDB TX buffer
{
txRec.data = new byte[12];
recPtr = eventInfo.hostBuffer;
for (rec = 0; rec < pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.almostFull; rec++)
{
txRec.repeatCount = 1;
txRec.data[0] = (byte)rec;
txRec.data[1] = (byte)rec;
txRec.data[2] = (byte)rec;
txRec.data[3] = (byte)rec;
txRec.data[4] = (byte)rec;
txRec.data[5] = (byte)rec;
Marshal.StructureToPtr(txRec, recPtr, true);
mxfCSDBNextDataRecordPtrGet(recPtr, out recPtr);
}
rc = mxfTxPeriodicUpdateMsgWrite(pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer, rec, eventInfo.hostBuffer);
}
break;
}
case MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD:
{
// Set data for ASYNC TX buffer
if (pendingList[0].condition.txAperiodicBufferThreshold.buffer == eventInfo.channel[ASYNC_IDX].txBuffer[0])
{
txRec.data = new byte[256];
recPtr = eventInfo.hostBuffer;
int i;
for (rec = 0; rec < pendingList[0].condition.txAperiodicBufferThreshold.almostFull; rec++)
{
txRec.repeatCount = 1;
txRec.dataSize = 10; //10 bytes
for (i = 0; i < 10; i++)
txRec.data[i] = (byte)rec;
Marshal.StructureToPtr(txRec, recPtr, true);
mxfASYNCEHNextDataRecordPtrGet(recPtr, out recPtr);
}
rc = mxfTxAperiodicWrite(pendingList[0].condition.txAperiodicBufferThreshold.buffer, MXF_TXAPERIODIC_FLAG_DEFAULT, RATE * rec, rec, eventInfo.hostBuffer);
}
else if (pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer == eventInfo.channel[DISCRETE_IDX].txBuffer[0]) // Set data for Discrete TX buffer
{
recPtr = eventInfo.hostBuffer;
if (discreteTimer == 0)
{
UInt64 device;
rc = mxfChannelInfoGet(eventInfo.channel[DISCRETE_IDX].txChannel[0], out device, IntPtr.Zero);
if (rc == MAXT_SUCCESS)
rc = mxfDeviceTimerGet(device, out discreteTimer);
if (rc != MAXT_SUCCESS)
break;
}
for (rec = 0; rec < pendingList[0].condition.txAperiodicBufferThreshold.almostFull; rec++)
{
txRec.timeTag = discreteTimer;
txRec.repeatCount = 1;
txRec.data = (byte)rec;
txRec.edge = 0x00ff;
Marshal.StructureToPtr(txRec, recPtr, true);
mxfDiscreteNextDataRecordPtrGet(recPtr, out recPtr);
discreteTimer += RATE;
}
rc = mxfTxAperiodicWrite(pendingList[0].condition.txAperiodicBufferThreshold.buffer, MXF_TXAPERIODIC_FLAG_USE_RECORD_ABSOLUTE_TIME, 0, rec, eventInfo.hostBuffer);
}
else if (pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer == eventInfo.channel[HDLC_IDX].txBuffer[0]) // Set data for HDLC TX buffer
{
txRec.data = new UInt16[2048];
recPtr = eventInfo.hostBuffer;
UInt64 i;
for (rec = 0; rec < pendingList[0].condition.txAperiodicBufferThreshold.almostFull; rec++)
{
txRec.repeatCount = 1;
txRec.dataSize = 20; //20 bytes
for (i = 0; i < txRec.dataSize / 2; i++)
txRec.data[i] = (UInt16)rec;
Marshal.StructureToPtr(txRec, recPtr, true);
mxfHDLCNextDataRecordPtrGet(recPtr, out recPtr);
}
rc = mxfTxAperiodicWrite(pendingList[0].condition.txAperiodicBufferThreshold.buffer, MXF_TXAPERIODIC_FLAG_DEFAULT, RATE * rec, rec, eventInfo.hostBuffer);
}
break;
}
case MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD:
{
UInt64 rxAcqStatus, msgCount, byteCount;
rc = mxfASYNCEHRxAcqRead(pendingList[0].condition.rxAcqBufferThreshold.buffer, 0, BUFFER_SIZE, out rxAcqStatus, out msgCount, out byteCount, eventInfo.hostBuffer);
if (rc != MAXT_SUCCESS)
break;
// Get data for MIL1553 BM buffer
if (pendingList[0].condition.rxAcqBufferThreshold.buffer == eventInfo.channel[MIL1553_IDX].rxBuffer[0])
{
var rxRec = new MXF_MIL1553_DATAREC[msgCount];
UInt64 data;
recPtr = eventInfo.hostBuffer;
for (rec = 0; rc == MAXT_SUCCESS && rec < msgCount; rec++)
{
rxRec[rec] = (MXF_MIL1553_DATAREC)Marshal.PtrToStructure(recPtr, typeof(MXF_MIL1553_DATAREC));
Console.Write("MIL1553 --> {0} ", rxRec[rec].timeTag);
Console.Write("{0:x8} ", rxRec[rec].control);
Console.Write("{0:0000} ", (rxRec[rec].dataSize / 2) - 1);
for (data = 0; data < Math.Min(8, rxRec[rec].dataSize / 2); data++)
{
Console.Write("{0:X4} ", rxRec[rec].data[data]);
}
Console.Write("\n\r");
mxfMIL1553NextDataRecordPtrGet(recPtr, out recPtr);
}
}
else if (pendingList[0].condition.rxAcqBufferThreshold.buffer == eventInfo.channel[A429_IDX].rxBuffer[0]) // Get data for A429 RX buffer
{
var rxRec = new MXF_A429_DATAREC[msgCount];
recPtr = eventInfo.hostBuffer;
for (rec = 0; rc == MAXT_SUCCESS && rec < msgCount; rec++)
{
rxRec[rec] = (MXF_A429_DATAREC)Marshal.PtrToStructure(recPtr, typeof(MXF_A429_DATAREC));
Console.Write("A429 --> {0} ", rxRec[rec].timeTag);
Console.Write("{0:x8} ", rxRec[rec].control);
Console.Write("{0:x8} \n\r", rxRec[rec].data);
mxfA429NextDataRecordPtrGet(recPtr, out recPtr);
}
}
else if (pendingList[0].condition.rxAcqBufferThreshold.buffer == eventInfo.channel[CSDB_IDX].rxBuffer[0]) // Get data for CSDB RX buffer
{
var rxRec = new MXF_CSDB_DATAREC[msgCount];
UInt64 data;
recPtr = eventInfo.hostBuffer;
for (rec = 0; rc == MAXT_SUCCESS && rec < msgCount; rec++)
{
rxRec[rec] = (MXF_CSDB_DATAREC)Marshal.PtrToStructure(recPtr, typeof(MXF_CSDB_DATAREC));
Console.Write("CSDB --> {0} ", rxRec[rec].timeTag);
Console.Write("{0:x8} ", rxRec[rec].control);
for (data = 0; data < 6; data++)
{
Console.Write("{0:X2} ", rxRec[rec].data[data]);
}
Console.Write("\n\r");
mxfCSDBNextDataRecordPtrGet(recPtr, out recPtr);
}
}
else if (pendingList[0].condition.rxAcqBufferThreshold.buffer == eventInfo.channel[ASYNC_IDX].rxBuffer[0]) // Get data for ASYNC RX buffer
{
var rxRec = new MXF_ASYNCEH_DATAREC[msgCount];
UInt64 data;
recPtr = eventInfo.hostBuffer;
for (rec = 0; rc == MAXT_SUCCESS && rec < msgCount; rec++)
{
rxRec[rec] = (MXF_ASYNCEH_DATAREC)Marshal.PtrToStructure(recPtr, typeof(MXF_ASYNCEH_DATAREC));
Console.Write("ASYNC --> {0} ", rxRec[rec].timeTag);
Console.Write("{0:x8} ", rxRec[rec].control);
Console.Write("{0:0000} ", rxRec[rec].dataSize);
for (data = 0; data < rxRec[rec].dataSize; data++)
{
Console.Write("{0:X2} ", rxRec[rec].data[data]);
}
Console.Write("\n\r");
mxfASYNCEHNextDataRecordPtrGet(recPtr, out recPtr);
}
}
else if (pendingList[0].condition.rxAcqBufferThreshold.buffer == eventInfo.channel[DISCRETE_IDX].rxBuffer[0]) // Get data for Discrete RX buffer
{
var rxRec = new MXF_DISCRETE_DATAREC[msgCount];
recPtr = eventInfo.hostBuffer;
for (rec = 0; rc == MAXT_SUCCESS && rec < msgCount; rec++)
{
rxRec[rec] = (MXF_DISCRETE_DATAREC)Marshal.PtrToStructure(recPtr, typeof(MXF_DISCRETE_DATAREC));
Console.Write("DISCRETE --> {0} ", rxRec[rec].timeTag);
Console.Write("{0:X2} ", (byte)rxRec[rec].edge);
Console.Write("{0:X2} \n\r", (byte)rxRec[rec].data);
mxfDiscreteNextDataRecordPtrGet(recPtr, out recPtr);
}
}
else if (pendingList[0].condition.txPeriodicUpdateMsgBufferThreshold.buffer == eventInfo.channel[HDLC_IDX].rxBuffer[0]) // Get data for HDLC RX buffer
{
var rxRec = new MXF_HDLC_DATAREC[msgCount];
UInt64 data;
recPtr = eventInfo.hostBuffer;
for (rec = 0; rc == MAXT_SUCCESS && rec < msgCount; rec++)
{
rxRec[rec] = (MXF_HDLC_DATAREC)Marshal.PtrToStructure(recPtr, typeof(MXF_HDLC_DATAREC));
Console.Write("HDLC --> {0} ", rxRec[rec].timeTag);
Console.Write("{0:x8} ", rxRec[rec].control);
Console.Write("{0:0000} ", rxRec[rec].dataSize / 2);
for (data = 0; data < Math.Min(8, rxRec[rec].dataSize / 2); data++)
{
Console.Write("{0:X4} ", rxRec[rec].data[data]);
}
Console.Write("\n\r");
mxfHDLCNextDataRecordPtrGet(recPtr, out recPtr);
}
}
break;
}
}
}
if (rc != MAXT_SUCCESS)
Console.Write("event handler rc=0x{0:x8}\n\r", rc);
return rc;
}
}
}
Updated 03/30/2022