diff --git a/software/raspberry/superviseur-robot/.gitignore b/software/raspberry/superviseur-robot/.gitignore
index 8826514..8ba92f7 100644
--- a/software/raspberry/superviseur-robot/.gitignore
+++ b/software/raspberry/superviseur-robot/.gitignore
@@ -1,2 +1,11 @@
build/
src.sav/
+cmake-build-debug/
+futur/
+build/
+CMakeFiles/
+
+Makefile
+*.cmake
+CMakeCache.txt
+
diff --git a/software/raspberry/superviseur-robot/.idea/.name b/software/raspberry/superviseur-robot/.idea/.name
new file mode 100644
index 0000000..02eef87
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/.name
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..30aa626
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/codeStyles/Project.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/misc.xml b/software/raspberry/superviseur-robot/.idea/misc.xml
new file mode 100644
index 0000000..8822db8
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/modules.xml b/software/raspberry/superviseur-robot/.idea/modules.xml
new file mode 100644
index 0000000..7a92ef3
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ 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
new file mode 100644
index 0000000..f08604b
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/superviseur-robot.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/vcs.xml b/software/raspberry/superviseur-robot/.idea/vcs.xml
new file mode 100644
index 0000000..c2365ab
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/.idea/workspace.xml b/software/raspberry/superviseur-robot/.idea/workspace.xml
new file mode 100644
index 0000000..2579f0f
--- /dev/null
+++ b/software/raspberry/superviseur-robot/.idea/workspace.xml
@@ -0,0 +1,864 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/CMakeLists.txt b/software/raspberry/superviseur-robot/CMakeLists.txt
index 4230fc8..c7d8880 100644
--- a/software/raspberry/superviseur-robot/CMakeLists.txt
+++ b/software/raspberry/superviseur-robot/CMakeLists.txt
@@ -1,13 +1,23 @@
-cmake_minimum_required(VERSION 3.9)
-project(ProjDestjil CXX)
+cmake_minimum_required(VERSION 3.6)
+project(ProjDestijl CXX)
set (ProjDestjil_VERSION_MAJOR 1)
set (ProjDestjil_VERSION_MINOR 0)
set (CMAKE_CXX_STANDARD 11)
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/superviseur/bin)
+
+option(BUILD_FOR_XENOMAI "Build for Raspberry" OFF)
+
+set(CMAKE_BUILD_TYPE DEBUG)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy")
+
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed -lalchemy -lcopperplate /usr/xenomai/lib/xenomai/bootstrap.o -Wl,--wrap=main -Wl,--dynamic-list=/usr/xenomai/lib/dynlist.ld -L/usr/xenomai/lib -lmercury -lpthread -lrt")
add_subdirectory("lib")
-add_subdirectory("examples")
-#add_subdirectory("destjil_init")
+#add_subdirectory("examples")
+add_subdirectory("superviseur")
+
diff --git a/software/raspberry/superviseur-robot/ProjDestijl.cbp b/software/raspberry/superviseur-robot/ProjDestijl.cbp
new file mode 100644
index 0000000..7ade805
--- /dev/null
+++ b/software/raspberry/superviseur-robot/ProjDestijl.cbp
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/software/raspberry/superviseur-robot/compile_commands.json b/software/raspberry/superviseur-robot/compile_commands.json
new file mode 100644
index 0000000..e195bcd
--- /dev/null
+++ b/software/raspberry/superviseur-robot/compile_commands.json
@@ -0,0 +1,32 @@
+[
+{
+ "directory": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib",
+ "command": "/usr/bin/g++ -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/. -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -g3 -gdwarf-2 -std=gnu++11 -o CMakeFiles/destijl.dir/src/robot.cpp.o -c /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/robot.cpp",
+ "file": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/robot.cpp"
+},
+{
+ "directory": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib",
+ "command": "/usr/bin/g++ -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/. -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -g3 -gdwarf-2 -std=gnu++11 -o CMakeFiles/destijl.dir/src/monitor.cpp.o -c /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/monitor.cpp",
+ "file": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/monitor.cpp"
+},
+{
+ "directory": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib",
+ "command": "/usr/bin/g++ -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/. -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -g3 -gdwarf-2 -std=gnu++11 -o CMakeFiles/destijl.dir/src/message.cpp.o -c /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/message.cpp",
+ "file": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/message.cpp"
+},
+{
+ "directory": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib",
+ "command": "/usr/bin/g++ -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/. -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -g3 -gdwarf-2 -std=gnu++11 -o CMakeFiles/destijl.dir/src/image.cpp.o -c /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/image.cpp",
+ "file": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/image.cpp"
+},
+{
+ "directory": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur",
+ "command": "/usr/bin/g++ -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/./src -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/../lib -I/usr/xenomai/include -I/usr/xenomai/include/mercury -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -g3 -gdwarf-2 -std=gnu++11 -o CMakeFiles/superviseur.dir/src/main.cpp.o -c /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/src/main.cpp",
+ "file": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/src/main.cpp"
+},
+{
+ "directory": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur",
+ "command": "/usr/bin/g++ -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/./src -I/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/../lib -I/usr/xenomai/include -I/usr/xenomai/include/mercury -I/usr/xenomai/include/mercury -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -g3 -gdwarf-2 -std=gnu++11 -o CMakeFiles/superviseur.dir/src/functions.cpp.o -c /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/src/functions.cpp",
+ "file": "/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/superviseur/src/functions.cpp"
+}
+]
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/destijl_init/Makefile b/software/raspberry/superviseur-robot/destijl_init/Makefile
deleted file mode 100644
index b53f036..0000000
--- a/software/raspberry/superviseur-robot/destijl_init/Makefile
+++ /dev/null
@@ -1,36 +0,0 @@
-
-CC=g++
-CFLAGS=-D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -c -g -D_WITH_TRACE_ -I/usr/xenomai/include/ -I/usr/xenomai/include/mercury -MMD -MP
-LDFLAGS=-D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__MERCURY__ -I/usr/xenomai/include/alchemy -L/usr/xenomai/lib -lalchemy -lcopperplate -lmercury -L/opt/vc/lib -I/usr/local/include -lopencv_highgui -lopencv_core -lopencv_imgproc -Wl,--no-as-needed -lalchemy -lcopperplate /usr/xenomai/lib/xenomai/bootstrap.o -Wl,--wrap=main -Wl,--dynamic-list=/usr/xenomai/lib/dynlist.ld -L/usr/xenomai/lib -lmercury -lpthread -lrt -Wl,-rpath /usr/xenomai/lib -lopencv_highgui -lopencv_core -lopencv_imgcodecs -lraspicam_cv -lopencv_imgproc -lpthread
-EXEC=superviseur
-SRC= $(wildcard *.cpp ./src/*.cpp ./../src/*.cpp)
-OBJ= $(SRC:.cpp=.o)
-
-
-all: $(EXEC)
-
-
-$(EXEC): $(OBJ)
- @$(CC) -o $@ $^ $(LDFLAGS)
-
-
-main.o: main.cpp
-
-
-%.o: %.cpp
- @$(CC) -o $@ -c $< $(CFLAGS)
-
-
-.PHONY: clean mrproper
-
-
-clean:
- @rm -rf *.o
- @rm -rf *.d
- @rm -rf ./src/*.o
- @rm -rf ./src/*.d
- @rm -rf ./../src/*o
- @rm -rf ./../src/*.d
-
-mrproper: clean
- @rm -rf $(EXEC)
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/examples/CMakeLists.txt b/software/raspberry/superviseur-robot/examples/CMakeLists.txt
index 18f5ffb..619a497 100644
--- a/software/raspberry/superviseur-robot/examples/CMakeLists.txt
+++ b/software/raspberry/superviseur-robot/examples/CMakeLists.txt
@@ -4,8 +4,8 @@ set(serialTest_FILES ./src/serialTest.cpp)
set(serverTest_FILES ./src/serverTest.cpp)
include_directories(./src ../lib)
-add_executable(serialTest ${serialTest_FILES})
-target_link_libraries(serialTest destjil)
+add_executable(serialtest ${serialTest_FILES})
+target_link_libraries(serialtest destijl)
-add_executable(serverTest ${serverTest_FILES})
-target_link_libraries(serverTest destjil)
+add_executable(servertest ${serverTest_FILES})
+target_link_libraries(servertest destijl)
diff --git a/software/raspberry/superviseur-robot/lib/.gitignore b/software/raspberry/superviseur-robot/lib/.gitignore
index dce1580..25793f0 100644
--- a/software/raspberry/superviseur-robot/lib/.gitignore
+++ b/software/raspberry/superviseur-robot/lib/.gitignore
@@ -1 +1,6 @@
+CMakeFiles/
+
libdestjil.a
+Makefile
+*.cmake
+
diff --git a/software/raspberry/superviseur-robot/lib/CMakeLists.txt b/software/raspberry/superviseur-robot/lib/CMakeLists.txt
index 3e891f9..318684e 100644
--- a/software/raspberry/superviseur-robot/lib/CMakeLists.txt
+++ b/software/raspberry/superviseur-robot/lib/CMakeLists.txt
@@ -1,5 +1,5 @@
-set(LIB_FILES ./src/Serial.cpp ./src/Robot.cpp ./src/TcpServer.cpp)
+set(LIB_FILES ./src/robot.cpp ./src/monitor.cpp ./src/message.cpp ./src/image.cpp)
include_directories("./")
-add_library(destjil STATIC ${LIB_FILES})
+add_library(destijl STATIC ${LIB_FILES})
diff --git a/software/raspberry/superviseur-robot/lib/Robot.h b/software/raspberry/superviseur-robot/lib/Robot.h
deleted file mode 100644
index b3f9765..0000000
--- a/software/raspberry/superviseur-robot/lib/Robot.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018 INSA - GEI, Toulouse, France.
- * All rights reserved. This program and the accompanying materials
- * are made available "AS IS", without any warranty of any kind.
- *
- * INSA assumes no responsibility for errors or omissions in the
- * software or documentation available.
- *
- * Contributors:
- * Lucien Senaneuch - Initial API and implementation
- * Sebastien DI MERCURIO - Maintainer since Octobre 2018
- *******************************************************************************/
-/**
- * \file robot.h
- * \author L.Senaneuch
- * \version 1.0
- * \date 06/06/2017
- * \brief Fonction permettant la communication avec le robot.
- *
- * \details Ce fichier regroupe des fonctions facilitant la communication avec le robot en utilisant le port serie USART
- */
-
-#ifndef __ROBOT_H__
-#define __ROBOT_H__
-
-#include
-#include
-#include
-
-using namespace std;
-
-#define REJECTED_COMMAND -3
-#define INVALID_COMMAND -4
-#define TIMEOUT_COMMAND -5
-#define INVALID_ANSWER -6
-
-#define BATTERY_FULL 2
-#define BATTERY_LOW 1
-#define BATTERY_EMPTY 0
-
-class Robot : public Serial {
- public:
- Robot();
- virtual ~Robot();
-
- char Open();
- char Open(const char *path);
- char Close();
-
- int GetLastCommandStatus();
-
- void Ping();
- void Reset();
-
- void StartWithoutWatchdog();
- void StartWithWatchdog();
- void ResetWatchdog();
-
- void Move(int distance);
- void Turn(int angle);
-
- void PowerOff();
-
- char GetBatteryLevel();
- string GetVersion();
- bool IsBusy();
-
- // Ces deux methodes virtuelles sont a redefinir (surcharger) dans une classe qui etends la classe Robot
- // Servez vous en pour faire une action avant (prologue) ou apres (epilogue) une commande au robot
- virtual void CommunicationProlog();
- virtual void CommunicationEpilog();
-
- static const string InvalidAnswerException;
- private:
-
- int lastCommandStatus;
-
- char SendCommand(string cmd, string *ans);
- string AddChecksum(string cmd);
- bool ValidateChecksum(string *answerWithoutChecksum, string answer);
- void CheckAnswer(string ans);
-};
-
-#endif //__ROBOT_H__
diff --git a/software/raspberry/superviseur-robot/lib/Serial.h b/software/raspberry/superviseur-robot/lib/Serial.h
deleted file mode 100644
index c2a1b11..0000000
--- a/software/raspberry/superviseur-robot/lib/Serial.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Serial.h
- *
- * Created on: 12 oct. 2018
- * Author: dimercur
- */
-
-#ifndef SERIAL_H_
-#define SERIAL_H_
-
-#include
-#include
-#include
-
-using namespace std;
-
-#define SUCCESS 0
-#define INVALID_COMMUNICATION_PORT -1
-#define COMMUNICATION_PORT_ALREADY_OPENED -2
-
-#define DEFAULT_SERIAL_PORT "/dev/ttyS0"
-#define DEFAULT_BAUDRATE 9600
-
-class Serial {
- public:
- static const string TimeoutException;
- static const string IOErrorException;
- static const string BufferOverflowException;
-
- Serial();
- virtual ~Serial();
-
- char Open(void);
- char Open(int baudrate);
- char Open(const char *path, int baudrate);
- char Close(void);
-
- bool IsOpen();
- ssize_t Send(string mes);
- string Receive(int size);
- string Receive(vector endingChars, int maxLength);
-
- private:
- int serialPortDescriptor;
- int SetBaudrate(int baudrate);
- char GetChar(); // read 1 char
-};
-
-#endif /* SERIAL_H_ */
diff --git a/software/raspberry/superviseur-robot/lib/TcpServer.h b/software/raspberry/superviseur-robot/lib/TcpServer.h
deleted file mode 100644
index 450705b..0000000
--- a/software/raspberry/superviseur-robot/lib/TcpServer.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Created by senaneuc on 12/06/18.
-//
-
-#ifndef TCP_SERVER_H_
-#define TCP_SERVER_H_
-
-#define NB_CONNECTION_MAX 5
-
-#include
-#include
-
-using namespace std;
-
-class TcpServer {
-public:
- TcpServer();
- virtual ~TcpServer();
-
- int Listen (int port);
- int AcceptClient();
- int Send(int clien_fd, string mes);
- int Broadcast(string mes);
- string Receive(int client_fd, int size);
-
- const vector &getSocketClients() const;
-
- void SetSocketClients(const vector &socketClients);
-
-private:
- vector socketClients;
- int socketFD;
-};
-
-#endif /* TCP_SERVER_H_ */
diff --git a/software/raspberry/superviseur-robot/lib/definitions.h b/software/raspberry/superviseur-robot/lib/definitions.h
index 9d0f08d..b016653 100644
--- a/software/raspberry/superviseur-robot/lib/definitions.h
+++ b/software/raspberry/superviseur-robot/lib/definitions.h
@@ -14,6 +14,30 @@
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
+#define OPEN_COM_DMB 'o'
+#define CLOSE_COM_DMB 'C'
+
+#define DMB_PING 'p'
+#define DMB_IDLE 'r'
+#define DMB_START_WITHOUT_WD 'u'
+#define DMB_START_WITH_WD 'W'
+#define DMB_RELOAD_WD 'w'
+#define DMB_GET_VBAT 'v'
+#define DMB_IS_BUSY 'b'
+#define DMB_MOVE 'M'
+#define DMB_TURN 'T'
+#define DMB_GO_FORWARD 'F'
+#define DMB_GO_BACK 'B'
+#define DMB_GO_LEFT 'L'
+#define DMB_GO_RIGHT 'R'
+#define DMB_STOP_MOVE 'S'
+
+#define ROBOT_TIMED_OUT -3
+#define ROBOT_UKNOWN_CMD -2
+#define ROBOT_ERROR -1
+#define ROBOT_CHECKSUM -4
+#define ROBOT_OK 0
+
#define CAM_OPEN 'A'
#define CAM_CLOSE 'I'
#define CAM_ASK_ARENA 'y'
diff --git a/software/raspberry/superviseur-robot/lib/image.h b/software/raspberry/superviseur-robot/lib/image.h
index bf16031..0cc8466 100644
--- a/software/raspberry/superviseur-robot/lib/image.h
+++ b/software/raspberry/superviseur-robot/lib/image.h
@@ -14,6 +14,8 @@
#ifndef IMAGERIE_H
#define IMAGERIE_H
+#define __STUB__
+
#ifndef __STUB__
#include
#else
diff --git a/software/raspberry/superviseur-robot/lib/monitor.h b/software/raspberry/superviseur-robot/lib/monitor.h
index c06572d..ea128a4 100644
--- a/software/raspberry/superviseur-robot/lib/monitor.h
+++ b/software/raspberry/superviseur-robot/lib/monitor.h
@@ -62,7 +62,7 @@ typedef struct {
* \param file chemin du fichier de l'interface (défaut ./interface.js)
* \return retourne 0 si le process a été lancé et -1 sinon.
*/
-int run_nodejs(const char * path = DEFAULT_NODEJS_PATH, char * file = DEFAULT_INTERFACE_FILE);
+int run_nodejs(const char *path = (const char*)DEFAULT_NODEJS_PATH, char *file = (const char*)DEFAULT_INTERFACE_FILE);
/**
* \brief Tue le process exécutant nodejs.
diff --git a/software/raspberry/superviseur-robot/lib/robot.h b/software/raspberry/superviseur-robot/lib/robot.h
new file mode 100644
index 0000000..e095f27
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/robot.h
@@ -0,0 +1,64 @@
+/**
+ * \file robot.h
+ * \author L.Senaneuch
+ * \version 1.0
+ * \date 06/06/2017
+ * \brief Fonction permettant la communication avec le robot.
+ *
+ * \details Ce fichier regroupe des fonctions facilitant la communication avec le robot en utilisant le port serie USART
+ */
+
+
+#ifndef DUMBERC_SERIAL_H_H
+#define DUMBERC_SERIAL_H_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "definitions.h"
+
+
+#define serialPort "/dev/ttyS0"
+
+typedef struct
+ {
+ char header[4];
+ char data[20];
+ } MessageToRobot;
+
+ /**
+ * \brief Ouvre la communication avec le robot.
+ * \details Ouvre le serial port passé en paramétre. Par defaut cette fonction ouvre le port ttySO connecté au module xbee.
+ *
+ * \param *path chaine de caractère indiquant le path du port serie à ouvrir.
+ * \return Return -1 si l'ouverture c'est mal passé et 0 si le port est ouvert.
+ */
+int open_communication_robot(const char * path=serialPort);
+
+ /**
+ * \brief Ferme la communication avec le robot.
+ * \details Ferme le descripteur de fichier du port serie contrôlant le robot.
+ *
+ * \param void aucun
+ * \return Retourne -1 en cas d'erreur ou 0 en cas de fermeture effectué
+ */
+int close_communication_robot(void);
+
+ /**
+ * \brief Envoi une commande au robot et attends sa réponse.
+ * \details Envoi une commande au robot en ajoutant le checksum et lis la réponse du robot en verifiant le checksum.
+ Le premier paramétre \a cmd correspond au type de commande ex : PING, SETMOVE ...
+ Le second paramétre \a *arg correspond aux arguments à la commande ex : SETMOVE, "100"
+ La fonction retourne un code confirmation transmise par le robot (ROBOT_CHEKSUM, ROBOT_ERROR, ROBOT_TIMED_OUT, ROBOT_OK, ROBOT_UKNOW_CMD)
+ *
+ * \param cmd Entête de la commande
+ * \param *arg Argument de la commande
+ * \return retourne un code confirmation.
+ */
+int send_command_to_robot(char cmd, const char * arg=NULL);
+
+
+#endif //DUMBERC_SERIAL_H_H
diff --git a/software/raspberry/superviseur-robot/lib/src/Robot.cpp b/software/raspberry/superviseur-robot/lib/src/Robot.cpp
deleted file mode 100644
index c1abdab..0000000
--- a/software/raspberry/superviseur-robot/lib/src/Robot.cpp
+++ /dev/null
@@ -1,349 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018 INSA - GEI, Toulouse, France.
- * All rights reserved. This program and the accompanying materials
- * are made available "AS IS", without any warranty of any kind.
- *
- * INSA assumes no responsibility for errors or omissions in the
- * software or documentation available.
- *
- * Contributors:
- * Lucien Senaneuch - Initial API and implementation
- * Sebastien DI MERCURIO - Maintainer since Octobre 2018
- *******************************************************************************/
-
-/**
- * \file robot.cpp
- * \author L.Senaneuch
- * \version 1.0
- * \date 06/06/2017
- * \brief Fonction permettant la communication avec le robot.
- *
- * \details Ce fichier regroupe des fonctions facilitant la communication avec le robot en utilisant le port serie USART
- */
-
-#include "Robot.h"
-
-#include
-#include
-#include
-
-#include
-#include "definitions.h"
-
-using namespace std;
-
-#define ROBOT_CMD_ENDING_CHAR '\r'
-
-#define ROBOT_CMD_PING 'p'
-#define ROBOT_CMD_RESET 'r'
-#define ROBOT_CMD_START_WITHOUT_WD 'u'
-#define ROBOT_CMD_START_WITH_WD 'W'
-#define ROBOT_CMD_RELOAD_WD 'w'
-#define ROBOT_CMD_GET_VBAT 'v'
-#define ROBOT_CMD_IS_BUSY 'b'
-#define ROBOT_CMD_MOVE 'M'
-#define ROBOT_CMD_TURN 'T'
-#define ROBOT_CMD_GET_VERSION 'V'
-#define ROBOT_CMD_POWER_OFF 'z'
-
-#define ROBOT_CMD_OK_ANS "O"
-#define ROBOT_CMD_ERR_ANS "E"
-#define ROBOT_CMD_UNKNOW_ANS "C"
-
-const string Robot::InvalidAnswerException = "Invalid answer exception";
-
-Robot::Robot() {
-
-}
-
-Robot::~Robot() {
- this->Close();
-}
-
-char Robot::Open() {
- return Serial::Open(DEFAULT_SERIAL_PORT,9600);
-}
-
-char Robot::Open(const char *path) {
- return Serial::Open(path,9600);
-}
-
-char Robot::Close() {
- return Serial::Close();
-}
-
-int Robot::GetLastCommandStatus() {
- return this->lastCommandStatus;
-}
-
-void Robot::Ping() {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_PING), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::Reset() {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_RESET), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::StartWithoutWatchdog() {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_START_WITHOUT_WD), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::StartWithWatchdog() {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_START_WITH_WD), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::ResetWatchdog() {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_RELOAD_WD), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::Move(int distance) {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_MOVE) + "="+to_string(distance), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::Turn(int angle) {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_TURN) + "="+to_string(angle), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-void Robot::PowerOff() {
-#ifndef __STUB__
- string ans;
- SendCommand(string(1,ROBOT_CMD_POWER_OFF), &ans);
-
- CheckAnswer(ans);
-#else
- return SUCCESS;
-#endif /* __STUB__ */
-}
-
-char Robot::GetBatteryLevel() {
-#ifndef __STUB__
- string ans;
-
- SendCommand(string(1,ROBOT_CMD_GET_VBAT), &ans);
- lastCommandStatus=SUCCESS;
-
- if (ans.length()==1) {
- if ((ans[0] != '2') && (ans[0] != '1') && (ans[0] != '0')) {
- lastCommandStatus=INVALID_ANSWER;
- throw (InvalidAnswerException + " raised in Robot::GetBatteryLevel. Invalid battery value (" + ans[0] +")\n");
- }
- } else {
- lastCommandStatus=INVALID_ANSWER;
- throw (InvalidAnswerException + " raised in Robot::GetBatteryLevel. Invalid answer length (" + to_string(ans.length())+")\n");
- }
-
- return ans[0];
-#else
- return BATTERY_FULL;
-#endif /* __STUB__ */
-}
-
-string Robot::GetVersion() {
-#ifndef __STUB__
- string ans;
-
- SendCommand(string(1,ROBOT_CMD_GET_VERSION), &ans);
- lastCommandStatus=SUCCESS;
-
- if (ans.find("version")== string::npos) {
- lastCommandStatus=INVALID_ANSWER;
- throw (InvalidAnswerException + " raised in Robot::GetVersion. Invalid version (" + ans +")\n");
- }
-
- return ans;
-#else
- return "1.3";
-#endif /* __STUB__ */
-}
-
-bool Robot::IsBusy() {
-#ifndef __STUB__
- string ans;
-
- SendCommand(string(1,ROBOT_CMD_IS_BUSY), &ans);
- lastCommandStatus=SUCCESS;
-
- if (ans.length()!=1) {
- lastCommandStatus=INVALID_ANSWER;
- throw (InvalidAnswerException + " raised in Robot::GetBatteryLevel. Invalid answer length (" + to_string(ans.length())+")\n");
- }
-
- if (ans[0]=='1')
- return true;
- else if (ans[0]=='0')
- return false;
- else {
- lastCommandStatus=INVALID_ANSWER;
- throw (InvalidAnswerException + " raised in Robot::IsBusy. Invalid value (" + ans[0] +")\n");
- }
-#else
- return false;
-#endif /* __STUB__ */
-}
-
-void Robot::CommunicationProlog() {}
-void Robot::CommunicationEpilog() {}
-
-/****************************/
-/* PRIVATE */
-/****************************/
-
-char Robot::SendCommand(string cmd, string *ans) {
- string commandString;
- commandString = this->AddChecksum(cmd);
-
- this->CommunicationProlog(); // action avant le debut de la commande
-
- ssize_t status = Send(commandString);
-
- if (status == (ssize_t)commandString.length()) {
- // Recuperation de la reponse
- string commandResponse;
- vector endingChars;
-
- endingChars.push_back('\r');
- try {
- commandResponse = Serial::Receive(endingChars,30);
- } catch (string e) {
- if (e.find("Timeout")!= string::npos)
- lastCommandStatus= TIMEOUT_COMMAND;
- else
- lastCommandStatus=INVALID_ANSWER;
-
- if (lastCommandStatus == TIMEOUT_COMMAND)
- throw (Serial::TimeoutException + " raised in Robot::SendCommand. Timeout while receiving answer from robot.\n");
- else
- throw (e + " raised in Robot::SendCommand.\n");
- }
-
- this->CommunicationEpilog(); // Action a faire apres la commande
-
- if (ValidateChecksum(&commandResponse, commandResponse)) {
- ans->assign(commandResponse);
- } else {
- lastCommandStatus = INVALID_ANSWER;
- throw InvalidAnswerException;
- }
-
- lastCommandStatus=SUCCESS;
- } else {
- lastCommandStatus=INVALID_COMMUNICATION_PORT;
-
- throw IOErrorException;
- }
-
- return lastCommandStatus;
-}
-
-void Robot::CheckAnswer(string ans) {
-
- if (ans.length()==1)
- {
- switch (ans.at(0)) {
- case 'o':
- case 'O':
- lastCommandStatus=SUCCESS;
- break;
- case 'e':
- case 'E':
- lastCommandStatus=REJECTED_COMMAND;
- break;
- case 'c':
- case 'C':
- lastCommandStatus=INVALID_COMMAND;
- break;
- default:
- lastCommandStatus = INVALID_ANSWER;
- throw InvalidAnswerException;
- }
- } else {
- lastCommandStatus = INVALID_ANSWER;
- throw InvalidAnswerException;
- }
-}
-
-string Robot::AddChecksum(string cmd) {
- string commandWithChecksum(cmd);
- char checksum=0;
-
- commandWithChecksum.resize(cmd.length()+2, ' ');
-
- for (size_t i=0; iassign(localAnswer);
- return status;
-}
diff --git a/software/raspberry/superviseur-robot/lib/src/Serial.cpp b/software/raspberry/superviseur-robot/lib/src/Serial.cpp
deleted file mode 100644
index f9d1486..0000000
--- a/software/raspberry/superviseur-robot/lib/src/Serial.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018 INSA - GEI, Toulouse, France.
- * All rights reserved. This program and the accompanying materials
- * are made available "AS IS", without any warranty of any kind.
- *
- * INSA assumes no responsibility for errors or omissions in the
- * software or documentation available.
- *
- * Part of code Copyright ST Microelectronics.
- *
- * Contributors:
- * Lucien Senaneuch - Initial API and implementation
- * Sebastien DI MERCURIO - Maintainer since Octobre 2018
- *******************************************************************************/
-
-#include
-#include
-#include
-#include
-
-#include
-
-#include
-
-const string Serial::TimeoutException = "Timeout exception";
-const string Serial::IOErrorException = "IO error exception";
-const string Serial::BufferOverflowException = "Buffer overflow exception";
-
-Serial::Serial() {
- this->serialPortDescriptor=-1;
-}
-
-Serial::~Serial() {
- this->Close();
-}
-
-char Serial::Open(void) {
- return this->Open(DEFAULT_SERIAL_PORT, DEFAULT_BAUDRATE);
-}
-
-char Serial::Open(int baudrate) {
- return this->Open(DEFAULT_SERIAL_PORT, baudrate);
-}
-
-char Serial::Open(const char *path, int baudrate) {
-#ifndef __STUB__
- struct termios options;
-
- if (this->IsOpen() == true) return COMMUNICATION_PORT_ALREADY_OPENED;
-
- this->serialPortDescriptor = open(path, O_RDWR | O_NOCTTY | O_NDELAY);
-
- if(this->serialPortDescriptor >= 0) {
- fcntl(this->serialPortDescriptor, F_SETFL, 0);
- tcgetattr(this->serialPortDescriptor, &options);
- options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
- cfsetospeed (&options, this->SetBaudrate(baudrate));
- cfsetispeed (&options, this->SetBaudrate(baudrate));
- options.c_cc[VMIN]=0;
- options.c_cc[VTIME]=10;
- tcsetattr(this->serialPortDescriptor, TCSANOW, &options);
-
- return SUCCESS;
- }
- else {
- std::cerr << "[Robot::Open] Can't open port " << path;
- return INVALID_COMMUNICATION_PORT;
- }
-#else
- return SUCCESS;
-#endif
-}
-
-char Serial::Close(void) {
-#ifndef __STUB__
- if (this->serialPortDescriptor<0) {
- if (close(this->serialPortDescriptor) == 0)
- return SUCCESS;
- else return INVALID_COMMUNICATION_PORT;
- } else return SUCCESS;
-#else
- return SUCCESS;
-#endif
-}
-
-bool Serial::IsOpen() {
- if(this->serialPortDescriptor >= 0)
- return true;
- else
- return false;
-}
-
-ssize_t Serial::Send(string mes) {
- ssize_t n;
-
- n=write(this->serialPortDescriptor, (void*)mes.c_str(), mes.length());
-
- if (n< (ssize_t)mes.length())
- throw (IOErrorException + " raised in Serial::Send. Requested to send " + to_string(mes.length()) + " characters, sent only " + to_string(n) +"\n");
- else
- return n;
-}
-
-string Serial::Receive(int size) {
- string mes;
-
- while(mes.length() < (unsigned int)size){
- mes += this->GetChar();
- }
-
- return mes;
-}
-
-string Serial::Receive(vector endingChars,int maxLength) {
- string mes;
- char c;
-
- bool characterFound = false;
-
- do {
- c= GetChar();
-
- if (std::find(endingChars.begin(), endingChars.end(), c)!=endingChars.end()) //recherche du caractere dans la liste des caractere de fin
- characterFound=true;
- else {
- mes += c;
- }
- } while ((mes.length()<(unsigned int)maxLength) && (characterFound==false));
-
- if (mes.length()>=(unsigned int)maxLength) {
- throw (BufferOverflowException + " raised in Serial::Receive. Received data exceed " + to_string(maxLength) + "chars\n");
- }
-
- return mes;
-}
-
-int Serial::SetBaudrate(int baudrate) {
- switch(baudrate){
- case 4800:
- return baudrate = B4800;
- case 9600:
- return baudrate = B9600;
- case 38400:
- return baudrate = B38400;
- case 57600:
- return baudrate = B57600;
- case 115200:
- return baudrate = B115200;
- default:
- std::cerr << "Baudrate not supported" << std::endl;
- return -1;
- }
-}
-
-char Serial::GetChar() {
- char c;
-
- if (read(this->serialPortDescriptor, &c, 1) > 0)
- return c;
- else
- throw (TimeoutException + " raised in Serial::GetChar\n");
-}
-
-
diff --git a/software/raspberry/superviseur-robot/lib/src/TcpServer.cpp b/software/raspberry/superviseur-robot/lib/src/TcpServer.cpp
deleted file mode 100644
index 7fe55d4..0000000
--- a/software/raspberry/superviseur-robot/lib/src/TcpServer.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018 INSA - GEI, Toulouse, France.
- * All rights reserved. This program and the accompanying materials
- * are made available "AS IS", without any warranty of any kind.
- *
- * INSA assumes no responsibility for errors or omissions in the
- * software or documentation available.
- *
- * Part of code Copyright ST Microelectronics.
- *
- * Contributors:
- * Lucien Senaneuch - Initial API and implementation
- * Sebastien DI MERCURIO - Maintainer since Octobre 2018
- *******************************************************************************/
-
-
-#include "TcpServer.h"
-#include
-#include
-#include
-
-TcpServer::TcpServer() {
- this->socketFD = -1;
- this->socketClients.clear();
-}
-
-int TcpServer::Listen (int port) {
- struct sockaddr_in server;
-
- this->socketFD = socket(AF_INET, SOCK_STREAM, 0);
- if(this->socketFD < 0){
- throw invalid_argument("Can not create socket");
- }
-
- server.sin_addr.s_addr = INADDR_ANY;
- server.sin_family = AF_INET;
- server.sin_port = htons(port);
-
- if(bind(this->socketFD, (struct sockaddr *) &server, sizeof(server)) < 0) {
- throw invalid_argument("Can not bind socket");
- }
-
- listen(this->socketFD , NB_CONNECTION_MAX);
-
- return this->socketFD;
-}
-
-int TcpServer::AcceptClient() {
- struct sockaddr_in client;
- int c = sizeof(struct sockaddr_in);
-
- int fd = accept(this->socketFD,(struct sockaddr *) &client, (socklen_t*)&c);
-
- if (fd >=0 )
- this->socketClients.push_back(fd);
- else throw invalid_argument("Accept failed in TcpServer::AcceptClient");
-
- return fd;
-}
-
-int TcpServer::Send(int client, string mes) {
- return write(client, mes.c_str(), mes.size());
-}
-
-string TcpServer::Receive(int client_fd, int size){
- char tab[size];
-
- if(recv(client_fd,tab,size,0) >0) {
- tab[size] = 0;
- return string(tab);
- } else
- return string();
-}
-
-int TcpServer::Broadcast(string mes) {
- for (int socket : this->socketClients) {
- int err = write(socket, mes.c_str(), mes.size());
- }
-
- return 0;
-}
-
-const vector &TcpServer::getSocketClients() const {
- return socketClients;
-}
-
-void TcpServer::SetSocketClients(const std::vector &socketClients) {
- this->socketClients = socketClients;
-}
-
-TcpServer::~TcpServer() {
- close(this->socketFD);
-}
diff --git a/software/raspberry/superviseur-robot/lib/src/message.cpp b/software/raspberry/superviseur-robot/lib/src/message.cpp
index 62f350f..717250c 100644
--- a/software/raspberry/superviseur-robot/lib/src/message.cpp
+++ b/software/raspberry/superviseur-robot/lib/src/message.cpp
@@ -25,5 +25,5 @@ void free_msgToMon_data(MessageToMon *msg) {
void print_msgToMon(MessageToMon *msg) {
printf("header: %s\n", msg->header);
- printf("data: %s\n", msg->data);
+ printf("data: %s\n", (char*)msg->data);
}
diff --git a/software/raspberry/superviseur-robot/lib/src/monitor.cpp b/software/raspberry/superviseur-robot/lib/src/monitor.cpp
index 9bd5ed4..f145f46 100644
--- a/software/raspberry/superviseur-robot/lib/src/monitor.cpp
+++ b/software/raspberry/superviseur-robot/lib/src/monitor.cpp
@@ -102,7 +102,7 @@ int send_message_to_monitor(const char* typeMessage, const void * data) {
serverSend("TRAME", 5);
return 0;
} else if ((string) typeMessage == HEADER_STM_POS) {
- char buffer[20];
+ char buffer[400];
Position * maPosition = (Position*) data;
sprintf(buffer, "POScenter: %3d;%3d | %.1fTRAME", maPosition->center.x, maPosition->center.y, maPosition->angle);
serverSend(buffer, strlen(buffer));
diff --git a/software/raspberry/superviseur-robot/lib/src/robot.cpp b/software/raspberry/superviseur-robot/lib/src/robot.cpp
new file mode 100644
index 0000000..b3c4242
--- /dev/null
+++ b/software/raspberry/superviseur-robot/lib/src/robot.cpp
@@ -0,0 +1,236 @@
+/**
+ * \file robot.cpp
+ * \author L.Senaneuch
+ * \version 1.0
+ * \date 06/06/2017
+ * \brief Fonction permettant la communication avec le robot.
+ *
+ * \details Ce fichier regroupe des fonctions facilitant la communication avec le robot en utilisant le port serie USART
+ */
+
+#include "robot.h"
+
+int fd;
+
+int getChar(char * c);
+int readSerial(char * msg);
+char checkSumGO(char * msg);
+int receiveMsg(void);
+int sendCmd(char cmd, const char * arg);
+
+int open_communication_robot(const char * path)
+{
+#ifndef __STUB__
+ struct termios options;
+ fd = open(path, O_RDWR | O_NOCTTY | O_NDELAY);
+ if(fd !=-1)
+ {
+ fcntl(fd, F_SETFL, 0);
+ tcgetattr(fd, &options);
+ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+ cfsetospeed (&options, B9600);
+ cfsetispeed (&options, B9600);
+ options.c_cc[VMIN]=0;
+ options.c_cc[VTIME]=0;
+ tcsetattr(fd, TCSANOW, &options);
+ return 0;
+ }
+ else
+ {
+ perror("can't openSerial");
+ return -1;
+ }
+#else
+ return 0;
+#endif
+}
+
+
+int close_communication_robot(void)
+{
+#ifndef __STUB__
+ return close(fd);
+#else
+ return 0;
+#endif
+}
+
+
+int send_command_to_robot(char cmd, const char * arg)
+{
+#ifndef __STUB__
+ sendCmd(cmd,arg);
+ // TODO : check return from sendCmd
+ return receiveMsg();
+#else
+ int reponse;
+ switch(cmd)
+ {
+ case DMB_PING:
+ reponse = 0;
+ break;
+ case DMB_IDLE:
+ reponse = 0;
+ break;
+ case DMB_START_WITH_WD:
+ reponse = 0;
+ break;
+ case DMB_RELOAD_WD:
+ reponse = 0;
+ break;
+ case DMB_GET_VBAT:
+ reponse = 2;
+ break;
+ case DMB_IS_BUSY:
+ reponse = 1;
+ break;
+ case DMB_START_WITHOUT_WD:
+ reponse = 0;
+ break;
+ case DMB_MOVE:
+ reponse = 0;
+ break;
+ case DMB_TURN:
+ reponse = 0;
+ break;
+ case DMB_GO_FORWARD:
+ reponse = 0;
+ break;
+ case DMB_GO_BACK:
+ reponse = 0;
+ break;
+ case DMB_GO_LEFT:
+ reponse = 0;
+ break;
+ case DMB_GO_RIGHT:
+ reponse = 0;
+ break;
+ case DMB_STOP_MOVE:
+ reponse = 0;
+ break;
+ default:
+ reponse = 0;
+ break;
+ }
+ return reponse;
+#endif
+}
+
+/****************************/
+/* PRIVATE */
+/****************************/
+
+int sendCmd(char cmd, const char * arg)
+{
+ char cmdWithArg[20]={};
+ cmdWithArg[0]=cmd;
+ switch(cmd)
+ {
+ case DMB_GO_FORWARD: strcpy(cmdWithArg,"M=+64000");
+ break;
+ case DMB_GO_BACK: strcpy(cmdWithArg,"M=-64000");
+ break;
+ case DMB_GO_LEFT: strcpy(cmdWithArg,"T=+64000");
+ break;
+ case DMB_GO_RIGHT: strcpy(cmdWithArg,"T=-64000");
+ break;
+ case DMB_STOP_MOVE: strcpy(cmdWithArg,"M=0");
+ break;
+ case DMB_MOVE: strcat(cmdWithArg,"=");
+ strcat(cmdWithArg,arg);
+ break;
+ case DMB_TURN: strcat(cmdWithArg,"=");
+ strcat(cmdWithArg,arg);
+ break;
+ }
+ int sizeCmd = strlen(cmdWithArg);
+ cmdWithArg[sizeCmd] = checkSumGO(cmdWithArg);
+ cmdWithArg[sizeCmd+1] = '\r';
+ cmdWithArg[sizeCmd+2] = '\0';
+ return write(fd,cmdWithArg,strlen(cmdWithArg));
+}
+
+int receiveMsg(void)
+{
+ char msg[20];
+ int b;
+ if((b = readSerial(msg))!=ROBOT_TIMED_OUT)
+ {
+ int taille = strlen(msg);
+ char checksum = msg[taille-2];
+ msg[taille-1] = 0;
+ msg[taille-2] = 0;
+ if(checksum!=checkSumGO(msg))
+ {
+ return ROBOT_CHECKSUM;
+ }
+ else
+ {
+ switch(msg[0])
+ {
+ case 'O' : return 0;
+ case 'E' : return ROBOT_ERROR;
+ case 'C' : return ROBOT_UKNOWN_CMD;
+ default : return atoi(&msg[0]);
+ }
+ }
+ }
+ else
+ {
+ return ROBOT_TIMED_OUT;
+ }
+}
+
+int getChar(char * c)
+{
+ int n =0;
+ int delay =0;
+ while((n=read(fd,c,1)) <=0)
+ {
+ usleep(5000);
+ delay++;
+ if(delay > 10)
+ {
+ return ROBOT_TIMED_OUT;
+ }
+
+ }
+ return n;
+}
+
+int readSerial(char * msg)
+{
+ char car=0;
+ int i=0;
+ for(int j = 0 ; j < 20 ; j++)
+ msg[j]=0;
+
+ while(car !='\r' && car!='\n') {
+ if(i>=20)
+ return -5;
+
+ if(getChar(&car)==ROBOT_TIMED_OUT) {
+ return ROBOT_TIMED_OUT;
+ }
+
+ msg[i] = car;
+ i++;
+ }
+ return i;
+}
+
+char checkSumGO(char * msg)
+{
+ char resultat = 0;
+ int i = 0;
+ int taille = strlen(msg);
+ for(i=0;i
+
+
+
+
+
+ image.cpp
+ message.cpp
+ monitor.cpp
+ robot.cpp
+
+
+
+
+ functions.cpp
+ main.cpp
+
+ .gitignore
+
+
+
+ CMakeLists.txt
+ Makefile
+ nbproject/private/launcher.properties
+
+
+ ^(nbproject)$
+
+ .
+
+ Makefile
+
+
+
+ default
+ false
+ false
+
+
+
+
+
+
+
+
+ .
+ ${MAKE} -f Makefile
+ ${MAKE} -f Makefile clean
+
+
+
+ _GNU_SOURCE
+ _REENTRANT
+ __MERCURY__
+
+
+
+
+ .
+ ${CMAKE} -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${IDE_CC} -DCMAKE_CXX_COMPILER=${IDE_CXX} -DCMAKE_C_FLAGS_DEBUG="-g3 -gdwarf-2" -DCMAKE_CXX_FLAGS_DEBUG="-g3 -gdwarf-2" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
+
+
+
+
+
+ lib
+ /usr/xenomai/include/mercury
+ /usr/xenomai/include
+ /usr/xenomai/include/alchemy
+
+
+
+
+
+
+ superviseur/src
+ lib
+ /usr/xenomai/include
+ /usr/xenomai/include/mercury
+ /usr/xenomai/include/alchemy
+ superviseur
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+ -
+
+
+
+ -
+
+
+
+
+
+
diff --git a/software/raspberry/superviseur-robot/nbproject/project.xml b/software/raspberry/superviseur-robot/nbproject/project.xml
new file mode 100644
index 0000000..54c6d81
--- /dev/null
+++ b/software/raspberry/superviseur-robot/nbproject/project.xml
@@ -0,0 +1,26 @@
+
+
+ org.netbeans.modules.cnd.makeproject
+
+
+ superviseur-robot
+
+ cpp,cxx
+ h
+ UTF-8
+
+
+ .
+
+
+
+ Default
+ 0
+
+
+
+ false
+
+
+
+
diff --git a/software/raspberry/superviseur-robot/superviseur-pthread/CMakeLists.txt b/software/raspberry/superviseur-robot/superviseur-pthread/CMakeLists.txt
new file mode 100644
index 0000000..a7619e8
--- /dev/null
+++ b/software/raspberry/superviseur-robot/superviseur-pthread/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../superviseur-pthread/bin)
+
+set(superviseur_pthread_FILES ./src/Program.cpp src/Tasks.cpp)
+
+include_directories(./src ../lib)
+
+add_executable(superviseur-pthread ${superviseur_pthread_FILES})
+target_link_libraries(superviseur-pthread destijl pthread rt)
+
diff --git a/software/raspberry/superviseur-robot/superviseur-pthread/bin/monitor b/software/raspberry/superviseur-robot/superviseur-pthread/bin/monitor
new file mode 100755
index 0000000..72ffe5c
Binary files /dev/null and b/software/raspberry/superviseur-robot/superviseur-pthread/bin/monitor differ
diff --git a/software/raspberry/superviseur-robot/superviseur-pthread/bin/superviseur-pthread b/software/raspberry/superviseur-robot/superviseur-pthread/bin/superviseur-pthread
new file mode 100755
index 0000000..3f87ec5
Binary files /dev/null and b/software/raspberry/superviseur-robot/superviseur-pthread/bin/superviseur-pthread differ
diff --git a/software/raspberry/superviseur-robot/superviseur-pthread/src/Program.cpp b/software/raspberry/superviseur-robot/superviseur-pthread/src/Program.cpp
new file mode 100644
index 0000000..dd97455
--- /dev/null
+++ b/software/raspberry/superviseur-robot/superviseur-pthread/src/Program.cpp
@@ -0,0 +1,273 @@
+/*
+ * File: Program.c
+ * Author: dimercur
+ *
+ * Created on 23 octobre 2018, 19:45
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#include
+#include
+#include
+#include
+
+#include "Tasks.h"
+
+using namespace std;
+
+class Program {
+public:
+// Déclaration des handleurs de tache
+ pthread_t th_server;
+ pthread_t th_sendToMon;
+ pthread_t th_receiveFromMon;
+ pthread_t th_openComRobot;
+ pthread_t th_startRobot;
+ pthread_t th_move;
+
+// Déclaration des priorités des taches
+ int PRIORITY_TSERVER = 30;
+ int PRIORITY_TOPENCOMROBOT = 20;
+ int PRIORITY_TMOVE = 10;
+ int PRIORITY_TSENDTOMON = 25;
+ int PRIORITY_TRECEIVEFROMMON = 22;
+ int PRIORITY_TSTARTROBOT = 20;
+
+// Declaration de mutex
+ pthread_mutex_t mutex_robotStarted;
+ pthread_mutex_t mutex_move;
+
+//declaration de semaphores
+ sem_t sem_barrier;
+ sem_t sem_openComRobot;
+ sem_t sem_serverOk;
+ sem_t sem_startRobot;
+
+// Déclaration des files de message
+ mqd_t q_messageToMon;
+ struct mq_attr q_messageToMonAttr;
+
+ int MSG_QUEUE_SIZE = 10;
+
+// Déclaration des ressources partagées
+ int etatCommMoniteur = 1;
+ int robotStarted = 0;
+
+ Program();
+ virtual ~Program();
+
+/**
+ * \fn void initStruct(void)
+ * \brief Initialisation des structures de l'application (tâches, mutex,
+ * semaphore, etc.)
+ */
+ void initStruct(void);
+
+/**
+ * \fn void startTasks(void)
+ * \brief Démarrage des tâches
+ */
+ void startTasks(void);
+
+/**
+ * \fn void deleteTasks(void)
+ * \brief Arrêt des tâches
+ */
+ void deleteTasks(void);
+
+ /**
+ * \fn int run(void)
+ * \brief execute program
+ */
+ int run(void);
+};
+
+int main(int argc, char **argv) {
+ int err;
+ Program myProg;
+ TcpServer server;
+
+ Tasks::messages.SetServer(&server);
+
+ //Lock the memory to avoid memory swapping for this program
+ mlockall(MCL_CURRENT | MCL_FUTURE);
+
+ printf("#################################\n");
+ printf("# DE STIJL PROJECT #\n");
+ printf("#################################\n");
+
+ return myProg.run();
+}
+
+Program::Program() {}
+Program::~Program() {}
+
+int Program::run(void) {
+
+ this->initStruct();
+ this->startTasks();
+ //sem_post(&sem_barrier);
+ pause();
+ this->deleteTasks();
+}
+
+void Program::initStruct(void) {
+
+ int err;
+
+ /* Creation des mutex */
+ mutex_robotStarted=PTHREAD_MUTEX_INITIALIZER;
+ mutex_move=PTHREAD_MUTEX_INITIALIZER;
+
+ /* Creation du semaphore */
+ if (sem_init(&sem_barrier, 0, 0) == -1) {
+ printf("Error semaphore create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ if (sem_init(&sem_openComRobot, 0, 0) == -1) {
+ printf("Error semaphore create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ if (sem_init(&sem_serverOk, 0, 0) == -1) {
+ printf("Error semaphore create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ if (sem_init(&sem_startRobot, 0, 0) == -1) {
+ printf("Error semaphore create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* Sous pthread, les taches sont executées dés leur creation
+ * la creation des taches se fait donc dans startTask */
+
+ /* Creation des files de messages */
+ q_messageToMonAttr.mq_flags = 0;
+ q_messageToMonAttr.mq_maxmsg = 10;
+ q_messageToMonAttr.mq_msgsize = 200;
+ q_messageToMonAttr.mq_curmsgs = 0;
+
+ q_messageToMon = mq_open("MessageToMon", O_CREAT | O_RDWR, 0644, &q_messageToMonAttr);
+ if((mqd_t)-1 != q_messageToMon){
+ printf("Error msg queue create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+// if (err = rt_queue_create(&q_messageToMon, "toto", MSG_QUEUE_SIZE * sizeof (MessageToRobot), MSG_QUEUE_SIZE, Q_FIFO)) {
+// printf("Error msg queue create: %s\n", strerror(-err));
+// exit(EXIT_FAILURE);
+// }
+}
+
+void Program::startTasks() {
+
+ int err;
+ pthread_attr_t tattr;
+ pthread_t tid;
+ int ret;
+ sched_param param;
+
+ /* initialized with default attributes */
+ ret = pthread_attr_init (&tattr);
+
+ /* safe to get existing scheduling param */
+ ret = pthread_attr_getschedparam (&tattr, ¶m);
+
+ /* set the priority; others are unchanged */
+ param.sched_priority = PRIORITY_TSTARTROBOT;
+
+ /* setting the new scheduling param */
+ ret = pthread_attr_setschedparam (&tattr, ¶m);
+
+ /* Creation des taches */
+
+ if ((err = pthread_create(&th_startRobot, &tattr, (void* (*)(void*))Tasks::f_startRobot, NULL))) {
+ printf("Error task create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* safe to get existing scheduling param */
+ ret = pthread_attr_getschedparam (&tattr, ¶m);
+
+ /* set the priority; others are unchanged */
+ param.sched_priority = PRIORITY_TRECEIVEFROMMON;
+
+ /* setting the new scheduling param */
+ ret = pthread_attr_setschedparam (&tattr, ¶m);
+
+ if ((err = pthread_create(&th_receiveFromMon, &tattr, (void* (*)(void*))Tasks::f_receiveFromMon, NULL))) {
+ printf("Error task create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* safe to get existing scheduling param */
+ ret = pthread_attr_getschedparam (&tattr, ¶m);
+
+ /* set the priority; others are unchanged */
+ param.sched_priority = PRIORITY_TSENDTOMON;
+
+ /* setting the new scheduling param */
+ ret = pthread_attr_setschedparam (&tattr, ¶m);
+
+ if ((err = pthread_create(&th_sendToMon, &tattr, (void* (*)(void*))Tasks::f_sendToMon, NULL))) {
+ printf("Error task create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* safe to get existing scheduling param */
+ ret = pthread_attr_getschedparam (&tattr, ¶m);
+
+ /* set the priority; others are unchanged */
+ param.sched_priority = PRIORITY_TOPENCOMROBOT;
+
+ /* setting the new scheduling param */
+ ret = pthread_attr_setschedparam (&tattr, ¶m);
+
+ if ((err = pthread_create(&th_openComRobot, &tattr, (void* (*)(void*))Tasks::f_openComRobot, NULL))) {
+ printf("Error task create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* safe to get existing scheduling param */
+ ret = pthread_attr_getschedparam (&tattr, ¶m);
+
+ /* set the priority; others are unchanged */
+ param.sched_priority = PRIORITY_TMOVE;
+
+ /* setting the new scheduling param */
+ ret = pthread_attr_setschedparam (&tattr, ¶m);
+
+ if ((err = pthread_create(&th_move, &tattr, (void* (*)(void*))Tasks::f_move, NULL))) {
+ printf("Error task create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+
+ /* safe to get existing scheduling param */
+ ret = pthread_attr_getschedparam (&tattr, ¶m);
+
+ /* set the priority; others are unchanged */
+ param.sched_priority = PRIORITY_TSERVER;
+
+ /* setting the new scheduling param */
+ ret = pthread_attr_setschedparam (&tattr, ¶m);
+
+ if ((err = pthread_create(&th_server, &tattr, (void* (*)(void*))Tasks::f_server, NULL))) {
+ printf("Error task create: %s\n", strerror(-err));
+ exit(EXIT_FAILURE);
+ }
+}
+
+void Program::deleteTasks() {
+ pthread_cancel(th_server);
+ pthread_cancel(th_openComRobot);
+ pthread_cancel(th_move);
+}
diff --git a/software/raspberry/superviseur-robot/superviseur-pthread/src/Tasks.cpp b/software/raspberry/superviseur-robot/superviseur-pthread/src/Tasks.cpp
new file mode 100644
index 0000000..701647c
--- /dev/null
+++ b/software/raspberry/superviseur-robot/superviseur-pthread/src/Tasks.cpp
@@ -0,0 +1,246 @@
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+//#include "../../lib/Robot.h"
+//#include "../../lib/Camera.h"
+//#include "../../lib/Image.h"
+//#include "../../lib/TcpServer.h"
+
+#include "Tasks.h"
+
+void Tasks::f_server(void *arg) {
+// int err;
+// /* INIT */
+// RT_TASK_INFO info;
+// rt_task_inquire(NULL, &info);
+// printf("Init %s\n", info.name);
+// rt_sem_p(&sem_barrier, TM_INFINITE);
+//
+// err = run_nodejs("/usr/local/bin/node", "/home/pi/Interface_Robot/server.js");
+//
+// if (err < 0) {
+// printf("Failed to start nodejs: %s\n", strerror(-err));
+// exit(EXIT_FAILURE);
+// } else {
+//#ifdef _WITH_TRACE_
+// printf("%s: nodejs started\n", info.name);
+//#endif
+// open_server();
+// rt_sem_broadcast(&sem_serverOk);
+// }
+}
+
+void Tasks::f_sendToMon(void * arg) {
+// int err;
+// MessageToMon msg;
+//
+// /* INIT */
+// RT_TASK_INFO info;
+// rt_task_inquire(NULL, &info);
+// printf("Init %s\n", info.name);
+// rt_sem_p(&sem_barrier, TM_INFINITE);
+//
+//#ifdef _WITH_TRACE_
+// printf("%s : waiting for sem_serverOk\n", info.name);
+//#endif
+// rt_sem_p(&sem_serverOk, TM_INFINITE);
+// while (1) {
+//
+//#ifdef _WITH_TRACE_
+// printf("%s : waiting for a message in queue\n", info.name);
+//#endif
+// if (rt_queue_read(&q_messageToMon, &msg, sizeof (MessageToRobot), TM_INFINITE) >= 0) {
+//#ifdef _WITH_TRACE_
+// printf("%s : message {%s,%s} in queue\n", info.name, msg.header, msg.data);
+//#endif
+//
+// send_message_to_monitor(msg.header, msg.data);
+// free_msgToMon_data(&msg);
+// rt_queue_free(&q_messageToMon, &msg);
+// } else {
+// printf("Error msg queue write: %s\n", strerror(-err));
+// }
+// }
+}
+
+void Tasks::f_receiveFromMon(void *arg) {
+// MessageFromMon msg;
+// int err;
+//
+// /* INIT */
+// RT_TASK_INFO info;
+// rt_task_inquire(NULL, &info);
+// printf("Init %s\n", info.name);
+// rt_sem_p(&sem_barrier, TM_INFINITE);
+//
+//#ifdef _WITH_TRACE_
+// printf("%s : waiting for sem_serverOk\n", info.name);
+//#endif
+// rt_sem_p(&sem_serverOk, TM_INFINITE);
+// do {
+//#ifdef _WITH_TRACE_
+// printf("%s : waiting for a message from monitor\n", info.name);
+//#endif
+// err = receive_message_from_monitor(msg.header, msg.data);
+//#ifdef _WITH_TRACE_
+// printf("%s: msg {header:%s,data=%s} received from UI\n", info.name, msg.header, msg.data);
+//#endif
+// if (strcmp(msg.header, HEADER_MTS_COM_DMB) == 0) {
+// if (msg.data[0] == OPEN_COM_DMB) { // Open communication supervisor-robot
+//#ifdef _WITH_TRACE_
+// printf("%s: message open Xbee communication\n", info.name);
+//#endif
+// rt_sem_v(&sem_openComRobot);
+// }
+// } else if (strcmp(msg.header, HEADER_MTS_DMB_ORDER) == 0) {
+// if (msg.data[0] == DMB_START_WITHOUT_WD) { // Start robot
+//#ifdef _WITH_TRACE_
+// printf("%s: message start robot\n", info.name);
+//#endif
+// rt_sem_v(&sem_startRobot);
+//
+// } else if ((msg.data[0] == DMB_GO_BACK)
+// || (msg.data[0] == DMB_GO_FORWARD)
+// || (msg.data[0] == DMB_GO_LEFT)
+// || (msg.data[0] == DMB_GO_RIGHT)
+// || (msg.data[0] == DMB_STOP_MOVE)) {
+//
+// rt_mutex_acquire(&mutex_move, TM_INFINITE);
+// move = msg.data[0];
+// rt_mutex_release(&mutex_move);
+//#ifdef _WITH_TRACE_
+// printf("%s: message update movement with %c\n", info.name, move);
+//#endif
+//
+// }
+// }
+// } while (err > 0);
+
+}
+
+void Tasks::f_openComRobot(void * arg) {
+// int err;
+//
+// /* INIT */
+// RT_TASK_INFO info;
+// rt_task_inquire(NULL, &info);
+// printf("Init %s\n", info.name);
+// rt_sem_p(&sem_barrier, TM_INFINITE);
+//
+// while (1) {
+//#ifdef _WITH_TRACE_
+// printf("%s : Wait sem_openComRobot\n", info.name);
+//#endif
+// rt_sem_p(&sem_openComRobot, TM_INFINITE);
+//#ifdef _WITH_TRACE_
+// printf("%s : sem_openComRobot arrived => open communication robot\n", info.name);
+//#endif
+// err = open_communication_robot();
+// if (err == 0) {
+//#ifdef _WITH_TRACE_
+// printf("%s : the communication is opened\n", info.name);
+//#endif
+// MessageToMon msg;
+// set_msgToMon_header(&msg, HEADER_STM_ACK);
+// write_in_queue(&q_messageToMon, msg);
+// } else {
+// MessageToMon msg;
+// set_msgToMon_header(&msg, HEADER_STM_NO_ACK);
+// write_in_queue(&q_messageToMon, msg);
+// }
+// }
+}
+
+void Tasks::f_startRobot(void * arg) {
+// int err;
+//
+// /* INIT */
+// RT_TASK_INFO info;
+// rt_task_inquire(NULL, &info);
+// printf("Init %s\n", info.name);
+// rt_sem_p(&sem_barrier, TM_INFINITE);
+//
+// while (1) {
+//#ifdef _WITH_TRACE_
+// printf("%s : Wait sem_startRobot\n", info.name);
+//#endif
+// rt_sem_p(&sem_startRobot, TM_INFINITE);
+//#ifdef _WITH_TRACE_
+// printf("%s : sem_startRobot arrived => Start robot\n", info.name);
+//#endif
+// err = send_command_to_robot(DMB_START_WITHOUT_WD);
+// if (err == 0) {
+//#ifdef _WITH_TRACE_
+// printf("%s : the robot is started\n", info.name);
+//#endif
+// rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
+// robotStarted = 1;
+// rt_mutex_release(&mutex_robotStarted);
+// MessageToMon msg;
+// set_msgToMon_header(&msg, HEADER_STM_ACK);
+// write_in_queue(&q_messageToMon, msg);
+// } else {
+// MessageToMon msg;
+// set_msgToMon_header(&msg, HEADER_STM_NO_ACK);
+// write_in_queue(&q_messageToMon, msg);
+// }
+// }
+}
+
+void Tasks::f_move(void *arg) {
+// /* INIT */
+// RT_TASK_INFO info;
+// rt_task_inquire(NULL, &info);
+// printf("Init %s\n", info.name);
+// rt_sem_p(&sem_barrier, TM_INFINITE);
+//
+// /* PERIODIC START */
+//#ifdef _WITH_TRACE_
+// printf("%s: start period\n", info.name);
+//#endif
+// rt_task_set_periodic(NULL, TM_NOW, 100000000);
+// while (1) {
+//#ifdef _WITH_TRACE_
+// printf("%s: Wait period \n", info.name);
+//#endif
+// rt_task_wait_period(NULL);
+//#ifdef _WITH_TRACE_
+// printf("%s: Periodic activation\n", info.name);
+// printf("%s: move equals %c\n", info.name, move);
+//#endif
+// rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
+// if (robotStarted) {
+// rt_mutex_acquire(&mutex_move, TM_INFINITE);
+// send_command_to_robot(move);
+// rt_mutex_release(&mutex_move);
+//#ifdef _WITH_TRACE_
+// printf("%s: the movement %c was sent\n", info.name, move);
+//#endif
+// }
+// rt_mutex_release(&mutex_robotStarted);
+// }
+}
+
+void Tasks::write_in_queue(mqd_t *queue, MsgManager msg) {
+// void *buff;
+// buff = rt_queue_alloc(&q_messageToMon, sizeof (MessageToMon));
+// memcpy(buff, &msg, sizeof (MessageToMon));
+// rt_queue_send(&q_messageToMon, buff, sizeof (MessageToMon), Q_NORMAL);
+}
+
+MsgManager Tasks::messages;
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/superviseur-pthread/src/Tasks.h b/software/raspberry/superviseur-robot/superviseur-pthread/src/Tasks.h
new file mode 100644
index 0000000..17cca2e
--- /dev/null
+++ b/software/raspberry/superviseur-robot/superviseur-pthread/src/Tasks.h
@@ -0,0 +1,44 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: functions.h
+ * Author: pehladik
+ *
+ * Created on 15 janvier 2018, 12:50
+ */
+
+#ifndef TASKS_H
+#define TASKS_H
+
+#include
+#include
+
+class Tasks {
+public:
+ static MsgManager messages;
+
+ static void f_server(void *arg);
+
+ static void f_sendToMon(void *arg);
+
+ static void f_receiveFromMon(void *arg);
+
+ static void f_openComRobot(void *arg);
+
+ static void f_move(void *arg);
+
+ static void f_startRobot(void *arg);
+
+private:
+ char mode_start;
+
+ static void write_in_queue(mqd_t *queue, MsgManager msg);
+ Tasks() {}
+};
+
+#endif /* TASKS_H */
+
diff --git a/software/raspberry/superviseur-robot/superviseur/.gitignore b/software/raspberry/superviseur-robot/superviseur/.gitignore
new file mode 100644
index 0000000..f7365e8
--- /dev/null
+++ b/software/raspberry/superviseur-robot/superviseur/.gitignore
@@ -0,0 +1,9 @@
+bin/
+build/
+CMakeFiles/
+
+.dep.inc
+Makefile
+*.cmake
+*.o
+
diff --git a/software/raspberry/superviseur-robot/superviseur/CMakeLists.txt b/software/raspberry/superviseur-robot/superviseur/CMakeLists.txt
new file mode 100644
index 0000000..fd22eaa
--- /dev/null
+++ b/software/raspberry/superviseur-robot/superviseur/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(superviseur_FILES ./src/main.cpp src/functions.cpp)
+
+include_directories(./src ../lib /usr/xenomai/include /usr/xenomai/include/mercury)
+link_directories(/usr/xenomai/lib)
+
+add_executable(superviseur ${superviseur_FILES})
+target_link_libraries(superviseur destijl)
+
+#add_custom_command(TARGET superviseur POST_BUILD
+# COMMAND sudo chown root ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/superviseur
+# COMMAND sudo chgrp root ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/superviseur
+# COMMAND sudo chmod +s ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/superviseur
+# WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+# COMMENT "Add sticky bit"
+#)
\ No newline at end of file
diff --git a/software/raspberry/superviseur-robot/destijl_init/src/functions.cpp b/software/raspberry/superviseur-robot/superviseur/src/functions.cpp
similarity index 98%
rename from software/raspberry/superviseur-robot/destijl_init/src/functions.cpp
rename to software/raspberry/superviseur-robot/superviseur/src/functions.cpp
index 4312e9e..59551d0 100644
--- a/software/raspberry/superviseur-robot/destijl_init/src/functions.cpp
+++ b/software/raspberry/superviseur-robot/superviseur/src/functions.cpp
@@ -1,4 +1,4 @@
-#include "../header/functions.h"
+#include "functions.h"
char mode_start;
@@ -102,7 +102,7 @@ void f_receiveFromMon(void *arg) {
|| (msg.data[0] == DMB_STOP_MOVE)) {
rt_mutex_acquire(&mutex_move, TM_INFINITE);
- move = msg.data[0];
+ robotMove = msg.data[0];
rt_mutex_release(&mutex_move);
#ifdef _WITH_TRACE_
printf("%s: message update movement with %c\n", info.name, move);
@@ -207,7 +207,7 @@ void f_move(void *arg) {
rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
if (robotStarted) {
rt_mutex_acquire(&mutex_move, TM_INFINITE);
- send_command_to_robot(move);
+ send_command_to_robot(robotMove);
rt_mutex_release(&mutex_move);
#ifdef _WITH_TRACE_
printf("%s: the movement %c was sent\n", info.name, move);
diff --git a/software/raspberry/superviseur-robot/destijl_init/header/functions.h b/software/raspberry/superviseur-robot/superviseur/src/functions.h
similarity index 90%
rename from software/raspberry/superviseur-robot/destijl_init/header/functions.h
rename to software/raspberry/superviseur-robot/superviseur/src/functions.h
index efe2faf..1953ac2 100644
--- a/software/raspberry/superviseur-robot/destijl_init/header/functions.h
+++ b/software/raspberry/superviseur-robot/superviseur/src/functions.h
@@ -25,10 +25,10 @@
#include
#include
-#include "../../src/monitor.h"
-#include "../../src/robot.h"
-#include "../../src/image.h"
-#include "../../src/message.h"
+#include "monitor.h"
+#include "robot.h"
+#include "image.h"
+#include "message.h"
extern RT_TASK th_server;
extern RT_TASK th_sendToMon;
@@ -49,7 +49,7 @@ extern RT_QUEUE q_messageToMon;
extern int etatCommMoniteur;
extern int robotStarted;
-extern char move;
+extern char robotMove;
extern int MSG_QUEUE_SIZE;
diff --git a/software/raspberry/superviseur-robot/destijl_init/main.cpp b/software/raspberry/superviseur-robot/superviseur/src/main.cpp
similarity index 91%
rename from software/raspberry/superviseur-robot/destijl_init/main.cpp
rename to software/raspberry/superviseur-robot/superviseur/src/main.cpp
index e451b6e..a12c146 100644
--- a/software/raspberry/superviseur-robot/destijl_init/main.cpp
+++ b/software/raspberry/superviseur-robot/superviseur/src/main.cpp
@@ -16,7 +16,7 @@
#include
#include
-#include "./header/functions.h"
+#include "functions.h"
// Déclaration des taches
RT_TASK th_server;
@@ -51,7 +51,7 @@ int MSG_QUEUE_SIZE = 10;
// Déclaration des ressources partagées
int etatCommMoniteur = 1;
int robotStarted = 0;
-char move = DMB_STOP_MOVE;
+char robotMove = DMB_STOP_MOVE;
/**
* \fn void initStruct(void)
@@ -91,10 +91,11 @@ int main(int argc, char **argv) {
}
void initStruct(void) {
+
int err;
/* Creation des mutex */
if (err = rt_mutex_create(&mutex_robotStarted, NULL)) {
- printf("Error mutex create: %s\n", strerror(-err));
+ printf("Error mutex create: %d %s\n", err, strerror(-err));
exit(EXIT_FAILURE);
}
if (err = rt_mutex_create(&mutex_move, NULL)) {
@@ -103,20 +104,20 @@ void initStruct(void) {
}
/* Creation du semaphore */
- if (err = rt_sem_create(&sem_barrier, NULL, 0, S_FIFO)) {
- printf("Error semaphore create: %s\n", strerror(-err));
+ if (err = rt_sem_create(&sem_barrier, "truc", 0, S_FIFO)) {
+ printf("Error semaphore create 1: %d %s\n", err, strerror(-err));
exit(EXIT_FAILURE);
}
if (err = rt_sem_create(&sem_openComRobot, NULL, 0, S_FIFO)) {
- printf("Error semaphore create: %s\n", strerror(-err));
+ printf("Error semaphore create 2: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}
if (err = rt_sem_create(&sem_serverOk, NULL, 0, S_FIFO)) {
- printf("Error semaphore create: %s\n", strerror(-err));
+ printf("Error semaphore create 3: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}
if (err = rt_sem_create(&sem_startRobot, NULL, 0, S_FIFO)) {
- printf("Error semaphore create: %s\n", strerror(-err));
+ printf("Error semaphore create 4: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}