Skip to content

Commit aceb2e1

Browse files
committed
feat: catch all anonymous
1 parent 27e08a1 commit aceb2e1

File tree

6 files changed

+99
-79
lines changed

6 files changed

+99
-79
lines changed

Application/Inc/CLI.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class CLI {
1818
void func_info(int32_t argc, char** argv);
1919
void func_rot(int32_t argc, char** argv);
2020
void func_crc(int32_t argc, char** argv);
21-
void func_dac(int32_t argc, char** argv); // Add function declaration
21+
void func_dac(int32_t argc, char** argv);
22+
void func_reset(int32_t argc, char** argv);
2223

2324
private:
2425
void setCommands();

Application/Inc/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#define configTICK_RATE_HZ ((TickType_t)1000)
6565
#define configMAX_PRIORITIES ( 7 )
6666
#define configMINIMAL_STACK_SIZE ((uint16_t)64)
67-
#define configTOTAL_HEAP_SIZE ((size_t)12000)
67+
#define configTOTAL_HEAP_SIZE ((size_t)14000)
6868
#define configMAX_TASK_NAME_LEN ( 16 )
6969
#define configUSE_16_BIT_TICKS 0
7070
#define configUSE_MUTEXES 1

Application/Inc/StateMachine.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SM {
2929
updateInjection(sm, injection, std::forward<ExternalInjection>(args)...);
3030
handleStateChange(sm, nextState, guard, action);
3131
}
32-
runAnonymous(sm, std::forward<ExternalInjection>(args)...);
32+
while(runAnonymous(sm, std::forward<ExternalInjection>(args)...)) {}
3333
}
3434

3535
template <typename... ExternalInjection>
@@ -42,19 +42,21 @@ class SM {
4242
updateInjection(sm, injection, std::forward<ExternalInjection>(args)...);
4343
handleStateChange(sm, state, guard, action);
4444
}
45-
runAnonymous(sm, std::forward<ExternalInjection>(args)...);
45+
while(runAnonymous(sm, std::forward<ExternalInjection>(args)...)) {}
4646
}
4747

