add loglevel commands

This commit is contained in:
2023-02-19 22:47:24 +01:00
parent fa85779088
commit 045302cc96
2 changed files with 36 additions and 17 deletions
+19 -12
View File
@@ -28,6 +28,10 @@ extern SPI_HandleTypeDef hspi1;
void print_version(void) { log::info("running PentaTrack v0.1.3"); }
void print_help(void);
void loglevel_error(void) { log::set_loglevel(LogLevel::ERROR); }
void loglevel_info(void) { log::set_loglevel(LogLevel::INFO); }
void loglevel_debug(void) { log::set_loglevel(LogLevel::DEBUG); }
template <size_t Size>
class cmd_holder {
public:
@@ -63,6 +67,7 @@ class cmd_holder {
std::array<command_t, Size> commands;
};
template <size_t Size>
class cmd_handler {
public:
static constexpr auto MaxCmdLength = 24;
@@ -70,11 +75,9 @@ class cmd_handler {
using iterator_t = array_t::iterator;
using const_iterator_t = array_t::const_iterator;
consteval cmd_handler()
: commands{std::make_tuple("ver", "Prints current version.",
&print_version),
std::make_tuple("help", "Prints available commands",
&print_help)},
template <typename... Args>
consteval cmd_handler(Args &&...command_list)
: commands{std::forward<Args &&>(command_list)...},
symbols{},
iterator{symbols.begin()} {}
@@ -121,19 +124,21 @@ class cmd_handler {
void print_help_() const { commands.print_help(); }
private:
cmd_holder<2> commands;
cmd_holder<Size> commands;
array_t symbols;
iterator_t iterator;
bool ShouldExecute = false;
};
static cmd_handler commands{};
static cmd_handler<5> commands{
std::make_tuple("ver", "Prints current version.", &print_version),
std::make_tuple("error", "Set LogLevel to Error.", &loglevel_error),
std::make_tuple("info", "Set LogLevel to Info.", &loglevel_info),
std::make_tuple("debug", "Set LogLevel to Debug.", &loglevel_debug),
std::make_tuple("help", "Prints available commands", &print_help)};
void print_help(void) { commands.print_help_(); }
// cmd_handler::array_t cmd_handler::symbols = cmd_handler::array_t{};
// cmd_handler::iterator_t cmd_handler::iterator = cmd_handler::iterator_t{};
// This prevent name mangling for functions used in C/assembly files.
extern "C" {
void SysTick_Handler(void) {
@@ -183,7 +188,8 @@ void initGPIO() {
GPIO_ConfigSPI.Pin = LoRa_CS_Pin | LoRa_RESET_Pin;
// bare metal init of led1:
// volatile uint32_t* CRH = reinterpret_cast<uint32_t*>(0x40011000 + 0x04);
// volatile uint32_t* CRH = reinterpret_cast<uint32_t*>(0x40011000 +
// 0x04);
//*CRH |= 0x3;
//*CRH &= (~0xC);
@@ -191,7 +197,8 @@ void initGPIO() {
HAL_GPIO_Init(BTN_PORT, &GPIO_Config2);
HAL_GPIO_Init(LoRa_CS_GPIO_Port, &GPIO_ConfigSPI);
// HAL_GPIO_WritePin(LoRa_CS_GPIO_Port, LoRa_CS_Pin, GPIO_PIN_SET);
// HAL_GPIO_WritePin(LoRa_RESET_GPIO_Port, LoRa_RESET_Pin, GPIO_PIN_SET);
// HAL_GPIO_WritePin(LoRa_RESET_GPIO_Port, LoRa_RESET_Pin,
// GPIO_PIN_SET);
}
extern "C" {