platform: implement commands for task management

This commit is contained in:
Torrie Fischer 2023-12-11 08:07:52 +01:00
parent ef74dc2178
commit d36de899fd
2 changed files with 74 additions and 0 deletions

View File

@ -255,6 +255,78 @@ Platform::restart() {
#endif
}
__attribute__((noreturn))
void
doReboot(Args& args, Print& out)
{
out.println("Rebooting");
Platform::restart();
}
__attribute__((noreturn))
void
doSafeMode(Args& args, Print& out)
{
out.println("Rebooting into safe mode");
Platform::bootopts.forceSafeMode();
Platform::restart();
}
String s;
void
doTaskStart(Args& args, Print& out)
{
s = args[1];
MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, s.c_str()});
}
void
doTaskStop(Args& args, Print& out)
{
s = args[1];
MainLoop::instance()->dispatch(InputEvent{InputEvent::StopThing, s.c_str()});
}
void
doTaskList(Args& args, Print& out)
{
auto sched = MainLoop::instance()->scheduler;
auto printer = Static<SerialInput>::instance()->printer();
out.println("Tasks:");
for(auto task : sched.tasks) {
bool isFigment = task->isFigment();
if (task->state == Task::Running) {
out.print("+");
} else {
out.print("-");
}
if (isFigment) {
out.print("F ");
} else {
out.print("T ");
}
out.println(task->name);
}
}
const std::vector<Command> _commands = {
{"tasks", doTaskList},
{"safe-mode", doSafeMode},
{"reboot", doReboot},
{"stop", doTaskStop},
{"start", doTaskStart}
};
const std::vector<Command>&
Platform::commands() const
{
return _commands;
}
BootOptions
Platform::bootopts;

View File

@ -105,4 +105,6 @@ class Platform : public Task {
}
static void restart();
const std::vector<Command>& commands() const override;
};