Big changes

This commit is contained in:
Duc
2025-03-13 12:04:22 -07:00
parent c689fcb7f9
commit ffa9905494
748 changed files with 199255 additions and 3743 deletions

View File

@@ -0,0 +1,441 @@
// 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.Text;
namespace Raytheon.Instruments
{
/// <summary>
/// A class that implements the Teradyne HSS Test Station Card
/// </summary>
public class CommFpgaHssubCardTs : IFpgaComm
{
#region PrivateClassMembers
private string _name;
private readonly string _cardAddress;
private readonly int _startingOffset;
private readonly string _firmware;
private readonly uint _chassisHandle;
private readonly int _hssubAppSyncHandle;
private readonly int _hssubAppHandle;
private readonly string _memMap;
private SelfTestResult _selfTestResult;
private int _cardHandle;
private int _latestLbAddress;
private int _latestLbData;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
public string DetailedStatus => throw new NotImplementedException();
public bool DisplayEnabled { get => false; set => throw new NotImplementedException(); }
public bool FrontPanelEnabled { get => false; set => throw new NotImplementedException(); }
public InstrumentMetadata Info => throw new NotImplementedException();
public string Name { get => _name; set { _name = value; } }
public SelfTestResult SelfTestResult => PerformSelfTest();
public State Status => State.Ready;
#endregion
#region PrivateFuctions
/// <summary>
///
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
HssubNativeMethods.terHss_close(_chassisHandle);
}
}
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 void Initialize()
{
int ret = HssubNativeMethods.terHss_Application_SendMessage(_chassisHandle, _hssubAppHandle, HssubNativeMethods.MESSAGE_CONTEXT_INIT_INSTRUMENT, _cardAddress.Length, Encoding.ASCII.GetBytes(_cardAddress), HssubNativeMethods.TERHSS_TIMEOUT_60SEC);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _name);
throw new Exception("terHss_Application_SendMessage() returned an error(" + ret + ")" + ": " + errorStr);
}
LoadFirmware();
}
/// <summary>
///
/// </summary>
private void LoadFirmware()
{
// send the file to the subsystem
int ret = HssubNativeMethods.terHss_Subsystem_SendFile(_chassisHandle, _firmware, "c:\\temp\\FPGAFile.hsi", HssubNativeMethods.TERHSS_OPTION_ALLOW_OVERWRITE);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _name);
throw new Exception("terHss_SubSyste_SendFile() returned an error(" + ret + ")" + ": " + errorStr);
}
// load the instrument
ret = HssubNativeMethods.terHss_Application_SendMessage(_chassisHandle, _hssubAppHandle, HssubNativeMethods.MESSAGE_CONTEXT_LOAD_INSTRUMENT, 4, BitConverter.GetBytes(_cardHandle), HssubNativeMethods.TERHSS_TIMEOUT_60SEC);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _name);
throw new Exception("terHss_Application_SendMessage() returned an error(" + ret + ")" + ": " + errorStr);
}
// wait for the callback event
HssUtilTs.WaitForSync(_chassisHandle, _hssubAppSyncHandle, _name);
// delete the file
ret = HssubNativeMethods.terHss_Subsystem_DeleteFile(_chassisHandle, "c:\\temp\\FPGAFile.hsi", HssubNativeMethods.TERHSS_OPTION_NONE);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _name);
throw new Exception("terHss_SubSyste_DeleteFile() returned an error(" + ret + ")" + ": " + errorStr);
}
}
#endregion
#region PublicFuctions
/// <summary>
/// CommFpgaHssubCardTs factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public CommFpgaHssubCardTs(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_cardAddress = _configuration.GetConfigurationValue("CommFpgaHssubCardTs", "CardAddress", "127.0.0.1");
_startingOffset = _configuration.GetConfigurationValue("CommFpgaHssubCardTs", "StartingOffset", 0);
_firmware = _configuration.GetConfigurationValue("CommFpgaHssubCardTs", "Firmware", "");
_chassisHandle = _configuration.GetConfigurationValue<uint>("CommFpgaHssubCardTs", "ChassisHandle", 0);
_hssubAppHandle = _configuration.GetConfigurationValue("CommFpgaHssubCardTs", "HssubAppHandle", 0);
_hssubAppSyncHandle = _configuration.GetConfigurationValue("CommFpgaHssubCardTs", "HssubAppSyncHandle", 0);
_memMap = _configuration.GetConfigurationValue("CommFpgaHssubCardTs", "MemMap", "");
_cardHandle = 0;
// this gets set by the HssubChassis when a LB Read callback arrives
_latestLbAddress = -1;
_latestLbData = -1;
Initialize();
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="cardAddress"></param>
/// <param name="startingOffset"></param>
/// <param name="firmware"></param>
/// <param name="chassisHandle"></param>
/// <param name="hssubAppHandle"></param>
/// <param name="hssubAppSyncHandle"></param>
public CommFpgaHssubCardTs(string name, string cardAddress, int startingOffset, string firmware, uint chassisHandle, int hssubAppHandle, int hssubAppSyncHandle, string memMap)
{
// hold onto args
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_cardAddress = cardAddress;
_startingOffset = startingOffset;
_firmware = firmware;
_chassisHandle = chassisHandle;
_hssubAppHandle = hssubAppHandle;
_hssubAppSyncHandle = hssubAppSyncHandle;
_memMap = memMap;
// this gets set by the HssubChassis in SetHandle()
_cardHandle = 0;
// this gets set by the HssubChassis when a LB Read callback arrives
_latestLbAddress = -1;
_latestLbData = -1;
Initialize();
}
/// <summary>
/// The finalizer.
/// </summary>
~CommFpgaHssubCardTs()
{
Dispose(false);
}
/// <summary>
///
/// </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>
/// <returns></returns>
public string GetMemMap()
{
return _memMap;
}
/// <summary>
///
/// </summary>
/// <param name="address"></param>
public uint Read(string fpgaName, uint address)
{
// populate the structure
HssUtilTs.LocalBusParams lbParams;
lbParams.cardHandle = _cardHandle;
lbParams.address = (int)(_startingOffset + address);
lbParams.data = 0;
// get the byte array
byte[] dataToSend = HssUtilTs.LocalBusParmsToByteArray(lbParams);
// reset the callback data items
_latestLbAddress = -1;
_latestLbData = -1;
// send the message
int ret = HssubNativeMethods.terHss_Application_SendMessage(_chassisHandle, _hssubAppHandle, HssubNativeMethods.MESSAGE_CONTEXT_LB_READ32, dataToSend.Length, dataToSend, HssubNativeMethods.TERHSS_TIMEOUT_10SEC);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _name);
throw new Exception("terHss_Application_SendMessage() returned an error(" + ret + ")" + ": " + errorStr);
}
// wait for the callback event
HssUtilTs.WaitForSync(_chassisHandle, _hssubAppSyncHandle, _name);
// confirm the address is what we requested (Set in SetLocalBusReadData())
if (_latestLbAddress != lbParams.address)
{
throw new Exception("Received address: " + _latestLbAddress.ToString("X8") + " Expected: " + lbParams.address.ToString("X8"));
}
return (uint)_latestLbData;
}
/// <summary>
///
/// </summary>
/// <param name="address"></param>
/// <param name="numberOfWordsToRead"></param>
/// <param name="shallWeIncrementAddress"></param>
/// <param name="dataRead"></param>
public void ReadBlock(string fpgaName, uint address, uint numberOfWordsToRead, bool shallWeIncrementAddress, ref uint[] dataRead)
{
throw new Exception("Not Implemented");
}
/// <summary>
///
/// </summary>
/// <param name="cardHandle"></param>
public void SetHandle(int cardHandle)
{
// this gets set in
_cardHandle = cardHandle;
}
/// <summary>
///
/// </summary>
/// <param name="address"></param>
/// <param name="data"></param>
public void SetLocalBusRxData(int address, int data)
{
_latestLbAddress = address;
_latestLbData = data;
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="value"></param>
public void Write(string fpgaName, uint address, uint value)
{
// populate the structure
HssUtilTs.LocalBusParams lbParams;
lbParams.cardHandle = _cardHandle;
lbParams.address = (int)(_startingOffset + address);
lbParams.data = (int)value;
// get the byte array
byte[] dataToSend = HssUtilTs.LocalBusParmsToByteArray(lbParams);
// reset the callback data items
_latestLbAddress = -1;
_latestLbData = -1;
// send the message
int ret = HssubNativeMethods.terHss_Application_SendMessage(_chassisHandle, _hssubAppHandle, HssubNativeMethods.MESSAGE_CONTEXT_LB_WRITE32, dataToSend.Length, dataToSend, HssubNativeMethods.TERHSS_TIMEOUT_10SEC);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _name);
throw new Exception("terHss_Application_SendMessage() returned an error(" + ret + ")" + ": " + errorStr);
}
// wait for the callback event
HssUtilTs.WaitForSync(_chassisHandle, _hssubAppSyncHandle, _name);
// confirm the address is what we requested (Set in SetLocalBusReadData())
/*if (_latestLbAddress != lbParams.address)
{
throw new Exception("Received address: " + _latestLbAddress.ToString("X8") + " Expected: " + lbParams.address.ToString("X8"));
}*/
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="numberOfWordsToWrite"></param>
/// <param name="data"></param>
/// <param name="shallWeIncrementAddress"></param>
public void WriteBlock(string fpgaName, uint address, uint numberOfWordsToWrite, uint[] data, bool shallWeIncrementAddress)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
public void Initialize(string fpgaName)
{
Initialize();
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
public void LoadFirmware(string fpgaName)
{
LoadFirmware();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
return false;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public SelfTestResult PerformSelfTest()
{
_selfTestResult = SelfTestResult.Unknown;
return _selfTestResult;
}
/// <summary>
///
/// </summary>
public void Reset()
{
Shutdown();
Initialize();
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
Dispose();
}
#endregion
}
}

View File

@@ -0,0 +1,139 @@
// **********************************************************************************************************
// CommFpgaHssubCardTsFactory.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 = "CommFpgaHssubCardTsFactory")]
public class CommFpgaHssubCardTsFactory : 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 CommFpgaHssubCardTsFactory(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 CommFpgaHssubCardTsFactory([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 CommFpgaHssubCardTs(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 CommFpgaHssubCardTs(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);
}
}
}

View File

@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.FPGA.HssubCardTs</AssemblyName>
<Product>FPGA HssubCardTs implementation</Product>
<Description>FPGA Hssub Card Ts implementation</Description>
<OutputType>Library</OutputType>
<!-- Static versioning (Suitable for Development) -->
<!-- Disable the line below for dynamic versioning -->
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</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>