blob: e14c3f2a78b6cd51131ad76c0c4b9e06a42a64f6 [file] [log] [blame]
Austin Schuh6b9c4152019-11-29 12:45:24 -08001#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
10namespace aos {
11
12// Class which sends out a Ping message every X ms, and times the response.
13class 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_;
Austin Schuh6b9c4152019-11-29 12:45:24 -080028 // Number of pings sent.
29 int count_ = 0;
Austin Schuh5d89cf52019-12-28 16:27:42 -080030 // Last pong value received so we can detect missed pongs.
31 int last_pong_value_ = 0;
Austin Schuh6b9c4152019-11-29 12:45:24 -080032};
33
34} // namespace aos
35
36#endif // AOS_EVENTS_PING_LIB_H_