forked from OpenSprinkler/OpenSprinkler-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 6
/
etherport.h
76 lines (66 loc) · 1.77 KB
/
etherport.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* OpenSprinkler Unified (AVR/RPI/BBB/LINUX) Firmware
* Copyright (C) 2015 by Ray Wang (ray@opensprinkler.com)
*
* Linux Ethernet functions header file
* This file is based on Richard Zimmerman's sprinklers_pi program
* Copyright (c) 2013 Richard Zimmerman
*
* This file is part of the OpenSprinkler library
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef _ETHERPORT_H_
#define _ETHERPORT_H_
#if defined(ARDUINO)
#else // headers for RPI/BBB
#include <stdio.h>
#include <inttypes.h>
#include <ctype.h>
#ifdef __APPLE__
#define MSG_NOSIGNAL SO_NOSIGPIPE
#endif
class EthernetServer;
class EthernetClient {
public:
EthernetClient();
EthernetClient(int sock);
~EthernetClient();
int connect(uint8_t ip[4], uint16_t port);
bool connected();
void stop();
int read(uint8_t *buf, size_t size);
size_t write(const uint8_t *buf, size_t size);
operator bool();
int GetSocket()
{
return m_sock;
}
private:
int m_sock;
bool m_connected;
friend class EthernetServer;
};
class EthernetServer {
public:
EthernetServer(uint16_t port);
~EthernetServer();
bool begin();
EthernetClient available();
private:
uint16_t m_port;
int m_sock;
};
#endif
#endif /* _ETHERPORT_H_ */