diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
deleted file mode 100644
index ee202d8..0000000
--- a/.vscode/c_cpp_properties.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "configurations": [
- {
- "name": "Linux",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "defines": [],
- "compilerPath": "/usr/bin/clang",
- "cStandard": "c11",
- "cppStandard": "c++17",
- "intelliSenseMode": "clang-x64"
- }
- ],
- "version": 4
-}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
deleted file mode 100644
index 29327bf..0000000
--- a/.vscode/tasks.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- // See https://go.microsoft.com/fwlink/?LinkId=733558
- // for the documentation about the tasks.json format
- "version": "2.0.0",
- "tasks": [
- {
- "taskName": "Compile on raspberry",
- "command": "rsync -az '${file}' 10.105.1.6:~ && ssh server.example.org 'chmod +x ./${fileBasename}; ./${fileBasename}'",
- "type": "shell",
- "group": {
- "kind": "build",
- "isDefault": true
- }
- }
- ]
-}
\ No newline at end of file
diff --git a/software/monitor/monitor/Client.cs b/software/monitor/monitor/Client.cs
index 48bb9c9..b6afe8a 100644
--- a/software/monitor/monitor/Client.cs
+++ b/software/monitor/monitor/Client.cs
@@ -23,6 +23,8 @@ using System;
using System.Net.Sockets;
using System.Text;
+using System.Threading;
+
namespace monitor
{
///
@@ -66,21 +68,26 @@ namespace monitor
///
private static byte[] receiveBuffer;
- private static int initialReceiveBufferIndex = 0;
+ //private static int initialReceiveBufferIndex = 0;
///
/// String containing received message from tcp server
///
private static StringBuilder message = new StringBuilder();
- private static int newLength = 1;
- private static int packetCounter = 0;
+ //private static int newLength = 1;
+ //private static int packetCounter = 0;
///
/// Callback to send received message to upper level
///
- public delegate void ReadEvent(string msg, byte[] buffer);
+ public delegate void ReadEvent(string msg);
public static ReadEvent readEvent = null;
+ ///
+ /// Thread used in reception
+ ///
+ private static Thread readThread;
+
///
/// Open connection to server "host", on default port number.
///
@@ -114,7 +121,12 @@ namespace monitor
// received data are stored in buffer
// Next reading will be done in ReadCallback method
- stream.BeginRead(buffer, 0, newLength, new AsyncCallback(ReadCallback), message);
+ stream.BeginRead(buffer, 0, 1, new AsyncCallback(ReadCallback), message);
+
+ // Start reading thread
+ //message.Clear();
+ //readThread = new Thread(new ThreadStart(ReadCallback));
+ //readThread.Start();
}
catch (ArgumentNullException e)
{
@@ -144,19 +156,142 @@ namespace monitor
if (client != null) client.Close();
}
+ ///
+ /// Callback call by stream.BeginRead after reception of newLength data
+ ///
+ //private static void ReadCallback()
+ //{
+ // char character;
+ // int data;
+ // byte[] buffer=new byte[4096];
+ // int lengthRead;
+
+ // while (client.Connected)
+ // {
+ // try
+ // {
+ // //data = stream.ReadByte();
+ // lengthRead = stream.Read(buffer, 0, buffer.Length);
+ // }
+ // catch (ObjectDisposedException)
+ // {
+ // Console.WriteLine("Connection to server dropped (object disposed)!");
+ // return;
+ // }
+ // catch (System.IO.IOException)
+ // {
+ // Console.WriteLine("Connection to server dropped (other error)");
+ // return;
+ // }
+
+ // if (lengthRead > 0) // a data was read
+ // {
+ // //character = (char)data;
+ // var str = System.Text.Encoding.Default.GetString(buffer);
+ // int indexOf = str.IndexOf('\n');
+
+ // //if (character != '\n')
+ // if (indexOf == -1) // \n doesn't exists
+ // {
+ // message.Append(str);
+
+ // //if (receiveBuffer == null) receiveBuffer = new byte[1];
+ // //else Array.Resize(ref receiveBuffer, receiveBuffer.Length + 1); // resize currrent buffer
+
+ // //receiveBuffer[receiveBuffer.Length - 1] = (byte)data;
+ // }
+ // else // end of string found
+ // {
+ // message.Append((str.Substring(0,indexOf)));
+ // readEvent?.Invoke(message.ToString(), receiveBuffer);
+
+ // message.Clear();
+ // receiveBuffer = null;
+ // }
+ // }
+ // }
+ //}
+
///
/// Callback call by stream.BeginRead after reception of newLength data
///
/// Not sure of what is it, but needed for terminate reading
+ //private static void ReadCallback(IAsyncResult ar)
+ //{
+ // if (client.Connected)
+ // {
+ // int bytesRead;
+
+ // try
+ // {
+ // // Termintae read operation, and get number of byte stored in buffer
+ // bytesRead = stream.EndRead(ar);
+ // }
+ // catch (ObjectDisposedException e)
+ // {
+ // Console.WriteLine("Connection to server dropped: " + e.ToString());
+ // return;
+ // }
+
+ // newLength = 1;
+
+ // // if number of byte read is not 0, concatenate string and buffer
+ // if (bytesRead > 0)
+ // {
+ // packetCounter++;
+
+ // if (packetCounter >= 3)
+ // {
+ // //Console.WriteLine("Supplementary packet " + packetCounter);
+ // }
+
+ // // Append new data to current string (expecting data are ascii)
+ // message.Append(Encoding.ASCII.GetString(buffer, 0, bytesRead));
+
+ // // Similarly, append received bytes to current buffer
+ // if (receiveBuffer == null) receiveBuffer = new byte[bytesRead];
+ // else Array.Resize(ref receiveBuffer, initialReceiveBufferIndex + bytesRead); // resize currrent buffer
+
+ // System.Buffer.BlockCopy(buffer, 0, receiveBuffer, initialReceiveBufferIndex, bytesRead); // and add received data
+ // initialReceiveBufferIndex = receiveBuffer.Length; // move last index of current buffer
+ // }
+
+ // // if it remains received data, prepare for a new reading (get another buffer to append to current one)
+ // if (client.Available > 0)
+ // {
+ // newLength = client.Available;
+ // if (newLength > BufferMaxSize) newLength = BufferMaxSize;
+ // else newLength = client.Available;
+ // }
+ // else
+ // {
+ // // no more data to read, buffer and string can be send to upper level
+ // readEvent?.Invoke(message.ToString(), receiveBuffer);
+
+ // message.Clear();
+ // receiveBuffer = null;
+ // initialReceiveBufferIndex = 0;
+ // packetCounter = 0;
+ // }
+
+ // // Prepare for reading new data
+ // if (newLength> BufferMaxSize) newLength = BufferMaxSize;
+ // if (newLength <= 0) newLength = 1;
+ // stream.BeginRead(buffer, 0, newLength, new AsyncCallback(ReadCallback), message);
+ // }
+ //}
+
private static void ReadCallback(IAsyncResult ar)
{
+ int newLength = 1;
+
if (client.Connected)
{
int bytesRead;
try
{
- // Termintae read operation, and get number of byte stored in buffer
+ // Terminate read operation, and get number of byte stored in buffer
bytesRead = stream.EndRead(ar);
}
catch (ObjectDisposedException e)
@@ -165,27 +300,13 @@ namespace monitor
return;
}
- newLength = 1;
+ //newLength = 1;
// if number of byte read is not 0, concatenate string and buffer
if (bytesRead > 0)
{
- packetCounter++;
-
- if (packetCounter >= 3)
- {
- //Console.WriteLine("Supplementary packet " + packetCounter);
- }
-
// Append new data to current string (expecting data are ascii)
message.Append(Encoding.ASCII.GetString(buffer, 0, bytesRead));
-
- // Similarly, append received bytes to current buffer
- if (receiveBuffer == null) receiveBuffer = new byte[bytesRead];
- else Array.Resize(ref receiveBuffer, initialReceiveBufferIndex + bytesRead); // resize currrent buffer
-
- System.Buffer.BlockCopy(buffer, 0, receiveBuffer, initialReceiveBufferIndex, bytesRead); // and add received data
- initialReceiveBufferIndex = receiveBuffer.Length; // move last index of current buffer
}
// if it remains received data, prepare for a new reading (get another buffer to append to current one)
@@ -198,12 +319,9 @@ namespace monitor
else
{
// no more data to read, buffer and string can be send to upper level
- readEvent?.Invoke(message.ToString(), receiveBuffer);
+ readEvent?.Invoke(message.ToString());
message.Clear();
- receiveBuffer = null;
- initialReceiveBufferIndex = 0;
- packetCounter = 0;
}
// Prepare for reading new data
diff --git a/software/monitor/monitor/CommandManager.cs b/software/monitor/monitor/CommandManager.cs
index 803e229..03efac1 100644
--- a/software/monitor/monitor/CommandManager.cs
+++ b/software/monitor/monitor/CommandManager.cs
@@ -33,7 +33,7 @@ namespace monitor
///
/// Callback for sending received data to upper level
///
- public delegate void CommandReceivedEvent(string msg, byte[] buffer);
+ public delegate void CommandReceivedEvent(string msg);
public CommandReceivedEvent commandReceivedEvent = null;
///
@@ -122,7 +122,7 @@ namespace monitor
///
/// Message received from server
/// Raw buffer reived from server
- private void OnMessageReception(string message, byte[] buffer)
+ private void OnMessageReception(string message)
{
waitTimer.Stop(); // Stop timeout stopwatch
@@ -144,7 +144,7 @@ namespace monitor
waitForAcknowledge = false;
- this.commandReceivedEvent?.Invoke(message, buffer);
+ this.commandReceivedEvent?.Invoke(message);
}
}
@@ -158,7 +158,7 @@ namespace monitor
messageReceived = null;
// set buffer and message as null to indicate that no message was received
// and call to OnMessagereception is due to timeout
- OnMessageReception(messageReceived, null);
+ OnMessageReception(messageReceived);
}
///
diff --git a/software/monitor/monitor/DestijlCommandManager.cs b/software/monitor/monitor/DestijlCommandManager.cs
index 2f85469..3257eb8 100644
--- a/software/monitor/monitor/DestijlCommandManager.cs
+++ b/software/monitor/monitor/DestijlCommandManager.cs
@@ -20,6 +20,7 @@
// along with this program. If not, see .
using System;
+using System.Globalization;
namespace monitor
{
@@ -28,47 +29,84 @@ namespace monitor
///
public static 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 ANSWER_ACK = "AACK";
+ public const string ANSWER_NACK = "ANAK";
+ public const string ANSWER_COM_ERROR = "ACER";
+ public const string ANSWER_TIMEOUT = "ATIM";
+ public const string ANSWER_CMD_REJECTED = "ACRJ";
+ public const string MESSAGE = "MSSG";
+ public const string CAMERA_OPEN = "COPN";
+ public const string CAMERA_CLOSE = "CCLS";
+ public const string CAMERA_IMAGE = "CIMG";
+ public const string CAMERA_ARENA_ASK = "CASA";
+ public const string CAMERA_ARENA_INFIRM = "CAIN";
+ public const string CAMERA_ARENA_CONFIRM = "CACO";
+ public const string CAMERA_POSITION_COMPUTE = "CPCO";
+ public const string CAMERA_POSITION_STOP = "CPST";
+ public const string CAMERA_POSITION = "CPOS";
+ public const string ROBOT_COM_OPEN = "ROPN";
+ public const string ROBOT_COM_CLOSE = "RCLS";
+ public const string ROBOT_PING = "RPIN";
+ public const string ROBOT_RESET = "RRST";
+ public const string ROBOT_START_WITHOUT_WD = "RSOW";
+ public const string ROBOT_START_WITH_WD = "RSWW";
+ public const string ROBOT_RELOAD_WD = "RLDW";
+ public const string ROBOT_MOVE = "RMOV";
+ public const string ROBOT_TURN = "RTRN";
+ public const string ROBOT_GO_FORWARD = "RGFW";
+ public const string ROBOT_GO_BACKWARD = "RGBW";
+ public const string ROBOT_GO_LEFT = "RGLF";
+ public const string ROBOT_GO_RIGHT = "RGRI";
+ public const string ROBOT_STOP = "RSTP";
+ public const string ROBOT_POWEROFF = "RPOF";
+ public const string ROBOT_BATTERY_LEVEL = "RBLV";
+ public const string ROBOT_GET_BATTERY = "RGBT";
+ public const string ROBOT_GET_STATE = "RGST";
+ public const string ROBOT_CURRENT_STATE = "RCST";
- public const string DataComOpen = "o";
- public const string DataComClose = "C";
+ public const char SEPARATOR_CHAR = ':';
- 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 HeaderMtsComDmb = "COM";
+ //public const string HeaderMtsDmbOrder = "DMB";
+ //public const string HeaderMtsCamera = "CAM";
+ //public const string HeaderMtsMessage = "MSG";
- 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 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";
}
///
/// Commands used for robot messages
///
- public static 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 static 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";
+ //}
///
/// Specialization class for command manager, which implemnent destijl protocol between monitor and server
@@ -93,7 +131,7 @@ namespace monitor
///
/// Callback for sending received data to application level
///
- public delegate void CommandReceivedEvent(string header, string data, byte[] buffer);
+ public delegate void CommandReceivedEvent(string header, string data);
public CommandReceivedEvent commandReceivedEvent = null;
///
@@ -114,6 +152,34 @@ namespace monitor
CommunicationLostWithServer
}
+ public struct Point {
+ public double x;
+ public double y;
+ }
+
+ public class Position {
+ public int robotID;
+ public double angle;
+ public Point centre;
+ public Point direction;
+
+ public Position() {
+ robotID = 0;
+ angle = 0.0;
+ centre.x = 0.0;
+ centre.y = 0.0;
+ direction.x = 0.0;
+ direction.y = 0.0;
+ }
+
+ public override string ToString() {
+ string s = "ID: " + robotID + ", Angle: " + angle +
+ ", Centre (x: " + centre.x + ", y: " + centre.y +
+ "), Direction (x: " + direction.x + ", y: " + direction.y + ")";
+ return s;
+ }
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -138,10 +204,13 @@ namespace monitor
///
/// String containing received message
/// Raw buffer to be used when data are not in ascii format (image for example)
- private void OnCommandReceived(string msg, byte[] buffer)
+ private void OnCommandReceived(string msg)
{
- // Firstly, split message in (at least) two part : header, and data
- string[] msgs = msg.Split(':');
+ // Firstly, remove ending \n and everything after
+ string[] msgsCarriageReturn = msg.Split('\n');
+
+ // Second, split message in (at least) two part : header, and data
+ string[] msgs = msgsCarriageReturn[0].Split(DestijlCommandList.SEPARATOR_CHAR);
// If it exist at least on element in string array, it should be command header
if (msgs.Length >= 1) receivedHeader = msgs[0];
@@ -152,7 +221,7 @@ namespace monitor
else receivedData = null;
// when split is done, provide data to application
- this.commandReceivedEvent?.Invoke(receivedHeader, receivedData, buffer);
+ this.commandReceivedEvent?.Invoke(receivedHeader, receivedData);
}
///
@@ -193,7 +262,17 @@ namespace monitor
/// Data part of the command
private string CreateCommand(string header, string data)
{
- return header + ":" + data;
+ return header + DestijlCommandList.SEPARATOR_CHAR + data+"\n";
+ }
+
+ ///
+ /// Creates the command to send to server, based on header
+ ///
+ /// The command string
+ /// Header part of the command
+ private string CreateCommand(string header)
+ {
+ return header + DestijlCommandList.SEPARATOR_CHAR+"\n";
}
///
@@ -215,9 +294,9 @@ namespace monitor
if (answer != null)
{
// if command is not acknowledged, return Rejected
- if (answer.ToUpper().Contains(DestijlCommandList.HeaderStmNoAck)) status = CommandStatus.Rejected;
+ if (answer.ToUpper().Contains(DestijlCommandList.ANSWER_NACK)) status = CommandStatus.Rejected;
// if communication is lost with robot, return CommunicationLostWithRobot
- else if (answer.ToUpper().Contains(DestijlCommandList.HeaderStmLostDmb)) status = CommandStatus.CommunicationLostWithRobot;
+ else if (answer.ToUpper().Contains(DestijlCommandList.ANSWER_TIMEOUT)) status = CommandStatus.CommunicationLostWithRobot;
// if answer is empty, communication with robot is lost
else if (answer.Length == 0) status = CommandStatus.CommunicationLostWithServer;
//else status = CommandStatus.InvalidAnswer;
@@ -237,7 +316,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsComDmb, DestijlCommandList.DataComOpen),
+ CreateCommand(DestijlCommandList.ROBOT_COM_OPEN),
out answer,
this.timeout);
@@ -254,7 +333,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsComDmb, DestijlCommandList.DataComClose),
+ CreateCommand(DestijlCommandList.ROBOT_COM_CLOSE),
out answer,
this.timeout);
@@ -271,7 +350,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotPing),
+ CreateCommand(DestijlCommandList.ROBOT_PING),
out answer,
this.timeout);
@@ -288,7 +367,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotReset),
+ CreateCommand(DestijlCommandList.ROBOT_RESET),
out answer,
0);
@@ -305,7 +384,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotStartWithWatchdog),
+ CreateCommand(DestijlCommandList.ROBOT_START_WITH_WD),
out answer,
this.timeout);
@@ -322,7 +401,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotStartWithoutWatchdog),
+ CreateCommand(DestijlCommandList.ROBOT_START_WITHOUT_WD),
out answer,
this.timeout);
@@ -340,7 +419,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotMove + "=" + distance),
+ CreateCommand(DestijlCommandList.ROBOT_MOVE, Convert.ToString(distance)),
out answer,
0);
@@ -358,7 +437,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotTurn + "=" + angle),
+ CreateCommand(DestijlCommandList.ROBOT_TURN, Convert.ToString(angle)),
out answer,
0);
@@ -375,48 +454,13 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotGetBattery),
+ CreateCommand(DestijlCommandList.ROBOT_GET_BATTERY),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
- ///
- /// Request robot firmware version
- ///
- /// Command status (see DecodeStatus)
- /// todo
- 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;
- }
-
///
/// Power off robot
///
@@ -427,7 +471,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsDmbOrder, RobotCommandList.RobotPowerOff),
+ CreateCommand(DestijlCommandList.ROBOT_POWEROFF),
out answer,
0);
@@ -444,7 +488,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamOpen),
+ CreateCommand(DestijlCommandList.CAMERA_OPEN),
out answer,
this.timeout);
@@ -461,7 +505,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamClose),
+ CreateCommand(DestijlCommandList.CAMERA_CLOSE),
out answer,
0);
@@ -478,7 +522,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamAskArena),
+ CreateCommand(DestijlCommandList.CAMERA_ARENA_ASK),
out answer,
0);
@@ -495,7 +539,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamArenaConfirm),
+ CreateCommand(DestijlCommandList.CAMERA_ARENA_CONFIRM),
out answer,
0);
@@ -512,7 +556,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamInfirm),
+ CreateCommand(DestijlCommandList.CAMERA_ARENA_INFIRM),
out answer,
0);
@@ -529,7 +573,7 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamComputePosition),
+ CreateCommand(DestijlCommandList.CAMERA_POSITION_COMPUTE),
out answer,
0);
@@ -546,11 +590,86 @@ namespace monitor
string answer;
localStatus = commandManager.SendCommand(
- CreateCommand(DestijlCommandList.HeaderMtsCamera, DestijlCommandList.DataCamStopComputePosition),
+ CreateCommand(DestijlCommandList.CAMERA_POSITION_STOP),
out answer,
0);
return DecodeStatus(localStatus, answer);
}
+
+ public static Position DecodePosition(string data) {
+ Position pos = new Position();
+
+ pos.robotID = 0;
+ pos.angle = 0.0;
+ pos.centre.x = 0.0;
+ pos.centre.y=0.0;
+ pos.direction.x = 0.0;
+ pos.direction.y = 0.0;
+
+ string[] parts = data.Split(';');
+
+ //for (int i = 0; i < parts.Length; i++) {
+ // Console.WriteLine(parts[i]);
+ //}
+
+ NumberFormatInfo provider = new NumberFormatInfo();
+ provider.NumberDecimalSeparator = ".";
+ provider.NumberGroupSeparator = ",";
+ provider.NumberGroupSizes = new int[] { 3 };
+
+ if (parts.Length == 6) {
+ pos.robotID = Convert.ToInt32(parts[0]);
+
+ try
+ {
+ pos.angle = Convert.ToDouble(parts[1]);
+ } catch (FormatException)
+ {
+ pos.angle = Convert.ToDouble(parts[1],provider);
+ }
+
+ try
+ {
+ pos.centre.x = Convert.ToDouble(parts[2]);
+ } catch (FormatException)
+ {
+ pos.centre.x = Convert.ToDouble(parts[2], provider);
+ }
+
+ try
+ {
+ pos.centre.y = Convert.ToDouble(parts[3]);
+ }
+ catch (FormatException)
+ {
+ pos.centre.y = Convert.ToDouble(parts[3], provider);
+ }
+
+ try
+ {
+ pos.direction.x = Convert.ToDouble(parts[4]);
+ }
+ catch (FormatException)
+ {
+ pos.direction.x = Convert.ToDouble(parts[4], provider);
+ }
+
+ try
+ {
+ pos.direction.y = Convert.ToDouble(parts[5]);
+ }
+ catch (FormatException)
+ {
+ pos.direction.y = Convert.ToDouble(parts[5], provider);
+ }
+
+ } else {
+ // misformatted data, return 0 filled position
+ Console.WriteLine("Misformated position");
+ }
+
+ return pos;
+ }
}
}
diff --git a/software/monitor/monitor/MonitorUI.cs b/software/monitor/monitor/MonitorUI.cs
index d042c15..0835562 100644
--- a/software/monitor/monitor/MonitorUI.cs
+++ b/software/monitor/monitor/MonitorUI.cs
@@ -23,6 +23,7 @@
using System;
using Gtk;
using Gdk;
+using Cairo;
using monitor;
@@ -41,6 +42,11 @@ public partial class MainWindow : Gtk.Window
///
private Pixbuf drawingareaCameraPixbuf;
+ ///
+ /// Position used for displaying position
+ ///
+ private DestijlCommandManager.Position position=new DestijlCommandManager.Position();
+
///
/// List of availble state for the application
///
@@ -200,8 +206,8 @@ public partial class MainWindow : Gtk.Window
a.RetVal = true;
}
- private byte[] imageComplete;
- private byte[] imageInProgress;
+ //private byte[] imageComplete;
+ //private byte[] imageInProgress;
///
/// Callback called when new message is received from server
@@ -209,17 +215,20 @@ public partial class MainWindow : Gtk.Window
/// Header of message
/// Data of message
/// Raw buffer corresponding of received message
- public void OnCommandReceivedEvent(string header, string data, byte[] buffer)
+ public void OnCommandReceivedEvent(string header, string data)
{
- if (buffer==null)
+ if (header == null)
{
// we have lost server
ChangeState(SystemState.NotConnected);
- MessagePopup(MessageType.Error,
+ Gtk.Application.Invoke(delegate
+ {
+ MessagePopup(MessageType.Error,
ButtonsType.Ok, "Server lost",
"Server is down: disconnecting");
- cmdManager.Close();
+ cmdManager.Close();
+ });
}
// if we have received a valid message
@@ -228,75 +237,104 @@ public partial class MainWindow : Gtk.Window
#if DEBUG
// print message content
if (header.Length > 4)
- Console.WriteLine("Bad header(" + buffer.Length + ")");
- else
- Console.WriteLine("Received header (" + header.Length + "): " + header);
+ Console.WriteLine("Bad header(" + header.Length + ")");
+ //else
+ // Console.WriteLine("Received header (" + header.Length + "): " + header);
//if (header.ToUpper() != DestijlCommandList.HeaderStmImage)
//{
// if (data != null) Console.WriteLine("Received data (" + data.Length + "): " + data);
//}
#endif
// Image management
- if (header == DestijlCommandList.HeaderStmImage)
- {
- imageComplete = imageInProgress;
- imageInProgress = buffer;
- }
- else
- {
- if (imageInProgress == null) imageInProgress = buffer;
- else
- {
- Array.Resize(ref imageInProgress, imageInProgress.Length + buffer.Length);
- System.Buffer.BlockCopy(buffer, 0, imageInProgress, imageInProgress.Length - buffer.Length, buffer.Length);
- }
- }
+ //if (header == DestijlCommandList.CAMERA_IMAGE)
+ //{
+ // imageComplete = imageInProgress;
+ // //TODO: Decoder le base64 pour recuperer le JPG
+ // imageInProgress = buffer;
+ //}
+ //else
+ //{
+ // if (imageInProgress == null) imageInProgress = buffer;
+ // else
+ // {
+ // Array.Resize(ref imageInProgress, imageInProgress.Length + buffer.Length);
+ // System.Buffer.BlockCopy(buffer, 0, imageInProgress, imageInProgress.Length - buffer.Length, buffer.Length);
+ // }
+ //}
// depending on message received (based on header)
// launch correponding action
- if (header.ToUpper() == DestijlCommandList.HeaderStmBat)
+ header = header.ToUpper();
+
+ if (header == DestijlCommandList.ROBOT_BATTERY_LEVEL)
{
+ string batLevel = "";
+
switch (data[0])
{
case '2':
- labelBatteryLevel.Text = "High";
+ batLevel = "High";
break;
case '1':
- labelBatteryLevel.Text = "Low";
+ batLevel = "Low";
break;
case '0':
- labelBatteryLevel.Text = "Empty";
+ batLevel = "Empty";
break;
default:
- labelBatteryLevel.Text = "Invalid value";
+ batLevel = "Invalid value";
break;
}
+
+ Gtk.Application.Invoke(delegate
+ {
+ labelBatteryLevel.Text = batLevel;
+ });
}
- else if (header.ToUpper() == DestijlCommandList.HeaderStmImage)
+ else if (header == DestijlCommandList.CAMERA_IMAGE)
{
// if message is an image, convert it to a pixbuf
// that can be displayed
- if (imageComplete != null)
- {
- byte[] image = new byte[imageComplete.Length - 4];
- System.Buffer.BlockCopy(imageComplete, 4, image, 0, image.Length);
+ //if (imageComplete != null)
+ //{
+ //TODO: Decoder le base64 et convertir en JPG
+ byte[] image = Convert.FromBase64String(data);
+ //byte[] image = new byte[imageComplete.Length - 4];
+ //System.Buffer.BlockCopy(imageComplete, 4, image, 0, image.Length);
- imageReceivedCounter++;
- try
+ imageReceivedCounter++;
+
+ try
+ {
+ drawingareaCameraPixbuf = new Pixbuf(image);
+
+ Gtk.Application.Invoke(delegate
{
- drawingareaCameraPixbuf = new Pixbuf(image);
drawingAreaCamera.QueueDraw();
- }
- catch (GLib.GException)
- {
- badImageReceivedCounter++;
-#if DEBUG
- Console.WriteLine("Bad Image: " + badImageReceivedCounter +
- " / " + imageReceivedCounter +
- " (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
-#endif
- }
+ });
}
+ catch (GLib.GException)
+ {
+ badImageReceivedCounter++;
+#if DEBUG
+ Console.WriteLine("Bad Image: " + badImageReceivedCounter +
+ " / " + imageReceivedCounter +
+ " (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
+#endif
+ }
+ //}
+ }
+ else if (header == DestijlCommandList.CAMERA_POSITION)
+ {
+ //Console.WriteLine("Pos data: " + data);
+
+ position = DestijlCommandManager.DecodePosition(data);
+ //Console.WriteLine("decoded position: " + position.ToString());
+
+ Gtk.Application.Invoke(delegate
+ {
+ drawingAreaCamera.QueueDraw();
+ });
}
}
}
@@ -417,10 +455,10 @@ public partial class MainWindow : Gtk.Window
DestijlCommandManager.CommandStatus status;
//if robot is not activated
- if (buttonRobotActivation.Label == "Activate")
+ if (buttonRobotActivation.Label == "Activate")
{
// if a startup with watchdog is requested
- if (radioButtonWithWatchdog.Active)
+ if (radioButtonWithWatchdog.Active)
{
status = cmdManager.RobotStartWithWatchdog();
}
@@ -557,9 +595,7 @@ public partial class MainWindow : Gtk.Window
{
if (cmdManager.CameraClose() != DestijlCommandManager.CommandStatus.Success)
{
- MessagePopup(MessageType.Error,
- ButtonsType.Ok, "Error",
- "Error when closing camera: bad answer for supervisor or timeout");
+ Console.WriteLine("Error when closing camera: bad answer for supervisor or timeout");
}
}
else // camera is not active, switch it on
@@ -569,10 +605,8 @@ public partial class MainWindow : Gtk.Window
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;
+ Console.WriteLine("Error when opening camera: bad answer for supervisor or timeout");
+ //checkButtonCameraOn.Active = false;
}
}
}
@@ -589,20 +623,16 @@ public partial class MainWindow : Gtk.Window
{
if (cmdManager.CameraStopComputePosition() != DestijlCommandManager.CommandStatus.Success)
{
- MessagePopup(MessageType.Error,
- ButtonsType.Ok, "Error",
- "Error when stopping position reception: bad answer for supervisor or timeout");
+ Console.WriteLine("Error when stopping position reception: bad answer for supervisor or timeout");
}
}
else // start reception of robot position
{
if (cmdManager.CameraComputePosition() != DestijlCommandManager.CommandStatus.Success)
{
- MessagePopup(MessageType.Error,
- ButtonsType.Ok, "Error",
- "Error when starting getting robot position: bad answer for supervisor or timeout");
+ Console.WriteLine("Error when starting getting robot position: bad answer for supervisor or timeout");
- checkButtonRobotPosition.Active = false;
+ //checkButtonRobotPosition.Active = false;
}
}
}
@@ -657,6 +687,47 @@ public partial class MainWindow : Gtk.Window
(areaHeight - displayPixbuf.Height) / 2,
displayPixbuf.Width, displayPixbuf.Height,
RgbDither.Normal, 0, 0);
+
+ if (checkButtonRobotPosition.Active) {
+ Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);
+ Cairo.Color textFontColor = new Cairo.Color(0.8, 0, 0);
+
+ cr.SelectFontFace("Cantarell", FontSlant.Normal, FontWeight.Bold);
+ cr.SetSourceColor(textFontColor);
+ cr.SetFontSize(16);
+
+ double space = 0.0;
+ string text = "Direction (" + position.direction.x.ToString("0.##") + " ; " + position.direction.y.ToString("0.##") +")";
+ TextExtents te = cr.TextExtents(text);
+ cr.MoveTo(areaWidth - te.Width-5,
+ areaHeight - te.Height -5);
+ space = te.Height;
+ cr.ShowText(text);
+
+ text = "Centre (" + position.centre.x.ToString("0.##") + " ; " + position.centre.y.ToString("0.##") + ")";
+ te = cr.TextExtents(text);
+ cr.MoveTo(areaWidth - te.Width - 5,
+ areaHeight - te.Height - 5 - space-5);
+ space = space+ te.Height+5;
+ cr.ShowText(text);
+
+ text = "Angle: " + position.angle.ToString("0.##");
+ te = cr.TextExtents(text);
+ cr.MoveTo(areaWidth - te.Width - 5,
+ areaHeight - te.Height - 5 - space - 5);
+ space = space+ te.Height+5;
+ cr.ShowText(text);
+
+ text = "ID: " + position.robotID;
+ te = cr.TextExtents(text);
+ cr.MoveTo(areaWidth - te.Width - 5,
+ areaHeight - te.Height - 5 - space-5);
+
+ cr.ShowText(text);
+
+ ((IDisposable)cr.GetTarget()).Dispose();
+ ((IDisposable)cr).Dispose();
+ }
}
///
diff --git a/software/monitor/monitor/monitor b/software/monitor/monitor/monitor
index d65f28c..fe4e274 100755
Binary files a/software/monitor/monitor/monitor and b/software/monitor/monitor/monitor differ
diff --git a/software/raspberry/superviseur-robot/.dep.inc b/software/raspberry/superviseur-robot/.dep.inc
deleted file mode 100644
index 38ba445..0000000
--- a/software/raspberry/superviseur-robot/.dep.inc
+++ /dev/null
@@ -1,5 +0,0 @@
-# This code depends on make tool being used
-DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES}))
-ifneq (${DEPFILES},)
-include ${DEPFILES}
-endif
diff --git a/software/raspberry/superviseur-robot/.idea/.name b/software/raspberry/superviseur-robot/.idea/.name
deleted file mode 100644
index 02eef87..0000000
--- a/software/raspberry/superviseur-robot/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-ProjDestijl
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/codeStyles/Project.xml b/software/raspberry/superviseur-robot/.idea/codeStyles/Project.xml
deleted file mode 100644
index 30aa626..0000000
--- a/software/raspberry/superviseur-robot/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/misc.xml b/software/raspberry/superviseur-robot/.idea/misc.xml
deleted file mode 100644
index 8822db8..0000000
--- a/software/raspberry/superviseur-robot/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/modules.xml b/software/raspberry/superviseur-robot/.idea/modules.xml
deleted file mode 100644
index 7a92ef3..0000000
--- a/software/raspberry/superviseur-robot/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/superviseur-robot.iml b/software/raspberry/superviseur-robot/.idea/superviseur-robot.iml
deleted file mode 100644
index f08604b..0000000
--- a/software/raspberry/superviseur-robot/.idea/superviseur-robot.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/vcs.xml b/software/raspberry/superviseur-robot/.idea/vcs.xml
deleted file mode 100644
index c2365ab..0000000
--- a/software/raspberry/superviseur-robot/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/workspace.xml b/software/raspberry/superviseur-robot/.idea/workspace.xml
deleted file mode 100644
index 2579f0f..0000000
--- a/software/raspberry/superviseur-robot/.idea/workspace.xml
+++ /dev/null
@@ -1,864 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- DEFINITION_ORDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1539692092358
-
-
- 1539692092358
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- file://$PROJECT_DIR$/examples/src/serverTest.cpp
- 28
-
-
-
- file://$PROJECT_DIR$/superviseur/src/functions.cpp
- 16
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/dist/Debug__Pthread_/GNU-Linux/superviseur-robot b/software/raspberry/superviseur-robot/dist/Debug__Pthread_/GNU-Linux/superviseur-robot
index ac66d60..386cdfa 100755
Binary files a/software/raspberry/superviseur-robot/dist/Debug__Pthread_/GNU-Linux/superviseur-robot and b/software/raspberry/superviseur-robot/dist/Debug__Pthread_/GNU-Linux/superviseur-robot differ
diff --git a/software/raspberry/superviseur-robot/lib/base64/.gitignore b/software/raspberry/superviseur-robot/lib/base64/.gitignore
new file mode 100644
index 0000000..089d9a5
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/.gitignore
@@ -0,0 +1,2 @@
+*.swp
+test-base64
diff --git a/software/raspberry/superviseur-robot/lib/base64/LICENSE b/software/raspberry/superviseur-robot/lib/base64/LICENSE
new file mode 100644
index 0000000..b20a237
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/LICENSE
@@ -0,0 +1,19 @@
+Copyright © 2004-2017 by René Nyffenegger
+
+This source code is provided 'as-is', without any express or implied
+warranty. In no event will the author be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this source code must not be misrepresented; you must not
+ claim that you wrote the original source code. If you use this source code
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original source code.
+
+3. This notice may not be removed or altered from any source distribution.
diff --git a/software/raspberry/superviseur-robot/lib/base64/README.md b/software/raspberry/superviseur-robot/lib/base64/README.md
new file mode 100644
index 0000000..dd4b0f4
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/README.md
@@ -0,0 +1,7 @@
+# base64 (C++)
+
+Base64 encoding and decoding with c++
+
+## See also
+
+https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
diff --git a/software/raspberry/superviseur-robot/lib/base64/base64.cpp b/software/raspberry/superviseur-robot/lib/base64/base64.cpp
new file mode 100644
index 0000000..c670f72
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/base64.cpp
@@ -0,0 +1,122 @@
+/*
+ base64.cpp and base64.h
+
+ base64 encoding and decoding with C++.
+
+ Version: 1.01.00
+
+ Copyright (C) 2004-2017 René Nyffenegger
+
+ This source code is provided 'as-is', without any express or implied
+ warranty. In no event will the author be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this source code must not be misrepresented; you must not
+ claim that you wrote the original source code. If you use this source code
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original source code.
+
+ 3. This notice may not be removed or altered from any source distribution.
+
+ René Nyffenegger rene.nyffenegger@adp-gmbh.ch
+
+*/
+
+#include "base64.h"
+#include
+
+static const std::string base64_chars =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
+
+
+static inline bool is_base64(unsigned char c) {
+ return (isalnum(c) || (c == '+') || (c == '/'));
+}
+
+std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
+ std::string ret;
+ int i = 0;
+ int j = 0;
+ unsigned char char_array_3[3];
+ unsigned char char_array_4[4];
+
+ while (in_len--) {
+ char_array_3[i++] = *(bytes_to_encode++);
+ if (i == 3) {
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+ char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[3] = char_array_3[2] & 0x3f;
+
+ for(i = 0; (i <4) ; i++)
+ ret += base64_chars[char_array_4[i]];
+ i = 0;
+ }
+ }
+
+ if (i)
+ {
+ for(j = i; j < 3; j++)
+ char_array_3[j] = '\0';
+
+ char_array_4[0] = ( char_array_3[0] & 0xfc) >> 2;
+ char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+
+ for (j = 0; (j < i + 1); j++)
+ ret += base64_chars[char_array_4[j]];
+
+ while((i++ < 3))
+ ret += '=';
+
+ }
+
+ return ret;
+
+}
+
+std::string base64_decode(std::string const& encoded_string) {
+ int in_len = encoded_string.size();
+ int i = 0;
+ int j = 0;
+ int in_ = 0;
+ unsigned char char_array_4[4], char_array_3[3];
+ std::string ret;
+
+ while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
+ char_array_4[i++] = encoded_string[in_]; in_++;
+ if (i ==4) {
+ for (i = 0; i <4; i++)
+ char_array_4[i] = base64_chars.find(char_array_4[i]);
+
+ char_array_3[0] = ( char_array_4[0] << 2 ) + ((char_array_4[1] & 0x30) >> 4);
+ char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+ for (i = 0; (i < 3); i++)
+ ret += char_array_3[i];
+ i = 0;
+ }
+ }
+
+ if (i) {
+ for (j = 0; j < i; j++)
+ char_array_4[j] = base64_chars.find(char_array_4[j]);
+
+ char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+ char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+
+ for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
+ }
+
+ return ret;
+}
diff --git a/software/raspberry/superviseur-robot/lib/base64/base64.h b/software/raspberry/superviseur-robot/lib/base64/base64.h
new file mode 100644
index 0000000..dd1134c
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/base64.h
@@ -0,0 +1,14 @@
+//
+// base64 encoding and decoding with C++.
+// Version: 1.01.00
+//
+
+#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
+#define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
+
+#include
+
+std::string base64_encode(unsigned char const* , unsigned int len);
+std::string base64_decode(std::string const& s);
+
+#endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */
diff --git a/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test b/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test
new file mode 100755
index 0000000..1ab5985
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/compile-and-run-test
@@ -0,0 +1,2 @@
+g++ test.cpp base64.cpp -o test-base64
+./test-base64
diff --git a/software/raspberry/superviseur-robot/lib/base64/test.cpp b/software/raspberry/superviseur-robot/lib/base64/test.cpp
new file mode 100644
index 0000000..d04abc3
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/base64/test.cpp
@@ -0,0 +1,56 @@
+#include "base64.h"
+#include
+
+int main() {
+ const std::string s =
+ "René Nyffenegger\n"
+ "http://www.renenyffenegger.ch\n"
+ "passion for data\n";
+
+ std::string encoded = base64_encode(reinterpret_cast(s.c_str()), s.length());
+ std::string decoded = base64_decode(encoded);
+
+ std::cout << "encoded: " << std::endl << encoded << std::endl << std::endl;
+ std::cout << "decoded: " << std::endl << decoded << std::endl;
+
+
+ // Test all possibilites of fill bytes (none, one =, two ==)
+ // References calculated with: https://www.base64encode.org/
+
+ std::string rest0_original = "abc";
+ std::string rest0_reference = "YWJj";
+
+ std::string rest0_encoded = base64_encode(reinterpret_cast(rest0_original.c_str()),
+ rest0_original.length());
+ std::string rest0_decoded = base64_decode(rest0_encoded);
+
+ std::cout << "encoded: " << rest0_encoded << std::endl;
+ std::cout << "reference: " << rest0_reference << std::endl;
+ std::cout << "decoded: " << rest0_decoded << std::endl << std::endl;
+
+
+ std::string rest1_original = "abcd";
+ std::string rest1_reference = "YWJjZA==";
+
+ std::string rest1_encoded = base64_encode(reinterpret_cast(rest1_original.c_str()),
+ rest1_original.length());
+ std::string rest1_decoded = base64_decode(rest1_encoded);
+
+ std::cout << "encoded: " << rest1_encoded << std::endl;
+ std::cout << "reference: " << rest1_reference << std::endl;
+ std::cout << "decoded: " << rest1_decoded << std::endl << std::endl;
+
+
+ std::string rest2_original = "abcde";
+ std::string rest2_reference = "YWJjZGU=";
+
+ std::string rest2_encoded = base64_encode(reinterpret_cast(rest2_original.c_str()),
+ rest2_original.length());
+ std::string rest2_decoded = base64_decode(rest2_encoded);
+
+ std::cout << "encoded: " << rest2_encoded << std::endl;
+ std::cout << "reference: " << rest2_reference << std::endl;
+ std::cout << "decoded: " << rest2_decoded << std::endl << std::endl;
+
+ return 0;
+}
diff --git a/software/raspberry/superviseur-robot/lib/camera.cpp b/software/raspberry/superviseur-robot/lib/camera.cpp
index 4203b61..0c87310 100644
--- a/software/raspberry/superviseur-robot/lib/camera.cpp
+++ b/software/raspberry/superviseur-robot/lib/camera.cpp
@@ -20,8 +20,24 @@
using namespace cv;
-void Camera::setSize(int size) {
+Camera::Camera(int size) {
+ this->SetSize(size);
+ this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3);
+ this->cap.set(CV_CAP_PROP_FRAME_WIDTH,width);
+ this->cap.set(CV_CAP_PROP_FRAME_HEIGHT,height);
+}
+
+bool Camera::Open() {
+ this->cap.open(0);
+}
+
+void Camera::Close() {
+ this->cap.release();
+}
+
+void Camera::SetSize(int size) {
this->size = size;
+
switch (size){
case xs:
this->width = 480;
@@ -46,40 +62,24 @@ void Camera::setSize(int size) {
}
}
-
-int Camera::open_camera() {
- this->cap.open(0);
-}
-
-Camera::Camera(int size) {
- this->setSize(size);
- this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3);
- this->cap.set(CV_CAP_PROP_FRAME_WIDTH,width);
- this->cap.set(CV_CAP_PROP_FRAME_HEIGHT,height);
-}
-
-int Camera::close_camera() {
- cap.release();
- return 0;
-}
-
-Img Camera::grab_image() {
+Img Camera::Grab() {
ImageMat frame;
+
cap >> frame;
Img capture = Img(frame);
+
return capture;
}
-
-bool Camera::isOpen() {
+bool Camera::IsOpen() {
return cap.isOpened();
}
-int Camera::getWidth() const {
+int Camera::GetWidth() const {
return width;
}
-int Camera::getHeight() const {
+int Camera::GetHeight() const {
return height;
}
diff --git a/software/raspberry/superviseur-robot/lib/camera.h b/software/raspberry/superviseur-robot/lib/camera.h
index 3857657..935dc65 100644
--- a/software/raspberry/superviseur-robot/lib/camera.h
+++ b/software/raspberry/superviseur-robot/lib/camera.h
@@ -27,20 +27,18 @@ enum captureSize {xs, sm, md, lg};
class Camera {
public:
-
Camera(int size);
- int open_camera();
+ bool Open();
+ void Close();
+
+ int GetWidth() const;
+ int GetHeight() const;
- int getWidth() const;
+ bool IsOpen();
+ void SetSize(int size);
- int getHeight() const;
-
- bool isOpen();
- void setSize(int size);
-
- int close_camera();
- Img grab_image();
+ Img Grab();
private:
cv::VideoCapture cap;
diff --git a/software/raspberry/superviseur-robot/lib/commonitor.cpp b/software/raspberry/superviseur-robot/lib/commonitor.cpp
index fa3aa36..ea5ffb8 100644
--- a/software/raspberry/superviseur-robot/lib/commonitor.cpp
+++ b/software/raspberry/superviseur-robot/lib/commonitor.cpp
@@ -28,6 +28,8 @@
#include
#include
+#include "base64/base64.h"
+
/*
* @brief Constants used for sending commands to monitor
*/
@@ -41,7 +43,7 @@ const string LABEL_MONITOR_CAMERA_OPEN = "COPN";
const string LABEL_MONITOR_CAMERA_CLOSE = "CCLS";
const string LABEL_MONITOR_CAMERA_IMAGE = "CIMG";
const string LABEL_MONITOR_CAMERA_ARENA_ASK = "CASA";
-const string LABEL_MONITOR_CAMERA_ARENA_INFIRME = "CAIN";
+const string LABEL_MONITOR_CAMERA_ARENA_INFIRM = "CAIN";
const string LABEL_MONITOR_CAMERA_ARENA_CONFIRM = "CACO";
const string LABEL_MONITOR_CAMERA_POSITION_COMPUTE = "CPCO";
const string LABEL_MONITOR_CAMERA_POSITION_STOP = "CPST";
@@ -83,6 +85,12 @@ int ComMonitor::Open(int port) {
throw std::runtime_error{"Can not create socket"};
}
+ int enable = 1;
+ if (setsockopt(socketFD, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
+ cerr<<"setsockopt(SO_REUSEADDR) failed"<c_str() << endl;
write(clientID, str.c_str(), str.length());
- delete(&msg);
-
+ if (!msg->CompareID(MESSAGE_CAM_IMAGE)) {
+ delete(msg);
+ }
+
// Call user method after write
Write_Post();
}
@@ -191,13 +201,17 @@ Message *ComMonitor::Read() {
* @param msg Message to be converted
* @return A string, image of the message
*/
-string ComMonitor::MessageToString(Message &msg) {
+string ComMonitor::MessageToString(Message *msg) {
int id;
string str;
- Message *localMsg = &msg;
+ //Message *localMsg = msg;
Position pos;
- id = msg.GetID();
+ Img *image;
+ Jpg jpeg ;
+ string s;
+
+ id = msg->GetID();
switch (id) {
case MESSAGE_ANSWER_ACK :
@@ -219,17 +233,23 @@ string ComMonitor::MessageToString(Message &msg) {
str.append(LABEL_MONITOR_ANSWER_COM_ERROR);
break;
case MESSAGE_CAM_POSITION:
- pos = ((MessagePosition*) & msg)->GetPosition();
+ pos = ((MessagePosition*) msg)->GetPosition();
str.append(LABEL_MONITOR_CAMERA_POSITION + LABEL_SEPARATOR_CHAR + to_string(pos.robotId) + ";" +
to_string(pos.angle) + ";" + to_string(pos.center.x) + ";" + to_string(pos.center.y) + ";" +
to_string(pos.direction.x) + ";" + to_string(pos.direction.y));
break;
case MESSAGE_CAM_IMAGE:
- str.append(LABEL_MONITOR_CAMERA_IMAGE + LABEL_SEPARATOR_CHAR + ((MessageImg*) & msg)->GetImage()->ToBase64());
+ image=((MessageImg*) msg)->GetImage();
+ jpeg = image->ToJpg();
+
+ cout << "Jpeg size: " << to_string(jpeg.size())<GetLevel()));
+ str.append(LABEL_MONITOR_ROBOT_BATTERY_LEVEL + LABEL_SEPARATOR_CHAR + to_string(((MessageBattery*) msg)->GetLevel()));
break;
case MESSAGE_ROBOT_STATE_BUSY:
str.append(LABEL_MONITOR_ROBOT_CURRENT_STATE + LABEL_SEPARATOR_CHAR + "1");
@@ -238,13 +258,13 @@ string ComMonitor::MessageToString(Message &msg) {
str.append(LABEL_MONITOR_ROBOT_CURRENT_STATE + LABEL_SEPARATOR_CHAR + "0");
break;
case MESSAGE_LOG:
- str.append(LABEL_MONITOR_MESSAGE + LABEL_SEPARATOR_CHAR + ((MessageString*) & msg)->GetString());
+ str.append(LABEL_MONITOR_MESSAGE + LABEL_SEPARATOR_CHAR + ((MessageString*) msg)->GetString());
break;
case MESSAGE_EMPTY:
str.append(""); //empty string
break;
default:
- cerr<<"["<<__PRETTY_FUNCTION__<<"] (from ComMonitor::Write): Invalid message to send ("<ToString()<<")"<arene.height==0) || (this->arene.width==0)) return true;
+bool Arena::IsEmpty() {
+ if ((this->arena.height==0) || (this->arena.width==0)) return true;
else return false;
}
@@ -29,23 +29,19 @@ Img::Img(ImageMat imgMatrice) {
string Img::ToString() {
return "Image size: "+to_string(this->img.cols)+"x"+to_string(this->img.rows)+" (dim="+to_string(this->img.dims)+")";
}
-
-string Img::ToBase64() {
- return "";
-}
Img* Img::Copy() {
return new Img(this->img);
}
-float Img::calculAngle(Position robot) {
+float Img::CalculAngle(Position robot) {
float a = robot.direction.x - robot.center.x;
float b = robot.direction.y - robot.center.y ;
float angle = atan2(b,a);
return angle * 180.f/M_PI;
}
-float Img::calculAngle2(cv::Point2f pt1, cv::Point2f pt2) {
+float Img::CalculAngle2(cv::Point2f pt1, cv::Point2f pt2) {
float a = pt1.x - pt2.x;
float b = pt1.y - pt2.y ;
float angle = atan2(b,a);
@@ -61,7 +57,7 @@ cv::Point2f Img::find_aruco_direction(std::vector aruco) {
return ((aruco[0]+aruco[1])/2);;
}
-std::list Img::search_aruco(Arene monArene) {
+std::list Img::search_aruco(Arena monArene) {
ImageMat imgTraitment;
std::list positionList;
cv::Point2f areneCoor;
@@ -93,12 +89,12 @@ std::list Img::search_aruco(Arene monArene) {
}
#endif // __WITH_ARUCO__
-float Img::euclideanDist(cv::Point2f p, cv::Point2f q) {
+float Img::EuclideanDistance(cv::Point2f p, cv::Point2f q) {
cv::Point diff = p - q;
return cv::sqrt(diff.x*diff.x + diff.y*diff.y);
}
-Jpg Img::toJpg() {
+Jpg Img::ToJpg() {
Jpg imgJpg;
cv::imencode(".jpg",this->img,imgJpg);
return imgJpg;
@@ -112,7 +108,7 @@ Jpg Img::toJpg() {
// return imgBase64;
//}
-std::list Img::search_robot(Arene monArene) {
+std::list Img::SearchRobot(Arena monArene) {
std::list robotsFind;
std::vector > contours;
@@ -121,10 +117,10 @@ std::list Img::search_robot(Arene monArene) {
ImageMat imgTraitment;
- if(monArene.empty())
+ if(monArene.IsEmpty())
imgTraitment=this->img.clone();
else
- imgTraitment = cropArena(monArene);
+ imgTraitment = CropArena(monArene);
cvtColor(imgTraitment,imgTraitment,CV_RGB2GRAY);
threshold(imgTraitment,imgTraitment,128,255,CV_THRESH_BINARY);
@@ -145,14 +141,14 @@ std::list Img::search_robot(Arene monArene) {
c = approx[2];
- if(!monArene.empty()) // ajout de l'offset de l'arène
+ if(!monArene.IsEmpty()) // ajout de l'offset de l'arène
{
- a.x += monArene.arene.x;
- a.y += monArene.arene.y;
- b.x += monArene.arene.x;
- b.y += monArene.arene.y;
- c.x += monArene.arene.x;
- c.y += monArene.arene.y;
+ a.x += monArene.arena.x;
+ a.y += monArene.arena.y;
+ b.x += monArene.arena.x;
+ b.y += monArene.arena.y;
+ c.x += monArene.arena.x;
+ c.y += monArene.arena.y;
}
center.x = (a.x + b.x + c.x)/3;
@@ -160,13 +156,13 @@ std::list Img::search_robot(Arene monArene) {
Position newPos;
newPos.center=center;
- if(euclideanDist(center,b) > euclideanDist(center,a) && euclideanDist(center,b) > euclideanDist(center,c) )
+ if(EuclideanDistance(center,b) > EuclideanDistance(center,a) && EuclideanDistance(center,b) > EuclideanDistance(center,c) )
{
newPos.direction=b;
//line(img,center,b,Scalar(0,125,0),2,8,0);
}
- else if(euclideanDist(center,a) > euclideanDist(center,c))
+ else if(EuclideanDistance(center,a) > EuclideanDistance(center,c))
{
newPos.direction=a;
//line(img,center,a,Scalar(0,125,0),2,8,0);
@@ -177,14 +173,14 @@ std::list Img::search_robot(Arene monArene) {
newPos.direction=c;
//line(img,center,c,Scalar(0,125,0),2,8,0);
}
- newPos.angle=calculAngle(newPos);
+ newPos.angle=CalculAngle(newPos);
robotsFind.push_back(newPos);
}
}
return robotsFind;
}
-Arene Img::search_arena() {
+Arena Img::SearchArena() {
std::vector > contours;
std::vector approx;
std::vector hierarchy;
@@ -200,31 +196,31 @@ Arene Img::search_arena() {
approxPolyDP(ImageMat(contours[i]), approx, cv::arcLength(ImageMat(contours[i]), true)*0.1, true);
if(approx.size()==4 && fabs(cv::contourArea(contours[i])) > 100000)
{
- Arene rectangle;
- rectangle.arene = cv::boundingRect(ImageMat(contours[i]));
+ Arena rectangle;
+ rectangle.arena = cv::boundingRect(ImageMat(contours[i]));
return rectangle;
}
}
- return Arene();
+ return Arena();
}
-int Img::draw_robot(Position robot) {
+int Img::DrawRobot(Position robot) {
cv::arrowedLine(this->img, (cv::Point2f)robot.center, (cv::Point2f)robot.direction, cv::Scalar(0,0,255),3,8,0);
return 0;
}
-int Img::draw_all_robots(std::list robots) {
+int Img::DrawAllRobots(std::list robots) {
for(Position robot : robots){
cv::arrowedLine(this->img, (cv::Point2f)robot.center, (cv::Point2f)robot.direction, cv::Scalar(0,0,255),3,8,0);
}
return robots.size();
}
-int Img::draw_arena(Arene areneToDraw) {
- cv::rectangle(this->img,areneToDraw.arene.tl(),areneToDraw.arene.br(),cv::Scalar(0,0,125),2,8,0);
+int Img::DrawArena(Arena areneToDraw) {
+ cv::rectangle(this->img,areneToDraw.arena.tl(),areneToDraw.arena.br(),cv::Scalar(0,0,125),2,8,0);
return 0;
}
-ImageMat Img::cropArena(Arene arene) {
- return this->img(arene.arene);
+ImageMat Img::CropArena(Arena arene) {
+ return this->img(arene.arena);
}
diff --git a/software/raspberry/superviseur-robot/lib/img.h b/software/raspberry/superviseur-robot/lib/img.h
index dc0efe8..ef30ca0 100644
--- a/software/raspberry/superviseur-robot/lib/img.h
+++ b/software/raspberry/superviseur-robot/lib/img.h
@@ -47,12 +47,12 @@ typedef struct {
int robotId;
} Position;
-class Arene {
+class Arena {
public:
- Arene() {}
+ Arena() {}
- cv::Rect arene;
- bool empty();
+ cv::Rect arena;
+ bool IsEmpty();
};
class Img {
@@ -62,18 +62,17 @@ public:
string ToString();
Img* Copy();
- Jpg toJpg();
- string ToBase64();
- Arene search_arena();
+ Jpg ToJpg();
+ Arena SearchArena();
- int draw_robot(Position robot);
- int draw_all_robots(std::list robots);
- int draw_arena(Arene areneToDraw);
- std::list search_robot(Arene monArene);
+ int DrawRobot(Position robot);
+ int DrawAllRobots(std::list robots);
+ int DrawArena(Arena areneToDraw);
+ std::list SearchRobot(Arena myArena);
#ifdef __WITH_ARUCO__
- list search_aruco(Arene monArene = NULL);
+ list search_aruco(Arena monArene = NULL);
#endif // __WITH_ARUCO__
private:
ImageMat img;
@@ -84,10 +83,10 @@ private:
cv::Point2f find_aruco_direction(std::vector aruco);
#endif // __WITH_ARUCO__
- float calculAngle(Position robots);
- float calculAngle2(cv::Point2f pt1, cv::Point2f pt2);
- float euclideanDist(cv::Point2f p, cv::Point2f q);
- ImageMat cropArena(Arene arene);
+ float CalculAngle(Position robots);
+ float CalculAngle2(cv::Point2f pt1, cv::Point2f pt2);
+ float EuclideanDistance(cv::Point2f p, cv::Point2f q);
+ ImageMat CropArena(Arena arene);
};
#endif //__IMG_H__
diff --git a/software/raspberry/superviseur-robot/lib/messages.cpp b/software/raspberry/superviseur-robot/lib/messages.cpp
index 904bc2f..2a07824 100644
--- a/software/raspberry/superviseur-robot/lib/messages.cpp
+++ b/software/raspberry/superviseur-robot/lib/messages.cpp
@@ -291,7 +291,7 @@ MessageImg::MessageImg() {
* @param image Image
* @throw std::runtime_error if message ID is incompatible with image
*/
-MessageImg::MessageImg(MessageID id, Img* image) {
+MessageImg::MessageImg(MessageID id, Img *image) {
MessageImg::SetID(id);
MessageImg::SetImage(image);
}
@@ -322,7 +322,8 @@ void MessageImg::SetID(MessageID id) {
* @param image Reference to image object
*/
void MessageImg::SetImage(Img* image) {
- this->image = image->Copy();
+ //this->image = image->Copy();
+ this->image = image;
}
/**
@@ -341,7 +342,6 @@ string MessageImg::ToString() {
* @return A message, copy of current
*/
Message* MessageImg::Copy() {
-
return new MessageImg(this->messageID, this->image->Copy());
}
diff --git a/software/raspberry/superviseur-robot/lib/messages.h b/software/raspberry/superviseur-robot/lib/messages.h
index 60328de..3d5ba9c 100644
--- a/software/raspberry/superviseur-robot/lib/messages.h
+++ b/software/raspberry/superviseur-robot/lib/messages.h
@@ -39,14 +39,14 @@ typedef enum {
MESSAGE_ANSWER_ROBOT_UNKNOWN_COMMAND,
MESSAGE_ANSWER_ROBOT_ERROR,
MESSAGE_ANSWER_COM_ERROR,
-
+
+ // Messages specific to server
+ MESSAGE_MONITOR_LOST,
+
// messages for serial communication with robot
MESSAGE_ROBOT_COM_OPEN,
MESSAGE_ROBOT_COM_CLOSE,
- // Messages specific to server
- MESSAGE_MONITOR_LOST,
-
// Messages for camera
MESSAGE_CAM_OPEN,
MESSAGE_CAM_CLOSE,
@@ -373,7 +373,7 @@ public:
* @param image Pointer to image
* @throw std::runtime_error if message ID is incompatible with image message
*/
- MessageImg(MessageID id, Img* image);
+ MessageImg(MessageID id, Img *image);
/**
* Destroy Image message
diff --git a/software/raspberry/superviseur-robot/main.cpp b/software/raspberry/superviseur-robot/main.cpp
index de9d762..fd44ad2 100644
--- a/software/raspberry/superviseur-robot/main.cpp
+++ b/software/raspberry/superviseur-robot/main.cpp
@@ -38,15 +38,16 @@ int main(int argc, char **argv) {
tasks.Init();
- /*if (tasks.AcceptClient()) {
+ if (tasks.AcceptClient()) {
+ cout << "Rock'n'Roll baby, client accepted!"<
+ /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/base64/base64.h
./lib/camera.h
/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/commonitor.h
/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/comrobot.h
@@ -26,6 +27,7 @@
+ /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/base64/base64.cpp
/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/camera.cpp
/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp
/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp
@@ -127,6 +129,16 @@
-
+ -
+
+ -
+
-
-
+ -
+
+ -
+
-
-
+ -
+
+ -
+
-
-
+ -
+
+ -
+
- file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp
- file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/comrobot.h
file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/tasks_pthread.h
file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/commonitor.h
+ file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/img.h
file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/main.cpp
file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/messages.h
file:/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp
diff --git a/software/raspberry/superviseur-robot/tasks_pthread.cpp b/software/raspberry/superviseur-robot/tasks_pthread.cpp
index 5cb92d8..c6a9eee 100644
--- a/software/raspberry/superviseur-robot/tasks_pthread.cpp
+++ b/software/raspberry/superviseur-robot/tasks_pthread.cpp
@@ -52,7 +52,7 @@ void Tasks::Init() {
/* Open com port with STM32 */
cout << "Open serial com (";
- status = robot.Open("/dev/ttyUSB1");
+ status = robot.Open("/dev/ttyUSB0");
cout << status;
cout << ")" << endl;
@@ -72,41 +72,40 @@ void Tasks::Init() {
}
void Tasks::Run() {
- Message *msgRcv;
- Message *msgSend;
- int counter = 3;
-
- // threadServer=new thread((void (*)(void*)) &Tasks::ServerTask,this);
+
+ threadTimer=new thread((void (*)(void*)) &Tasks::TimerTask,this);
+ threadServer=new thread((void (*)(void*)) &Tasks::ServerTask,this);
// threadSendToMon=new thread((void (*)(void*)) &Tasks::SendToMonTask,this);
- // threadTimer=new thread((void (*)(void*)) &Tasks::TimerTask,this);
+
- msgSend = ComRobot::Ping();
- cout << "Send => " << msgSend->ToString() << endl << flush;
- msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
- cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
-
- delete(msgRcv);
-
- msgSend = ComRobot::StartWithoutWD();
- cout << "Send => " << msgSend->ToString() << endl << flush;
- msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
- cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
-
- delete(msgRcv);
-
- msgSend = ComRobot::Move(1000);
- cout << "Send => " << msgSend->ToString() << endl << flush;
- msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
- cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
-
- delete(msgRcv);
-
- msgSend = ComRobot::GetBattery();
- cout << "Send => " << msgSend->ToString() << endl << flush;
- msgRcv = robot.SendCommand(msgSend, MESSAGE_ROBOT_BATTERY_LEVEL, 3);
- cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
-
- delete(msgRcv);
+// msgSend = ComRobot::Ping();
+// cout << "Send => " << msgSend->ToString() << endl << flush;
+// msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
+// cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
+//
+// delete(msgRcv);
+//
+// msgSend = ComRobot::StartWithoutWD();
+// cout << "Send => " << msgSend->ToString() << endl << flush;
+// msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
+// cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
+//
+// delete(msgRcv);
+//
+// msgSend = ComRobot::Move(1000);
+// cout << "Send => " << msgSend->ToString() << endl << flush;
+// msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
+// cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
+//
+// delete(msgRcv);
+//
+// msgSend = ComRobot::GetBattery();
+// cout << "Send => " << msgSend->ToString() << endl << flush;
+// msgRcv = robot.SendCommand(msgSend, MESSAGE_ROBOT_BATTERY_LEVEL, 3);
+// cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
+//
+// delete(msgRcv);
+ cout<<"Tasks launched"<ToString() << endl << flush;
+
+ if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) msgSend = new Message(MESSAGE_ANSWER_ACK);
+ if (msgRcv->CompareID(MESSAGE_ROBOT_COM_CLOSE)) msgSend = new Message(MESSAGE_ANSWER_ACK);
+
+ if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITH_WD)) msgSend = new Message(MESSAGE_ANSWER_ACK);
+ if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITHOUT_WD)) msgSend = new Message(MESSAGE_ANSWER_ACK);
+
+ if (msgRcv->CompareID(MESSAGE_ROBOT_COM_CLOSE)) isActive = false;
+
+ if (msgRcv->CompareID(MESSAGE_CAM_OPEN)) {
+ sendImage=true;
+ msgSend = new Message(MESSAGE_ANSWER_ACK);
+ }
+
+ if (msgRcv->CompareID(MESSAGE_CAM_CLOSE)) {
+ sendImage=false;
+ msgSend = new Message(MESSAGE_ANSWER_ACK);
+ }
+
+ if (msgRcv->CompareID(MESSAGE_CAM_POSITION_COMPUTE_START)) {
+ sendPosition=true;
+ msgSend = new Message(MESSAGE_ANSWER_ACK);
+ }
+
+ if (msgRcv->CompareID(MESSAGE_CAM_POSITION_COMPUTE_STOP)) {
+ sendPosition=false;
+ msgSend = new Message(MESSAGE_ANSWER_ACK);
+ }
+
+ if (msgRcv->CompareID(MESSAGE_ROBOT_BATTERY_GET)) msgSend = new MessageBattery(MESSAGE_ROBOT_BATTERY_LEVEL,BATTERY_FULL);
+
+ if (msgSend != NULL) monitor.Write(msgSend);
+ delete(msgRcv);
}
}
void Tasks::TimerTask(void* arg) {
struct timespec tim, tim2;
+ Message *msgSend;
+ int counter;
+
tim.tv_sec = 0;
- tim.tv_nsec = 100000000;
+ tim.tv_nsec = 50000000; // 50ms (20fps)
cout << "Start " << __PRETTY_FUNCTION__ <=1) {
+ counter=0;
+ Img image=camera.Grab();
+
+ cout << image.ToString()<