CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
SerialCmd.h
Go to the documentation of this file.
1#pragma once
2
3#include "ICommandRegistry.h"
4#include <cstdint>
5
6namespace cdc::serial {
7
11using TextChangeCallback = void (*)(const char* field, const char* value);
12using TimeChangeCallback = void (*)();
13
23class SerialCmd {
24public:
25 static constexpr size_t CMD_BUFFER_SIZE = 256;
26 static constexpr uint32_t AUTH_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
27
31 static void init();
32
38 static bool process();
39
44
45 // === Callbacks ===
46
50 static void setTextCallback(TextChangeCallback callback);
51
55 static void setTimeCallback(TimeChangeCallback callback);
56
57 // === Authentication (FEATURE_SECURE_SERIAL) ===
58
62 static bool isAuthenticated();
63
68 static bool authenticate(const char* pin);
69
73 static void logout();
74
80 static void touchAuthSession();
81
82 // === Built-in Commands ===
83
87 static void registerBuiltinCommands();
88
89private:
90 SerialCmd() = delete; // Static-only class
91
92 static void executeCommand(char* cmd);
93 static char* trim(char* str);
94
98 enum class HistoryDirection : uint8_t { OLDER, NEWER };
99
104 static void handleHistoryNav(HistoryDirection dir);
105
111 static bool handleEscape(int c);
112
118 static void handleSpecialChar(int c, bool& commandReady);
119};
120
121} // namespace cdc::serial
static bool isAuthenticated()
Returns whether the serial session is currently authenticated.
static void registerBuiltinCommands()
Registers all built-in serial commands.
static void init()
Public SerialCmd interface implementation.
static bool process()
Processes one pending input character from the serial console.
static ICommandRegistry & getRegistry()
Returns the shared command registry instance.
static void logout()
Logs out the current serial session.
static void setTextCallback(TextChangeCallback callback)
Sets the callback used by text-setting commands.
static bool authenticate(const char *pin)
Attempts to authenticate the serial session with a PIN.
static void setTimeCallback(TimeChangeCallback callback)
Sets the callback invoked after successful date/time updates.
static constexpr uint32_t AUTH_TIMEOUT_MS
Definition SerialCmd.h:26
static constexpr size_t CMD_BUFFER_SIZE
Definition SerialCmd.h:25
static void touchAuthSession()
Keeps the auth session alive during a long-running serial activity.
void(*)() TimeChangeCallback
Definition SerialCmd.h:12
void(*)(const char *field, const char *value) TextChangeCallback
Definition SerialCmd.h:11