ROVER - Modularization - added new files to src/ and include/ folders
Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
diff --git a/rover/include/tasks/booth_modes_task.h b/rover/include/tasks/booth_modes_task.h
new file mode 100644
index 0000000..3586447
--- /dev/null
+++ b/rover/include/tasks/booth_modes_task.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Booth modes implemented for demonstration of the APP4MC-APPSTACLE Rover
+ * Header file
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 23.10.2017
+ *
+ */
+
+#ifndef TASKS_BOOTH_MODES_TASK_H_
+#define TASKS_BOOTH_MODES_TASK_H_
+
+/* Defines */
+
+
+/* Interfaces */
+void *Booth_Modes_Task(void * arg);
+
+
+#endif /* TASKS_BOOTH_MODES_TASK_H_ */
diff --git a/rover/include/tasks/image_processing_task.h b/rover/include/tasks/image_processing_task.h
new file mode 100644
index 0000000..6ba7f9d
--- /dev/null
+++ b/rover/include/tasks/image_processing_task.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Image processing task that is used for basic traffic cone detection
+ * Using OpenCV 2.4.9
+ * Header file
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, libraries compiled for cross compilation 16.10.2017
+ * M.Ozcelikors <mozcelikors@gmail.com>, demonstrator image processing task added, 19.10.2017
+ *
+ * Usage Instructions:
+ * 1) To cross compile OpenCV, make sure you install OpenCV in your Raspberry Pi
+ * 2) Then find opencv shared objects using the following command
+ * find / -name libopencv*.so
+ * find / -name libopencv*.so*
+ * 3) Copy all of the found .so files to your C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\lib\arm-linux-gnueabihf (on Windows)
+ * 4) Be sure to use following Linker flags: (adjust the path to your system):
+ * -Wl,-verbose,-rpath-link,"C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\lib\arm-linux-gnueabihf"
+ * 5) Be sure to add the libraries you are using to the linker using -l:
+ * such as ... -lopencv_core -lopencv_ml -lopencv_imgproc
+ * 6) Be sure to include the library search paths using -L:
+ * -L"C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\lib\arm-linux-gnueabihf"
+ * 7) Be sure to include OpenCV include directories in gcc using -I flag.
+ *
+ */
+
+#ifndef TASKS_IMAGE_PROCESSING_TASK_H_
+#define TASKS_IMAGE_PROCESSING_TASK_H_
+
+/* Interfaces */
+void *Image_Processing_Task (void *arg);
+
+
+
+#endif /* TASKS_IMAGE_PROCESSING_TASK_H_ */
diff --git a/rover/include/tasks/infrared_distance_task.h b/rover/include/tasks/infrared_distance_task.h
new file mode 100644
index 0000000..ef57970
--- /dev/null
+++ b/rover/include/tasks/infrared_distance_task.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Eclipse Foundation, FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Infrared Distance Sensor Task with wiringPi and pThreads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ * Gael Blondelle - API functions
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ *
+ */
+
+#ifndef INFRARED_DISTANCE_TASK_H_
+#define INFRARED_DISTANCE_TASK_H_
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+
+void *InfraredDistance_Task (void * arg);
+
+#endif /* INFRARED_DISTANCE_TASK_H_ */
diff --git a/rover/include/tasks/keycommand_task.h b/rover/include/tasks/keycommand_task.h
new file mode 100644
index 0000000..23e6ea0
--- /dev/null
+++ b/rover/include/tasks/keycommand_task.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Key command obtainer function with pThreads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ *
+ */
+
+#ifndef KEYCOMMAND_TASK_H_
+#define KEYCOMMAND_TASK_H_
+
+#include <string.h>
+#include <stdio.h>
+
+
+
+void *KeyCommandInput_Task(void * arg);
+
+#endif /* KEYCOMMAND_TASK_H_ */
diff --git a/rover/include/tasks/motordriver_task.h b/rover/include/tasks/motordriver_task.h
new file mode 100644
index 0000000..588ef79
--- /dev/null
+++ b/rover/include/tasks/motordriver_task.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Eclipse Foundation, FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Motor driving Task with wiringPi and pThreads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ * Gael Blondelle - API functions
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ *
+ */
+
+#ifndef MOTORDRIVER_TASK_H_
+#define MOTORDRIVER_TASK_H_
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+void *MotorDriver_Task(void * arg);
+
+void ExitAutomaticModes(void);
+
+#endif /* MOTORDRIVER_TASK_H_ */
diff --git a/rover/include/tasks/oled_task.h b/rover/include/tasks/oled_task.h
new file mode 100644
index 0000000..3afc6b7
--- /dev/null
+++ b/rover/include/tasks/oled_task.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * SSD1306 I2C OLED Display Task
+ *
+ * Contributors / Revision History:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 04.10.2017
+ * M.Ozcelikors <mozcelikors@gmail.com>, application is enhanced (status, appstacle displays) 08.10.2017
+ *
+ * Usage Instructions:
+ * 1) One should set-up I2C on Raspberry Pi to run this script properly (taken from Adafruit):
+ * 1.1) Install necessary modules:
+ * sudo apt-get install -y python-smbus
+ * sudo apt-get install -y i2c-tools
+ * 1.2) In /etc/modules, add following lines:
+ * i2c-bcm2708
+ * i2c-dev
+ * 1.3) In /etc/modprobe.d/raspi-blacklist.conf, uncomment possible following lines:
+ * blacklist spi-bcm2708
+ * blacklist i2c-bcm2708
+ * 1.4) In /boot/config.txt, add following lines:
+ * dtparam=i2c1=on
+ * dtparam=i2c_arm=on
+ * 1.5) Then reboot
+ * sudo reboot
+ * 1.6) To test I2C and see the addresses,
+ * sudo i2cdetect -y 1
+ * 2) For cross-compilation using Eclipse IDE, make sure to follow the instructions located under readme.txt files
+ * in drivers/oled_drivers:
+ * Please note that in order to use OLED SSD1306 with I2C,
+ * one has to download bcm2835.c, bcm2835.h, and has access to current <linux/i2c-dev.h>.
+ * In case the compiler complains, please also download the newest i2c-dev.h and put it in drivers/oled_drivers folder.
+ * Download i2c-dev.h from: https://www.kernel.org/pub/linux/
+ * Download bcm2835.c and bcm2835.h from: https://github.com/hallard/ArduiPi_SSD1306
+ */
+
+#ifndef TASKS_OLED_TASK_H_
+#define TASKS_OLED_TASK_H_
+
+/* Defines */
+#define NUMFLAKES 10
+#define XPOS 0
+#define YPOS 1
+#define DELTAY 2
+
+/* Intefaces */
+void *OLED_Task(void * arg);
+void shutdownOSwithDisplay(void);
+
+#endif /* TASKS_OLED_TASK_H_ */
diff --git a/rover/include/tasks/parking_task.h b/rover/include/tasks/parking_task.h
new file mode 100644
index 0000000..09d74b9
--- /dev/null
+++ b/rover/include/tasks/parking_task.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Parking task - Header file
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+
+ * Update History:
+ * 06.06.2017 - added initial task
+ *
+ */
+
+#ifndef TASKS_PARKING_TASK_H_
+#define TASKS_PARKING_TASK_H_
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+void *Parking_Task(void * arg);
+
+
+#endif /* TASKS_PARKING_TASK_H_ */
diff --git a/rover/include/tasks/record_timing_task.h b/rover/include/tasks/record_timing_task.h
new file mode 100644
index 0000000..7fc73af
--- /dev/null
+++ b/rover/include/tasks/record_timing_task.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Displays timing statistics of threads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ *
+ * Update History:
+ * 23.03.2017 - first revision
+ *
+ *
+ */
+
+#ifndef TASKS_RECORD_TIMING_TASK_H_
+#define TASKS_RECORD_TIMING_TASK_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+void *Record_Timing_Task (void * arg);
+
+
+
+#endif /* TASKS_RECORD_TIMING_TASK_H_ */
diff --git a/rover/include/tasks/rover_test_task.h b/rover/include/tasks/rover_test_task.h
new file mode 100644
index 0000000..a9a6848
--- /dev/null
+++ b/rover/include/tasks/rover_test_task.h
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2017 FH-Dortmund and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * FH-Dortmund - initial API and implementation
+ *******************************************************************************/
+
+#ifndef ROVER_TEST_TASK_H_
+#define ROVER_TEST_TASK_H_
+
+//Includes needed
+#include <pthread.h>
+#include <iostream>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+#include <cstdio>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+
+#include <libraries/pthread_monitoring/collect_thread_name.h>
+#include <roverapp.h>
+#include <libraries/timing/timing.h>
+#include <api/basic_psys_rover.h>
+#include <interfaces.h>
+
+
+void *Rover_Test_Task(void *unused);
+void say(char *text);
+void autopark() ;
+void getDistanceTrain(int channel,int rounds);
+
+
+#endif /* ROVER_TEST_TASK_H_ */
diff --git a/rover/include/tasks/socket_client_task.h b/rover/include/tasks/socket_client_task.h
new file mode 100644
index 0000000..1e36568
--- /dev/null
+++ b/rover/include/tasks/socket_client_task.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Socket client for rover-app to rover-web communication
+ * Header file
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 26.10.2017
+ *
+ */
+
+#ifndef TASKS_SOCKET_CLIENT_TASK_H_
+#define TASKS_SOCKET_CLIENT_TASK_H_
+
+/* Interfaces */
+void *Socket_Client_Task (void * arg);
+
+
+#endif /* TASKS_SOCKET_CLIENT_TASK_H_ */
diff --git a/rover/include/tasks/socket_server_task.h b/rover/include/tasks/socket_server_task.h
new file mode 100644
index 0000000..923df7c
--- /dev/null
+++ b/rover/include/tasks/socket_server_task.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Socket server for rover-web to rover-app communication
+ * Header file
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 26.10.2017
+ *
+ */
+
+
+#ifndef TASKS_SOCKET_SERVER_TASK_H_
+#define TASKS_SOCKET_SERVER_TASK_H_
+
+
+/* Interfaces */
+void *Socket_Server_Task(void * arg);
+
+
+#endif /* TASKS_SOCKET_SERVER_TASK_H_ */
diff --git a/rover/include/tasks/srf02_task.h b/rover/include/tasks/srf02_task.h
new file mode 100644
index 0000000..fe02460
--- /dev/null
+++ b/rover/include/tasks/srf02_task.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * SRF02 Proximity sensor Task using PThreads
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 05.10.2017
+ *
+ */
+
+#ifndef TASKS_SRF02_TASK_H_
+#define TASKS_SRF02_TASK_H_
+
+/* Defines */
+#define FRONT_SRF02_ADDR ((int) 0x70)
+#define REAR_SRF02_ADDR ((int) 0x73)
+
+/* Interfaces */
+void *SRF02_Task(void * arg);
+
+
+#endif /* TASKS_SRF02_TASK_H_ */
diff --git a/rover/include/tasks/temperature_task.h b/rover/include/tasks/temperature_task.h
new file mode 100644
index 0000000..f89b4c9
--- /dev/null
+++ b/rover/include/tasks/temperature_task.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Eclipse Foundation, FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Temperature and Humidity Sensor DHT22 Task with wiringPi and pThreads - header file
+ * (Adapted from the tutorial: http://www.uugear.com/portfolio/read-dht1122-temperature-humidity-sensor-from-raspberry-pi/)
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ * 11.10.2017 - re-compiled for DHT22 sensor
+ *
+*/
+
+#ifndef TEMPERATURE_TASK_H_
+#define TEMPERATURE_TASK_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_TIMINGS 85
+
+#define DHT22_RPI_PIN 24 //BCM19, wiringPi 24
+
+void *Temperature_Task(void * arg);
+
+
+#endif /* TEMPERATURE_TASK_H_ */
diff --git a/rover/include/tasks/ultrasonic_sensor_grove_task.h b/rover/include/tasks/ultrasonic_sensor_grove_task.h
new file mode 100644
index 0000000..f79d806
--- /dev/null
+++ b/rover/include/tasks/ultrasonic_sensor_grove_task.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Ultrasonic Distance Sensor Task with wiringPi and pThreads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ *
+ * Additional:
+ * Migrated from Groove Ultrasonic Sensor Python Library
+ *
+ * Pin for SIG input
+ * -> BCM-5, Physical 29, wiringPi 21
+ *
+ */
+
+#ifndef ULTRASONIC_SENSOR_GROVE_TASK_H_
+#define ULTRASONIC_SENSOR_GROVE_TASK_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+
+#define SIG 2 //BCM-27 -> WiringPi 2 //Same as ECHO1 pin, if some one wants to replace back sr04 with groove sensor
+
+void *Ultrasonic_Sensor_Grove_Task(void *);
+int getCM_GrooveUltrasonicRanger();
+void setup_GrooveUltrasonicRanger();
+
+#endif /* ULTRASONIC_SENSOR_GROVE_TASK_H_ */
diff --git a/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h b/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h
new file mode 100644
index 0000000..13e454b
--- /dev/null
+++ b/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * HCSR-04 ultrasonic sensor code with wiringPi and pThreads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ * Resource: https://ninedof.wordpress.com/2013/07/16/rpi-hc-sr04-ultrasonic-sensor-mini-project/
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ * 25.03.2017 - timing library added
+ * 27.03.2017 - ultrasonic hc-sr04 sensor implementation corrected.
+ *
+ */
+
+//Only necessary if you do not use logic level converter:
+//A voltage divided should be used and it should be made sure that the grounds are not isolated and are connected to same line.
+// ___________
+// +5V|----------------------------> Raspberry Pi +5V Pin
+// |
+// |
+// TRIG|----------------------------> Raspberry Pi BCM-24 Pin
+// |
+// |
+// | -----> Connect to Raspberry Pi BCM-25 Pin
+// HC-SR04 | |
+// | |
+// | 330 ohm | 470 ohm
+// ECHO|-------------^^^^^^^^^^--------^^^^^^^^^^--------> Connect to Raspberry Pi GND
+// |
+// |
+// GND|---------------------------------------------------> Connect to Raspberry Pi GND
+// __________|
+
+
+#ifndef TASKS_ULTRASONIC_SENSOR_SR04_BACK_TASK_H_
+#define TASKS_ULTRASONIC_SENSOR_SR04_BACK_TASK_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+#define TRIG1 1 //BCM-18 -> WiringPi 1
+#define ECHO1 2 //BCM-27 -> WiringPi 2
+
+void *Ultrasonic_Sensor_SR04_Back_Task(void *);
+int getCM_HCSR04UltrasonicBack();
+void setup_HCSR04UltrasonicBack();
+
+
+#endif /* TASKS_ULTRASONIC_SENSOR_SR04_BACK_TASK_H_ */
diff --git a/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h b/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h
new file mode 100644
index 0000000..36a8a77
--- /dev/null
+++ b/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * HCSR-04 ultrasonic sensor code with wiringPi and pThreads
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ * Resource: https://ninedof.wordpress.com/2013/07/16/rpi-hc-sr04-ultrasonic-sensor-mini-project/
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ * 25.03.2017 - timing library added
+ * 27.03.2017 - ultrasonic hc-sr04 sensor implementation corrected.
+ *
+ */
+
+//Only necessary if you do not use logic level converter:
+//A voltage divided should be used and it should be made sure that the grounds are not isolated and are connected to same line.
+// ___________
+// +5V|----------------------------> Raspberry Pi +5V Pin
+// |
+// |
+// TRIG|----------------------------> Raspberry Pi BCM-24 Pin
+// |
+// |
+// | -----> Connect to Raspberry Pi BCM-25 Pin
+// HC-SR04 | |
+// | |
+// | 330 ohm | 470 ohm
+// ECHO|-------------^^^^^^^^^^--------^^^^^^^^^^--------> Connect to Raspberry Pi GND
+// |
+// |
+// GND|---------------------------------------------------> Connect to Raspberry Pi GND
+// __________|
+
+
+#ifndef TASKS_ULTRASONIC_SENSOR_SR04_FRONT_TASK_H_
+#define TASKS_ULTRASONIC_SENSOR_SR04_FRONT_TASK_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+#define TRIG0 7 //BCM-4 -> WiringPi 7
+#define ECHO0 0 //BCM-17 -> WiringPi 0
+
+void *Ultrasonic_Sensor_SR04_Front_Task(void *);
+int getCM_HCSR04UltrasonicFront();
+void setup_HCSR04UltrasonicFront();
+
+
+#endif /* TASKS_ULTRASONIC_SENSOR_SR04_FRONT_TASK_H_ */
diff --git a/rover/src/drivers/oled_drivers/connectivity_icons.c b/rover/src/drivers/oled_drivers/connectivity_icons.c
new file mode 100644
index 0000000..e6dd386
--- /dev/null
+++ b/rover/src/drivers/oled_drivers/connectivity_icons.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Connectivity icons created for 128x64 bitmap monochrome displays
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 04.10.2017
+ *
+ */
+
+#ifndef CONN_ICONS_
+#define CONN_ICONS_
+
+/* 16 x 16 */
+static unsigned char bluetooth_icon [] =
+{
+ 0b00000000, 0b00000000,
+ 0b00000001, 0b10000000,
+ 0b00000001, 0b11000000,
+ 0b00000001, 0b01100000,
+ 0b00001001, 0b00110000,
+ 0b00001101, 0b00110000,
+ 0b00000111, 0b01100000,
+ 0b00000011, 0b11000000,
+ 0b00000001, 0b10000000,
+ 0b00000011, 0b11000000,
+ 0b00000111, 0b01100000,
+ 0b00001101, 0b00110000,
+ 0b00001001, 0b00110000,
+ 0b00000001, 0b01100000,
+ 0b00000001, 0b11000000,
+ 0b00000001, 0b10000000,
+};
+
+/* 16 x 16 */
+static unsigned char wlan_icon[] =
+{
+ 0b00000000, 0b00000000,
+ 0b00000111, 0b11100000,
+ 0b00011111, 0b11111000,
+ 0b00111111, 0b11111100,
+ 0b01110000, 0b00001110,
+ 0b01100111, 0b11100110,
+ 0b00001111, 0b11110000,
+ 0b00011000, 0b00011000,
+ 0b00000011, 0b11000000,
+ 0b00000111, 0b11100000,
+ 0b00000100, 0b00100000,
+ 0b00000001, 0b10000000,
+ 0b00000001, 0b10000000,
+ 0b00000000, 0b00000000,
+ 0b00000000, 0b00000000,
+ 0b00000000, 0b00000000,
+};
+
+#endif
diff --git a/rover/src/libraries/hono_interaction/hono_interaction.cpp b/rover/src/libraries/hono_interaction/hono_interaction.cpp
new file mode 100644
index 0000000..b248a9a
--- /dev/null
+++ b/rover/src/libraries/hono_interaction/hono_interaction.cpp
@@ -0,0 +1,372 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Hono interaction library for Rover
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Version Summary:
+ * v1.2: Compliance changes for Hono Instance 0.5-M9
+ *
+ * Usage:
+ * To test the hono interaction library:
+ *
+ * registerDeviceToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", 4771);
+ * sendEventDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", 4771,"Bearing",0.5);
+ *
+ */
+
+#include <libraries/hono_interaction/hono_interaction.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+
+//Buffers to work with strings
+char buffer[256];
+char num_buffer[33];
+
+/**
+ * Function Name: handleCode
+ * Description: Handles code that is returned with HTTP response
+ * Arguments: int code
+ * Returns: Generates a status value
+ * If the action completed -> returns 1
+ * If the action failed -> returns 0
+ */
+int handleCode(int code)
+{
+ int status = 0;
+ switch (code)
+ {
+ case 200: //Accepted
+ printf("200 Accepted\n");
+ printf("Registration of device to Hono instance accepted.\n");
+ status = 1;
+ break;
+ case 201: //Created
+ printf("201 Created\n");
+ printf("Registration of device to Hono instance is done.\n");
+ status = 1;
+ break;
+ case 202:
+ status = 1; //Telemetry data accepted
+ break;
+ case 203:
+ case 204:
+ case 205:
+ case 206:
+ case 207:
+ case 208:
+ case 209:
+ status = 1;
+ break;
+ case 400:
+ fprintf(stderr, ("400 Bad Request\n"));
+ status = 0;
+ break;
+ case 403:
+ fprintf(stderr, ("403 Forbidden\n"));
+ status = 0;
+ break;
+ case 409:
+ fprintf(stderr, ("409 Conflict. A device with this ID is registered already. \n"));
+ status = 0;
+ break;
+ case 503:
+ fprintf(stderr, ("503 Service Unavailable. You may need to create a consumer."));
+ status = 0;
+ break;
+ case 401:
+ case 402:
+ case 404:
+ case 405:
+ case 406:
+ case 407:
+ case 408:
+ fprintf(stderr, ("Error in Hono connection. \n"));
+ status = 0;
+ break;
+ default:
+ status = 0;
+ break;
+ }
+ return status;
+}
+
+/**
+ * Function Name: registerDeviceToHonoInstance
+ * Description: Registers a device to Eclipse Hono instance.
+ * A device should be registered only once.
+ * Arguments: char * host_name
+ * int port
+ * char * tenant_name
+ * char * device_id
+ * Returns: Successfully returns status data.
+ * If the action completed -> returns 1
+ * If the action failed -> returns 0
+ */
+int registerDeviceToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id)
+{
+ FILE *fp;
+ int code;
+ int status;
+
+ //Prepare command as string
+ //Example: "curl -X POST -i -H 'Content-Type: application/json' -d '{"device-id": "4711"}' http://idial.institute:28080/registration/DEFAULT_TENANT"
+ sprintf(buffer, "curl -X POST -i -H 'Content-Type: application/json' -d '{\"device-id\":\"");
+ strcat(buffer, device_id);
+ strcat(buffer, "\"}' http://");
+ strcat(buffer, host_name);
+ strcat(buffer, ":");
+ snprintf(num_buffer, sizeof(num_buffer), "%d", port);
+ strcat(buffer, num_buffer);
+ num_buffer[0] = 0; //Clear array
+ strcat(buffer, "/registration/");
+ strcat(buffer, tenant_name);
+
+ //To redirect pipe to prevent stdout showing all outputs generated by curl
+ strcat(buffer, " 2>/dev/null"); //2>&1 would redirect to stderr, we choose to be able to parse returned code
+
+#ifdef DEBUG_DEVICE_REGISTRATION
+ //Print the command that is created
+ printf("Command=%s\n",buffer);
+#endif
+
+ //Execute the command
+ fp = popen(buffer,"r");
+
+ //Get and Parse the output
+ fgets(buffer, 13, fp); //Get the string HTTP/1.1 XXX
+
+ //Prepare the response code
+ sscanf(buffer, "HTTP/1.1 %d", &code);
+
+#ifdef DEBUG_DEVICE_REGISTRATION
+ //Print the code
+ printf("Code=%d\n",code);
+
+ //Print the response
+ printf("Response=%s\n",buffer);
+#endif
+
+ //Handle the code and return status: 1-succeeded 0-failed
+ status = handleCode(code);
+
+ //Close the file
+ fclose(fp);
+
+ //Return status
+ return status;
+}
+
+
+/**
+ * Function Name: sendTelemetryDataToHonoInstance
+ * Description: Sends telemetry data to a hono instance with given
+ * host name and port
+ * Arguments: char * host_name
+ * int port
+ * char * tenant_name
+ * char * device_id
+ * char * field
+ * double value
+ * Returns: Successfully returns status data.
+ * If the action completed -> returns 1
+ * If the action failed -> returns 0
+ */
+int sendTelemetryDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * field, double value)
+{
+ FILE *fp;
+ int code;
+ int status;
+
+ //Prepare command as string
+ //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"Bearing": 0.5}' http://idial.institute:8080/telemetry/DEFAULT_TENANT/4711"
+
+ //For Hono 0.5-M9
+ //Example: "curl -X POST -i -u sensor1@DEFAULT_TENANT:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' http://idial.institute:8080/telemetry"
+
+ //To get the information in dashboard, we use device ID as the entry name, and "value" as field.
+ //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"value": 0.5}' http://idial.institute:8080/telemetry/DEFAULT_TENANT/roverRearSensor"
+
+ sprintf(buffer, "curl -X POST -i -u sensor1@");
+ strcat(buffer, tenant_name);
+ strcat(buffer, ":hono-secret -H 'Content-Type: application/json' --data-binary '{\"");
+
+ strcat(buffer, field);
+ strcat(buffer, "\": ");
+ snprintf(num_buffer, sizeof(num_buffer), "%f", value);
+ strcat(buffer, num_buffer);
+ num_buffer[0] = 0; //Clear array
+
+ strcat(buffer, "}' http://");
+ strcat(buffer, host_name);
+ strcat(buffer, ":");
+ snprintf(num_buffer, sizeof(num_buffer), "%d", port);
+ strcat(buffer, num_buffer);
+ num_buffer[0] = 0; //Clear array
+ strcat(buffer, "/telemetry");
+
+ //To redirect pipe to prevent stdout showing all outputs generated by curl
+ strcat(buffer, " 2>/dev/null"); //2>&1 would redirect to stderr, we choose to be able to parse returned code
+
+#ifdef DEBUG_HTTP_RESPONSE
+ //Print the command that is created
+ printf("Command=%s\n",buffer);
+#endif
+
+ //Execute the command
+ fp = popen(buffer,"r");
+
+ //Get and Parse the output
+ fgets(buffer, 13, fp); //Get the string HTTP/1.1 XXX
+
+ //Prepare the response code
+ sscanf(buffer, "HTTP/1.1 %d", &code);
+
+#ifdef DEBUG_HTTP_RESPONSE
+ //Print the code
+ printf("Code=%d\n",code);
+
+ //Print the response
+ printf("Response=%s\n",buffer);
+#endif
+
+ if (code == 503)
+ {
+ pthread_exit(NULL);
+ }
+
+
+ //Handle the code and return status: 1-succeeded 0-failed
+ status = handleCode(code);
+
+ //Close the file
+ fclose(fp);
+
+ //Return status
+ return status;
+}
+
+
+/**
+ * Function Name: sendEventDataToHonoInstance
+ * Description: Sends event data to a hono instance with given
+ * host name and port
+ * Arguments: char * host_name
+ * int port
+ * char * tenant_name
+ * char * device_id
+ * char * field
+ * double value
+ * Returns: Successfully returns status data.
+ * If the action completed -> returns 1
+ * If the action failed -> returns 0
+ */
+int sendEventDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * field, double value)
+{
+ FILE *fp;
+ int code;
+ int status;
+
+ //Prepare command as string
+ //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"Bearing": 0.5}' http://idial.institute:8080/event/DEFAULT_TENANT/4711"
+
+ //For Hono 0.5-M9
+ //Example: "curl -X POST -i -u sensor1@DEFAULT_TENANT:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' http://idial.institute:8080/event"
+
+ //To get the information in dashboard, we use device ID as the entry name, and "value" as field.
+ //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"value": 0.5}' http://idial.institute:8080/event/DEFAULT_TENANT/roverRearSensor"
+
+ sprintf(buffer, "curl -X POST -i -u sensor1@");
+ strcat(buffer, tenant_name);
+ strcat(buffer, ":hono-secret -H 'Content-Type: application/json' --data-binary '{\"");
+
+ strcat(buffer, field);
+ strcat(buffer, "\": ");
+ snprintf(num_buffer, sizeof(num_buffer), "%f", value);
+ strcat(buffer, num_buffer);
+ num_buffer[0] = 0; //Clear array
+
+ strcat(buffer, "}' http://");
+ strcat(buffer, host_name);
+ strcat(buffer, ":");
+ snprintf(num_buffer, sizeof(num_buffer), "%d", port);
+ strcat(buffer, num_buffer);
+ num_buffer[0] = 0; //Clear array
+ strcat(buffer, "/event");
+
+ //To redirect pipe to prevent stdout showing all outputs generated by curl
+ strcat(buffer, " 2>/dev/null"); //2>&1 would redirect to stderr, we choose to be able to parse returned code
+
+#ifdef DEBUG_HTTP_RESPONSE
+ //Print the command that is created
+ printf("Command=%s\n",buffer);
+#endif
+
+ //Execute the command
+ fp = popen(buffer,"r");
+
+ //Get and Parse the output
+ fgets(buffer, 13, fp); //Get the string HTTP/1.1 XXX
+
+ //Prepare the response code XXX
+ sscanf(buffer, "HTTP/1.1 %d", &code);
+
+#ifdef DEBUG_HTTP_RESPONSE
+ //Print the code
+ printf("Code=%d\n",code);
+
+ //Print the response
+ printf("Response=%s\n",buffer);
+#endif
+
+ if (code == 503)
+ {
+ pthread_exit(NULL);
+ }
+
+ //Handle the code and return status: 1-succeeded 0-failed
+ status = handleCode(code);
+
+ //Close the file
+ fclose(fp);
+
+ //Return status
+ return status;
+}
+
+/**
+ * Function Name: registerSensorsToHonoInstance
+ * Description: If non registered already, this function
+ * registers all the sensors and other entries
+ * of APP4MC Rover as devices to Hono instance.
+ * for visualization of Raw data in Granafa/InfluxDB.
+ */
+int registerEntriesToHonoInstance (void)
+{
+ /*registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverFront");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverFrontLeft");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverFrontRight");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverRear");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverRearLeft");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverRearRight");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverBearing");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu1");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu2");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu3");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu4");
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "connectionCheck");*/
+ registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "4711");
+
+ return 1;
+}
+
diff --git a/rover/src/libraries/pthread_distribution_lib/pthread_distribution.cpp b/rover/src/libraries/pthread_distribution_lib/pthread_distribution.cpp
new file mode 100644
index 0000000..419522e
--- /dev/null
+++ b/rover/src/libraries/pthread_distribution_lib/pthread_distribution.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * pThread Core Affinity Pinning
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ *
+ */
+
+
+#include <libraries/pthread_distribution_lib/pthread_distribution.h>
+
+
+int placeThisThreadToCore(int core_id)
+{
+ int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
+ if (core_id < 0 || core_id >= num_cores)
+ return EINVAL;
+
+ cpu_set_t cpuset;
+ CPU_ZERO(&cpuset);
+ CPU_SET(core_id, &cpuset);
+
+ pthread_t current_thread = pthread_self();
+ int rc = pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &cpuset);
+ if (rc != 0) {
+ std::cerr << "Error calling pthread_setaffinity_np: " << rc << "\n";
+ }
+ return rc;
+}
+
+
+int placeAThreadToCore (pthread_t thread, int core_id)
+{
+ int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
+ if (core_id < 0 || core_id >= num_cores)
+ return EINVAL;
+
+ cpu_set_t cpuset;
+ CPU_ZERO(&cpuset);
+ CPU_SET(core_id, &cpuset);
+
+ int rc = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+ if (rc != 0) {
+ std::cerr << "Error calling pthread_setaffinity_np: " << rc << "\n";
+ }
+ return rc;
+}
+
diff --git a/rover/src/libraries/pthread_monitoring/collect_thread_name.cpp b/rover/src/libraries/pthread_monitoring/collect_thread_name.cpp
new file mode 100644
index 0000000..241ed3d
--- /dev/null
+++ b/rover/src/libraries/pthread_monitoring/collect_thread_name.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Function to collect thread name, process id, and kernel thread ids in a file for trace analysis
+ *
+ * Authors:
+ * M. Ozcelikors,
+ * <mozcelikors@gmail.com>
+ *
+ * Contributors:
+ *
+ * Update History:
+ * 30.05.2017 - function created
+ *
+ */
+
+#include <libraries/pthread_monitoring/collect_thread_name.h>
+
+#include <syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+pid_t gettid(void)
+{
+ return(syscall(SYS_gettid));
+}
+
+void CollectProcessID(void)
+{
+ ofstream myfile;
+
+ uint64_t process_id = getpid();
+
+ myfile.open("/home/pi/Threads_List.txt", std::ios::app); //Append
+
+ myfile << "Process ID = " << process_id << "\n";
+ myfile.close();
+}
+
+void CollectThreadName(char * thread_name)
+{
+ ofstream myfile;
+
+ uint64_t thread_id = gettid();
+
+ myfile.open("/home/pi/Threads_List.txt", std::ios::app); //Append
+
+ myfile << thread_name << " " << thread_id << "\n";
+ myfile.close();
+
+}
+
+void RefreshThreadList (void)
+{
+ ifstream fin("/home/pi/Threads_List.txt");
+ if (fin)
+ {
+ fin.close();
+ system("rm -rf /home/pi/Threads_List.txt");
+ }
+}
diff --git a/rover/src/libraries/status_library/status_library.cpp b/rover/src/libraries/status_library/status_library.cpp
new file mode 100644
index 0000000..28400ef
--- /dev/null
+++ b/rover/src/libraries/status_library/status_library.cpp
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Status library for getting WiFi, Ethernet Interface, Internet, Bluetooth, Hono Cloud status
+ *
+ * Contributors:
+ * M.Ozcelikors <mozcelikors@gmail.com>, created 04.10.2017
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include <libraries/status_library/status_library.h>
+#include <libraries/hono_interaction/hono_interaction.h>
+
+/* Returns 1 for ON, 0 for OFF
+ Assuming the connection is named by default as 'wlan0' */
+int retrieveWLANStatus (void)
+{
+ FILE *fp;
+ char buffer[2];
+
+ /* Execute the command */
+ fp = popen("ifconfig wlan0 2>&1 | grep 'RUNNING' | wc -l","r");
+
+ /* Read from pipe */
+ fgets(buffer, 2, fp);
+
+ /* Test the output char */
+ //printf("buf=%c\n",buffer[0]);
+
+ /* Return */
+ if (buffer[0] == '0')
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+/* Returns 1 for ON, 0 for OFF
+ Assuming the connection is named by default as 'eth0' */
+int retrieveETHStatus (void)
+{
+ FILE *fp;
+ char buffer[2];
+
+ /* Execute the command */
+ fp = popen("ifconfig eth0 2>&1 | grep 'RUNNING' | wc -l","r");
+
+ /* Read from pipe */
+ fgets(buffer, 2, fp);
+
+ /* Test the output char */
+ //printf("buf=%c\n",buffer[0]);
+
+ /* Return */
+ if (buffer[0] == '0')
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+/* Returns 1 for ON, 0 for OFF */
+int retrieveINTERNETStatus (void)
+{
+ FILE *fp;
+ char buffer[2];
+
+ /* Execute the command */
+ fp = popen("ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` 1>/dev/null 2>/dev/null && echo 1 || echo 0","r");
+
+ /* Read from pipe */
+ fgets(buffer, 2, fp);
+
+ /* Test the output char */
+ //printf("buf=%c\n",buffer[0]);
+
+ /* Return */
+ if (buffer[0] == '0')
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+// Returns 1 for ON, 0 for OFF
+int retrieveBLUETOOTHStatus (void)
+{
+ FILE *fp;
+ char buffer[2];
+
+ // Execute the command
+ fp = popen("service bluetooth status | grep inactive | wc -l","r");
+
+ /* Read from pipe */
+ fgets(buffer, 2, fp);
+
+ /* Test the output char */
+ //printf("buf=%c\n",buffer[0]);
+
+ /* Return */
+ if (buffer[0] == '1')
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+// Returns 1 for ON, 0 for OFF
+// hono_interaction.cpp -> registerEntriesToHonoInstance() should be called first. It is called in main()
+int retrieveHONOStatus (void)
+{
+ /* Dumb way to do it :) TODO: Make this more generic */
+ FILE *fp;
+ char buffer[20];
+ int code;
+ int status = 0;
+
+ /* Execute the command */
+ fp = popen("curl -X POST -i -u sensor1@DEFAULT_TENANT:hono-secret -H 'Content-Type: application/json' --data-binary '{\"connection_check\": 1}' http://idial.institute:8080/telemetry 2>/dev/null","r");
+
+ /* Read from pipe */
+ fgets(buffer, 13, fp); //Get the string HTTP/1.1 XXX
+
+ /* Prepare the response code XXX */
+ sscanf(buffer, "HTTP/1.1 %d", &code);
+
+ /* Debug */
+ //printf("Response=%s\n",buffer);
+
+ /* Get status */
+ status = handleCode(code);
+
+ /* Return */
+ if (status == 1)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
diff --git a/rover/src/libraries/timing/timing.cpp b/rover/src/libraries/timing/timing.cpp
new file mode 100644
index 0000000..82cd91b
--- /dev/null
+++ b/rover/src/libraries/timing/timing.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * Timing class created for thread performance analysis.
+ *
+ * Authors:
+ * M. Ozcelikors,
+ * <mozcelikors@gmail.com>
+ *
+ * Contributors:
+ *
+ * Update History:
+ * 23.03.2017 - initial revision
+ *
+ */
+
+#include <libraries/timing/timing.h>
+
+timing::timing() {
+ this->_TASK_ID = "None";
+ this->_DEADLINE_MISS_PERCENTAGE = 0;
+ this->_START_TIME = (clock_t) 0.0;
+ this->_END_TIME = (clock_t) 0.0;
+ this->_DEADLINE = 0.0;
+ this->_PERIOD = 0.0;
+ this->_EXECUTION_TIME=0.0;
+ this->_TOTAL_CYCLES=0;
+ this->_MISSED_CYCLES=0;
+ this->_PREV_SLACK_TIME=0.0;
+}
+
+timing::~timing() {
+ // TODO Auto-generated destructor stub
+}
+
+void timing::setDeadline(double deadline)
+{
+ this->_DEADLINE = deadline;
+}
+
+void timing::setPeriod(double period)
+{
+ this->_PERIOD = period;
+}
+
+void timing::recordStartTime(void)
+{
+ this->_START_TIME = std::clock();
+}
+
+void timing::recordEndTime(void)
+{
+ this->_END_TIME = std::clock();
+}
+
+void timing::calculateExecutionTime(void)
+{
+ this->_EXECUTION_TIME = ( this->_END_TIME - this->_START_TIME ) / (double) CLOCKS_PER_SEC;
+}
+
+void timing::calculatePreviousSlackTime(void)
+{
+ this->_PREV_SLACK_TIME = ( this->_START_TIME - this->_END_TIME ) / (double) CLOCKS_PER_SEC;
+}
+
+void timing::calculateDeadlineMissPercentage(void)
+{
+ this->_DEADLINE_MISS_PERCENTAGE = (int) (this->_MISSED_CYCLES / (double) this->_TOTAL_CYCLES)*100;
+}
+
+int timing::getTotalCycles(void)
+{
+ return this->_TOTAL_CYCLES;
+}
+int timing::getMissedCycles(void)
+{
+ return this->_MISSED_CYCLES;
+}
+double timing::getDeadline(void)
+{
+ return this->_DEADLINE;
+}
+double timing::getPeriod(void)
+{
+ return this->_PERIOD;
+}
+double timing::getStartTime(void)
+{
+ return this->_START_TIME / (double) CLOCKS_PER_SEC;
+}
+double timing::getEndTime(void)
+{
+ return this->_END_TIME / (double) CLOCKS_PER_SEC;
+}
+double timing::getPrevSlackTime(void)
+{
+ return this->_PREV_SLACK_TIME;
+}
+double timing::getExecutionTime(void)
+{
+ return this->_EXECUTION_TIME;
+}
+double timing::getDeadlineMissPercentage(void)
+{
+ return this->_DEADLINE_MISS_PERCENTAGE;
+}
+void timing::setTaskID(char * taskid)
+{
+ this->_TASK_ID = taskid;
+}
+char * timing::getTaskID(void)
+{
+ return this->_TASK_ID;
+}
+void timing::incrementTotalCycles(void)
+{
+ this->_TOTAL_CYCLES = this->_TOTAL_CYCLES + 1;
+}
+void timing::incrementMissedCycles(void)
+{
+ this->_MISSED_CYCLES = this->_MISSED_CYCLES + 1;
+}
+void timing::sleepToMatchPeriod(void)
+{
+ if (this->_EXECUTION_TIME > this->_DEADLINE)
+ {
+ this->_MISSED_CYCLES = this -> _MISSED_CYCLES + 1;
+ }
+ else
+ {
+ delayMicroseconds(getPeriod() * SECONDS_TO_MICROSECONDS);
+ }
+}
diff --git a/rover/src/roverapp.cpp b/rover/src/roverapp.cpp
new file mode 100644
index 0000000..773794a
--- /dev/null
+++ b/rover/src/roverapp.cpp
@@ -0,0 +1,494 @@
+/*
+ * Copyright (c) 2017 FH Dortmund and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Description:
+ * pThread skeleton implementation for PolarSys rover
+ *
+ * Authors:
+ * M. Ozcelikors, R.Hottger
+ * <mozcelikors@gmail.com> <robert.hoettger@fh-dortmund.de>
+ *
+ * Contributors:
+ * Gael Blondelle - API functions
+ *
+ * Update History:
+ * 02.02.2017 - first compilation
+ * 15.03.2017 - updated tasks for web-based driving
+ *
+ */
+
+#include <roverapp.h>
+
+#include <libraries/pthread_distribution_lib/pthread_distribution.h>
+#include <libraries/pthread_monitoring/collect_thread_name.h>
+#include <libraries/hono_interaction/hono_interaction.h>
+#include <libraries/timing/timing.h>
+
+#include <tasks/ultrasonic_sensor_grove_task.h>
+#include <tasks/temperature_task.h>
+#include <tasks/keycommand_task.h>
+#include <tasks/motordriver_task.h>
+#include <tasks/infrared_distance_task.h>
+#include <tasks/display_sensors_task.h>
+#include <tasks/compass_sensor_task.h>
+#include <tasks/record_timing_task.h>
+#include <tasks/ultrasonic_sensor_sr04_front_task.h>
+#include <tasks/ultrasonic_sensor_sr04_back_task.h>
+#include <tasks/adaptive_cruise_control_task.h>
+#include <tasks/parking_task.h>
+#include <tasks/hono_interaction_task.h>
+#include <tasks/cpu_logger_task.h>
+#include <tasks/oled_task.h>
+#include <tasks/srf02_task.h>
+#include <tasks/bluetooth_task.h>
+#include <tasks/external_gpio_task.h>
+#include <tasks/image_processing_task.h>
+#include <tasks/booth_modes_task.h>
+#include <tasks/socket_client_task.h>
+#include <tasks/socket_server_task.h>
+
+#include <api/basic_psys_rover.h>
+
+#include <interfaces.h>
+#include <signal.h>
+
+//Please comment the line below to work with SR-04 sensor instead of GROOVE for rear proximity sensing.
+//#define USE_GROOVE_SENSOR 1
+
+using namespace std;
+
+/* Threads */
+pthread_t ultrasonic_grove_thread;
+pthread_t ultrasonic_sr04_front_thread;
+pthread_t ultrasonic_sr04_back_thread;
+pthread_t temperature_thread;
+// pthread_t keycommand_input_thread;
+pthread_t motordriver_thread;
+pthread_t infrared_thread;
+pthread_t displaysensors_thread;
+pthread_t compasssensor_thread;
+pthread_t record_timing_thread;
+pthread_t adaptive_cruise_control_thread;
+pthread_t parking_thread;
+pthread_t hono_interaction_thread;
+pthread_t cpu_logger_thread;
+pthread_t oled_thread;
+pthread_t srf02_thread;
+pthread_t bluetooth_thread;
+pthread_t extgpio_thread;
+pthread_t booth_thread;
+pthread_t socket_client_thread;
+pthread_t socket_server_thread;
+
+/* Timing interfaces for thread measurement */
+timing_interface compass_task_ti;
+pthread_mutex_t compass_task_ti_l;
+
+timing_interface temperature_task_ti;
+pthread_mutex_t temperature_task_ti_l;
+
+timing_interface display_sensors_task_ti;
+pthread_mutex_t display_sensors_task_ti_l;
+
+timing_interface infrared_distance_task_ti;
+pthread_mutex_t infrared_distance_task_ti_l;
+
+timing_interface keycommand_task_ti;
+pthread_mutex_t keycommand_task_ti_l;
+
+timing_interface motordriver_task_ti;
+pthread_mutex_t motordriver_task_ti_l;
+
+timing_interface ultrasonic_grove_task_ti;
+pthread_mutex_t ultrasonic_grove_task_ti_l;
+
+timing_interface ultrasonic_sr04_front_task_ti;
+pthread_mutex_t ultrasonic_sr04_front_task_ti_l;
+
+timing_interface ultrasonic_sr04_back_task_ti;
+pthread_mutex_t ultrasonic_sr04_back_task_ti_l;
+
+timing_interface compass_sensor_task_ti;
+pthread_mutex_t compass_sensor_task_ti_l;
+
+timing_interface acc_task_ti;
+pthread_mutex_t acc_task_ti_l;
+
+timing_interface record_timing_task_ti;
+
+timing_interface parking_task_ti;
+pthread_mutex_t parking_task_ti_l;
+
+timing_interface hono_task_ti;
+pthread_mutex_t hono_task_ti_l;
+
+timing_interface cpu_logger_task_ti;
+pthread_mutex_t cpu_logger_task_ti_l;
+
+timing_interface oled_task_ti;
+pthread_mutex_t oled_task_ti_l;
+
+timing_interface srf02_task_ti;
+pthread_mutex_t srf02_task_ti_l;
+
+timing_interface bluetooth_task_ti;
+pthread_mutex_t bluetooth_task_ti_l;
+
+timing_interface extgpio_task_ti;
+pthread_mutex_t extgpio_task_ti_l;
+
+timing_interface imgproc_task_ti;
+pthread_mutex_t imgproc_task_ti_l;
+
+timing_interface booth_task_ti;
+pthread_mutex_t booth_task_ti_l;
+
+timing_interface socket_client_task_ti;
+pthread_mutex_t socket_client_task_ti_l;
+
+timing_interface socket_server_task_ti;
+pthread_mutex_t socket_server_task_ti_l;
+
+//Shared data between threads
+
+float temperature_shared;
+pthread_mutex_t temperature_lock;
+
+float humidity_shared;
+pthread_mutex_t humidity_lock;
+
+int distance_grove_shared;
+pthread_mutex_t distance_grove_lock;
+
+int distance_sr04_front_shared;
+pthread_mutex_t distance_sr04_front_lock;
+
+int distance_sr04_back_shared;
+pthread_mutex_t distance_sr04_back_lock;
+
+char keycommand_shared;
+pthread_mutex_t keycommand_lock;
+
+float infrared_shared[4];
+pthread_mutex_t infrared_lock;
+
+float bearing_shared;
+pthread_mutex_t compass_lock;
+
+float timing_shared;
+pthread_mutex_t timing_lock;
+
+int driving_mode;
+pthread_mutex_t driving_mode_lock;
+
+int speed_shared;
+pthread_mutex_t speed_lock;
+
+double cpu_util_shared[4];
+pthread_mutex_t cpu_util_shared_lock;
+
+int buzzer_status_shared;
+pthread_mutex_t buzzer_status_shared_lock;
+
+int shutdown_hook_shared;
+
+/* For proper termination */
+int running_flag;
+
+void exitHandler(int dummy)
+{
+ pthread_kill(ultrasonic_grove_thread, SIGTERM);
+ pthread_kill(ultrasonic_sr04_front_thread, SIGTERM);
+ pthread_kill(ultrasonic_sr04_back_thread, SIGTERM);
+ pthread_kill(temperature_thread, SIGTERM);
+ pthread_kill(motordriver_thread, SIGTERM);
+ pthread_kill(infrared_thread, SIGTERM);
+ pthread_kill(displaysensors_thread, SIGTERM);
+ pthread_kill(compasssensor_thread, SIGTERM);
+ pthread_kill(record_timing_thread, SIGTERM);
+ pthread_kill(adaptive_cruise_control_thread, SIGTERM);
+ pthread_kill(parking_thread, SIGTERM);
+ pthread_kill(hono_interaction_thread, SIGTERM);
+ pthread_kill(cpu_logger_thread, SIGTERM);
+ pthread_kill(oled_thread, SIGTERM);
+ pthread_kill(srf02_thread, SIGTERM);
+ pthread_kill(bluetooth_thread, SIGTERM);
+ pthread_kill(extgpio_thread, SIGTERM);
+ pthread_kill(booth_thread, SIGTERM);
+ pthread_kill(socket_client_thread, SIGTERM);
+ pthread_kill(socket_server_thread, SIGTERM);
+}
+
+int main()
+{
+ //Register all the entries as devices to cloud
+ registerEntriesToHonoInstance();
+
+ /* Add signals to exit threads properly */
+ signal(SIGINT, exitHandler);
+ signal(SIGTERM, exitHandler);
+ signal(SIGKILL, exitHandler);
+
+ RefreshThreadList();
+
+ CollectProcessID();
+
+ CollectThreadName("Main_Thread");
+
+ wiringPiSetup();
+
+ //Initialize shared data
+ temperature_shared = 0.0;
+ humidity_shared = 0.0;
+ distance_grove_shared = 0;
+ distance_sr04_front_shared = 0;
+ distance_sr04_back_shared = 0;
+ keycommand_shared = 'f';
+ infrared_shared[0] = 0.0;
+ infrared_shared[1] = 0.0;
+ infrared_shared[2] = 0.0;
+ infrared_shared[3] = 0.0;
+ bearing_shared = 0.0;
+ driving_mode = MANUAL;
+ speed_shared = FULL_SPEED;
+ buzzer_status_shared = 0;
+ shutdown_hook_shared = 0;
+ running_flag = 1;
+
+ //Initialize mutexes
+ pthread_mutex_init(&temperature_lock, NULL);
+ pthread_mutex_init(&humidity_lock, NULL);
+ pthread_mutex_init(&distance_grove_lock, NULL);
+ pthread_mutex_init(&distance_sr04_front_lock, NULL);
+ pthread_mutex_init(&distance_sr04_back_lock, NULL);
+ pthread_mutex_init(&keycommand_lock, NULL);
+ pthread_mutex_init(&infrared_lock, NULL);
+ pthread_mutex_init(&compass_lock, NULL);
+ pthread_mutex_init(&driving_mode_lock, NULL);
+ pthread_mutex_init(&buzzer_status_shared_lock, NULL);
+
+ //Thread objects
+ pthread_t main_thread = pthread_self();
+ pthread_setname_np(main_thread, "main_thread");
+
+
+
+ //Thread creation
+
+#ifdef USE_GROOVE_SENSOR
+ if(pthread_create(&ultrasonic_grove_thread, NULL, Ultrasonic_Sensor_Grove_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(ultrasonic_grove_thread, "US_grove"); //If name is too long, this function silently fails.
+ }
+#else
+ if(pthread_create(&ultrasonic_sr04_back_thread, NULL, Ultrasonic_Sensor_SR04_Back_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(ultrasonic_sr04_back_thread, "US_sr04_back"); //If name is too long, this function silently fails.
+ }
+#endif
+
+ if(pthread_create(&ultrasonic_sr04_front_thread, NULL, Ultrasonic_Sensor_SR04_Front_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(ultrasonic_sr04_front_thread, "US_sr04_front"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&temperature_thread, NULL, Temperature_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(temperature_thread, "temperature"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&motordriver_thread, NULL, MotorDriver_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(motordriver_thread, "motordriver"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&infrared_thread, NULL, InfraredDistance_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(infrared_thread, "infrared"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&displaysensors_thread, NULL, DisplaySensors_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(displaysensors_thread, "displaysensors"); //If name is too long, this function silently fails.
+ }
+
+ if (pthread_create(&compasssensor_thread, NULL, CompassSensor_Task, NULL)) {
+ fprintf(stderr, "Error creating compass sensor thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(compasssensor_thread, "compasssensor"); //If name is too long, this function silently fails.
+ }
+
+ if (pthread_create(&record_timing_thread, NULL, Record_Timing_Task, NULL)) {
+ fprintf(stderr, "Error creating compass sensor thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(record_timing_thread, "record_timing"); //If name is too long, this function silently fails.
+ }
+
+ if (pthread_create(&adaptive_cruise_control_thread, NULL, Adaptive_Cruise_Control_Task, NULL))
+ {
+ fprintf(stderr, "Error creating compass sensor thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(adaptive_cruise_control_thread, "acc"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&parking_thread, NULL, Parking_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(parking_thread, "parking"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&hono_interaction_thread, NULL, Hono_Interaction_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(hono_interaction_thread, "hono"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&cpu_logger_thread, NULL, Cpu_Logger_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(cpu_logger_thread, "cpulog"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&oled_thread, NULL, OLED_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(oled_thread, "oled"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&extgpio_thread, NULL, External_GPIO_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(extgpio_thread, "extg"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&booth_thread, NULL, Booth_Modes_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(booth_thread, "booth"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&socket_client_thread, NULL, Socket_Client_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(socket_client_thread, "SC"); //If name is too long, this function silently fails.
+ }
+
+ if(pthread_create(&socket_server_thread, NULL, Socket_Server_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(socket_server_thread, "SS"); //If name is too long, this function silently fails.
+ }
+
+ /*if(pthread_create(&srf02_thread, NULL, SRF02_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(srf02_thread, "srf02"); //If name is too long, this function silently fails.
+ }*/
+
+ /*if(pthread_create(&bluetooth_thread, NULL, Bluetooth_Task, NULL)) {
+ fprintf(stderr, "Error creating thread\n");
+ return 1;
+ }
+ else
+ {
+ pthread_setname_np(bluetooth_thread, "ble"); //If name is too long, this function silently fails.
+ }*/
+
+ //Core pinning/mapping
+/* placeAThreadToCore (main_thread, 1);
+ placeAThreadToCore (ultrasonic_sr04_front_thread, 2);
+#ifdef USE_GROOVE_SENSOR
+ placeAThreadToCore (ultrasonic_grove_thread, 3);
+#else
+ placeAThreadToCore (ultrasonic_sr04_back_thread, 3);
+#endif
+ placeAThreadToCore (temperature_thread, 3);
+ placeAThreadToCore (compasssensor_thread, 0);
+ placeAThreadToCore (motordriver_thread, 0);
+ placeAThreadToCore (adaptive_cruise_control_thread, 0);
+ placeAThreadToCore (parking_thread, 0);
+ placeAThreadToCore (infrared_thread, 2);
+ placeAThreadToCore (displaysensors_thread, 0);
+ placeAThreadToCore (webserver_motordrive_thread, 0);
+ */
+
+ while (running_flag)
+ {
+ //What main thread does should come here..
+ // ...
+ delayMicroseconds(1* SECONDS_TO_MICROSECONDS);
+ }
+ pthread_exit(NULL);
+
+ //Return 0
+ return 0;
+}
+