acquisition: drive a DataSource from the registry; --source and --source-opt
This commit is contained in:
1 parent
46076312cc
commit
504bc193ea
8 files changed
+156
-164
No files matched your search
+36
-2
@@ -6,6 +6,7 @@
|
||||
// For `RowSet::kMaxRows`: `--plots` names a row count, and one constant for the ceiling
|
||||
// is what stops the message and the clamp from drifting apart.
|
||||
#include "plot_host.hpp"
|
||||
#include "source/registry.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -40,14 +41,35 @@ double parse_double(const char* name, const std::string& v) {
|
||||
|
||||
} // namespace
|
||||
|
||||
SourceConfig Config::source_config() const {
|
||||
SourceConfig out;
|
||||
if (source_kind == "udps") {
|
||||
out.set("server", server);
|
||||
out.set("port", std::to_string(port));
|
||||
if (!multicast.empty()) out.set("multicast", multicast);
|
||||
if (!interface_addr.empty()) out.set("interface", interface_addr);
|
||||
out.set("recv_buffer", std::to_string(recv_buffer_bytes));
|
||||
}
|
||||
for (const auto& kv : source_opts.items()) out.set(kv.first, kv.second);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string Config::session_host() const { return udpscope::session_host(source_kind, source_config()); }
|
||||
std::uint16_t Config::session_port() const { return udpscope::session_port(source_kind, source_config()); }
|
||||
|
||||
void print_usage(std::FILE* out, const char* argv0) {
|
||||
std::string names;
|
||||
for (const SourceKind* k : kinds()) names += (names.empty() ? "" : ", ") + k->id();
|
||||
std::fprintf(out,
|
||||
"usage: %s --server ADDR --port PORT [options]\n"
|
||||
"usage: %s --server ADDR --port PORT [--source NAME] [options]\n"
|
||||
"\n"
|
||||
" --server ADDR stream source IPv4 address (default 127.0.0.1)\n"
|
||||
" --port PORT UDP port (unicast) or TCP port (multicast) (default 8000)\n"
|
||||
" --multicast GROUP join GROUP for DATA instead of unicast\n"
|
||||
" --interface ADDR local IPv4 of the interface to join on\n"
|
||||
" --source NAME source kind (%s; default udps). --server/--port/\n"
|
||||
" --multicast/--interface configure udps\n"
|
||||
" --source-opt K=V a setting for the source kind; repeatable\n"
|
||||
" --buffer-mb MB size of each of the two sample buffers (default 200)\n"
|
||||
" --max-window SEC largest time window the toolbar offers (default 600)\n"
|
||||
" --holdoff SEC default trigger hold-off (default 0.010)\n"
|
||||
@@ -69,7 +91,7 @@ void print_usage(std::FILE* out, const char* argv0) {
|
||||
" and the GL area has no hardware context, so the window\n"
|
||||
" never paints or allocates\n"
|
||||
" -h, --help this text\n",
|
||||
argv0);
|
||||
argv0, names.c_str());
|
||||
}
|
||||
|
||||
Config parse_args(int argc, char** argv) {
|
||||
@@ -91,6 +113,18 @@ Config parse_args(int argc, char** argv) {
|
||||
c.multicast = value_of(argc, argv, i, "--multicast");
|
||||
} else if (a == "--interface" || a.rfind("--interface=", 0) == 0) {
|
||||
c.interface_addr = value_of(argc, argv, i, "--interface");
|
||||
} else if (a == "--source" || a.rfind("--source=", 0) == 0) {
|
||||
const std::string v = value_of(argc, argv, i, "--source");
|
||||
if (find_kind(v) == nullptr) {
|
||||
std::string names;
|
||||
for (const SourceKind* k : kinds()) names += (names.empty() ? "" : ", ") + k->id();
|
||||
fail("unknown source '" + v + "' (available: " + names + ")");
|
||||
}
|
||||
c.source_kind = v;
|
||||
c.source_specified = true;
|
||||
} else if (a == "--source-opt" || a.rfind("--source-opt=", 0) == 0) {
|
||||
const std::string v = value_of(argc, argv, i, "--source-opt");
|
||||
if (!c.source_opts.parse_assignment(v)) fail("--source-opt must be key=value: " + v);
|
||||
} else if (a == "--buffer-mb" || a.rfind("--buffer-mb=", 0) == 0) {
|
||||
c.buffer_mb = parse_double("--buffer-mb", value_of(argc, argv, i, "--buffer-mb"));
|
||||
c.buffer_mb_specified = true;
|
||||
|
||||
Reference in new issue
Block a user