Rebuild connecting, bugfixes

This commit is contained in:
2015-10-19 22:25:23 +02:00
parent f03ccad863
commit f0578091d8
7 changed files with 41 additions and 40 deletions
@@ -6,19 +6,22 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace ErgometerApplication
{
public class ChartPanel:Panel
public class ChartPanel : Panel
{
private Chart chart;
private MetingType type;
private ChartArea chartArea;
private Series series;
private SeriesChartType ChartType;
public ChartPanel(MetingType type) : base()
public ChartPanel(MetingType type, SeriesChartType charttype) : base()
{
this.type = type;
this.ChartType = charttype;
this.chart = new Chart();
this.chartArea = new ChartArea();
this.chart.Titles.Add(new Title(type.ToString()));
@@ -32,7 +35,7 @@ namespace ErgometerApplication
this.chartArea.Name = "chartArea";
this.chart.Size = new System.Drawing.Size(250, 200);
this.chart.Dock = DockStyle.Fill;
this.chart.Series.Add(series);
this.chart.Text = "chart";
@@ -56,7 +59,7 @@ namespace ErgometerApplication
{
Series serie = new Series();
serie.Name = "series";
serie.ChartType = SeriesChartType.Line;
serie.ChartType = ChartType;
serie.ChartArea = "chartArea";
serie.BorderWidth = 3;
return serie;
@@ -64,7 +67,7 @@ namespace ErgometerApplication
public int getMetingType(Meting meting)
{
switch(type)
switch (type)
{
case MetingType.HEARTBEAT:
return meting.HeartBeat;
@@ -83,7 +86,7 @@ namespace ErgometerApplication
case MetingType.ACTUALPOWER:
return meting.ActualPower;
default:
return 0;
return 0;
}
}
@@ -96,7 +99,7 @@ namespace ErgometerApplication
POWER,
ENERGY,
SECONDS,
ACTUALPOWER
ACTUALPOWER
}
}
}
@@ -57,7 +57,7 @@ namespace ErgometerApplication
//
// updateTimer
//
this.updateTimer.Interval = 800;
this.updateTimer.Interval = 600;
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
//
// panelClientContainer
@@ -32,10 +32,8 @@ namespace ErgometerApplication
private void updateTimer_Tick(object sender, EventArgs e)
{
Console.WriteLine("Trying to send data....");
if(MainClient.Doctor.Connected)
{
Console.WriteLine("Sending data");
MainClient.ComPort.Write("ST");
string response = MainClient.ComPort.Read();
Meting m = MainClient.SaveMeting(response);
@@ -13,7 +13,7 @@ namespace ErgometerApplication
{
public static ComPort ComPort { get; }
public static TcpClient Doctor { get; }
public static TcpClient Doctor { get; set; }
public static List<Meting> Metingen { get; }
public static List<ChatMessage> Chat { get; }
@@ -37,8 +37,6 @@ namespace ErgometerApplication
Metingen = new List<Meting>();
Chat = new List<ChatMessage>();
t = new Thread(run);
Name = "Unknown";
Session = 0;
Loggedin = false;
@@ -53,16 +51,21 @@ namespace ErgometerApplication
{
error = "Succes";
if (!Doctor.Connected)
if (Doctor == null || !Doctor.Connected)
{
try {
if (Doctor == null)
Doctor = new TcpClient();
try
{
Doctor.Connect(HOST, PORT);
}
catch (Exception e)
{
error = "De server is niet online.";
error = "Server is niet online.";
return false;
}
Name = name;
NetCommand net = NetHelper.ReadNetCommand(Doctor);
@@ -72,6 +75,8 @@ namespace ErgometerApplication
throw new Exception("Session not assigned");
running = true;
t = new Thread(run);
t.IsBackground = true;
t.Start();
}
@@ -105,7 +110,6 @@ namespace ErgometerApplication
ComPort.Write("ST");
string response = ComPort.Read();
Console.WriteLine(response);
SaveMeting(response);
}
@@ -136,6 +140,8 @@ namespace ErgometerApplication
NetHelper.SendNetCommand(Doctor, new NetCommand(NetCommand.CommandType.LOGOUT, Session));
Loggedin = false;
running = false;
Doctor.Close();
Doctor = null;
}
}
@@ -183,6 +189,9 @@ namespace ErgometerApplication
case NetCommand.CommandType.SESSION:
Session = command.Session;
break;
case NetCommand.CommandType.ERROR:
Console.WriteLine("An error occured, ignoring");
break;
default:
throw new FormatException("Error in Netcommand: Received command not recognized");
}
@@ -5,10 +5,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace ErgometerApplication
{
public class PanelGraphView:Panel
public class PanelGraphView : Panel
{
private List<ChartPanel> charts;
@@ -16,7 +17,7 @@ namespace ErgometerApplication
public PanelGraphView() : base()
{
createCharts();
createCharts();
flowlayout = new FlowLayoutPanel();
@@ -26,22 +27,13 @@ namespace ErgometerApplication
flowlayout.Name = "flowlayout";
flowlayout.Padding = new Padding(15);
flowlayout.AutoScroll = true;
foreach(ChartPanel chart in charts)
foreach (ChartPanel chart in charts)
{
flowlayout.Controls.Add(chart);
}
List<Meting> metingen = new List<Meting>();
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(0, 0, 0, 0, 0, 0, 0, 0, 0));
updateAllCharts(metingen);
//
@@ -59,19 +51,18 @@ namespace ErgometerApplication
public void createCharts()
{
charts = new List<ChartPanel>();
charts.Add(new ChartPanel(ChartPanel.MetingType.HEARTBEAT));
charts.Add(new ChartPanel(ChartPanel.MetingType.RPM));
charts.Add(new ChartPanel(ChartPanel.MetingType.SPEED));
charts.Add(new ChartPanel(ChartPanel.MetingType.DISTANCE));
charts.Add(new ChartPanel(ChartPanel.MetingType.ENERGY));
charts.Add(new ChartPanel(ChartPanel.MetingType.SECONDS));
charts.Add(new ChartPanel(ChartPanel.MetingType.POWER));
charts.Add(new ChartPanel(ChartPanel.MetingType.ACTUALPOWER));
charts.Add(new ChartPanel(ChartPanel.MetingType.HEARTBEAT, SeriesChartType.Line));
charts.Add(new ChartPanel(ChartPanel.MetingType.RPM, SeriesChartType.Line));
charts.Add(new ChartPanel(ChartPanel.MetingType.SPEED, SeriesChartType.Line));
charts.Add(new ChartPanel(ChartPanel.MetingType.DISTANCE, SeriesChartType.Line));
charts.Add(new ChartPanel(ChartPanel.MetingType.ENERGY, SeriesChartType.Line));
charts.Add(new ChartPanel(ChartPanel.MetingType.POWER, SeriesChartType.Line));
charts.Add(new ChartPanel(ChartPanel.MetingType.ACTUALPOWER, SeriesChartType.Line));
}
public void updateAllCharts(List<Meting> metingen)
{
foreach(ChartPanel chart in charts)
foreach (ChartPanel chart in charts)
{
chart.updateChart(metingen);
}