laatzen/Common/CordoPlot/MainWindow.xaml.cs
2024-05-06 15:42:40 +02:00

139 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
using Xylem.Common.Metrology.Measurements;
namespace CordoPlot
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(Object sender, RoutedEventArgs e)
{
var dialog = new Microsoft.Win32.OpenFileDialog();
dialog.FileName = "led"; // Default file name
dialog.DefaultExt = ".log"; // Default file extension
dialog.Filter = "Text documents (.log)|*.log"; // Filter files by extension
// Show open file dialog box
bool? result = dialog.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dialog.FileName;
var AllLines = File.ReadAllLines(filename);
var listOfData = new List<IMeasurementRecord>();
var decoder = new StreamingDecoder();
var currentSyncmark = SyncMarkRecord.DecodeEveryPackage;
//DecodeMsg
foreach (var line in AllLines)
{
decoder = new StreamingDecoder();
if (line.Contains("|"))
{
var t = line.Split('|');
DateTime recived = DateTime.Now;
DateTime.TryParse(t[0], out recived);
if (t[1].Contains("@"))
{
decoder.DecodeMsg(t[1].Trim());
IMeasurementRecord recordToAdd;
if (decoder.DataBendDetectTest.IsValid)
{
decoder.DataBendDetectTest.ReceivedTime = recived;
decoder.DataBendDetectTest.SyncMarkRecord = currentSyncmark;
recordToAdd = decoder.DataBendDetectTest ;
}
else if (decoder.DataCalib.IsValid)
{
decoder.DataCalib.ReceivedTime = recived;
decoder.DataCalib.SyncMarkRecord = currentSyncmark;
recordToAdd = decoder.DataCalib;
}
else if (decoder.DataFlowTest.IsValid)
{
decoder.DataFlowTest.ReceivedTime = recived;
decoder.DataFlowTest.SyncMarkRecord = currentSyncmark;
recordToAdd = decoder.DataFlowTest;
}
else
{
//No valid data
continue;
}
listOfData.Add(recordToAdd);
}
else
{
if (line.Contains("Mark next incoming record as"))
{
if (line.Contains("Mark next incoming record as SyncStart"))
{
currentSyncmark = SyncMarkRecord.SyncStart;
}
else if (line.Contains("Mark next incoming record as DecodeIntermediate"))
{
currentSyncmark = SyncMarkRecord.DecodeIntermediate;
}
else if (line.Contains("Mark next incoming record as SkipDecoding"))
{
currentSyncmark = SyncMarkRecord.SkipDecoding;
}
else if (line.Contains("Mark next incoming record as SyncEnd"))
{
currentSyncmark = SyncMarkRecord.SyncEnd;
}
else
{
currentSyncmark = SyncMarkRecord.DecodeEveryPackage;
}
}
}
}
//FlowTestRecord
}
}
double[] dataX = { 1, 2, 3, 4, 5 };
double[] dataY = { 1, 4, 9, 16, 25 };
WpfPlot1.Plot.Add.Scatter(dataX, dataY);
WpfPlot1.Refresh();
}
}
}