From 8c2380fa743856459b4db19e4c5e2203f0af63ac Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 15:38:38 +0200 Subject: [PATCH 01/39] Copied dummy module --- modules/ScenarioControl/CMakeLists.txt | 46 ++++++++++++++++++++++++ modules/ScenarioControl/README.md | 18 ++++++++++ modules/ScenarioControl/src/main.cpp | 50 ++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 modules/ScenarioControl/CMakeLists.txt create mode 100644 modules/ScenarioControl/README.md create mode 100644 modules/ScenarioControl/src/main.cpp diff --git a/modules/ScenarioControl/CMakeLists.txt b/modules/ScenarioControl/CMakeLists.txt new file mode 100644 index 000000000..58b3ae31a --- /dev/null +++ b/modules/ScenarioControl/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 2.8) + +project(ScenarioControl) +# This module is an example of how to set up a new module external to the Maestro executable + + +include_directories(inc) +include_directories(../../util/C/logging) +include_directories(../../util/C/time) +include_directories(../../util/C/MQBus) +include_directories(../../server/inc) +include(GNUInstallDirs) + + +# Create library +add_library(MaestroLogging + ../../util/C/logging/logging.h + ../../util/C/logging/logging.c +) + +add_library(MaestroTime + ../../util/C/time/maestroTime.h + ../../util/C/time/maestroTime.c +) + +add_library(MQBus + ../../util/C/MQBus/mqbus.h + ../../util/C/MQBus/mqbus.c +) + +# Create library +add_library(util + ../../server/src/util.c + ../../server/inc/util.h +) + +add_executable(ScenarioControl src/main.cpp) + +install(TARGETS ScenarioControl DESTINATION bin) + +target_link_libraries(ScenarioControl MaestroTime MaestroLogging util) +target_link_libraries(util MQBus MaestroTime MaestroLogging) +target_link_libraries(MQBus rt m) + + + diff --git a/modules/ScenarioControl/README.md b/modules/ScenarioControl/README.md new file mode 100644 index 000000000..e6bce0e21 --- /dev/null +++ b/modules/ScenarioControl/README.md @@ -0,0 +1,18 @@ +## Dummy module +TODO. + +### Build process +1) Ensure your util repo is up to date +2) Navigate to this README.md file +3) Create the build directory: ```mkdir build``` +4) Enter the build directory: ```cd build``` +5) Generate necessary cmake files: ```cmake ..``` +6) Build the module: ```make``` + +### Run the module +1) Ensure you have built the module +2) Navigate to the build directory +3) Run the module: ```./ScenarioControl``` +4) Run Maestro + +Note: steps 3 and 4 can be replaced with running the runServer.sh script in the top directory of this repository diff --git a/modules/ScenarioControl/src/main.cpp b/modules/ScenarioControl/src/main.cpp new file mode 100644 index 000000000..30ddbbb2b --- /dev/null +++ b/modules/ScenarioControl/src/main.cpp @@ -0,0 +1,50 @@ +#include +#include + +#include "logging.h" +#include "util.h" + +#define MODULE_NAME "Dummy" + +int main() +{ + COMMAND command = COMM_INV; + char mqRecvData[MQ_MSG_SIZE]; + const struct timespec sleepTimePeriod = {0,10000000}; + const struct timespec abortWaitTime = {1,0}; + struct timespec remTime; + + LogInit(MODULE_NAME,LOG_LEVEL_DEBUG); + LogMessage(LOG_LEVEL_INFO, "Task running with PID: %u",getpid()); + + // Initialize message bus connection + while(iCommInit()) + { + nanosleep(&sleepTimePeriod,&remTime); + } + + while(true) + { + if (iCommRecv(&command,mqRecvData,MQ_MSG_SIZE,nullptr) < 0) + { + util_error("Message bus receive error"); + } + + switch (command) { + case COMM_INV: + nanosleep(&sleepTimePeriod,&remTime); + break; + case COMM_OBC_STATE: + break; + case COMM_STRT: + nanosleep(&abortWaitTime,&remTime); + LogMessage(LOG_LEVEL_WARNING,"Sending ABORT"); + iCommSend(COMM_ABORT,nullptr,0); + break; + default: + LogMessage(LOG_LEVEL_INFO,"Received command %u",command); + } + } + + return 0; +} From e27dc35a6a505fb2c1d135a11d21aa14c4f8d7ec Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 15:43:12 +0200 Subject: [PATCH 02/39] Util module reference update --- util | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util b/util index 32d9e9ba1..ea293911d 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit 32d9e9ba1aaa71332d177628a5b87e216158cf48 +Subproject commit ea293911d756e7c109f0c5406556cdd4f97793ea From 81bcbd831403287c74af8f6fc27c98693ff14eb3 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 15:45:47 +0200 Subject: [PATCH 03/39] Removed dummy module functionality --- modules/ScenarioControl/src/main.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/modules/ScenarioControl/src/main.cpp b/modules/ScenarioControl/src/main.cpp index 30ddbbb2b..f089cdbb8 100644 --- a/modules/ScenarioControl/src/main.cpp +++ b/modules/ScenarioControl/src/main.cpp @@ -4,7 +4,7 @@ #include "logging.h" #include "util.h" -#define MODULE_NAME "Dummy" +#define MODULE_NAME "ScenarioControl" int main() { @@ -34,13 +34,6 @@ int main() case COMM_INV: nanosleep(&sleepTimePeriod,&remTime); break; - case COMM_OBC_STATE: - break; - case COMM_STRT: - nanosleep(&abortWaitTime,&remTime); - LogMessage(LOG_LEVEL_WARNING,"Sending ABORT"); - iCommSend(COMM_ABORT,nullptr,0); - break; default: LogMessage(LOG_LEVEL_INFO,"Received command %u",command); } From 2a590c1ab43514ab0afa5da41ae33108b0286b19 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 15:47:58 +0200 Subject: [PATCH 04/39] Removed unused variable --- modules/ScenarioControl/src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ScenarioControl/src/main.cpp b/modules/ScenarioControl/src/main.cpp index f089cdbb8..4bc11d538 100644 --- a/modules/ScenarioControl/src/main.cpp +++ b/modules/ScenarioControl/src/main.cpp @@ -11,7 +11,6 @@ int main() COMMAND command = COMM_INV; char mqRecvData[MQ_MSG_SIZE]; const struct timespec sleepTimePeriod = {0,10000000}; - const struct timespec abortWaitTime = {1,0}; struct timespec remTime; LogInit(MODULE_NAME,LOG_LEVEL_DEBUG); From 910c9d3259cb506a064ba4a2a414a72e7372420c Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 15:50:57 +0200 Subject: [PATCH 05/39] updated server run script --- runServer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runServer.sh b/runServer.sh index f6e87f4d0..92d205629 100755 --- a/runServer.sh +++ b/runServer.sh @@ -2,7 +2,7 @@ #### User settings # Modify this array by adding more modules to include them in the execution -MODULES=(dummy) +MODULES=(ScenarioControl) From 12f093f8dae3702d13fb1bc472b44d87a09f5b06 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 16:04:13 +0200 Subject: [PATCH 06/39] Updated cmakelists to include the new class --- modules/ScenarioControl/CMakeLists.txt | 24 +++++++++++++++--------- modules/ScenarioControl/src/trigger.cpp | 6 ++++++ modules/ScenarioControl/src/trigger.h | 11 +++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 modules/ScenarioControl/src/trigger.cpp create mode 100644 modules/ScenarioControl/src/trigger.h diff --git a/modules/ScenarioControl/CMakeLists.txt b/modules/ScenarioControl/CMakeLists.txt index 58b3ae31a..43789730b 100644 --- a/modules/ScenarioControl/CMakeLists.txt +++ b/modules/ScenarioControl/CMakeLists.txt @@ -5,6 +5,7 @@ project(ScenarioControl) include_directories(inc) +include_directories(src) include_directories(../../util/C/logging) include_directories(../../util/C/time) include_directories(../../util/C/MQBus) @@ -14,31 +15,36 @@ include(GNUInstallDirs) # Create library add_library(MaestroLogging - ../../util/C/logging/logging.h - ../../util/C/logging/logging.c + ../../util/C/logging/logging.h + ../../util/C/logging/logging.c ) add_library(MaestroTime - ../../util/C/time/maestroTime.h - ../../util/C/time/maestroTime.c + ../../util/C/time/maestroTime.h + ../../util/C/time/maestroTime.c ) add_library(MQBus - ../../util/C/MQBus/mqbus.h - ../../util/C/MQBus/mqbus.c + ../../util/C/MQBus/mqbus.h + ../../util/C/MQBus/mqbus.c ) # Create library add_library(util - ../../server/src/util.c - ../../server/inc/util.h + ../../server/src/util.c + ../../server/inc/util.h +) + +add_library(Trigger + src/trigger.cpp + inc/trigger.h ) add_executable(ScenarioControl src/main.cpp) install(TARGETS ScenarioControl DESTINATION bin) -target_link_libraries(ScenarioControl MaestroTime MaestroLogging util) +target_link_libraries(ScenarioControl MaestroTime MaestroLogging util Trigger) target_link_libraries(util MQBus MaestroTime MaestroLogging) target_link_libraries(MQBus rt m) diff --git a/modules/ScenarioControl/src/trigger.cpp b/modules/ScenarioControl/src/trigger.cpp new file mode 100644 index 000000000..6ce34e700 --- /dev/null +++ b/modules/ScenarioControl/src/trigger.cpp @@ -0,0 +1,6 @@ +#include "trigger.h" + +Trigger::Trigger() +{ + +} diff --git a/modules/ScenarioControl/src/trigger.h b/modules/ScenarioControl/src/trigger.h new file mode 100644 index 000000000..f043b5170 --- /dev/null +++ b/modules/ScenarioControl/src/trigger.h @@ -0,0 +1,11 @@ +#ifndef TRIGGER_H +#define TRIGGER_H + + +class Trigger +{ +public: + Trigger(); +}; + +#endif // TRIGGER_H \ No newline at end of file From 623f1ec4a3b63565bfa552f582135a918358cf09 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 16:04:40 +0200 Subject: [PATCH 07/39] moved header file --- modules/ScenarioControl/src/trigger.h | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 modules/ScenarioControl/src/trigger.h diff --git a/modules/ScenarioControl/src/trigger.h b/modules/ScenarioControl/src/trigger.h deleted file mode 100644 index f043b5170..000000000 --- a/modules/ScenarioControl/src/trigger.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TRIGGER_H -#define TRIGGER_H - - -class Trigger -{ -public: - Trigger(); -}; - -#endif // TRIGGER_H \ No newline at end of file From b20ff3832256ccab330faa4636cb4041bdecdfc0 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 16:04:54 +0200 Subject: [PATCH 08/39] secod part of the move --- modules/ScenarioControl/inc/trigger.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 modules/ScenarioControl/inc/trigger.h diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h new file mode 100644 index 000000000..f043b5170 --- /dev/null +++ b/modules/ScenarioControl/inc/trigger.h @@ -0,0 +1,11 @@ +#ifndef TRIGGER_H +#define TRIGGER_H + + +class Trigger +{ +public: + Trigger(); +}; + +#endif // TRIGGER_H \ No newline at end of file From 38a92a772b1d121af8f67e29f1710935a94a2445 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 16:23:23 +0200 Subject: [PATCH 09/39] Added ISO spec trigger types as enum --- modules/ScenarioControl/inc/trigger.h | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index f043b5170..8c4941214 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -1,11 +1,41 @@ #ifndef TRIGGER_H #define TRIGGER_H +#include class Trigger { public: Trigger(); + uint16_t getTriggerType(); + +private: + enum TriggerType { + UNDEFINED = 0x0000, + TRIGGER_TYPE_1 = 0x0001, + SPEED = 0x0010, + DISTANCE = 0x0020, + ACCELERATION = 0x0030, + LANE_CHANGED = 0x0040, + LANE_OFFSET = 0x0050, + POSITION_REACHED = 0x0060, + POSITION_LEFT = 0x0061, + POSITION_OFFSET = 0x0062, + STEERING_ANGLE = 0x0070, + THROTTLE_VALUE = 0x0080, + BRAKE = 0x0090, + ACTIVE_TRAJECTORY = 0x00A0, + OTHER_OBJECT_FEATURE = 0x00B0, + INFRASTRUCTURE = 0x00C0, + TEST_SCENARIO_EVENT = 0x00D0, + MISC_DIGITAL_INPUT = 0x00E0, + MISC_ANALOG_INPUT = 0x00F0, + TIMER_EVENT_OCCURRED = 0x0100, + MODE_CHANGED = 0x0110, + UNAVAILABLE = 0xFFFF + } triggerType = UNDEFINED; + + }; -#endif // TRIGGER_H \ No newline at end of file +#endif // TRIGGER_H From b86859d1286800563b6d00b96dead4860d7de11e Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Mon, 1 Jul 2019 17:35:27 +0200 Subject: [PATCH 10/39] Added abstract class definition which can handle ISO spec contents --- modules/ScenarioControl/inc/trigger.h | 102 +++++++++++++++++++------- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 8c4941214..3bde34884 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -2,39 +2,89 @@ #define TRIGGER_H #include +#include +#include class Trigger { public: Trigger(); - uint16_t getTriggerType(); + virtual ~Trigger(); -private: - enum TriggerType { - UNDEFINED = 0x0000, - TRIGGER_TYPE_1 = 0x0001, - SPEED = 0x0010, - DISTANCE = 0x0020, - ACCELERATION = 0x0030, - LANE_CHANGED = 0x0040, - LANE_OFFSET = 0x0050, - POSITION_REACHED = 0x0060, - POSITION_LEFT = 0x0061, - POSITION_OFFSET = 0x0062, - STEERING_ANGLE = 0x0070, - THROTTLE_VALUE = 0x0080, - BRAKE = 0x0090, - ACTIVE_TRAJECTORY = 0x00A0, - OTHER_OBJECT_FEATURE = 0x00B0, - INFRASTRUCTURE = 0x00C0, - TEST_SCENARIO_EVENT = 0x00D0, - MISC_DIGITAL_INPUT = 0x00E0, - MISC_ANALOG_INPUT = 0x00F0, - TIMER_EVENT_OCCURRED = 0x0100, - MODE_CHANGED = 0x0110, - UNAVAILABLE = 0xFFFF - } triggerType = UNDEFINED; + virtual uint16_t getType(); + virtual uint16_t getID(); + + virtual void setType(uint16_t triggerType); + virtual void setID(uint16_t triggerID); + + virtual int8_t appendTriggerParameter(uint32_t triggerParameter); + + friend std::ostream& operator<<(std::ostream &strm, const Trigger &a) { + return strm << "TODO"; + } +protected: + typedef enum { + TRIGGER_UNDEFINED = 0x0000, + TRIGGER_TYPE_1 = 0x0001, + TRIGGER_SPEED = 0x0010, + TRIGGER_DISTANCE = 0x0020, + TRIGGER_ACCELERATION = 0x0030, + TRIGGER_LANE_CHANGED = 0x0040, + TRIGGER_LANE_OFFSET = 0x0050, + TRIGGER_POSITION_REACHED = 0x0060, + TRIGGER_POSITION_LEFT = 0x0061, + TRIGGER_POSITION_OFFSET = 0x0062, + TRIGGER_STEERING_ANGLE = 0x0070, + TRIGGER_THROTTLE_VALUE = 0x0080, + TRIGGER_BRAKE = 0x0090, + TRIGGER_ACTIVE_TRAJECTORY = 0x00A0, + TRIGGER_OTHER_OBJECT_FEATURE = 0x00B0, + TRIGGER_INFRASTRUCTURE = 0x00C0, + TRIGGER_TEST_SCENARIO_EVENT = 0x00D0, + TRIGGER_MISC_DIGITAL_INPUT = 0x00E0, + TRIGGER_MISC_ANALOG_INPUT = 0x00F0, + TRIGGER_TIMER_EVENT_OCCURRED = 0x0100, + TRIGGER_MODE_CHANGED = 0x0110, + TRIGGER_UNAVAILABLE = 0xFFFF + } TriggerType_t; + + typedef enum { + TRIGGER_PARAMETER_FALSE = 0x00000000, + TRIGGER_PARAMETER_TRUE = 0x00000001, + TRIGGER_PARAMETER_RELEASED = 0x00000010, + TRIGGER_PARAMETER_PRESSED = 0x00000011, + TRIGGER_PARAMETER_LOW = 0x00000020, + TRIGGER_PARAMETER_HIGH = 0x00000021, + TRIGGER_PARAMETER_RISING_EDGE = 0x00000022, + TRIGGER_PARAMETER_FALLING_EDGE = 0x00000023, + TRIGGER_PARAMETER_ANY_EDGE = 0x00000024, + TRIGGER_PARAMETER_RELATIVE = 0x00000030, + TRIGGER_PARAMETER_ABSOLUTE = 0x00000031, + TRIGGER_PARAMETER_VALUE = 0x00000040, + TRIGGER_PARAMETER_MIN = 0x00000050, + TRIGGER_PARAMETER_MAX = 0x00000051, + TRIGGER_PARAMETER_MEAN = 0x00000052, + TRIGGER_PARAMETER_EQUAL_TO = 0x00000060, + TRIGGER_PARAMETER_GREATER_THAN = 0x00000061, + TRIGGER_PARAMETER_GREATER_THAN_OR_EQUAL_TO = 0x00000062, + TRIGGER_PARAMETER_LESS_THAN = 0x00000063, + TRIGGER_PARAMETER_LESS_THAN_OR_EQUAL_TO = 0x00000064, + TRIGGER_PARAMETER_NOT_EQUAL_TO = 0x00000065, + TRIGGER_PARAMETER_X = 0x00000070, + TRIGGER_PARAMETER_Y = 0x00000071, + TRIGGER_PARAMETER_Z = 0x00000072, + TRIGGER_PARAMETER_TIME = 0x00000080, + TRIGGER_PARAMETER_DATE = 0x00000081, + TRIGGER_PARAMETER_RULE = 0x000000A0, + TRIGGER_PARAMETER_UNAVAILABLE = 0xFFFFFFFF + } TriggerParameter_t; + + +private: + uint16_t triggerID; + TriggerType_t triggerType = TRIGGER_UNDEFINED; + std::set triggerParameters; }; From 553e306c698f156037080666de4db33c568776db Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 09:11:15 +0200 Subject: [PATCH 11/39] Moved typedefs to public --- modules/ScenarioControl/inc/trigger.h | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 3bde34884..0c949ad35 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -8,22 +8,7 @@ class Trigger { public: - Trigger(); - virtual ~Trigger(); - - virtual uint16_t getType(); - virtual uint16_t getID(); - - virtual void setType(uint16_t triggerType); - virtual void setID(uint16_t triggerID); - - virtual int8_t appendTriggerParameter(uint32_t triggerParameter); - - friend std::ostream& operator<<(std::ostream &strm, const Trigger &a) { - return strm << "TODO"; - } - -protected: + /*! Typedefs */ typedef enum { TRIGGER_UNDEFINED = 0x0000, TRIGGER_TYPE_1 = 0x0001, @@ -80,6 +65,27 @@ class Trigger TRIGGER_PARAMETER_UNAVAILABLE = 0xFFFFFFFF } TriggerParameter_t; + /*! Constructor */ + Trigger(); + + /*! Destructor */ + virtual ~Trigger(); + + /*! Getters */ + virtual uint16_t getType(); + virtual uint16_t getID(); + + /*! Setters */ + virtual void setType(uint16_t triggerType); + virtual void setID(uint16_t triggerID); + + virtual int8_t appendTriggerParameter(uint32_t triggerParameter); + + /*! To string */ + friend std::ostream& operator<<(std::ostream &strm, const Trigger &a) { + return strm << "TODO"; + } + private: uint16_t triggerID; From 8e39ee104f25481266817057dc288c5ba405c9bd Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 12:28:50 +0200 Subject: [PATCH 12/39] Added class for brake trigger --- modules/ScenarioControl/CMakeLists.txt | 4 +++- modules/ScenarioControl/inc/braketrigger.h | 12 ++++++++++++ modules/ScenarioControl/src/braketrigger.cpp | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 modules/ScenarioControl/inc/braketrigger.h create mode 100644 modules/ScenarioControl/src/braketrigger.cpp diff --git a/modules/ScenarioControl/CMakeLists.txt b/modules/ScenarioControl/CMakeLists.txt index 43789730b..fee8ca620 100644 --- a/modules/ScenarioControl/CMakeLists.txt +++ b/modules/ScenarioControl/CMakeLists.txt @@ -36,8 +36,10 @@ add_library(util ) add_library(Trigger - src/trigger.cpp inc/trigger.h + src/trigger.cpp + inc/braketrigger.h + src/braketrigger.cpp ) add_executable(ScenarioControl src/main.cpp) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h new file mode 100644 index 000000000..ab92d398a --- /dev/null +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -0,0 +1,12 @@ +#ifndef BRAKETRIGGER_H +#define BRAKETRIGGER_H + +#include "trigger.h" + +class BrakeTrigger : public Trigger +{ + BrakeTrigger(); + ~BrakeTrigger(); +}; + +#endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp new file mode 100644 index 000000000..7e29165c9 --- /dev/null +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -0,0 +1,11 @@ +#include "braketrigger.h" + +BrakeTrigger::BrakeTrigger() +{ + +} + +uint16_t BrakeTrigger::getType() +{ + +} From 96cb272b672364bd6c2f15167a277cdaff7cc2bc Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 12:29:28 +0200 Subject: [PATCH 13/39] Changed return type of getType --- modules/ScenarioControl/inc/trigger.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 0c949ad35..afccad8a7 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -72,11 +72,10 @@ class Trigger virtual ~Trigger(); /*! Getters */ - virtual uint16_t getType(); + virtual TriggerType_t getType(); virtual uint16_t getID(); /*! Setters */ - virtual void setType(uint16_t triggerType); virtual void setID(uint16_t triggerID); virtual int8_t appendTriggerParameter(uint32_t triggerParameter); From fbd09f3835e09bf3c3fb9531169bbec7652b58e7 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 13:58:31 +0200 Subject: [PATCH 14/39] Moved some function definitions to Trigger class --- modules/ScenarioControl/inc/braketrigger.h | 7 ++++++- modules/ScenarioControl/inc/braketrigger.h.autosave | 13 +++++++++++++ modules/ScenarioControl/inc/trigger.h | 10 ++++++---- modules/ScenarioControl/src/braketrigger.cpp | 7 +------ modules/ScenarioControl/src/trigger.cpp | 4 ++-- 5 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 modules/ScenarioControl/inc/braketrigger.h.autosave diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index ab92d398a..2a7be99c0 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -5,8 +5,13 @@ class BrakeTrigger : public Trigger { - BrakeTrigger(); +public: + //BrakeTrigger(TriggerType_t triggerID); ~BrakeTrigger(); + + TriggerType_t getType() { return TRIGGER_BRAKE; } + + TriggerReturnCode_t appendTriggerParameter(uint32_t triggerParameter); }; #endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/inc/braketrigger.h.autosave b/modules/ScenarioControl/inc/braketrigger.h.autosave new file mode 100644 index 000000000..8f1c342fa --- /dev/null +++ b/modules/ScenarioControl/inc/braketrigger.h.autosave @@ -0,0 +1,13 @@ +#ifndef BRAKETRIGGER_H +#define BRAKETRIGGER_H + +#include "trigger.h" + +class BrakeTrigger : public Trigger +{ +public: + TriggerType_t getType() { return TRIGGER_BRAKE; } + TriggerReturnCode_t appendTriggerParameter(uint32_t triggerParameter); +}; + +#endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index afccad8a7..3ea34376b 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -65,20 +65,22 @@ class Trigger TRIGGER_PARAMETER_UNAVAILABLE = 0xFFFFFFFF } TriggerParameter_t; + typedef enum {OK} TriggerReturnCode_t; + /*! Constructor */ - Trigger(); + Trigger(TriggerType_t triggerID); /*! Destructor */ virtual ~Trigger(); /*! Getters */ virtual TriggerType_t getType(); - virtual uint16_t getID(); + uint16_t getID() { return this->triggerID; } /*! Setters */ - virtual void setID(uint16_t triggerID); + void setID(uint16_t triggerID) { this->triggerID = triggerID; } - virtual int8_t appendTriggerParameter(uint32_t triggerParameter); + virtual TriggerReturnCode_t appendTriggerParameter(uint32_t triggerParameter); /*! To string */ friend std::ostream& operator<<(std::ostream &strm, const Trigger &a) { diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 7e29165c9..eb93a3d72 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -1,11 +1,6 @@ #include "braketrigger.h" -BrakeTrigger::BrakeTrigger() -{ - -} - -uint16_t BrakeTrigger::getType() +Trigger::TriggerReturnCode_t BrakeTrigger::appendTriggerParameter(uint32_t triggerParameter) { } diff --git a/modules/ScenarioControl/src/trigger.cpp b/modules/ScenarioControl/src/trigger.cpp index 6ce34e700..8ae2e9486 100644 --- a/modules/ScenarioControl/src/trigger.cpp +++ b/modules/ScenarioControl/src/trigger.cpp @@ -1,6 +1,6 @@ #include "trigger.h" -Trigger::Trigger() +Trigger::Trigger(TriggerType_t triggerID) { - + this->triggerID = triggerID; } From b5460e34c4f1362f7f024f458d2576b013d07c08 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 15:31:27 +0200 Subject: [PATCH 15/39] Removed accidental include --- modules/ScenarioControl/inc/braketrigger.h.autosave | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 modules/ScenarioControl/inc/braketrigger.h.autosave diff --git a/modules/ScenarioControl/inc/braketrigger.h.autosave b/modules/ScenarioControl/inc/braketrigger.h.autosave deleted file mode 100644 index 8f1c342fa..000000000 --- a/modules/ScenarioControl/inc/braketrigger.h.autosave +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef BRAKETRIGGER_H -#define BRAKETRIGGER_H - -#include "trigger.h" - -class BrakeTrigger : public Trigger -{ -public: - TriggerType_t getType() { return TRIGGER_BRAKE; } - TriggerReturnCode_t appendTriggerParameter(uint32_t triggerParameter); -}; - -#endif // BRAKETRIGGER_H From c0fb63d26da8487f36d88a6db4cd95520587f6e2 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 15:31:56 +0200 Subject: [PATCH 16/39] Implemented check on allowed parameters --- modules/ScenarioControl/inc/braketrigger.h | 7 ++++- modules/ScenarioControl/src/braketrigger.cpp | 29 +++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 2a7be99c0..5d79abd15 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -11,7 +11,12 @@ class BrakeTrigger : public Trigger TriggerType_t getType() { return TRIGGER_BRAKE; } - TriggerReturnCode_t appendTriggerParameter(uint32_t triggerParameter); + TriggerReturnCode_t appendTriggerParameter(TriggerParameter_t triggerParameter); + +private: + std::set triggerParameters; + + TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t triggerParameter); }; #endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index eb93a3d72..0a1843f72 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -1,6 +1,33 @@ #include "braketrigger.h" -Trigger::TriggerReturnCode_t BrakeTrigger::appendTriggerParameter(uint32_t triggerParameter) +static constexpr Trigger::TriggerParameter_t acceptedParameters[] = { + Trigger::TRIGGER_PARAMETER_FALSE, + Trigger::TRIGGER_PARAMETER_TRUE, + Trigger::TRIGGER_PARAMETER_RELEASED, + Trigger::TRIGGER_PARAMETER_PRESSED, + Trigger::TRIGGER_PARAMETER_LOW, + Trigger::TRIGGER_PARAMETER_HIGH, + Trigger::TRIGGER_PARAMETER_RISING_EDGE, + Trigger::TRIGGER_PARAMETER_FALLING_EDGE, + Trigger::TRIGGER_PARAMETER_ANY_EDGE, + Trigger::TRIGGER_PARAMETER_EQUAL_TO, + Trigger::TRIGGER_PARAMETER_NOT_EQUAL_TO +}; + +Trigger::TriggerReturnCode_t BrakeTrigger::appendTriggerParameter(Trigger::TriggerParameter_t triggerParameter) { + TriggerReturnCode_t retval = NOT_OK; + + if( (retval = checkTriggerParameter(triggerParameter)) != OK) + return retval; } + +Trigger::TriggerReturnCode_t BrakeTrigger::checkTriggerParameter(TriggerParameter_t triggerParameter) +{ + for (const TriggerParameter_t param : acceptedParameters) { + if (triggerParameter == param) + return OK; + } + return NOT_OK; +} From 6e0fbb625b3bae0ea1c149d865826d2e3390ada3 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Tue, 2 Jul 2019 15:32:32 +0200 Subject: [PATCH 17/39] Minor modifications on trigger header --- modules/ScenarioControl/inc/trigger.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 3ea34376b..4dd6526a7 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -65,22 +65,29 @@ class Trigger TRIGGER_PARAMETER_UNAVAILABLE = 0xFFFFFFFF } TriggerParameter_t; - typedef enum {OK} TriggerReturnCode_t; + typedef uint16_t TriggerID_t; + + typedef enum {OK, NOT_OK} TriggerReturnCode_t; + /*! Constructor */ Trigger(TriggerType_t triggerID); + /*! Destructor */ virtual ~Trigger(); + /*! Getters */ virtual TriggerType_t getType(); uint16_t getID() { return this->triggerID; } + /*! Setters */ void setID(uint16_t triggerID) { this->triggerID = triggerID; } - virtual TriggerReturnCode_t appendTriggerParameter(uint32_t triggerParameter); + virtual TriggerReturnCode_t appendTriggerParameter(TriggerParameter_t triggerParameter); + /*! To string */ friend std::ostream& operator<<(std::ostream &strm, const Trigger &a) { @@ -89,10 +96,10 @@ class Trigger private: - uint16_t triggerID; - TriggerType_t triggerType = TRIGGER_UNDEFINED; + TriggerID_t triggerID; std::set triggerParameters; + virtual TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t param); }; #endif // TRIGGER_H From ff04a7b7700a922031076fc7e0ce134199832478 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:39:02 +0200 Subject: [PATCH 18/39] Made parameters an ordered list --- modules/ScenarioControl/inc/trigger.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 4dd6526a7..a0a44b49f 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -4,6 +4,7 @@ #include #include #include +#include class Trigger { @@ -97,7 +98,10 @@ class Trigger private: TriggerID_t triggerID; - std::set triggerParameters; + std::list parameters; + + virtual std::set getAcceptedParameters() + { return {TRIGGER_PARAMETER_UNAVAILABLE}; } virtual TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t param); }; From a1a531cf709a951c582cb693fd3471a13a96b167 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:40:06 +0200 Subject: [PATCH 19/39] Made initialization variable be an ID type --- modules/ScenarioControl/inc/trigger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index a0a44b49f..e9253dc08 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -72,7 +72,7 @@ class Trigger /*! Constructor */ - Trigger(TriggerType_t triggerID); + Trigger(TriggerID_t triggerID); /*! Destructor */ From e5528ee18270d0715b2381c0eb5fddb4593835cd Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:40:52 +0200 Subject: [PATCH 20/39] Moved a bunch of functions to be virtual --- modules/ScenarioControl/inc/trigger.h | 15 ++++++++++----- modules/ScenarioControl/src/trigger.cpp | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index e9253dc08..d03e7a503 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -80,22 +80,28 @@ class Trigger /*! Getters */ - virtual TriggerType_t getType(); + virtual TriggerType_t getType() = 0; uint16_t getID() { return this->triggerID; } /*! Setters */ void setID(uint16_t triggerID) { this->triggerID = triggerID; } - virtual TriggerReturnCode_t appendTriggerParameter(TriggerParameter_t triggerParameter); + virtual TriggerReturnCode_t appendParameter(TriggerParameter_t triggerParameter) = 0; + virtual TriggerReturnCode_t parseParameters() = 0; // TODO: Maybe make this a Trigger function /*! To string */ - friend std::ostream& operator<<(std::ostream &strm, const Trigger &a) { - return strm << "TODO"; + friend std::ostream& operator<<(std::ostream &strm, const Trigger &trig) { + return strm << "TODO, but here is the ID: " << trig.triggerID; } + +protected: + TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t triggerParameter); + + private: TriggerID_t triggerID; std::list parameters; @@ -103,7 +109,6 @@ class Trigger virtual std::set getAcceptedParameters() { return {TRIGGER_PARAMETER_UNAVAILABLE}; } - virtual TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t param); }; #endif // TRIGGER_H diff --git a/modules/ScenarioControl/src/trigger.cpp b/modules/ScenarioControl/src/trigger.cpp index 8ae2e9486..d0fe1baee 100644 --- a/modules/ScenarioControl/src/trigger.cpp +++ b/modules/ScenarioControl/src/trigger.cpp @@ -1,6 +1,28 @@ #include "trigger.h" -Trigger::Trigger(TriggerType_t triggerID) + +Trigger::Trigger(TriggerID_t triggerID) { this->triggerID = triggerID; } + +Trigger::~Trigger() +{ + +} + + +/*! + * \brief Trigger::checkTriggerParameter Checks if the queried parameter is within the list of accepted parameters + * \param triggerParameter Queried parameter + * \return According to ::TriggerReturnCode_t + */ +Trigger::TriggerReturnCode_t Trigger::checkTriggerParameter(TriggerParameter_t triggerParameter) +{ + std::set acceptedParameters = getAcceptedParameters(); + for (const TriggerParameter_t param : acceptedParameters) { + if (triggerParameter == param) + return OK; + } + return NOT_OK; +} From 1010cb6a7995587f942ea1939454d47cda57143a Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:41:52 +0200 Subject: [PATCH 21/39] Made braketrigger follow correct structure --- modules/ScenarioControl/inc/braketrigger.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 5d79abd15..8aaa6c9b8 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -11,7 +11,8 @@ class BrakeTrigger : public Trigger TriggerType_t getType() { return TRIGGER_BRAKE; } - TriggerReturnCode_t appendTriggerParameter(TriggerParameter_t triggerParameter); + TriggerReturnCode_t appendParameter(TriggerParameter_t triggerParameter); + TriggerReturnCode_t parseParameters(); private: std::set triggerParameters; From d7749eac2873ce8cbf1b1b594f1d619fc81da646 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:42:26 +0200 Subject: [PATCH 22/39] Forgot a piece --- modules/ScenarioControl/inc/braketrigger.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 8aaa6c9b8..e96dc22a8 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -3,10 +3,12 @@ #include "trigger.h" +#include + class BrakeTrigger : public Trigger { public: - //BrakeTrigger(TriggerType_t triggerID); + BrakeTrigger(TriggerID_t triggerID); ~BrakeTrigger(); TriggerType_t getType() { return TRIGGER_BRAKE; } From 6419fe94cadfad05ff50bde1874d514f6e2a887c Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:42:49 +0200 Subject: [PATCH 23/39] Implemented acceptedParameters getter function --- modules/ScenarioControl/inc/braketrigger.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index e96dc22a8..fbb97a9eb 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -17,9 +17,23 @@ class BrakeTrigger : public Trigger TriggerReturnCode_t parseParameters(); private: - std::set triggerParameters; - - TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t triggerParameter); + std::list parameters; + std::set getAcceptedParameters() + { + return { + Trigger::TRIGGER_PARAMETER_FALSE, + Trigger::TRIGGER_PARAMETER_TRUE, + Trigger::TRIGGER_PARAMETER_RELEASED, + Trigger::TRIGGER_PARAMETER_PRESSED, + Trigger::TRIGGER_PARAMETER_LOW, + Trigger::TRIGGER_PARAMETER_HIGH, + Trigger::TRIGGER_PARAMETER_RISING_EDGE, + Trigger::TRIGGER_PARAMETER_FALLING_EDGE, + Trigger::TRIGGER_PARAMETER_ANY_EDGE, + Trigger::TRIGGER_PARAMETER_EQUAL_TO, + Trigger::TRIGGER_PARAMETER_NOT_EQUAL_TO + }; + } }; #endif // BRAKETRIGGER_H From ddebb46aae0f1c7e8b96616bb740d28a395db33b Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 13:43:34 +0200 Subject: [PATCH 24/39] Implemented the functions as specified by header file --- modules/ScenarioControl/src/braketrigger.cpp | 37 +++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 0a1843f72..2c31c7d79 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -1,33 +1,28 @@ #include "braketrigger.h" -static constexpr Trigger::TriggerParameter_t acceptedParameters[] = { - Trigger::TRIGGER_PARAMETER_FALSE, - Trigger::TRIGGER_PARAMETER_TRUE, - Trigger::TRIGGER_PARAMETER_RELEASED, - Trigger::TRIGGER_PARAMETER_PRESSED, - Trigger::TRIGGER_PARAMETER_LOW, - Trigger::TRIGGER_PARAMETER_HIGH, - Trigger::TRIGGER_PARAMETER_RISING_EDGE, - Trigger::TRIGGER_PARAMETER_FALLING_EDGE, - Trigger::TRIGGER_PARAMETER_ANY_EDGE, - Trigger::TRIGGER_PARAMETER_EQUAL_TO, - Trigger::TRIGGER_PARAMETER_NOT_EQUAL_TO -}; - -Trigger::TriggerReturnCode_t BrakeTrigger::appendTriggerParameter(Trigger::TriggerParameter_t triggerParameter) + +BrakeTrigger::BrakeTrigger(Trigger::TriggerID_t triggerID) : Trigger (triggerID) +{ + +} + +BrakeTrigger::~BrakeTrigger() +{ + parameters.clear(); +} + +Trigger::TriggerReturnCode_t BrakeTrigger::appendParameter(Trigger::TriggerParameter_t triggerParameter) { TriggerReturnCode_t retval = NOT_OK; if( (retval = checkTriggerParameter(triggerParameter)) != OK) return retval; + parameters.push_back(triggerParameter); + return OK; } -Trigger::TriggerReturnCode_t BrakeTrigger::checkTriggerParameter(TriggerParameter_t triggerParameter) +Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() { - for (const TriggerParameter_t param : acceptedParameters) { - if (triggerParameter == param) - return OK; - } - return NOT_OK; + } From a648fa578389d79385b5f0c2d50a1d5f004ce320 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 14:20:31 +0200 Subject: [PATCH 25/39] Moved appendparameter to trigger. Added function declarations for state updates --- modules/ScenarioControl/inc/braketrigger.h | 6 +++--- modules/ScenarioControl/inc/trigger.h | 15 +++++++++++---- modules/ScenarioControl/src/braketrigger.cpp | 14 +++----------- modules/ScenarioControl/src/trigger.cpp | 12 ++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index fbb97a9eb..99ee9210d 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -11,13 +11,13 @@ class BrakeTrigger : public Trigger BrakeTrigger(TriggerID_t triggerID); ~BrakeTrigger(); - TriggerType_t getType() { return TRIGGER_BRAKE; } - - TriggerReturnCode_t appendParameter(TriggerParameter_t triggerParameter); TriggerReturnCode_t parseParameters(); private: + static constexpr TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; + std::list parameters; + std::set getAcceptedParameters() { return { diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index d03e7a503..9ed544420 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -33,7 +33,7 @@ class Trigger TRIGGER_TIMER_EVENT_OCCURRED = 0x0100, TRIGGER_MODE_CHANGED = 0x0110, TRIGGER_UNAVAILABLE = 0xFFFF - } TriggerType_t; + } TriggerTypeCode_t; typedef enum { TRIGGER_PARAMETER_FALSE = 0x00000000, @@ -80,15 +80,15 @@ class Trigger /*! Getters */ - virtual TriggerType_t getType() = 0; + TriggerTypeCode_t getTypeCode() { return this->triggerTypeCode; } uint16_t getID() { return this->triggerID; } /*! Setters */ void setID(uint16_t triggerID) { this->triggerID = triggerID; } - virtual TriggerReturnCode_t appendParameter(TriggerParameter_t triggerParameter) = 0; - virtual TriggerReturnCode_t parseParameters() = 0; // TODO: Maybe make this a Trigger function + TriggerReturnCode_t appendParameter(TriggerParameter_t triggerParameter); + virtual TriggerReturnCode_t parseParameters() = 0; /*! To string */ @@ -96,6 +96,9 @@ class Trigger return strm << "TODO, but here is the ID: " << trig.triggerID; } + TriggerReturnCode_t update(double value); + TriggerReturnCode_t update(int value); + TriggerReturnCode_t update(bool value); protected: @@ -104,6 +107,10 @@ class Trigger private: TriggerID_t triggerID; + TriggerTypeCode_t triggerTypeCode; + + + std::list parameters; virtual std::set getAcceptedParameters() diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 2c31c7d79..0e07105ae 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -11,18 +11,10 @@ BrakeTrigger::~BrakeTrigger() parameters.clear(); } -Trigger::TriggerReturnCode_t BrakeTrigger::appendParameter(Trigger::TriggerParameter_t triggerParameter) -{ - TriggerReturnCode_t retval = NOT_OK; - - if( (retval = checkTriggerParameter(triggerParameter)) != OK) - return retval; - - parameters.push_back(triggerParameter); - return OK; -} - Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() { + for (const TriggerParameter_t param : parameters) + { + } } diff --git a/modules/ScenarioControl/src/trigger.cpp b/modules/ScenarioControl/src/trigger.cpp index d0fe1baee..e131a6dc0 100644 --- a/modules/ScenarioControl/src/trigger.cpp +++ b/modules/ScenarioControl/src/trigger.cpp @@ -26,3 +26,15 @@ Trigger::TriggerReturnCode_t Trigger::checkTriggerParameter(TriggerParameter_t t } return NOT_OK; } + + +Trigger::TriggerReturnCode_t Trigger::appendParameter(Trigger::TriggerParameter_t triggerParameter) +{ + TriggerReturnCode_t retval = NOT_OK; + + if( (retval = checkTriggerParameter(triggerParameter)) != OK) + return retval; + + parameters.push_back(triggerParameter); + return OK; +} From e7000d376b0b000882e77eeb61e0c7c8a84420a0 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 15:24:15 +0200 Subject: [PATCH 26/39] Implemented update function as template --- modules/ScenarioControl/inc/braketrigger.h | 13 +++++++++++++ modules/ScenarioControl/inc/trigger.h | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 99ee9210d..3333ae653 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -13,11 +13,23 @@ class BrakeTrigger : public Trigger TriggerReturnCode_t parseParameters(); + template TriggerReturnCode_t update(T) { return INVALID_ARGUMENT; } + + template<> TriggerReturnCode_t update(bool isBrakeCurrentlyPressed) + { + wasBrakePressed = isBrakePressed; + isBrakePressed = isBrakeCurrentlyPressed; + return OK; + } + + private: static constexpr TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; std::list parameters; + bool isBrakePressed = false, wasBrakePressed = false; + std::set getAcceptedParameters() { return { @@ -34,6 +46,7 @@ class BrakeTrigger : public Trigger Trigger::TRIGGER_PARAMETER_NOT_EQUAL_TO }; } + }; #endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 9ed544420..2c4ed3ec5 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -68,7 +68,7 @@ class Trigger typedef uint16_t TriggerID_t; - typedef enum {OK, NOT_OK} TriggerReturnCode_t; + typedef enum {OK, NOT_OK, INVALID_ARGUMENT} TriggerReturnCode_t; /*! Constructor */ @@ -96,10 +96,7 @@ class Trigger return strm << "TODO, but here is the ID: " << trig.triggerID; } - TriggerReturnCode_t update(double value); - TriggerReturnCode_t update(int value); - TriggerReturnCode_t update(bool value); - + template TriggerReturnCode_t update(T) { return INVALID_ARGUMENT; } protected: TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t triggerParameter); From 204a58fbed624dba52be06ec6300abc2c95d44a2 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 15:52:50 +0200 Subject: [PATCH 27/39] Implemented checker function for trigger occurred --- modules/ScenarioControl/inc/braketrigger.h | 13 ++++------- modules/ScenarioControl/inc/trigger.h | 12 ++++++++-- modules/ScenarioControl/src/braketrigger.cpp | 23 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 3333ae653..e4c0602d8 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -13,15 +13,7 @@ class BrakeTrigger : public Trigger TriggerReturnCode_t parseParameters(); - template TriggerReturnCode_t update(T) { return INVALID_ARGUMENT; } - - template<> TriggerReturnCode_t update(bool isBrakeCurrentlyPressed) - { - wasBrakePressed = isBrakePressed; - isBrakePressed = isBrakeCurrentlyPressed; - return OK; - } - + TriggerReturnCode_t update(bool); private: static constexpr TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; @@ -47,6 +39,9 @@ class BrakeTrigger : public Trigger }; } + TriggerReturnCode_t checkIfTriggered(void); + + enum TriggerMode {PRESSED, RELEASED, EDGE_RISING, EDGE_FALLING, EDGE_ANY} mode; }; #endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 2c4ed3ec5..a7de4a19f 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -6,6 +6,8 @@ #include #include + + class Trigger { public: @@ -68,7 +70,7 @@ class Trigger typedef uint16_t TriggerID_t; - typedef enum {OK, NOT_OK, INVALID_ARGUMENT} TriggerReturnCode_t; + typedef enum {OK, NOT_OK, INVALID_ARGUMENT, TRIGGER_OCCURRED, NO_TRIGGER_OCCURRED} TriggerReturnCode_t; /*! Constructor */ @@ -96,7 +98,12 @@ class Trigger return strm << "TODO, but here is the ID: " << trig.triggerID; } - template TriggerReturnCode_t update(T) { return INVALID_ARGUMENT; } + TriggerReturnCode_t update(void) { return INVALID_ARGUMENT; } + TriggerReturnCode_t update(bool) { return INVALID_ARGUMENT; } + TriggerReturnCode_t update(char) { return INVALID_ARGUMENT; } + TriggerReturnCode_t update(int) { return INVALID_ARGUMENT; } + TriggerReturnCode_t update(float) { return INVALID_ARGUMENT; } + TriggerReturnCode_t update(double) { return INVALID_ARGUMENT; } protected: TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t triggerParameter); @@ -113,6 +120,7 @@ class Trigger virtual std::set getAcceptedParameters() { return {TRIGGER_PARAMETER_UNAVAILABLE}; } + virtual TriggerReturnCode_t checkIfTriggered(void) = 0; }; #endif // TRIGGER_H diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 0e07105ae..b1597539a 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -18,3 +18,26 @@ Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() } } + +Trigger::TriggerReturnCode_t BrakeTrigger::update(bool isBrakeCurrentlyPressed) +{ + wasBrakePressed = isBrakePressed; + isBrakePressed = isBrakeCurrentlyPressed; + return checkIfTriggered(); +} + +Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() +{ + switch (mode) { + case PRESSED: + return isBrakePressed ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case RELEASED: + return isBrakePressed ? NO_TRIGGER_OCCURRED : TRIGGER_OCCURRED; + case EDGE_ANY: + return (isBrakePressed != wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case EDGE_RISING: + return (isBrakePressed && !wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case EDGE_FALLING: + return (!isBrakePressed && wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + } +} From b286bc01a4178a8520159d37d6557b4571d11907 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Wed, 3 Jul 2019 15:56:43 +0200 Subject: [PATCH 28/39] Missed adding the actual implementation --- modules/ScenarioControl/src/braketrigger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index b1597539a..d7eee2831 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -32,7 +32,7 @@ Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() case PRESSED: return isBrakePressed ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; case RELEASED: - return isBrakePressed ? NO_TRIGGER_OCCURRED : TRIGGER_OCCURRED; + return !isBrakePressed ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; case EDGE_ANY: return (isBrakePressed != wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; case EDGE_RISING: From cd88006354452835def0a50a675af7beb903cde6 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Thu, 4 Jul 2019 09:45:14 +0200 Subject: [PATCH 29/39] Removed overly complex parsing of arguments --- modules/ScenarioControl/inc/braketrigger.h | 18 ++++-- modules/ScenarioControl/src/braketrigger.cpp | 58 +++++++++++++++++--- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index e4c0602d8..8fc5452eb 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -3,7 +3,8 @@ #include "trigger.h" -#include +#include +#include class BrakeTrigger : public Trigger { @@ -18,7 +19,7 @@ class BrakeTrigger : public Trigger private: static constexpr TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; - std::list parameters; + std::vector parameters; bool isBrakePressed = false, wasBrakePressed = false; @@ -33,15 +34,20 @@ class BrakeTrigger : public Trigger Trigger::TRIGGER_PARAMETER_HIGH, Trigger::TRIGGER_PARAMETER_RISING_EDGE, Trigger::TRIGGER_PARAMETER_FALLING_EDGE, - Trigger::TRIGGER_PARAMETER_ANY_EDGE, - Trigger::TRIGGER_PARAMETER_EQUAL_TO, - Trigger::TRIGGER_PARAMETER_NOT_EQUAL_TO + Trigger::TRIGGER_PARAMETER_ANY_EDGE }; } TriggerReturnCode_t checkIfTriggered(void); - enum TriggerMode {PRESSED, RELEASED, EDGE_RISING, EDGE_FALLING, EDGE_ANY} mode; + enum TriggerMode { + INVALID_MODE, + PRESSED, + RELEASED, + EDGE_RISING, + EDGE_FALLING, + EDGE_ANY} + mode = INVALID_MODE; }; #endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index d7eee2831..9066a5730 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -1,6 +1,5 @@ #include "braketrigger.h" - BrakeTrigger::BrakeTrigger(Trigger::TriggerID_t triggerID) : Trigger (triggerID) { @@ -11,14 +10,6 @@ BrakeTrigger::~BrakeTrigger() parameters.clear(); } -Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() -{ - for (const TriggerParameter_t param : parameters) - { - - } -} - Trigger::TriggerReturnCode_t BrakeTrigger::update(bool isBrakeCurrentlyPressed) { wasBrakePressed = isBrakePressed; @@ -39,5 +30,54 @@ Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() return (isBrakePressed && !wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; case EDGE_FALLING: return (!isBrakePressed && wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case INVALID_MODE: + return NO_TRIGGER_OCCURRED; } } + + +Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() +{ + if (parameters.size() == 1) + { + switch (parameters.front()) + { + case TRIGGER_PARAMETER_PRESSED: + case TRIGGER_PARAMETER_TRUE: + case TRIGGER_PARAMETER_HIGH: + mode = PRESSED; + isBrakePressed = false; + wasBrakePressed = false; + return OK; + case TRIGGER_PARAMETER_RELEASED: + case TRIGGER_PARAMETER_FALSE: + case TRIGGER_PARAMETER_LOW: + mode = RELEASED; + isBrakePressed = true; + wasBrakePressed = true; + return OK; + case TRIGGER_PARAMETER_RISING_EDGE: + mode = EDGE_RISING; + isBrakePressed = false; + wasBrakePressed = false; + return OK; + case TRIGGER_PARAMETER_FALLING_EDGE: + mode = EDGE_FALLING; + isBrakePressed = false; + wasBrakePressed = false; + return OK; + case TRIGGER_PARAMETER_ANY_EDGE: + mode = EDGE_ANY; + isBrakePressed = false; + wasBrakePressed = false; + return OK; + default: + return INVALID_ARGUMENT; + } + } + else return INVALID_ARGUMENT; +} + + + + From 7de0456199d694faabbc5d0cb15b323b63545e09 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Thu, 4 Jul 2019 09:45:48 +0200 Subject: [PATCH 30/39] Modified some structure of trigger --- modules/ScenarioControl/inc/trigger.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index a7de4a19f..5033c925b 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include @@ -70,7 +70,13 @@ class Trigger typedef uint16_t TriggerID_t; - typedef enum {OK, NOT_OK, INVALID_ARGUMENT, TRIGGER_OCCURRED, NO_TRIGGER_OCCURRED} TriggerReturnCode_t; + typedef enum { + OK, + NOT_OK, + INVALID_ARGUMENT, + TRIGGER_OCCURRED, + NO_TRIGGER_OCCURRED + } TriggerReturnCode_t; /*! Constructor */ @@ -115,7 +121,7 @@ class Trigger - std::list parameters; + std::vector parameters; virtual std::set getAcceptedParameters() { return {TRIGGER_PARAMETER_UNAVAILABLE}; } From 7a96926e938df8b343657510036feb1983953132 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Thu, 4 Jul 2019 09:48:09 +0200 Subject: [PATCH 31/39] Return error if attempting to update when not configured correctly --- modules/ScenarioControl/src/braketrigger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 9066a5730..814f65041 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -31,7 +31,7 @@ Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() case EDGE_FALLING: return (!isBrakePressed && wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; case INVALID_MODE: - return NO_TRIGGER_OCCURRED; + return NOT_OK; } } From 3f8700316cba753ce647b0b1cf86e93f396509b1 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Thu, 4 Jul 2019 13:21:02 +0200 Subject: [PATCH 32/39] Small modifications --- modules/ScenarioControl/src/braketrigger.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 814f65041..5d286a08f 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -10,6 +10,11 @@ BrakeTrigger::~BrakeTrigger() parameters.clear(); } +/*! + * \brief BrakeTrigger::update Updates the brake signal connected to the trigger to the value specified + * \param isBrakeCurrentlyPressed Boolean describing if the brake is currently pressed + * \return Value according to ::TriggerReturnCode_t + */ Trigger::TriggerReturnCode_t BrakeTrigger::update(bool isBrakeCurrentlyPressed) { wasBrakePressed = isBrakePressed; @@ -17,6 +22,10 @@ Trigger::TriggerReturnCode_t BrakeTrigger::update(bool isBrakeCurrentlyPressed) return checkIfTriggered(); } +/*! + * \brief BrakeTrigger::checkIfTriggered Check if the trigger has occurred based on the mode and state + * \return Value according to ::TriggerReturnCode_t + */ Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() { switch (mode) { @@ -35,7 +44,10 @@ Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() } } - +/*! + * \brief BrakeTrigger::parseParameters Parses the parameter vector and sets the trigger mode accordingly + * \return Value according to ::TriggerReturnCode_t + */ Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() { if (parameters.size() == 1) From 72edea277f1be1951903bb98806b5c56f5214dc1 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Thu, 4 Jul 2019 17:04:50 +0200 Subject: [PATCH 33/39] Made separate booleantrigger class and commented a bunch of functions --- modules/ScenarioControl/CMakeLists.txt | 2 + modules/ScenarioControl/inc/booleantrigger.h | 49 +++++++++++++ modules/ScenarioControl/inc/braketrigger.h | 31 ++------ .../ScenarioControl/src/booleantrigger.cpp | 37 ++++++++++ modules/ScenarioControl/src/braketrigger.cpp | 73 ++++--------------- 5 files changed, 109 insertions(+), 83 deletions(-) create mode 100644 modules/ScenarioControl/inc/booleantrigger.h create mode 100644 modules/ScenarioControl/src/booleantrigger.cpp diff --git a/modules/ScenarioControl/CMakeLists.txt b/modules/ScenarioControl/CMakeLists.txt index fee8ca620..d58609e31 100644 --- a/modules/ScenarioControl/CMakeLists.txt +++ b/modules/ScenarioControl/CMakeLists.txt @@ -38,6 +38,8 @@ add_library(util add_library(Trigger inc/trigger.h src/trigger.cpp + inc/booleantrigger.h + src/booleantrigger.cpp inc/braketrigger.h src/braketrigger.cpp ) diff --git a/modules/ScenarioControl/inc/booleantrigger.h b/modules/ScenarioControl/inc/booleantrigger.h new file mode 100644 index 000000000..61e29eed6 --- /dev/null +++ b/modules/ScenarioControl/inc/booleantrigger.h @@ -0,0 +1,49 @@ +#ifndef BOOLEANTRIGGER_H +#define BOOLEANTRIGGER_H + +#include "trigger.h" + +#include +#include + +class BooleanTrigger : public Trigger +{ +public: + using Trigger::Trigger; + + virtual TriggerReturnCode_t parseParameters() override = 0; + + TriggerReturnCode_t update(bool) override; + +protected: + TriggerReturnCode_t checkIfTriggered(void) override; + + enum TriggerMode { + INVALID_MODE, + HIGH, + LOW, + EDGE_RISING, + EDGE_FALLING, + EDGE_ANY} + mode = INVALID_MODE; + + bool isStateTrue = false, wasStateTrue = false; + +private: + TriggerTypeCode_t triggerTypeCode; + + virtual std::set getAcceptedParameters() override + { + return { + Trigger::TRIGGER_PARAMETER_FALSE, + Trigger::TRIGGER_PARAMETER_TRUE, + Trigger::TRIGGER_PARAMETER_RISING_EDGE, + Trigger::TRIGGER_PARAMETER_FALLING_EDGE, + Trigger::TRIGGER_PARAMETER_ANY_EDGE + }; + } + + +}; + +#endif // BOOLEANTRIGGER_H diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 8fc5452eb..4460093c5 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -1,29 +1,24 @@ #ifndef BRAKETRIGGER_H #define BRAKETRIGGER_H -#include "trigger.h" +#include "booleantrigger.h" -#include #include +#include -class BrakeTrigger : public Trigger +class BrakeTrigger : public BooleanTrigger { public: - BrakeTrigger(TriggerID_t triggerID); - ~BrakeTrigger(); + using BooleanTrigger::BooleanTrigger; - TriggerReturnCode_t parseParameters(); - - TriggerReturnCode_t update(bool); + TriggerReturnCode_t parseParameters() override; private: - static constexpr TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; + TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; std::vector parameters; - bool isBrakePressed = false, wasBrakePressed = false; - - std::set getAcceptedParameters() + std::set getAcceptedParameters() override { return { Trigger::TRIGGER_PARAMETER_FALSE, @@ -37,17 +32,5 @@ class BrakeTrigger : public Trigger Trigger::TRIGGER_PARAMETER_ANY_EDGE }; } - - TriggerReturnCode_t checkIfTriggered(void); - - enum TriggerMode { - INVALID_MODE, - PRESSED, - RELEASED, - EDGE_RISING, - EDGE_FALLING, - EDGE_ANY} - mode = INVALID_MODE; }; - #endif // BRAKETRIGGER_H diff --git a/modules/ScenarioControl/src/booleantrigger.cpp b/modules/ScenarioControl/src/booleantrigger.cpp new file mode 100644 index 000000000..7016a126e --- /dev/null +++ b/modules/ScenarioControl/src/booleantrigger.cpp @@ -0,0 +1,37 @@ +#include "booleantrigger.h" + +/*! + * \brief BooleanTrigger::update Updates the signal connected to the trigger to the value specified + * \param isBrakeCurrentlyPressed Boolean describing if the boolean + * \return Value according to ::TriggerReturnCode_t + */ +Trigger::TriggerReturnCode_t BooleanTrigger::update(bool currentStateValue) +{ + wasStateTrue = isStateTrue; + isStateTrue = currentStateValue; + return checkIfTriggered(); +} + +/*! + * \brief BooleanTrigger::checkIfTriggered Check if the trigger has occurred based on the mode and state + * \return Value according to ::TriggerReturnCode_t + */ +Trigger::TriggerReturnCode_t BooleanTrigger::checkIfTriggered() +{ + switch (mode) { + case HIGH: + return isStateTrue ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case LOW: + return !isStateTrue ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case EDGE_ANY: + return (isStateTrue != wasStateTrue) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case EDGE_RISING: + return (isStateTrue && !wasStateTrue) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case EDGE_FALLING: + return (!isStateTrue && wasStateTrue) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; + case INVALID_MODE: + return NOT_OK; + } +} + + diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 5d286a08f..59ffbb59a 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -1,51 +1,8 @@ -#include "braketrigger.h" - -BrakeTrigger::BrakeTrigger(Trigger::TriggerID_t triggerID) : Trigger (triggerID) -{ - -} - -BrakeTrigger::~BrakeTrigger() -{ - parameters.clear(); -} -/*! - * \brief BrakeTrigger::update Updates the brake signal connected to the trigger to the value specified - * \param isBrakeCurrentlyPressed Boolean describing if the brake is currently pressed - * \return Value according to ::TriggerReturnCode_t - */ -Trigger::TriggerReturnCode_t BrakeTrigger::update(bool isBrakeCurrentlyPressed) -{ - wasBrakePressed = isBrakePressed; - isBrakePressed = isBrakeCurrentlyPressed; - return checkIfTriggered(); -} - -/*! - * \brief BrakeTrigger::checkIfTriggered Check if the trigger has occurred based on the mode and state - * \return Value according to ::TriggerReturnCode_t - */ -Trigger::TriggerReturnCode_t BrakeTrigger::checkIfTriggered() -{ - switch (mode) { - case PRESSED: - return isBrakePressed ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; - case RELEASED: - return !isBrakePressed ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; - case EDGE_ANY: - return (isBrakePressed != wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; - case EDGE_RISING: - return (isBrakePressed && !wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; - case EDGE_FALLING: - return (!isBrakePressed && wasBrakePressed) ? TRIGGER_OCCURRED : NO_TRIGGER_OCCURRED; - case INVALID_MODE: - return NOT_OK; - } -} +#include "braketrigger.h" /*! - * \brief BrakeTrigger::parseParameters Parses the parameter vector and sets the trigger mode accordingly + * \brief BooleanTrigger::parseParameters Parses the parameter vector and sets the trigger mode accordingly * \return Value according to ::TriggerReturnCode_t */ Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() @@ -57,31 +14,31 @@ Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() case TRIGGER_PARAMETER_PRESSED: case TRIGGER_PARAMETER_TRUE: case TRIGGER_PARAMETER_HIGH: - mode = PRESSED; - isBrakePressed = false; - wasBrakePressed = false; + mode = HIGH; + isStateTrue = false; + wasStateTrue = false; return OK; case TRIGGER_PARAMETER_RELEASED: case TRIGGER_PARAMETER_FALSE: case TRIGGER_PARAMETER_LOW: - mode = RELEASED; - isBrakePressed = true; - wasBrakePressed = true; + mode = LOW; + isStateTrue = true; + wasStateTrue = true; return OK; case TRIGGER_PARAMETER_RISING_EDGE: mode = EDGE_RISING; - isBrakePressed = false; - wasBrakePressed = false; + isStateTrue = false; + wasStateTrue = false; return OK; case TRIGGER_PARAMETER_FALLING_EDGE: mode = EDGE_FALLING; - isBrakePressed = false; - wasBrakePressed = false; + isStateTrue = false; + wasStateTrue = false; return OK; case TRIGGER_PARAMETER_ANY_EDGE: mode = EDGE_ANY; - isBrakePressed = false; - wasBrakePressed = false; + isStateTrue = false; + wasStateTrue = false; return OK; default: return INVALID_ARGUMENT; @@ -91,5 +48,3 @@ Trigger::TriggerReturnCode_t BrakeTrigger::parseParameters() } - - From 3cf874e4f0df35c52dd3d5599ef90b9b4216cf87 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Thu, 4 Jul 2019 18:05:33 +0200 Subject: [PATCH 34/39] Modified constructors --- modules/ScenarioControl/inc/booleantrigger.h | 1 - modules/ScenarioControl/inc/braketrigger.h | 5 +- modules/ScenarioControl/inc/trigger.h | 35 +++-- modules/ScenarioControl/src/braketrigger.cpp | 2 + modules/ScenarioControl/src/trigger.cpp | 155 ++++++++++++++++++- 5 files changed, 174 insertions(+), 24 deletions(-) diff --git a/modules/ScenarioControl/inc/booleantrigger.h b/modules/ScenarioControl/inc/booleantrigger.h index 61e29eed6..08691f9e4 100644 --- a/modules/ScenarioControl/inc/booleantrigger.h +++ b/modules/ScenarioControl/inc/booleantrigger.h @@ -30,7 +30,6 @@ class BooleanTrigger : public Trigger bool isStateTrue = false, wasStateTrue = false; private: - TriggerTypeCode_t triggerTypeCode; virtual std::set getAcceptedParameters() override { diff --git a/modules/ScenarioControl/inc/braketrigger.h b/modules/ScenarioControl/inc/braketrigger.h index 4460093c5..84c118916 100644 --- a/modules/ScenarioControl/inc/braketrigger.h +++ b/modules/ScenarioControl/inc/braketrigger.h @@ -9,13 +9,10 @@ class BrakeTrigger : public BooleanTrigger { public: - using BooleanTrigger::BooleanTrigger; - + BrakeTrigger(TriggerID_t triggerID); TriggerReturnCode_t parseParameters() override; private: - TriggerTypeCode_t triggerTypeCode = TRIGGER_BRAKE; - std::vector parameters; std::set getAcceptedParameters() override diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 5033c925b..ced9ec554 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -80,7 +80,7 @@ class Trigger /*! Constructor */ - Trigger(TriggerID_t triggerID); + Trigger(TriggerID_t triggerID, TriggerTypeCode_t triggerType); /*! Destructor */ @@ -88,8 +88,9 @@ class Trigger /*! Getters */ - TriggerTypeCode_t getTypeCode() { return this->triggerTypeCode; } - uint16_t getID() { return this->triggerID; } + virtual TriggerTypeCode_t getTypeCode() { return triggerTypeCode; } + uint16_t getID() { return triggerID; } + std::vector getParameters() { return parameters; } /*! Setters */ @@ -100,27 +101,29 @@ class Trigger /*! To string */ - friend std::ostream& operator<<(std::ostream &strm, const Trigger &trig) { - return strm << "TODO, but here is the ID: " << trig.triggerID; + friend std::ostream& operator<<(std::ostream &strm, Trigger &trig) { + return strm << "TRIGGER ID " << trig.triggerID << + " TYPE " << getTypeAsString(trig.getTypeCode()) << + " PARAMETERS " << trig.getParametersString(); } - TriggerReturnCode_t update(void) { return INVALID_ARGUMENT; } - TriggerReturnCode_t update(bool) { return INVALID_ARGUMENT; } - TriggerReturnCode_t update(char) { return INVALID_ARGUMENT; } - TriggerReturnCode_t update(int) { return INVALID_ARGUMENT; } - TriggerReturnCode_t update(float) { return INVALID_ARGUMENT; } - TriggerReturnCode_t update(double) { return INVALID_ARGUMENT; } + static std::string getTypeAsString(TriggerTypeCode_t typeCode); + static std::string getParameterAsString(TriggerParameter_t param); + std::string getParametersString(); + + virtual TriggerReturnCode_t update(void) { return INVALID_ARGUMENT; } + virtual TriggerReturnCode_t update(bool) { return INVALID_ARGUMENT; } + virtual TriggerReturnCode_t update(char) { return INVALID_ARGUMENT; } + virtual TriggerReturnCode_t update(int) { return INVALID_ARGUMENT; } + virtual TriggerReturnCode_t update(float) { return INVALID_ARGUMENT; } + virtual TriggerReturnCode_t update(double) { return INVALID_ARGUMENT; } protected: TriggerReturnCode_t checkTriggerParameter(TriggerParameter_t triggerParameter); - + TriggerTypeCode_t triggerTypeCode; private: TriggerID_t triggerID; - TriggerTypeCode_t triggerTypeCode; - - - std::vector parameters; virtual std::set getAcceptedParameters() diff --git a/modules/ScenarioControl/src/braketrigger.cpp b/modules/ScenarioControl/src/braketrigger.cpp index 59ffbb59a..f4443710d 100644 --- a/modules/ScenarioControl/src/braketrigger.cpp +++ b/modules/ScenarioControl/src/braketrigger.cpp @@ -1,6 +1,8 @@ #include "braketrigger.h" +BrakeTrigger::BrakeTrigger(Trigger::TriggerID_t triggerID) : BooleanTrigger(triggerID, Trigger::TRIGGER_BRAKE) { } + /*! * \brief BooleanTrigger::parseParameters Parses the parameter vector and sets the trigger mode accordingly * \return Value according to ::TriggerReturnCode_t diff --git a/modules/ScenarioControl/src/trigger.cpp b/modules/ScenarioControl/src/trigger.cpp index e131a6dc0..33a6f8aff 100644 --- a/modules/ScenarioControl/src/trigger.cpp +++ b/modules/ScenarioControl/src/trigger.cpp @@ -1,14 +1,15 @@ #include "trigger.h" -Trigger::Trigger(TriggerID_t triggerID) +Trigger::Trigger(TriggerID_t triggerID, TriggerTypeCode_t triggerType) { this->triggerID = triggerID; + this->triggerTypeCode = triggerType; } Trigger::~Trigger() { - + parameters.clear(); } @@ -27,7 +28,11 @@ Trigger::TriggerReturnCode_t Trigger::checkTriggerParameter(TriggerParameter_t t return NOT_OK; } - +/*! + * \brief Trigger::appendParameter Adds a parameter to the parameter list if it is among the accepted parameters + * \param triggerParameter Parameter to append + * \return Return code according to ::TriggerReturnCode_t + */ Trigger::TriggerReturnCode_t Trigger::appendParameter(Trigger::TriggerParameter_t triggerParameter) { TriggerReturnCode_t retval = NOT_OK; @@ -38,3 +43,147 @@ Trigger::TriggerReturnCode_t Trigger::appendParameter(Trigger::TriggerParameter_ parameters.push_back(triggerParameter); return OK; } + +/*! + * \brief Trigger::getParametersString Converts the list of loaded parameters into a string + * \return String describing all parameters + */ +std::string Trigger::getParametersString() +{ + std::string retval; + if (parameters.size() == 0) + return "EMPTY"; + + for (const TriggerParameter_t param : parameters) + { + retval.append(getParameterAsString(param) + " "); + } + retval.pop_back(); + return retval; +} + +/*! + * \brief Trigger::getParameterAsString Converts a ::TriggerParameter_t into a string + * \param param Parameter to be converted + * \return String describing the parameter + */ +std::string Trigger::getParameterAsString(TriggerParameter_t param) +{ + switch (param) + { + case TRIGGER_PARAMETER_FALSE: + return "FALSE"; + case TRIGGER_PARAMETER_TRUE: + return "TRUE"; + case TRIGGER_PARAMETER_RELEASED: + return "RELEASED"; + case TRIGGER_PARAMETER_PRESSED: + return "PRESSED"; + case TRIGGER_PARAMETER_LOW: + return "LOW"; + case TRIGGER_PARAMETER_HIGH: + return "HIGH"; + case TRIGGER_PARAMETER_RISING_EDGE: + return "RISING EDGE"; + case TRIGGER_PARAMETER_FALLING_EDGE: + return "FALLING EDGE"; + case TRIGGER_PARAMETER_ANY_EDGE: + return "ANY EDGE"; + case TRIGGER_PARAMETER_RELATIVE: + return "RELATIVE"; + case TRIGGER_PARAMETER_ABSOLUTE: + return "ABSOLUTE"; + case TRIGGER_PARAMETER_VALUE: + return "VALUE"; + case TRIGGER_PARAMETER_MIN: + return "MIN"; + case TRIGGER_PARAMETER_MAX: + return "MAX"; + case TRIGGER_PARAMETER_MEAN: + return "MEAN"; + case TRIGGER_PARAMETER_EQUAL_TO: + return "EQUAL TO"; + case TRIGGER_PARAMETER_GREATER_THAN: + return "GREATER THAN"; + case TRIGGER_PARAMETER_GREATER_THAN_OR_EQUAL_TO: + return "GREATER THAN OR EQUAL TO"; + case TRIGGER_PARAMETER_LESS_THAN: + return "LESS THAN"; + case TRIGGER_PARAMETER_LESS_THAN_OR_EQUAL_TO: + return "LESS THAN OR EQUAL TO"; + case TRIGGER_PARAMETER_NOT_EQUAL_TO: + return "NOT EQUAL TO"; + case TRIGGER_PARAMETER_X: + return "X"; + case TRIGGER_PARAMETER_Y: + return "Y"; + case TRIGGER_PARAMETER_Z: + return "Z"; + case TRIGGER_PARAMETER_TIME: + return "TIME"; + case TRIGGER_PARAMETER_DATE: + return "DATE"; + case TRIGGER_PARAMETER_RULE: + return "RULE"; + case TRIGGER_PARAMETER_UNAVAILABLE: + return "UNAVAILABLE"; + } + return "<>"; +} + +/*! + * \brief Trigger::getTypeAsString Maps a ::TriggerTypeCode_t to a string + * \param triggerTypeCode Type code + * \return String describing the trigger type + */ +std::string Trigger::getTypeAsString(Trigger::TriggerTypeCode_t typeCode) +{ + switch (typeCode) + { + case TRIGGER_UNDEFINED: + return "UNDEFINED"; + case TRIGGER_TYPE_1: + return "TYPE 1"; + case TRIGGER_SPEED: + return "SPEED"; + case TRIGGER_DISTANCE: + return "DISTANCE"; + case TRIGGER_ACCELERATION: + return "ACCELERATION"; + case TRIGGER_LANE_CHANGED: + return "LANE CHANGED"; + case TRIGGER_LANE_OFFSET: + return "LANE OFFSET"; + case TRIGGER_POSITION_REACHED: + return "POSITION REACHED"; + case TRIGGER_POSITION_LEFT: + return "POSITION LEFT"; + case TRIGGER_POSITION_OFFSET: + return "POSITION OFFSET"; + case TRIGGER_STEERING_ANGLE: + return "STEERING ANGLE"; + case TRIGGER_THROTTLE_VALUE: + return "THROTTLE VALUE"; + case TRIGGER_BRAKE: + return "BRAKE"; + case TRIGGER_ACTIVE_TRAJECTORY: + return "ACTIVE TRAJECTORY"; + case TRIGGER_OTHER_OBJECT_FEATURE: + return "OTHER OBJECT FEATURE"; + case TRIGGER_INFRASTRUCTURE: + return "INFRASTRUCTURE"; + case TRIGGER_TEST_SCENARIO_EVENT: + return "TEST SCENARIO EVENT"; + case TRIGGER_MISC_DIGITAL_INPUT: + return "MISC DIGITAL INPUT"; + case TRIGGER_MISC_ANALOG_INPUT: + return "MISC ANALOG INPUT"; + case TRIGGER_TIMER_EVENT_OCCURRED: + return "TIMER EVENT OCCURRED"; + case TRIGGER_MODE_CHANGED: + return "MODE CHANGED"; + case TRIGGER_UNAVAILABLE: + return "TRIGGER UNAVAILABLE"; + } + return "<>"; +} From b6c42401153f52590f39417f1a655516b9ce7a7c Mon Sep 17 00:00:00 2001 From: LukasWikander Date: Thu, 4 Jul 2019 18:19:10 +0200 Subject: [PATCH 35/39] Update README.md --- modules/ScenarioControl/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ScenarioControl/README.md b/modules/ScenarioControl/README.md index e6bce0e21..ab11606c5 100644 --- a/modules/ScenarioControl/README.md +++ b/modules/ScenarioControl/README.md @@ -1,4 +1,4 @@ -## Dummy module +## ScenarioControl module TODO. ### Build process From 8aa894c25d1d728b441a7801556673129ce818ac Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Fri, 5 Jul 2019 16:36:20 +0200 Subject: [PATCH 36/39] Added c++11 standard as forced --- modules/ScenarioControl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ScenarioControl/CMakeLists.txt b/modules/ScenarioControl/CMakeLists.txt index d58609e31..bf03e05a8 100644 --- a/modules/ScenarioControl/CMakeLists.txt +++ b/modules/ScenarioControl/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8) +set (CMAKE_CXX_STANDARD 11) project(ScenarioControl) # This module is an example of how to set up a new module external to the Maestro executable From a7d1b211a34e7b8e20a6f06154fd02e1b0c5deee Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Fri, 5 Jul 2019 16:39:53 +0200 Subject: [PATCH 37/39] Clarified a function description --- modules/ScenarioControl/src/booleantrigger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ScenarioControl/src/booleantrigger.cpp b/modules/ScenarioControl/src/booleantrigger.cpp index 7016a126e..bc27e4451 100644 --- a/modules/ScenarioControl/src/booleantrigger.cpp +++ b/modules/ScenarioControl/src/booleantrigger.cpp @@ -1,7 +1,7 @@ #include "booleantrigger.h" /*! - * \brief BooleanTrigger::update Updates the signal connected to the trigger to the value specified + * \brief BooleanTrigger::update Updates the tracked signal (i.e. which causes the trigger) to the value specified * \param isBrakeCurrentlyPressed Boolean describing if the boolean * \return Value according to ::TriggerReturnCode_t */ From 87e8eb206d49195f0a257874d6fe82a6824a5ddd Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Fri, 5 Jul 2019 16:50:04 +0200 Subject: [PATCH 38/39] Added comments on intended use of update functions --- modules/ScenarioControl/inc/trigger.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index ced9ec554..4197bf46d 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -111,6 +111,11 @@ class Trigger static std::string getParameterAsString(TriggerParameter_t param); std::string getParametersString(); + /*! Update tracked signal (i.e. signal which causes the trigger to occur). + * Inheriting classes should override the appropriate function(s) + * - e.g. a trigger tracking a floating point trigger should override + * update(float) and update(double) + */ virtual TriggerReturnCode_t update(void) { return INVALID_ARGUMENT; } virtual TriggerReturnCode_t update(bool) { return INVALID_ARGUMENT; } virtual TriggerReturnCode_t update(char) { return INVALID_ARGUMENT; } From 21358407df920f7435b027438f9a4e4ac3783e00 Mon Sep 17 00:00:00 2001 From: Lukas Wikander Date: Fri, 5 Jul 2019 16:57:36 +0200 Subject: [PATCH 39/39] Added function description for trigger functions --- modules/ScenarioControl/inc/trigger.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/ScenarioControl/inc/trigger.h b/modules/ScenarioControl/inc/trigger.h index 4197bf46d..2d045ecaa 100644 --- a/modules/ScenarioControl/inc/trigger.h +++ b/modules/ScenarioControl/inc/trigger.h @@ -96,7 +96,17 @@ class Trigger /*! Setters */ void setID(uint16_t triggerID) { this->triggerID = triggerID; } + /*! + * \brief appendParameter Appends an ISO parameter to the parameters list. + * \param triggerParameter Parameter to append + * \return Value according to ::TriggerReturnCode_t + */ TriggerReturnCode_t appendParameter(TriggerParameter_t triggerParameter); + + /*! + * \brief parseParameters Parse the parameters list into an appropriate Trigger mode. + * \return Value according to ::TriggerReturnCode_t + */ virtual TriggerReturnCode_t parseParameters() = 0; @@ -111,7 +121,8 @@ class Trigger static std::string getParameterAsString(TriggerParameter_t param); std::string getParametersString(); - /*! Update tracked signal (i.e. signal which causes the trigger to occur). + /*! + * \brief update Update tracked signal (i.e. signal which causes the trigger to occur). * Inheriting classes should override the appropriate function(s) * - e.g. a trigger tracking a floating point trigger should override * update(float) and update(double)