Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
cmd_parser.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <array>
7#include <cstddef>
8#include <cstdint>
9
11
12namespace lampda {
13namespace common {
14namespace cli {
15
16static constexpr size_t MaxStringArgumentLen = 32;
17
19{
20 static constexpr uint8_t maxArgumentCount = 8;
21
22 bsp::text_in::Inputs::Command buffer {};
23
24 uint8_t commandOffset = 0;
25 std::array<uint8_t, maxArgumentCount> argumentOffsets {};
26 uint8_t argumentCount = 0;
27
29 const char* name() const;
30
32 const char* argument(const size_t index) const;
33
36};
37
39namespace argument {
40
42bool parse_uint8(const ParsedCommand& command, const size_t index, uint8_t& value);
43
45bool parse_uint16(const ParsedCommand& command, const size_t index, uint16_t& value);
46
48bool parse_text(const ParsedCommand& command, const size_t index, std::array<char, MaxStringArgumentLen>& value);
49
50} // namespace argument
51
55ParsedCommand parseCommand(const bsp::text_in::Inputs::Command& input);
56
57} // namespace cli
58} // namespace common
59} // namespace lampda
bool parse_text(const ParsedCommand &command, const size_t index, std::array< char, MaxStringArgumentLen > &value)
Parse an argument as a char array.
Definition: cmd_parser.cpp:95
bool parse_uint8(const ParsedCommand &command, const size_t index, uint8_t &value)
Parse an argument as a 8 bit unsigned number.
Definition: cmd_parser.cpp:67
bool parse_uint16(const ParsedCommand &command, const size_t index, uint16_t &value)
Parse an argument as a 16 bit unsigned number.
Definition: cmd_parser.cpp:81
Program scope.
Definition: control_fixed_modes.hpp:12
Definition: cmd_parser.h:19
const char * argument(const size_t index) const
Return the argument at the desired index, or nullptr if it do not exist.
Definition: cmd_parser.cpp:22
const char * name() const
Return the name of the command.
Definition: cmd_parser.cpp:20
ParsedCommand shift_to_first_parameter() const
Create a new command shifted by one argument.
Definition: cmd_parser.cpp:30
Handle user text inputs.