35 PixbufFormat[] format =
Gdk.Pixbuf.Formats;
36 foreach (PixbufFormat f
in format)
38 Console.WriteLine(
"Format: " + f.Name);
46 drawingareaCameraPixbuf =
new Pixbuf((
string)null);
47 drawingareaCameraPixbuf = Pixbuf.LoadFromResource(
"monitor.ressources.missing_picture.png");
51 entryTimeout.Text =
"10000";
59 labelRobot.Sensitive =
false;
60 gtkAlignmentRobot.Sensitive =
false;
62 labelRobotControl.Sensitive =
false;
63 gtkAlignmentRobotControl.Sensitive =
false;
64 boxCamera.Sensitive =
false;
66 buttonServerConnection.Label =
"Connect";
67 buttonRobotActivation.Label =
"Activate";
68 labelBatteryLevel.Text =
"Unknown";
70 checkButtonCameraOn.Active =
false;
71 checkButtonRobotPosition.Active =
false;
72 if (cmdManager != null) cmdManager.
Close();
77 buttonServerConnection.Label =
"Disconnect";
78 buttonRobotActivation.Label =
"Activate";
79 labelBatteryLevel.Text =
"Unknown";
81 labelRobot.Sensitive =
true;
82 gtkAlignmentRobot.Sensitive =
true;
83 boxCamera.Sensitive =
true;
85 labelRobotControl.Sensitive =
false;
86 gtkAlignmentRobotControl.Sensitive =
false;
91 buttonRobotActivation.Label =
"Reset";
92 labelRobotControl.Sensitive =
true;
93 gtkAlignmentRobotControl.Sensitive =
true;
98 labelRobot.Sensitive =
false;
99 gtkAlignmentRobot.Sensitive =
false;
101 labelRobotControl.Sensitive =
false;
102 gtkAlignmentRobotControl.Sensitive =
false;
103 boxCamera.Sensitive =
false;
105 buttonServerConnection.Label =
"Connect";
106 buttonRobotActivation.Label =
"Activate";
107 labelBatteryLevel.Text =
"Unknown";
109 checkButtonCameraOn.Active =
false;
110 checkButtonRobotPosition.Active =
false;
117 systemState = newState;
120 private void MessagePopup(MessageType type, ButtonsType buttons,
string title,
string message)
122 MessageDialog md =
new MessageDialog(
this, DialogFlags.DestroyWithParent, type, buttons, message)
133 Console.WriteLine(
"Bye bye");
135 if (cmdManager != null) cmdManager.
Close();
144 Console.WriteLine(
"Received header (" + header.Length +
"): " + header);
147 if (data != null) Console.WriteLine(
"Received data (" + data.Length +
"): " + data);
155 labelBatteryLevel.Text =
"High";
158 labelBatteryLevel.Text =
"Low";
161 labelBatteryLevel.Text =
"Empty";
164 labelBatteryLevel.Text =
"Invalid value";
170 byte[] image =
new byte[buffer.Length - 4];
171 System.Buffer.BlockCopy(buffer, 4, image, 0, image.Length);
173 drawingareaCameraPixbuf =
new Pixbuf(image);
174 drawingAreaCamera.QueueDraw();
181 Console.WriteLine(
"Bye bye 2");
182 if (cmdManager != null) cmdManager.
Close();
190 ButtonsType.Ok,
"Info",
191 "Logger not yet implemented");
198 if (buttonServerConnection.Label ==
"Disconnect")
204 if ((entryServerName.Text ==
"") || (entryServerPort.Text ==
""))
207 ButtonsType.Ok,
"Error",
208 "Server name or port is invalid");
212 Console.WriteLine(
"Connecting to " + entryServerName.Text +
":" + entryServerPort.Text);
217 cmdManager.
timeout = Convert.ToDouble(entryTimeout.Text);
222 entryTimeout.Text = cmdManager.
timeout.ToString();
227 status = cmdManager.
Open(entryServerName.Text, Convert.ToInt32(entryServerPort.Text));
231 Console.WriteLine(
"Something went wrong during connection");
238 ButtonsType.Ok,
"Error",
239 "Unable to connect to server " + entryServerName.Text +
":" + Convert.ToInt32(entryServerPort.Text));
243 Console.Write(
"Send command RobotOpenCom: ");
245 Console.WriteLine(statusCmd.ToString());
254 ButtonsType.Ok,
"Error",
255 "Unable to open communication with robot.\nCheck that supervisor is accepting OPEN_COM_DMB command");
268 if (buttonRobotActivation.Label ==
"Activate")
270 if (radioButtonWithWatchdog.Active)
287 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Connection lost with server");
292 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Command rejected\nCheck that supervisor accept \nDMB_START_WITH_WD and/or DMB_START_WITHOUT_WD");
308 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Connection lost with server");
313 MessagePopup(MessageType.Error, ButtonsType.Ok,
"Error",
"Unknown error");
321 if (sender == buttonRight)
325 else if (sender == buttonLeft)
329 else if (sender == buttonForward)
333 else if (sender == buttonDown)
339 MessagePopup(MessageType.Warning, ButtonsType.Ok,
"Abnormal behavior",
"Callback OnButtonMouvClicked called by unknown sender");
348 if (checkButtonGetBattery.Active)
357 Console.WriteLine(
"Error: Connection lost with server");
359 labelBatteryLevel.Text =
"Unknown";
364 Console.WriteLine(
"Error: Connection lost with robot");
366 labelBatteryLevel.Text =
"Unknown";
371 labelBatteryLevel.Text =
"Unknown";
381 if (!checkButtonCameraOn.Active)
386 ButtonsType.Ok,
"Error",
387 "Error when closing camera: bad answer for supervisor or timeout");
395 ButtonsType.Ok,
"Error",
396 "Error when opening camera: bad answer for supervisor or timeout");
397 checkButtonCameraOn.Active =
false;
404 if (!checkButtonRobotPosition.Active)
409 ButtonsType.Ok,
"Error",
410 "Error when stopping position reception: bad answer for supervisor or timeout");
418 ButtonsType.Ok,
"Error",
419 "Error when starting getting robot position: bad answer for supervisor or timeout");
421 checkButtonRobotPosition.Active =
false;
430 DrawingArea area = (DrawingArea)o;
431 Gdk.Pixbuf displayPixbuf;
432 int areaWidth, areaHeight;
434 Gdk.GC gc = area.Style.BackgroundGC(
Gtk.StateType.Normal);
436 area.GdkWindow.GetSize(out areaWidth, out areaHeight);
437 int width = drawingareaCameraPixbuf.Width;
438 int height = drawingareaCameraPixbuf.Height;
439 float ratio = (float)width / (
float)height;
441 if (areaWidth <= width)
444 height = (int)(width / ratio);
447 if (width > areaWidth)
452 if (height > areaHeight)
457 displayPixbuf = drawingareaCameraPixbuf.ScaleSimple(width, height, InterpType.Bilinear);
459 area.GdkWindow.DrawPixbuf(gc, displayPixbuf,
461 (areaWidth - displayPixbuf.Width) / 2,
462 (areaHeight - displayPixbuf.Height) / 2,
463 displayPixbuf.Width, displayPixbuf.Height,
464 RgbDither.Normal, 0, 0);
470 MessageDialog md =
new MessageDialog(
this, DialogFlags.DestroyWithParent,
471 MessageType.Question, ButtonsType.YesNo,
"Arena is correct ?");
473 Title =
"Check arena";
476 ResponseType result = (ResponseType)md.Run();
479 if (result == ResponseType.Yes)
491 ButtonsType.Ok,
"Error",
492 "Unable to send Confirm or Infirm arena command to supervisor");
501 ButtonsType.Ok,
"Error",
502 "Error when asking for arena rendering");
const string HeaderStmImage
CommandStatus RobotStartWithoutWatchdog()
const int defaultPort
Default server port number
void OnButtonServerConnectionClicked(object sender, EventArgs e)
CommandStatus CameraArenaInfirm()
const string HeaderStmBat
void OnButtonRobotActivationClicked(object sender, EventArgs e)
DestijlCommandManager cmdManager
CommandStatus RobotGetBattery()
void OnCheckButtonCameraOnClicked(object sender, EventArgs e)
CommandStatus RobotStartWithWatchdog()
Pixbuf drawingareaCameraPixbuf
void OnDeleteEvent(object sender, DeleteEventArgs a)
CommandStatus CameraComputePosition()
CommandStatus CameraStopComputePosition()
const string defaultIP
Default server name
CommandStatus CameraArenaConfirm()
void OnBatteryTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
void OnButtonMouvClicked(object sender, EventArgs e)
void OnShowLogWindowActionActivated(object sender, EventArgs e)
void OnCheckButtonRobotPositionClicked(object sender, EventArgs e)
CommandStatus CameraAskArena()
CommandStatus RobotReset()
void ChangeState(SystemState newState)
void MessagePopup(MessageType type, ButtonsType buttons, string title, string message)
void OnQuitActionActivated(object sender, EventArgs e)
CommandStatus CameraClose()
CommandStatus RobotTurn(int angle)
CommandStatus CameraOpen()
void OnDrawingAreaCameraExposeEvent(object o, ExposeEventArgs args)
void OnButtonAskArenaClicked(object sender, EventArgs e)
Static class for TCP client
System.Timers.Timer batteryTimer
CommandStatus RobotMove(int distance)
CommandStatus RobotOpenCom()
void OnCommandReceivedEvent(string header, string data, byte[] buffer)
bool Open(string hostname)