init
This commit is contained in:
109
DataPRO/IService/Classes/CAN/CANConfig.cs
Normal file
109
DataPRO/IService/Classes/CAN/CANConfig.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public class CANConfig : IXmlSerializable
|
||||
{
|
||||
private readonly Dictionary<string, CANModuleConfig> _modules = new Dictionary<string, CANModuleConfig>();
|
||||
public Dictionary<string, CANModuleConfig> Modules { get { return _modules; } }
|
||||
private readonly string _fileName;
|
||||
public string FileName { get { return _fileName; } }
|
||||
|
||||
public CANConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public CANConfig(string fileName, bool deleteIfPresent)
|
||||
{
|
||||
const string dasConfigs = "DASConfigs";
|
||||
var location = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), dasConfigs), fileName);
|
||||
|
||||
_fileName = location;
|
||||
if (File.Exists(location))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (deleteIfPresent)
|
||||
{
|
||||
try { File.Delete(_fileName); }
|
||||
catch (Exception ex) { APILogger.Log("Problem deleting ", _fileName, ex); }
|
||||
}
|
||||
else { using (var sr = new StreamReader(_fileName)) { ReadXml(XmlReader.Create(sr)); } }
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log("Problem reading ", _fileName, ex); }
|
||||
}
|
||||
}
|
||||
public void SetModule(CANModuleConfig module)
|
||||
{
|
||||
if (_modules.ContainsKey(module.SerialNumber)) { _modules[module.SerialNumber] = module; }
|
||||
else { _modules.Add(module.SerialNumber, module); }
|
||||
}
|
||||
public CANModuleConfig GetModule(CANModuleConfig module)
|
||||
{
|
||||
if (_modules.ContainsKey(module.SerialNumber)) { return _modules[module.SerialNumber]; }
|
||||
else
|
||||
{
|
||||
_modules.Add(module.SerialNumber, module);
|
||||
return module;
|
||||
}
|
||||
}
|
||||
public XmlSchema GetSchema()
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Generates an object from its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// reader:
|
||||
// The System.Xml.XmlReader stream from which the object is deserialized.
|
||||
public void ReadXml(XmlReader reader)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
reader.ReadStartElement("CANConfig");
|
||||
|
||||
reader.ReadStartElement("Modules");
|
||||
|
||||
while (reader.MoveToContent() == XmlNodeType.Element)
|
||||
{
|
||||
CANModuleConfig tConfig = new CANModuleConfig();
|
||||
tConfig.ReadXml(reader);
|
||||
SetModule(tConfig);
|
||||
}
|
||||
|
||||
reader.ReadEndElement();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Converts an object into its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// writer:
|
||||
// The System.Xml.XmlWriter stream to which the object is serialized.
|
||||
public void WriteXml(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("CANConfig");
|
||||
|
||||
writer.WriteStartElement("Modules");
|
||||
writer.Flush();
|
||||
|
||||
foreach (CANModuleConfig module in _modules.Values)
|
||||
{
|
||||
module.WriteXml(writer);
|
||||
writer.Flush();
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndElement();
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
260
DataPRO/IService/Classes/CAN/CANModuleConfig.cs
Normal file
260
DataPRO/IService/Classes/CAN/CANModuleConfig.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public class CANModuleConfig : IXmlSerializable
|
||||
{
|
||||
public string SerialNumber { get; set; } = "";
|
||||
public string TestId { get; set; } = "";
|
||||
public string TestDescription { get; set; } = "";
|
||||
|
||||
public DFConstantsAndEnums.RecordingMode RecordingMode { get; set; } = DFConstantsAndEnums.RecordingMode.InvalidArmMode;
|
||||
public float AAFilterRateHz { get; set; } = 0;
|
||||
public double PreTriggerSeconds { get; set; } = 0;
|
||||
public double PostTriggerSeconds { get; set; } = 0;
|
||||
|
||||
private readonly Dictionary<int, DASChannel> _channels = new Dictionary<int, DASChannel>();
|
||||
|
||||
private readonly string _fileName;
|
||||
public string FileName { get { return _fileName; } }
|
||||
|
||||
public string FirmwareVersion { get; set; } = "";
|
||||
public UInt64? MaxEventStorageSpaceInBytes { get; set; } = 0;
|
||||
public int ModuleArrayIndex { get; set; } = 0;
|
||||
|
||||
public CANModuleConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public CANModuleConfig(string fileName)
|
||||
{
|
||||
const string dasConfigs = "DASConfigs";
|
||||
var location = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), dasConfigs), fileName);
|
||||
_fileName = location;
|
||||
if (File.Exists(_fileName))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(_fileName))
|
||||
{
|
||||
ReadXml(System.Xml.XmlReader.Create(sr));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log("Problem reading ", _fileName, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SetChannel(CANInputDASChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { _channels[channel.ModuleChannelNumber] = channel; }
|
||||
else { _channels.Add(channel.ModuleChannelNumber, channel); }
|
||||
}
|
||||
public CANInputDASChannel GetChannel(CANInputDASChannel channel)
|
||||
{
|
||||
if (_channels.ContainsKey(channel.ModuleChannelNumber)) { return _channels[channel.ModuleChannelNumber] as CANInputDASChannel; }
|
||||
else
|
||||
{
|
||||
_channels.Add(channel.ModuleChannelNumber, channel);
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
public XmlSchema GetSchema()
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
//
|
||||
// Summary:
|
||||
// Generates an object from its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// reader:
|
||||
// The System.Xml.XmlReader stream from which the object is deserialized.
|
||||
public void ReadXml(XmlReader reader)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
reader.ReadStartElement("CANModule");
|
||||
reader.ReadStartElement("SerialNumber");
|
||||
SerialNumber = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
reader.ReadStartElement("TestId");
|
||||
TestId = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
reader.ReadStartElement("TestDescription");
|
||||
TestDescription = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("RecordingMode");
|
||||
string recordingMode = reader.ReadString();
|
||||
try
|
||||
{
|
||||
RecordingMode = (DFConstantsAndEnums.RecordingMode)Enum.Parse(typeof(DFConstantsAndEnums.RecordingMode), recordingMode);
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log("Failed to load RecordingMode ", recordingMode, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("AAFilterRateHz");
|
||||
string aaFilterRateHz = reader.ReadString();
|
||||
try
|
||||
{
|
||||
AAFilterRateHz = (float)Convert.ToDouble(aaFilterRateHz);
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log("Failed to load AAFilterRateHz ", aaFilterRateHz, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("PreTriggerSeconds");
|
||||
string preTriggerSeconds = reader.ReadString();
|
||||
try
|
||||
{
|
||||
PreTriggerSeconds = Convert.ToDouble(preTriggerSeconds);
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log("Failed to load PreTriggerSeconds ", preTriggerSeconds, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("PostTriggerSeconds");
|
||||
string postTriggerSeconds = reader.ReadString();
|
||||
try
|
||||
{
|
||||
PostTriggerSeconds = Convert.ToDouble(postTriggerSeconds);
|
||||
}
|
||||
catch (Exception ex) { APILogger.Log("Failed to load PostTriggerSeconds ", postTriggerSeconds, ex); }
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("FirmwareVersion");
|
||||
FirmwareVersion = reader.ReadString();
|
||||
reader.ReadEndElement();
|
||||
|
||||
reader.ReadStartElement("MaxEventStorageSpaceInBytes");
|
||||
string maxEventStorageSpaceInBytes = reader.ReadString();
|
||||
|
||||
double d;
|
||||
if (double.TryParse(maxEventStorageSpaceInBytes, out d))
|
||||
{
|
||||
if (d >= 0 && d < ulong.MaxValue) { MaxEventStorageSpaceInBytes = Convert.ToUInt64(d); }
|
||||
else { APILogger.Log("Failed to load MaxEventStorageSpaceInBytes ", maxEventStorageSpaceInBytes); }
|
||||
}
|
||||
else { APILogger.Log("Failed to load MaxEventStorageSpaceInBytes ", maxEventStorageSpaceInBytes); }
|
||||
|
||||
reader.ReadEndElement();
|
||||
ReadModuleArray(reader);
|
||||
|
||||
reader.ReadStartElement("Channels");
|
||||
|
||||
while (reader.MoveToContent() == XmlNodeType.Element)
|
||||
{
|
||||
CANInputDASChannel cic = new CANInputDASChannel();
|
||||
cic.ReadXml(reader);
|
||||
SetChannel(cic);
|
||||
}
|
||||
|
||||
reader.ReadEndElement();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
//FB 45086 sonarqube - reduce cyclomatic complexity
|
||||
private void ReadModuleArray(XmlReader reader)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement("ModuleArrayIndex");
|
||||
string moduleArrayIndex = reader.ReadString();
|
||||
|
||||
int m;
|
||||
if (int.TryParse(moduleArrayIndex, out m))
|
||||
{
|
||||
if (m >= 0 && m < int.MaxValue) { ModuleArrayIndex = Convert.ToInt32(m); }
|
||||
else { APILogger.Log("Failed to load ModuleArrayIndex ", moduleArrayIndex); }
|
||||
}
|
||||
else { APILogger.Log("Failed to load ModuleArrayIndex ", moduleArrayIndex); }
|
||||
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//This must be an old config file
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Converts an object into its XML representation.
|
||||
//
|
||||
// Parameters:
|
||||
// writer:
|
||||
// The System.Xml.XmlWriter stream to which the object is serialized.
|
||||
public void WriteXml(XmlWriter writer)
|
||||
{
|
||||
//writer.WriteStartElement ( attributeExtractor.ExtractAttachedAttributeFromObject ( this
|
||||
writer.WriteStartElement("CANModule");
|
||||
writer.WriteStartElement("SerialNumber");
|
||||
writer.WriteString(SerialNumber);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("TestId");
|
||||
writer.WriteString(TestId);
|
||||
writer.WriteEndElement();
|
||||
writer.WriteStartElement("TestDescription");
|
||||
writer.WriteString(TestDescription);
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("RecordingMode");
|
||||
writer.WriteString(RecordingMode.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("AAFilterRateHz");
|
||||
writer.WriteString(AAFilterRateHz.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("PreTriggerSeconds");
|
||||
writer.WriteString(PreTriggerSeconds.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("PostTriggerSeconds");
|
||||
writer.WriteString(PostTriggerSeconds.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("FirmwareVersion");
|
||||
writer.WriteString(FirmwareVersion);
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("MaxEventStorageSpaceInBytes");
|
||||
writer.WriteString(MaxEventStorageSpaceInBytes.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("ModuleArrayIndex");
|
||||
writer.WriteString(ModuleArrayIndex.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("Channels");
|
||||
writer.Flush();
|
||||
|
||||
foreach (DASChannel channel in _channels.Values)
|
||||
{
|
||||
channel.WriteElementStart(writer);
|
||||
channel.WriteXml(writer);
|
||||
channel.WriteElementEnd(writer);
|
||||
writer.Flush();
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
writer.WriteEndElement();
|
||||
writer.Flush();
|
||||
}
|
||||
public virtual void WriteElementStart(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("CANModule");
|
||||
var tgt = GetType();
|
||||
writer.WriteAttributeString("xsi", "type", null, tgt.Name);
|
||||
}
|
||||
|
||||
public virtual void WriteElementEnd(XmlWriter writer)
|
||||
{
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
2629
DataPRO/IService/Classes/CAN/SLICEProFD.cs
Normal file
2629
DataPRO/IService/Classes/CAN/SLICEProFD.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user