4848
template <typename... ExternalInjection>
49-
static void runAnonymous(StateMachine &sm, ExternalInjection... args) {
49+
static bool runAnonymous(StateMachine &sm, ExternalInjection... args) {
5050
auto it = std::ranges::find_if(sm.anonymous.begin(), sm.anonymous.end(),
5151
[&](const auto &entry) { return std::get<0>(entry) == sm.currentState; });
5252

5353
if (it != sm.anonymous.end()) {
5454
auto [fromState, nextState, guard, action, injection] = *it;
5555
updateInjection(sm, injection, std::forward<ExternalInjection>(args)...);
5656
handleStateChange(sm, nextState, guard, action);
57+
return true;
5758
}
59+
return false;
5860
}
5961

6062
static Parent::State getState(Parent::StateMachine &sm) { return sm.currentState; }

Application/Inc/Thread.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class Thread {
2626
TaskHandle_t telemetry_handle;
2727
void runner();
2828
TaskHandle_t runner_handle;
29+
void flashSave();
30+
TaskHandle_t flashSave_handle;
31+
void flashLoad();
32+
TaskHandle_t flashLoad_handle;
2933
void calculator();
3034
TaskHandle_t calculator_handle;
3135
void dacUpdate();

Application/Src/CLI.cpp

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ void CLI::setCommands() {
1414
cmd_map["led"] = [this](int32_t argc, char** argv) { func_led(argc, argv); };
1515
cmd_map["flash"] = [this](int32_t argc, char** argv) { func_flash(argc, argv); };
1616
cmd_map["info"] = [this](int32_t argc, char** argv) { func_info(argc, argv); };
17-
cmd_map["rot"] = [this](int32_t argc, char** argv) { func_rot(argc, argv); };
18-
cmd_map["crc"] = [this](int32_t argc, char** argv) { func_crc(argc, argv); };
19-
cmd_map["dac"] = [this](int32_t argc, char** argv) { func_dac(argc, argv); }; // Register func_dac
17+
cmd_map["rot"] = [this](int32_t argc, char** argv) { func_rot(argc, argv); };
18+
cmd_map["crc"] = [this](int32_t argc, char** argv) { func_crc(argc, argv); };
19+
cmd_map["dac"] = [this](int32_t argc, char** argv) { func_dac(argc, argv); };
20+
cmd_map["reset"] = [this](int32_t argc, char** argv) { func_reset(argc, argv); };
2021
}
2122

2223
void CLI::func_help(int32_t argc, char** argv) {
@@ -87,19 +88,17 @@ void CLI::func_flash(int32_t argc, char** argv) {
8788
if (arg == "help" || arg == "?" || arg == "-h") {
8889
serial.sendString(help_text);
8990
} else if (arg == "save") {
90-
if (flash.Save()) {
91-
serial.sendString("Flash Saved\n");
92-
}
91+
xTaskCreate(Thread::task<&Thread::flashSave>, "Flash Save", 200, NULL, 1, &thread.flashSave_handle);
9392
} else if (arg == "load") {
94-
flash.Load();
95-
} else if (arg == "purge") {
96-
if (flash.Purge()) {
97-
serial.sendString("Flash Purged\n");
98-
}
99-
} else if (arg == "init") {
100-
if(flash.Init()) {
101-
serial.sendString("Flash Initialized\n");
102-
}
93+
xTaskCreate(Thread::task<&Thread::flashLoad>, "Flash Load", 200, NULL, 1, &thread.flashLoad_handle);
94+
} else if (arg == "purge") {
95+
if (flash.Purge()) {
96+
serial.sendString("Flash Purged\n");
97+
}
98+
} else if (arg == "init") {
99+
if (flash.Init()) {
100+
serial.sendString("Flash Initialized\n");
101+
}
103102
} else {
104103
serial.sendString("Command not found\n");
105104
}
@@ -133,50 +132,50 @@ void CLI::func_info(int32_t argc, char** argv) {
133132
}
134133

135134
void CLI::func_rot(int32_t argc, char** argv) {
136-
// Detailed Menu
137-
const char* help_text =
138-
"\nRotation Functions:\n"
139-
" start\t\tStart Rotation\n"
140-
" stop\t\tStop Rotation\n\n";
141-
142-
// Sub Command
143-
if (argc > 1) {
144-
std::string arg = argv[1];
145-
if (arg == "help" || arg == "?" || arg == "-h") {
146-
serial.sendString(help_text);
147-
} else if (arg == "on") {
148-
SM<Thread>::triggerEvent(Thread::Event::START, thread.runner_sm);
149-
} else if (arg == "off") {
150-
SM<Thread>::setState(Thread::State::OFF, thread.runner_sm);
151-
} else if (arg == "set" && argc == 3) {
152-
SM<Thread>::setState(Thread::State::INIT, thread.runner_sm, int{std::stoi(argv[2])});
153-
} else {
154-
serial.sendString("Command not found\n");
155-
}
156-
}
135+
// Detailed Menu
136+
const char* help_text =
137+
"\nRotation Functions:\n"
138+
" start\t\tStart Rotation\n"
139+
" stop\t\tStop Rotation\n\n";
140+
141+
// Sub Command
142+
if (argc > 1) {
143+
std::string arg = argv[1];
144+
if (arg == "help" || arg == "?" || arg == "-h") {
145+
serial.sendString(help_text);
146+
} else if (arg == "on") {
147+
SM<Thread>::triggerEvent(Thread::Event::START, thread.runner_sm);
148+
} else if (arg == "off") {
149+
SM<Thread>::setState(Thread::State::OFF, thread.runner_sm);
150+
} else if (arg == "set" && argc == 3) {
151+
SM<Thread>::setState(Thread::State::INIT, thread.runner_sm, int{std::stoi(argv[2])});
152+
} else {
153+
serial.sendString("Command not found\n");
154+
}
155+
}
157156
}
158157

159158
void CLI::func_crc(int32_t argc, char** argv) {
160-
// Detailed Menu
161-
const char* help_text =
162-
"\nCRC Functions:\n"
163-
" acc [#]\tAccumulate CRC\n"
164-
" cal [#]\tCalculate CRC\n\n";
165-
166-
// Sub Command
167-
if (argc > 1) {
168-
std::string arg = argv[1];
169-
if (arg == "help" || arg == "?" || arg == "-h") {
170-
serial.sendString(help_text);
171-
} else if (arg == "cal") {
172-
if (argc == 3) {
173-
uint8_t input = std::stoi(argv[2]);
174-
SM<Thread>::setState(Thread::State::CRC_CAL, thread.runner_sm, std::vector<uint8_t>{input});
175-
}
176-
} else {
177-
serial.sendString("Command not found\n");
178-
}
179-
}
159+
// Detailed Menu
160+
const char* help_text =
161+
"\nCRC Functions:\n"
162+
" acc [#]\tAccumulate CRC\n"
163+
" cal [#]\tCalculate CRC\n\n";
164+
165+
// Sub Command
166+
if (argc > 1) {
167+
std::string arg = argv[1];
168+
if (arg == "help" || arg == "?" || arg == "-h") {
169+
serial.sendString(help_text);
170+
} else if (arg == "cal") {
171+
if (argc == 3) {
172+
uint8_t input = std::stoi(argv[2]);
173+
SM<Thread>::setState(Thread::State::CRC_CAL, thread.runner_sm, std::vector<uint8_t>{input});
174+
}
175+
} else {
176+
serial.sendString("Command not found\n");
177+
}
178+
}
180179
}
181180

182181
void CLI::func_dac(int32_t argc, char** argv) {
@@ -212,4 +211,6 @@ void CLI::func_dac(int32_t argc, char** argv) {
212211
serial.sendString("Command not found\n");
213212
}
214213
}
215-
}
214+
}
215+
216+
void CLI::func_reset(int32_t argc, char** argv) { NVIC_SystemReset(); }

Application/Src/Thread.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,32 @@ Thread::~Thread() {}
7171
// Initialize System
7272
void Thread::init() {
7373
while (1) {
74-
dac.init();
74+
dac.init();
7575
flash.Load();
7676
SM<Thread>::triggerEvent(Event::INIT_DONE, thread_sm);
7777
vTaskDelete(NULL);
7878
}
7979
}
8080
Action Thread::actionSystemInit() {
81-
return [this]() {
82-
xTaskCreate(task<&Thread::init>, "system init", 800, this, 6, &init_handle);
83-
};
81+
return [this]() { xTaskCreate(task<&Thread::init>, "system init", 1100, this, 6, &init_handle); };
8482
}
8583
Action Thread::actionSystemRun() {
8684
return [this]() {
87-
xTaskCreate(task<&Thread::serialTX>, "serial send tx", 64, this, 1, &serial_handle);
88-
xTaskCreate(task<&Thread::parse>, "cli parsing", 200, this, 2, &parse_handle);
89-
xTaskCreate(task<&Thread::schedule_20Hz>, "schedule 20Hz", 64, this, 5, &schedule_20Hz_handle);
90-
xTaskCreate(task<&Thread::telemetry>, "telemetry", 400, this, 3, &telemetry_handle);
85+
xTaskCreate(task<&Thread::serialTX>, "serial send tx", 100, this, 1, &serial_handle);
86+
xTaskCreate(task<&Thread::parse>, "cli parsing", 420, this, 2, &parse_handle);
87+
xTaskCreate(task<&Thread::schedule_20Hz>, "schedule 20Hz", 64, this, 5, &schedule_20Hz_handle);
88+
xTaskCreate(task<&Thread::telemetry>, "telemetry", 400, this, 3, &telemetry_handle);
9189
vTaskSuspend(telemetry_handle);
92-
xTaskCreate(task<&Thread::runner>, "task simulation", 400, this, 3, &runner_handle);
90+
xTaskCreate(task<&Thread::runner>, "task simulation", 420, this, 3, &runner_handle);
9391
vTaskSuspend(runner_handle);
94-
xTaskCreate(task<&Thread::calculator>, "calculator", 400, this, 5, &calculator_handle);
95-
vTaskSuspend(calculator_handle);
96-
xTaskCreate(task<&Thread::dacUpdate>, "dacUpdate", 64, this, 4, &dacUpdate_handle);
92+
// xTaskCreate(task<&Thread::calculator>, "calculator", 200, this, 5, &calculator_handle);
93+
// vTaskSuspend(calculator_handle);
94+
xTaskCreate(task<&Thread::dacUpdate>, "dacUpdate", 64, this, 4, &dacUpdate_handle);
9795
vTaskSuspend(dacUpdate_handle);
98-
serial.sendString("\nCurrent Free Heap: ");
96+
serial.sendString("\nCurrent Free Heap: ");
9997
serial.sendNumber(xPortGetFreeHeapSize());
100-
serial.sendString("\n\nSystem Boot OK\n");
101-
SM<Thread>::triggerEvent(Event::CREATE_DONE, thread_sm);
98+
serial.sendString("\n\nSystem Boot OK\n");
99+
SM<Thread>::triggerEvent(Event::CREATE_DONE, thread_sm);
102100
};
103101
}
104102

@@ -118,8 +116,8 @@ void Thread::telemetry() {
118116
serial.sendNumber(xPortGetFreeHeapSize());
119117
serial.sendString("\nMinimum Free Heap: ");
120118
serial.sendNumber(xPortGetMinimumEverFreeHeapSize());
121-
serial.sendString("\nStack High Water Mark: ");
122-
serial.sendNumber(static_cast<uint32_t>(uxTaskGetStackHighWaterMark(NULL)));
119+
serial.sendString("\nStack High Water Mark: ");
120+
serial.sendNumber(static_cast<uint32_t>(uxTaskGetStackHighWaterMark(NULL)));
123121
serial.sendLn();
124122

125123
SM<Thread>::triggerEvent(Event::TASK_DONE, telemetry_sm);
@@ -217,6 +215,20 @@ Action Thread::actionRotate() {
217215
};
218216
}
219217

218+
void Thread::flashSave() {
219+
while (1) {
220+
flash.Save();
221+
vTaskDelete(NULL);
222+
}
223+
}
224+
225+
void Thread::flashLoad() {
226+
while (1) {
227+
flash.Load();
228+
vTaskDelete(NULL);
229+
}
230+
}
231+
220232
void Thread::calculator() {
221233
while (1) {
222234
// get std::vector<uint8> input from injection

0 commit comments

Comments
 (0)