fwt_software/include/fgc/ChannelTopics.h

45 lines
1.8 KiB
C++

#pragma once
#include "fgc/IControlChannel.h"
#include <string>
namespace fgc {
// Topic names and payload encoding for the control channel, kept here rather
// than inside MqttControlChannel so the null channel produces byte-identical
// output (its history has to show what WOULD have been sent, not an
// approximation) and so the JSON is unit-testable without a broker.
//
// Scheme: GGS/FWT/<tower>/<leaf> — see docs/mqtt-api.md.
// Leaf names, so the two channels and the UI agree on spelling.
inline constexpr const char* kTopicTargetHdg = "target_HDG";
inline constexpr const char* kTopicControlCode = "ControlCode";
inline constexpr const char* kTopicStatusCode = "StatusCode";
inline constexpr const char* kTopicCamEvent = "CamEvent";
// Any console command, in; its answer, out. See docs/mqtt-api.md.
inline constexpr const char* kTopicCommand = "Command";
inline constexpr const char* kTopicCommandReply = "CommandReply";
std::string towerTopic(const std::string& tower, const std::string& leaf);
// Payload builders. One definition each, used by both channels.
std::string camEventJson(const CamEvent& e);
// A Command payload: {"id":"...","cmd":"..."} (a flat JSON object of strings;
// other keys ignored), or a bare command line with no id - for testing from a
// shell. On a payload that is neither, `error` says why.
RemoteCommand parseCommandPayload(const std::string& payload);
// A CommandReply payload. Caps the lines at kReplyMaxLines / kReplyMaxBytes and
// sets `truncated` when it had to cut.
inline constexpr size_t kReplyMaxLines = 200;
inline constexpr size_t kReplyMaxBytes = 16 * 1024;
std::string commandReplyJson(const CommandReply& r);
// A JSON string literal, quotes included, with the escapes JSON requires.
std::string jsonString(const std::string& s);
} // namespace fgc