Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 1 | #include <netdb.h> |
| 2 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 3 | #include "aos/events/shm_event_loop.h" |
Austin Schuh | 300f2f6 | 2019-05-27 13:49:23 -0700 | [diff] [blame] | 4 | #include "aos/init.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 5 | #include "aos/logging/logging.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 6 | #include "aos/time/time.h" |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 7 | #include "aos/vision/events/udp.h" |
| 8 | #include "y2018/vision.pb.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 9 | #include "y2018/vision/vision_generated.h" |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 10 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 11 | namespace y2018::vision { |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 12 | |
| 13 | using aos::monotonic_clock; |
| 14 | |
| 15 | int Main() { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 16 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 17 | aos::configuration::ReadConfig("aos_config.json"); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 18 | |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 19 | ::aos::events::RXUdpSocket video_rx(5001); |
| 20 | char data[65507]; |
| 21 | ::y2018::VisionStatus status; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 22 | |
| 23 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 24 | ::aos::Sender<VisionStatus> vision_status_sender_ = |
| 25 | event_loop.MakeSender<VisionStatus>("/superstructure"); |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 26 | |
| 27 | while (true) { |
| 28 | const ssize_t rx_size = video_rx.Recv(data, sizeof(data)); |
| 29 | if (rx_size > 0) { |
| 30 | status.ParseFromArray(data, rx_size); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 31 | |
| 32 | auto builder = vision_status_sender_.MakeBuilder(); |
| 33 | VisionStatus::Builder vision_status_builder = |
| 34 | builder.MakeBuilder<VisionStatus>(); |
| 35 | vision_status_builder.add_high_frame_count(status.high_frame_count()); |
| 36 | vision_status_builder.add_low_frame_count(status.low_frame_count()); |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 37 | if (builder.Send(vision_status_builder.Finish()) != |
| 38 | aos::RawSender::Error::kOk) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 39 | AOS_LOG(ERROR, "Failed to send vision information\n"); |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 45 | } // namespace y2018::vision |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 46 | |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 47 | int main(int argc, char **argv) { |
| 48 | ::aos::InitGoogle(&argc, &argv); |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 49 | ::y2018::vision::Main(); |
| 50 | } |