Correction sur le moniteur pour prendre an charge les messages de timeout et d'erreur de communication + suppression du timer et bouton getbattery

This commit is contained in:
Sébastien DI MERCURIO 2019-04-11 13:00:24 +02:00
parent 25790e81bc
commit cd9534f04d
4 changed files with 155 additions and 218 deletions

View file

@ -25,6 +25,11 @@
// 15/10/2019 dimercur
// Demande #43: Migrer le code lié à la gestion des images dans sa propre classe widget
// 11/04/2019 dimercur
// Suppression du timer battery
// suppression de la case à cocher getbattery
// Prise en charge des messages ANSWER_TIMEOUT et ANSWER_COM_ERROR dans OnCommandReceivedEvent
using System;
using Gtk;
using Gdk;
@ -68,11 +73,6 @@ public partial class MainWindow : Gtk.Window
/// </summary>
private ImageWidget imageWidget;
/// <summary>
/// Timer for battery request
/// </summary>
private System.Timers.Timer batteryTimer;
/// <summary>
/// Counter for image reception and detecting bad picture ratio
/// </summary>
@ -91,10 +91,6 @@ public partial class MainWindow : Gtk.Window
// Init of image widget
imageWidget = new ImageWidget(drawingAreaCamera);
// create new timer for battery request, every 10s
batteryTimer = new System.Timers.Timer(10000.0);
batteryTimer.Elapsed += OnBatteryTimerElapsed;
// Customize controls
AdjustControls();
}
@ -145,7 +141,6 @@ public partial class MainWindow : Gtk.Window
if (cmdManager != null) cmdManager.Close();
batteryTimer.Stop();
break;
case SystemState.ServerConnected:
buttonServerConnection.Label = "Disconnect";
@ -159,14 +154,12 @@ public partial class MainWindow : Gtk.Window
labelRobotControl.Sensitive = false;
gtkAlignmentRobotControl.Sensitive = false;
batteryTimer.Stop();
break;
case SystemState.RobotConnected:
buttonRobotActivation.Label = "Reset";
labelRobotControl.Sensitive = true;
gtkAlignmentRobotControl.Sensitive = true;
batteryTimer.Start();
break;
default:
labelRobot.Sensitive = false;
@ -259,64 +252,81 @@ public partial class MainWindow : Gtk.Window
// Depending on message received (based on header), launch correponding action
header = header.ToUpper();
if (header == DestijlCommandList.ROBOT_BATTERY_LEVEL)
switch (header)
{
string batLevel = "";
case DestijlCommandList.ANSWER_TIMEOUT:
case DestijlCommandList.ANSWER_COM_ERROR:
Console.WriteLine("Communication lost with robot");
Gtk.Application.Invoke(delegate
{
MessagePopup(MessageType.Error, ButtonsType.Ok, "Robot lost", "Communication with robot lost !");
});
switch (data[0])
{
case '2':
batLevel = "High";
break;
case '1':
batLevel = "Low";
break;
case '0':
batLevel = "Empty";
break;
default:
batLevel = "Invalid value";
break;
}
ChangeState(SystemState.ServerConnected);
Gtk.Application.Invoke(delegate
{
labelBatteryLevel.Text = batLevel;
});
}
else if (header == DestijlCommandList.CAMERA_IMAGE)
{
imageReceivedCounter++;
break;
case DestijlCommandList.ROBOT_BATTERY_LEVEL:
string batLevel = "";
byte[] image = new byte[2];
try
{
image = Convert.FromBase64String(data);
}
catch (FormatException)
{
badImageReceivedCounter++;
Console.WriteLine("Unable to convert from base64 ");
}
switch (data[0])
{
case '2':
batLevel = "High";
break;
case '1':
batLevel = "Low";
break;
case '0':
batLevel = "Empty";
break;
default:
batLevel = "Invalid value";
break;
}
try
{
imageWidget.ShowImage(image);
}
catch (GLib.GException)
{
badImageReceivedCounter++;
Gtk.Application.Invoke(delegate
{
labelBatteryLevel.Text = batLevel;
});
break;
case DestijlCommandList.CAMERA_IMAGE:
imageReceivedCounter++;
byte[] image = new byte[2];
try
{
image = Convert.FromBase64String(data);
}
catch (FormatException)
{
badImageReceivedCounter++;
Console.WriteLine("Unable to convert from base64 ");
}
try
{
imageWidget.ShowImage(image);
}
catch (GLib.GException)
{
badImageReceivedCounter++;
#if DEBUG
Console.WriteLine("Bad Image: " + badImageReceivedCounter +
" / " + imageReceivedCounter +
" (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
Console.WriteLine("Bad Image: " + badImageReceivedCounter +
" / " + imageReceivedCounter +
" (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
#endif
}
//}
}
else if (header == DestijlCommandList.CAMERA_POSITION)
{
imageWidget.Position = DestijlCommandManager.DecodePosition(data);
}
break;
case DestijlCommandList.CAMERA_POSITION:
imageWidget.Position = DestijlCommandManager.DecodePosition(data);
break;
default:
Console.WriteLine("Untreated message from supervisor: " + header + ": " + data);
break;
}
}
}
@ -526,50 +536,6 @@ public partial class MainWindow : Gtk.Window
}
}
/// <summary>
/// Callback called when battery timer expired
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event</param>
void OnBatteryTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
DestijlCommandManager.CommandStatus status;
batteryTimer.Stop();
// if battery checkbox is checked, a request for battery level is done
if (checkButtonGetBattery.Active)
{
status = cmdManager.RobotGetBattery();
// if status is not ok, show appropriate message and print "Unknown" for battery level
switch (status)
{
case DestijlCommandManager.CommandStatus.Success:
batteryTimer.Start();
break;
case DestijlCommandManager.CommandStatus.CommunicationLostWithServer:
Console.WriteLine("Error: Connection lost with server");
batteryTimer.Stop();
labelBatteryLevel.Text = "Unknown";
ChangeState(SystemState.NotConnected);
break;
case DestijlCommandManager.CommandStatus.CommunicationLostWithRobot:
Console.WriteLine("Error: Connection lost with robot");
batteryTimer.Stop();
labelBatteryLevel.Text = "Unknown";
ChangeState(SystemState.ServerConnected);
break;
default:
labelBatteryLevel.Text = "Unknown";
batteryTimer.Start();
break;
}
}
else batteryTimer.Start();
}
/// <summary>
/// Callback called when checkbutton for camera is clicked
/// </summary>

