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 | 0de4feb | 2022-04-15 12:16:59 -0700 | [diff] [blame] | 14 | |
| 15 | int main(int argc, char *argv[]) { |
| 16 | gflags::SetUsageMessage( |
| 17 | "Runs a websocket server that a foxglove instance can connect to in " |
| 18 | "order to view live data on a device.\n\n" |
| 19 | "Typical Usage: foxglove_websocket [--port 8765]\n" |
| 20 | "If the default port is not exposed directly, you can port-forward with " |
| 21 | "SSH by doing\n" |
| 22 | "$ ssh -L 8765:localhost:8765 ssh_target\n\n" |
| 23 | "When accessing this in foxglove:\n" |
| 24 | "1) Open a data source (this window may be open by default).\n" |
| 25 | "2) Select \"Open Connection\"\n" |
| 26 | "3) Select \"Foxglove WebSocket\" (do NOT select the rosbridge option)\n" |
| 27 | "4) Fill out the URL for the machine. If port forwarding, the default\n" |
| 28 | " ws://localhost:8765 should work.\n\n" |
| 29 | "Note that this does not start up a foxglove instance itself. You must " |
| 30 | "either have one locally on your laptop, or go to " |
| 31 | "https://studio.foxglove.dev, or use another application to serve the " |
| 32 | "foxglove HTML pages.\n" |
| 33 | "If you want to use the studio.foxglove.dev page to view data (which " |
| 34 | "won't send any of your data to foxglove.dev--it's just needed to load " |
| 35 | "the HTML files), you can also go directly to:\n" |
| 36 | "https://studio.foxglove.dev/?ds=foxglove-websocket&ds.url=ws://" |
| 37 | "localhost:8765\n" |
| 38 | "where localhost:8765 must be updated if you aren't port-forwarding " |
| 39 | "and/or are using a different port number. Similarly, if you are serving " |
| 40 | "the static foxglove files locally, you can update the " |
| 41 | "studio.foxglove.dev to point at your local webserver.\n"); |
| 42 | aos::InitGoogle(&argc, &argv); |
| 43 | |
| 44 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 45 | aos::configuration::ReadConfig(FLAGS_config); |
| 46 | |
| 47 | aos::ShmEventLoop event_loop(&config.message()); |
| 48 | |
James Kuszmaul | f1dbaff | 2023-02-08 21:17:32 -0800 | [diff] [blame] | 49 | aos::FoxgloveWebsocketServer server( |
| 50 | &event_loop, FLAGS_port, |
| 51 | FLAGS_mode == "flatbuffer" |
| 52 | ? aos::FoxgloveWebsocketServer::Serialization::kFlatbuffer |
| 53 | : aos::FoxgloveWebsocketServer::Serialization::kJson, |
| 54 | FLAGS_fetch_pinned_channels |
| 55 | ? aos::FoxgloveWebsocketServer::FetchPinnedChannels::kYes |
| 56 | : aos::FoxgloveWebsocketServer::FetchPinnedChannels::kNo); |
James Kuszmaul | 0de4feb | 2022-04-15 12:16:59 -0700 | [diff] [blame] | 57 | |
| 58 | event_loop.Run(); |
| 59 | } |