Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -16,9 +16,10 @@ UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using System;
using Raytheon.Common;
using System.IO;
using System.Collections.Generic;
using System.IO;
using NLog;
using Raytheon.Common;
namespace BitMeasurementManagerLib
{
@@ -48,6 +49,7 @@ namespace BitMeasurementManagerLib
private readonly bool _shallWeLogIncomingAsciiData;
private readonly uint _bitmask;
private readonly string _crcFieldName;
private readonly ILogger _logger;
#endregion
#region PublicFuctions
@@ -66,6 +68,7 @@ namespace BitMeasurementManagerLib
unsafe public BitMsgHandler(BitMessageIDs messageIds, MeasurementManagerLib.BitMeasurementManager.MessageReceivedDelegate callback, uint bufferSize, string binLogFileName, string asciiLogFileName, bool shallWeLogOutgoingBinData, bool shallWeLogOutgoingAsciiData, bool shallWeLogIncomingBinData, bool shallWeLogIncomingAsciiData, uint crcBitmask, string crcFieldName, bool shallWePerformVerboseParserLogging)
: base(new BitMsgParser(messageIds, shallWePerformVerboseParserLogging), bufferSize)
{
_logger = LogManager.GetCurrentClassLogger();
_messageIds = messageIds;
// hold onto the callback
@@ -166,7 +169,7 @@ namespace BitMeasurementManagerLib
{
if (_messageIds.ContainsId(msgId) == false)
{
ErrorLogger.Instance().Write("BitMsgHandler::OnCompleteMessage() - detected unknown msg id: " + msgId.ToString());
_logger.Warn("BitMsgHandler::OnCompleteMessage() - detected unknown msg id: " + msgId.ToString());
}
else
{
@@ -184,7 +187,7 @@ namespace BitMeasurementManagerLib
if (maskedStatus != 0)
{
ErrorLogger.Instance().Write($"Message Status register indicates that a CRC error may have occurred. Raw status read: 0x{rawStatus:X8}. Masked status value: 0x{maskedStatus:X8}");
_logger.Warn($"Message Status register indicates that a CRC error may have occurred. Raw status read: 0x{rawStatus:X8}. Masked status value: 0x{maskedStatus:X8}");
callbackValue = -1;
}
}
@@ -207,14 +210,10 @@ namespace BitMeasurementManagerLib
}
// some debugging
ErrorLogger.Instance().Write("BitMsgHandler::HandleMsg() - added message " + msgId.ToString("X8") + " to buffer ", ErrorLogger.LogLevel.INFO);
_logger.Debug("added message " + msgId.ToString("X8") + " to buffer ");
}
}
catch (Exception err)
{
//@@@ need to flow error to the host
ErrorLogger.Instance().Write("BitMsgHandler::HandleMsg() - caught an error: " + err.Message, ErrorLogger.LogLevel.ERROR);
}
catch { }
}
/// <summary>
@@ -271,7 +270,7 @@ namespace BitMeasurementManagerLib
{
if (_binWriter == null && _shallWeLogIncomingBinData == true)
{
throw new Exception("BitMsgHandler::WriteIncomingDataToLog() - Trying to log bin data before the log file is open");
throw new Exception("Trying to log bin data before the log file is open");
}
else if (_shallWeLogIncomingBinData == true)
{
@@ -292,7 +291,7 @@ namespace BitMeasurementManagerLib
{
if (_asciiWriter == null && _shallWeLogIncomingAsciiData == true)
{
throw new Exception("BitMsgHandler::WriteIncomingDataToLog() - Trying to log ascii data before the log file is open");
throw new Exception("Trying to log ascii data before the log file is open");
}
else if (_shallWeLogIncomingAsciiData == true)
{
@@ -318,7 +317,7 @@ namespace BitMeasurementManagerLib
{
if (_binWriter == null && _shallWeLogOutgoingBinData == true)
{
throw new Exception("BitMsgHandler::WriteOutgoingDataToLog() - Trying to log bin data before the log file is open");
throw new Exception("Trying to log bin data before the log file is open");
}
else if (_shallWeLogOutgoingBinData == true)
{
@@ -339,7 +338,7 @@ namespace BitMeasurementManagerLib
{
if (_asciiWriter == null && _shallWeLogOutgoingAsciiData == true)
{
throw new Exception("BitMsgHandler::WriteOutgoingDataToLog() - Trying to log ascii data before the log file is open");
throw new Exception("Trying to log ascii data before the log file is open");
}
else if (_shallWeLogOutgoingAsciiData == true)
{
@@ -362,25 +361,18 @@ namespace BitMeasurementManagerLib
{
if (disposing)
{
try
// call the parent dispose first
base.Dispose(disposing);
// now dispose of our resources
if (_binWriter != null)
{
// call the parent dispose first
base.Dispose(disposing);
// now dispose of our resources
if (_binWriter != null)
{
_binWriter.Dispose();
}
if (_asciiWriter != null)
{
_asciiWriter.Dispose();
}
_binWriter.Dispose();
}
catch (Exception err)
if (_asciiWriter != null)
{
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
_asciiWriter.Dispose();
}
}
}

View File

@@ -15,8 +15,9 @@ GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using Raytheon.Common;
using System;
using NLog;
using Raytheon.Common;
namespace BitMeasurementManagerLib
{
@@ -34,6 +35,7 @@ namespace BitMeasurementManagerLib
private readonly BitMessageIDs _messageIdToSizeMap;
private BitMsgEndianControl.HeaderDef _headerDef;
private readonly bool _shallWePerformVerboseParserLogging;
private readonly ILogger _logger;
#endregion
#region PrivateFuctions
@@ -54,7 +56,7 @@ namespace BitMeasurementManagerLib
if (numBytesInPdata < payloadHeaderSize)
{
ErrorLogger.Instance().Write("BitMsgParser::HandleData() - not enough data in the buffer to form a header. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes, needed " + payloadHeaderSize.ToString() + " for a header", ErrorLogger.LogLevel.INFO);
_logger.Debug("not enough data in the buffer to form a header. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes, needed " + payloadHeaderSize.ToString() + " for a header");
bytesToRemove = 0;
return false;
}
@@ -67,8 +69,8 @@ namespace BitMeasurementManagerLib
if (_messageIdToSizeMap.ContainsId(id) == false)
{
uint numBytesToRemove = Resync(pData, numBytesInPdata);
string msg = "BitMsgParser::HandleData() - unknown id received: " + id.ToString("X8") + " When resyncing threw away " + numBytesToRemove.ToString() + " Bytes";
ErrorLogger.Instance().Write(msg, ErrorLogger.LogLevel.ERROR);
string msg = "unknown id received: " + id.ToString("X8") + " When resyncing threw away " + numBytesToRemove.ToString() + " Bytes";
_logger.Warn(msg);
bytesToRemove = numBytesToRemove;
return false;
}
@@ -79,8 +81,8 @@ namespace BitMeasurementManagerLib
if (secondaryId != _headerDef.secondaryMsgIdExpectedValue)
{
uint numBytesToRemove = Resync(pData, numBytesInPdata);
string msg = "BitMsgParser::HandleData() - detected seondary ID: " + secondaryId.ToString("X8") + " was not as expected: " + _headerDef.secondaryMsgIdExpectedValue.ToString("X8") + " When resyncing threw away " + numBytesToRemove.ToString() + " Bytes";
ErrorLogger.Instance().Write(msg, ErrorLogger.LogLevel.ERROR);
string msg = "detected seondary ID: " + secondaryId.ToString("X8") + " was not as expected: " + _headerDef.secondaryMsgIdExpectedValue.ToString("X8") + " When resyncing threw away " + numBytesToRemove.ToString() + " Bytes";
_logger.Warn(msg);
bytesToRemove = numBytesToRemove;
return false;
}
@@ -91,7 +93,7 @@ namespace BitMeasurementManagerLib
// do we have enough data to make the complete message
if (numBytesInPdata < msgSize)
{
ErrorLogger.Instance().Write("BitMsgParser::HandleData() - not enough data in the buffer to form a entire message. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes, expected msg size is: " + msgSize.ToString(), ErrorLogger.LogLevel.INFO);
_logger.Debug("not enough data in the buffer to form a entire message. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes, expected msg size is: " + msgSize.ToString());
// need to wait for more data
bytesToRemove = 0;
return false;
@@ -102,7 +104,7 @@ namespace BitMeasurementManagerLib
if (_shallWePerformVerboseParserLogging == true)
{
ErrorLogger.Instance().Write("BitMsgParser::HandleData() - found msg: " + id.ToString() + " which has " + msgSize.ToString() + " bytes", ErrorLogger.LogLevel.INFO);
_logger.Debug("found msg: " + id.ToString() + " which has " + msgSize.ToString() + " bytes");
}
messageId = id;
@@ -118,7 +120,7 @@ namespace BitMeasurementManagerLib
/// <returns>The number of bytes to remove from the buffer</returns>
private uint Resync(IntPtr pData, uint numBytesInPdata)
{
ErrorLogger.Instance().Write("BitMsgParser::Resync() - Begin", ErrorLogger.LogLevel.INFO);
_logger.Debug("Begin");
// increment pData by 1
pData = IntPtr.Add(pData, 1);
@@ -138,7 +140,7 @@ namespace BitMeasurementManagerLib
if (numBytesInPdata < payloadHeaderSize)
{
ErrorLogger.Instance().Write("BitMsgParser::Resync() - not enough data in the buffer to form a header. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes, needed " + payloadHeaderSize.ToString() + " for a header. Removing " + bytesToRemove.ToString() + " bytes", ErrorLogger.LogLevel.INFO);
_logger.Debug("not enough data in the buffer to form a header. Buffer contained " + Convert.ToString(numBytesInPdata) + " bytes, needed " + payloadHeaderSize.ToString() + " for a header. Removing " + bytesToRemove.ToString() + " bytes");
break;
}
@@ -179,20 +181,20 @@ namespace BitMeasurementManagerLib
else
{
didWeFindMsg = true;
ErrorLogger.Instance().Write("BitMsgParser::Resync() - Detected message ID: " + id.ToString("X8") + ". Detected Secondary ID: " + secondaryId.ToString("X8") + " Resync complete. Removing " + bytesToRemove.ToString() + " Bytes", ErrorLogger.LogLevel.INFO);
_logger.Debug("Detected message ID: " + id.ToString("X8") + ". Detected Secondary ID: " + secondaryId.ToString("X8") + " Resync complete. Removing " + bytesToRemove.ToString() + " Bytes");
break;
}
}
else
{
didWeFindMsg = true;
ErrorLogger.Instance().Write("BitMsgParser::Resync() - Detected message ID: " + id.ToString("X8") + ". Resync complete. Removing " + bytesToRemove.ToString() + " Bytes", ErrorLogger.LogLevel.INFO);
_logger.Debug("Detected message ID: " + id.ToString("X8") + ". Resync complete. Removing " + bytesToRemove.ToString() + " Bytes");
break;
}
}
}
ErrorLogger.Instance().Write("BitMsgParser::Resync() - returning " + bytesToRemove.ToString(), ErrorLogger.LogLevel.INFO);
_logger.Debug("returning " + bytesToRemove.ToString());
return bytesToRemove;
@@ -208,6 +210,7 @@ namespace BitMeasurementManagerLib
/// <param name="shallWePerformVerboseParserLogging"></param>
public BitMsgParser(BitMessageIDs messageIds, bool shallWePerformVerboseParserLogging)
{
_logger = LogManager.GetCurrentClassLogger();
// Using it to hold onto valid message ids and the size
_messageIdToSizeMap = messageIds;
_shallWePerformVerboseParserLogging = shallWePerformVerboseParserLogging;