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 | |
| 11 | namespace y2018 { |
| 12 | namespace vision { |
| 13 | |
| 14 | using aos::monotonic_clock; |
| 15 | |
| 16 | int Main() { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 17 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 18 | aos::configuration::ReadConfig("config.json"); |
| 19 | |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 20 | ::aos::events::RXUdpSocket video_rx(5001); |
| 21 | char data[65507]; |
| 22 | ::y2018::VisionStatus status; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 23 | |
| 24 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 25 | ::aos::Sender<VisionStatus> vision_status_sender_ = |
| 26 | event_loop.MakeSender<VisionStatus>("/superstructure"); |
Austin Schuh | 8d5fff4 | 2018-05-30 20:44:12 -0700 | [diff] [blame] | 27 | |
| 28 | while (true) { |
| 29 | const ssize_t rx_size = video_rx.Recv(data, sizeof(data)); |
| 30 | if (rx_size > 0) { |
| 31 | status.ParseFromArray(data, rx_size); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 32 | |
| 33 | auto builder = vision_status_sender_.MakeBuilder(); |
| 34 | VisionStatus::Builder vision_status_builder = |
| 35 | builder.MakeBuilder<VisionStatus>(); |
| 36 | vision_status_builder.add_high_frame_count(status.high_frame_count()); |
| 37 | vision_status_builder.add_low_frame_count(status.low_frame_count()); |
| 38 | if (!builder.Send(vision_status_builder.Finish())) { |
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 | |
| 45 | } // namespace vision |
| 46 | } // namespace y2018 |
| 47 | |
| 48 | int main(int /*argc*/, char ** /*argv*/) { |
| 49 | ::aos::InitNRT(); |
| 50 | ::y2018::vision::Main(); |
| 51 | } |