View file

@ -125,8 +125,6 @@ public partial class MainWindow
private global::Gtk.Label labelBatteryLevel;
private global::Gtk.CheckButton checkButtonGetBattery;
protected virtual void Build()
{
global::Stetic.Gui.Initialize(this);
@ -530,92 +528,91 @@ public partial class MainWindow
this.table4.ColumnSpacing = ((uint)(6));
// Container child table4.Gtk.Table+TableChild
this.buttonDown = new global::Gtk.Button();
global::Gtk.Tooltips w40 = new Gtk.Tooltips();
w40.SetTip(this.buttonDown, "Move robot backward", "Move robot backward");
this.buttonDown.TooltipMarkup = "Move robot backward";
this.buttonDown.CanFocus = true;
this.buttonDown.Name = "buttonDown";
this.buttonDown.UseUnderline = true;
global::Gtk.Image w41 = new global::Gtk.Image();
w41.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-down-symbolic.symbolic.png");
this.buttonDown.Image = w41;
global::Gtk.Image w40 = new global::Gtk.Image();
w40.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-down-symbolic.symbolic.png");
this.buttonDown.Image = w40;
this.table4.Add(this.buttonDown);
global::Gtk.Table.TableChild w42 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonDown]));
w42.TopAttach = ((uint)(2));
w42.BottomAttach = ((uint)(3));
w42.LeftAttach = ((uint)(1));
w42.RightAttach = ((uint)(2));
w42.XOptions = ((global::Gtk.AttachOptions)(4));
w42.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w41 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonDown]));
w41.TopAttach = ((uint)(2));
w41.BottomAttach = ((uint)(3));
w41.LeftAttach = ((uint)(1));
w41.RightAttach = ((uint)(2));
w41.XOptions = ((global::Gtk.AttachOptions)(4));
w41.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table4.Gtk.Table+TableChild
this.buttonForward = new global::Gtk.Button();
w40.SetTip(this.buttonForward, "Move robot forward", "Move robot forward");
this.buttonForward.TooltipMarkup = "Move robot forward";
this.buttonForward.CanFocus = true;
this.buttonForward.Name = "buttonForward";
this.buttonForward.UseUnderline = true;
global::Gtk.Image w43 = new global::Gtk.Image();
w43.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-up-symbolic.symbolic.png");
this.buttonForward.Image = w43;
global::Gtk.Image w42 = new global::Gtk.Image();
w42.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-up-symbolic.symbolic.png");
this.buttonForward.Image = w42;
this.table4.Add(this.buttonForward);
global::Gtk.Table.TableChild w44 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonForward]));
w44.LeftAttach = ((uint)(1));
w44.RightAttach = ((uint)(2));
w44.XOptions = ((global::Gtk.AttachOptions)(4));
w44.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w43 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonForward]));
w43.LeftAttach = ((uint)(1));
w43.RightAttach = ((uint)(2));
w43.XOptions = ((global::Gtk.AttachOptions)(4));
w43.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table4.Gtk.Table+TableChild
this.buttonLeft = new global::Gtk.Button();
w40.SetTip(this.buttonLeft, "Turn robot to the left", "Turn robot to the left");
this.buttonLeft.TooltipMarkup = "Turn robot to the left";
this.buttonLeft.CanFocus = true;
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.UseUnderline = true;
global::Gtk.Image w45 = new global::Gtk.Image();
w45.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-start-symbolic.symbolic.png");
this.buttonLeft.Image = w45;
global::Gtk.Image w44 = new global::Gtk.Image();
w44.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-start-symbolic.symbolic.png");
this.buttonLeft.Image = w44;
this.table4.Add(this.buttonLeft);
global::Gtk.Table.TableChild w46 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonLeft]));
w46.TopAttach = ((uint)(1));
w46.BottomAttach = ((uint)(2));
w46.XOptions = ((global::Gtk.AttachOptions)(4));
w46.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w45 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonLeft]));
w45.TopAttach = ((uint)(1));
w45.BottomAttach = ((uint)(2));
w45.XOptions = ((global::Gtk.AttachOptions)(4));
w45.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table4.Gtk.Table+TableChild
this.buttonRight = new global::Gtk.Button();
w40.SetTip(this.buttonRight, "Turn robot to the right", "Turn robot to the right");
this.buttonRight.TooltipMarkup = "Turn robot to the right";
this.buttonRight.CanFocus = true;
this.buttonRight.Name = "buttonRight";
this.buttonRight.UseUnderline = true;
global::Gtk.Image w47 = new global::Gtk.Image();
w47.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-end-symbolic.symbolic.png");
this.buttonRight.Image = w47;
global::Gtk.Image w46 = new global::Gtk.Image();
w46.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.pan-end-symbolic.symbolic.png");
this.buttonRight.Image = w46;
this.table4.Add(this.buttonRight);
global::Gtk.Table.TableChild w48 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonRight]));
w48.TopAttach = ((uint)(1));
w48.BottomAttach = ((uint)(2));
w48.LeftAttach = ((uint)(2));
w48.RightAttach = ((uint)(3));
w48.XOptions = ((global::Gtk.AttachOptions)(4));
w48.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w47 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonRight]));
w47.TopAttach = ((uint)(1));
w47.BottomAttach = ((uint)(2));
w47.LeftAttach = ((uint)(2));
w47.RightAttach = ((uint)(3));
w47.XOptions = ((global::Gtk.AttachOptions)(4));
w47.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table4.Gtk.Table+TableChild
this.buttonStop = new global::Gtk.Button();
w40.SetTip(this.buttonStop, "Stop robot movements", "Stop robot movements");
this.buttonStop.TooltipMarkup = "Stop robot movements";
this.buttonStop.CanFocus = true;
this.buttonStop.Name = "buttonStop";
this.buttonStop.UseUnderline = true;
global::Gtk.Image w49 = new global::Gtk.Image();
w49.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.hand-filled-32.png");
this.buttonStop.Image = w49;
global::Gtk.Image w48 = new global::Gtk.Image();
w48.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.hand-filled-32.png");
this.buttonStop.Image = w48;
this.table4.Add(this.buttonStop);
global::Gtk.Table.TableChild w50 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonStop]));
w50.TopAttach = ((uint)(1));
w50.BottomAttach = ((uint)(2));
w50.LeftAttach = ((uint)(1));
w50.RightAttach = ((uint)(2));
w50.XOptions = ((global::Gtk.AttachOptions)(4));
w50.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w49 = ((global::Gtk.Table.TableChild)(this.table4[this.buttonStop]));
w49.TopAttach = ((uint)(1));
w49.BottomAttach = ((uint)(2));
w49.LeftAttach = ((uint)(1));
w49.RightAttach = ((uint)(2));
w49.XOptions = ((global::Gtk.AttachOptions)(4));
w49.YOptions = ((global::Gtk.AttachOptions)(4));
this.alignment8.Add(this.table4);
this.vbox9.Add(this.alignment8);
global::Gtk.Box.BoxChild w52 = ((global::Gtk.Box.BoxChild)(this.vbox9[this.alignment8]));
w52.Position = 0;
w52.Expand = false;
w52.Fill = false;
global::Gtk.Box.BoxChild w51 = ((global::Gtk.Box.BoxChild)(this.vbox9[this.alignment8]));
w51.Position = 0;
w51.Expand = false;
w51.Fill = false;
// Container child vbox9.Gtk.Box+BoxChild
this.table3 = new global::Gtk.Table(((uint)(1)), ((uint)(2)), false);
this.table3.Name = "table3";
@ -628,10 +625,10 @@ public partial class MainWindow
this.label3.LabelProp = global::Mono.Unix.Catalog.GetString("Battery level:");
this.label3.Justify = ((global::Gtk.Justification)(1));
this.table3.Add(this.label3);
global::Gtk.Table.TableChild w53 = ((global::Gtk.Table.TableChild)(this.table3[this.label3]));
w53.YPadding = ((uint)(10));
w53.XOptions = ((global::Gtk.AttachOptions)(4));
w53.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w52 = ((global::Gtk.Table.TableChild)(this.table3[this.label3]));
w52.YPadding = ((uint)(10));
w52.XOptions = ((global::Gtk.AttachOptions)(4));
w52.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table3.Gtk.Table+TableChild
this.labelBatteryLevel = new global::Gtk.Label();
this.labelBatteryLevel.Name = "labelBatteryLevel";
@ -639,49 +636,36 @@ public partial class MainWindow
this.labelBatteryLevel.Xalign = 0F;
this.labelBatteryLevel.LabelProp = global::Mono.Unix.Catalog.GetString("Unknown");
this.table3.Add(this.labelBatteryLevel);
global::Gtk.Table.TableChild w54 = ((global::Gtk.Table.TableChild)(this.table3[this.labelBatteryLevel]));
w54.LeftAttach = ((uint)(1));
w54.RightAttach = ((uint)(2));
w54.YOptions = ((global::Gtk.AttachOptions)(4));
global::Gtk.Table.TableChild w53 = ((global::Gtk.Table.TableChild)(this.table3[this.labelBatteryLevel]));
w53.LeftAttach = ((uint)(1));
w53.RightAttach = ((uint)(2));
w53.YOptions = ((global::Gtk.AttachOptions)(4));
this.vbox9.Add(this.table3);
global::Gtk.Box.BoxChild w55 = ((global::Gtk.Box.BoxChild)(this.vbox9[this.table3]));
w55.Position = 2;
w55.Expand = false;
w55.Fill = false;
// Container child vbox9.Gtk.Box+BoxChild
this.checkButtonGetBattery = new global::Gtk.CheckButton();
this.checkButtonGetBattery.CanFocus = true;
this.checkButtonGetBattery.Name = "checkButtonGetBattery";
this.checkButtonGetBattery.Label = global::Mono.Unix.Catalog.GetString("Get battery level");
this.checkButtonGetBattery.Active = true;
this.checkButtonGetBattery.DrawIndicator = true;
this.checkButtonGetBattery.UseUnderline = true;
this.vbox9.Add(this.checkButtonGetBattery);
global::Gtk.Box.BoxChild w56 = ((global::Gtk.Box.BoxChild)(this.vbox9[this.checkButtonGetBattery]));
w56.Position = 3;
w56.Expand = false;
w56.Fill = false;
global::Gtk.Box.BoxChild w54 = ((global::Gtk.Box.BoxChild)(this.vbox9[this.table3]));
w54.Position = 2;
w54.Expand = false;
w54.Fill = false;
this.gtkAlignmentRobotControl.Add(this.vbox9);
this.vbox12.Add(this.gtkAlignmentRobotControl);
global::Gtk.Box.BoxChild w58 = ((global::Gtk.Box.BoxChild)(this.vbox12[this.gtkAlignmentRobotControl]));
w58.Position = 1;
global::Gtk.Box.BoxChild w56 = ((global::Gtk.Box.BoxChild)(this.vbox12[this.gtkAlignmentRobotControl]));
w56.Position = 1;
this.vbox5.Add(this.vbox12);
global::Gtk.Box.BoxChild w59 = ((global::Gtk.Box.BoxChild)(this.vbox5[this.vbox12]));
w59.Position = 4;
global::Gtk.Box.BoxChild w57 = ((global::Gtk.Box.BoxChild)(this.vbox5[this.vbox12]));
w57.Position = 4;
this.alignment3.Add(this.vbox5);
this.hbox3.Add(this.alignment3);
global::Gtk.Box.BoxChild w61 = ((global::Gtk.Box.BoxChild)(this.hbox3[this.alignment3]));
w61.Position = 1;
w61.Expand = false;
w61.Fill = false;
global::Gtk.Box.BoxChild w59 = ((global::Gtk.Box.BoxChild)(this.hbox3[this.alignment3]));
w59.Position = 1;
w59.Expand = false;
w59.Fill = false;
this.hbox1.Add(this.hbox3);
global::Gtk.Box.BoxChild w62 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.hbox3]));
w62.Position = 1;
w62.Expand = false;
w62.Fill = false;
global::Gtk.Box.BoxChild w60 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.hbox3]));
w60.Position = 1;
w60.Expand = false;
w60.Fill = false;
this.vbox1.Add(this.hbox1);
global::Gtk.Box.BoxChild w63 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hbox1]));
w63.Position = 1;
global::Gtk.Box.BoxChild w61 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hbox1]));
w61.Position = 1;
this.Add(this.vbox1);
if ((this.Child != null))
{

View file

@ -809,20 +809,7 @@
</packing>
</child>
<child>
<widget class="Gtk.CheckButton" id="checkButtonGetBattery">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Label" translatable="yes">Get battery level</property>
<property name="DrawIndicator">True</property>
<property name="HasLabel">True</property>
<property name="UseUnderline">True</property>
</widget>
<packing>
<property name="Position">3</property>
<property name="AutoSize">True</property>
<property name="Expand">False</property>
<property name="Fill">False</property>
</packing>
<placeholder />
</child>
</widget>
</child>

Binary file not shown.