blob: 44e24c8c94123349de224bae5f804899320d9b6b [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "gflags/gflags.h"
2
James Kuszmaul0de4feb2022-04-15 12:16:59 -07003#include "aos/events/shm_event_loop.h"
4#include "aos/init.h"
5#include "aos/util/foxglove_websocket_lib.h"
James Kuszmaul0de4feb2022-04-15 12:16:59 -07006
James Kuszmaul77d536c2023-02-11 17:30:59 -08007DEFINE_string(config, "aos_config.json", "Path to the config.");
James Kuszmaul0de4feb2022-04-15 12:16:59 -07008DEFINE_uint32(port, 8765, "Port to use for foxglove websocket server.");
James Kuszmaulf1dbaff2023-02-08 21:17:32 -08009DEFINE_string(mode, "flatbuffer", "json or flatbuffer serialization.");
10DEFINE_bool(fetch_pinned_channels, true,
11 "Set this to allow foxglove_websocket to make fetchers on channels "
12 "with a read_method of PIN (see aos/configuration.fbs; PIN is an "
13 "enum value). Having this enabled will cause foxglove to consume "
14 "extra shared memory resources.");
James Kuszmaul1e418f62023-02-26 14:40:20 -080015DEFINE_bool(
16 canonical_channel_names, false,
17 "If set, use full channel names; by default, will shorten names to be the "
18 "shortest possible version of the name (e.g., /aos instead of /pi/aos).");
James Kuszmaul0de4feb2022-04-15 12:16:59 -070019
20int main(int argc, char *argv[]) {
21 gflags::SetUsageMessage(
22 "Runs a websocket server that a foxglove instance can connect to in "
23 "order to view live data on a device.\n\n"
24 "Typical Usage: foxglove_websocket [--port 8765]\n"
25 "If the default port is not exposed directly, you can port-forward with "
26 "SSH by doing\n"
27 "$ ssh -L 8765:localhost:8765 ssh_target\n\n"
28 "When accessing this in foxglove:\n"
29 "1) Open a data source (this window may be open by default).\n"
30 "2) Select \"Open Connection\"\n"
31 "3) Select \"Foxglove WebSocket\" (do NOT select the rosbridge option)\n"
32 "4) Fill out the URL for the machine. If port forwarding, the default\n"
33 " ws://localhost:8765 should work.\n\n"
34 "Note that this does not start up a foxglove instance itself. You must "
35 "either have one locally on your laptop, or go to "
36 "https://studio.foxglove.dev, or use another application to serve the "
37 "foxglove HTML pages.\n"
38 "If you want to use the studio.foxglove.dev page to view data (which "
39 "won't send any of your data to foxglove.dev--it's just needed to load "
40 "the HTML files), you can also go directly to:\n"
41 "https://studio.foxglove.dev/?ds=foxglove-websocket&ds.url=ws://"
42 "localhost:8765\n"
43 "where localhost:8765 must be updated if you aren't port-forwarding "
44 "and/or are using a different port number. Similarly, if you are serving "
45 "the static foxglove files locally, you can update the "
46 "studio.foxglove.dev to point at your local webserver.\n");
47 aos::InitGoogle(&argc, &argv);
48
49 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
50 aos::configuration::ReadConfig(FLAGS_config);
51
52 aos::ShmEventLoop event_loop(&config.message());
53
James Kuszmaulf1dbaff2023-02-08 21:17:32 -080054 aos::FoxgloveWebsocketServer server(
55 &event_loop, FLAGS_port,
56 FLAGS_mode == "flatbuffer"
57 ? aos::FoxgloveWebsocketServer::Serialization::kFlatbuffer
58 : aos::FoxgloveWebsocketServer::Serialization::kJson,
59 FLAGS_fetch_pinned_channels
60 ? aos::FoxgloveWebsocketServer::FetchPinnedChannels::kYes
James Kuszmaul1e418f62023-02-26 14:40:20 -080061 : aos::FoxgloveWebsocketServer::FetchPinnedChannels::kNo,
62 FLAGS_canonical_channel_names
63 ? aos::FoxgloveWebsocketServer::CanonicalChannelNames::kCanonical
64 : aos::FoxgloveWebsocketServer::CanonicalChannelNames::kShortened);
James Kuszmaul0de4feb2022-04-15 12:16:59 -070065
66 event_loop.Run();
67}