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 // 15/10/2019 dimercur
// Demande #43: Migrer le code lié à la gestion des images dans sa propre classe widget // 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 System;
using Gtk; using Gtk;
using Gdk; using Gdk;
@ -68,11 +73,6 @@ public partial class MainWindow : Gtk.Window
/// </summary> /// </summary>
private ImageWidget imageWidget; private ImageWidget imageWidget;
/// <summary>
/// Timer for battery request
/// </summary>
private System.Timers.Timer batteryTimer;
/// <summary> /// <summary>
/// Counter for image reception and detecting bad picture ratio /// Counter for image reception and detecting bad picture ratio
/// </summary> /// </summary>
@ -91,10 +91,6 @@ public partial class MainWindow : Gtk.Window
// Init of image widget // Init of image widget
imageWidget = new ImageWidget(drawingAreaCamera); imageWidget = new ImageWidget(drawingAreaCamera);
// create new timer for battery request, every 10s
batteryTimer = new System.Timers.Timer(10000.0);
batteryTimer.Elapsed += OnBatteryTimerElapsed;
// Customize controls // Customize controls
AdjustControls(); AdjustControls();
} }
@ -145,7 +141,6 @@ public partial class MainWindow : Gtk.Window
if (cmdManager != null) cmdManager.Close(); if (cmdManager != null) cmdManager.Close();
batteryTimer.Stop();
break; break;
case SystemState.ServerConnected: case SystemState.ServerConnected:
buttonServerConnection.Label = "Disconnect"; buttonServerConnection.Label = "Disconnect";
@ -159,14 +154,12 @@ public partial class MainWindow : Gtk.Window
labelRobotControl.Sensitive = false; labelRobotControl.Sensitive = false;
gtkAlignmentRobotControl.Sensitive = false; gtkAlignmentRobotControl.Sensitive = false;
batteryTimer.Stop();
break; break;
case SystemState.RobotConnected: case SystemState.RobotConnected:
buttonRobotActivation.Label = "Reset"; buttonRobotActivation.Label = "Reset";
labelRobotControl.Sensitive = true; labelRobotControl.Sensitive = true;
gtkAlignmentRobotControl.Sensitive = true; gtkAlignmentRobotControl.Sensitive = true;
batteryTimer.Start();
break; break;
default: default:
labelRobot.Sensitive = false; labelRobot.Sensitive = false;
@ -259,8 +252,20 @@ public partial class MainWindow : Gtk.Window
// Depending on message received (based on header), launch correponding action // Depending on message received (based on header), launch correponding action
header = header.ToUpper(); header = header.ToUpper();
if (header == DestijlCommandList.ROBOT_BATTERY_LEVEL) switch (header)
{ {
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 !");
});
ChangeState(SystemState.ServerConnected);
break;
case DestijlCommandList.ROBOT_BATTERY_LEVEL:
string batLevel = ""; string batLevel = "";
switch (data[0]) switch (data[0])
@ -283,9 +288,9 @@ public partial class MainWindow : Gtk.Window
{ {
labelBatteryLevel.Text = batLevel; labelBatteryLevel.Text = batLevel;
}); });
}
else if (header == DestijlCommandList.CAMERA_IMAGE) break;
{ case DestijlCommandList.CAMERA_IMAGE:
imageReceivedCounter++; imageReceivedCounter++;
byte[] image = new byte[2]; byte[] image = new byte[2];
@ -312,11 +317,16 @@ public partial class MainWindow : Gtk.Window
" (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)"); " (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
#endif #endif
} }
//}
} break;
else if (header == DestijlCommandList.CAMERA_POSITION) case DestijlCommandList.CAMERA_POSITION:
{
imageWidget.Position = DestijlCommandManager.DecodePosition(data); 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> /// <summary>
/// Callback called when checkbutton for camera is clicked /// Callback called when checkbutton for camera is clicked
/// </summary> /// </summary>

View file

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

View file

@ -809,20 +809,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="Gtk.CheckButton" id="checkButtonGetBattery"> <placeholder />
<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>
</child> </child>
</widget> </widget>
</child> </child>

Binary file not shown.