sauvegarde

This commit is contained in:
Sébastien DI MERCURIO 2018-11-07 11:32:19 +01:00
parent 8536d288ce
commit a1cd0af6ef
38 changed files with 3967 additions and 128 deletions

4
.gitignore vendored
View file

@ -62,4 +62,6 @@ GUI
# Android
*.apk
/software/raspberry/superviseur-robot/superviseur/dist/
/software/raspberry/superviseur-robot/superviseur/dist/
/software/raspberry/testeur/testeur/build/
/software/raspberry/testeur/testeur/dist/

View file

@ -0,0 +1,156 @@
using System;
using System.Net.Sockets;
using System.Threading;
using System.Text;
namespace monitor
{
public class ClientReadEvent
{
private static TcpClient myClient = null;
private static NetworkStream myStream = null;
private const int BufferMaxSize = 512;
private static byte[] buffer = new byte[BufferMaxSize];
private static StringBuilder sb = new StringBuilder();
private static int newLength = 1;
public delegate void ReadEvent(string str);
public static ReadEvent readEvent = null;
public static void Set(TcpClient client, NetworkStream stream)
{
myClient = client;
myStream = stream;
}
public static void ReadThread()
{
while (true)
{
if (myClient.Connected)
{
myStream.BeginRead(buffer, 0, newLength, new AsyncCallback(ReadCallback), sb);
}
else Thread.Sleep(200);
}
}
public static void ReadCallback(IAsyncResult ar)
{
}
}
public class Client
{
public const string defaultIP = "localhost";
public const int defaultPort = 4500;
private static TcpClient client = null;
private static NetworkStream stream = null;
private const int BufferMaxSize = 512;
private static byte[] buffer = new byte[BufferMaxSize];
private static StringBuilder message = new StringBuilder();
private static int newLength = 1;
public delegate void ReadEvent(string msg);
public static ReadEvent readEvent = null;
public Client()
{
}
public static bool Open(string host)
{
return Client.Open(host, defaultPort);
}
public static bool Open(string host, int port)
{
bool status = true;
try
{
client = new TcpClient(host, port);
stream = client.GetStream();
stream.BeginRead(buffer, 0, newLength, new AsyncCallback(ReadCallback), message);
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: " + e);
status = false;
}
catch (SocketException e)
{
Console.WriteLine("SocketException: " + e.ToString());
status = false;
}
catch (Exception e)
{
Console.WriteLine("Unknown Exception: " + e.ToString());
status = false;
}
return status;
}
public static void Close()
{
if (stream!=null) stream.Close();
if (client!=null) client.Close();
}
private static void ReadCallback(IAsyncResult ar)
{
if (client.Connected)
{
int bytesRead;
try
{
bytesRead = stream.EndRead(ar);
}
catch (ObjectDisposedException e)
{
Console.WriteLine("Connection to server dropped: " + e.ToString());
return;
}
newLength = 1;
if (bytesRead > 0)
{
message.Append(Encoding.ASCII.GetString(buffer, 0, bytesRead));
}
if (client.Available > 0)
{
newLength = client.Available;
if (newLength > BufferMaxSize) newLength = BufferMaxSize;
else newLength = client.Available;
}
else
{
readEvent?.Invoke(message.ToString());
message.Clear();
}
stream.BeginRead(buffer, 0, newLength, new AsyncCallback(ReadCallback), message);
}
}
public static void Write(string mes)
{
if (client.Connected)
{
byte[] writeBuffer = Encoding.UTF8.GetBytes(mes);
stream.Write(writeBuffer, 0, mes.Length);
}
}
}
}

View file

@ -0,0 +1,110 @@
using System.Threading;
namespace monitor
{
public class CommandManager
{
public delegate void CommandReceivedEvent(string msg);
public CommandReceivedEvent commandReceivedEvent = null;
private System.Timers.Timer waitTimer = new System.Timers.Timer();
private ManualResetEvent waitEvent = new ManualResetEvent(false);
private bool waitForAcknowledge = false;
private string messageReceived = null;
private bool isBusy = false;
public enum CommandManagerStatus
{
AnswerReceived,
Timeout,
Busy
};
public CommandManager(CommandReceivedEvent callback)
{
Client.readEvent += this.OnMessageReception;
this.commandReceivedEvent += callback;
waitTimer.Elapsed += OnMessageTimeout;
}
~CommandManager()
{
Client.Close();
}
public bool Open(string hostname)
{
return this.Open(hostname, Client.defaultPort);
}
public bool Open(string hostname, int port)
{
return Client.Open(hostname, port);
}
public void Close()
{
Client.Close();
}
private void OnMessageReception(string message)
{
waitTimer.Stop();
this.messageReceived = message;
isBusy = false;
if (waitForAcknowledge) {
waitForAcknowledge = false;
waitEvent.Set(); // Envoi de l'evenement
}
else {
waitForAcknowledge = false;
this.commandReceivedEvent?.Invoke(message);
}
}
private void OnMessageTimeout(object sender, System.Timers.ElapsedEventArgs e)
{
messageReceived = null;
OnMessageReception(messageReceived);
}
public CommandManagerStatus SendCommand(string cmd, out string answer, double timeout)
{
CommandManagerStatus status = CommandManagerStatus.AnswerReceived;
answer = null;
if (isBusy) status = CommandManagerStatus.Busy;
else
{
isBusy = true;
Client.Write(cmd);
if (timeout > 0) // la commande attend un acquitement
{
waitForAcknowledge = true;
waitTimer.Interval = timeout;
waitTimer.Start();
waitEvent.WaitOne();
waitEvent.Reset(); // remise à zero pour une prochaine commande
if (this.messageReceived == null) // timeout: connection au serveur defectueuse
{
status = CommandManagerStatus.Timeout;
}
}
else isBusy = false;
answer = this.messageReceived;
this.messageReceived = null;
}
return status;
}
}
}

View file

@ -0,0 +1,420 @@
using System;
namespace monitor
{
public class DestijlCommandList
{
public const string HeaderMtsComDmb = "COM";
public const string HeaderMtsDmbOrder = "DMB";
public const string HeaderMtsCamera = "CAM";
public const string HeaderMtsMessage = "MSG";
public const string DataComOpen = "o";
public const string DataComClose = "C";
public const string DataCamOpen = "A";
public const string DataCamClose = "I";
public const string DataCamAskArena = "y";
public const string DataCamArenaConfirm = "x";
public const string DataCamInfirm = "z";
public const string DataCamComputePosition = "p";
public const string DataCamStopComputePosition = "s";
public const string HeaderStmAck = "ACK";
public const string HeaderStmNoAck = "NAK";
public const string HeaderStmLostDmb = "LCD";
public const string HeaderStmImage = "IMG";
public const string HeaderStmPos = "POS";
public const string HeaderStmMes = "MSG";
public const string HeaderStmBat = "BAT";
}
public class RobotCommandList
{
public const string RobotPing = "p";
public const string RobotReset = "r";
public const string RobotStartWithoutWatchdog = "u";
public const string RobotStartWithWatchdog = "W";
public const string RobotGetBattery = "v";
public const string RobotGetBusyState = "b";
public const string RobotMove = "M";
public const string RobotTurn = "T";
public const string RobotGetVersion = "V";
public const string RobotPowerOff = "z";
}
public class DestijlCommandManager
{
private CommandManager commandManager = null;
private string receivedHeader = null;
private string receivedData = null;
public delegate void CommandReceivedEvent(string header, string data);
public CommandReceivedEvent commandReceivedEvent = null;
public double timeout = 100; // timeout pour les commandes avec acquitement
public enum CommandStatus
{
Success,
Rejected,
InvalidAnswer,
Busy,
CommunicationLostWithRobot,
CommunicationLostWithServer
}
public DestijlCommandManager(CommandReceivedEvent callback)
{
commandManager = new CommandManager(OnCommandReceived);
this.commandReceivedEvent += callback;
}
~DestijlCommandManager()
{
if (commandManager != null) commandManager.Close();
}
private void OnCommandReceived(string msg)
{
string[] msgs = msg.Split(':');
if (msgs.Length >= 1) receivedHeader = msgs[0];
else receivedHeader = null;
if (msgs.Length >= 2) receivedData = msgs[1];
else receivedData = null;
this.commandReceivedEvent?.Invoke(receivedHeader, receivedData);
}
public bool Open(string hostname)
{
return this.Open(hostname, Client.defaultPort);
}
public bool Open(string hostname, int port)
{
if (commandManager != null) return commandManager.Open(hostname, port);
else return false;
}
public void Close()
{
if (commandManager != null) commandManager.Close();
}
private string CreateCommand(string header, string data)
{
return header + ":" + data;
}
private void SplitCommand(string cmd, out string header, out string data)
{
string[] cmdParts = cmd.Split(':');
if (cmdParts.Length > 0) header = cmdParts[0];
else header = null;
if (cmdParts.Length > 1) data = cmdParts[1];
else data = null;
}
private CommandStatus DecodeStatus(CommandManager.CommandManagerStatus localStatus, string answer)
{
CommandStatus status = CommandStatus.Success;
if (localStatus == CommandManager.CommandManagerStatus.Timeout) status = CommandStatus.CommunicationLostWithServer;
else if (localStatus == CommandManager.CommandManagerStatus.Busy) status = CommandStatus.Busy;
else
{
if (answer != null)
{
if (answer.ToUpper().Contains(DestijlCommandList.HeaderStmNoAck)) status = CommandStatus.Rejected;
else if (answer.ToUpper().Contains(DestijlCommandList.HeaderStmLostDmb)) status = CommandStatus.CommunicationLostWithRobot;
else if (answer.ToUpper().Contains(DestijlCommandList.HeaderStmAck)) status = CommandStatus.Success;
else if (answer.Length == 0) status = CommandStatus.CommunicationLostWithServer;
else status = CommandStatus.InvalidAnswer;
}
}
return status;
}
public CommandStatus RobotOpenCom()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsComDmb, DestijlCommandList.DataComOpen),
out answer,
this.timeout);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotCloseCom()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsComDmb, DestijlCommandList.DataComClose),
out answer,
this.timeout);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotPing()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotPing),
out answer,
this.timeout);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotReset()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotReset),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotStartWithWatchdog()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotStartWithWatchdog),
out answer,
this.timeout);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotStartWithoutWatchdog()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotStartWithoutWatchdog),
out answer,
this.timeout);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotMove(int distance)
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotMove + "=" + distance),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotTurn(int angle)
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotTurn + "=" + angle),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
//public CommandStatus RobotGetBattery(out int battery)
public CommandStatus RobotGetBattery()
{
CommandManager.CommandManagerStatus localStatus;
//CommandStatus status = CommandStatus.Success;
//battery = -1;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotGetBattery),
out answer,
0);
//if (localStatus == CommandManager.CommandManagerStatus.AnswerReceived) {
// string[] msg = answer.Split(':');
// if (msg.Length > 1)
// {
// try
// {
// battery = Convert.ToInt32(msg[1]);
// }
// catch (Exception) { }
// }
//}
//else if (localStatus == CommandManager.CommandManagerStatus.Timeout)
//{
// status = CommandStatus.CommunicationLostWithServer;
//}
//return status;
return DecodeStatus(localStatus, answer);
}
public CommandStatus RobotGetVersion(out string version)
{
CommandManager.CommandManagerStatus localStatus;
CommandStatus status = CommandStatus.Success;
version = "";
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotGetVersion),
out answer,
this.timeout);
if (localStatus == CommandManager.CommandManagerStatus.AnswerReceived)
{
string[] msg = answer.Split(':');
if (msg.Length > 1)
{
version = msg[1];
}
}
else if (localStatus == CommandManager.CommandManagerStatus.Timeout)
{
status = CommandStatus.CommunicationLostWithServer;
}
return status;
}
public CommandStatus RobotPowerOff()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotPowerOff),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraOpen()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamOpen),
out answer,
this.timeout);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraClose()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamClose),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraAskArena()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamAskArena),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraArenaConfirm()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamArenaConfirm),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraArenaInfirm()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamInfirm),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraComputePosition()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamComputePosition),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
public CommandStatus CameraStopComputePosition()
{
CommandManager.CommandManagerStatus localStatus;
string answer;
localStatus = commandManager.SendCommand(
CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamStopComputePosition),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
}
}

View file

@ -1,16 +1,452 @@
using System;
using Gtk;
using Gdk;
using monitor;
public partial class MainWindow : Gtk.Window
{
private DestijlCommandManager cmdManager;
private Pixbuf drawingareaCameraPixbuf;
enum SystemState
{
NotConnected,
ServerConnected,
RobotConnected
};
private SystemState systemState = SystemState.NotConnected;
private System.Timers.Timer batteryTimer;
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
Build();
cmdManager = new DestijlCommandManager(OnCommandReceivedEvent);
batteryTimer = new System.Timers.Timer(10000.0);
batteryTimer.Elapsed += OnBatteryTimerElapsed;
AdjustControls();
}
public void AdjustControls()
{
ChangeState(SystemState.NotConnected);
drawingareaCameraPixbuf = new Pixbuf((string)null);
drawingareaCameraPixbuf = Pixbuf.LoadFromResource("monitor.ressources.missing_picture.png");
entryServerName.Text = Client.defaultIP;
entryServerPort.Text = Client.defaultPort.ToString();
entryTimeout.Text = "10000";
}
private void ChangeState(SystemState newState)
{
switch (newState)
{
case SystemState.NotConnected:
labelRobot.Sensitive = false;
gtkAlignmentRobot.Sensitive = false;
labelRobotControl.Sensitive = false;
gtkAlignmentRobotControl.Sensitive = false;
boxCamera.Sensitive = false;
buttonServerConnection.Label = "Connect";
buttonRobotActivation.Label = "Activate";
labelBatteryLevel.Text = "Unknown";
checkButtonCameraOn.Active = false;
checkButtonRobotPosition.Active = false;
if (cmdManager != null) cmdManager.Close();
batteryTimer.Stop();
break;
case SystemState.ServerConnected:
buttonServerConnection.Label = "Disconnect";
buttonRobotActivation.Label = "Activate";
labelBatteryLevel.Text = "Unknown";
labelRobot.Sensitive = true;
gtkAlignmentRobot.Sensitive = true;
boxCamera.Sensitive = true;
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;
gtkAlignmentRobot.Sensitive = false;
labelRobotControl.Sensitive = false;
gtkAlignmentRobotControl.Sensitive = false;
boxCamera.Sensitive = false;
buttonServerConnection.Label = "Connect";
buttonRobotActivation.Label = "Activate";
labelBatteryLevel.Text = "Unknown";
checkButtonCameraOn.Active = false;
checkButtonRobotPosition.Active = false;
systemState = SystemState.NotConnected;
return;
}
systemState = newState;
}
private void MessagePopup(MessageType type, ButtonsType buttons, string title, string message)
{
MessageDialog md = new MessageDialog(this, DialogFlags.DestroyWithParent, type, buttons, message)
{
Title = title
};
md.Run();
md.Destroy();
}
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
Console.WriteLine("Bye bye");
if (cmdManager != null) cmdManager.Close();
Application.Quit();
a.RetVal = true;
}
public void OnCommandReceivedEvent(string header, string data)
{
if (header != null) Console.WriteLine("Received header (" + header.Length + "): " + header);
if (data != null) Console.WriteLine("Received data (" + data.Length + "): " + data);
if (header.ToUpper() == DestijlCommandList.HeaderStmBat)
{
switch (data[0])
{
case '2':
labelBatteryLevel.Text = "High";
break;
case '1':
labelBatteryLevel.Text = "Low";
break;
case '0':
labelBatteryLevel.Text = "Empty";
break;
default:
labelBatteryLevel.Text = "Invalid value";
break;
}
}
}
protected void OnQuitActionActivated(object sender, EventArgs e)
{
Console.WriteLine("Bye bye 2");
if (cmdManager != null) cmdManager.Close();
this.Destroy();
Application.Quit();
}
protected void OnShowLogWindowActionActivated(object sender, EventArgs e)
{
MessagePopup(MessageType.Info,
ButtonsType.Ok, "Info",
"Logger not yet implemented");
}
protected void OnButtonServerConnectionClicked(object sender, EventArgs e)
{
DestijlCommandManager.CommandStatus statusCmd;
if (buttonServerConnection.Label == "Disconnect")
{
ChangeState(SystemState.NotConnected);
}
else
{
if ((entryServerName.Text == "") || (entryServerPort.Text == ""))
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Server name or port is invalid");
}
else
{
Console.WriteLine("Connecting to " + entryServerName.Text + ":" + entryServerPort.Text);
bool status = false;
try
{
cmdManager.timeout = Convert.ToDouble(entryTimeout.Text);
}
catch (Exception)
{
cmdManager.timeout = 100;
entryTimeout.Text = cmdManager.timeout.ToString();
}
try
{
status = cmdManager.Open(entryServerName.Text, Convert.ToInt32(entryServerPort.Text));
}
catch (Exception)
{
Console.WriteLine("Something went wrong during connection");
return;
}
if (status != true)
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Unable to connect to server " + entryServerName.Text + ":" + Convert.ToInt32(entryServerPort.Text));
}
else
{
Console.Write("Send command RobotOpenCom: ");
statusCmd = cmdManager.RobotOpenCom();
Console.WriteLine(statusCmd.ToString());
if (statusCmd == DestijlCommandManager.CommandStatus.Success)
{
ChangeState(SystemState.ServerConnected);
}
else
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Unable to open communication with robot.\nCheck that supervisor is accepting OPEN_COM_DMB command");
cmdManager.Close();
}
}
}
}
}
protected void OnButtonRobotActivationClicked(object sender, EventArgs e)
{
DestijlCommandManager.CommandStatus status;
if (buttonRobotActivation.Label == "Activate") // activation du robot
{
if (radioButtonWithWatchdog.Active) // Demarrage avec watchdog
{
status = cmdManager.RobotStartWithWatchdog();
}
else // Demarrage sans watchdog
{
status = cmdManager.RobotStartWithoutWatchdog();
}
if (status == DestijlCommandManager.CommandStatus.Success)
{
ChangeState(SystemState.RobotConnected);
}
else
{
if (status == DestijlCommandManager.CommandStatus.CommunicationLostWithServer)
{
MessagePopup(MessageType.Error, ButtonsType.Ok, "Error", "Connection lost with server");
ChangeState(SystemState.NotConnected);
}
else
{
MessagePopup(MessageType.Error, ButtonsType.Ok, "Error", "Command rejected\nCheck that supervisor accept \nDMB_START_WITH_WD and/or DMB_START_WITHOUT_WD");
}
}
}
else // Reset du robot
{
status = cmdManager.RobotReset();
if (status == DestijlCommandManager.CommandStatus.Success)
{
ChangeState(SystemState.ServerConnected);
}
else
{
if (status == DestijlCommandManager.CommandStatus.CommunicationLostWithServer)
{
MessagePopup(MessageType.Error, ButtonsType.Ok, "Error", "Connection lost with server");
ChangeState(SystemState.NotConnected);
}
else
{
MessagePopup(MessageType.Error, ButtonsType.Ok, "Error", "Unknown error");
}
}
}
}
protected void OnButtonMouvClicked(object sender, EventArgs e)
{
if (sender == buttonRight)
{
cmdManager.RobotTurn(90);
}
else if (sender == buttonLeft)
{
cmdManager.RobotTurn(-90);
}
else if (sender == buttonForward)
{
cmdManager.RobotMove(100);
}
else if (sender == buttonDown)
{
cmdManager.RobotMove(-100);
}
else
{
MessagePopup(MessageType.Warning, ButtonsType.Ok, "Abnormal behavior", "Callback OnButtonMouvClicked called by unknown sender");
}
}
void OnBatteryTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
DestijlCommandManager.CommandStatus status;
//int batteryLevel;
batteryTimer.Stop();
if (checkButtonGetBattery.Active)
{
//status = cmdManager.RobotGetBattery(out batteryLevel);
status = cmdManager.RobotGetBattery();
switch (status)
{
case DestijlCommandManager.CommandStatus.Success:
/*switch (batteryLevel)
{
case 2:
labelBatteryLevel.Text = "High";
break;
case 1:
labelBatteryLevel.Text = "Low";
break;
case 0:
labelBatteryLevel.Text = "Empty";
break;
default:
labelBatteryLevel.Text = "Unknown";
break;
}*/
batteryTimer.Start();
break;
case DestijlCommandManager.CommandStatus.CommunicationLostWithServer:
//MessagePopup(MessageType.Error, ButtonsType.Ok, "Error", "Connection lost with server");
Console.WriteLine("Error: Connection lost with server");
batteryTimer.Stop();
labelBatteryLevel.Text = "Unknown";
ChangeState(SystemState.NotConnected);
break;
case DestijlCommandManager.CommandStatus.CommunicationLostWithRobot:
//MessagePopup(MessageType.Error, ButtonsType.Ok, "Error", "Connection lost with robot");
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();
}
protected void OnCheckButtonCameraOnClicked(object sender, EventArgs e)
{
if (!checkButtonCameraOn.Active)
{
if (cmdManager.CameraClose() != DestijlCommandManager.CommandStatus.Success)
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Error when closing camera: bad answer for supervisor or timeout");
}
}
else
{
if (cmdManager.CameraOpen() != DestijlCommandManager.CommandStatus.Success)
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Error when opening camera: bad answer for supervisor or timeout");
checkButtonCameraOn.Active = false;
}
}
}
protected void OnCheckButtonRobotPositionClicked(object sender, EventArgs e)
{
if (!checkButtonRobotPosition.Active)
{
if (cmdManager.CameraStopComputePosition() != DestijlCommandManager.CommandStatus.Success)
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Error when stopping position reception: bad answer for supervisor or timeout");
}
}
else
{
if (cmdManager.CameraComputePosition() != DestijlCommandManager.CommandStatus.Success)
{
MessagePopup(MessageType.Error,
ButtonsType.Ok, "Error",
"Error when starting getting robot position: bad answer for supervisor or timeout");
checkButtonRobotPosition.Active = false;
}
}
}
protected void OnDrawingAreaCameraRealized(object sender, EventArgs e)
{
Console.WriteLine("Event realized. Args = " + e.ToString());
}
protected void OnDrawingAreaCameraExposeEvent(object o, ExposeEventArgs args)
{
//Console.WriteLine("Event expose. Args = " + args.ToString());
DrawingArea area = (DrawingArea)o;
Gdk.GC gc = area.Style.BackgroundGC(Gtk.StateType.Normal);
area.GdkWindow.GetSize(out int areaWidth, out int areaHeight);
area.GdkWindow.DrawPixbuf(gc, drawingareaCameraPixbuf,
0, 0,
(areaWidth - drawingareaCameraPixbuf.Width) / 2,
(areaHeight - drawingareaCameraPixbuf.Height) / 2,
drawingareaCameraPixbuf.Width, drawingareaCameraPixbuf.Height,
RgbDither.Normal, 0, 0);
}
protected void OnDrawingAreaCameraConfigureEvent(object o, ConfigureEventArgs args)
{
//Console.WriteLine("Event configure. Args = " + args.ToString());
}
}

View file

@ -5,27 +5,119 @@ public partial class MainWindow
{
private global::Gtk.UIManager UIManager;
private global::Gtk.Action FileAction;
private global::Gtk.Action QuitAction;
private global::Gtk.Action LogAction;
private global::Gtk.Action ShowLogWindowAction;
private global::Gtk.VBox vbox1;
private global::Gtk.MenuBar menubar1;
private global::Gtk.MenuBar menuBar;
private global::Gtk.HBox hbox1;
private global::Gtk.DrawingArea drawingarea1;
private global::Gtk.VBox boxCamera;
private global::Gtk.DrawingArea drawingAreaCamera;
private global::Gtk.Alignment alignment1;
private global::Gtk.ScrolledWindow GtkScrolledWindow;
private global::Gtk.HBox hbox2;
private global::Gtk.Frame frame1;
private global::Gtk.CheckButton checkButtonCameraOn;
private global::Gtk.Fixed fixed4;
private global::Gtk.CheckButton checkButtonRobotPosition;
private global::Gtk.Button button7;
private global::Gtk.HBox hbox3;
private global::Gtk.Label GtkLabel2;
private global::Gtk.VSeparator vseparator1;
private global::Gtk.Statusbar statusbar1;
private global::Gtk.Alignment alignment3;
private global::Gtk.VBox vbox5;
private global::Gtk.VBox vbox10;
private global::Gtk.Label labelServer;
private global::Gtk.Alignment gtkAlignmentServer;
private global::Gtk.VBox vbox6;
private global::Gtk.Table table1;
private global::Gtk.Entry entryServerName;
private global::Gtk.Entry entryServerPort;
private global::Gtk.Entry entryTimeout;
private global::Gtk.Label label1;
private global::Gtk.Label label2;
private global::Gtk.Label label5;
private global::Gtk.Button buttonServerConnection;
private global::Gtk.HSeparator hseparator1;
private global::Gtk.VBox vbox11;
private global::Gtk.Label labelRobot;
private global::Gtk.Alignment alignment9;
private global::Gtk.Alignment gtkAlignmentRobot;
private global::Gtk.VBox vbox8;
private global::Gtk.Alignment alignment6;
private global::Gtk.HBox hbox4;
private global::Gtk.RadioButton radioButtonWithWatchdog;
private global::Gtk.RadioButton radioButtonWithoutWatchdog;
private global::Gtk.Alignment alignment5;
private global::Gtk.Alignment alignment7;
private global::Gtk.Button buttonRobotActivation;
private global::Gtk.HSeparator hseparator2;
private global::Gtk.VBox vbox12;
private global::Gtk.Label labelRobotControl;
private global::Gtk.Alignment gtkAlignmentRobotControl;
private global::Gtk.VBox vbox9;
private global::Gtk.Alignment alignment8;
private global::Gtk.Table table4;
private global::Gtk.Button buttonDown;
private global::Gtk.Button buttonForward;
private global::Gtk.Button buttonLeft;
private global::Gtk.Button buttonRight;
private global::Gtk.Table table3;
private global::Gtk.Label label3;
private global::Gtk.Label labelBatteryLevel;
private global::Gtk.CheckButton checkButtonGetBattery;
protected virtual void Build()
{
@ -33,21 +125,37 @@ public partial class MainWindow
// Widget MainWindow
this.UIManager = new global::Gtk.UIManager();
global::Gtk.ActionGroup w1 = new global::Gtk.ActionGroup("Default");
this.FileAction = new global::Gtk.Action("FileAction", global::Mono.Unix.Catalog.GetString("File"), null, null);
this.FileAction.IsImportant = true;
this.FileAction.ShortLabel = global::Mono.Unix.Catalog.GetString("File");
w1.Add(this.FileAction, null);
this.QuitAction = new global::Gtk.Action("QuitAction", global::Mono.Unix.Catalog.GetString("Quit..."), null, null);
this.QuitAction.IsImportant = true;
this.QuitAction.ShortLabel = global::Mono.Unix.Catalog.GetString("Quit");
w1.Add(this.QuitAction, "<Primary><Mod2>q");
this.LogAction = new global::Gtk.Action("LogAction", global::Mono.Unix.Catalog.GetString("Log"), null, null);
this.LogAction.ShortLabel = global::Mono.Unix.Catalog.GetString("Log");
w1.Add(this.LogAction, null);
this.ShowLogWindowAction = new global::Gtk.Action("ShowLogWindowAction", global::Mono.Unix.Catalog.GetString("Show log window"), null, null);
this.ShowLogWindowAction.ShortLabel = global::Mono.Unix.Catalog.GetString("Show log window");
w1.Add(this.ShowLogWindowAction, "<Primary><Mod2>s");
this.UIManager.InsertActionGroup(w1, 0);
this.AddAccelGroup(this.UIManager.AccelGroup);
this.Name = "MainWindow";
this.Title = global::Mono.Unix.Catalog.GetString("Monitor UI");
this.Icon = global::Gdk.Pixbuf.LoadFromResource("monitor.ressources.robot-icon.resized.png");
this.WindowPosition = ((global::Gtk.WindowPosition)(4));
this.BorderWidth = ((uint)(5));
// Container child MainWindow.Gtk.Container+ContainerChild
this.vbox1 = new global::Gtk.VBox();
this.vbox1.Name = "vbox1";
this.vbox1.Spacing = 6;
// Container child vbox1.Gtk.Box+BoxChild
this.UIManager.AddUiFromString("<ui><menubar name=\'menubar1\'/></ui>");
this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget("/menubar1")));
this.menubar1.Name = "menubar1";
this.vbox1.Add(this.menubar1);
global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.menubar1]));
this.UIManager.AddUiFromString(@"<ui><menubar name='menuBar'><menu name='FileAction' action='FileAction'><menuitem name='QuitAction' action='QuitAction'/></menu><menu name='LogAction' action='LogAction'><menuitem name='ShowLogWindowAction' action='ShowLogWindowAction'/></menu></menubar></ui>");
this.menuBar = ((global::Gtk.MenuBar)(this.UIManager.GetWidget("/menuBar")));
this.menuBar.Name = "menuBar";
this.vbox1.Add(this.menuBar);
global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.menuBar]));
w2.Position = 0;
w2.Expand = false;
w2.Fill = false;
@ -56,71 +164,486 @@ public partial class MainWindow
this.hbox1.Name = "hbox1";
this.hbox1.Spacing = 6;
// Container child hbox1.Gtk.Box+BoxChild
this.drawingarea1 = new global::Gtk.DrawingArea();
this.drawingarea1.Name = "drawingarea1";
this.hbox1.Add(this.drawingarea1);
global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.drawingarea1]));
this.boxCamera = new global::Gtk.VBox();
this.boxCamera.Name = "boxCamera";
this.boxCamera.Spacing = 6;
// Container child boxCamera.Gtk.Box+BoxChild
this.drawingAreaCamera = new global::Gtk.DrawingArea();
this.drawingAreaCamera.Name = "drawingAreaCamera";
this.boxCamera.Add(this.drawingAreaCamera);
global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.boxCamera[this.drawingAreaCamera]));
w3.Position = 0;
// Container child hbox1.Gtk.Box+BoxChild
this.alignment1 = new global::Gtk.Alignment(0.5F, 0.5F, 1F, 1F);
// Container child boxCamera.Gtk.Box+BoxChild
this.alignment1 = new global::Gtk.Alignment(0F, 0.5F, 0F, 1F);
this.alignment1.Name = "alignment1";
this.alignment1.BorderWidth = ((uint)(6));
// Container child alignment1.Gtk.Container+ContainerChild
this.GtkScrolledWindow = new global::Gtk.ScrolledWindow();
this.GtkScrolledWindow.Name = "GtkScrolledWindow";
this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1));
// Container child GtkScrolledWindow.Gtk.Container+ContainerChild
global::Gtk.Viewport w4 = new global::Gtk.Viewport();
w4.ShadowType = ((global::Gtk.ShadowType)(0));
// Container child GtkViewport.Gtk.Container+ContainerChild
this.frame1 = new global::Gtk.Frame();
this.frame1.Name = "frame1";
this.frame1.ShadowType = ((global::Gtk.ShadowType)(0));
// Container child frame1.Gtk.Container+ContainerChild
this.fixed4 = new global::Gtk.Fixed();
this.fixed4.Name = "fixed4";
this.fixed4.HasWindow = false;
// Container child fixed4.Gtk.Fixed+FixedChild
this.button7 = new global::Gtk.Button();
this.button7.CanFocus = true;
this.button7.Name = "button7";
this.button7.UseUnderline = true;
this.button7.Label = global::Mono.Unix.Catalog.GetString("GtkButton");
this.fixed4.Add(this.button7);
global::Gtk.Fixed.FixedChild w5 = ((global::Gtk.Fixed.FixedChild)(this.fixed4[this.button7]));
w5.X = 30;
w5.Y = 25;
this.frame1.Add(this.fixed4);
this.GtkLabel2 = new global::Gtk.Label();
this.GtkLabel2.Name = "GtkLabel2";
this.GtkLabel2.LabelProp = global::Mono.Unix.Catalog.GetString("<b>Controls</b>");
this.GtkLabel2.UseMarkup = true;
this.frame1.LabelWidget = this.GtkLabel2;
w4.Add(this.frame1);
this.GtkScrolledWindow.Add(w4);
this.alignment1.Add(this.GtkScrolledWindow);
this.hbox1.Add(this.alignment1);
global::Gtk.Box.BoxChild w10 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.alignment1]));
w10.Position = 1;
this.hbox2 = new global::Gtk.HBox();
this.hbox2.Name = "hbox2";
this.hbox2.Spacing = 6;
// Container child hbox2.Gtk.Box+BoxChild
this.checkButtonCameraOn = new global::Gtk.CheckButton();
this.checkButtonCameraOn.CanFocus = true;
this.checkButtonCameraOn.Name = "checkButtonCameraOn";
this.checkButtonCameraOn.Label = global::Mono.Unix.Catalog.GetString("Camera On");
this.checkButtonCameraOn.DrawIndicator = true;
this.checkButtonCameraOn.UseUnderline = true;
this.hbox2.Add(this.checkButtonCameraOn);
global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.checkButtonCameraOn]));
w4.Position = 0;
// Container child hbox2.Gtk.Box+BoxChild
this.checkButtonRobotPosition = new global::Gtk.CheckButton();
this.checkButtonRobotPosition.CanFocus = true;
this.checkButtonRobotPosition.Name = "checkButtonRobotPosition";
this.checkButtonRobotPosition.Label = global::Mono.Unix.Catalog.GetString("Robot Position");
this.checkButtonRobotPosition.DrawIndicator = true;
this.checkButtonRobotPosition.UseUnderline = true;
this.hbox2.Add(this.checkButtonRobotPosition);
global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.checkButtonRobotPosition]));
w5.Position = 1;
this.alignment1.Add(this.hbox2);
this.boxCamera.Add(this.alignment1);
global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.boxCamera[this.alignment1]));
w7.Position = 1;
w7.Expand = false;
w7.Fill = false;
this.hbox1.Add(this.boxCamera);
global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.boxCamera]));
w8.Position = 0;
// Container child hbox1.Gtk.Box+BoxChild
this.hbox3 = new global::Gtk.HBox();
this.hbox3.Name = "hbox3";
this.hbox3.Spacing = 6;
// Container child hbox3.Gtk.Box+BoxChild
this.vseparator1 = new global::Gtk.VSeparator();
this.vseparator1.Name = "vseparator1";
this.hbox3.Add(this.vseparator1);
global::Gtk.Box.BoxChild w9 = ((global::Gtk.Box.BoxChild)(this.hbox3[this.vseparator1]));
w9.Position = 0;
w9.Expand = false;
w9.Fill = false;
// Container child hbox3.Gtk.Box+BoxChild
this.alignment3 = new global::Gtk.Alignment(1F, 0F, 0F, 0F);
this.alignment3.Name = "alignment3";
this.alignment3.BorderWidth = ((uint)(4));
// Container child alignment3.Gtk.Container+ContainerChild
this.vbox5 = new global::Gtk.VBox();
this.vbox5.Name = "vbox5";
this.vbox5.Spacing = 6;
// Container child vbox5.Gtk.Box+BoxChild
this.vbox10 = new global::Gtk.VBox();
this.vbox10.Name = "vbox10";
this.vbox10.Spacing = 6;
// Container child vbox10.Gtk.Box+BoxChild
this.labelServer = new global::Gtk.Label();
this.labelServer.HeightRequest = 36;
this.labelServer.Name = "labelServer";
this.labelServer.LabelProp = global::Mono.Unix.Catalog.GetString("<b><u>Server connection</u></b>");
this.labelServer.UseMarkup = true;
this.vbox10.Add(this.labelServer);
global::Gtk.Box.BoxChild w10 = ((global::Gtk.Box.BoxChild)(this.vbox10[this.labelServer]));
w10.Position = 0;
w10.Expand = false;
w10.Fill = false;
// Container child vbox10.Gtk.Box+BoxChild
this.gtkAlignmentServer = new global::Gtk.Alignment(0F, 0F, 1F, 1F);
this.gtkAlignmentServer.Name = "gtkAlignmentServer";
this.gtkAlignmentServer.LeftPadding = ((uint)(12));
// Container child gtkAlignmentServer.Gtk.Container+ContainerChild
this.vbox6 = new global::Gtk.VBox();
this.vbox6.Name = "vbox6";
this.vbox6.Spacing = 6;
// Container child vbox6.Gtk.Box+BoxChild
this.table1 = new global::Gtk.Table(((uint)(3)), ((uint)(2)), false);
this.table1.Name = "table1";
this.table1.RowSpacing = ((uint)(6));
this.table1.ColumnSpacing = ((uint)(6));
// Container child table1.Gtk.Table+TableChild
this.entryServerName = new global::Gtk.Entry();
this.entryServerName.CanFocus = true;
this.entryServerName.Name = "entryServerName";
this.entryServerName.IsEditable = true;
this.entryServerName.InvisibleChar = '●';
this.table1.Add(this.entryServerName);
global::Gtk.Table.TableChild w11 = ((global::Gtk.Table.TableChild)(this.table1[this.entryServerName]));
w11.LeftAttach = ((uint)(1));
w11.RightAttach = ((uint)(2));
w11.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.entryServerPort = new global::Gtk.Entry();
this.entryServerPort.CanFocus = true;
this.entryServerPort.Name = "entryServerPort";
this.entryServerPort.IsEditable = true;
this.entryServerPort.InvisibleChar = '●';
this.table1.Add(this.entryServerPort);
global::Gtk.Table.TableChild w12 = ((global::Gtk.Table.TableChild)(this.table1[this.entryServerPort]));
w12.TopAttach = ((uint)(1));
w12.BottomAttach = ((uint)(2));
w12.LeftAttach = ((uint)(1));
w12.RightAttach = ((uint)(2));
w12.YOptions = ((global::Gtk.AttachOptions)(4));
// Container child table1.Gtk.Table+TableChild
this.entryTimeout = new global::Gtk.Entry();
this.entryTimeout.CanFocus = true;
this.entryTimeout.Name = "entryTimeout";
this.entryTimeout.IsEditable = true;
this.entryTimeout.InvisibleChar = '●';
this.table1.Add(this.entryTimeout);
global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1[this.entryTimeout]));
w13.TopAttach =</