diff --git a/Components/Core/Inc/Command.hpp b/Components/Core/Inc/Command.hpp index 64c3c921..0efed470 100644 --- a/Components/Core/Inc/Command.hpp +++ b/Components/Core/Inc/Command.hpp @@ -25,9 +25,11 @@ enum GLOBAL_COMMANDS : uint8_t HEARTBEAT_COMMAND, // Control actions for heartbeat commands RADIOHB_CHANGE_PERIOD, // Change Radio HB Period to Provided TaskCommand Period in Seconds PROTOCOL_COMMAND, // Protocol command, used for commands to the Protocol Task - TELEMETRY_CHANGE_PERIOD, // Change Telemetry Period to Provided TaskCommand Period in Milliseconds + TELEMETRY_CHANGE_PERIOD, // Change Telemetry Period to Provided TaskCommand Period in Milliseconds + DATA_BROKER_COMMAND, }; + /* Class -----------------------------------------------------------------*/ /** diff --git a/Components/DataBroker/Inc/DataBroker.hpp b/Components/DataBroker/Inc/DataBroker.hpp new file mode 100644 index 00000000..a2257701 --- /dev/null +++ b/Components/DataBroker/Inc/DataBroker.hpp @@ -0,0 +1,173 @@ +/** + ******************************************************************************** + * @file DataBroker.hpp + * @author shivam + * @date Nov 23, 2024 + * @brief + ******************************************************************************** + */ + +#ifndef DATA_BROKER_HPP_ +#define DATA_BROKER_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include "Publisher.hpp" +#include "SensorDataTypes.hpp" +#include "Command.hpp" +#include "DataBrokerMessageTypes.hpp" +#include "SystemDefines.hpp" +#include "Mutex.hpp" +#include +#include + +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ +class DataBroker { + public: + /** + * @brief Publish data of a certain type + * NOTE: You must ensure that there is a publisher for that type + */ + template + static void Publish(T* dataToPublish) { + if (subscriberListLock.Lock(SUBSCRIBER_LIST_MUTEX_TIMEOUT)) { + Publisher* publisher = getPublisher(); + if (publisher != nullptr) { + publisher->Publish(dataToPublish); + } + else { + SOAR_ASSERT("Data Publisher not found \n"); + } + subscriberListLock.Unlock(); + return; + } + else { + SOAR_PRINT("Could Not Subscribe to Data Broker Publisher \n"); + } + return; + } + + /** + * @brief Subscribe to a certain type of data in the system + * @param taskToSubscribe Task Handle of the task that will receive + * and handle the data. (i.e. -> Subscribe(this)) + */ + template + static void Subscribe(Task* taskToSubscribe) { + if (subscriberListLock.Lock(SUBSCRIBER_LIST_MUTEX_TIMEOUT)) { + Publisher* publisher = getPublisher(); + if (publisher != nullptr) { + publisher->Subscribe(taskToSubscribe); + } + else { + SOAR_ASSERT("Data Publisher not found \n"); + } + subscriberListLock.Unlock(); + return; + } + else { + SOAR_PRINT("Could Not Subscribe to Data Broker Publisher \n"); + } + return; + } + + /** + * @brief Unsubscribe to a certain type of data in the system + * @param taskToUnsubscribe Task Handle of the task that will stop + * receiving the data. (i.e. -> Unsubscribe(this)) + */ + template + static void Unsubscribe(Task* taskToUnsubscribe) { + if (subscriberListLock.Lock(SUBSCRIBER_LIST_MUTEX_TIMEOUT)) { + Publisher* publisher = getPublisher(); + if (publisher != nullptr) { + publisher->Unsubscribe(taskToUnsubscribe); + } + else { + SOAR_ASSERT("Data Publisher not found \n"); + } + subscriberListLock.Unlock(); + return; + } + else { + SOAR_PRINT("Could Not Unsubscribe to Data Broker Publisher \n"); + } + return; + } + + template + static constexpr T ExtractData(const Command &cm) { + if (cm.GetCommand() != DATA_BROKER_COMMAND) { + SOAR_ASSERT("Not a Data Broker Command!\n"); + } + + // The data allocated by this command ptr will be freed when cm.Reset()] + // is called. So we do not have to free this memory here + T* dataPtr = reinterpret_cast(cm.GetDataPointer()); + + T data{}; + + std::memcpy(&data, dataPtr, sizeof(T)); + + return data; + } + + static DataBrokerMessageTypes getMessageType(const Command &cm) { + return static_cast(cm.GetTaskCommand()); + } + + private: + // Deleting the default constructor as this class is not + // instanceable + DataBroker() = delete; + + // Deleting the copy constructor to prevent copies + DataBroker(const DataBroker& obj) = delete; + + // Deleting assignment operator to prevent assignment operations + DataBroker& operator=(DataBroker const&) = delete; + + // Mutex to access the Subscriber List + inline static Mutex subscriberListLock{}; + // Mutex lock wait time + static constexpr uint16_t SUBSCRIBER_LIST_MUTEX_TIMEOUT = 1000; + + // matcher - match template type with publisher type + template + static constexpr bool matchType() { + return std::is_same_v; + } + + // get data publisher + template + static constexpr auto getPublisher(void) { + if constexpr (matchType()) { + return &IMU_Data_publisher; + } else if constexpr (matchType()) { + return &Thermocouple_Data_publisher; + } else { + SOAR_ASSERT(false, "This publisher type does not exist, you must create it"); + } + } + + // list of publishers + inline static Publisher IMU_Data_publisher {DataBrokerMessageTypes::IMU_DATA}; + inline static Publisher Thermocouple_Data_publisher {DataBrokerMessageTypes::THERMOCOUPLE_DATA}; + +}; +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +#endif /* DATA_BROKER_HPP_ */ diff --git a/Components/DataBroker/Inc/Publisher.hpp b/Components/DataBroker/Inc/Publisher.hpp new file mode 100644 index 00000000..37c48c87 --- /dev/null +++ b/Components/DataBroker/Inc/Publisher.hpp @@ -0,0 +1,108 @@ +/** + ******************************************************************************** + * @file Publisher.hpp + * @author shivam + * @date Nov 23, 2024 + * @brief + ******************************************************************************** + */ + +#ifndef PUBLISHER_HPP_ +#define PUBLISHER_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include +#include +#include +#include "Task.hpp" +#include "Subscriber.hpp" +#include "SystemDefines.hpp" + + +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ +template +class Publisher { + public: + // Constructor + Publisher(DataBrokerMessageTypes messageType) { + publisherMessageType = messageType; + } + + // subscribe + bool Subscribe(Task* taskToSubscribe) { + // Check if subscriber already exists + for (Subscriber& subscriber : subscribersList) { + if (subscriber.getSubscriberTaskHandle() == taskToSubscribe) { + return true; + } + } + + // Add the subscriber + for (Subscriber& subscriber : subscribersList) { + if (subscriber.getSubscriberTaskHandle() == nullptr) { + subscriber.Init(taskToSubscribe); + return true; + } + } + + SOAR_ASSERT(true, "Failed to add subscriber\n"); + return false; + } + + // unsubscribe + bool Unsubscribe(Task* taskToUnsubscribe) { + for (Subscriber& subscriber : subscribersList) { + if (subscriber.getSubscriberTaskHandle() == taskToUnsubscribe) { + subscriber.Delete(); + return true; + } + } + + SOAR_ASSERT(true, "Subscriber not Deleted\n"); + return false; + } + + // publish + void Publish(T* dataToPublish) { + for (const Subscriber& subscriber : subscribersList) { + if (subscriber.getSubscriberTaskHandle() != nullptr) { + // create command + uint16_t messageType = static_cast(publisherMessageType); + + Command brokerData(DATA_BROKER_COMMAND, messageType); + + uint8_t* messsageData = reinterpret_cast(dataToPublish); + + // copy data to command + brokerData.CopyDataToCommand(messsageData, sizeof(T)); + + subscriber.getSubscriberQueueHandle()->Send(brokerData); + } + } + } + + private: + // list of subscribers + Subscriber subscribersList[MaxSubscribers] = {}; + + // message type for system routing + DataBrokerMessageTypes publisherMessageType = DataBrokerMessageTypes::INVALID; +}; + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +#endif /* PUBLISHER_HPP_ */ diff --git a/Components/DataBroker/Inc/Subscriber.hpp b/Components/DataBroker/Inc/Subscriber.hpp new file mode 100644 index 00000000..c3ec88bd --- /dev/null +++ b/Components/DataBroker/Inc/Subscriber.hpp @@ -0,0 +1,59 @@ +/** + ******************************************************************************** + * @file Subscriber.hpp + * @author shiva + * @date Nov 23, 2024 + * @brief + ******************************************************************************** + */ + +#ifndef SUBSCRIBER_HPP_ +#define SUBSCRIBER_HPP_ + +/************************************ + * INCLUDES + ************************************/ +#include "Task.hpp" +#include "SystemDefines.hpp" + +/************************************ + * MACROS AND DEFINES + ************************************/ + +/************************************ + * TYPEDEFS + ************************************/ + +/************************************ + * CLASS DEFINITIONS + ************************************/ +class Subscriber { + public: + void Init(Task* subscriberTaskHandle) { + if (taskHandle != nullptr || taskQueue != nullptr) { + SOAR_ASSERT(false, "You cannot overwrite a subscriber"); + return; + } + taskHandle = subscriberTaskHandle; + taskQueue = taskHandle->GetEventQueue(); + } + + void Delete() { + taskHandle = nullptr; + taskQueue = nullptr; + } + + inline const Task* getSubscriberTaskHandle() const { return taskHandle; } + + inline Queue* getSubscriberQueueHandle() const { return taskQueue; } + + private: + Task* taskHandle = nullptr; + Queue* taskQueue = nullptr; +}; + +/************************************ + * FUNCTION DECLARATIONS + ************************************/ + +#endif /* SUBSCRIBER_HPP_ */ diff --git a/Components/FlightControl/Inc/WatchdogTask.hpp b/Components/FlightControl/Inc/WatchdogTask.hpp index 658333ca..07e9a258 100644 --- a/Components/FlightControl/Inc/WatchdogTask.hpp +++ b/Components/FlightControl/Inc/WatchdogTask.hpp @@ -36,6 +36,7 @@ class WatchdogTask : public Task static void HeartbeatFailureCallback(TimerHandle_t rtTimerHandle); // Callback for timer which aborts system in case of data ghosting void HandleCommand(Command& cm); void HandleHeartbeat(uint16_t taskCommand); // If it receives a heartbeat then it resets the timer + void HandleDataBrokerCommand(const Command& cm); Timer* heartbeatTimer; private: diff --git a/Components/FlightControl/TelemetryTask.cpp b/Components/FlightControl/TelemetryTask.cpp index 0eb79452..9788f932 100644 --- a/Components/FlightControl/TelemetryTask.cpp +++ b/Components/FlightControl/TelemetryTask.cpp @@ -55,7 +55,7 @@ void TelemetryTask::Run(void* pvParams) HandleCommand(cm); osDelay(loggingDelayMs); - RunLogSequence(); +// RunLogSequence(); } } diff --git a/Components/FlightControl/WatchdogTask.cpp b/Components/FlightControl/WatchdogTask.cpp index 183dce65..ccb8c40f 100644 --- a/Components/FlightControl/WatchdogTask.cpp +++ b/Components/FlightControl/WatchdogTask.cpp @@ -9,6 +9,7 @@ #include "Timer.hpp" #include "WatchdogTask.hpp" #include "FlightTask.hpp" +#include "DataBroker.hpp" /** @@ -64,6 +65,9 @@ void WatchdogTask::HandleCommand(Command& cm) SOAR_PRINT("HB Period Changed to %d s\n", (cm.GetTaskCommand())); heartbeatTimer->ChangePeriodMsAndStart((cm.GetTaskCommand()*1000)); break; + case DATA_BROKER_COMMAND: + HandleDataBrokerCommand(cm); + break; default: SOAR_PRINT("WatchdogTask - Received Unsupported Command {%d}\n", cm.GetCommand()); break; @@ -103,6 +107,8 @@ void WatchdogTask::Run(void * pvParams) heartbeatTimer->ChangePeriodMs(5000); heartbeatTimer->Start(); + DataBroker::Subscribe(this); + while (1) { //TODO: Move into HID Task GPIO::LED1::On(); @@ -129,3 +135,29 @@ void WatchdogTask::Run(void * pvParams) } } + +/** + * @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 WatchdogTask::HandleDataBrokerCommand(const Command& cm) { + DataBrokerMessageTypes messageType = DataBroker::getMessageType(cm); + switch (messageType) { + + case DataBrokerMessageTypes::THERMOCOUPLE_DATA: { + ThermocoupleData thermData = DataBroker::ExtractData(cm); + SOAR_PRINT("\n THERMOCOUPLE DATA START: \n"); + SOAR_PRINT(" Temp -> %d \n", thermData.temperature); + SOAR_PRINT("--DATA_END--\n\n"); + break; + } + + case DataBrokerMessageTypes::INVALID: + [[fallthrough]]; + default: + break; + } +} diff --git a/Components/PubSubTest/Inc/PubSubReceive.hpp b/Components/PubSubTest/Inc/PubSubReceive.hpp new file mode 100644 index 00000000..e8f23776 --- /dev/null +++ b/Components/PubSubTest/Inc/PubSubReceive.hpp @@ -0,0 +1,57 @@ +/** + ******************************************************************************** + * @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 00000000..ebe76205 --- /dev/null +++ b/Components/PubSubTest/Inc/PubSubSend.hpp @@ -0,0 +1,56 @@ +/** + ******************************************************************************** + * @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 00000000..239fb415 --- /dev/null +++ b/Components/PubSubTest/PubSubReceive.cpp @@ -0,0 +1,128 @@ +/** + ******************************************************************************** + * @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 00000000..3ec37925 --- /dev/null +++ b/Components/PubSubTest/PubSubSend.cpp @@ -0,0 +1,105 @@ +/** + ******************************************************************************** + * @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/Components/SystemDefines.hpp b/Components/SystemDefines.hpp index ac750471..30803c99 100644 --- a/Components/SystemDefines.hpp +++ b/Components/SystemDefines.hpp @@ -94,6 +94,16 @@ constexpr uint16_t BATTERY_TASK_STACK_DEPTH_WORDS = 512; // Size of the b constexpr uint32_t TELEMETRY_DEFAULT_LOGGING_RATE_MS = 1000; // Default logging delay for telemetry task +// 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 + /* Flash Addresses ------------------------------------------------------------------*/ // Start of the system storage area (spans 2 sectors) // Holds previous Rocket State, and other low-frequency state information diff --git a/Components/SystemTypes/DataBrokerMessageTypes.hpp b/Components/SystemTypes/DataBrokerMessageTypes.hpp new file mode 100644 index 00000000..d43ede08 --- /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/SystemTypes/SensorDataTypes.hpp b/Components/SystemTypes/SensorDataTypes.hpp new file mode 100644 index 00000000..1fd8ad5c --- /dev/null +++ b/Components/SystemTypes/SensorDataTypes.hpp @@ -0,0 +1,42 @@ +/** + ******************************************************************************** + * @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 new file mode 100644 index 00000000..e3d046b0 --- /dev/null +++ b/Components/SystemTypes/SystemCommunicationTypes.hpp @@ -0,0 +1,22 @@ +/** + ******************************************************************************** + * @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 new file mode 100644 index 00000000..578f0972 --- /dev/null +++ b/Components/SystemTypes/SystemConfigTypes.hpp @@ -0,0 +1,18 @@ +/** + ******************************************************************************** + * @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/Components/main_avionics.cpp b/Components/main_avionics.cpp index 9420cf86..f4a54383 100644 --- a/Components/main_avionics.cpp +++ b/Components/main_avionics.cpp @@ -29,6 +29,8 @@ #include "PressureTransducerTask.hpp" #include "BatteryTask.hpp" #include "GPSTask.hpp" +#include "PubSubReceive.hpp" +#include "PubSubSend.hpp" //TODO: Temporary UART fakes UART_HandleTypeDef huart1; @@ -44,7 +46,7 @@ Mutex Global::vaListMutex; */ void run_main() { // Init Tasks - osDelay(500); // TODO: Get rid of this if possible?? +// osDelay(500); // TODO: Get rid of this if possible?? WatchdogTask::Inst().InitTask(); FlightTask::Inst().InitTask(); UARTTask::Inst().InitTask(); @@ -58,6 +60,8 @@ void run_main() { //BatteryTask::Inst().InitTask(); //GPSTask::Inst().InitTask(); FlashTask::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-- SOAR AVIONICS --\n");