45 lines
1.6 KiB
C++
45 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace fgc {
|
|
|
|
// A parsed console command line: "<verb> [device] [option] [value]".
|
|
// Examples:
|
|
// "snapshot" -> verb=snapshot
|
|
// "capture on" -> verb=capture device=on
|
|
// "gimbal nudge yaw 5" -> verb=gimbal device=nudge option=yaw value=5
|
|
// "set camera profile night" -> verb=set device=camera option="profile night"
|
|
struct Command {
|
|
std::string verb;
|
|
std::string device;
|
|
std::string option;
|
|
double value = 0.0;
|
|
bool has_value = false;
|
|
|
|
bool empty() const { return verb.empty(); }
|
|
};
|
|
|
|
// Whitespace-tokenizing parser. Robust to commands with or without a trailing
|
|
// numeric value and to non-numeric option strings (e.g. raw motor commands).
|
|
// Replaces the fragile Boost.Spirit Qi grammar.
|
|
Command parseCommand(const std::string& line);
|
|
|
|
// The target of `gimbal move` / `gimbal steps`: "<yaw>[,<pitch>]", also written
|
|
// "<yaw> <pitch>", read from tokens[from] onward. Pitch is optional, so the same
|
|
// command aims a yaw-only tower. nullopt when yaw is missing, a value is not a
|
|
// number, or anything follows the pitch.
|
|
struct Aim {
|
|
double yaw = 0.0;
|
|
std::optional<double> pitch;
|
|
};
|
|
std::optional<Aim> parseAim(const std::vector<std::string>& tokens, size_t from);
|
|
|
|
// The firmware MOVE to absolute counts: "MOVE <yaw>,<pitch>" with a pitch, else
|
|
// "MOVE Y <yaw>" - which a yaw-only firmware needs, as it refuses the pair.
|
|
std::string moveCommand(long yaw_counts, std::optional<long> pitch_counts);
|
|
|
|
} // namespace fgc
|