blob: e6b71ea730445a2681f6ad3d9d9f6ab0df925b53 [file] [log] [blame]
Austin Schuh99f7c6a2024-06-25 22:07:44 -07001#include "absl/flags/flag.h"
2
Austin Schuhe84c3ed2019-12-14 15:29:48 -08003#include "aos/events/shm_event_loop.h"
4#include "aos/init.h"
Sarah Newman45a64df2022-04-11 19:33:46 -07005#include "aos/logging/dynamic_logging.h"
Austin Schuh60e77942022-05-16 17:48:24 -07006#include "aos/network/message_bridge_client_lib.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07007#include "aos/network/sctp_lib.h"
Austin Schuhb0e439d2023-05-15 10:55:40 -07008#include "aos/sha256.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07009#include "aos/util/file.h"
Austin Schuhe84c3ed2019-12-14 15:29:48 -080010
Austin Schuh99f7c6a2024-06-25 22:07:44 -070011ABSL_FLAG(std::string, config, "aos_config.json", "Path to the config.");
12ABSL_FLAG(int32_t, rt_priority, -1, "If > 0, run as this RT priority");
13ABSL_FLAG(bool, wants_sctp_authentication, false,
14 "When set, try to use SCTP authentication if provided by the kernel");
Austin Schuhe84c3ed2019-12-14 15:29:48 -080015
Stephan Pleinesf63bde82024-01-13 15:59:33 -080016namespace aos::message_bridge {
Austin Schuhe84c3ed2019-12-14 15:29:48 -080017
Adam Snaider96a0f4b2023-05-18 20:41:19 -070018using ::aos::util::ReadFileToVecOrDie;
19
Austin Schuhe84c3ed2019-12-14 15:29:48 -080020int Main() {
21 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuh99f7c6a2024-06-25 22:07:44 -070022 aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config));
Austin Schuhe84c3ed2019-12-14 15:29:48 -080023
24 aos::ShmEventLoop event_loop(&config.message());
Austin Schuh99f7c6a2024-06-25 22:07:44 -070025 if (absl::GetFlag(FLAGS_rt_priority) > 0) {
26 event_loop.SetRuntimeRealtimePriority(absl::GetFlag(FLAGS_rt_priority));
Austin Schuha922ad02021-10-23 23:25:50 -070027 }
Austin Schuhe84c3ed2019-12-14 15:29:48 -080028
Adam Snaiderdd847fd2023-06-26 16:34:15 -070029 MessageBridgeClient app(&event_loop, Sha256(config.span()),
Austin Schuh99f7c6a2024-06-25 22:07:44 -070030 absl::GetFlag(FLAGS_wants_sctp_authentication)
Adam Snaiderdd847fd2023-06-26 16:34:15 -070031 ? SctpAuthMethod::kAuth
32 : SctpAuthMethod::kNoAuth);
Austin Schuhe84c3ed2019-12-14 15:29:48 -080033
Sarah Newman45a64df2022-04-11 19:33:46 -070034 logging::DynamicLogging dynamic_logging(&event_loop);
Austin Schuhe84c3ed2019-12-14 15:29:48 -080035 // TODO(austin): Save messages into a vector to be logged. One file per
36 // channel? Need to sort out ordering.
37 //
38 // TODO(austin): Low priority, "reliable" logging channel.
39
40 event_loop.Run();
41
42 return EXIT_SUCCESS;
43}
44
Stephan Pleinesf63bde82024-01-13 15:59:33 -080045} // namespace aos::message_bridge
Austin Schuhe84c3ed2019-12-14 15:29:48 -080046
47int main(int argc, char **argv) {
48 aos::InitGoogle(&argc, &argv);
49
50 return aos::message_bridge::Main();
51}