-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogging_Task_M.cpp
More file actions
159 lines (128 loc) · 4.25 KB
/
Logging_Task_M.cpp
File metadata and controls
159 lines (128 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
********************************************************************************
* @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 "DataBroker.hpp"
#include "DataBrokerMessageTypes.hpp"
/************************************
* PRIVATE MACROS AND DEFINES
************************************/
/************************************
* VARIABLES
************************************/
/************************************
* FUNCTION DECLARATIONS
************************************/
/************************************
* FUNCTION DEFINITIONS
************************************/
/**
* @brief Constructor for LoggingTask
*/
LoggingTask::LoggingTask()
: Task(LOGGING_TASK_DEPTH_OBJS)
{
}
/**
* @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)LOGGING_TASK_DEPTH_WORDS,
(void*)this,
(UBaseType_t)LOGGING_TASK_PRIORITY,
(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<AccelerometerData>(this);
DataBroker::Subscribe<PressureData>(this);
DataBroker::Subscribe<ThermocoupleData>(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 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){
DataBrokerMessageTypes messageType = DataBroker::getMessageType(cm);
AccelerometerData accel_data = {};
PressureData pressure_data = {};
ThermocoupleData thermocouple_data = {};
switch (messageType){
case DataBrokerMessageTypes :: ACCELEROMETER_DATA:
accel_data = DataBroker::ExtractData<AccelerometerData>(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:
pressure_data = DataBroker::ExtractData<PressureData>(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:
thermocouple_data = DataBroker::ExtractData<ThermocoupleData>(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;
}
}