forked from arduino-libraries/Arduino_ConnectionHandler
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEthernetConnectionHandler.h
More file actions
83 lines (64 loc) · 2.61 KB
/
EthernetConnectionHandler.h
File metadata and controls
83 lines (64 loc) · 2.61 KB
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
77
78
79
80
81
82
83
/*
This file is part of the Arduino_ConnectionHandler library.
Copyright (c) 2020 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef ARDUINO_ETHERNET_CONNECTION_HANDLER_H_
#define ARDUINO_ETHERNET_CONNECTION_HANDLER_H_
/******************************************************************************
INCLUDE
******************************************************************************/
#include "ConnectionHandlerInterface.h"
#if defined(ARDUINO_ARCH_ZEPHYR)
#include <Ethernet.h>
#include <EthernetUdp.h>
#elif defined(ARDUINO_PORTENTA_H7_M7)
#include <Ethernet.h>
#include <PortentaEthernet.h>
#elif defined(ARDUINO_PORTENTA_C33)
#include <EthernetC33.h>
#include <EthernetUdp.h>
#elif defined(ARDUINO_OPTA)
#include <Ethernet.h>
#include <PortentaEthernet.h>
#endif
#ifndef BOARD_HAS_ETHERNET
#error "Board doesn't support ETHERNET"
#endif
/******************************************************************************
CLASS DECLARATION
******************************************************************************/
class EthernetConnectionHandler : public ConnectionHandler
{
public:
EthernetConnectionHandler(
unsigned long const timeout = 15000,
unsigned long const responseTimeout = 4000,
bool const keep_alive = true);
EthernetConnectionHandler(
const IPAddress ip,
const IPAddress dns,
const IPAddress gateway,
const IPAddress netmask,
unsigned long const timeout = 15000,
unsigned long const responseTimeout = 4000,
bool const keep_alive = true);
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
virtual unsigned long getTime() override { return 0; }
virtual Client & getClient() override{ return _eth_client; }
virtual UDP & getUDP() override { return _eth_udp; }
protected:
virtual NetworkConnectionState update_handleInit () override;
virtual NetworkConnectionState update_handleConnecting () override;
virtual NetworkConnectionState update_handleConnected () override;
virtual NetworkConnectionState update_handleDisconnecting() override;
virtual NetworkConnectionState update_handleDisconnected () override;
private:
EthernetUDP _eth_udp;
EthernetClient _eth_client;
};
#endif /* ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ */