91 drawingareaCameraPixbuf = Pixbuf.LoadFromResource(
"monitor.ressources.missing_picture.png");
96 entryTimeout.Text =
"100";
108 labelRobot.Sensitive =
false;
109 gtkAlignmentRobot.Sensitive =
false;
111 labelRobotControl.Sensitive =
false;
112 gtkAlignmentRobotControl.Sensitive =
false;
113 boxCamera.Sensitive =
false;
115 buttonServerConnection.Label =
"Connect";
116 buttonRobotActivation.Label =
"Activate";
117 labelBatteryLevel.Text =
"Unknown";
119 checkButtonCameraOn.Active =
false;
120 checkButtonRobotPosition.Active =
false;
121 if (cmdManager != null) cmdManager.
Close();
126 buttonServerConnection.Label =
"Disconnect";
127 buttonRobotActivation.Label =
"Activate";
128 labelBatteryLevel.Text =
"Unknown";
130 labelRobot.Sensitive =
true;
131 gtkAlignmentRobot.Sensitive =
true;
132 boxCamera.Sensitive =
true;
134 labelRobotControl.Sensitive =
false;
135 gtkAlignmentRobotControl.Sensitive =
false;
140 buttonRobotActivation.Label =
"Reset";
141 labelRobotControl.Sensitive =
true;
142 gtkAlignmentRobotControl.Sensitive =
true;
147 labelRobot.Sensitive =
false;
148 gtkAlignmentRobot.Sensitive =
false;
150 labelRobotControl.Sensitive =
false;
151 gtkAlignmentRobotControl.Sensitive =
false;
152 boxCamera.Sensitive =
false;
154 buttonServerConnection.Label =
"Connect";
155 buttonRobotActivation.Label =
"Activate";
156 labelBatteryLevel.Text =
"Unknown";
158 checkButtonCameraOn.Active =
false;
159 checkButtonRobotPosition.Active =
false;
166 systemState = newState;
176 private void MessagePopup(MessageType type, ButtonsType buttons,
string title,
string message)
178 MessageDialog md =
new MessageDialog(
this, DialogFlags.DestroyWithParent, type, buttons, message)
194 Console.WriteLine(
"Bye bye");
196 if (cmdManager != null) cmdManager.
Close();
213 Console.WriteLine(
"Received header (" + header.Length +
"): " + header);
216 if (data != null) Console.WriteLine(
"Received data (" + data.Length +
"): " + data);
226 labelBatteryLevel.Text =
"High";
229 labelBatteryLevel.Text =
"Low";
232 labelBatteryLevel.Text =
"Empty";
235 labelBatteryLevel.Text =
"Invalid value";
243 byte[] image =
new byte[buffer.Length - 4];
244 System.Buffer.BlockCopy(buffer, 4, image, 0, image.Length);
246 drawingareaCameraPixbuf =
new Pixbuf(image);
247 drawingAreaCamera.QueueDraw();
259 Console.WriteLine(
"Bye bye 2");
260 if (cmdManager != null) cmdManager.
Close();
273 ButtonsType.Ok,
"Info",
274 "Logger not yet implemented");
287 if (buttonServerConnection.Label ==
"Disconnect")
295 if ((entryServerName.Text ==
"") || (entryServerPort.Text ==
""))
298 ButtonsType.Ok,
"Error",
299 "Server name or port is invalid");
303 Console.WriteLine(
"Connecting to " + entryServerName.Text +
":" + entryServerPort.Text);
309 cmdManager.
timeout = Convert.ToDouble(entryTimeout.Text);
314 entryTimeout.Text = cmdManager.
timeout.ToString();
320 status = cmdManager.
Open(entryServerName.Text, Convert.ToInt32(entryServerPort.Text));
324 Console.WriteLine(
"Something went wrong during connection");
332 ButtonsType.Ok,
"Error",
333 "Unable to connect to server " + entryServerName.Text +
":" + Convert.ToInt32(entryServerPort.Text));
337 Console.Write(
"Send command RobotOpenCom: ");
339 Console.WriteLine(statusCmd.ToString());
348 ButtonsType.Ok,
"Error",
349 "Unable to open communication with robot.\nCheck that supervisor is accepting OPEN_COM_DMB command");
368 if (buttonRobotActivation.Label ==
"Activate")
371 if (radioButtonWithWatchdog.Active)
389 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Connection lost with server");
394 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Command rejected\nCheck that supervisor accept \nDMB_START_WITH_WD and/or DMB_START_WITHOUT_WD");
411 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Connection lost with server");
416 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Unknown error");
430 if (sender == buttonRight)
434 else if (sender == buttonLeft)
438 else if (sender == buttonForward)
442 else if (sender == buttonDown)
448 MessagePopup(MessageType.Warning, ButtonsType.Ok,
"Abnormal behavior",
"Callback OnButtonMouvClicked called by unknown sender");
463 if (checkButtonGetBattery.Active)
474 Console.WriteLine(
"Error: Connection lost with server");
476 labelBatteryLevel.Text =
"Unknown";
481 Console.WriteLine(
"Error: Connection lost with robot");
483 labelBatteryLevel.Text =
"Unknown";
488 labelBatteryLevel.Text =
"Unknown";
504 if (!checkButtonCameraOn.Active)
509 ButtonsType.Ok,
"Error",
510 "Error when closing camera: bad answer for supervisor or timeout");
518 ButtonsType.Ok,
"Error",
519 "Error when opening camera: bad answer for supervisor or timeout");
520 checkButtonCameraOn.Active =
false;
533 if (!checkButtonRobotPosition.Active)
538 ButtonsType.Ok,
"Error",
539 "Error when stopping position reception: bad answer for supervisor or timeout");
547 ButtonsType.Ok,
"Error",
548 "Error when starting getting robot position: bad answer for supervisor or timeout");
550 checkButtonRobotPosition.Active =
false;
564 DrawingArea area = (DrawingArea)o;
565 Gdk.Pixbuf displayPixbuf;
566 int areaWidth, areaHeight;
569 Gdk.GC gc = area.Style.BackgroundGC(
Gtk.StateType.Normal);
572 area.GdkWindow.GetSize(out areaWidth, out areaHeight);
573 int width = drawingareaCameraPixbuf.Width;
574 int height = drawingareaCameraPixbuf.Height;
575 float ratio = (float)width / (
float)height;
578 if (areaWidth <= width)
581 height = (int)(width / ratio);
585 if (width > areaWidth)
590 if (height > areaHeight)
596 displayPixbuf = drawingareaCameraPixbuf.ScaleSimple(width, height, InterpType.Bilinear);
599 area.GdkWindow.DrawPixbuf(gc, displayPixbuf,
601 (areaWidth - displayPixbuf.Width) / 2,
602 (areaHeight - displayPixbuf.Height) / 2,
603 displayPixbuf.Width, displayPixbuf.Height,
604 RgbDither.Normal, 0, 0);
613 MessageDialog md =
new MessageDialog(
this, DialogFlags.DestroyWithParent,
614 MessageType.Question, ButtonsType.YesNo,
"Arena is correct ?");
616 Title =
"Check arena";
619 ResponseType result = (ResponseType)md.Run();
622 if (result == ResponseType.Yes)
634 ButtonsType.Ok,
"Error",
635 "Unable to send Confirm or Infirm arena command to supervisor");
650 ButtonsType.Ok,
"Error",
651 "Error when asking for arena rendering");
const string HeaderStmImage
CommandStatus RobotStartWithoutWatchdog()
Start robot, without enabling watchdog
const int defaultPort
Default server port number
void OnButtonServerConnectionClicked(object sender, EventArgs e)
Callback called by "buttonServerConnection" button
CommandStatus CameraArenaInfirm()
Reject arena detected (after requesting image of detected arena, using CameraAskArena ...
void Close()
Close connection to server
SystemState
List of availble state for the application
const string HeaderStmBat
void OnButtonRobotActivationClicked(object sender, EventArgs e)
Callback called when "buttonRobotactivation" is clicked
DestijlCommandManager cmdManager
Destijl command manager reference
CommandStatus RobotGetBattery()
Request robot battery level
void OnCheckButtonCameraOnClicked(object sender, EventArgs e)
Callback called when checkbutton for camera is clicked
CommandStatus RobotStartWithWatchdog()
Start robot, enabling watchdog
void DetectArena()
Show a popup asking user to tell if arena is correct or not
Pixbuf drawingareaCameraPixbuf
Pixbuffer used for displaying image
void OnDeleteEvent(object sender, DeleteEventArgs a)
Callback called when delete event is sent by window
Specialization class for command manager, which implemnent destijl protocol between monitor and serve...
CommandStatus CameraComputePosition()
Request robot position computing
CommandStatus CameraStopComputePosition()
Stop robot position computing
const string defaultIP
Default server name
CommandStatus CameraArenaConfirm()
Confirm arena detection (after requesting image of detected arena, using CameraAskArena ...
CommandStatus
List of available return status
void OnBatteryTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
Callback called when battery timer expired
void OnButtonMouvClicked(object sender, EventArgs e)
Callback called when user click on direction button
void OnShowLogWindowActionActivated(object sender, EventArgs e)
Callback called by "show log" menu
void OnCheckButtonRobotPositionClicked(object sender, EventArgs e)
Callback called when checkbutton robot position is clicked
CommandStatus CameraAskArena()
Request still image of detected arena
CommandStatus RobotReset()
Reset robot and let it in idle mode
void ChangeState(SystemState newState)
Method used to change controls visibility (greyed or not) depending on current state ...
void MessagePopup(MessageType type, ButtonsType buttons, string title, string message)
Display a popup message window
void OnQuitActionActivated(object sender, EventArgs e)
Callback called by "quit" menu
MainWindow()
Initializes a new instance of the MainWindow class.
CommandStatus CameraClose()
Close camera on remote device
CommandStatus RobotTurn(int angle)
Make robot turn left or right, for a given angle
CommandStatus CameraOpen()
Open camera on remote device
void OnDrawingAreaCameraExposeEvent(object o, ExposeEventArgs args)
Callback called when drawingarea need refresh
void OnButtonAskArenaClicked(object sender, EventArgs e)
Callback called when "detect Arena " button is clicked
Static class for TCP client
System.Timers.Timer batteryTimer
Timer for battery request
void AdjustControls()
Make some adjustement to controls, like disabling some controls
CommandStatus RobotMove(int distance)
Move robot forward or backward, for a distance expressed in millimeter
SystemState systemState
The state of the system. Can take a value from SystemState
Main part of the program, behavior of main window
CommandStatus RobotOpenCom()
Open communication with robot and wait acknowledge
Commands and options parameters used in Destijl project when communicating with server ...
void OnCommandReceivedEvent(string header, string data, byte[] buffer)
Callback called when new message is received from server
bool Open(string hostname)
Open the specified hostname server, using default port number.
double timeout
Timeout used for command with acknowledge