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