Major upgrade
This commit is contained in:
93
Source/Program/Threads/TacticalUartReadThread.cs
Normal file
93
Source/Program/Threads/TacticalUartReadThread.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// 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.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Raytheon.Instruments;
|
||||
|
||||
namespace ProgramLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Thread to read tactical UART data
|
||||
/// </summary>
|
||||
internal class TacticalUartReadThread : BasicThread
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
public static ConcurrentQueue<byte[]> _byteQueue = new ConcurrentQueue<byte[]>();
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public TacticalUartReadThread()
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_byteQueue = new ConcurrentQueue<byte[]>();
|
||||
}
|
||||
|
||||
~TacticalUartReadThread()
|
||||
{
|
||||
_logger.Debug($"Waiting for {this.GetType().Name} to exit...");
|
||||
WaitForExit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method that executes on the thread.
|
||||
/// </summary>
|
||||
protected override void DoWork()
|
||||
{
|
||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||
|
||||
string serialDeviceInstanceName = Program.Instance().ProgramSpecificConfig.ReadValue("UART_INFO", "SERIAL_DEVICE_INSTANCE_NAME");
|
||||
ICommDevice _serialDevice = (ICommDevice)Program.Instance().InstrumentManager.GetGenericInstrument(serialDeviceInstanceName);
|
||||
DateTime startDateTime = DateTime.Now;
|
||||
const int MAX_PBIT_WAIT_SEC = 17;
|
||||
|
||||
try
|
||||
{
|
||||
byte[] receiveByteArray = null;
|
||||
uint numBytesRead = 0;
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
numBytesRead = _serialDevice.Read(ref receiveByteArray);
|
||||
List<byte> bytelist = receiveByteArray.ToList();
|
||||
_byteQueue.Enqueue(bytelist.Skip(0).Take((int)numBytesRead).ToArray());
|
||||
}
|
||||
catch { }
|
||||
|
||||
TimeSpan ts = DateTime.Now - startDateTime;
|
||||
|
||||
if (ts.TotalSeconds > MAX_PBIT_WAIT_SEC)
|
||||
break;
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
||||
}
|
||||
|
||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user