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 01/17] 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 02/17] 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 03/17] 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 04/17] 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 05/17] 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 06/17] 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 07/17] 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 From 5213604262c0b7b3d212eeceb2101ebb14eb75e8 Mon Sep 17 00:00:00 2001 From: Local user Date: Sat, 15 Mar 2025 14:47:52 -0600 Subject: [PATCH 08/17] -basic classes set up, timer callback --- .../RateDistributor/DistributorTask.cpp | 75 +++++++++++++++++++ .../RateDistributor/Inc/DistributorTask.hpp | 50 +++++++++++++ .../RateDistributor/Inc/RateDistributor.hpp | 48 ++++++++++++ .../RateDistributor/Inc/RatedSubscriber.hpp | 56 ++++++++++++++ .../RateDistributor/RateDistributor.cpp | 10 +++ Components/RateDistributor/RateSubscriber.cpp | 0 6 files changed, 239 insertions(+) create mode 100644 Components/RateDistributor/DistributorTask.cpp create mode 100644 Components/RateDistributor/Inc/DistributorTask.hpp create mode 100644 Components/RateDistributor/Inc/RateDistributor.hpp create mode 100644 Components/RateDistributor/Inc/RatedSubscriber.hpp create mode 100644 Components/RateDistributor/RateDistributor.cpp create mode 100644 Components/RateDistributor/RateSubscriber.cpp diff --git a/Components/RateDistributor/DistributorTask.cpp b/Components/RateDistributor/DistributorTask.cpp new file mode 100644 index 0000000..e0e3298 --- /dev/null +++ b/Components/RateDistributor/DistributorTask.cpp @@ -0,0 +1,75 @@ +/* + * DistributorTask.cpp + * + * Created on: Mar 15, 2025 + * Author: Local user + */ + +/* Includes ------------------------------------------------------------------*/ +#include "DistributorTask.hpp" +#include "Command.hpp" +#include "CubeUtils.hpp" +#include +#include "SensorDataTypes.hpp" +#include "RateDistributor.hpp" + +#include "stm32h7xx_hal.h" + +// External Tasks (to send debug commands to) + +/* Macros --------------------------------------------------------------------*/ + +/* Structs -------------------------------------------------------------------*/ + +/* Constants -----------------------------------------------------------------*/ + +/* Variables -----------------------------------------------------------------*/ + +/* Prototypes ----------------------------------------------------------------*/ + +/* Functions -----------------------------------------------------------------*/ +/** + * @brief Constructor, sets all member variables + */ +DistributorTask::DistributorTask() + : Task(TASK_DEBUG_QUEUE_DEPTH_OBJS) { +} + +/** + * @brief Init task for RTOS + */ +void DistributorTask::InitTask() { + // Make sure the task is not already initialized + SOAR_ASSERT(rtTaskHandle == nullptr, "Cannot initialize Debug task twice"); + + // Start the task + BaseType_t rtValue = xTaskCreate( + (TaskFunction_t)DistributorTask::RunTask, (const char*)"DistributorTask", + (uint16_t)TASK_DEBUG_STACK_DEPTH_WORDS, (void*)this, + (UBaseType_t)TASK_DEBUG_PRIORITY, (TaskHandle_t*)&rtTaskHandle); + + // Ensure creation succeded + SOAR_ASSERT(rtValue == pdPASS, "DistributorTask::InitTask - xTaskCreate() failed"); +} + +/** + * @brief Runcode for the DistributorTask + */ +void DistributorTask::Run(void* pvParams) { + + RateDistributor imudist; + imudist.Subscribe(this, 100); + while (1) { + Command cm; + + // Wait forever for a command + qEvtQueue->ReceiveWait(cm); + + // Process the command + if (cm.GetCommand() == DATA_COMMAND) { + } + + cm.Reset(); + } +} + diff --git a/Components/RateDistributor/Inc/DistributorTask.hpp b/Components/RateDistributor/Inc/DistributorTask.hpp new file mode 100644 index 0000000..77d013f --- /dev/null +++ b/Components/RateDistributor/Inc/DistributorTask.hpp @@ -0,0 +1,50 @@ +/* + * DistributorTask.hpp + * + * Created on: Mar 15, 2025 + * Author: Local user + */ + +#ifndef DISTRIBUTORTASK_HPP_ +#define DISTRIBUTORTASK_HPP_ + +/* Includes ------------------------------------------------------------------*/ +#include "Task.hpp" +#include "SystemDefines.hpp" +#include "UARTDriver.hpp" + +/* Enums ------------------------------------------------------------------*/ +enum DEBUG_TASK_COMMANDS { + DEBUG_TASK_COMMAND_NONE = 0, + EVENT_DEBUG_RX_COMPLETE +}; + +/* Macros ------------------------------------------------------------------*/ +constexpr uint16_t DEBUG_RX_BUFFER_SZ_BYTES = 16; + +/* Class ------------------------------------------------------------------*/ +class DistributorTask : public Task { + public: + static DistributorTask& Inst() { + static DistributorTask inst; + return inst; + } + + void InitTask(); + + protected: + static void RunTask(void* pvParams) { + DistributorTask::Inst().Run(pvParams); + } // Static Task Interface, passes control to the instance Run(); + + void Run(void* pvParams); // Main run code + + + private: + DistributorTask(); // Private constructor + DistributorTask(const DistributorTask&); // Prevent copy-construction + DistributorTask& operator=(const DistributorTask&); // Prevent assignment +}; + + +#endif /* DISTRIBUTORTASK_HPP_ */ diff --git a/Components/RateDistributor/Inc/RateDistributor.hpp b/Components/RateDistributor/Inc/RateDistributor.hpp new file mode 100644 index 0000000..12677f6 --- /dev/null +++ b/Components/RateDistributor/Inc/RateDistributor.hpp @@ -0,0 +1,48 @@ +/* + * RateDistributor.hpp + * + * Created on: Mar 15, 2025 + * Author: Local user + */ + +#ifndef INC_RATEDISTRIBUTOR_HPP_ +#define INC_RATEDISTRIBUTOR_HPP_ + +#define MAX_RATED_SUBSCRIBERS 10 +#define MAX_RAW_SAMPLES 1000 +#include + + // is called by a rated subscriber when it wants a sample + void RatedCallback(TimerHandle_t timer) { + + RatedSubscriber* subs = static_cast(pvTimerGetTimerID(timer)); + } + +template +class RateDistributor { +public: + + bool Subscribe(Task* subscriber, uint16_t msPerRequest) { + SOAR_ASSERT(numRatedSubs < MAX_RATED_SUBSCRIBERS, "Too many subscribers"); + + + ratedsubs[numRatedSubs] = RatedSubscriber{Subscriber(),msPerRequest,&ratedsubs[numRatedSubs],RatedCallback}; + ratedsubs[numRatedSubs].getSubscriber().Init(subscriber); + numRatedSubs++; + + return true; + } + + + + +private: + + RatedSubscriber ratedsubs[MAX_RATED_SUBSCRIBERS]; + uint16_t numRatedSubs = 0; + T rawsamples[MAX_RAW_SAMPLES]; + +}; + + +#endif /* INC_RATEDISTRIBUTOR_HPP_ */ diff --git a/Components/RateDistributor/Inc/RatedSubscriber.hpp b/Components/RateDistributor/Inc/RatedSubscriber.hpp new file mode 100644 index 0000000..f43467a --- /dev/null +++ b/Components/RateDistributor/Inc/RatedSubscriber.hpp @@ -0,0 +1,56 @@ +/* + * RatedSubscriber.hpp + * + * Created on: Mar 15, 2025 + * Author: Local user + */ + +#ifndef INC_RATEDSUBSCRIBER_HPP_ +#define INC_RATEDSUBSCRIBER_HPP_ + +#include "Subscriber.hpp" + +class RatedSubscriber { +public: + + RatedSubscriber(Subscriber subscriber, uint16_t msPerRequest, RatedSubscriber* subscriberID, TimerCallbackFunction_t callback) + : msPerRequest(msPerRequest), subscriber(subscriber) { + timer = xTimerCreate("ratetimer", msPerRequest, pdTRUE, (void*)subscriberID, callback); + xTimerStart(timer,0); + + } + + RatedSubscriber() + : msPerRequest(0), subscriber() + { + + } + + const uint16_t getMsPerRequest() const { + return msPerRequest; + } + + Subscriber& getSubscriber() { + return subscriber; + } + + void operator=(const RatedSubscriber& other) { + this->msPerRequest = other.msPerRequest; + subscriber = other.subscriber; + xTimerDelete(this->timer,0); + this->timer = other.timer; + + } + +private: + + uint16_t msPerRequest; + Subscriber subscriber; + + TimerHandle_t timer; + + +}; + + +#endif /* INC_RATEDSUBSCRIBER_HPP_ */ diff --git a/Components/RateDistributor/RateDistributor.cpp b/Components/RateDistributor/RateDistributor.cpp new file mode 100644 index 0000000..70e1eb6 --- /dev/null +++ b/Components/RateDistributor/RateDistributor.cpp @@ -0,0 +1,10 @@ +/* + * RateDistributor.cpp + * + * Created on: Mar 15, 2025 + * Author: Local user + */ + + + + diff --git a/Components/RateDistributor/RateSubscriber.cpp b/Components/RateDistributor/RateSubscriber.cpp new file mode 100644 index 0000000..e69de29 From 6601f9f37162d3f6ff9a7dcc69bb3efd821bf7d6 Mon Sep 17 00:00:00 2001 From: Local user Date: Sat, 15 Mar 2025 14:58:37 -0600 Subject: [PATCH 09/17] changed task --- Components/RateDistributor/DistributorTask.cpp | 3 +++ Components/RateDistributor/Inc/RateDistributor.hpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Components/RateDistributor/DistributorTask.cpp b/Components/RateDistributor/DistributorTask.cpp index e0e3298..455d0a7 100644 --- a/Components/RateDistributor/DistributorTask.cpp +++ b/Components/RateDistributor/DistributorTask.cpp @@ -67,6 +67,9 @@ void DistributorTask::Run(void* pvParams) { // Process the command if (cm.GetCommand() == DATA_COMMAND) { + // switch command target + // pick a rate distirbutor + // addsample on it } cm.Reset(); diff --git a/Components/RateDistributor/Inc/RateDistributor.hpp b/Components/RateDistributor/Inc/RateDistributor.hpp index 12677f6..d5f4980 100644 --- a/Components/RateDistributor/Inc/RateDistributor.hpp +++ b/Components/RateDistributor/Inc/RateDistributor.hpp @@ -25,7 +25,6 @@ class RateDistributor { bool Subscribe(Task* subscriber, uint16_t msPerRequest) { SOAR_ASSERT(numRatedSubs < MAX_RATED_SUBSCRIBERS, "Too many subscribers"); - ratedsubs[numRatedSubs] = RatedSubscriber{Subscriber(),msPerRequest,&ratedsubs[numRatedSubs],RatedCallback}; ratedsubs[numRatedSubs].getSubscriber().Init(subscriber); numRatedSubs++; @@ -33,8 +32,9 @@ class RateDistributor { return true; } - - + void AddSample(T& sample) { + rawsamples[0] = sample; // todo + } private: From d6e7cc4691eefb79b36ce2198e55710a0195e772 Mon Sep 17 00:00:00 2001 From: Local user Date: Wed, 19 Mar 2025 18:40:13 -0600 Subject: [PATCH 10/17] implemented callback, task. currently, massive bottleneck in one task taking all sensor data. todo: maybe modify existing pubsub to send directly to queue instead of requiring a task --- .../RateDistributor/DistributorTask.cpp | 25 ++++++++++++++++--- .../RateDistributor/Inc/RateDistributor.hpp | 13 +++++++++- .../RateDistributor/Inc/RatedSubscriber.hpp | 17 ++++++++++--- Components/SoarDebug/DebugTask.cpp | 1 + 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Components/RateDistributor/DistributorTask.cpp b/Components/RateDistributor/DistributorTask.cpp index 455d0a7..b02b122 100644 --- a/Components/RateDistributor/DistributorTask.cpp +++ b/Components/RateDistributor/DistributorTask.cpp @@ -12,6 +12,7 @@ #include #include "SensorDataTypes.hpp" #include "RateDistributor.hpp" +#include "DataBrokerMessageTypes.hpp" #include "stm32h7xx_hal.h" @@ -57,8 +58,11 @@ void DistributorTask::InitTask() { */ void DistributorTask::Run(void* pvParams) { + RateDistributor imudist; - imudist.Subscribe(this, 100); + imudist.Subscribe(this, 100); // just for testing, no point in doing this + + RateDistributor thermo; while (1) { Command cm; @@ -66,10 +70,23 @@ void DistributorTask::Run(void* pvParams) { qEvtQueue->ReceiveWait(cm); // Process the command - if (cm.GetCommand() == DATA_COMMAND) { + // We have received a sensor task + if (cm.GetCommand() == DATA_BROKER_COMMAND) { // switch command target - // pick a rate distirbutor - // addsample on it + + switch(static_cast(cm.GetTaskCommand())) { + + case DataBrokerMessageTypes::IMU_DATA: + imudist.AddSample(*(IMUData*)(cm.GetDataPointer())); + break; + + case DataBrokerMessageTypes::THERMOCOUPLE_DATA: + thermo.AddSample(*(ThermocoupleData*)(cm.GetDataPointer())); + break; + + default: + break; + } } cm.Reset(); diff --git a/Components/RateDistributor/Inc/RateDistributor.hpp b/Components/RateDistributor/Inc/RateDistributor.hpp index d5f4980..0901b47 100644 --- a/Components/RateDistributor/Inc/RateDistributor.hpp +++ b/Components/RateDistributor/Inc/RateDistributor.hpp @@ -16,6 +16,17 @@ void RatedCallback(TimerHandle_t timer) { RatedSubscriber* subs = static_cast(pvTimerGetTimerID(timer)); + + Command brokerData(DATA_BROKER_COMMAND); + + uint8_t* messsageData = reinterpret_cast(subs->getDataArray()); + + // copy data to command + brokerData.CopyDataToCommand(messsageData, subs->getDataSize()); + + subs->getSubscriber().getSubscriberQueueHandle()->Send(brokerData); + + } template @@ -25,7 +36,7 @@ class RateDistributor { bool Subscribe(Task* subscriber, uint16_t msPerRequest) { SOAR_ASSERT(numRatedSubs < MAX_RATED_SUBSCRIBERS, "Too many subscribers"); - ratedsubs[numRatedSubs] = RatedSubscriber{Subscriber(),msPerRequest,&ratedsubs[numRatedSubs],RatedCallback}; + ratedsubs[numRatedSubs] = RatedSubscriber{Subscriber(),msPerRequest,&ratedsubs[numRatedSubs],RatedCallback,sizeof(T),&rawsamples}; ratedsubs[numRatedSubs].getSubscriber().Init(subscriber); numRatedSubs++; diff --git a/Components/RateDistributor/Inc/RatedSubscriber.hpp b/Components/RateDistributor/Inc/RatedSubscriber.hpp index f43467a..733b236 100644 --- a/Components/RateDistributor/Inc/RatedSubscriber.hpp +++ b/Components/RateDistributor/Inc/RatedSubscriber.hpp @@ -13,15 +13,15 @@ class RatedSubscriber { public: - RatedSubscriber(Subscriber subscriber, uint16_t msPerRequest, RatedSubscriber* subscriberID, TimerCallbackFunction_t callback) - : msPerRequest(msPerRequest), subscriber(subscriber) { + RatedSubscriber(Subscriber subscriber, uint16_t msPerRequest, RatedSubscriber* subscriberID, TimerCallbackFunction_t callback, uint32_t dataSize, void* dataArray) + : msPerRequest(msPerRequest), subscriber(subscriber), dataSize(dataSize), dataArray(dataArray) { timer = xTimerCreate("ratetimer", msPerRequest, pdTRUE, (void*)subscriberID, callback); xTimerStart(timer,0); } RatedSubscriber() - : msPerRequest(0), subscriber() + : msPerRequest(0), subscriber(), dataSize(0) { } @@ -42,6 +42,14 @@ class RatedSubscriber { } + const uint32_t getDataSize() const { + return dataSize; + } + + void* getDataArray() const { + return dataArray; + } + private: uint16_t msPerRequest; @@ -49,6 +57,9 @@ class RatedSubscriber { TimerHandle_t timer; + const uint32_t dataSize; + void* dataArray; + }; diff --git a/Components/SoarDebug/DebugTask.cpp b/Components/SoarDebug/DebugTask.cpp index 31db9ba..e88b036 100644 --- a/Components/SoarDebug/DebugTask.cpp +++ b/Components/SoarDebug/DebugTask.cpp @@ -76,6 +76,7 @@ void DebugTask::Run(void* pvParams) { } cm.Reset(); + } } From 40d800a9e8255431003aa42cbd6a5e747c6b27a1 Mon Sep 17 00:00:00 2001 From: Local user Date: Wed, 19 Mar 2025 18:44:56 -0600 Subject: [PATCH 11/17] - merged jads work --- Components/RateDistributor/Inc/RateDistributor.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Components/RateDistributor/Inc/RateDistributor.hpp b/Components/RateDistributor/Inc/RateDistributor.hpp index 0901b47..12d5b2f 100644 --- a/Components/RateDistributor/Inc/RateDistributor.hpp +++ b/Components/RateDistributor/Inc/RateDistributor.hpp @@ -44,7 +44,10 @@ class RateDistributor { } void AddSample(T& sample) { - rawsamples[0] = sample; // todo + SOAR_ASSERT(numSamples < MAX_RAW_SAMPLES,"Too many samples. todo: circular buffer"); + + rawsamples[numSamples] = sample; + numSamples++; } private: @@ -52,6 +55,7 @@ class RateDistributor { RatedSubscriber ratedsubs[MAX_RATED_SUBSCRIBERS]; uint16_t numRatedSubs = 0; T rawsamples[MAX_RAW_SAMPLES]; + uint32_t numSamples; }; From 12d73b2f4a1ffef1bcec5d5fb8c97bc39411b520 Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Wed, 19 Mar 2025 19:35:45 -0600 Subject: [PATCH 12/17] removed distributor task in order to remove bottleneck and have data broker send sensor data to queue --- .cproject | 8 +- Components/PubSubTest/PubSubReceive.cpp | 2 +- .../RateDistributor/DistributorTask.cpp | 95 ------------------- .../RateDistributor/Inc/DistributorTask.hpp | 50 ---------- .../RateDistributor/Inc/RateDistributor.hpp | 2 +- SoarOS | 2 +- 6 files changed, 10 insertions(+), 149 deletions(-) delete mode 100644 Components/RateDistributor/DistributorTask.cpp delete mode 100644 Components/RateDistributor/Inc/DistributorTask.hpp diff --git a/.cproject b/.cproject index 721d02a..33db2db 100644 --- a/.cproject +++ b/.cproject @@ -64,6 +64,7 @@ + @@ -116,6 +117,7 @@ + @@ -168,6 +170,7 @@ + @@ -316,6 +320,7 @@ + @@ -367,6 +372,7 @@ + @@ -427,4 +433,4 @@ - + \ No newline at end of file diff --git a/Components/PubSubTest/PubSubReceive.cpp b/Components/PubSubTest/PubSubReceive.cpp index 5574d7b..c325f0b 100644 --- a/Components/PubSubTest/PubSubReceive.cpp +++ b/Components/PubSubTest/PubSubReceive.cpp @@ -57,7 +57,7 @@ void PubSubReceive::InitTask() { */ void PubSubReceive::Run(void* pvParams) { // SOAR_PRINT("PUBSUB RECIEVE STARTED\n"); - DataBroker::Subscribe(this); + DataBroker::Subscribe(this->qEvtQueue); // DataBroker::Unsubscribe(this); while (1) { /* Process commands in blocking mode */ diff --git a/Components/RateDistributor/DistributorTask.cpp b/Components/RateDistributor/DistributorTask.cpp deleted file mode 100644 index b02b122..0000000 --- a/Components/RateDistributor/DistributorTask.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * DistributorTask.cpp - * - * Created on: Mar 15, 2025 - * Author: Local user - */ - -/* Includes ------------------------------------------------------------------*/ -#include "DistributorTask.hpp" -#include "Command.hpp" -#include "CubeUtils.hpp" -#include -#include "SensorDataTypes.hpp" -#include "RateDistributor.hpp" -#include "DataBrokerMessageTypes.hpp" - -#include "stm32h7xx_hal.h" - -// External Tasks (to send debug commands to) - -/* Macros --------------------------------------------------------------------*/ - -/* Structs -------------------------------------------------------------------*/ - -/* Constants -----------------------------------------------------------------*/ - -/* Variables -----------------------------------------------------------------*/ - -/* Prototypes ----------------------------------------------------------------*/ - -/* Functions -----------------------------------------------------------------*/ -/** - * @brief Constructor, sets all member variables - */ -DistributorTask::DistributorTask() - : Task(TASK_DEBUG_QUEUE_DEPTH_OBJS) { -} - -/** - * @brief Init task for RTOS - */ -void DistributorTask::InitTask() { - // Make sure the task is not already initialized - SOAR_ASSERT(rtTaskHandle == nullptr, "Cannot initialize Debug task twice"); - - // Start the task - BaseType_t rtValue = xTaskCreate( - (TaskFunction_t)DistributorTask::RunTask, (const char*)"DistributorTask", - (uint16_t)TASK_DEBUG_STACK_DEPTH_WORDS, (void*)this, - (UBaseType_t)TASK_DEBUG_PRIORITY, (TaskHandle_t*)&rtTaskHandle); - - // Ensure creation succeded - SOAR_ASSERT(rtValue == pdPASS, "DistributorTask::InitTask - xTaskCreate() failed"); -} - -/** - * @brief Runcode for the DistributorTask - */ -void DistributorTask::Run(void* pvParams) { - - - RateDistributor imudist; - imudist.Subscribe(this, 100); // just for testing, no point in doing this - - RateDistributor thermo; - while (1) { - Command cm; - - // Wait forever for a command - qEvtQueue->ReceiveWait(cm); - - // Process the command - // We have received a sensor task - if (cm.GetCommand() == DATA_BROKER_COMMAND) { - // switch command target - - switch(static_cast(cm.GetTaskCommand())) { - - case DataBrokerMessageTypes::IMU_DATA: - imudist.AddSample(*(IMUData*)(cm.GetDataPointer())); - break; - - case DataBrokerMessageTypes::THERMOCOUPLE_DATA: - thermo.AddSample(*(ThermocoupleData*)(cm.GetDataPointer())); - break; - - default: - break; - } - } - - cm.Reset(); - } -} - diff --git a/Components/RateDistributor/Inc/DistributorTask.hpp b/Components/RateDistributor/Inc/DistributorTask.hpp deleted file mode 100644 index 77d013f..0000000 --- a/Components/RateDistributor/Inc/DistributorTask.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * DistributorTask.hpp - * - * Created on: Mar 15, 2025 - * Author: Local user - */ - -#ifndef DISTRIBUTORTASK_HPP_ -#define DISTRIBUTORTASK_HPP_ - -/* Includes ------------------------------------------------------------------*/ -#include "Task.hpp" -#include "SystemDefines.hpp" -#include "UARTDriver.hpp" - -/* Enums ------------------------------------------------------------------*/ -enum DEBUG_TASK_COMMANDS { - DEBUG_TASK_COMMAND_NONE = 0, - EVENT_DEBUG_RX_COMPLETE -}; - -/* Macros ------------------------------------------------------------------*/ -constexpr uint16_t DEBUG_RX_BUFFER_SZ_BYTES = 16; - -/* Class ------------------------------------------------------------------*/ -class DistributorTask : public Task { - public: - static DistributorTask& Inst() { - static DistributorTask inst; - return inst; - } - - void InitTask(); - - protected: - static void RunTask(void* pvParams) { - DistributorTask::Inst().Run(pvParams); - } // Static Task Interface, passes control to the instance Run(); - - void Run(void* pvParams); // Main run code - - - private: - DistributorTask(); // Private constructor - DistributorTask(const DistributorTask&); // Prevent copy-construction - DistributorTask& operator=(const DistributorTask&); // Prevent assignment -}; - - -#endif /* DISTRIBUTORTASK_HPP_ */ diff --git a/Components/RateDistributor/Inc/RateDistributor.hpp b/Components/RateDistributor/Inc/RateDistributor.hpp index 12d5b2f..27f8359 100644 --- a/Components/RateDistributor/Inc/RateDistributor.hpp +++ b/Components/RateDistributor/Inc/RateDistributor.hpp @@ -33,7 +33,7 @@ template class RateDistributor { public: - bool Subscribe(Task* subscriber, uint16_t msPerRequest) { + bool Subscribe(Queue* subscriber, uint16_t msPerRequest) { SOAR_ASSERT(numRatedSubs < MAX_RATED_SUBSCRIBERS, "Too many subscribers"); ratedsubs[numRatedSubs] = RatedSubscriber{Subscriber(),msPerRequest,&ratedsubs[numRatedSubs],RatedCallback,sizeof(T),&rawsamples}; diff --git a/SoarOS b/SoarOS index 2796fa8..3548484 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 2796fa848c102683b4b35c48c7ba8e3ea3872d6d +Subproject commit 35484847eb9796223014863b2044d413c7719a77 From f969134c5f9589c8cd9555c636f9a83a1862d35c Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Sat, 13 Sep 2025 13:27:00 -0600 Subject: [PATCH 13/17] added FSB protocol to eventually handle protobuf messages, and added Logging task which subsribes to the data handled by the protobuf task --- Components/Core/Inc/Logging_Task_M.hpp | 59 +++++++++ Components/Core/Logging_Task_M.cpp | 114 ++++++++++++++++++ Components/FSBProtocol/FSBProtocolTask.cpp | 90 ++++++++++++++ .../FSBProtocol/Inc/FSBProtocolTask.hpp | 57 +++++++++ SoarOS | 2 +- 5 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 Components/Core/Inc/Logging_Task_M.hpp create mode 100644 Components/Core/Logging_Task_M.cpp create mode 100644 Components/FSBProtocol/FSBProtocolTask.cpp create mode 100644 Components/FSBProtocol/Inc/FSBProtocolTask.hpp diff --git a/Components/Core/Inc/Logging_Task_M.hpp b/Components/Core/Inc/Logging_Task_M.hpp new file mode 100644 index 0000000..51bdb75 --- /dev/null +++ b/Components/Core/Inc/Logging_Task_M.hpp @@ -0,0 +1,59 @@ +/** + ******************************************************************************** + * @file Logging_Task_M.hpp + * @author jaddina + * @date Sep 6, 2025 + * @brief + ******************************************************************************** + */ + +#ifndef CORE_INC_LOGGING_TASK_M_HPP_ +#define CORE_INC_LOGGING_TASK_M_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include "SensorDataTypes.hpp" +#include "Task.hpp" +#include "SystemDefines.hpp" + +/************************************ + * MACROS AND DEFINES + ************************************/ +constexpr uint16_t LOGGING_RX_BUFFER_SZ_BYTES = 16; +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ +class LoggingTask : public Task +{ + public: + static LoggingTask& Inst() { + static LoggingTask inst; + return inst; + } + + void InitTask(); + + protected: + bool RecieveData(); + static void RunTask(void* pvParams) { LoggingTask::Inst().Run(pvParams); } // Static Task Interface, passes control to the instance Run(); + void Run(void * pvParams); // Main run code + void HandleCommand(Command& cm); + bool LoggingTask::HandleDataBrokerCommand(Command& cm); + uint8_t debugBuffer[LOGGING_RX_BUFFER_SZ_BYTES + 1]; + + private: + // Private Functions + LoggingTask(); // Private constructor + LoggingTask(const LoggingTask&); // Prevent copy-construction + LoggingTask& operator=(const LoggingTask&); // Prevent assignment + +#endif /* CORE_INC_LOGGING_TASK_M_HPP_ */ diff --git a/Components/Core/Logging_Task_M.cpp b/Components/Core/Logging_Task_M.cpp new file mode 100644 index 0000000..2135813 --- /dev/null +++ b/Components/Core/Logging_Task_M.cpp @@ -0,0 +1,114 @@ +/** + ******************************************************************************** + * @file Logging_Task_M.cpp + * @author jaddina + * @date Sep 6, 2025 + * @brief + * + * * Setup Steps + * 1. Define the Task Queue Depth in SystemDefines.hpp + * 2. Define the Task Stack Depth in SystemDefines.hpp + * 3. Define the Task Priority in SystemDefines.hpp + * 4. Replace all placeholders marked with a $ sign + ******************************************************************************** + */ + +/************************************ + * INCLUDES + ************************************/ +#include "Logging_Task_M.hpp" +#include "SystemDefines.hpp" +#include "Command.hpp" +#include "stm32h7xx_hal.h" +#include "DataBroker.hpp" + +/************************************ + * PRIVATE MACROS AND DEFINES + ************************************/ + +/************************************ + * VARIABLES + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +/************************************ + * FUNCTION DEFINITIONS + ************************************/ +/** + * @brief Constructor for LoggingTask + */ +LoggingTask::LoggingTask() +: Task(${TaskQueueDepthDefinedInSystemDefines}) +{ + +} + +/** + * @brief Initialize the LoggingTask + * Do not modify this function aside from adding the task name + */ +void LoggingTask::InitTask() +{ + // Make sure the task is not already initialized + SOAR_ASSERT(rtTaskHandle == nullptr, "Cannot initialize watchdog task twice"); + + BaseType_t rtValue = + xTaskCreate((TaskFunction_t)LoggingTask::RunTask, + (const char*)"LoggingTask", + (uint16_t)${TaskStackDepthDefinedInSystemDefines}, + (void*)this, + (UBaseType_t)${TaskPriorityDefinedInSystemDefines}, + (TaskHandle_t*)&rtTaskHandle); + + SOAR_ASSERT(rtValue == pdPASS, "LoggingTask::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 LoggingTask::Run(void * pvParams) +{ + DataBroker::Subscribe(this->qEvtQueue); + DataBroker::Subscribe(this->qEvtQueue); + DataBroker::Subscribe(this->qEvtQueue); + + + 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 LoggingTask::HandleCommand(Command& cm) +{ + switch (cm.GetCommand()) { + + case DATA_BROKER_COMMAND: + HandleDataBrokerCommand(cm); + break; + + + default: + SOAR_PRINT("LoggingTask - Received Unsupported Command {%d}\n", cm.GetCommand()); + break; + } + + //No matter what we happens, we must reset allocated data + cm.Reset(); +} + +bool LoggingTask::HandleDataBrokerCommand(Command& cm){ + // put data into buffer +} diff --git a/Components/FSBProtocol/FSBProtocolTask.cpp b/Components/FSBProtocol/FSBProtocolTask.cpp new file mode 100644 index 0000000..0eb063d --- /dev/null +++ b/Components/FSBProtocol/FSBProtocolTask.cpp @@ -0,0 +1,90 @@ +/** + ******************************************************************************** + * @file FSBProtocolTask.cpp + * @author jaddina + * @date Sep 13, 2025 + * @brief + ******************************************************************************** + */ + +/************************************ + * INCLUDES + ************************************/ +#include "FSBProtocolTask.hpp" +#include "SystemDefines.hpp" +#include "Command.hpp" +#include "stm32h7xx_hal.h" +#include "DataBroker.hpp" +#include "Task.hpp" +/************************************ + * PRIVATE MACROS AND DEFINES + ************************************/ + +/************************************ + * VARIABLES + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + + + +/************************************ + * FUNCTION DEFINITIONS + ************************************/ +FSBProtocolTask::FSBProtocolTask():Task(TASK_FSB_PROTOCOL_QUEUE_DEPTH_OBJS) +{ + +} + +/** + * @brief Initialize the FSBProtocolTask + * Do not modify this function aside from adding the task name + */ +void FSBProtocolTask::InitTask() +{ + // Make sure the task is not already initialized + SOAR_ASSERT(rtTaskHandle == nullptr, "Cannot initialize watchdog task twice"); + + BaseType_t rtValue = + xTaskCreate((TaskFunction_t)FSBProtocolTask::RunTask, + (const char*)"FSBProtocolTask", + (uint16_t)TASK_FSB_PROTOCOL_STACK_DEPTH_WORDS, + (void*)this, + (UBaseType_t)TASK_FSB_PROTOCOL_DEPTH_WORD, + (TaskHandle_t*)&rtTaskHandle); + + SOAR_ASSERT(rtValue == pdPASS, "FSBProtocolTask::InitTask() - xTaskCreate() failed"); +} + +void FSBProtocolTask::HandleCommand(Data test){ + + //Checks for Data type + switch (test.testEnum){ + + case PRESSURE_DATA: + PressureData testing; + testing.pressure = 100; //random number to mimic data from test + DataBroker::Publish(&testing); + break; + + case IMU_DATA: + IMUData testing; + testing.accelX = 5; + testing.accelY = 10; + testing.accelZ = 15; + DataBroker::Publish(&testing); + break; + + + case THERMOCOUPLE_DATA: + ThermocoupleData testing; + testing.temperature = 100; + DataBroker::Publish(&testing); + break; + } + +} + + diff --git a/Components/FSBProtocol/Inc/FSBProtocolTask.hpp b/Components/FSBProtocol/Inc/FSBProtocolTask.hpp new file mode 100644 index 0000000..d2f59af --- /dev/null +++ b/Components/FSBProtocol/Inc/FSBProtocolTask.hpp @@ -0,0 +1,57 @@ +/** + ******************************************************************************** + * @file FSBProtocolTask.hpp + * @author jaddina + * @date Sep 13, 2025 + * @brief + ******************************************************************************** + */ + +#ifndef FSBPROTOCOL_INC_FSBPROTOCOLTASK_HPP_ +#define FSBPROTOCOL_INC_FSBPROTOCOLTASK_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include "Task.hpp" +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ +class FSBProtocolTask: public Task +{ + public: + static FSBProtocolTask& Inst() { + static FSBProtocolTask inst; + return inst; + } + + void InitTask(); + + + + protected: + bool RecieveData(); + static void RunTask(void* pvParams) { FSBProtocolTask::Inst().Run(pvParams); } // Static Task Interface, passes control to the instance Run(); + void Run(void * pvParams); // Main run code + void HandleCommand(Data test); + uint8_t debugBuffer[LOGGING_RX_BUFFER_SZ_BYTES + 1]; + + private: + // Private Functions + FSBProtocolTask(); // Private constructor + FSBProtocolTask(const FSBProtocolTask&); // Prevent copy-construction + FSBProtocolTask& operator=(const FSBProtocolTask&); // Prevent assignment + +#endif /* FSBPROTOCOL_INC_FSBPROTOCOLTASK_HPP_ */ diff --git a/SoarOS b/SoarOS index 3548484..bbe2d37 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit 35484847eb9796223014863b2044d413c7719a77 +Subproject commit bbe2d373a07fa777a138947e84de2897762299c9 From 29d49d8933d015aa0708590b0c2a3fbffc1755cb Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Sat, 20 Sep 2025 10:47:09 -0600 Subject: [PATCH 14/17] added subscriber and message handling on LoggingTask_M --- Components/Core/Inc/Logging_Task_M.hpp | 9 +++-- Components/Core/Logging_Task_M.cpp | 39 ++++++++++++++++--- Components/FSBProtocol/FSBProtocolTask.cpp | 16 ++++---- .../FSBProtocol/Inc/FSBProtocolTask.hpp | 2 +- Components/SystemDefines.hpp | 11 ++++++ 5 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Components/Core/Inc/Logging_Task_M.hpp b/Components/Core/Inc/Logging_Task_M.hpp index 51bdb75..07321cf 100644 --- a/Components/Core/Inc/Logging_Task_M.hpp +++ b/Components/Core/Inc/Logging_Task_M.hpp @@ -47,13 +47,14 @@ class LoggingTask : public Task static void RunTask(void* pvParams) { LoggingTask::Inst().Run(pvParams); } // Static Task Interface, passes control to the instance Run(); void Run(void * pvParams); // Main run code void HandleCommand(Command& cm); - bool LoggingTask::HandleDataBrokerCommand(Command& cm); - uint8_t debugBuffer[LOGGING_RX_BUFFER_SZ_BYTES + 1]; + void WriteData();//put argue + bool HandleDataBrokerCommand(Command& cm); private: // Private Functions LoggingTask(); // Private constructor - LoggingTask(const LoggingTask&); // Prevent copy-construction - LoggingTask& operator=(const LoggingTask&); // Prevent assignment + LoggingTask(const LoggingTask&); // Prevent copy-construction + LoggingTask& operator=(const LoggingTask&); // Prevent assignment +}; #endif /* CORE_INC_LOGGING_TASK_M_HPP_ */ diff --git a/Components/Core/Logging_Task_M.cpp b/Components/Core/Logging_Task_M.cpp index 2135813..e9933da 100644 --- a/Components/Core/Logging_Task_M.cpp +++ b/Components/Core/Logging_Task_M.cpp @@ -21,6 +21,7 @@ #include "Command.hpp" #include "stm32h7xx_hal.h" #include "DataBroker.hpp" +#include "DataBrokerMessageTypes.hpp" /************************************ * PRIVATE MACROS AND DEFINES @@ -41,7 +42,7 @@ * @brief Constructor for LoggingTask */ LoggingTask::LoggingTask() -: Task(${TaskQueueDepthDefinedInSystemDefines}) +: Task(LOGGING_TASK_DEPTH_OBJS) { } @@ -58,9 +59,9 @@ void LoggingTask::InitTask() BaseType_t rtValue = xTaskCreate((TaskFunction_t)LoggingTask::RunTask, (const char*)"LoggingTask", - (uint16_t)${TaskStackDepthDefinedInSystemDefines}, + (uint16_t)LOGGING_TASK_DEPTH_WORDS, (void*)this, - (UBaseType_t)${TaskPriorityDefinedInSystemDefines}, + (UBaseType_t)LOGGING_TASK_PRIORITY, (TaskHandle_t*)&rtTaskHandle); SOAR_ASSERT(rtValue == pdPASS, "LoggingTask::InitTask() - xTaskCreate() failed"); @@ -76,7 +77,6 @@ void LoggingTask::Run(void * pvParams) DataBroker::Subscribe(this->qEvtQueue); DataBroker::Subscribe(this->qEvtQueue); - while (1) { /* Process commands in blocking mode */ Command cm; @@ -99,7 +99,6 @@ void LoggingTask::HandleCommand(Command& cm) HandleDataBrokerCommand(cm); break; - default: SOAR_PRINT("LoggingTask - Received Unsupported Command {%d}\n", cm.GetCommand()); break; @@ -110,5 +109,33 @@ void LoggingTask::HandleCommand(Command& cm) } bool LoggingTask::HandleDataBrokerCommand(Command& cm){ - // put data into buffer + + DataBrokerMessageTypes messageType = DataBroker::getMessageType(cm); + + switch (messageType){ + + case DataBrokerMessageTypes::IMU_DATA: + IMUData imu_data = DataBroker::ExtractData(cm); + + + //access IMU data, then write data to a file in the fs + //Use FreeRTOS FATFS wrapper + break; + case DataBrokerMessageTypes::PRESSURE_DATA: + PressureData pressure_data = DataBroker::ExtractData(cm); + //access PressureData data, then write data to a file in the fs + //Use FreeRTOS FATFS wrapper + + break; + case DataBrokerMessageTypes::THERMOCOUPLE_DATA: + ThermocoupleData thermocouple_data = DataBroker::ExtractData(cm); + + //access Thermocouple data, then write data to a file in the fs + //Use FreeRTOS FATFS wrapper + + break; + + } + + } diff --git a/Components/FSBProtocol/FSBProtocolTask.cpp b/Components/FSBProtocol/FSBProtocolTask.cpp index 0eb063d..eb78934 100644 --- a/Components/FSBProtocol/FSBProtocolTask.cpp +++ b/Components/FSBProtocol/FSBProtocolTask.cpp @@ -70,18 +70,18 @@ void FSBProtocolTask::HandleCommand(Data test){ break; case IMU_DATA: - IMUData testing; - testing.accelX = 5; - testing.accelY = 10; - testing.accelZ = 15; - DataBroker::Publish(&testing); + IMUData imu; + imu.accelX = 5; + imu.accelY = 10; + imu.accelZ = 15; + DataBroker::Publish(&imu); break; case THERMOCOUPLE_DATA: - ThermocoupleData testing; - testing.temperature = 100; - DataBroker::Publish(&testing); + ThermocoupleData temp; + temp.temperature = 100; + DataBroker::Publish(&temp); break; } diff --git a/Components/FSBProtocol/Inc/FSBProtocolTask.hpp b/Components/FSBProtocol/Inc/FSBProtocolTask.hpp index d2f59af..d88aae1 100644 --- a/Components/FSBProtocol/Inc/FSBProtocolTask.hpp +++ b/Components/FSBProtocol/Inc/FSBProtocolTask.hpp @@ -53,5 +53,5 @@ class FSBProtocolTask: public Task FSBProtocolTask(); // Private constructor FSBProtocolTask(const FSBProtocolTask&); // Prevent copy-construction FSBProtocolTask& operator=(const FSBProtocolTask&); // Prevent assignment - +}; #endif /* FSBPROTOCOL_INC_FSBPROTOCOLTASK_HPP_ */ diff --git a/Components/SystemDefines.hpp b/Components/SystemDefines.hpp index 7a2ba55..0445461 100644 --- a/Components/SystemDefines.hpp +++ b/Components/SystemDefines.hpp @@ -55,6 +55,17 @@ constexpr uint8_t TASK_DEBUG_PRIORITY = 2; // Priority of the debug 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 +//FSB PROTOCOL +constexpr uint8_t TASK_FSB_PROTOCOL_PRIORITY = 2; // Priority of the fsb task +constexpr uint8_t TASK_FSB_PROTOCOL_DEPTH_OBJS = 10; // Size of the fsb task queue +constexpr uint16_t TASK_FSB_PROTOCOL_DEPTH_WORDS = 512; // Size of the fsb task stack + +//LOGGING TASK +constexpr uint8_t LOGGING_TASK_PRIORITY = 2; // Priority of the task +constexpr uint8_t LOGGING_TASK_DEPTH_OBJS = 10; // Size of the fsb task queue +constexpr uint16_t LOGGING_TASK_DEPTH_WORDS = 512; // Size of the fsb 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 From 04134fdf21e8035ce4134128f69488d9f9aa889b Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Sat, 25 Oct 2025 12:32:45 -0600 Subject: [PATCH 15/17] changed files that were tested --- .cproject | 6 ++ Components/Core/Inc/Logging_Task_M.hpp | 4 +- Components/Core/Logging_Task_M.cpp | 38 ++++++--- Components/FSBProtocol/FSBProtocolTask.cpp | 77 +++++++++++++------ .../FSBProtocol/Inc/FSBProtocolTask.hpp | 9 ++- Components/PubSubTest/PubSubReceive.cpp | 7 +- Components/PubSubTest/PubSubSend.cpp | 4 +- SoarOS | 2 +- 8 files changed, 102 insertions(+), 45 deletions(-) diff --git a/.cproject b/.cproject index 33db2db..127b1e6 100644 --- a/.cproject +++ b/.cproject @@ -65,6 +65,7 @@ + @@ -118,6 +119,7 @@ + @@ -171,6 +173,7 @@ + @@ -321,6 +325,7 @@ + @@ -373,6 +378,7 @@ + diff --git a/Components/Core/Inc/Logging_Task_M.hpp b/Components/Core/Inc/Logging_Task_M.hpp index 07321cf..cae8251 100644 --- a/Components/Core/Inc/Logging_Task_M.hpp +++ b/Components/Core/Inc/Logging_Task_M.hpp @@ -13,7 +13,7 @@ /************************************ * INCLUDES ************************************/ -#include "SensorDataTypes.hpp" +//#include "SensorDataTypes.hpp" #include "Task.hpp" #include "SystemDefines.hpp" @@ -40,6 +40,8 @@ class LoggingTask : public Task return inst; } + + void InitTask(); protected: diff --git a/Components/Core/Logging_Task_M.cpp b/Components/Core/Logging_Task_M.cpp index e9933da..2e09058 100644 --- a/Components/Core/Logging_Task_M.cpp +++ b/Components/Core/Logging_Task_M.cpp @@ -19,7 +19,6 @@ #include "Logging_Task_M.hpp" #include "SystemDefines.hpp" #include "Command.hpp" -#include "stm32h7xx_hal.h" #include "DataBroker.hpp" #include "DataBrokerMessageTypes.hpp" @@ -67,15 +66,17 @@ void LoggingTask::InitTask() SOAR_ASSERT(rtValue == pdPASS, "LoggingTask::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 LoggingTask::Run(void * pvParams) { - DataBroker::Subscribe(this->qEvtQueue); - DataBroker::Subscribe(this->qEvtQueue); - DataBroker::Subscribe(this->qEvtQueue); + DataBroker::Subscribe(this); + DataBroker::Subscribe(this); + DataBroker::Subscribe(this); + while (1) { /* Process commands in blocking mode */ @@ -111,29 +112,46 @@ void LoggingTask::HandleCommand(Command& cm) bool LoggingTask::HandleDataBrokerCommand(Command& cm){ DataBrokerMessageTypes messageType = DataBroker::getMessageType(cm); + AccelerometerData accel_data = {}; + PressureData pressure_data = {}; + ThermocoupleData thermocouple_data = {}; switch (messageType){ - case DataBrokerMessageTypes::IMU_DATA: - IMUData imu_data = DataBroker::ExtractData(cm); + case DataBrokerMessageTypes :: ACCELEROMETER_DATA: + accel_data = DataBroker::ExtractData(cm); + + + + SOAR_PRINT("Data Recieved\n"); + SOAR_PRINT("accelX: %d\n", accel_data.accelX); + SOAR_PRINT("accelY: %d\n", accel_data.accelY); + SOAR_PRINT("accelZ: %d\n", accel_data.accelZ); //access IMU data, then write data to a file in the fs //Use FreeRTOS FATFS wrapper break; case DataBrokerMessageTypes::PRESSURE_DATA: - PressureData pressure_data = DataBroker::ExtractData(cm); + pressure_data = DataBroker::ExtractData(cm); //access PressureData data, then write data to a file in the fs //Use FreeRTOS FATFS wrapper - + SOAR_PRINT("Data Recieved"); + SOAR_PRINT("pressure: %f", pressure_data.pressure); break; case DataBrokerMessageTypes::THERMOCOUPLE_DATA: - ThermocoupleData thermocouple_data = DataBroker::ExtractData(cm); - + thermocouple_data = DataBroker::ExtractData(cm); //access Thermocouple data, then write data to a file in the fs //Use FreeRTOS FATFS wrapper + SOAR_PRINT("Data Recieved\n"); + SOAR_PRINT("temperature: %f", thermocouple_data.temperature); break; + case DataBrokerMessageTypes :: INVALID: + SOAR_PRINT("Invalid data type"); + default: + break; + } diff --git a/Components/FSBProtocol/FSBProtocolTask.cpp b/Components/FSBProtocol/FSBProtocolTask.cpp index eb78934..04fcb98 100644 --- a/Components/FSBProtocol/FSBProtocolTask.cpp +++ b/Components/FSBProtocol/FSBProtocolTask.cpp @@ -13,9 +13,14 @@ #include "FSBProtocolTask.hpp" #include "SystemDefines.hpp" #include "Command.hpp" -#include "stm32h7xx_hal.h" + #include "DataBroker.hpp" #include "Task.hpp" +/* +#include "WriteBufferFixedSize.h" +#include "ReadBufferFixedSize.h" +#include "cobs.h" +*/ /************************************ * PRIVATE MACROS AND DEFINES ************************************/ @@ -33,7 +38,7 @@ /************************************ * FUNCTION DEFINITIONS ************************************/ -FSBProtocolTask::FSBProtocolTask():Task(TASK_FSB_PROTOCOL_QUEUE_DEPTH_OBJS) +FSBProtocolTask::FSBProtocolTask():Task(TASK_FSB_PROTOCOL_DEPTH_OBJS) { } @@ -50,39 +55,63 @@ void FSBProtocolTask::InitTask() BaseType_t rtValue = xTaskCreate((TaskFunction_t)FSBProtocolTask::RunTask, (const char*)"FSBProtocolTask", - (uint16_t)TASK_FSB_PROTOCOL_STACK_DEPTH_WORDS, + (uint16_t)TASK_FSB_PROTOCOL_DEPTH_WORDS, (void*)this, - (UBaseType_t)TASK_FSB_PROTOCOL_DEPTH_WORD, + (UBaseType_t)TASK_FSB_PROTOCOL_PRIORITY, (TaskHandle_t*)&rtTaskHandle); SOAR_ASSERT(rtValue == pdPASS, "FSBProtocolTask::InitTask() - xTaskCreate() failed"); } -void FSBProtocolTask::HandleCommand(Data test){ +void FSBProtocolTask::Run(void * pvParams){ + + while (1) { + /* Process commands in blocking mode */ + Command cm; + bool res = qEvtQueue->ReceiveWait(cm); + if(res){ + + HandleCommand(cm); + } + } +} + +void FSBProtocolTask::HandleCommand(Command& cm){ + + + switch(cm.GetTaskCommand()){ + + case PUBLISH_PRESSURE: + { + + PressureData pd; + pd.pressure = 140; + SOAR_PRINT("Pressure published"); + + DataBroker::Publish(&pd); + break; + } + + case PUBLISH_IMU: + { - //Checks for Data type - switch (test.testEnum){ - case PRESSURE_DATA: - PressureData testing; - testing.pressure = 100; //random number to mimic data from test - DataBroker::Publish(&testing); - break; + AccelerometerData acceleration = {100, 150, 200}; + SOAR_PRINT("IMU published"); + DataBroker::Publish(&acceleration); + break; + } - case IMU_DATA: - IMUData imu; - imu.accelX = 5; - imu.accelY = 10; - imu.accelZ = 15; - DataBroker::Publish(&imu); - break; + case PUBLISH_THERMOCOUPLE: + { + ThermocoupleData tc; + tc.temperature = 150; + SOAR_PRINT("Temperature published"); - case THERMOCOUPLE_DATA: - ThermocoupleData temp; - temp.temperature = 100; - DataBroker::Publish(&temp); - break; + DataBroker::Publish(&tc); + break; + } } } diff --git a/Components/FSBProtocol/Inc/FSBProtocolTask.hpp b/Components/FSBProtocol/Inc/FSBProtocolTask.hpp index d88aae1..1b23858 100644 --- a/Components/FSBProtocol/Inc/FSBProtocolTask.hpp +++ b/Components/FSBProtocol/Inc/FSBProtocolTask.hpp @@ -17,6 +17,11 @@ /************************************ * MACROS AND DEFINES ************************************/ +enum FSB_TASK_COMMANDS { + PUBLISH_IMU =0, + PUBLISH_PRESSURE, + PUBLISH_THERMOCOUPLE, +}; /************************************ * TYPEDEFS @@ -45,8 +50,8 @@ class FSBProtocolTask: public Task bool RecieveData(); static void RunTask(void* pvParams) { FSBProtocolTask::Inst().Run(pvParams); } // Static Task Interface, passes control to the instance Run(); void Run(void * pvParams); // Main run code - void HandleCommand(Data test); - uint8_t debugBuffer[LOGGING_RX_BUFFER_SZ_BYTES + 1]; + void HandleCommand(Command& cm); + //uint8_t debugBuffer[LOGGING_RX_BUFFER_SZ_BYTES + 1]; private: // Private Functions diff --git a/Components/PubSubTest/PubSubReceive.cpp b/Components/PubSubTest/PubSubReceive.cpp index c325f0b..e0c51f7 100644 --- a/Components/PubSubTest/PubSubReceive.cpp +++ b/Components/PubSubTest/PubSubReceive.cpp @@ -57,7 +57,7 @@ void PubSubReceive::InitTask() { */ void PubSubReceive::Run(void* pvParams) { // SOAR_PRINT("PUBSUB RECIEVE STARTED\n"); - DataBroker::Subscribe(this->qEvtQueue); + DataBroker::Subscribe(this); // DataBroker::Unsubscribe(this); while (1) { /* Process commands in blocking mode */ @@ -101,9 +101,8 @@ void PubSubReceive::HandleDataBrokerCommand(const Command& cm) { 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(" X -> %d \n", imu_data.imu_stuff); + SOAR_PRINT("--DATA_END--\n\n"); break; } diff --git a/Components/PubSubTest/PubSubSend.cpp b/Components/PubSubTest/PubSubSend.cpp index 9fb3091..5f2d03e 100644 --- a/Components/PubSubTest/PubSubSend.cpp +++ b/Components/PubSubTest/PubSubSend.cpp @@ -64,9 +64,7 @@ void PubSubSend::Run(void* pvParams) { HandleCommand(cm); } else { IMUData imuData = { - .accelX = 1, - .accelY = 2, - .accelZ = 3, + .imu_stuff = 100 }; DataBroker::Publish(&imuData); diff --git a/SoarOS b/SoarOS index bbe2d37..3548484 160000 --- a/SoarOS +++ b/SoarOS @@ -1 +1 @@ -Subproject commit bbe2d373a07fa777a138947e84de2897762299c9 +Subproject commit 35484847eb9796223014863b2044d413c7719a77 From f0cb3ae7bcc7483edcaefb878053893ad62a61e1 Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Sat, 29 Nov 2025 13:23:13 -0700 Subject: [PATCH 16/17] added Protobuf submodule: --- .gitmodules | 3 +++ SoarProtobufs | 1 + 2 files changed, 4 insertions(+) create mode 160000 SoarProtobufs diff --git a/.gitmodules b/.gitmodules index fec813e..a94310c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "SoarCommunications"] path = SoarCommunications url = https://github.com/UCSOAR/CommunicationSystemsSubmodule.git +[submodule "SoarProtobufs"] + path = SoarProtobufs + url = https://github.com/StudentOrganisationForAerospaceResearch/SoarProto.git diff --git a/SoarProtobufs b/SoarProtobufs new file mode 160000 index 0000000..711d668 --- /dev/null +++ b/SoarProtobufs @@ -0,0 +1 @@ +Subproject commit 711d668f5680ec801389f98f42d8ab1a55fbd2e7 From abeae8c361b7df86a1c644e0e9186bd3ddb3a722 Mon Sep 17 00:00:00 2001 From: Jad Dina Date: Sat, 29 Nov 2025 13:27:54 -0700 Subject: [PATCH 17/17] Submodule tracking Jad/Protobufs --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index a94310c..e83611b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,4 @@ [submodule "SoarProtobufs"] path = SoarProtobufs url = https://github.com/StudentOrganisationForAerospaceResearch/SoarProto.git + branch = Jad/Protobufs