Austin Schuh | 6b9c415 | 2019-11-29 12:45:24 -0800 | [diff] [blame^] | 1 | #ifndef AOS_EVENTS_PING_LIB_H_ |
| 2 | #define AOS_EVENTS_PING_LIB_H_ |
| 3 | |
| 4 | #include <chrono> |
| 5 | |
| 6 | #include "aos/events/event_loop.h" |
| 7 | #include "aos/events/pong_generated.h" |
| 8 | #include "aos/events/ping_generated.h" |
| 9 | |
| 10 | namespace aos { |
| 11 | |
| 12 | // Class which sends out a Ping message every X ms, and times the response. |
| 13 | class Ping { |
| 14 | public: |
| 15 | Ping(EventLoop *event_loop); |
| 16 | |
| 17 | private: |
| 18 | // Sends out the ping message with an incrementing count. |
| 19 | void SendPing(); |
| 20 | |
| 21 | // Receives the reply and measures the latency. |
| 22 | void HandlePong(const examples::Pong &pong); |
| 23 | |
| 24 | aos::EventLoop *event_loop_; |
| 25 | aos::Sender<examples::Ping> sender_; |
| 26 | // Timer handle which sends the Ping message. |
| 27 | aos::TimerHandler *timer_handle_; |
| 28 | // Number of pings sent. |
| 29 | int count_ = 0; |
| 30 | }; |
| 31 | |
| 32 | } // namespace aos |
| 33 | |
| 34 | #endif // AOS_EVENTS_PING_LIB_H_ |