Big changes
This commit is contained in:
@@ -0,0 +1,593 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using FpgaMeasurementInstrumentsLib;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// This class serves as an interface to FPGAs that implement a UDP interface.
|
||||
/// It allows for the ability to read and write to registers.
|
||||
/// </summary>
|
||||
public class CommFpgaEthernet : IFpgaComm, IDisposable
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private UdpClient _udpClient;
|
||||
private readonly int _localPort;
|
||||
private readonly int _remotePort;
|
||||
private readonly string _remoteAddress;
|
||||
private static object _syncObj = new Object();
|
||||
private SelfTestResult _selfTestResult;
|
||||
private State _state;
|
||||
private string _name;
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFuctions
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~CommFpgaEthernet()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
_udpClient.Close();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read data off of the socket
|
||||
/// </summary>
|
||||
/// <param name="dataRead">The data that was read</param>
|
||||
/// <returns>The number of bytes read</returns>
|
||||
private int ReadData(ref byte[] dataRead)
|
||||
{
|
||||
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, _localPort);
|
||||
|
||||
dataRead = _udpClient.Receive(ref remoteIPEndPoint);
|
||||
|
||||
int numBytesRead = dataRead.Length;
|
||||
|
||||
return numBytesRead;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command message and get a response message
|
||||
/// </summary>
|
||||
/// <param name="commandMsg">The message to send</param>
|
||||
/// <param name="rspMsg">The response</param>
|
||||
private void SendCommandGetResponse(FPGACmdMessage commandMsg, ref FPGARspMessage rspMsg)
|
||||
{
|
||||
uint rxBufferSize = rspMsg.GetEntireMsgLength();
|
||||
uint rxNumBytesExpected = rxBufferSize;
|
||||
|
||||
uint dataToSendNumBytes = commandMsg.GetEntireMsgLength();
|
||||
|
||||
// send the command
|
||||
byte[] dataToSend = new byte[dataToSendNumBytes];
|
||||
|
||||
// get a pointer to the data
|
||||
GCHandle sendPinnedArray = GCHandle.Alloc(dataToSend, GCHandleType.Pinned);
|
||||
IntPtr pByte = sendPinnedArray.AddrOfPinnedObject();
|
||||
commandMsg.Format(pByte);
|
||||
sendPinnedArray.Free();
|
||||
|
||||
// send the data
|
||||
int numBytesSent = SendData(dataToSend);
|
||||
|
||||
if (dataToSendNumBytes != numBytesSent)
|
||||
{
|
||||
throw new Exception("wanted to send: " + dataToSendNumBytes.ToString() + " bytes, SendData() reported that it sent: " + numBytesSent.ToString());
|
||||
}
|
||||
|
||||
// read the response
|
||||
byte[] rspBuffer = new byte[rxBufferSize];
|
||||
int numBytesRead = ReadData(ref rspBuffer);
|
||||
|
||||
if (numBytesRead != rxNumBytesExpected)
|
||||
{
|
||||
throw new Exception("received " + numBytesRead.ToString() + " bytes, expected " + rxNumBytesExpected.ToString());
|
||||
}
|
||||
|
||||
// populate the rspMsg object
|
||||
GCHandle rxPinnedArray = GCHandle.Alloc(rspBuffer, GCHandleType.Pinned);
|
||||
IntPtr pBytePtr = rxPinnedArray.AddrOfPinnedObject();
|
||||
rspMsg.Parse(pBytePtr);
|
||||
rxPinnedArray.Free();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send data out of the socket
|
||||
/// </summary>
|
||||
/// <param name="dataToSend">The data to send</param>
|
||||
/// <returns>The number of bytes sent</returns>
|
||||
private int SendData(byte[] dataToSend)
|
||||
{
|
||||
IPAddress addy = IPAddress.Parse(_remoteAddress);
|
||||
|
||||
IPEndPoint ipEndPoint = new IPEndPoint(addy, _remotePort);
|
||||
|
||||
int numBytesSent = _udpClient.Send(dataToSend, dataToSend.Length, ipEndPoint);
|
||||
|
||||
return numBytesSent;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
|
||||
/// <summary>
|
||||
/// CommFpgaEthernet factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public CommFpgaEthernet(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
_state = State.Uninitialized;
|
||||
|
||||
_localPort = _configuration.GetConfigurationValue("CommFpgaEthernet", "LocalPort", 0);
|
||||
_remotePort = _configuration.GetConfigurationValue("CommFpgaEthernet", "RemotePort", 0);
|
||||
_remoteAddress = _configuration.GetConfigurationValue("CommFpgaEthernet", "RemoteAddress", "127.0.0.1");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fpgaName"></param>
|
||||
/// <param name="localPort">The port on the local computer</param>
|
||||
/// <param name="remotePort">The port that the FPGA is using</param>
|
||||
/// <param name="remoteAddress">The address that the FPGA is using</param>
|
||||
public CommFpgaEthernet(string name, int localPort, int remotePort, string remoteAddress)
|
||||
{
|
||||
_name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
_state = State.Uninitialized;
|
||||
|
||||
_localPort = localPort;
|
||||
_remotePort = remotePort;
|
||||
_remoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a FPGA Ethernet called " + _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
Initialize(string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fpga"></param>
|
||||
public void Initialize(string fpga)
|
||||
{
|
||||
//5 second timeout
|
||||
const int TIMEOUT = 5000;
|
||||
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_udpClient = new UdpClient(_localPort);
|
||||
|
||||
_udpClient.Client.ReceiveBufferSize = int.MaxValue;
|
||||
|
||||
_udpClient.Client.SendBufferSize = int.MaxValue;
|
||||
|
||||
_udpClient.Client.SendTimeout = TIMEOUT;
|
||||
|
||||
_udpClient.Client.ReceiveTimeout = TIMEOUT;
|
||||
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString() + " on card " + _name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
return _selfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a single register
|
||||
/// </summary>
|
||||
/// <param name="page">The page of the register to read from</param>
|
||||
/// <param name="address">The register address to read from</param>
|
||||
/// <returns>The data at the address</returns>
|
||||
public uint Read(string fpgaName, uint address)
|
||||
{
|
||||
// lock up the FPGA resource
|
||||
lock (_syncObj)
|
||||
{
|
||||
FPGACmdMessage cmd = new FPGAReadRegisterCmdMessage((FPGACmdMessage.Page)0, address);
|
||||
|
||||
// this get populated in SendCommandGetResponse()
|
||||
FPGARspMessage rsp = new FPGAReadRegisterRspMessage(0, 0);
|
||||
|
||||
SendCommandGetResponse(cmd, ref rsp);
|
||||
|
||||
return rsp.GetData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fpgaName"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="numberOfWordsToRead"></param>
|
||||
/// <param name="dataRead"></param>
|
||||
/// <param name="shallWeIncrementAddress"></param>
|
||||
public void ReadBlock(string fpgaName, uint address, uint numberOfWordsToRead, bool shallWeIncrementAddress, ref uint[] dataRead)
|
||||
{
|
||||
// lock up the FPGA resource
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (shallWeIncrementAddress)
|
||||
{
|
||||
FPGACmdMessage cmd = new FPGAReadRegisterCmdBlockIncrMessage((FPGACmdMessage.Page)0, address, numberOfWordsToRead, false);
|
||||
|
||||
// this get populated in SendCommandGetResponse()
|
||||
FPGARspMessage rsp = new FPGAReadRegisterBlockIncrRspMessage(0, ref dataRead);
|
||||
|
||||
SendCommandGetResponse(cmd, ref rsp);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Not Implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Shutdown();
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
// lock up the FPGA resource
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
_udpClient.Close();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write to a single register
|
||||
/// </summary>
|
||||
/// <param name="page">The page of the register to read from</param>
|
||||
/// <param name="address">The address to write to</param>
|
||||
/// <param name="value">The data to write</param>
|
||||
public void Write(string fpgaName, uint address, uint value)
|
||||
{
|
||||
// lock up the FPGA resource
|
||||
lock (_syncObj)
|
||||
{
|
||||
FPGACmdMessage cmd = new FPGAWriteRegisterCmdMessage((FPGACmdMessage.Page)0, address, value);
|
||||
|
||||
// this get populated in SendCommandGetResponse()
|
||||
FPGARspMessage rsp = new FPGAWriteRegisterRspMessage(0, 0);
|
||||
|
||||
SendCommandGetResponse(cmd, ref rsp);
|
||||
|
||||
if (rsp.GetAddress() != address)
|
||||
{
|
||||
throw new Exception("Command write on address: " + address.ToString("X8") + ", received address: " + rsp.GetAddress().ToString("X8"));
|
||||
}
|
||||
else if (rsp.GetData() != 0xace0beef)
|
||||
{
|
||||
throw new Exception("Command write on address: " + address.ToString("X8") + " returned value: " + rsp.GetData().ToString("X8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fpgaName"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="numberOfBytes"></param>
|
||||
/// <param name="data"></param>
|
||||
public void WriteBlock(string fpgaName, uint address, uint numberOfWordsToWrite, uint[] data, bool shallWeIncrementAddress)
|
||||
{
|
||||
// lock up the FPGA resource
|
||||
lock (_syncObj)
|
||||
{
|
||||
FPGACmdMessage cmd = null;
|
||||
|
||||
if (shallWeIncrementAddress)
|
||||
{
|
||||
cmd = new FPGAWriteRegisterCmdBlockIncrMessage((FPGACmdMessage.Page)0, address, data, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = new FPGAWriteRegisterCmdBlockMessage((FPGACmdMessage.Page)0, address, data, false);
|
||||
}
|
||||
|
||||
// this get populated in SendCommandGetResponse()
|
||||
FPGARspMessage rsp = new FPGAWriteRegisterRspMessage(0, 0);
|
||||
|
||||
SendCommandGetResponse(cmd, ref rsp);
|
||||
|
||||
if (rsp.GetAddress() != address)
|
||||
{
|
||||
throw new Exception("Command write on address: " + address.ToString("X8") + ", received address: " + rsp.GetAddress().ToString("X8"));
|
||||
}
|
||||
else if (rsp.GetData() != 0xace0beef)
|
||||
{
|
||||
throw new Exception("Command write on address: " + address.ToString("X8") + " returned value: " + rsp.GetData().ToString("X8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="incrementAddress"></param>
|
||||
/// <param name="byteSwap"></param>
|
||||
public void WriteRegister(uint page, uint address, uint[] data, bool incrementAddress = true, bool byteSwap = true)
|
||||
{
|
||||
// lock up the FPGA resource
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (page > (uint)FPGACmdMessage.Page.PAGE3)
|
||||
{
|
||||
throw new Exception("input parameter 'page' is out of range: " + page.ToString());
|
||||
}
|
||||
|
||||
FPGACmdMessage cmd;
|
||||
|
||||
if (incrementAddress)
|
||||
{
|
||||
cmd = new FPGAWriteRegisterCmdBlockIncrMessage((FPGACmdMessage.Page)page, address, data, byteSwap);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = new FPGAWriteRegisterCmdBlockMessage((FPGACmdMessage.Page)page, address, data, byteSwap);
|
||||
}
|
||||
|
||||
|
||||
// this get populated in SendCommandGetResponse()
|
||||
FPGARspMessage rsp = new FPGAWriteRegisterRspMessage(0, 0);
|
||||
|
||||
SendCommandGetResponse(cmd, ref rsp);
|
||||
|
||||
if (rsp.GetAddress() != address)
|
||||
{
|
||||
throw new Exception("Command write on address: " + address.ToString("X8") + ", received address: " + rsp.GetAddress().ToString("X8"));
|
||||
}
|
||||
else if (rsp.GetData() != 0xace0beef)
|
||||
{
|
||||
throw new Exception("Command write on address: " + address.ToString("X8") + " returned value: " + rsp.GetData().ToString("X8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads firmware
|
||||
/// </summary>
|
||||
/// <param name="fpgaName"></param>
|
||||
public void LoadFirmware(string fpgaName)
|
||||
{
|
||||
Initialize(fpgaName);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// **********************************************************************************************************
|
||||
// CommFpgaEthernetFactory.cs
|
||||
// 2/20/2023
|
||||
// NGI - Next Generation Interceptor
|
||||
//
|
||||
// Contract No. HQ0856-21-C-0003/1022000209
|
||||
//
|
||||
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
|
||||
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
|
||||
//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
|
||||
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
|
||||
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
|
||||
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
|
||||
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
|
||||
// RAYTHEON COMPANY.
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
|
||||
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
|
||||
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
|
||||
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
|
||||
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
|
||||
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
|
||||
//
|
||||
// CONTROLLED BY: MISSILE DEFENSE AGENCY
|
||||
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
|
||||
// CUI CATEGORY: CTI
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// POC: Alex Kravchenko (1118268)
|
||||
// **********************************************************************************************************
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "CommFpgaEthernetFactory")]
|
||||
public class CommFpgaEthernetFactory : IInstrumentFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// The supported interfaces
|
||||
/// </summary>
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
private ILogger _logger;
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
public CommFpgaEthernetFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// COECommDeviceInstrumentFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public CommFpgaEthernetFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IFpgaComm));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new CommFpgaEthernet(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public object GetInstrument(string name, bool simulateHw)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
if (simulateHw)
|
||||
return new CommFpgaSim(name, _configurationManager, _logger);
|
||||
else
|
||||
return new CommFpgaEthernet(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets supported interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static IConfigurationManager GetConfigurationManager()
|
||||
{
|
||||
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.FPGA.Ethernet</AssemblyName>
|
||||
<Product>FPGA Ethernet implementation</Product>
|
||||
<Description>FPGA Ethernet implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.FpgaComm.Contracts" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FpgaSim\FpgaSim.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Copy all *.dlls and *.pdb in the output folder to a temp folder -->
|
||||
<Target Name="CopyFiles" AfterTargets="AfterBuild">
|
||||
<ItemGroup>
|
||||
<FILES_1 Include="$(OutDir)*.dll" />
|
||||
<FILES_2 Include="$(OutDir)*.pdb" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(FILES_1)" DestinationFolder="$(HalTempFolder)" />
|
||||
<Copy SourceFiles="@(FILES_2)" DestinationFolder="$(HalTempFolder)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,227 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract base class for FPGACmdMessages that go between the client and server
|
||||
/// </summary>
|
||||
internal abstract class FPGACmdMessage : ICloneable
|
||||
{
|
||||
#region PublicClassMembers
|
||||
public enum Page
|
||||
{
|
||||
PAGE0,
|
||||
PAGE1,
|
||||
PAGE2,
|
||||
PAGE3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PrivateClassMembers
|
||||
private readonly string m_description;
|
||||
|
||||
protected FPGACmdMessageHeader m_header;
|
||||
|
||||
protected static void SwapWord(ref byte[] input)
|
||||
{
|
||||
//Word Size
|
||||
int WORD_SIZE = 4;
|
||||
|
||||
for (int i = 0; i < input.Length; i = i + WORD_SIZE)
|
||||
{
|
||||
//Temp array for swap
|
||||
byte[] temp = new byte[WORD_SIZE];
|
||||
|
||||
//Copy a word into temp
|
||||
Buffer.BlockCopy(input, i, temp, 0, WORD_SIZE);
|
||||
|
||||
//Swap bytes
|
||||
Array.Reverse(temp);
|
||||
|
||||
//Replace word
|
||||
Buffer.BlockCopy(temp, 0, input, i, WORD_SIZE);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PrivateFuctions
|
||||
/// <summary>
|
||||
/// A command message constructor for all children to invoke
|
||||
/// </summary>
|
||||
/// <param name="commandType">The command message id</param>
|
||||
/// <param name="page">The page of the command message</param>
|
||||
/// <param name="description">The description of the command message</param>
|
||||
protected FPGACmdMessage(FPGACmdMsgIds commandType, Page page, string description)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_description = description;
|
||||
m_header = new FPGACmdMessageHeader(commandType, page);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy Constructor
|
||||
/// </summary>
|
||||
/// <param name="FPGACmdMessage">The FPGACmdMessage to copy from</param>
|
||||
protected FPGACmdMessage(FPGACmdMessage FPGACmdMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_header = new FPGACmdMessageHeader(FPGACmdMessage.m_header);
|
||||
m_description = FPGACmdMessage.m_description;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A clone function for the children to implement
|
||||
/// </summary>
|
||||
/// <returns>a clone of the child object</returns>
|
||||
protected abstract object CloneSelf();
|
||||
|
||||
/// <summary>
|
||||
/// A function to encode outgoing data
|
||||
/// </summary>
|
||||
/// <param name="pData">a pointer to the encoded data</param>
|
||||
protected abstract void FormatData(IntPtr pData);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract int GetPayloadSize();
|
||||
|
||||
/// <summary>
|
||||
/// a function to decode incoming data
|
||||
/// </summary>
|
||||
/// <param name="pData">A pointer to data to populate this object with</param>
|
||||
protected abstract void ParseData(IntPtr pData);
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
|
||||
/// <summary>
|
||||
/// Get a copy of the FPGACmdMessage object
|
||||
/// </summary>
|
||||
/// <returns>A clone of this object</returns>
|
||||
public object Clone()
|
||||
{
|
||||
// tell the child to clone itself
|
||||
return this.CloneSelf();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the FPGACmdMessage into a byte array for sending
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the FPGACmdMessage items</param>
|
||||
public void Format(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_header.Format(pData);
|
||||
|
||||
IntPtr pPayload = IntPtr.Add(pData, (int)GetHeaderLength());
|
||||
|
||||
// ask child class to format its data
|
||||
FormatData(pPayload);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Getter for the description
|
||||
/// </summary>
|
||||
/// <returns>The description</returns>
|
||||
public string GetDescription()
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the message id
|
||||
/// </summary>
|
||||
/// <returns>The id</returns>
|
||||
public FPGACmdMsgIds GetMessageId()
|
||||
{
|
||||
return m_header.GetMessageId();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the header length
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes in the header</returns>
|
||||
public uint GetHeaderLength()
|
||||
{
|
||||
return m_header.GetHeaderLength();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public uint GetEntireMsgLength()
|
||||
{
|
||||
return m_header.GetHeaderLength() + (uint)GetPayloadSize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the FPGACmdMessage object
|
||||
/// </summary>
|
||||
/// <param name="pData">The FPGACmdMessage in byte form</param>
|
||||
public void Parse(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_header.Parse(pData);
|
||||
|
||||
IntPtr pPayLoad = IntPtr.Add(pData, (int)GetHeaderLength());
|
||||
|
||||
ParseData(pPayLoad);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this FPGACmdMessage into string form
|
||||
/// </summary>
|
||||
/// <returns>The FPGACmdMessage in string form</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string desc = "Description: " + GetDescription() + "\n" + m_header.ToString();
|
||||
|
||||
return desc;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// The header for all command messages
|
||||
/// </summary>
|
||||
internal class FPGACmdMessageHeader
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private const int m_HEADER_SIZE = 1;
|
||||
private byte m_headerCmd;
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="header">The header to copy</param>
|
||||
public FPGACmdMessageHeader(FPGACmdMessageHeader header)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_headerCmd = header.m_headerCmd;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for when receiving data.
|
||||
/// Use this constructor and then parse to populate it
|
||||
/// </summary>
|
||||
public FPGACmdMessageHeader()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_headerCmd = 0;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for sending
|
||||
/// </summary>
|
||||
/// <param name="commandType">the type of the message</param>
|
||||
/// <param name="page">The page to read or write to</param>
|
||||
public FPGACmdMessageHeader(FPGACmdMsgIds commandType, FPGACmdMessage.Page page)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_headerCmd = (byte)((byte)commandType | (byte)page);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the header into a byte array for sending
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
public void Format(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
Marshal.StructureToPtr(m_headerCmd, pData, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the number of bytes in the header
|
||||
/// </summary>
|
||||
/// <returns>The header length in bytes</returns>
|
||||
public uint GetHeaderLength()
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_HEADER_SIZE;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the message id
|
||||
/// </summary>
|
||||
/// <returns>The message id</returns>
|
||||
public FPGACmdMsgIds GetMessageId()
|
||||
{
|
||||
byte temp = (byte)(m_headerCmd >> 4);
|
||||
return (FPGACmdMsgIds)temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the header object
|
||||
/// </summary>
|
||||
/// <param name="pData">The header in byte form</param>
|
||||
public void Parse(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_headerCmd = System.Runtime.InteropServices.Marshal.ReadByte(pData, 0);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string version of the header members
|
||||
/// </summary>
|
||||
/// <returns>A string containning the header data</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = "Header Data:\r\n";
|
||||
msg += "Command: " + m_headerCmd.ToString("X") + "\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
#region PublicClassMembers
|
||||
/// <summary>
|
||||
/// The command message IDs for messages that go between the host pc and the fpga
|
||||
/// </summary>
|
||||
internal enum FPGACmdMsgIds
|
||||
{
|
||||
TYPE_TWO_READ_CMD_ID = 0x40,
|
||||
TYPE_TWO_WRITE_CMD_ID = 0xC0,
|
||||
TYPE_THREE_READ_CMD_ID = 0x58,
|
||||
TYPE_THREE_WRITE_CMD_ID = 0xD8
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The command message IDs for messages that go between the host pc and the fpga
|
||||
/// </summary>
|
||||
internal enum FPGARspMsgIds
|
||||
{
|
||||
TYPE_TWO_READ_RSP_ID = 0xC0,
|
||||
TYPE_TWO_WRITE_RSP_ID = 0xAA,
|
||||
TYPE_THREE_WRITE_RSP_ID = 0x0
|
||||
};
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// A message to read a register of the FPGA
|
||||
/// </summary>
|
||||
internal class FPGAReadRegisterCmdBlockIncrMessage : FPGACmdMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
};
|
||||
|
||||
private Data m_dataStruct;
|
||||
|
||||
//Dummy Array used to identify how much data will be sent back
|
||||
private byte[] m_data;
|
||||
|
||||
private bool m_byteSwap;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAReadRegisterCmdBlockIncrMessage msg = new FPGAReadRegisterCmdBlockIncrMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// perform byte swapping and copy data into the buffer
|
||||
Data dataTemp = m_dataStruct;
|
||||
|
||||
//Swap address bytes
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
|
||||
//Create a pointer to message we want to send
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
|
||||
//Increment pointer to account for the m_dataStruct struct
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
|
||||
//Copy array into pointer
|
||||
Marshal.Copy(m_data, 0, pData, m_data.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(m_dataStruct) + m_data.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// copy data into our structure
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
|
||||
//Increment point address to end of structure
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
|
||||
//Copy data from pointer to array
|
||||
Marshal.Copy(pData, m_data, 0, m_data.Length);
|
||||
|
||||
//swap address
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAReadRegisterCmdBlockIncrMessage(FPGAReadRegisterCmdBlockIncrMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
m_byteSwap = rhs.m_byteSwap;
|
||||
m_data = rhs.m_data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for sending
|
||||
/// </summary>
|
||||
/// <param name="page">The page to read from</param>
|
||||
/// <param name="address">The address to read</param>
|
||||
public FPGAReadRegisterCmdBlockIncrMessage(Page page, uint address, uint numWords, bool swapDataBytes)
|
||||
: base(FPGACmdMsgIds.TYPE_THREE_READ_CMD_ID, page, "Read Register Command")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_byteSwap = swapDataBytes;
|
||||
|
||||
//Create an empty array the size of numWords
|
||||
m_data = new byte[numWords * sizeof(uint)];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns>A string representing this message</returns>
|
||||
public override String ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString() + "\r\n\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// A message to read a register of the FPGA
|
||||
/// </summary>
|
||||
internal class FPGAReadRegisterCmdMessage : FPGACmdMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
public uint m_spare;
|
||||
};
|
||||
|
||||
private Data m_dataStruct;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAReadRegisterCmdMessage msg = new FPGAReadRegisterCmdMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// perform byte swapping and copy data into the buffer
|
||||
Data dataTemp = m_dataStruct;
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(m_dataStruct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// copy data into our structure and byte swap
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAReadRegisterCmdMessage(FPGAReadRegisterCmdMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for sending
|
||||
/// </summary>
|
||||
/// <param name="page">The page to read from</param>
|
||||
/// <param name="address">The address to read</param>
|
||||
public FPGAReadRegisterCmdMessage(Page page, uint address)
|
||||
: base(FPGACmdMsgIds.TYPE_TWO_READ_CMD_ID, page, "Read Register Command")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns>A string representing this message</returns>
|
||||
public override String ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString("X8") + "\r\n\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// The response message for the FPGAReadRegisterCmdMessage
|
||||
/// </summary>
|
||||
internal class FPGAReadRegisterBlockIncrRspMessage : FPGARspMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
public uint m_data;
|
||||
};
|
||||
|
||||
//array for all received data (address/data)
|
||||
private Data[] m_dataArray;
|
||||
|
||||
//Array(ref) for received data (data only)
|
||||
private uint[] m_refArray;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAReadRegisterBlockIncrRspMessage msg = new FPGAReadRegisterBlockIncrRspMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
//From base class. Data does not need to be formatted (will not be sent out)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
//Size of Data (address and data) * number of elements
|
||||
return Marshal.SizeOf(typeof(Data)) * m_dataArray.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_dataArray.Length; i++)
|
||||
{
|
||||
//Copy data into the structure
|
||||
m_dataArray[i] = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
|
||||
//Increment pointer
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
|
||||
//Swap Address
|
||||
m_dataArray[i].m_address = Util.Swap(m_dataArray[i].m_address);
|
||||
|
||||
//Swap Data
|
||||
m_dataArray[i].m_data = Util.Swap(m_dataArray[i].m_data);
|
||||
|
||||
//Move data into referenced array
|
||||
m_refArray[i] = m_dataArray[i].m_data;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAReadRegisterBlockIncrRspMessage(FPGAReadRegisterBlockIncrRspMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataArray = rhs.m_dataArray;
|
||||
m_refArray = rhs.m_refArray;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="address">The address that was read from from</param>
|
||||
/// <param name="data">The data that was read</param>
|
||||
public FPGAReadRegisterBlockIncrRspMessage(uint address, ref uint[] data)
|
||||
: base(FPGARspMsgIds.TYPE_TWO_READ_RSP_ID, "Read Register Response Message")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataArray = new Data[data.Length];
|
||||
|
||||
m_refArray = data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the address
|
||||
/// </summary>
|
||||
/// <returns>TThe address</returns>
|
||||
public override uint GetAddress()
|
||||
{
|
||||
//Array of data. This function would need to change
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the data
|
||||
/// </summary>
|
||||
/// <returns>The data</returns>
|
||||
public override uint GetData()
|
||||
{
|
||||
//Array of data. This function would need to change
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns>The string form of this object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
for (int i = 0; i < m_dataArray.Length; i++)
|
||||
{
|
||||
msg += " address: " + m_dataArray[i].m_address.ToString("X8") + "\r\n";
|
||||
msg += " data: " + m_dataArray[i].m_data.ToString("X8") + "\r\n\r\n";
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// The response message for the FPGAReadRegisterCmdMessage
|
||||
/// </summary>
|
||||
internal class FPGAReadRegisterRspMessage : FPGARspMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
public uint m_data;
|
||||
};
|
||||
|
||||
private Data m_dataStruct;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAReadRegisterRspMessage msg = new FPGAReadRegisterRspMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// perform byte swapping and copy data into the buffer
|
||||
Data dataTemp = m_dataStruct;
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
dataTemp.m_data = Util.Swap(dataTemp.m_data);
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(typeof(Data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// copy data into our structure and byte swap
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
m_dataStruct.m_data = Util.Swap(m_dataStruct.m_data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAReadRegisterRspMessage(FPGAReadRegisterRspMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="address">The address that was read from from</param>
|
||||
/// <param name="data">The data that was read</param>
|
||||
public FPGAReadRegisterRspMessage(uint address, uint data)
|
||||
: base(FPGARspMsgIds.TYPE_TWO_READ_RSP_ID, "Read Register Response Message")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_dataStruct.m_data = data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the address
|
||||
/// </summary>
|
||||
/// <returns>TThe address</returns>
|
||||
public override uint GetAddress()
|
||||
{
|
||||
return m_dataStruct.m_address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the data
|
||||
/// </summary>
|
||||
/// <returns>The data</returns>
|
||||
public override uint GetData()
|
||||
{
|
||||
return m_dataStruct.m_data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns>The string form of this object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString("X8") + "\r\n";
|
||||
msg += " data: " + m_dataStruct.m_data.ToString("X8") + "\r\n\r\n";
|
||||
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract base class for FPGARspMessages that go between the client and server
|
||||
/// </summary>
|
||||
internal abstract class FPGARspMessage : ICloneable
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
protected FPGARspMessageHeader m_header;
|
||||
private readonly string m_description;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor that the children will call
|
||||
/// </summary>
|
||||
/// <param name="commandType">The message id</param>
|
||||
/// <param name="description">The message description</param>
|
||||
protected FPGARspMessage(FPGARspMsgIds commandType, string description)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_description = description;
|
||||
m_header = new FPGARspMessageHeader(commandType);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy Constructor
|
||||
/// </summary>
|
||||
/// <param name="FPGARspMessage">The FPGARspMessage to copy from</param>
|
||||
protected FPGARspMessage(FPGARspMessage FPGARspMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_header = new FPGARspMessageHeader(FPGARspMessage.m_header);
|
||||
m_description = FPGARspMessage.m_description;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A function to create a copy of the object for all children to implement
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract object CloneSelf();
|
||||
|
||||
/// <summary>
|
||||
/// A function to encode data for sending
|
||||
/// </summary>
|
||||
/// <param name="pData">A pointer to the spot to put the encoded data</param>
|
||||
protected abstract void FormatData(IntPtr pData);
|
||||
|
||||
/// <summary>
|
||||
/// Get the size of the payload
|
||||
/// </summary>
|
||||
/// <returns>The size of the message payload</returns>
|
||||
protected abstract int GetPayloadSize();
|
||||
|
||||
/// <summary>
|
||||
/// A function to decode data that was received
|
||||
/// </summary>
|
||||
/// <param name="pData">A pointer to the data to decode</param>
|
||||
protected abstract void ParseData(IntPtr pData);
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Get a copy of the FPGARspMessage object
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object Clone()
|
||||
{
|
||||
// tell the child to clone itself
|
||||
return this.CloneSelf();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the FPGARspMessage into a byte array for sending
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the FPGARspMessage items</param>
|
||||
public void Format(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_header.Format(pData);
|
||||
|
||||
IntPtr pPayload = IntPtr.Add(pData, (int)GetHeaderLength());
|
||||
|
||||
// ask child class to format its data
|
||||
FormatData(pPayload);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A getter function for the children to implement
|
||||
/// </summary>
|
||||
/// <returns>The address that was read</returns>
|
||||
public abstract uint GetAddress();
|
||||
|
||||
/// <summary>
|
||||
/// A getter function for the children to implement
|
||||
/// </summary>
|
||||
/// <returns>The data that was read</returns>
|
||||
public abstract uint GetData();
|
||||
|
||||
/// <summary>
|
||||
/// Getter for this message description
|
||||
/// </summary>
|
||||
/// <returns>The description</returns>
|
||||
public string GetDescription()
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Getter for the number of bytes in the entire message
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes in the FPGARspMessage, including header</returns>
|
||||
public uint GetEntireMsgLength()
|
||||
{
|
||||
return GetHeaderLength() + (uint)GetPayloadSize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the number of bytes in the header
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes in the head</returns>
|
||||
public uint GetHeaderLength()
|
||||
{
|
||||
return m_header.GetHeaderLength();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the FPGARspMessage object
|
||||
/// </summary>
|
||||
/// <param name="pData">The FPGARspMessage in byte form</param>
|
||||
public void Parse(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_header.Parse(pData);
|
||||
|
||||
IntPtr pPayLoad = IntPtr.Add(pData, (int)GetHeaderLength());
|
||||
|
||||
ParseData(pPayLoad);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this FPGARspMessage into string form
|
||||
/// </summary>
|
||||
/// <returns>The FPGARspMessage in string form</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return "Description: " + GetDescription() + "\n" + m_header.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// The header for the response messages
|
||||
/// </summary>
|
||||
internal class FPGARspMessageHeader
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private const int m_HEADER_SIZE = 0;
|
||||
private const uint m_ENTIRE_MSG_SIZE = 8;
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="header">The header to copy</param>
|
||||
public FPGARspMessageHeader(FPGARspMessageHeader header)
|
||||
{
|
||||
try
|
||||
{
|
||||
// m_data = header.m_data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for when receiving data.
|
||||
/// Use this constructor and then parse to populate it
|
||||
/// </summary>
|
||||
public FPGARspMessageHeader()
|
||||
{
|
||||
try
|
||||
{
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for sending
|
||||
/// </summary>
|
||||
/// <param name="commandType">the type of the message</param>
|
||||
public FPGARspMessageHeader(FPGARspMsgIds commandType)
|
||||
{
|
||||
try
|
||||
{
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the header into a byte array for sending
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
public void Format(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Getter for the entire message length in bytes
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes in the message, including header</returns>
|
||||
public uint GetEntireMsgLength()
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_ENTIRE_MSG_SIZE;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the header length in bytes
|
||||
/// </summary>
|
||||
/// <returns>The header length in bytes</returns>
|
||||
public uint GetHeaderLength()
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_HEADER_SIZE;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the header object
|
||||
/// </summary>
|
||||
/// <param name="pData">The header in byte form</param>
|
||||
public void Parse(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// copy data into our structure and byte swap
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string version of the header members
|
||||
/// </summary>
|
||||
/// <returns>A string containning the header data</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = "Header Data:\r\n\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal class FPGAWriteRegisterCmdBlockIncrMessage : FPGACmdMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
};
|
||||
|
||||
private byte[] m_data;
|
||||
|
||||
private Data m_dataStruct;
|
||||
|
||||
private bool m_byteSwap;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAWriteRegisterCmdBlockIncrMessage msg = new FPGAWriteRegisterCmdBlockIncrMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Temporary storage for message data
|
||||
Data dataTemp = m_dataStruct;
|
||||
|
||||
//address swap
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
|
||||
//Do we need to swap bytes
|
||||
if (m_byteSwap == true)
|
||||
{
|
||||
SwapWord(ref m_data);
|
||||
}
|
||||
|
||||
//Pointer to message
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
Marshal.Copy(m_data, 0, pData, m_data.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(m_dataStruct) + m_data.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
//copy data into our structure
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
Marshal.Copy(pData, m_data, 0, m_data.Length);
|
||||
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
|
||||
//Swap data if required
|
||||
if (m_byteSwap)
|
||||
{
|
||||
SwapWord(ref m_data);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAWriteRegisterCmdBlockIncrMessage(FPGAWriteRegisterCmdBlockIncrMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
m_byteSwap = rhs.m_byteSwap;
|
||||
m_data = rhs.m_data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for sending
|
||||
/// </summary>
|
||||
public FPGAWriteRegisterCmdBlockIncrMessage(Page page, uint address, byte[] data, bool swapDataBytes)
|
||||
: base(FPGACmdMsgIds.TYPE_THREE_WRITE_CMD_ID, page, "Write Register Command Increment Block")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_data = data;
|
||||
m_byteSwap = swapDataBytes;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="swapDataBytes"></param>
|
||||
public FPGAWriteRegisterCmdBlockIncrMessage(Page page, uint address, uint[] data, bool swapDataBytes)
|
||||
: base(FPGACmdMsgIds.TYPE_THREE_WRITE_CMD_ID, page, "Write Register Command Increment Block")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_byteSwap = swapDataBytes;
|
||||
|
||||
//Convert to Byte Array
|
||||
m_data = new byte[data.Length * sizeof(uint)];
|
||||
Buffer.BlockCopy(data, 0, m_data, 0, m_data.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString("X8") + "\r\n\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal class FPGAWriteRegisterCmdBlockMessage : FPGACmdMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
};
|
||||
|
||||
private byte[] m_data;
|
||||
|
||||
private Data m_dataStruct;
|
||||
|
||||
private bool m_byteSwap;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAWriteRegisterCmdBlockMessage msg = new FPGAWriteRegisterCmdBlockMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Temporary storage for message data
|
||||
Data dataTemp = m_dataStruct;
|
||||
|
||||
//address swap
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
|
||||
//Do we need to swap bytes
|
||||
if (m_byteSwap)
|
||||
{
|
||||
//Swap
|
||||
SwapWord(ref m_data);
|
||||
}
|
||||
|
||||
//Pointer to message
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
Marshal.Copy(m_data, 0, pData, m_data.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(m_dataStruct) + m_data.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
//copy data into our structure
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
pData = IntPtr.Add(pData, Marshal.SizeOf(typeof(Data)));
|
||||
Marshal.Copy(pData, m_data, 0, m_data.Length);
|
||||
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
|
||||
//Swap data if required
|
||||
if (m_byteSwap)
|
||||
{
|
||||
SwapWord(ref m_data);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAWriteRegisterCmdBlockMessage(FPGAWriteRegisterCmdBlockMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
m_byteSwap = rhs.m_byteSwap;
|
||||
m_data = rhs.m_data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for sending
|
||||
/// </summary>
|
||||
public FPGAWriteRegisterCmdBlockMessage(Page page, uint address, byte[] data, bool swapDataBytes)
|
||||
: base(FPGACmdMsgIds.TYPE_TWO_WRITE_CMD_ID, page, "Write Register Command Block")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_byteSwap = swapDataBytes;
|
||||
m_data = data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="swapDataBytes"></param>
|
||||
public FPGAWriteRegisterCmdBlockMessage(Page page, uint address, uint[] data, bool swapDataBytes)
|
||||
: base(FPGACmdMsgIds.TYPE_TWO_WRITE_CMD_ID, page, "Write Register Command Block")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_byteSwap = swapDataBytes;
|
||||
|
||||
m_data = new byte[data.Length * sizeof(uint)];
|
||||
Buffer.BlockCopy(data, 0, m_data, 0, m_data.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString("X8") + "\r\n\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// The message that targets the VRSUI to make a connection
|
||||
/// </summary>
|
||||
internal class FPGAWriteRegisterCmdMessage : FPGACmdMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
public uint m_data;
|
||||
};
|
||||
|
||||
private Data m_dataStruct;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAWriteRegisterCmdMessage msg = new FPGAWriteRegisterCmdMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// perform byte swapping and copy data into the buffer
|
||||
Data dataTemp = m_dataStruct;
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
dataTemp.m_data = Util.Swap(dataTemp.m_data);
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(m_dataStruct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// copy data into our structure and byte swap
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
m_dataStruct.m_data = Util.Swap(m_dataStruct.m_data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAWriteRegisterCmdMessage(FPGAWriteRegisterCmdMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for sending
|
||||
/// </summary>
|
||||
public FPGAWriteRegisterCmdMessage(Page page, uint address, uint data)
|
||||
: base(FPGACmdMsgIds.TYPE_TWO_WRITE_CMD_ID, page, "Write Register Command")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_dataStruct.m_data = data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString("X8") + "\r\n";
|
||||
msg += " data: " + m_dataStruct.m_data.ToString("X8") + "\r\n\r\n";
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace FpgaMeasurementInstrumentsLib
|
||||
{
|
||||
/// <summary>
|
||||
/// The response message from the VRSUI upon receiving a VrsConnectCmdMessage
|
||||
/// </summary>
|
||||
internal class FPGAWriteRegisterRspMessage : FPGARspMessage
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct Data
|
||||
{
|
||||
public uint m_address;
|
||||
public uint m_data;
|
||||
};
|
||||
|
||||
private Data m_dataStruct;
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of this object
|
||||
/// </summary>
|
||||
/// <returns>A copy of this object</returns>
|
||||
protected override object CloneSelf()
|
||||
{
|
||||
FPGAWriteRegisterRspMessage msg = new FPGAWriteRegisterRspMessage(this);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode the message into a byte array for sending.
|
||||
/// </summary>
|
||||
/// <param name="pData">The buffer to put the message items</param>
|
||||
protected override void FormatData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// perform byte swapping and copy data into the buffer
|
||||
Data dataTemp = m_dataStruct;
|
||||
dataTemp.m_address = Util.Swap(dataTemp.m_address);
|
||||
dataTemp.m_data = Util.Swap(dataTemp.m_data);
|
||||
Marshal.StructureToPtr(dataTemp, pData, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override int GetPayloadSize()
|
||||
{
|
||||
return Marshal.SizeOf(typeof(Data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an array of bytes and populates the message object
|
||||
/// </summary>
|
||||
/// <param name="pData">The message in byte form</param>
|
||||
protected override void ParseData(IntPtr pData)
|
||||
{
|
||||
try
|
||||
{
|
||||
// copy data into our structure and byte swap
|
||||
m_dataStruct = (Data)(Marshal.PtrToStructure(pData, typeof(Data)));
|
||||
m_dataStruct.m_address = Util.Swap(m_dataStruct.m_address);
|
||||
m_dataStruct.m_data = Util.Swap(m_dataStruct.m_data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs">The object to copy</param>
|
||||
public FPGAWriteRegisterRspMessage(FPGAWriteRegisterRspMessage rhs)
|
||||
: base(rhs)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct = rhs.m_dataStruct;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for sending
|
||||
/// </summary>
|
||||
/// <param name="address">The address to write to</param>
|
||||
/// <param name="data">The data to write</param>
|
||||
public FPGAWriteRegisterRspMessage(uint address, uint data)
|
||||
: base(FPGARspMsgIds.TYPE_TWO_WRITE_RSP_ID, "Write Register Response Message")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dataStruct.m_address = address;
|
||||
m_dataStruct.m_data = data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the address
|
||||
/// </summary>
|
||||
/// <returns>The address</returns>
|
||||
public override uint GetAddress()
|
||||
{
|
||||
return m_dataStruct.m_address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getter for the data
|
||||
/// </summary>
|
||||
/// <returns>The data</returns>
|
||||
public override uint GetData()
|
||||
{
|
||||
return m_dataStruct.m_data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this object into string form
|
||||
/// </summary>
|
||||
/// <returns>The string form of this object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string msg = base.ToString();
|
||||
msg += " address: " + m_dataStruct.m_address.ToString("X8") + "\r\n";
|
||||
msg += " data: " + m_dataStruct.m_data.ToString("X8") + "\r\n\r\n";
|
||||
|
||||
return msg;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user