#define LOOPBACK
using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace csdb_example
{
class csdb_rx_sampling
{
const int BUFFER_SIZE = 4096;
const int LABEL = 0x3;
const int SI = 0;
const int BLOCKCOUNT = 6;
public static void Main(string[] args)
{
UInt32 rc;
UInt64 server;
UInt64 device = 0;
var module = new UInt64[1];
var rxChannel = new UInt64[1];
var txChannel = new UInt64[1];
UInt64 rxBuffer = 0;
var txBuffer = new UInt64[2];
UInt64 count = 0;
IntPtr hostBuffer = IntPtr.Zero;
IntPtr txHostBuffer = IntPtr.Zero;
IntPtr recPtr = IntPtr.Zero;
UInt64 schedule = 0;
UInt64 msg = 0;
UInt64 i, j, dataIndex;
UInt64 msgsCount, bytesCount;
var label = new UInt64[] { 0xA5 };
MXF_SYSTEM_INIT_ATTRIBUTE_UINT64_HANDLER _initHandler = initHandler;
{
data = new byte[12]
};
{
data = new byte[12]
};
#if LOCAL
#else
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc != MAXT_SUCCESS)
{
Console.Write("Failed to connect; rc=0x{0:x8}", rc);
Console.WriteLine();
Console.WriteLine("Press a key to terminate");
Console.Read();
return;
}
Console.WriteLine();
Console.WriteLine("Starting");
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if ((rc == MAXT_SUCCESS) && (count != 0))
if ((rc == MAXT_SUCCESS) && (count == 0))
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
#if LOOPBACK
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
try
{
hostBuffer = Marshal.AllocHGlobal(BUFFER_SIZE);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
try
{
txHostBuffer = Marshal.AllocHGlobal(BUFFER_SIZE);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
Console.WriteLine("Sampling started");
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
for (i = 0; i < BLOCKCOUNT; i++)
Marshal.StructureToPtr(recCsdb, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
recCsdb.
data[1] = 0x8 | SI;
for (i = 2; i < BLOCKCOUNT; i++)
recCsdb.
data[i] = (byte)i;
Marshal.StructureToPtr(recCsdb, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine("Running periodic transmission, please wait...");
}
for (i = 0; (i < 10) && (rc == MAXT_SUCCESS); i++)
{
rc =
mxfCSDBRxSamplingRead(rxBuffer, MXF_RXSAMPLING_FLAG_DEFAULT, 0, BUFFER_SIZE, out msgsCount, out bytesCount, hostBuffer);
if (rc == MAXT_SUCCESS)
{
Console.WriteLine("Read {0} messages", msgsCount);
recPtr = hostBuffer;
for (j = 0; (rc == MAXT_SUCCESS) && (j < msgsCount); j++)
{
Console.Write(
"{0:D2}: Timetag={1:D16}: CSDB data=[ ", j, recSamp.
timeTag);
for (dataIndex = 0; dataIndex < BLOCKCOUNT; dataIndex++)
Console.Write(
"0x{0:X2} ", recSamp.
data[dataIndex]);
Console.Write("]\n\r");
}
}
if (rc != MAXT_SUCCESS)
Console.WriteLine("Sampling read failed; rc=0x{0:x8}", rc);
else
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc != MAXT_SUCCESS)
{
StringBuilder buffer = new StringBuilder(256);
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
Console.WriteLine(buffer);
}
if (hostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(hostBuffer);
Console.WriteLine();
Console.WriteLine("Press enter to terminate");
Console.Read();
return;
}
private static UInt32 initHandler(UInt64 server, UInt64 deviceIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
UInt64 device;
UInt32 rc;
if (attrib == KMXF_CHANNEL_CLASS)
{
if (rc == MAXT_SUCCESS)
if ((rc == MAXT_SUCCESS) && (deviceInfo.modules[moduleIndex].type == MXF_MODULE_ASYNC_EH))
{
if ((channelIndex == 0) || (channelIndex == deviceInfo.modules[moduleIndex].txCount))
{
value = MXF_CLASS_CSDB;
return Convert.ToUInt32(true);
}
}
}
return Convert.ToUInt32(false);
}
}
}