laatzen/GenesisDisplayTool/CsvLogging.cs
2021-10-01 11:10:17 +02:00

2086 lines
128 KiB
C#

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Globalization;
namespace GenesisDisplayTool
{
public static partial class CsvLogging
{
public static void Log(UInt16 inputPath, ref Int32[] csvIndexValue, bool enablePath0, bool enablePath1, bool enablePath2, DecodedData[] inputData, String saveDataPath, String timestamp, ref String[] dataToLog, int[] cyclesToStorage)
{
#region Definitions and initializations
StringBuilder CsvLine = new StringBuilder();
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
#endregion
#region Everything else
try
{
#region Process data and write to files
if (((enablePath0) && (inputPath == Constants.PATH0))
|| ((enablePath1) && (inputPath == Constants.PATH1))
|| ((enablePath2) && (inputPath == Constants.PATH2)))
{
#region Set CSV-values
for (UInt16 Hit = 0; Hit < 8; Hit++)
{
CsvLine.Append(inputData[inputPath].TofUp[Hit].ToString(Formats.TofLogString, culture) + Units.TofCsvLogString
+ inputData[inputPath].TofDown[Hit].ToString(Formats.TofLogString, culture) + Units.TofCsvLogString);
}
CsvLine.Append(inputData[inputPath].PulsewidthUp.ToString(Formats.PwLogString, culture) + ";"
+ inputData[inputPath].PulsewidthDown.ToString(Formats.PwLogString, culture) + ";"
+ inputData[inputPath].AmpUpCalculated.ToString(Formats.AmpLogString, culture) + ";"
+ inputData[inputPath].AmpDownCalculated.ToString(Formats.AmpLogString, culture) + ";"
+ inputData[inputPath].Mode + ";"
+ inputData[inputPath].TemperatureHot.ToString(Formats.TempLogString, culture) + ";"
+ inputData[inputPath].TemperatureCold.ToString(Formats.TempLogString, culture) + ";");
#endregion
dataToLog[inputPath] = dataToLog[inputPath] + csvIndexValue[inputPath].ToString(culture) + ";" + timestamp + CsvLine + "\r\n";
if (GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetCsvDataToLogCounter()[inputPath] > cyclesToStorage[inputPath])
{
String temp = dataToLog[inputPath];
Task.Run(() =>
{
using (StreamWriter sw = File.AppendText(saveDataPath + (inputPath + 1).ToString(culture) + ".csv"))
{
sw.Write(temp);
}
});
dataToLog[inputPath] = String.Empty;
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetCsvDataToLogCounter()[inputPath] = 0;
}
else
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetCsvDataToLogCounter()[inputPath]++;
#region Increase CSV-index
csvIndexValue[inputPath]++;
#endregion
}
#endregion
}
catch (Exception ex)
{
ErrorLog.Log(LogErrReason.Exception(), "CsvLogging.Log() failed", "0x" + ex.HResult.ToString("X", culture), "Path =" + inputPath.ToString(culture));
}
#endregion
}
public static void Convert(Double crystalFrequency, ref String defaultDirectory)
{
#region Definitions and initializations
#region File handling
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
String OpenDataPath = String.Empty;
String OpenFileName = String.Empty;
String FileContent = String.Empty;
String SaveFileName = String.Empty;
String[] SaveDataPath = new String[Constants.NumberOfPaths];
String SaveDataPathCommon = String.Empty;
String NewDefaultDirectory = String.Empty;
Boolean OpenDialogOK = false;
Boolean SaveDialogOK = false;
for (UInt16 Path = Constants.PATH0; Path < Constants.NumberOfPaths; Path++)
SaveDataPath[Path] = String.Empty;
#endregion
#region Input data
String[] Lines;
#endregion
#endregion
#region Everything else
try
{
#region Open and read PATH
OpenDialogOK = Files.OpenFileDialogText(out OpenDataPath, defaultDirectory);
if (!OpenDialogOK)
return;
OpenFileName = Path.GetFileNameWithoutExtension(OpenDataPath);
FileContent = File.ReadAllText(OpenDataPath);
#endregion
#region Get data
FileContent = Regex.Replace(FileContent, @"\n", String.Empty);
Lines = FileContent.Split('\r');
#endregion
#region Save file dialog and filename
SaveFileName = OpenFileName.Replace("RAW", "CSV");
SaveDialogOK = Files.SaveFiledialogConversion(SaveFileName, ref SaveDataPathCommon, defaultDirectory);
if (!SaveDialogOK)
return;
Task t = Task.Run(() =>
{
MessageBox.Show("Do not touch the generated files until generation has finished!", "Form Closing", MessageBoxButtons.OK, MessageBoxIcon.Information);
});
SaveDataPathCommon = Path.GetDirectoryName(SaveDataPathCommon);
NewDefaultDirectory = SaveDataPathCommon;
SaveDataPathCommon = SaveDataPathCommon + "\\" + SaveFileName;
#endregion
#region Create empty CSV-files
#region PATH0
SaveDataPath[Constants.PATH0] = SaveDataPathCommon + "_PATH1.csv";
using (StreamWriter sw0 = File.CreateText(@SaveDataPath[Constants.PATH0])) { };
#endregion
#region PATH1
SaveDataPath[Constants.PATH1] = SaveDataPathCommon + "_PATH2.csv";
using (StreamWriter sw1 = File.CreateText(@SaveDataPath[Constants.PATH1])) { };
#endregion
#region PATH2
SaveDataPath[Constants.PATH2] = SaveDataPathCommon + "_PATH3.csv";
using (StreamWriter sw2 = File.CreateText(@SaveDataPath[Constants.PATH2])) { };
#endregion
#endregion
#region Decode and store data
CsvLogging.DecodeHeader(Lines, SaveDataPath);
CsvLogging.DecodeAandB(Lines, SaveDataPath, crystalFrequency);
CsvLogging.DecodeD(Lines, SaveDataPath, crystalFrequency);
CsvLogging.DecodeI(Lines, SaveDataPath, crystalFrequency);
MessageBox.Show("Conversion to CSV finished", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Information);
#endregion
#region New default directory
defaultDirectory = NewDefaultDirectory;
#endregion
}
catch (Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exception(), "CsvLogging.Convert() failed", "0x" + ex.HResult.ToString("X", culture), String.Empty);
MessageBox.Show("Conversion to CSV failed", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endregion
}
#endregion
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Value = 0;
}
public static void DecodeHeader(String[] lines, String[] saveDataPath)
{
#region Definitions and initializations
String HeaderText = String.Empty;
String[] HexValues;
Int32 NumberOfLines = lines.Count();
UInt32 RawLine = 0;
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
#endregion
try
{
for (RawLine = 0; RawLine < NumberOfLines - 1; RawLine++)
{
#region Prepare data
HexValues = lines[RawLine].Split(' ');
#endregion
#region Header
if (HexValues[0] == Message.Hcc)
{
#region Prepare data
for (Int32 HeaderColumnIndex = 0; HeaderColumnIndex < (Int32)HexValues.Count(); HeaderColumnIndex++)
{
if ((HeaderColumnIndex == 0) || (HeaderColumnIndex == (Int32)HexValues.Count() - 2) || (HeaderColumnIndex == (Int32)HexValues.Count() - 1))
HeaderText = HeaderText + HexValues[HeaderColumnIndex] + ";";
else
HeaderText = HeaderText + HexValues[HeaderColumnIndex] + " ";
}
#endregion
#region Write to file
using (StreamWriter sw0 = File.AppendText(@saveDataPath[Constants.PATH0]))
sw0.WriteLine(HeaderText);
using (StreamWriter sw1 = File.AppendText(@saveDataPath[Constants.PATH1]))
sw1.WriteLine(HeaderText);
using (StreamWriter sw2 = File.AppendText(@saveDataPath[Constants.PATH2]))
sw2.WriteLine(HeaderText);
HeaderText = String.Empty;
#endregion
}
#endregion
}
}
catch(Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exception(), "CsvLogging.DecodeHeader() failed", "0x" + ex.HResult.ToString("X", culture), RawLine.ToString(culture));
#endregion
}
}
public static void DecodeAandB(String[] lines, String[] saveDataPath, Double crystalFrequency)
{
#region Definitions and initializations
DecodedData[] Data = DecodedDataHelper.getDefaultDecodedDataArray(Constants.NumberOfPaths);
Double temp = 0;
UInt16 DecodedPath = Constants.PATH0;
Int32 index = 0;
Int32 NumberOfLines = lines.Count();
String[] CsvModeString = new String[Constants.NumberOfPaths] { String.Empty, String.Empty, String.Empty };
String[] HexValues;
String[] Date = new String[Constants.NumberOfPaths] { String.Empty, String.Empty, String.Empty };
String[] Time = new String[Constants.NumberOfPaths] { String.Empty, String.Empty, String.Empty };
String HeaderText = String.Empty;
String[] CsvLine = new String[Constants.NumberOfPaths] { String.Empty, String.Empty, String.Empty };
String CsvIndex = String.Empty;
UInt32[] CsvIndexValue = new UInt32[Constants.NumberOfPaths] { 0, 0, 0 };
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
#endregion
try
{
#region Convert data to files
for (UInt32 RawLine = 0; RawLine < NumberOfLines - 1; RawLine++)
{
#region Prepare data
HexValues = lines[RawLine].Split(' ');
#endregion
#region TDC data
if (HexValues[2].Contains("a") || (HexValues[2].Contains("b") && (!(HexValues[3].Contains(Message.Temperature)))))
{
#region Decode and display
foreach (String HexValue in HexValues)
{
HexValue.Replace(@"\", String.Empty);
switch (index)
{
#region Decode and display telegram
#region Date (not used)
case 0:
// [not used]
break;
#endregion
#region Time (not used)
case 1:
// [not used]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Decode PATH
case 3:
DecodedPath = UInt16.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Date[DecodedPath] = HexValues[0];
Time[DecodedPath] = HexValues[1];
break;
#endregion
#region Decode HCC-Val
case 4:
#region Calculate value
UInt32 HccValTemp = UInt32.Parse(HexValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Data[DecodedPath].HccVal = (Double)HccValTemp;
Data[DecodedPath].HccCorrectionFactor = (4 * Constants.NominalFrequency * 1000000) / ((HccValTemp >> 16) * 32768);
#endregion
break;
#endregion
#region TOF sum of all up
case 5:
#region Calculate Value
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofSumOfAllUp = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region Pulse width up
case 6:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].PulsewidthUp = Math.Round((((Double)temp / 128)), 2);
#endregion
break;
#endregion
#region Amplitude up
case 7:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].AmpUpRaw = (Double)UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier);
#endregion
break;
#endregion
#region Amplitude calibrate value high
case 8:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].AmpCalHigh = (Double)UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier);
#endregion
break;
#endregion
#region TOF sum of all down
case 9:
#region Calculate Value
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofSumOfAllDown = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region Pulse width down
case 10:
#region Calculate value
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].PulsewidthDown = Math.Round((((Double)temp / 128)), 2);
#endregion
break;
#endregion
#region Amplitude down
case 11:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].AmpDownRaw = (Double)UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier);
#endregion
break;
#endregion
#region Amplitude calibrate value low
case 12:
#region Calculate Value
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].AmpCalLow = (Double)UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier);
Data[DecodedPath].AmpGradient = Constants.Vcal / (Data[DecodedPath].AmpCalHigh - Data[DecodedPath].AmpCalLow);
Data[DecodedPath].AmpOffset = ((2 * Data[DecodedPath].AmpCalLow) - Data[DecodedPath].AmpCalHigh) * Data[DecodedPath].AmpGradient;
Data[DecodedPath].AmpUpCalculated = Data[DecodedPath].AmpGradient * Data[DecodedPath].AmpUpRaw - Data[DecodedPath].AmpOffset;
Data[DecodedPath].AmpDownCalculated = Data[DecodedPath].AmpGradient * Data[DecodedPath].AmpDownRaw - Data[DecodedPath].AmpOffset;
#endregion
break;
#endregion
#region TOF0 up
case 13:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT0] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF1 up
case 14:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT1] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF2 up
case 15:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT2] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF3 up
case 16:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT3] = Math.Round((((double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF4 up
case 17:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT4] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF5 up
case 18:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT5] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF6 up
case 19:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT6] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF7 up
case 20:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofUp[Constants.HIT7] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF0 down
case 21:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofDown[Constants.HIT0] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF1 down
case 22:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofDown[Constants.HIT1] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF2 down
case 23:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofDown[Constants.HIT2] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF3 down
case 24:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier);
Data[DecodedPath].TofDown[Constants.HIT3] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF4 down
case 25:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofDown[Constants.HIT4] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF5 down
case 26:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier);
Data[DecodedPath].TofDown[Constants.HIT5] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF6 down
case 27:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofDown[Constants.HIT6] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region TOF7 down
case 28:
#region Calculate value and assign
temp = UInt32.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
Data[DecodedPath].TofDown[Constants.HIT7] = Math.Round((((Double)temp / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
#endregion
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == HexValues.Count()-1)
{
#region Mode
CsvModeString[DecodedPath] = Constants.CsvDefaultModeString;
#endregion
#region Misc
CsvIndex = String.Format(Formats.CsvIndexLogString, CsvIndexValue[DecodedPath]); // set first colums csv index value
index = 0; // reset counter
#endregion
#region Fill CSV-String PATH0 and write to file
#region Fill CSV-String
CsvLine[DecodedPath] = Date[DecodedPath] + ";" + Time[DecodedPath] + ";";
for (UInt16 Hit = 0; Hit < 8; Hit++)
{
CsvLine[DecodedPath] = CsvLine[DecodedPath] + Data[DecodedPath].TofUp[Hit].ToString(Formats.TofLogString, culture) + Units.TofCsvLogString
+ Data[DecodedPath].TofDown[Hit].ToString(Formats.TofLogString) + Units.TofCsvLogString;
}
CsvLine[DecodedPath] = CsvLine[DecodedPath] + Data[DecodedPath].PulsewidthUp.ToString(Formats.PwLogString, culture) + ";"
+ Data[DecodedPath].PulsewidthDown.ToString(Formats.PwLogString, culture) + ";"
+ Data[DecodedPath].AmpUpCalculated.ToString(Formats.AmpLogString, culture) + ";"
+ Data[DecodedPath].AmpDownCalculated.ToString(Formats.AmpLogString, culture) + ";"
+ CsvModeString[DecodedPath] + ";"
+ Data[DecodedPath].TemperatureHot.ToString(Formats.TempLogString, culture) + ";"
+ Data[DecodedPath].TemperatureCold.ToString(Formats.TempLogString, culture);
#endregion
#region Write to file
using (StreamWriter sw0 = File.AppendText(@saveDataPath[DecodedPath]))
sw0.WriteLine(CsvIndexValue[DecodedPath] + ";" + CsvLine[DecodedPath] + ";");
CsvLine[DecodedPath] = String.Empty; // Reset String
CsvIndexValue[DecodedPath]++;
#endregion
#endregion
}
else
index++; // switch to next position of data
}
#endregion
goto SkipOptions; // also works without 'goto' if you want to be MISRA compliant
}
#endregion
#region Temperature data
if (HexValues[2].Contains("b") && HexValues[3].Contains(Message.Temperature))
{
#region Decode and display
foreach (String HexValue in HexValues)
{
switch (index)
{
#region Decode and display telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Decode PATH
case 4:
DecodedPath = UInt16.Parse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
break;
#endregion
#region Schmitt trigger delay compensation value (not used)
case 5:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference impedance value (not used)
case 6:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT cold impedance value (not used)
case 7:
#region Calculate Value
// [tbd]
#endregion
break;
#endregion
#region Pt hot impedance value (not used)
case 8:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference 1st (on) correction value (not used)
case 9:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region Schmitt trigger delay compensation value (not used)
case 10:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference impedance value (not used)
case 11:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT cold impedance value (not used)
case 12:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT hot impedance value (not used)
case 13:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference 1st (on) correction value (not used)
case 14:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region Temperature (cold)
case 15:
#region Calculate value
Data[DecodedPath].TemperatureCold = (Double)UInt32.Parse(HexValue, CultureInfo.InvariantCulture);
Data[DecodedPath].TemperatureHot = 0.00; // Dummy data
#endregion
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == HexValues.Count()-1)
{
#region Reset index
index = 0;
#endregion
}
else
index++; // switch to next position of data
}
#endregion
}
#endregion
SkipOptions:;
}
#endregion
}
catch(Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exception(), "CsvLogging.DecodeAandB() failed", "0x" + ex.HResult.ToString("X", culture), "index= "+index.ToString());
#endregion
}
}
public static void DecodeD(String[] lines, String[] saveDataPath, Double crystalFrequency)
{
#region Definitions and initializations
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
DecodedData[] Data = new DecodedData[Constants.NumberOfPaths];
for (UInt16 Path = Constants.PATH0; Path < Constants.NumberOfPaths; Path++)
{
Data[Path] = new DecodedData();
Data[Path].HccCorrectionFactor = 1; // Default value
}
Double tempDouble = 0;
UInt32 tempUInt32 = 0;
UInt16 DecodedPath = Constants.PATH0;
Int32 index = 0;
Int32 NumberOfLines = lines.Count();
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Maximum = NumberOfLines - 1;
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Value = 0;
String[] CsvModeString = new String[Constants.NumberOfPaths];
String[] HexValues;
String[] Date = new String[Constants.NumberOfPaths];
String[] Time = new String[Constants.NumberOfPaths];
String HeaderText = String.Empty;
String[] CsvLine = new String[Constants.NumberOfPaths];
String CsvIndex = String.Empty;
UInt32[] CsvIndexValue = new UInt32[Constants.NumberOfPaths];
for(UInt16 Path = Constants.PATH0; Path < Constants.NumberOfPaths; Path++)
{
CsvModeString[Path] = String.Empty;
Date[Path] = String.Empty;
Time[Path] = String.Empty;
CsvLine[Path] = String.Empty;
CsvIndexValue[Path] = 0;
}
#endregion
try
{
#region Convert data to files
for (UInt32 RawLine = 0; RawLine < NumberOfLines-1; RawLine++)
{
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Value = (Int32)RawLine;
#region Prepare data
HexValues = lines[RawLine].Split(' ');
#endregion
#region TDC data
if (HexValues.Count() == 30)
{
if ((HexValues[2] == "d") && (HexValues[3] == Message.Data))
{
#region Decode and display
foreach (String HexValue in HexValues)
{
// HexValue.Replace(@"\", String.Empty); Why have I done this?
switch (index)
{
#region Decode telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Decode PATH
case 4:
if (UInt16.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out DecodedPath))
{
DecodedPath--;
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (HexValues[0].Contains("-"))
{
Date[DecodedPath] = HexValues[0];
Time[DecodedPath] = HexValues[1];
}
else
{
Date[DecodedPath] = HexValues[1];
Time[DecodedPath] = HexValues[0];
}
}
}
else
DecodedPath = Constants.NOPATH;
break;
#endregion
#region Data valid (not used)
case 5:
// [tbd]
break;
#endregion
#region TOF sum of all up (not used
case 6:
// [tbd]
break;
#endregion
#region Pulse width up
case 7:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].PulsewidthUp = Math.Round((((Double)tempUInt32 / 128)), 2);
else
Data[DecodedPath].PulsewidthUp = 0;
}
#endregion
break;
#endregion
#region Amplitude up
case 8:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].AmpUpRaw = (Double)tempUInt32;
else
Data[DecodedPath].AmpUpRaw = 0;
}
#endregion
break;
#endregion
#region Amplitude calibrate value high
case 9:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].AmpCalHigh = (Double)tempUInt32;
else
Data[DecodedPath].AmpCalHigh = 0;
}
#endregion
break;
#endregion
#region TOF sum of all down
case 10:
#region Calculate Value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofSumOfAllDown = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofSumOfAllDown = 0;
}
#endregion
break;
#endregion
#region Pulse width down
case 11:
#region Calculate value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].PulsewidthDown = Math.Round((((double)tempUInt32 / 128)), 2);
else
Data[DecodedPath].PulsewidthDown = 0;
}
#endregion
break;
#endregion
#region Amplitude down
case 12:
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].AmpDownRaw = tempUInt32;
else
Data[DecodedPath].AmpDownRaw = 0;
}
break;
#endregion
#region Amplitude calibrate value low
case 13:
#region Calculate value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
{
Data[DecodedPath].AmpCalLow = (Double)tempUInt32;
Data[DecodedPath].AmpGradient = Constants.Vcal / (Data[DecodedPath].AmpCalHigh - Data[DecodedPath].AmpCalLow);
Data[DecodedPath].AmpOffset = ((2 * Data[DecodedPath].AmpCalLow) - Data[DecodedPath].AmpCalHigh) * Data[DecodedPath].AmpGradient;
Data[DecodedPath].AmpUpCalculated = Data[DecodedPath].AmpGradient * Data[DecodedPath].AmpUpRaw - Data[DecodedPath].AmpOffset;
Data[DecodedPath].AmpDownCalculated = Data[DecodedPath].AmpGradient * Data[DecodedPath].AmpDownRaw - Data[DecodedPath].AmpOffset;
}
else
{
Data[DecodedPath].AmpCalLow = 0;
Data[DecodedPath].AmpGradient = 0;
Data[DecodedPath].AmpOffset = 0;
Data[DecodedPath].AmpUpCalculated = 0;
Data[DecodedPath].AmpDownCalculated = 0;
}
}
#endregion
break;
#endregion
#region TOF0 up
case 14:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT0] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT0] = 0;
}
#endregion
break;
#endregion
#region TOF1 up
case 15:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT1] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT1] = 0;
}
#endregion
break;
#endregion
#region TOF2 up
case 16:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT2] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT2] = 0;
}
#endregion
break;
#endregion
#region TOF3 up
case 17:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT3] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT3] = 0;
}
#endregion
break;
#endregion
#region TOF4 up
case 18:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT4] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT4] = 0;
}
#endregion
break;
#endregion
#region TOF5 up
case 19:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT5] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT5] = 0;
}
#endregion
break;
#endregion
#region TOF6 up
case 20:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT6] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT6] = 0;
}
#endregion
break;
#endregion
#region TOF7 up
case 21:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT7] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT7] = 0;
}
#endregion
break;
#endregion
#region TOF0 down
case 22:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT0] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT0] = 0;
}
#endregion
break;
#endregion
#region TOF1 down
case 23:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT1] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT1] = 0;
}
#endregion
break;
#endregion
#region TOF2 down
case 24:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT2] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT2] = 0;
}
#endregion
break;
#endregion
#region TOF3 down
case 25:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT3] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT3] = 0;
}
#endregion
break;
#endregion
#region TOF4 down
case 26:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT4] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT4] = 0;
}
#endregion
break;
#endregion
#region TOF5 down
case 27:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT5] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT5] = 0;
}
#endregion
break;
#endregion
#region TOF6 down
case 28:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT6] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT6] = 0;
}
#endregion
break;
#endregion
#region TOF7 down
case 29:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT7] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT7] = 0;
}
#endregion
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == HexValues.Count() - 1)
{
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
#region Mode
CsvModeString[DecodedPath] = Constants.CsvDefaultModeString;
#endregion
#region Set/ reset indeces
CsvIndex = String.Format(Formats.CsvIndexLogString, CsvIndexValue[DecodedPath]); // set first colums csv index value
index = 0; // reset counter
#endregion
#region Fill CSV-String PATH0 and write to file
#region Fill CSV-String
Date[DecodedPath] = Date[DecodedPath].Replace('-', '.');
CsvLine[DecodedPath] = Time[DecodedPath] + ";" + Date[DecodedPath] + ";";
for (UInt16 Hit = Constants.HIT0; Hit < 8; Hit++)
{
CsvLine[DecodedPath] = CsvLine[DecodedPath] + Data[DecodedPath].TofUp[Hit].ToString(Formats.TofLogString) + Units.TofCsvLogString
+ Data[DecodedPath].TofDown[Hit].ToString(Formats.TofLogString) + Units.TofCsvLogString;
}
CsvLine[DecodedPath] =
CsvLine[DecodedPath] + Data[DecodedPath].PulsewidthUp.ToString(Formats.PwLogString) + ";"
+ Data[DecodedPath].PulsewidthDown.ToString(Formats.PwLogString) + ";"
+ Data[DecodedPath].AmpUpCalculated.ToString(Formats.AmpLogString) + ";"
+ Data[DecodedPath].AmpDownCalculated.ToString(Formats.AmpLogString) + ";"
+ CsvModeString[DecodedPath] + ";"
+ Data[DecodedPath].TemperatureHot.ToString(Formats.TempLogString) + ";"
+ Data[DecodedPath].TemperatureCold.ToString(Formats.TempLogString);
#endregion
#region Write to file
using (StreamWriter sw0 = File.AppendText(@saveDataPath[DecodedPath]))
sw0.WriteLine(CsvIndexValue[DecodedPath] + ";" + CsvLine[DecodedPath] + ";");
CsvLine[DecodedPath] = String.Empty; // Reset String
CsvIndexValue[DecodedPath]++;
#endregion
#endregion
}
index = 0;
}
else
index++; // switch to next position of data
}
#endregion
goto SkipOptions; // Also works without 'goto' if you want to be MISRA compliant
}
}
#endregion
#region Temperature data
if (HexValues.Count() == 16)
{
if ((HexValues[2] == "d") && (HexValues[3] == Message.Temperature))
{
#region Decode and Display
foreach (String HexValue in HexValues)
{
switch (index)
{
#region Decode and display telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Data valid (not used)
case 4:
// [tbd]
break;
#endregion
#region Schmitt trigger delay compensation value (not used)
case 5:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference impedance value (not used)
case 6:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT cold impedance value (not used)
case 7:
#region Calculate Value
// [tbd]
#endregion
break;
#endregion
#region Pt hot impedance value (not used)
case 8:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference 1st (on) correction value (not used)
case 9:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region Schmitt trigger delay compensation value (not used)
case 10:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference impedance value (not used)
case 11:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT cold impedance value (not used)
case 12:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT hot impedance value (not used)
case 13:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference 1st (on) correction value (not used)
case 14:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region Temperature (cold)
case 15:
#region Calculate value
if (Double.TryParse(HexValue, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out tempDouble))
{
Data[Constants.PATH0].TemperatureCold = tempDouble;
Data[Constants.PATH1].TemperatureCold = tempDouble;
Data[Constants.PATH2].TemperatureCold = tempDouble;
}
else
{
Data[Constants.PATH0].TemperatureCold = 0;
Data[Constants.PATH1].TemperatureCold = 0;
Data[Constants.PATH2].TemperatureCold = 0;
}
Data[Constants.PATH0].TemperatureHot = 0.00; // Dummy data
Data[Constants.PATH1].TemperatureHot = 0.00; // Dummy data
Data[Constants.PATH2].TemperatureHot = 0.00; // Dummy data
#endregion
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == HexValues.Count() - 1)
{
#region Reset index
index = 0;
#endregion
}
else
index++; // switch to next position of data
}
#endregion
goto SkipOptions; // Also works without 'goto' if you want to be MISRA compliant
}
}
#endregion
#region HCC-Value
if (HexValues.Count() == 6)
{
if ((HexValues[2] == "d") && (HexValues[3] == Message.Hcc))
{
#region Decode and display
foreach (String HexValue in HexValues)
{
switch (index)
{
#region Decode and display telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Decode PATH
case 4:
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
DecodedPath = (UInt16)tempUInt32;
else
DecodedPath = Constants.NOPATH;
DecodedPath--;
break;
#endregion
#region HCC-Value
case 5:
#region Calculate value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
UInt32 HccValTemp = UInt32.Parse(HexValue, NumberStyles.HexNumber);
Data[DecodedPath].HccVal = (double)HccValTemp;
Data[DecodedPath].HccCorrectionFactor = (4 * Constants.NominalFrequency * 1000000) / ((HccValTemp >> 16) * 32768);
}
#endregion
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == HexValues.Count() - 1)
{
#region reset index
index = 0;
#endregion
}
else
index++; // switch to next position of data
}
#endregion
}
}
#endregion
SkipOptions:; // from 'goto'
}
#endregion
}
catch (Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exception(), "CsvLogging.DecodeD() failed", "0x" + ex.HResult.ToString("X"), "index= " + index.ToString());
#endregion
}
}
public static void DecodeI(String[] lines, String[] saveDataPath, Double crystalFrequency)
{
#region Definitions and initializations
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
DecodedData[] Data = new DecodedData[Constants.NumberOfPaths];
for (UInt16 Path = Constants.PATH0; Path < Constants.NumberOfPaths; Path++)
Data[Path] = new DecodedData();
Data[Constants.PATH0].HccCorrectionFactor = 1; // Default value
Data[Constants.PATH1].HccCorrectionFactor = 1; // Default value
Data[Constants.PATH2].HccCorrectionFactor = 1; // Default value
Double tempDouble = 0;
UInt32 tempUInt32 = 0;
UInt16 DecodedPath = Constants.PATH0;
Int32 index = 0;
Int32 NumberOfLines = lines.Count();
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Maximum = NumberOfLines - 1;
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Value = 0;
String[] CsvModeString = new String[Constants.NumberOfPaths];
String[] HexValues;
String[] Date = new String[Constants.NumberOfPaths];
String[] Time = new String[Constants.NumberOfPaths];
String HeaderText = String.Empty;
String[] CsvLine = new String[Constants.NumberOfPaths];
String CsvIndex = String.Empty;
UInt32[] CsvIndexValue = new UInt32[Constants.NumberOfPaths];
for (UInt16 Path = Constants.PATH0; Path < Constants.NumberOfPaths; Path++)
{
CsvModeString[Path] = String.Empty;
Date[Path] = String.Empty;
Time[Path] = String.Empty;
CsvLine[Path] = String.Empty;
CsvIndexValue[Path] = 0;
}
#endregion
try
{
#region Convert data to files
for (UInt32 RawLine = 0; RawLine < NumberOfLines - 1; RawLine++)
{
GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.pB_CsvConversion.Value = (Int32)RawLine;
#region Prepare data
HexValues = lines[RawLine].Split(' ');
#endregion
#region TDC data
if ((HexValues[2] == "i") && (HexValues[3] == Message.Data)&&(HexValues.Count() == 31))
{
#region Decode and display
foreach (String HexValue in HexValues)
{
// HexValue.Replace(@"\", String.Empty); Why have I done this?
switch (index)
{
#region Decode telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Decode PATH
case 4:
if (UInt16.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out DecodedPath))
{
DecodedPath--;
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
Date[DecodedPath] = HexValues[0];
Time[DecodedPath] = HexValues[1];
}
}
else
DecodedPath = Constants.NOPATH;
break;
#endregion
#region Data valid (not used)
case 5:
// [tbd]
break;
#endregion
#region TOF sum of all up (not used
case 6:
// [tbd]
break;
#endregion
#region Pulse width up
case 7:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].PulsewidthUp = Math.Round((((Double)tempUInt32 / 128)), 2);
else
Data[DecodedPath].PulsewidthUp = 0;
}
#endregion
break;
#endregion
#region Amplitude up
case 8:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].AmpUpRaw = (Double)tempUInt32;
else
Data[DecodedPath].AmpUpRaw = 0;
}
#endregion
break;
#endregion
#region Amplitude calibrate value high
case 9:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].AmpCalHigh = (Double)tempUInt32;
else
Data[DecodedPath].AmpCalHigh = 0;
}
#endregion
break;
#endregion
#region TOF sum of all down
case 10:
#region Calculate Value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofSumOfAllDown = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofSumOfAllDown = 0;
}
#endregion
break;
#endregion
#region Pulse width down
case 11:
#region Calculate value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].PulsewidthDown = Math.Round((((Double)tempUInt32 / 128)), 2);
else
Data[DecodedPath].PulsewidthDown = 0;
}
#endregion
break;
#endregion
#region Amplitude down
case 12:
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].AmpDownRaw = tempUInt32;
else
Data[DecodedPath].AmpDownRaw = 0;
}
break;
#endregion
#region Amplitude calibrate value low
case 13:
#region Calculate value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
{
Data[DecodedPath].AmpCalLow = (Double)tempUInt32;
Data[DecodedPath].AmpGradient = Constants.Vcal / (Data[DecodedPath].AmpCalHigh - Data[DecodedPath].AmpCalLow);
Data[DecodedPath].AmpOffset = ((2 * Data[DecodedPath].AmpCalLow) - Data[DecodedPath].AmpCalHigh) * Data[DecodedPath].AmpGradient;
Data[DecodedPath].AmpUpCalculated = Data[DecodedPath].AmpGradient * Data[DecodedPath].AmpUpRaw - Data[DecodedPath].AmpOffset;
Data[DecodedPath].AmpDownCalculated = Data[DecodedPath].AmpGradient * Data[DecodedPath].AmpDownRaw - Data[DecodedPath].AmpOffset;
}
else
{
Data[DecodedPath].AmpCalLow = 0;
Data[DecodedPath].AmpGradient = 0;
Data[DecodedPath].AmpOffset = 0;
Data[DecodedPath].AmpUpCalculated = 0;
Data[DecodedPath].AmpDownCalculated = 0;
}
}
#endregion
break;
#endregion
#region TOF0 up
case 14:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT0] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT0] = 0;
}
#endregion
break;
#endregion
#region TOF1 up
case 15:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT1] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT1] = 0;
}
#endregion
break;
#endregion
#region TOF2 up
case 16:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT2] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT2] = 0;
}
#endregion
break;
#endregion
#region TOF3 up
case 17:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT3] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT3] = 0;
}
#endregion
break;
#endregion
#region TOF4 up
case 18:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT4] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT4] = 0;
}
#endregion
break;
#endregion
#region TOF5 up
case 19:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT5] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT5] = 0;
}
#endregion
break;
#endregion
#region TOF6 up
case 20:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT6] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT6] = 0;
}
#endregion
break;
#endregion
#region TOF7 up
case 21:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofUp[Constants.HIT7] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofUp[Constants.HIT7] = 0;
}
#endregion
break;
#endregion
#region TOF0 down
case 22:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT0] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT0] = 0;
}
#endregion
break;
#endregion
#region TOF1 down
case 23:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT1] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT1] = 0;
}
#endregion
break;
#endregion
#region TOF2 down
case 24:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT2] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT2] = 0;
}
#endregion
break;
#endregion
#region TOF3 down
case 25:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT3] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT3] = 0;
}
#endregion
break;
#endregion
#region TOF4 down
case 26:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT4] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT4] = 0;
}
#endregion
break;
#endregion
#region TOF5 down
case 27:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT5] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT5] = 0;
}
#endregion
break;
#endregion
#region TOF6 down
case 28:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT6] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT6] = 0;
}
#endregion
break;
#endregion
#region TOF7 down
case 29:
#region Calculate value and assign
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
Data[DecodedPath].TofDown[Constants.HIT7] = Math.Round((((Double)tempUInt32 / 65536) * (1000 / (crystalFrequency))) * Data[DecodedPath].HccCorrectionFactor, 8);
else
Data[DecodedPath].TofDown[Constants.HIT7] = 0;
}
#endregion
break;
#endregion
#region CRC
case 30:
//[tbd]
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == HexValues.Count() - 1)
{
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
#region Mode
CsvModeString[DecodedPath] = Constants.CsvDefaultModeString;
#endregion
#region Set/ reset indeces
CsvIndex = String.Format(Formats.CsvIndexLogString, CsvIndexValue[DecodedPath]); // set first colums csv index value
index = 0; // reset counter
#endregion
#region Fill CSV-String PATH0 and write to file
#region Fill CSV-String
Date[DecodedPath] = Date[DecodedPath].Replace('-', '.');
CsvLine[DecodedPath] = Time[DecodedPath] + ";" + Date[DecodedPath] + ";";
for (UInt16 Hit = Constants.HIT0; Hit < 8; Hit++)
{
CsvLine[DecodedPath] = CsvLine[DecodedPath] + Data[DecodedPath].TofUp[Hit].ToString(Formats.TofLogString, culture) + Units.TofCsvLogString
+ Data[DecodedPath].TofDown[Hit].ToString(Formats.TofLogString, culture) + Units.TofCsvLogString;
}
CsvLine[DecodedPath] =
CsvLine[DecodedPath] + Data[DecodedPath].PulsewidthUp.ToString(Formats.PwLogString, culture) + ";"
+ Data[DecodedPath].PulsewidthDown.ToString(Formats.PwLogString, culture) + ";"
+ Data[DecodedPath].AmpUpCalculated.ToString(Formats.AmpLogString, culture) + ";"
+ Data[DecodedPath].AmpDownCalculated.ToString(Formats.AmpLogString, culture) + ";"
+ CsvModeString[DecodedPath] + ";"
+ Data[DecodedPath].TemperatureHot.ToString(Formats.TempLogString) + ";"
+ Data[DecodedPath].TemperatureCold.ToString(Formats.TempLogString, culture);
#endregion
#region Write to file
using (StreamWriter sw0 = File.AppendText(@saveDataPath[DecodedPath]))
sw0.WriteLine(CsvIndexValue[DecodedPath] + ";" + CsvLine[DecodedPath] + ";");
CsvLine[DecodedPath] = String.Empty; // Reset String
CsvIndexValue[DecodedPath]++;
#endregion
#endregion
}
index = 0;
}
else
index++; // switch to next position of data
}
#endregion
goto SkipOptions; // Also works without 'goto' if you want to be MISRA compliant
}
#endregion
#region Temperature data
if ((HexValues[2] == "i") && (HexValues[3] == Message.Temperature) && (HexValues.Count() == 17))
{
#region Decode and Display
foreach (String HexValue in HexValues)
{
switch (index)
{
#region Decode and display telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Data valid (not used)
case 4:
// [tbd]
break;
#endregion
#region Schmitt trigger delay compensation value (not used)
case 5:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference impedance value (not used)
case 6:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT cold impedance value (not used)
case 7:
#region Calculate Value
// [tbd]
#endregion
break;
#endregion
#region Pt hot impedance value (not used)
case 8:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference 1st (on) correction value (not used)
case 9:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region Schmitt trigger delay compensation value (not used)
case 10:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference impedance value (not used)
case 11:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT cold impedance value (not used)
case 12:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT hot impedance value (not used)
case 13:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region PT reference 1st (on) correction value (not used)
case 14:
#region Calculate value
// [tbd]
#endregion
break;
#endregion
#region Temperature (cold)
case 15:
#region Calculate value
if (Double.TryParse(HexValue, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out tempDouble))
{
Data[Constants.PATH0].TemperatureCold = tempDouble;
Data[Constants.PATH1].TemperatureCold = tempDouble;
Data[Constants.PATH2].TemperatureCold = tempDouble;
}
else
{
Data[Constants.PATH0].TemperatureCold = 0;
Data[Constants.PATH1].TemperatureCold = 0;
Data[Constants.PATH2].TemperatureCold = 0;
}
Data[Constants.PATH0].TemperatureHot = 0.00; // Dummy data
Data[Constants.PATH1].TemperatureHot = 0.00; // Dummy data
Data[Constants.PATH2].TemperatureHot = 0.00; // Dummy data
#endregion
break;
#endregion
#region CRC
case 16:
// tbd
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == 16)
{
#region Reset index
index = 0;
#endregion
}
else
index++; // switch to next position of data
}
#endregion
goto SkipOptions; // Also works without 'goto' if you want to be MISRA compliant
}
#endregion
#region HCC-Value
if ((HexValues[2] == "i") && (HexValues[3] == Message.Hcc) && (HexValues.Count() == 7))
{
#region Decode and display
foreach (String HexValue in HexValues)
{
switch (index)
{
#region Decode and display telegram
#region Date (not used)
case 0:
// [tbd]
break;
#endregion
#region Time (not used)
case 1:
// [tbd]
break;
#endregion
#region Protocol version (not used)
case 2:
// [tbd]
break;
#endregion
#region Message type (not used)
case 3:
// [tbd]
break;
#endregion
#region Decode PATH
case 4:
if (UInt32.TryParse(HexValue, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out (tempUInt32)))
DecodedPath = (UInt16)tempUInt32;
else
DecodedPath = Constants.NOPATH;
DecodedPath--;
break;
#endregion
#region HCC-Value
case 5:
#region Calculate value
if ((DecodedPath == Constants.PATH0) || (DecodedPath == Constants.PATH1) || (DecodedPath == Constants.PATH2))
{
UInt32 HccValTemp = UInt32.Parse(HexValue, NumberStyles.HexNumber);
Data[DecodedPath].HccVal = (Double)HccValTemp;
Data[DecodedPath].HccCorrectionFactor = (4 * Constants.NominalFrequency * 1000000) / ((HccValTemp >> 16) * 32768);
}
#endregion
break;
#endregion
#region CRC
case 6:
// [tbd]
break;
#endregion
#region Default
default: break;
#endregion
#endregion
}
if (index == 6)
{
#region reset index
index = 0;
#endregion
}
else
index++; // switch to next position of data
}
#endregion
}
#endregion
SkipOptions:; // from 'goto'
}
#endregion
}
catch (Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exception(), "CsvLogging.DecodeI() failed", "0x" + ex.HResult.ToString("X", culture), "index= " + index.ToString(culture));
#endregion
}
}
}
}