From 64594665493ef81ec84928331dfc4d7c4aac3bdc Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Sat, 30 Nov 2024 09:48:16 -0700 Subject: [PATCH 1/7] Integrate Publish Subscribe with accel and temp data types --- .cproject | 49 +++++++++++----------- Components/SystemDefines.hpp | 1 + Components/SystemTypes/SensorDataTypes.hpp | 17 ++++++++ SoarOS | 2 +- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/.cproject b/.cproject index f6da38a..a47c6bd 100644 --- a/.cproject +++ b/.cproject @@ -55,6 +55,10 @@ + + + + @@ -98,6 +102,10 @@ + + + + @@ -141,6 +149,10 @@ + + + + @@ -296,6 +287,10 @@ + + + + @@ -338,6 +333,10 @@ + + + + diff --git a/Components/SystemDefines.hpp b/Components/SystemDefines.hpp index 11200f2..8459f05 100644 --- a/Components/SystemDefines.hpp +++ b/Components/SystemDefines.hpp @@ -35,6 +35,7 @@ enum GLOBAL_COMMANDS : uint8_t { TASK_SPECIFIC_COMMAND, // Runs a task specific command when given this object DATA_COMMAND, // Data command, used to send data to a task. Target is stored // in taskCommand + DATA_BROKER_COMMAND, }; /* Cube++ Optional Code Configuration diff --git a/Components/SystemTypes/SensorDataTypes.hpp b/Components/SystemTypes/SensorDataTypes.hpp index fade876..655b0e1 100644 --- a/Components/SystemTypes/SensorDataTypes.hpp +++ b/Components/SystemTypes/SensorDataTypes.hpp @@ -11,6 +11,8 @@ #ifndef SENSORDATATYPES_HPP_ #define SENSORDATATYPES_HPP_ +#include + /************************************ * MACROS AND DEFINES ************************************/ @@ -19,4 +21,19 @@ * TYPEDEFS ************************************/ +/** + * @param accelX The acceleration in the X axis relative to the sensor + * @param accelY The acceleration in the Y axis relative to the sensor + * @param accelZ The acceleration in the Z axis relative to the sensor + */ +struct IMUData { + uint32_t accelX; + uint32_t accelY; + uint32_t accelZ; +}; + +struct ThermocoupleData { + int32_t temperature; +}; + #endif /* SENSORDATATYPES_HPP_ */ diff --git a/SoarOS b/SoarOS index 038a687..da7af04 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 038a687ec48f894996084122b590058398fffc7d +Subproject commit da7af04abb2fc07f4657a34544f32a7959811325 From 8c0f371c10a20b6385693795bf570bd9f8840918 Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:49:23 -0700 Subject: [PATCH 2/7] Updated Git ignore to include vscode folder --- .gitignore | 1 + Components/SystemTypes/SensorDataTypes.hpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 77aa44f..f607ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ STM32L152-Discovery.elf.launch # VS2022 .vs/ +.vscode/ # OS Specific **/.DS_Store diff --git a/Components/SystemTypes/SensorDataTypes.hpp b/Components/SystemTypes/SensorDataTypes.hpp index 655b0e1..1fd8ad5 100644 --- a/Components/SystemTypes/SensorDataTypes.hpp +++ b/Components/SystemTypes/SensorDataTypes.hpp @@ -32,6 +32,9 @@ struct IMUData { uint32_t accelZ; }; +/** + * @param Temperature. Can be any where from -2147483648 to 2147483647 + */ struct ThermocoupleData { int32_t temperature; }; From 3591887c9f8665695fee5913198ce33d1f94cf6a Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Sun, 8 Dec 2024 15:58:22 -0700 Subject: [PATCH 3/7] update os submodule --- SoarOS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoarOS b/SoarOS index da7af04..1d4dee2 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit da7af04abb2fc07f4657a34544f32a7959811325 +Subproject commit 1d4dee27609f11039784789901b9368ac2cb607e From a49bafbe90f68321863e39a127cede91087c0c84 Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Fri, 3 Jan 2025 21:05:47 -0700 Subject: [PATCH 4/7] Pub Sub Integration --- .cproject | 12 ++++ .pre-commit-config.yaml | 66 ++++++++++--------- Components/SystemDefines.hpp | 33 ++++++---- .../SystemTypes/DataBrokerMessageTypes.hpp | 39 +++++++++++ Components/main_avionics.cpp | 11 ++-- SoarOS | 2 +- 6 files changed, 111 insertions(+), 52 deletions(-) create mode 100644 Components/SystemTypes/DataBrokerMessageTypes.hpp diff --git a/.cproject b/.cproject index a47c6bd..9bece60 100644 --- a/.cproject +++ b/.cproject @@ -59,6 +59,8 @@ + + @@ -106,6 +108,8 @@ + + @@ -153,6 +157,8 @@ + + @@ -291,6 +299,8 @@ + + @@ -337,6 +347,8 @@ + + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ea88dd5..c4767f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,32 +1,34 @@ -repos: - - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: 7d85583be209cb547946c82fbe51f4bc5dd1d017 - hooks: - - id: clang-format - args: ['--style={BasedOnStyle: Google, SortIncludes: false}'] - files: \.(cpp|hpp)$ - stages: [commit] - - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.5.1 - hooks: - - id: prettier - files: \.(js|ts|jsx|tsx|css|less|html|json|markdown|md|yaml|yml)$ - - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.1 - hooks: - - id: ruff - types_or: [ python, pyi ] - args: [ --fix ] - stages: [commit] - - id: ruff-format - stages: [commit] - - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml +repos: + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: 7d85583be209cb547946c82fbe51f4bc5dd1d017 + hooks: + - id: clang-format + args: + [ + "--style={BasedOnStyle: Google, SortIncludes: false, ColumnLimit: 120}", + ] + files: \.(cpp|hpp)$ + stages: [commit] + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.5.1 + hooks: + - id: prettier + files: \.(js|ts|jsx|tsx|css|less|html|json|markdown|md|yaml|yml)$ + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.1 + hooks: + - id: ruff + types_or: [python, pyi] + args: [--fix] + stages: [commit] + - id: ruff-format + stages: [commit] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml diff --git a/Components/SystemDefines.hpp b/Components/SystemDefines.hpp index 8459f05..7a2ba55 100644 --- a/Components/SystemDefines.hpp +++ b/Components/SystemDefines.hpp @@ -28,13 +28,12 @@ /* Cube++ Required Configuration * ------------------------------------------------------------------*/ #include "CubeDefines.hpp" -constexpr UARTDriver* const DEFAULT_DEBUG_UART_DRIVER = - UART::Debug; // UART Handle that ASSERT messages are sent over +constexpr UARTDriver* const DEFAULT_DEBUG_UART_DRIVER = UART::Debug; // UART Handle that ASSERT messages are sent over enum GLOBAL_COMMANDS : uint8_t { COMMAND_NONE = 0, // No command, packet can probably be ignored TASK_SPECIFIC_COMMAND, // Runs a task specific command when given this object - DATA_COMMAND, // Data command, used to send data to a task. Target is stored - // in taskCommand + DATA_COMMAND, // Data command, used to send data to a task. Target is stored + // in taskCommand DATA_BROKER_COMMAND, }; @@ -47,17 +46,23 @@ enum GLOBAL_COMMANDS : uint8_t { * ---------------------------------*/ // UART TASK -constexpr uint8_t UART_TASK_RTOS_PRIORITY = 2; // Priority of the uart task -constexpr uint8_t UART_TASK_QUEUE_DEPTH_OBJS = - 10; // Size of the uart task queue -constexpr uint16_t UART_TASK_STACK_DEPTH_WORDS = - 512; // Size of the uart task stack +constexpr uint8_t UART_TASK_RTOS_PRIORITY = 2; // Priority of the uart task +constexpr uint8_t UART_TASK_QUEUE_DEPTH_OBJS = 10; // Size of the uart task queue +constexpr uint16_t UART_TASK_STACK_DEPTH_WORDS = 512; // Size of the uart task stack // DEBUG TASK -constexpr uint8_t TASK_DEBUG_PRIORITY = 2; // Priority of the debug task -constexpr uint8_t TASK_DEBUG_QUEUE_DEPTH_OBJS = - 10; // Size of the debug task queue -constexpr uint16_t TASK_DEBUG_STACK_DEPTH_WORDS = - 512; // Size of the debug task stack +constexpr uint8_t TASK_DEBUG_PRIORITY = 2; // Priority of the debug task +constexpr uint8_t TASK_DEBUG_QUEUE_DEPTH_OBJS = 10; // Size of the debug task queue +constexpr uint16_t TASK_DEBUG_STACK_DEPTH_WORDS = 512; // Size of the debug task stack + +// PUBSUB SEND Task +constexpr uint8_t PUBSUB_SEND_TASK_RTOS_PRIORITY = 1; // Priority of the pubsub send task +constexpr uint8_t PUBSUB_SEND_TASK_QUEUE_DEPTH_OBJS = 10; // Size of the pubsub send task queue +constexpr uint16_t PUBSUB_SEND_TASK_STACK_DEPTH_WORDS = 512; // Size of the pubsub send task stack + +// PUBSUB RECEIVE Task +constexpr uint8_t PUBSUB_RECEIVE_TASK_RTOS_PRIORITY = 1; // Priority of the pubsub receive task +constexpr uint8_t PUBSUB_RECEIVE_TASK_QUEUE_DEPTH_OBJS = 10; // Size of the pubsub receive task queue +constexpr uint16_t PUBSUB_RECEIVE_TASK_STACK_DEPTH_WORDS = 512; // Size of the pubsub receive task stack #endif // CUBE_MAIN_SYSTEM_DEFINES_H diff --git a/Components/SystemTypes/DataBrokerMessageTypes.hpp b/Components/SystemTypes/DataBrokerMessageTypes.hpp new file mode 100644 index 0000000..d43ede0 --- /dev/null +++ b/Components/SystemTypes/DataBrokerMessageTypes.hpp @@ -0,0 +1,39 @@ +/** + ******************************************************************************** + * @file DataBrokerMessageTypes.hpp + * @author shivam + * @date Nov 23, 2024 + * @brief + ******************************************************************************** + */ + +#ifndef DATA_BROKER_MESSAGE_TYPES_HPP_ +#define DATA_BROKER_MESSAGE_TYPES_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include + +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ +enum class DataBrokerMessageTypes : uint8_t { + INVALID = 0, + IMU_DATA, + THERMOCOUPLE_DATA, +}; + +/************************************ + * CLASS DEFINITIONS + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +#endif /* DATA_BROKER_MESSAGE_TYPES_HPP_ */ diff --git a/Components/main_avionics.cpp b/Components/main_avionics.cpp index fa0164b..9d1a497 100644 --- a/Components/main_avionics.cpp +++ b/Components/main_avionics.cpp @@ -10,6 +10,8 @@ #include "SystemDefines.hpp" #include "UARTDriver.hpp" #include "CubeTask.hpp" +#include "PubSubReceive.hpp" +#include "PubSubSend.hpp" /* Drivers ------------------------------------------------------------------*/ namespace Driver { @@ -26,16 +28,15 @@ void run_main() { // Init Tasks CubeTask::Inst().InitTask(); DebugTask::Inst().InitTask(); + PubSubReceive::Inst().InitTask(); + PubSubSend::Inst().InitTask(); // Print System Boot Info : Warning, don't queue more than 10 prints before // scheduler starts SOAR_PRINT("\n-- CUBE SYSTEM --\n"); - SOAR_PRINT( - "System Reset Reason: [TODO]\n"); // TODO: System reset reason can be - // implemented via. Flash storage + SOAR_PRINT("System Reset Reason: [TODO]\n"); // TODO: System reset reason can be implemented via. Flash storage SOAR_PRINT("Current System Free Heap: %d Bytes\n", xPortGetFreeHeapSize()); - SOAR_PRINT("Lowest Ever Free Heap: %d Bytes\n\n", - xPortGetMinimumEverFreeHeapSize()); + SOAR_PRINT("Lowest Ever Free Heap: %d Bytes\n\n", xPortGetMinimumEverFreeHeapSize()); // Start the Scheduler // Guidelines: diff --git a/SoarOS b/SoarOS index 1d4dee2..2bdcab7 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 1d4dee27609f11039784789901b9368ac2cb607e +Subproject commit 2bdcab7fff6670431184001ed6c23624e9f0afa1 From a8f7342e627ef6abec38554877cb6ac8ea22c2a0 Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Fri, 3 Jan 2025 22:08:03 -0700 Subject: [PATCH 5/7] Moved System Types to Operating system submodule --- .cproject | 6 +++ .../SystemTypes/DataBrokerMessageTypes.hpp | 39 ----------------- Components/SystemTypes/SensorDataTypes.hpp | 42 ------------------- .../SystemTypes/SystemCommunicationTypes.hpp | 22 ---------- Components/SystemTypes/SystemConfigTypes.hpp | 18 -------- SoarOS | 2 +- 6 files changed, 7 insertions(+), 122 deletions(-) delete mode 100644 Components/SystemTypes/DataBrokerMessageTypes.hpp delete mode 100644 Components/SystemTypes/SensorDataTypes.hpp delete mode 100644 Components/SystemTypes/SystemCommunicationTypes.hpp delete mode 100644 Components/SystemTypes/SystemConfigTypes.hpp diff --git a/.cproject b/.cproject index 9bece60..c55fa53 100644 --- a/.cproject +++ b/.cproject @@ -61,6 +61,7 @@ + @@ -110,6 +111,7 @@ + @@ -159,6 +161,7 @@ + @@ -301,6 +305,7 @@ + @@ -349,6 +354,7 @@ + diff --git a/Components/SystemTypes/DataBrokerMessageTypes.hpp b/Components/SystemTypes/DataBrokerMessageTypes.hpp deleted file mode 100644 index d43ede0..0000000 --- a/Components/SystemTypes/DataBrokerMessageTypes.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - ******************************************************************************** - * @file DataBrokerMessageTypes.hpp - * @author shivam - * @date Nov 23, 2024 - * @brief - ******************************************************************************** - */ - -#ifndef DATA_BROKER_MESSAGE_TYPES_HPP_ -#define DATA_BROKER_MESSAGE_TYPES_HPP_ - -/************************************ - * INCLUDES - ************************************/ -#include - -/************************************ - * MACROS AND DEFINES - ************************************/ - -/************************************ - * TYPEDEFS - ************************************/ -enum class DataBrokerMessageTypes : uint8_t { - INVALID = 0, - IMU_DATA, - THERMOCOUPLE_DATA, -}; - -/************************************ - * CLASS DEFINITIONS - ************************************/ - -/************************************ - * FUNCTION DECLARATIONS - ************************************/ - -#endif /* DATA_BROKER_MESSAGE_TYPES_HPP_ */ diff --git a/Components/SystemTypes/SensorDataTypes.hpp b/Components/SystemTypes/SensorDataTypes.hpp deleted file mode 100644 index 1fd8ad5..0000000 --- a/Components/SystemTypes/SensorDataTypes.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/** - ******************************************************************************** - * @file SensorDataTypes.hpp - * @author Shivam Desai - * @date Nov 3, 2024 - * @brief General sensor data structure to pass around in the system or - *log it to flash memory - ******************************************************************************** - */ - -#ifndef SENSORDATATYPES_HPP_ -#define SENSORDATATYPES_HPP_ - -#include - -/************************************ - * MACROS AND DEFINES - ************************************/ - -/************************************ - * TYPEDEFS - ************************************/ - -/** - * @param accelX The acceleration in the X axis relative to the sensor - * @param accelY The acceleration in the Y axis relative to the sensor - * @param accelZ The acceleration in the Z axis relative to the sensor - */ -struct IMUData { - uint32_t accelX; - uint32_t accelY; - uint32_t accelZ; -}; - -/** - * @param Temperature. Can be any where from -2147483648 to 2147483647 - */ -struct ThermocoupleData { - int32_t temperature; -}; - -#endif /* SENSORDATATYPES_HPP_ */ diff --git a/Components/SystemTypes/SystemCommunicationTypes.hpp b/Components/SystemTypes/SystemCommunicationTypes.hpp deleted file mode 100644 index e3d046b..0000000 --- a/Components/SystemTypes/SystemCommunicationTypes.hpp +++ /dev/null @@ -1,22 +0,0 @@ -/** - ******************************************************************************** - * @file SystemCommunicationTypes.hpp - * @author Shivam Desai - * @date Nov 3, 2024 - * @brief Data structures to pass around other system information such as - * commands, events or state information - ******************************************************************************** - */ - -#ifndef SYSTEMCOMMUNICATIONTYPES_HPP_ -#define SYSTEMCOMMUNICATIONTYPES_HPP_ - -/************************************ - * MACROS AND DEFINES - ************************************/ - -/************************************ - * TYPEDEFS - ************************************/ - -#endif /* SYSTEMCOMMUNICATIONTYPES_HPP_ */ diff --git a/Components/SystemTypes/SystemConfigTypes.hpp b/Components/SystemTypes/SystemConfigTypes.hpp deleted file mode 100644 index 578f097..0000000 --- a/Components/SystemTypes/SystemConfigTypes.hpp +++ /dev/null @@ -1,18 +0,0 @@ -/** - ******************************************************************************** - * @file SystemConfigTypes.hpp - * @author Shivam Desai - * @date Nov 3, 2024 - * @brief Defines that allow the system to build with different - *functionality by changing the value of the define in this file - ******************************************************************************** - */ - -#ifndef SYSTEMCONFIGTYPES_HPP_ -#define SYSTEMCONFIGTYPES_HPP_ - -/************************************ - * MACROS AND DEFINES - ************************************/ - -#endif /* SYSTEMCONFIGTYPES_HPP_ */ diff --git a/SoarOS b/SoarOS index 2bdcab7..3bc83f2 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 2bdcab7fff6670431184001ed6c23624e9f0afa1 +Subproject commit 3bc83f2da3fe81c313a4cc62b50fb51b9f133f6b From 721f197788d5ad78c93ebb099ca7bf738845b946 Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:04:15 -0700 Subject: [PATCH 6/7] Moved pub sub test from OS to template repo --- .cproject | 12 ++ Components/PubSubTest/Inc/PubSubReceive.hpp | 58 ++++++++++ Components/PubSubTest/Inc/PubSubSend.hpp | 57 ++++++++++ Components/PubSubTest/PubSubReceive.cpp | 119 ++++++++++++++++++++ Components/PubSubTest/PubSubSend.cpp | 94 ++++++++++++++++ SoarOS | 2 +- 6 files changed, 341 insertions(+), 1 deletion(-) create mode 100644 Components/PubSubTest/Inc/PubSubReceive.hpp create mode 100644 Components/PubSubTest/Inc/PubSubSend.hpp create mode 100644 Components/PubSubTest/PubSubReceive.cpp create mode 100644 Components/PubSubTest/PubSubSend.cpp diff --git a/.cproject b/.cproject index c55fa53..721d02a 100644 --- a/.cproject +++ b/.cproject @@ -62,6 +62,8 @@ + + @@ -112,6 +114,8 @@ + + @@ -162,6 +166,8 @@ + + @@ -306,6 +314,8 @@ + + @@ -355,6 +365,8 @@ + + diff --git a/Components/PubSubTest/Inc/PubSubReceive.hpp b/Components/PubSubTest/Inc/PubSubReceive.hpp new file mode 100644 index 0000000..df94e6c --- /dev/null +++ b/Components/PubSubTest/Inc/PubSubReceive.hpp @@ -0,0 +1,58 @@ +/** + ******************************************************************************** + * @file PubSubReceive.hpp + * @author shiva + * @date Dec 14, 2024 + * @brief + ******************************************************************************** + */ + +#ifndef PUBSUBRECEIEVE_HPP_ +#define PUBSUBRECEIEVE_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include "Task.hpp" +#include "SystemDefines.hpp" + +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ +class PubSubReceive : public Task { + public: + static PubSubReceive& Inst() { + static PubSubReceive inst; + return inst; + } + + void InitTask(); + + protected: + static void RunTask(void* pvParams) { + PubSubReceive::Inst().Run(pvParams); + } // Static Task Interface, passes control to the instance Run(); + void Run(void* pvParams); // Main run code + void HandleCommand(Command& cm); + void HandleDataBrokerCommand(const Command& cm); + + private: + // Private Functions + PubSubReceive(); // Private constructor + PubSubReceive(const PubSubReceive&); // Prevent copy-construction + PubSubReceive& operator=(const PubSubReceive&); // Prevent assignment +}; + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +#endif /* PUBSUBRECEIEVE_HPP_ */ diff --git a/Components/PubSubTest/Inc/PubSubSend.hpp b/Components/PubSubTest/Inc/PubSubSend.hpp new file mode 100644 index 0000000..8874e65 --- /dev/null +++ b/Components/PubSubTest/Inc/PubSubSend.hpp @@ -0,0 +1,57 @@ +/** + ******************************************************************************** + * @file PubSubSend.hpp + * @author shiva + * @date Dec 14, 2024 + * @brief + ******************************************************************************** + */ + +#ifndef PUBSUBSEND_HPP_ +#define PUBSUBSEND_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include "Task.hpp" +#include "SystemDefines.hpp" + +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ +class PubSubSend : public Task { + public: + static PubSubSend& Inst() { + static PubSubSend inst; + return inst; + } + + void InitTask(); + + protected: + static void RunTask(void* pvParams) { + PubSubSend::Inst().Run(pvParams); + } // Static Task Interface, passes control to the instance Run(); + void Run(void* pvParams); // Main run code + void HandleCommand(Command& cm); + + private: + // Private Functions + PubSubSend(); // Private constructor + PubSubSend(const PubSubSend&); // Prevent copy-construction + PubSubSend& operator=(const PubSubSend&); // Prevent assignment +}; + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +#endif /* PUBSUBSEND_HPP_ */ diff --git a/Components/PubSubTest/PubSubReceive.cpp b/Components/PubSubTest/PubSubReceive.cpp new file mode 100644 index 0000000..aed3929 --- /dev/null +++ b/Components/PubSubTest/PubSubReceive.cpp @@ -0,0 +1,119 @@ +/** + ******************************************************************************** + * @file PubSubReceive.cpp + * @author shiva + * @date Dec 14, 2024 + * @brief + ******************************************************************************** + */ + +/************************************ + * INCLUDES + ************************************/ +#include "PubSubReceive.hpp" +#include "SystemDefines.hpp" +#include "SensorDataTypes.hpp" +#include "DataBroker.hpp" + +/************************************ + * PRIVATE MACROS AND DEFINES + ************************************/ + +/************************************ + * VARIABLES + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +/************************************ + * FUNCTION DEFINITIONS + ************************************/ + +/** + * @brief Constructor for PubSubReceive + */ +PubSubReceive::PubSubReceive() : Task(PUBSUB_RECEIVE_TASK_QUEUE_DEPTH_OBJS) {} + +/** + * @brief Initialize the PubSubReceive + * Do not modify this function aside from adding the task name + */ +void PubSubReceive::InitTask() { + // Make sure the task is not already initialized + SOAR_ASSERT(rtTaskHandle == nullptr, "Cannot initialize watchdog task twice"); + + BaseType_t rtValue = xTaskCreate((TaskFunction_t)PubSubReceive::RunTask, (const char*)"PubSubReceive", + (uint16_t)PUBSUB_RECEIVE_TASK_STACK_DEPTH_WORDS, (void*)this, + (UBaseType_t)PUBSUB_RECEIVE_TASK_RTOS_PRIORITY, (TaskHandle_t*)&rtTaskHandle); + + SOAR_ASSERT(rtValue == pdPASS, "PubSubReceive::InitTask() - xTaskCreate() failed"); +} + +/** + * @brief Instance Run loop for the Task, runs on scheduler start as long as the task is initialized. + * @param pvParams RTOS Passed void parameters, contains a pointer to the object instance, should not be used + */ +void PubSubReceive::Run(void* pvParams) { + // SOAR_PRINT("PUBSUB RECIEVE STARTED\n"); + DataBroker::Subscribe(this); + // DataBroker::Unsubscribe(this); + while (1) { + /* Process commands in blocking mode */ + Command cm; + bool res = qEvtQueue->ReceiveWait(cm); + if (res) { + HandleCommand(cm); + } + } +} + +/** + * @brief Handles a command + * @param cm Command reference to handle + */ +void PubSubReceive::HandleCommand(Command& cm) { + switch (cm.GetCommand()) { + case DATA_BROKER_COMMAND: + HandleDataBrokerCommand(cm); + break; + + default: + SOAR_PRINT("PubSubReceive - Received Unsupported Command {%d}\n", cm.GetCommand()); + break; + } + + // No matter what we happens, we must reset allocated data + cm.Reset(); +} + +/** + * @brief Handle all data broker commands + * @param cm The command object with the data + * Use cm.GetTaskCommand() to get the message type + * Message types must be cast back into DataBrokerMessageTypes enum + * Use cm.GetDataPointer() to get the pointer to the data + */ +void PubSubReceive::HandleDataBrokerCommand(const Command& cm) { + DataBrokerMessageTypes messageType = DataBroker::getMessageType(cm); + switch (messageType) { + case DataBrokerMessageTypes::IMU_DATA: { + IMUData imu_data = DataBroker::ExtractData(cm); + SOAR_PRINT("\n IMU DATA : \n"); + SOAR_PRINT(" X -> %d \n", imu_data.accelX); + SOAR_PRINT(" Y -> %d \n", imu_data.accelY); + SOAR_PRINT(" Z -> %d \n", imu_data.accelZ); + SOAR_PRINT("--DATA_END--\n\n"); + break; + } + + case DataBrokerMessageTypes::THERMOCOUPLE_DATA: + break; + + case DataBrokerMessageTypes::INVALID: + [[fallthrough]]; + default: + break; + } +} diff --git a/Components/PubSubTest/PubSubSend.cpp b/Components/PubSubTest/PubSubSend.cpp new file mode 100644 index 0000000..248139b --- /dev/null +++ b/Components/PubSubTest/PubSubSend.cpp @@ -0,0 +1,94 @@ +/** + ******************************************************************************** + * @file PubSubSend.cpp + * @author shiva + * @date Dec 14, 2024 + * @brief + ******************************************************************************** + */ + +/************************************ + * INCLUDES + ************************************/ +#include "PubSubSend.hpp" +#include "SystemDefines.hpp" +#include "SensorDataTypes.hpp" +#include "DataBroker.hpp" + +/************************************ + * PRIVATE MACROS AND DEFINES + ************************************/ + +/************************************ + * VARIABLES + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +/************************************ + * FUNCTION DEFINITIONS + ************************************/ + +/** + * @brief Constructor for PubSubSend + */ +PubSubSend::PubSubSend() : Task(PUBSUB_SEND_TASK_QUEUE_DEPTH_OBJS) {} + +/** + * @brief Initialize the PubSubSend + * Do not modify this function aside from adding the task name + */ +void PubSubSend::InitTask() { + // Make sure the task is not already initialized + SOAR_ASSERT(rtTaskHandle == nullptr, "Cannot initialize watchdog task twice"); + + BaseType_t rtValue = xTaskCreate((TaskFunction_t)PubSubSend::RunTask, (const char*)"PubSubSend", + (uint16_t)PUBSUB_SEND_TASK_STACK_DEPTH_WORDS, (void*)this, + (UBaseType_t)PUBSUB_SEND_TASK_RTOS_PRIORITY, (TaskHandle_t*)&rtTaskHandle); + + SOAR_ASSERT(rtValue == pdPASS, "PubSubSend::InitTask() - xTaskCreate() failed"); +} + +/** + * @brief Instance Run loop for the Task, runs on scheduler start as long as the task is initialized. + * @param pvParams RTOS Passed void parameters, contains a pointer to the object instance, should not be used + */ +void PubSubSend::Run(void* pvParams) { + // SOAR_PRINT("\nPUBSUB SEND STARTED\n"); + + while (1) { + Command cm; + if (qEvtQueue->Receive(cm, 5000)) { + HandleCommand(cm); + } else { + IMUData imuData = { + .accelX = 1, + .accelY = 2, + .accelZ = 3, + }; + DataBroker::Publish(&imuData); + + ThermocoupleData thermData = { + .temperature = -52, + }; + DataBroker::Publish(&thermData); + } + } +} + +/** + * @brief Handles a command + * @param cm Command reference to handle + */ +void PubSubSend::HandleCommand(Command& cm) { + switch (cm.GetCommand()) { + default: + SOAR_PRINT("PubSubSend - Received Unsupported Command {%d}\n", cm.GetCommand()); + break; + } + + // No matter what we happens, we must reset allocated data + cm.Reset(); +} diff --git a/SoarOS b/SoarOS index 3bc83f2..3871370 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 3bc83f2da3fe81c313a4cc62b50fb51b9f133f6b +Subproject commit 3871370b5c596737a7c4bd9bea98ef1cf979f650 From 0aa04c33628d0abe0977997efef5346bed862cd3 Mon Sep 17 00:00:00 2001 From: shivamdesai04 <101665374+shivamdesai04@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:34:26 -0700 Subject: [PATCH 7/7] Check if types are compatible when extracting data --- Components/PubSubTest/Inc/PubSubReceive.hpp | 8 ++++---- Components/PubSubTest/Inc/PubSubSend.hpp | 8 ++++---- Components/PubSubTest/PubSubReceive.cpp | 2 +- Components/PubSubTest/PubSubSend.cpp | 2 +- SoarOS | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Components/PubSubTest/Inc/PubSubReceive.hpp b/Components/PubSubTest/Inc/PubSubReceive.hpp index df94e6c..17a5165 100644 --- a/Components/PubSubTest/Inc/PubSubReceive.hpp +++ b/Components/PubSubTest/Inc/PubSubReceive.hpp @@ -1,14 +1,14 @@ /** ******************************************************************************** * @file PubSubReceive.hpp - * @author shiva + * @author Shivam Desai * @date Dec 14, 2024 * @brief ******************************************************************************** */ -#ifndef PUBSUBRECEIEVE_HPP_ -#define PUBSUBRECEIEVE_HPP_ +#ifndef PUBSUB_RECEIEVE_HPP_ +#define PUBSUB_RECEIEVE_HPP_ /************************************ * INCLUDES @@ -55,4 +55,4 @@ class PubSubReceive : public Task { * FUNCTION DECLARATIONS ************************************/ -#endif /* PUBSUBRECEIEVE_HPP_ */ +#endif /* PUBSUB_RECEIEVE_HPP_ */ diff --git a/Components/PubSubTest/Inc/PubSubSend.hpp b/Components/PubSubTest/Inc/PubSubSend.hpp index 8874e65..ef09d94 100644 --- a/Components/PubSubTest/Inc/PubSubSend.hpp +++ b/Components/PubSubTest/Inc/PubSubSend.hpp @@ -1,14 +1,14 @@ /** ******************************************************************************** * @file PubSubSend.hpp - * @author shiva + * @author Shivam Desai * @date Dec 14, 2024 * @brief ******************************************************************************** */ -#ifndef PUBSUBSEND_HPP_ -#define PUBSUBSEND_HPP_ +#ifndef PUBSUB_SEND_HPP_ +#define PUBSUB_SEND_HPP_ /************************************ * INCLUDES @@ -54,4 +54,4 @@ class PubSubSend : public Task { * FUNCTION DECLARATIONS ************************************/ -#endif /* PUBSUBSEND_HPP_ */ +#endif /* PUBSUB_SEND_HPP_ */ diff --git a/Components/PubSubTest/PubSubReceive.cpp b/Components/PubSubTest/PubSubReceive.cpp index aed3929..5574d7b 100644 --- a/Components/PubSubTest/PubSubReceive.cpp +++ b/Components/PubSubTest/PubSubReceive.cpp @@ -1,7 +1,7 @@ /** ******************************************************************************** * @file PubSubReceive.cpp - * @author shiva + * @author Shivam Desai * @date Dec 14, 2024 * @brief ******************************************************************************** diff --git a/Components/PubSubTest/PubSubSend.cpp b/Components/PubSubTest/PubSubSend.cpp index 248139b..9fb3091 100644 --- a/Components/PubSubTest/PubSubSend.cpp +++ b/Components/PubSubTest/PubSubSend.cpp @@ -1,7 +1,7 @@ /** ******************************************************************************** * @file PubSubSend.cpp - * @author shiva + * @author Shivam Desai * @date Dec 14, 2024 * @brief ******************************************************************************** diff --git a/SoarOS b/SoarOS index 3871370..2796fa8 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 3871370b5c596737a7c4bd9bea98ef1cf979f650 +Subproject commit 2796fa848c102683b4b35c48c7ba8e3ea3872d6d