Major upgrade
This commit is contained in:
@@ -15,11 +15,11 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
@@ -27,270 +27,237 @@ namespace Raytheon.Instruments
|
||||
/// A simulated video recorder
|
||||
/// </summary>
|
||||
public class VideoRecorderSim : IVideoRecorder
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private const string _SIM_VIDEO_FILE_NAME = "SimVideo";
|
||||
private string _lastGrabFileName;
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private const string _SIM_VIDEO_FILE_NAME = "SimVideo";
|
||||
private string _lastGrabFileName;
|
||||
|
||||
public string DetailedStatus { get; protected set; }
|
||||
public string DetailedStatus { get; protected set; }
|
||||
|
||||
public bool DisplayEnabled { get; set; }
|
||||
public bool FrontPanelEnabled { get; set; }
|
||||
public bool DisplayEnabled { get; set; }
|
||||
public bool FrontPanelEnabled { get; set; }
|
||||
|
||||
public InstrumentMetadata Info { get; set; }
|
||||
public InstrumentMetadata Info { get; set; }
|
||||
|
||||
public string Name { get; protected set; }
|
||||
public string Name { get; protected set; }
|
||||
|
||||
public SelfTestResult SelfTestResult => PerformSelfTest();
|
||||
public SelfTestResult SelfTestResult => PerformSelfTest();
|
||||
|
||||
public State Status { get; set; }
|
||||
public State Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
#endregion
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#region PrivateClassFunctions
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~VideoRecorderSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region PrivateClassFunctions
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~VideoRecorderSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#region PublicClassFunctions
|
||||
/// <summary>
|
||||
/// VideoRecorderSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public VideoRecorderSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
_logger = logger;
|
||||
#region PublicClassFunctions
|
||||
/// <summary>
|
||||
/// VideoRecorderSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public VideoRecorderSim(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
}
|
||||
/// <summary>
|
||||
/// The sim constructor
|
||||
/// </summary>
|
||||
public VideoRecorderSim()
|
||||
{
|
||||
_lastGrabFileName = "";
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="videoFile"></param>
|
||||
/// <param name="attributeFile"></param>
|
||||
public void AddNcdfAttributes(string videoFile, string attributeFile)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
}
|
||||
/// <summary>
|
||||
/// The sim constructor
|
||||
/// </summary>
|
||||
public VideoRecorderSim()
|
||||
{
|
||||
_lastGrabFileName = "";
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="videoFile"></param>
|
||||
/// <param name="attributeFile"></param>
|
||||
public void AddNcdfAttributes(string videoFile, string attributeFile)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
/// <summary>
|
||||
/// This will create an empty video file in the user temp folder
|
||||
/// </summary>
|
||||
/// <param name="numberOfFrames"></param>
|
||||
/// <param name="format"></param>
|
||||
public void GrabVideoToDisk(uint numberOfFrames, VideoSaveFormat format)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// create a dummy file
|
||||
string tempDirectory = Path.GetTempPath();
|
||||
/// <summary>
|
||||
/// This will create an empty video file in the user temp folder
|
||||
/// </summary>
|
||||
/// <param name="numberOfFrames"></param>
|
||||
/// <param name="format"></param>
|
||||
public void GrabVideoToDisk(uint numberOfFrames, VideoSaveFormat format)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
|
||||
string time = Util.GetTimeString();
|
||||
// create a dummy file
|
||||
string tempDirectory = Path.GetTempPath();
|
||||
|
||||
if (format == VideoSaveFormat.BIN)
|
||||
{
|
||||
tempDirectory += time + _SIM_VIDEO_FILE_NAME + ".bin";
|
||||
}
|
||||
else if (format == VideoSaveFormat.NCDF)
|
||||
{
|
||||
tempDirectory += time + _SIM_VIDEO_FILE_NAME + ".ncdf";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("UnhandledExceptionEventArgs save format" + format);
|
||||
}
|
||||
string time = Util.GetTimeString();
|
||||
|
||||
string simFileName = tempDirectory;
|
||||
if (format == VideoSaveFormat.BIN)
|
||||
{
|
||||
tempDirectory += time + _SIM_VIDEO_FILE_NAME + ".bin";
|
||||
}
|
||||
else if (format == VideoSaveFormat.NCDF)
|
||||
{
|
||||
tempDirectory += time + _SIM_VIDEO_FILE_NAME + ".ncdf";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("UnhandledExceptionEventArgs save format" + format);
|
||||
}
|
||||
|
||||
File.Create(simFileName);
|
||||
string simFileName = tempDirectory;
|
||||
|
||||
_lastGrabFileName = simFileName;
|
||||
}
|
||||
File.Create(simFileName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="driveSpace1">The number of free Gigabytes</param>
|
||||
/// <param name="driveSpace2">The number of free Gigabytes</param>
|
||||
/// <param name="driveSpace3">The number of free Gigabytes</param>
|
||||
/// <param name="driveSpace4">The number of free Gigabytes</param>
|
||||
public void QueryHardDrive(ref float driveSpace1, ref float driveSpace2, ref float driveSpace3, ref float driveSpace4)
|
||||
{
|
||||
const float FREE_SPACE_IN_GB = 10.0f;
|
||||
const float FULL_IN_GB = 0.0f;
|
||||
_lastGrabFileName = simFileName;
|
||||
}
|
||||
|
||||
driveSpace1 = FREE_SPACE_IN_GB;
|
||||
driveSpace2 = FULL_IN_GB;
|
||||
driveSpace3 = FULL_IN_GB;
|
||||
driveSpace4 = FULL_IN_GB;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="driveSpace1">The number of free Gigabytes</param>
|
||||
/// <param name="driveSpace2">The number of free Gigabytes</param>
|
||||
/// <param name="driveSpace3">The number of free Gigabytes</param>
|
||||
/// <param name="driveSpace4">The number of free Gigabytes</param>
|
||||
public void QueryHardDrive(ref float driveSpace1, ref float driveSpace2, ref float driveSpace3, ref float driveSpace4)
|
||||
{
|
||||
const float FREE_SPACE_IN_GB = 10.0f;
|
||||
const float FULL_IN_GB = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fromFile"></param>
|
||||
/// <param name="toFile"></param>
|
||||
/// <param name="control"></param>
|
||||
public void MoveFile(string fromFile, string toFile, MoveControl control)
|
||||
{
|
||||
File.Move(fromFile, toFile);
|
||||
}
|
||||
driveSpace1 = FREE_SPACE_IN_GB;
|
||||
driveSpace2 = FULL_IN_GB;
|
||||
driveSpace3 = FULL_IN_GB;
|
||||
driveSpace4 = FULL_IN_GB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void ShowLiveVideo()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fromFile"></param>
|
||||
/// <param name="toFile"></param>
|
||||
/// <param name="control"></param>
|
||||
public void MoveFile(string fromFile, string toFile, MoveControl control)
|
||||
{
|
||||
File.Move(fromFile, toFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void StopLiveVideo()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void ShowLiveVideo()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will return the file created by GrabVideoToDisk()
|
||||
/// </summary>
|
||||
/// <param name="timeoutms"></param>
|
||||
/// <returns></returns>
|
||||
public string WaitForGrabToComplete(int timeoutms)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void StopLiveVideo()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
// return the last file that was created, and clear the last file name for the next time
|
||||
string lastFileName = _lastGrabFileName;
|
||||
_lastGrabFileName = "";
|
||||
return lastFileName;
|
||||
}
|
||||
/// <summary>
|
||||
/// This will return the file created by GrabVideoToDisk()
|
||||
/// </summary>
|
||||
/// <param name="timeoutms"></param>
|
||||
/// <returns></returns>
|
||||
public string WaitForGrabToComplete(int timeoutms)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// return the last file that was created, and clear the last file name for the next time
|
||||
string lastFileName = _lastGrabFileName;
|
||||
_lastGrabFileName = "";
|
||||
return lastFileName;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
return SelfTestResult.Unknown;
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Shutdown();
|
||||
Initialize();
|
||||
}
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
return SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Disconnect();
|
||||
Dispose();
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
Shutdown();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public byte[] GetSmallVideoFrame(string name, int nFrames, bool sensor, ref uint numBytesRead, bool deleteVideoFile)
|
||||
{
|
||||
return new byte[1024];
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
public void Shutdown()
|
||||
{
|
||||
Disconnect();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public byte[] GetSmallVideoFrame(string name, int nFrames, bool sensor, ref uint numBytesRead, bool deleteVideoFile)
|
||||
{
|
||||
return new byte[1024];
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,71 +31,64 @@
|
||||
// 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;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "VideoRecorderSimFactory")]
|
||||
public class VideoRecorderSimFactory : 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;
|
||||
[ExportInstrumentFactory(ModelNumber = "VideoRecorderSimFactory")]
|
||||
public class VideoRecorderSimFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public VideoRecorderSimFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
/// <summary>
|
||||
/// COECommDeviceInstrumentFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public VideoRecorderSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public VideoRecorderSimFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
/// <summary>
|
||||
/// VideoRecorderSimFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public VideoRecorderSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IVideoRecorder));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new VideoRecorderSim(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
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(IVideoRecorder));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new VideoRecorderSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -106,9 +99,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
return new VideoRecorderSim(name, _configurationManager, _logger);
|
||||
return new VideoRecorderSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -121,17 +112,17 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,357 +15,315 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface to sending/receiving data over comm devices
|
||||
/// </summary>
|
||||
internal class CommDeviceNode : ICommDevice, IDisposable
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private ICommDevice _commDevice;
|
||||
private IWorkerInterface _socketReadWorker;
|
||||
private Thread _socketReadThread;
|
||||
private readonly string _name;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private State _state;
|
||||
/// <summary>
|
||||
/// An interface to sending/receiving data over comm devices
|
||||
/// </summary>
|
||||
internal class CommDeviceNode : ICommDevice, IDisposable
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private ICommDevice _commDevice;
|
||||
private IWorkerInterface _socketReadWorker;
|
||||
private Thread _socketReadThread;
|
||||
private readonly string _name;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private State _state;
|
||||
|
||||
private uint _commReadWorkerBufferSize;
|
||||
private uint _readWorkerRestTimeInMs;
|
||||
private MsgDevice _msgHandler;
|
||||
private uint _commReadWorkerBufferSize;
|
||||
private uint _readWorkerRestTimeInMs;
|
||||
private MsgDevice _msgHandler;
|
||||
private readonly ILogger _logger;
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFuctions
|
||||
/// <summary>
|
||||
/// The finalizer. Necessary for quitting the read thread
|
||||
/// </summary>
|
||||
~CommDeviceNode()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
#region PrivateFuctions
|
||||
/// <summary>
|
||||
/// The finalizer. Necessary for quitting the read thread
|
||||
/// </summary>
|
||||
~CommDeviceNode()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Quit the threads associated with the node
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
State initialState = _state;
|
||||
/// <summary>
|
||||
/// Quit the threads associated with the node
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
State initialState = _state;
|
||||
|
||||
// close the socket and threads
|
||||
try
|
||||
{
|
||||
if (initialState == State.Ready)
|
||||
{
|
||||
Shutdown();
|
||||
_commDevice.Shutdown();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
// close the socket and threads
|
||||
if (initialState == State.Ready)
|
||||
{
|
||||
Shutdown();
|
||||
_commDevice.Shutdown();
|
||||
}
|
||||
|
||||
// dispose of the resources
|
||||
try
|
||||
{
|
||||
if (initialState == State.Ready)
|
||||
{
|
||||
_socketReadWorker.Dispose();
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (initialState == State.Ready)
|
||||
{
|
||||
_socketReadWorker.Dispose();
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
#region PublicFuctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="name">The name of this instance</param>
|
||||
/// <param name="commDevice">The communication device</param>
|
||||
/// <param name="msgHandler">The message handler for this interface</param>
|
||||
/// <param name="commReadWorkerBufferSize">The number of bytes for the buffer internal to this class. Each individual read will read upto this buffer size (or until the timeout happens)</param>
|
||||
/// <param name="readWorkerRestTimeInMs">Number of ms to reset between read calls on the comm interface</param>
|
||||
public CommDeviceNode(string name, ICommDevice commDevice, MsgDevice msgHandler, uint commReadWorkerBufferSize = 100000, uint readWorkerRestTimeInMs = 10)
|
||||
{
|
||||
_name = name;
|
||||
_commDevice = commDevice;
|
||||
|
||||
_commReadWorkerBufferSize = commReadWorkerBufferSize;
|
||||
_readWorkerRestTimeInMs = readWorkerRestTimeInMs;
|
||||
_msgHandler = msgHandler;
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="name">The name of this instance</param>
|
||||
/// <param name="commDevice">The communication device</param>
|
||||
/// <param name="msgHandler">The message handler for this interface</param>
|
||||
/// <param name="commReadWorkerBufferSize">The number of bytes for the buffer internal to this class. Each individual read will read upto this buffer size (or until the timeout happens)</param>
|
||||
/// <param name="readWorkerRestTimeInMs">Number of ms to reset between read calls on the comm interface</param>
|
||||
public CommDeviceNode(string name, ICommDevice commDevice, MsgDevice msgHandler, uint commReadWorkerBufferSize = 100000, uint readWorkerRestTimeInMs = 10)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_name = name;
|
||||
_commDevice = commDevice;
|
||||
|
||||
Open();
|
||||
}
|
||||
_commReadWorkerBufferSize = commReadWorkerBufferSize;
|
||||
_readWorkerRestTimeInMs = readWorkerRestTimeInMs;
|
||||
_msgHandler = msgHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Starts communication thread
|
||||
/// </summary>
|
||||
public void Open()
|
||||
{
|
||||
_socketReadWorker = new CommReadWorker(this, _msgHandler, _commReadWorkerBufferSize, _readWorkerRestTimeInMs);
|
||||
_socketReadThread = new Thread(_socketReadWorker.DoWork);
|
||||
Open();
|
||||
}
|
||||
|
||||
// start the read thread
|
||||
_socketReadThread.Start();
|
||||
/// <summary>
|
||||
/// Starts communication thread
|
||||
/// </summary>
|
||||
public void Open()
|
||||
{
|
||||
_socketReadWorker = new CommReadWorker(this, _msgHandler, _commReadWorkerBufferSize, _readWorkerRestTimeInMs);
|
||||
_socketReadThread = new Thread(_socketReadWorker.DoWork);
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
// start the read thread
|
||||
_socketReadThread.Start();
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// there is no error msg repository
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// there is no error msg repository
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Comm Sim Device Node " + _name;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Comm Sim Device Node " + _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
_commDevice.Initialize();
|
||||
_state = State.Ready;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
_commDevice.Initialize();
|
||||
_state = State.Ready;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read data from the socket
|
||||
/// </summary>
|
||||
/// <param name="dataRead">The data that was read</param>
|
||||
/// <returns>the number of bytes read</returns>
|
||||
public uint Read(ref byte[] dataRead)
|
||||
{
|
||||
return _commDevice.Read(ref dataRead);
|
||||
}
|
||||
/// <summary>
|
||||
/// Read data from the socket
|
||||
/// </summary>
|
||||
/// <param name="dataRead">The data that was read</param>
|
||||
/// <returns>the number of bytes read</returns>
|
||||
public uint Read(ref byte[] dataRead)
|
||||
{
|
||||
return _commDevice.Read(ref dataRead);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets communications
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Close();
|
||||
Open();
|
||||
}
|
||||
/// <summary>
|
||||
/// Resets communications
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Close();
|
||||
Open();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="readTimeout"></param>
|
||||
public void SetReadTimeout(uint readTimeout)
|
||||
{
|
||||
_commDevice.SetReadTimeout(readTimeout);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="readTimeout"></param>
|
||||
public void SetReadTimeout(uint readTimeout)
|
||||
{
|
||||
_commDevice.SetReadTimeout(readTimeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close communications
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
/// <summary>
|
||||
/// Close communications
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close communications
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
const int THREAD_QUIT_TIMEOUT_MS = 3000;
|
||||
/// <summary>
|
||||
/// Close communications
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
const int THREAD_QUIT_TIMEOUT_MS = 3000;
|
||||
|
||||
// tell the thread to quit
|
||||
_socketReadWorker.QuitWork();
|
||||
// tell the thread to quit
|
||||
_socketReadWorker.QuitWork();
|
||||
|
||||
// close the socket which the thread might be blocked on
|
||||
_commDevice.Shutdown();
|
||||
// close the socket which the thread might be blocked on
|
||||
_commDevice.Shutdown();
|
||||
|
||||
if (_socketReadThread.IsAlive)
|
||||
{
|
||||
bool didThreadQuit = _socketReadThread.Join(THREAD_QUIT_TIMEOUT_MS);
|
||||
if (_socketReadThread.IsAlive)
|
||||
{
|
||||
bool didThreadQuit = _socketReadThread.Join(THREAD_QUIT_TIMEOUT_MS);
|
||||
|
||||
if (didThreadQuit == false)
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommDeviceNode::Close() - Logging Thread did not quit as expected, aborting it");
|
||||
_socketReadThread.Abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommDeviceNode::Close() - Logging Thread quit successfully after join", ErrorLogger.LogLevel.INFO);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommDeviceNode::Close() - Logging Thread quit successfully", ErrorLogger.LogLevel.INFO);
|
||||
}
|
||||
}
|
||||
if (didThreadQuit == false)
|
||||
{
|
||||
_logger.Debug("Logging Thread did not quit as expected, aborting it");
|
||||
_socketReadThread.Abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Logging Thread quit successfully after join");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Logging Thread quit successfully");
|
||||
}
|
||||
}
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send data on the socket
|
||||
/// </summary>
|
||||
/// <param name="dataToSend">The data to send</param>
|
||||
/// <param name="numBytesToWrite">The number of bytes to write from the dataToSend buffer</param>
|
||||
/// <returns>The number of bytes sent</returns>
|
||||
public uint Write(byte[] dataToSend, uint numBytesToWrite)
|
||||
{
|
||||
return _commDevice.Write(dataToSend, numBytesToWrite);
|
||||
}
|
||||
/// <summary>
|
||||
/// Send data on the socket
|
||||
/// </summary>
|
||||
/// <param name="dataToSend">The data to send</param>
|
||||
/// <param name="numBytesToWrite">The number of bytes to write from the dataToSend buffer</param>
|
||||
/// <returns>The number of bytes sent</returns>
|
||||
public uint Write(byte[] dataToSend, uint numBytesToWrite)
|
||||
{
|
||||
return _commDevice.Write(dataToSend, numBytesToWrite);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Net.Sockets;
|
||||
using Raytheon.Instruments;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
@@ -35,6 +34,7 @@ namespace Raytheon.Instruments
|
||||
private AutoResetEvent _quitEvent;
|
||||
private byte[] _dataRead;
|
||||
private readonly uint _timeToRestBetweenReadsInMs;
|
||||
private readonly ILogger _logger;
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
@@ -48,6 +48,7 @@ namespace Raytheon.Instruments
|
||||
/// <param name="timeToRestBetweenReadsInMs">Number of ms to rest after a read call</param>
|
||||
public CommReadWorker(ICommDevice commNode, MsgDevice msghandler, uint bufferSize, uint timeToRestBetweenReadsInMs)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_commNode = commNode;
|
||||
_threadQuitControl = false;
|
||||
_msgHandler = msghandler;
|
||||
@@ -69,23 +70,9 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,33 +97,14 @@ namespace Raytheon.Instruments
|
||||
// not using timeToRestBetweenReadsInMs. Just going to wait 1 ms and get back to the read
|
||||
if (_quitEvent.WaitOne(1))
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - received signal to quit", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("received signal to quit");
|
||||
_threadQuitControl = true;
|
||||
}
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.SocketErrorCode == SocketError.TimedOut)
|
||||
{
|
||||
//expected
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - " + e.Message, ErrorLogger.LogLevel.ERROR);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - " + e.Message, ErrorLogger.LogLevel.ERROR);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - exiting", ErrorLogger.LogLevel.INFO);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,23 +122,9 @@ namespace Raytheon.Instruments
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
if (disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_quitEvent.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
_quitEvent.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -15,9 +15,10 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
@@ -29,6 +30,7 @@ namespace Raytheon.Instruments
|
||||
#region PrivateClassMembers
|
||||
private Dictionary<uint, Func<IntPtr, bool>> _messageHandlerMap;
|
||||
private ICommDevice _commInterface;
|
||||
private readonly ILogger _logger;
|
||||
#endregion
|
||||
|
||||
#region PrivateClassFunctions
|
||||
@@ -42,17 +44,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleAddAttributesRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsAddAttributesRspMessage msg = new VrsAddAttributesRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -65,17 +64,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleConnectRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsConnectRspMessage msg = new VrsConnectRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -89,17 +85,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleDisconnectRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsDisconnectRspMessage msg = new VrsDisconnectRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -112,17 +105,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleGrabToDiskRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsGrabToDiskRspMessage msg = new VrsGrabToDiskRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -136,17 +126,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleGrabToDiskCompleteRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsGrabToDiskCompleteRspMessage msg = new VrsGrabToDiskCompleteRspMessage(false, "");
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -160,17 +147,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleMoveFileRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsMoveFileRspMessage msg = new VrsMoveFileRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -184,17 +168,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleQueryDiskRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrsQueryHardDriveRspMessage msg = new VrsQueryHardDriveRspMessage(false, 0, 0, 0, 0);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -208,17 +189,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleStopLiveVideoRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrStopLiveVideoRspMessage msg = new VrStopLiveVideoRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -232,17 +210,14 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::HandleShowLiveVideoRspMsg() - beginning", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("beginning");
|
||||
|
||||
VrShowLiveVideoRspMessage msg = new VrShowLiveVideoRspMessage(false);
|
||||
msg.Parse(pData);
|
||||
msg.ExecuteMsg();
|
||||
AutomationRxMsgBuffer.Instance().AddMsg(msg);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -257,6 +232,8 @@ namespace Raytheon.Instruments
|
||||
unsafe public VrsClientMsgHandler(uint bufferSize)
|
||||
: base(new VrsMsgParser(), bufferSize)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_commInterface = null;
|
||||
|
||||
// set the callback
|
||||
@@ -304,7 +281,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
if (_messageHandlerMap.ContainsKey(msgId) == false)
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsClientMsgHandler::OnCompleteMessage() - detected unknown msg id: " + msgId.ToString());
|
||||
_logger.Warn("VrsClientMsgHandler::OnCompleteMessage() - detected unknown msg id: " + msgId.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -15,9 +15,10 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
@@ -30,6 +31,7 @@ namespace Raytheon.Instruments
|
||||
#region PrivateClassMembers
|
||||
private List<uint> _messageList;
|
||||
private AutomationMessageHeader _header;
|
||||
private readonly ILogger _logger;
|
||||
#endregion
|
||||
|
||||
#region PublicClassFunctions
|
||||
@@ -39,6 +41,8 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
public VrsMsgParser()
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_messageList = new List<uint>();
|
||||
_messageList.Add((uint)VrsAutomationMsgIds.VRS_CONNECT_CMD);
|
||||
_messageList.Add((uint)VrsAutomationMsgIds.VRS_CONNECT_RSP);
|
||||
@@ -78,7 +82,7 @@ namespace Raytheon.Instruments
|
||||
// check to see if we have enough data for at least a header
|
||||
if (numBytesInPdata < AutomationMessageHeader.HEADER_EXPECTED_SIZE)
|
||||
{
|
||||
ErrorLogger.Instance().Write("VrsMsgParser::run() - not enough data in the buffer to form a header. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("not enough data in the buffer to form a header. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes");
|
||||
bytesToRemove = 0;
|
||||
return false;
|
||||
}
|
||||
@@ -91,8 +95,8 @@ namespace Raytheon.Instruments
|
||||
// do we have this message in our messageSizeMap_ dictionary?
|
||||
if (_messageList.Contains(_header.GetMessageId()) == false)
|
||||
{
|
||||
string msg = "VrsMsgParser::run() - unknown id received: " + Convert.ToString(_header.GetMessageId());
|
||||
ErrorLogger.Instance().Write(msg, ErrorLogger.LogLevel.ERROR);
|
||||
string msg = "unknown id received: " + Convert.ToString(_header.GetMessageId());
|
||||
_logger.Warn(msg);
|
||||
bytesToRemove = totalMsgSize; // move on to next message
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
|
||||
// Ignore Spelling: Ncdf
|
||||
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
@@ -29,490 +29,440 @@ namespace Raytheon.Instruments
|
||||
/// The interface for the test controller to automate the VRS system
|
||||
/// </summary>
|
||||
public class VideoRecorderVrsClient : IVideoRecorder
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private readonly string _remoteAddress;
|
||||
private readonly int _remotePort;
|
||||
private readonly int _localPort;
|
||||
private readonly CommDeviceNode _udpNode;
|
||||
private readonly ICommDevice _commDevice;
|
||||
private readonly uint _parseBufferSize;
|
||||
private static readonly object _syncObj = new Object();
|
||||
/// <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 => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public InstrumentMetadata Info => throw new NotImplementedException();
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public SelfTestResult SelfTestResult => throw new NotImplementedException();
|
||||
|
||||
public State Status => throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region PrivateClassFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~VideoRecorderVrsClient()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Disconnect();
|
||||
_commDevice.Shutdown();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_udpNode.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicClassFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="remoteAddress">The remote computer address</param>
|
||||
/// <param name="remotePort">The remote computer port</param>
|
||||
/// <param name="localPort">the local computer port</param>
|
||||
/// <param name="parseBufferSize">the parse buffer size in bytes</param>
|
||||
public VideoRecorderVrsClient(string remoteAddress, int remotePort, int localPort, uint parseBufferSize)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
// init error logger singleton
|
||||
ErrorLogger.Instance().Write("beginning", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
_remoteAddress = remoteAddress;
|
||||
|
||||
_remotePort = remotePort;
|
||||
|
||||
_localPort = localPort;
|
||||
|
||||
_parseBufferSize = parseBufferSize;
|
||||
|
||||
List<uint> msgIds = new List<uint>();
|
||||
|
||||
foreach (uint id in Enum.GetValues(typeof(VrsAutomationMsgIds)))
|
||||
{
|
||||
msgIds.Add(id);
|
||||
}
|
||||
|
||||
AutomationRxMsgBuffer.Instance(msgIds);
|
||||
|
||||
VrsClientMsgHandler msghandler = new VrsClientMsgHandler(_parseBufferSize);
|
||||
|
||||
_commDevice = new CommDeviceUdp("CommDeviceUdp", _localPort, _remotePort, _remoteAddress);
|
||||
|
||||
_udpNode = new CommDeviceNode("CommDeviceNode", _commDevice, msghandler);
|
||||
|
||||
msghandler.SetCommInterface(_udpNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// updated constructor
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
/// <param name="logger"></param>
|
||||
public VideoRecorderVrsClient(string name, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = name;
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_remoteAddress = _configuration.GetConfigurationValue("VideoRecorderVrsClient", "RemoteAddress", "127.0.0.1");
|
||||
_remotePort = _configuration.GetConfigurationValue("VideoRecorderVrsClient", "RemotePort", 0);
|
||||
_localPort = _configuration.GetConfigurationValue("VideoRecorderVrsClient", "LocalPort", 0);
|
||||
_parseBufferSize = _configuration.GetConfigurationValue<uint>("VideoRecorderVrsClient", "LocalPort", 1024);
|
||||
|
||||
List<uint> msgIds = new List<uint>();
|
||||
foreach (uint id in Enum.GetValues(typeof(VrsAutomationMsgIds)))
|
||||
{
|
||||
msgIds.Add(id);
|
||||
}
|
||||
|
||||
AutomationRxMsgBuffer.Instance(msgIds);
|
||||
|
||||
VrsClientMsgHandler msghandler = new VrsClientMsgHandler(_parseBufferSize);
|
||||
|
||||
_commDevice = new CommDeviceUdp("CommDeviceUdp", _localPort, _remotePort, _remoteAddress);
|
||||
_udpNode = new CommDeviceNode("CommDeviceNode", _commDevice, msghandler);
|
||||
|
||||
msghandler.SetCommInterface(_udpNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to the VRS and command it to add ncdf attributes to a video file
|
||||
/// </summary>
|
||||
/// <param name="videoFile">The video file to add attributes to</param>
|
||||
/// <param name="attributeFile">The attribute file</param>
|
||||
public void AddNcdfAttributes(string videoFile, string attributeFile)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
AutomationMessage addAttributesMsg = new VrsAddAttributesCmdMessage(videoFile, attributeFile);
|
||||
|
||||
AutomationMessage addAttributesRspMsg = new VrsAddAttributesRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, addAttributesMsg, ref addAttributesRspMsg);
|
||||
|
||||
VrsAddAttributesRspMessage tempRsp = (VrsAddAttributesRspMessage)addAttributesRspMsg;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsAddAttributesRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect to the VRS system
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage connectMsg = new VrsConnectCmdMessage();
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private readonly string _remoteAddress;
|
||||
private readonly int _remotePort;
|
||||
private readonly int _localPort;
|
||||
private readonly CommDeviceNode _udpNode;
|
||||
private readonly ICommDevice _commDevice;
|
||||
private readonly uint _parseBufferSize;
|
||||
private static readonly object _syncObj = new Object();
|
||||
|
||||
AutomationMessage connectRspMsg = new VrsConnectRspMessage(false);
|
||||
private readonly ILogger _logger;
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, connectMsg, ref connectRspMsg);
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
VrsConnectRspMessage tempRsp = (VrsConnectRspMessage)connectRspMsg;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsConnectRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect from the VRS
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage disconnectMsg = new VrsDisconnectCmdMessage();
|
||||
|
||||
AutomationMessage disconnectRspMsg = new VrsDisconnectRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, disconnectMsg, ref disconnectRspMsg);
|
||||
|
||||
VrsDisconnectRspMessage tempRsp = (VrsDisconnectRspMessage)disconnectRspMsg;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsDisconnectRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
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>
|
||||
/// record video to the VRS hard drive. This function returns once the grab has begun, Use WaitForGrabToComplete() to know when the grab is completed
|
||||
/// </summary>
|
||||
/// <param name="numberOfFrames">The number of frames to grab</param>
|
||||
/// <param name="format">The save file format</param>
|
||||
public void GrabVideoToDisk(uint numberOfFrames, VideoSaveFormat format)
|
||||
{
|
||||
const int RSP_TIMEOUT = 20000;
|
||||
|
||||
lock (_syncObj)
|
||||
{
|
||||
//reset the event for WaitForGrabComplete
|
||||
AutomationRxMsgBuffer.Instance().ResetRxEvent((uint)VrsAutomationMsgIds.VRS_GRAB_TO_DISK_COMPLETE_RSP);
|
||||
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage grabCmd = new VrsGrabToDiskCmdMessage(numberOfFrames, format);
|
||||
|
||||
AutomationMessage grabRsp = new VrsGrabToDiskRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, grabCmd, ref grabRsp, RSP_TIMEOUT);
|
||||
|
||||
VrsGrabToDiskRspMessage tempRsp = (VrsGrabToDiskRspMessage)grabRsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsGrabToDiskRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of GB free on the VRS system.
|
||||
/// </summary>
|
||||
/// <param name="driveSpace1">Drive 1 free space in GBs</param>
|
||||
/// <param name="driveSpace2">Drive 2 free space in GBs</param>
|
||||
/// <param name="driveSpace3">Drive 3 free space in GBs</param>
|
||||
/// <param name="driveSpace4">Drive 4 free space in GBs</param>
|
||||
public void QueryHardDrive(ref float driveSpace1, ref float driveSpace2, ref float driveSpace3, ref float driveSpace4)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage msg = new VrsQueryHardDriveCmdMessage();
|
||||
|
||||
AutomationMessage rsp = new VrsQueryHardDriveRspMessage(false, 0, 0, 0, 0);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, msg, ref rsp);
|
||||
|
||||
VrsQueryHardDriveRspMessage tempRsp = (VrsQueryHardDriveRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsQueryHardDriveRspMessage returned a successful flag of false");
|
||||
}
|
||||
|
||||
tempRsp.GetDriveSpace(ref driveSpace1, ref driveSpace2, ref driveSpace3, ref driveSpace4);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves a file from one location to another
|
||||
/// </summary>
|
||||
/// <param name="fromFile"></param>
|
||||
/// <param name="toFile"></param>
|
||||
/// <param name="control"></param>
|
||||
public void MoveFile(string fromFile, string toFile, MoveControl control)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage cmd = new VrsMoveFileCmdMessage(fromFile, toFile, control);
|
||||
|
||||
AutomationMessage rsp = new VrsMoveFileRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, cmd, ref rsp);
|
||||
|
||||
VrsMoveFileRspMessage tempRsp = (VrsMoveFileRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsMoveFileRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start displaying live video on the VRS
|
||||
/// </summary>
|
||||
public void ShowLiveVideo()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage cmd = new VrShowLiveVideoCmdMessage();
|
||||
|
||||
AutomationMessage rsp = new VrShowLiveVideoRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, cmd, ref rsp);
|
||||
|
||||
VrShowLiveVideoRspMessage tempRsp = (VrShowLiveVideoRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrShowLiveVideoRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop displaying video on the VRS
|
||||
/// </summary>
|
||||
public void StopLiveVideo()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage cmd = new VrStopLiveVideoCmdMessage();
|
||||
|
||||
AutomationMessage rsp = new VrStopLiveVideoRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, cmd, ref rsp);
|
||||
|
||||
VrStopLiveVideoRspMessage tempRsp = (VrStopLiveVideoRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
ErrorLogger.Instance().Write("init complete", ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrStopLiveVideoRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A blocking function that waits for a video capture to complete
|
||||
/// </summary>
|
||||
/// <param name="timeoutms"></param>
|
||||
/// <returns></returns>
|
||||
public string WaitForGrabToComplete(int timeoutms)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
bool didWeGetRsp = AutomationRxMsgBuffer.Instance().WaitForRspMsg((uint)VrsAutomationMsgIds.VRS_GRAB_TO_DISK_COMPLETE_RSP, timeoutms);
|
||||
|
||||
if (didWeGetRsp == true)
|
||||
{
|
||||
VrsGrabToDiskCompleteRspMessage rsp = (VrsGrabToDiskCompleteRspMessage)AutomationRxMsgBuffer.Instance().GetNewestMessage((uint)VrsAutomationMsgIds.VRS_GRAB_TO_DISK_COMPLETE_RSP);
|
||||
|
||||
return rsp.GetFileName();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Timed out waiting for response");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Disconnect();
|
||||
|
||||
Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public void Shutdown()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
public byte[] GetSmallVideoFrame(string name, int nFrames, bool sensor, ref uint numBytesRead, bool deleteVideoFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
public string DetailedStatus => throw new NotImplementedException();
|
||||
|
||||
public bool DisplayEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public InstrumentMetadata Info => throw new NotImplementedException();
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public SelfTestResult SelfTestResult => throw new NotImplementedException();
|
||||
|
||||
public State Status => throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region PrivateClassFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~VideoRecorderVrsClient()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Disconnect();
|
||||
_commDevice.Shutdown();
|
||||
_udpNode.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicClassFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="remoteAddress">The remote computer address</param>
|
||||
/// <param name="remotePort">The remote computer port</param>
|
||||
/// <param name="localPort">the local computer port</param>
|
||||
/// <param name="parseBufferSize">the parse buffer size in bytes</param>
|
||||
public VideoRecorderVrsClient(string remoteAddress, int remotePort, int localPort, uint parseBufferSize)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
// init error logger singleton
|
||||
_logger.Debug("beginning");
|
||||
|
||||
_remoteAddress = remoteAddress;
|
||||
|
||||
_remotePort = remotePort;
|
||||
|
||||
_localPort = localPort;
|
||||
|
||||
_parseBufferSize = parseBufferSize;
|
||||
|
||||
List<uint> msgIds = new List<uint>();
|
||||
|
||||
foreach (uint id in Enum.GetValues(typeof(VrsAutomationMsgIds)))
|
||||
{
|
||||
msgIds.Add(id);
|
||||
}
|
||||
|
||||
AutomationRxMsgBuffer.Instance(msgIds);
|
||||
|
||||
VrsClientMsgHandler msghandler = new VrsClientMsgHandler(_parseBufferSize);
|
||||
|
||||
_commDevice = new CommDeviceUdp("CommDeviceUdp", _localPort, _remotePort, _remoteAddress);
|
||||
|
||||
_udpNode = new CommDeviceNode("CommDeviceNode", _commDevice, msghandler);
|
||||
|
||||
msghandler.SetCommInterface(_udpNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// updated constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
/// <param name="logger"></param>
|
||||
public VideoRecorderVrsClient(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_remoteAddress = _configuration.GetConfigurationValue("VideoRecorderVrsClient", "RemoteAddress", "127.0.0.1");
|
||||
_remotePort = _configuration.GetConfigurationValue("VideoRecorderVrsClient", "RemotePort", 0);
|
||||
_localPort = _configuration.GetConfigurationValue("VideoRecorderVrsClient", "LocalPort", 0);
|
||||
_parseBufferSize = _configuration.GetConfigurationValue<uint>("VideoRecorderVrsClient", "LocalPort", 1024);
|
||||
|
||||
List<uint> msgIds = new List<uint>();
|
||||
foreach (uint id in Enum.GetValues(typeof(VrsAutomationMsgIds)))
|
||||
{
|
||||
msgIds.Add(id);
|
||||
}
|
||||
|
||||
AutomationRxMsgBuffer.Instance(msgIds);
|
||||
|
||||
VrsClientMsgHandler msghandler = new VrsClientMsgHandler(_parseBufferSize);
|
||||
|
||||
_commDevice = new CommDeviceUdp("CommDeviceUdp", _localPort, _remotePort, _remoteAddress);
|
||||
_udpNode = new CommDeviceNode("CommDeviceNode", _commDevice, msghandler);
|
||||
|
||||
msghandler.SetCommInterface(_udpNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to the VRS and command it to add ncdf attributes to a video file
|
||||
/// </summary>
|
||||
/// <param name="videoFile">The video file to add attributes to</param>
|
||||
/// <param name="attributeFile">The attribute file</param>
|
||||
public void AddNcdfAttributes(string videoFile, string attributeFile)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
AutomationMessage addAttributesMsg = new VrsAddAttributesCmdMessage(videoFile, attributeFile);
|
||||
|
||||
AutomationMessage addAttributesRspMsg = new VrsAddAttributesRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, addAttributesMsg, ref addAttributesRspMsg);
|
||||
|
||||
VrsAddAttributesRspMessage tempRsp = (VrsAddAttributesRspMessage)addAttributesRspMsg;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsAddAttributesRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect to the VRS system
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage connectMsg = new VrsConnectCmdMessage();
|
||||
|
||||
AutomationMessage connectRspMsg = new VrsConnectRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, connectMsg, ref connectRspMsg);
|
||||
|
||||
VrsConnectRspMessage tempRsp = (VrsConnectRspMessage)connectRspMsg;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsConnectRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect from the VRS
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage disconnectMsg = new VrsDisconnectCmdMessage();
|
||||
|
||||
AutomationMessage disconnectRspMsg = new VrsDisconnectRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, disconnectMsg, ref disconnectRspMsg);
|
||||
|
||||
VrsDisconnectRspMessage tempRsp = (VrsDisconnectRspMessage)disconnectRspMsg;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsDisconnectRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// record video to the VRS hard drive. This function returns once the grab has begun, Use WaitForGrabToComplete() to know when the grab is completed
|
||||
/// </summary>
|
||||
/// <param name="numberOfFrames">The number of frames to grab</param>
|
||||
/// <param name="format">The save file format</param>
|
||||
public void GrabVideoToDisk(uint numberOfFrames, VideoSaveFormat format)
|
||||
{
|
||||
const int RSP_TIMEOUT = 20000;
|
||||
|
||||
lock (_syncObj)
|
||||
{
|
||||
//reset the event for WaitForGrabComplete
|
||||
AutomationRxMsgBuffer.Instance().ResetRxEvent((uint)VrsAutomationMsgIds.VRS_GRAB_TO_DISK_COMPLETE_RSP);
|
||||
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage grabCmd = new VrsGrabToDiskCmdMessage(numberOfFrames, format);
|
||||
|
||||
AutomationMessage grabRsp = new VrsGrabToDiskRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, grabCmd, ref grabRsp, RSP_TIMEOUT);
|
||||
|
||||
VrsGrabToDiskRspMessage tempRsp = (VrsGrabToDiskRspMessage)grabRsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsGrabToDiskRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of GB free on the VRS system.
|
||||
/// </summary>
|
||||
/// <param name="driveSpace1">Drive 1 free space in GBs</param>
|
||||
/// <param name="driveSpace2">Drive 2 free space in GBs</param>
|
||||
/// <param name="driveSpace3">Drive 3 free space in GBs</param>
|
||||
/// <param name="driveSpace4">Drive 4 free space in GBs</param>
|
||||
public void QueryHardDrive(ref float driveSpace1, ref float driveSpace2, ref float driveSpace3, ref float driveSpace4)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage msg = new VrsQueryHardDriveCmdMessage();
|
||||
|
||||
AutomationMessage rsp = new VrsQueryHardDriveRspMessage(false, 0, 0, 0, 0);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, msg, ref rsp);
|
||||
|
||||
VrsQueryHardDriveRspMessage tempRsp = (VrsQueryHardDriveRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsQueryHardDriveRspMessage returned a successful flag of false");
|
||||
}
|
||||
|
||||
tempRsp.GetDriveSpace(ref driveSpace1, ref driveSpace2, ref driveSpace3, ref driveSpace4);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves a file from one location to another
|
||||
/// </summary>
|
||||
/// <param name="fromFile"></param>
|
||||
/// <param name="toFile"></param>
|
||||
/// <param name="control"></param>
|
||||
public void MoveFile(string fromFile, string toFile, MoveControl control)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage cmd = new VrsMoveFileCmdMessage(fromFile, toFile, control);
|
||||
|
||||
AutomationMessage rsp = new VrsMoveFileRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, cmd, ref rsp);
|
||||
|
||||
VrsMoveFileRspMessage tempRsp = (VrsMoveFileRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrsMoveFileRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start displaying live video on the VRS
|
||||
/// </summary>
|
||||
public void ShowLiveVideo()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage cmd = new VrShowLiveVideoCmdMessage();
|
||||
|
||||
AutomationMessage rsp = new VrShowLiveVideoRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, cmd, ref rsp);
|
||||
|
||||
VrShowLiveVideoRspMessage tempRsp = (VrShowLiveVideoRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrShowLiveVideoRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop displaying video on the VRS
|
||||
/// </summary>
|
||||
public void StopLiveVideo()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// send the vrs a message just to make sure the two apps are talking
|
||||
AutomationMessage cmd = new VrStopLiveVideoCmdMessage();
|
||||
|
||||
AutomationMessage rsp = new VrStopLiveVideoRspMessage(false);
|
||||
|
||||
CommUtil.Instance().SendCommandGetResponse(_udpNode, cmd, ref rsp);
|
||||
|
||||
VrStopLiveVideoRspMessage tempRsp = (VrStopLiveVideoRspMessage)rsp;
|
||||
|
||||
bool wasConnectMsgSuccessful = tempRsp.GetSuccessfulFlag();
|
||||
|
||||
_logger.Debug("init complete");
|
||||
|
||||
if (wasConnectMsgSuccessful == false)
|
||||
{
|
||||
throw new Exception("VrStopLiveVideoRspMessage returned a successful flag of false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A blocking function that waits for a video capture to complete
|
||||
/// </summary>
|
||||
/// <param name="timeoutms"></param>
|
||||
/// <returns></returns>
|
||||
public string WaitForGrabToComplete(int timeoutms)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
bool didWeGetRsp = AutomationRxMsgBuffer.Instance().WaitForRspMsg((uint)VrsAutomationMsgIds.VRS_GRAB_TO_DISK_COMPLETE_RSP, timeoutms);
|
||||
|
||||
if (didWeGetRsp == true)
|
||||
{
|
||||
VrsGrabToDiskCompleteRspMessage rsp = (VrsGrabToDiskCompleteRspMessage)AutomationRxMsgBuffer.Instance().GetNewestMessage((uint)VrsAutomationMsgIds.VRS_GRAB_TO_DISK_COMPLETE_RSP);
|
||||
|
||||
return rsp.GetFileName();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Timed out waiting for response");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Disconnect();
|
||||
|
||||
Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public void Shutdown()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
public byte[] GetSmallVideoFrame(string name, int nFrames, bool sensor, ref uint numBytesRead, bool deleteVideoFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,71 +31,64 @@
|
||||
// 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;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "VideoRecorderVrsClientFactory")]
|
||||
public class VideoRecorderVrsClientFactory : 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;
|
||||
[ExportInstrumentFactory(ModelNumber = "VideoRecorderVrsClientFactory")]
|
||||
public class VideoRecorderVrsClientFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public VideoRecorderVrsClientFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
/// <summary>
|
||||
/// COECommDeviceInstrumentFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public VideoRecorderVrsClientFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public VideoRecorderVrsClientFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
/// <summary>
|
||||
/// VideoRecorderVrsClientFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public VideoRecorderVrsClientFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(ICommDevice));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new VideoRecorderVrsClient(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
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(ICommDevice));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new VideoRecorderVrsClient(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -106,12 +99,10 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
if (simulateHw)
|
||||
return new VideoRecorderSim(name, _configurationManager, _logger);
|
||||
return new VideoRecorderSim(name, _configurationManager);
|
||||
else
|
||||
return new VideoRecorderVrsClient(name, _configurationManager, _logger);
|
||||
return new VideoRecorderVrsClient(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -124,17 +115,17 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user