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