blob: a12a8bfedede2e92ec6b24022e553ab36ac643b7 [file] [log] [blame]
Brian Silverman4acae812016-03-14 13:16:19 -04001#ifndef AOS_VISION_IMAGE_UDP_H_
2#define AOS_VISION_IMAGE_UDP_H_
3
4#include <arpa/inet.h>
5#include <sys/socket.h>
6#include <math.h>
7#include <unistd.h>
8#include <vector>
9
10#include "aos/common/macros.h"
11#include "aos/common/scoped_fd.h"
12
13namespace aos {
14namespace vision {
15
16// Simple wrapper around a transmitting UDP socket.
17//
18// LOG(FATAL)s for all errors, including from Send.
19class TXUdpSocket {
20 public:
21 TXUdpSocket(const char *ip_addr, int port);
22
23 // Returns the number of bytes actually sent.
24 int Send(const void *data, int size);
25
26 private:
27 ScopedFD fd_;
28
29 DISALLOW_COPY_AND_ASSIGN(TXUdpSocket);
30};
31
32// Simple wrapper around a receiving UDP socket.
33//
34// LOG(FATAL)s for all errors, including from Recv.
35class RXUdpSocket {
36 public:
37 RXUdpSocket(int port);
38
39 // Returns the number of bytes received.
40 int Recv(void *data, int size);
41
42 private:
43 ScopedFD fd_;
44
45 DISALLOW_COPY_AND_ASSIGN(RXUdpSocket);
46};
47
48} // namespace vision
49} // namespace aos
50
51#endif // AOS_VISION_IMAGE_UDP_H_