// 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.Collections.Generic;
using NLog;
using Raytheon.Common;
namespace Raytheon.Instruments
{
///
/// A class that implements the Teradyne HSS Sub System Chassis
///
public unsafe class CommFpgaHssubChassisSs : IFpgaComm
{
#region PrivateClassMembers
#pragma warning disable CS0649
public struct CardInfo
{
internal string cardName;
internal string cardAddress;
internal int startingOffset;
internal string cardFirmwareFile;
internal string memMap;
}
#pragma warning restore
private object _syncObj = new Object();
private SortedDictionary _hssCardNameMap;
private List _cardList;
private SelfTestResult _selfTestResult;
private State _state;
private string _name;
private readonly ILogger _logger;
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#endregion
#region PrivateFuctions
///
/// The finalizer.
///
~CommFpgaHssubChassisSs()
{
Dispose(false);
}
///
///
///
///
///
///
///
private void CreateCard(string cardName, string cardAddress, int startingOffset, string cardFirmwareFile, string memMap)
{
lock (_syncObj)
{
// create the card
CommFpgaHssubCardSs card = new CommFpgaHssubCardSs(cardName, cardAddress, startingOffset, cardFirmwareFile, memMap);
// hold onto the card
_hssCardNameMap[cardName] = card;
}
}
///
///
///
///
public void LoadFirmware(string fpgaName)
{
// lock up the FPGA resource
lock (_syncObj)
{
_hssCardNameMap[fpgaName].LoadFirmware();
}
}
///
///
///
private void SelfTest()
{
// loop through each card and command self test
/*short testResults = -1;
StringBuilder errorStrTemp = new StringBuilder(512);
int ret = HssubNativeMethods.terHss_self_test(_chassisHandle, ref testResults, errorStrTemp);
if (ret != 0)
{
string errorStr = HssUtilTs.BuildErrorString(_chassisHandle, ret, _chassisLogicalName);
throw new Exception("terHss_self_test returned an error(" + ret + ")" + ": " + errorStr);
}
else if (testResults != 0)
{
throw new Exception("HSSub Self Test returned an error: " + testResults.ToString() + ": " + errorStrTemp.ToString());
}*/
}
///
/// Dispose of this object's resources.
///
/// True = currently disposing, False = not disposing.
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
lock (_syncObj)
{
if (_state == State.Ready)
{
foreach (KeyValuePair entry in _hssCardNameMap)
{
entry.Value.Dispose();
}
_state = State.Uninitialized;
}
}
}
}
#endregion
#region PublicFuctions
///
/// CommFpgaHssubChassisSs factory constructor
///
///
///
public CommFpgaHssubChassisSs(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_cardList = new List();
// hold onto the card objects
_hssCardNameMap = new SortedDictionary();
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
}
///
///
///
///
public CommFpgaHssubChassisSs(string deviceName)
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_cardList = new List();
// hold onto the card objects
_hssCardNameMap = new SortedDictionary();
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
}
///
///
///
///
public void AddCard(CardInfo cardInfo)
{
_cardList.Add(cardInfo);
}
///
///
///
///
public bool ClearErrors()
{
return false;
}
///
///
///
public string DetailedStatus
{
get
{
return "This is a FPGA HSS Chassis SS " + _name;
}
}
///
///
///
public bool DisplayEnabled
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
///
/// Dispose of this object's resources.
///
public void Dispose()
{
// lock up the FPGA resource
lock (_syncObj)
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
///
///
///
public bool FrontPanelEnabled
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
///
///
///
///
///
public string GetMemMap(string fpga)
{
// lock up the FPGA resource
lock (_syncObj)
{
return _hssCardNameMap[fpga].GetMemMap();
}
}
///
///
///
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
///
///
///
public void Initialize()
{
Initialize(string.Empty);
}
///
///
///
///
public void Initialize(string fpga)
{
// lock up the FPGA resource
lock (_syncObj)
{
if (_state == State.Uninitialized)
{
// init each card
for (int i = 0; i < _cardList.Count; i++)
{
CreateCard(_cardList[i].cardName, _cardList[i].cardAddress, _cardList[i].startingOffset, _cardList[i].cardFirmwareFile, _cardList[i].memMap);
}
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString() + " on card " + _name);
}
}
}
///
///
///
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
///
///
///
///
public SelfTestResult PerformSelfTest()
{
_selfTestResult = SelfTestResult.Unknown;
return _selfTestResult;
}
///
///
///
///
///
///
public uint Read(string fpgaName, uint address)
{
// lock up the FPGA resource
lock (_syncObj)
{
return _hssCardNameMap[fpgaName].Read(fpgaName, address);
}
}
///
///
///
///
///
///
///
public void ReadBlock(string fpgaName, uint address, uint numberOfWordsToRead, bool shallWeIncrementAddress, ref uint[] dataRead)
{
// lock up the FPGA resource
lock (_syncObj)
{
_hssCardNameMap[fpgaName].ReadBlock(fpgaName, address, numberOfWordsToRead, shallWeIncrementAddress, ref dataRead);
}
}
///
///
///
public void Reset()
{
lock (_syncObj)
{
throw new NotImplementedException();
}
}
///
///
///
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
///
///
///
public void Shutdown()
{
// lock up the FPGA resource
lock (_syncObj)
{
if (_state == State.Ready)
{
foreach (KeyValuePair entry in _hssCardNameMap)
{
entry.Value.Dispose();
}
_state = State.Uninitialized;
}
}
}
///
///
///
public State Status
{
get
{
return _state;
}
}
///
///
///
///
///
///
public void Write(string fpgaName, uint address, uint value)
{
// lock up the FPGA resource
lock (_syncObj)
{
_hssCardNameMap[fpgaName].Write(fpgaName, address, value);
}
}
///
///
///
///
///
///
///
///
public void WriteBlock(string fpgaName, uint address, uint numberOfWordsToWrite, uint[] data, bool shallWeIncrementAddress)
{
// lock up the FPGA resource
lock (_syncObj)
{
_hssCardNameMap[fpgaName].WriteBlock(fpgaName, address, numberOfWordsToWrite, data, shallWeIncrementAddress);
}
}
#endregion
}
}