blob: ef727ebd43fe7e718b7843510efe0454a8748440 [file] [log] [blame]
Austin Schuhe84c3ed2019-12-14 15:29:48 -08001#include "aos/events/shm_event_loop.h"
2#include "aos/init.h"
Sarah Newman45a64df2022-04-11 19:33:46 -07003#include "aos/logging/dynamic_logging.h"
Austin Schuh60e77942022-05-16 17:48:24 -07004#include "aos/network/message_bridge_client_lib.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07005#include "aos/network/sctp_lib.h"
Austin Schuhb0e439d2023-05-15 10:55:40 -07006#include "aos/sha256.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07007#include "aos/util/file.h"
Austin Schuhe84c3ed2019-12-14 15:29:48 -08008
Austin Schuhc5fa6d92022-02-25 14:36:28 -08009DEFINE_string(config, "aos_config.json", "Path to the config.");
Austin Schuha922ad02021-10-23 23:25:50 -070010DEFINE_int32(rt_priority, -1, "If > 0, run as this RT priority");
Adam Snaiderdd847fd2023-06-26 16:34:15 -070011DEFINE_bool(
12 wants_sctp_authentication, false,
13 "When set, try to use SCTP authentication if provided by the kernel");
Austin Schuhe84c3ed2019-12-14 15:29:48 -080014
15namespace aos {
16namespace message_bridge {
17
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 =
22 aos::configuration::ReadConfig(FLAGS_config);
23
24 aos::ShmEventLoop event_loop(&config.message());
Austin Schuha922ad02021-10-23 23:25:50 -070025 if (FLAGS_rt_priority > 0) {
26 event_loop.SetRuntimeRealtimePriority(FLAGS_rt_priority);
27 }
Austin Schuhe84c3ed2019-12-14 15:29:48 -080028
Adam Snaiderdd847fd2023-06-26 16:34:15 -070029 MessageBridgeClient app(&event_loop, Sha256(config.span()),
30 FLAGS_wants_sctp_authentication
31 ? 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
45} // namespace message_bridge
46} // namespace aos
47
48int main(int argc, char **argv) {
49 aos::InitGoogle(&argc, &argv);
50
51 return aos::message_bridge::Main();
52}