common/Ui/GenesisToolBox/FrmRawDataInterpreter.cs
2026-04-23 17:50:07 +02:00

258 lines
9.0 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
namespace Xylem.Common.Ui.GenesisToolBox
{
public partial class FrmRawDataInterpreter : Form
{
public FrmRawDataInterpreter()
{
InitializeComponent();
}
private void btnOpenUpdateDirectory_Click(Object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
tbxFilePathSource.Text = openFileDialog.FileName;
tbxFilePathDest.Text = "same folder!";
}
private String ToLine(String time, List<String> entries)
{
var ret = time + ";";
foreach (var item in entries)
{
ret = ret + item + ";";
}
if (ret.Any())
{
ret.Substring(0, ret.Length - 1);
}
return ret;
}
private void btnWriteCsv_Click(Object sender, EventArgs e)
{
var lines = File.ReadAllLines(tbxFilePathSource.Text).ToList();
var listF = new List<String>();
var listH1 = new List<String>();
var listH2 = new List<String>();
var listH3 = new List<String>();
var outputFVolumeCm = cbFVolumeCm.Checked;
var outputFTimeS = cbFTimeS.Checked;
var outputHChannel = cbHChannel.Checked;
var outputHValidation = cbHValidation.Checked;
var outputHTotalTimeOfFlightS = cbHTotalTimeOfFlightS.Checked;
var outputHDeltaTimeOfFlightS = cbHDeltaTimeOfFlightS.Checked;
var outputHDeltaVolumeQm = cbHDeltaVolumeQm.Checked;
var outputHVolumeCm = cbHVolumeCm.Checked;
var outputHSampleIntervalS = cbHSampleIntervalS.Checked;
var outputHAmplitudeUpV = cbHAmplitudeUpV.Checked;
var outputHAmplitudeDownV = cbHAmplitudeDownV.Checked;
var outputHPulseWidthRatioUp = cbHPulseWidthRatioUp.Checked;
var outputHPulseWidthRatioDown = cbHPulseWidthRatioDown.Checked;
var outputHTemperatureDegC = cbHTemperatureDegC.Checked;
var outputHTimeS = cbHTimeS.Checked;
var header = "";
if (outputFVolumeCm) { header = header + "@F VolumeCm ;"; }
if (outputFTimeS) { header = header + "@F TimeS ;"; }
listF.Add("time;" + header);
header = "";
if (outputHChannel) { header = header + "@H Channel ;"; }
if (outputHValidation)
{
header = header + "@H Validation; ";
}
if (outputHTotalTimeOfFlightS)
{
header = header + "@H TotalTimeOfFlightS; ";
}
if (outputHDeltaTimeOfFlightS)
{
header = header + "@H DeltaTimeOfFlightS; ";
}
if (outputHDeltaVolumeQm)
{
header = header + "@H DeltaVolumeQm; ";
}
if (outputHVolumeCm)
{
header = header + "@H VolumeCm; ";
}
if (outputHSampleIntervalS)
{
header = header + "@H SampleIntervalS; ";
}
if (outputHAmplitudeUpV)
{
header = header + "@H AmplitudeUpV; ";
}
if (outputHAmplitudeDownV)
{
header = header + "@H AmplitudeDownV; ";
}
if (outputHPulseWidthRatioUp)
{
header = header + "@H PulseWidthRatioUp; ";
}
if (outputHPulseWidthRatioDown)
{
header = header + "@H PulseWidthRatioDown; ";
}
if (outputHTemperatureDegC)
{
header = header + "@H TemperatureDegC; ";
}
if (outputHTimeS)
{
header = header + "@H TimeS; ";
}
listH1.Add("time;" + header);
listH2.Add("time;" + header);
listH3.Add("time;" + header);
var _streamingDecode = new StreamingDecoder(false);
foreach (var txtline in lines)
{
var timeentry = txtline.Replace("| Trace |", "|").Split('|');
_streamingDecode = new StreamingDecoder(false);
if (_streamingDecode.DecodeMsg(timeentry[1].Trim()))
{
List<String> thisLine = new List<String>();
if (_streamingDecode.DataFlowTest != null)
{
if (outputFVolumeCm) { thisLine.Add(_streamingDecode.DataFlowTest.VolumeCm.ToString()); }
if (outputFTimeS)
{
thisLine.Add(_streamingDecode.DataFlowTest.TimeS.ToString());
}
listF.Add(ToLine(timeentry[0], thisLine));
}
else if (_streamingDecode.DataCalib != null)
{
if (outputHChannel)
{
thisLine.Add(_streamingDecode.DataCalib.Channel.ToString());
}
if (outputHValidation)
{
thisLine.Add(_streamingDecode.DataCalib.Validation.ToString());
}
if (outputHTotalTimeOfFlightS)
{
thisLine.Add(_streamingDecode.DataCalib.TotalTimeOfFlightS.ToString());
}
if (outputHDeltaTimeOfFlightS)
{
thisLine.Add(_streamingDecode.DataCalib.DeltaTimeOfFlightS.ToString());
}
if (outputHDeltaVolumeQm)
{
thisLine.Add(_streamingDecode.DataCalib.DeltaVolumeQm.ToString());
}
if (outputHVolumeCm)
{
thisLine.Add(_streamingDecode.DataCalib.VolumeCm.ToString());
}
if (outputHSampleIntervalS)
{
thisLine.Add(_streamingDecode.DataCalib.SampleIntervalS.ToString());
}
if (outputHAmplitudeUpV)
{
thisLine.Add(_streamingDecode.DataCalib.AmplitudeUpV.ToString());
}
if (outputHAmplitudeDownV)
{
thisLine.Add(_streamingDecode.DataCalib.AmplitudeDownV.ToString());
}
if (outputHPulseWidthRatioUp)
{
thisLine.Add(_streamingDecode.DataCalib.PulseWidthRatioUp.ToString());
}
if (outputHPulseWidthRatioDown)
{
thisLine.Add(_streamingDecode.DataCalib.PulseWidthRatioDown.ToString());
}
if (outputHTemperatureDegC)
{
thisLine.Add(_streamingDecode.DataCalib.TemperatureDegC.ToString());
}
if (outputHTimeS)
{
thisLine.Add(_streamingDecode.DataCalib.TimeS.ToString());
}
var fullAtrLine = ToLine(timeentry[0], thisLine);
if (_streamingDecode.DataCalib.Channel == 1)
{
listH1.Add(fullAtrLine);
}
if (_streamingDecode.DataCalib.Channel == 2)
{
listH2.Add(fullAtrLine);
}
if (_streamingDecode.DataCalib.Channel == 3)
{
listH3.Add(fullAtrLine);
}
}
}
}
var newfilenanme = tbxFilePathSource.Text.Substring(0, tbxFilePathSource.Text.Length - 4);
try
{
File.WriteAllLines(newfilenanme + "F.csv", listF.ToArray());
File.WriteAllLines(newfilenanme + "H1.csv", listH1.ToArray());
File.WriteAllLines(newfilenanme + "H2.csv", listH2.ToArray());
File.WriteAllLines(newfilenanme + "H3.csv", listH3.ToArray());
MessageBox.Show(@"done");
}
catch (Exception ex )
{
MessageBox.Show(@"abspeichern nicht geklappt . ggf. ist die datei noch geöffnet oder wir haben nicht genug rechte");
}
}
}
}