25
25
CTOR/DTOR
26
26
******************************************************************************/
27
27
28
- // FIXME
29
- EthernetConnectionHandler::EthernetConnectionHandler (unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
30
- : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
31
- // ,_ip{INADDR_NONE}
32
- // ,_dns{INADDR_NONE}
33
- // ,_gateway{INADDR_NONE}
34
- // ,_netmask{INADDR_NONE}
35
- // ,_timeout{timeout}
36
- // ,_response_timeout{responseTimeout}
37
- {
38
-
28
+ static inline void fromIPAddress (const IPAddress src, models::ip_addr& dst) {
29
+ if (src.type () == IPv4) {
30
+ dst.dword [IPADDRESS_V4_DWORD_INDEX] = (uint32_t )src;
31
+ } else if (src.type () == IPv6) {
32
+ for (uint8_t i=0 ; i<sizeof (dst.bytes ); i++) {
33
+ dst.bytes [i] = src[i];
34
+ }
35
+ }
39
36
}
40
37
41
- EthernetConnectionHandler::EthernetConnectionHandler (const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
38
+ // FIXME
39
+ EthernetConnectionHandler::EthernetConnectionHandler (
40
+ unsigned long const timeout,
41
+ unsigned long const responseTimeout,
42
+ bool const keep_alive)
42
43
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
43
- // ,_ip{ip}
44
- // ,_dns{dns}
45
- // ,_gateway{gateway}
46
- // ,_netmask{netmask}
47
- // ,_timeout{timeout}
48
- // ,_response_timeout{responseTimeout}
49
44
{
50
-
45
+ memset (_settings.eth .ip .dword , 0 , sizeof (_settings.eth .ip .dword ));
46
+ memset (_settings.eth .dns .dword , 0 , sizeof (_settings.eth .dns .dword ));
47
+ memset (_settings.eth .gateway .dword , 0 , sizeof (_settings.eth .gateway .dword ));
48
+ memset (_settings.eth .netmask .dword , 0 , sizeof (_settings.eth .netmask .dword ));
49
+ _settings.eth .timeout = timeout;
50
+ _settings.eth .response_timeout = responseTimeout;
51
51
}
52
52
53
- EthernetConnectionHandler::EthernetConnectionHandler (const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
53
+ EthernetConnectionHandler::EthernetConnectionHandler (
54
+ const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask,
55
+ unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
54
56
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
55
- // ,_ip{INADDR_NONE}
56
- // ,_dns{INADDR_NONE}
57
- // ,_gateway{INADDR_NONE}
58
- // ,_netmask{INADDR_NONE}
59
- // ,_timeout{timeout}
60
- // ,_response_timeout{responseTimeout}
61
57
{
62
- // if(!_ip.fromString(ip)) {
63
- // _ip = INADDR_NONE;
64
- // }
65
- // if(!_dns.fromString(dns)) {
66
- // _dns = INADDR_NONE;
67
- // }
68
- // if(!_gateway.fromString(gateway)) {
69
- // _gateway = INADDR_NONE;
70
- // }
71
- // if(!_netmask.fromString(netmask)) {
72
- // _netmask = INADDR_NONE;
73
- // }
58
+ fromIPAddress (ip, _settings.eth .ip );
59
+ fromIPAddress (dns, _settings.eth .dns );
60
+ fromIPAddress (gateway, _settings.eth .gateway );
61
+ fromIPAddress (netmask, _settings.eth .netmask );
62
+ _settings.eth .timeout = timeout;
63
+ _settings.eth .response_timeout = responseTimeout;
74
64
}
75
65
76
66
/* *****************************************************************************
@@ -88,12 +78,12 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
88
78
89
79
NetworkConnectionState EthernetConnectionHandler::update_handleConnecting ()
90
80
{
91
- if (_settings.eth .ip ! = INADDR_NONE) {
81
+ if (IPAddress ( _settings.eth .ip . type , _settings. eth . ip . bytes ) = = INADDR_NONE) {
92
82
if (Ethernet.begin (nullptr ,
93
- _settings.eth .ip ,
94
- _settings.eth .dns ,
95
- _settings.eth .gateway ,
96
- _settings.eth .netmask ,
83
+ IPAddress ( _settings.eth .ip . type , _settings. eth . ip . bytes ) ,
84
+ IPAddress ( _settings.eth .dns . type , _settings. eth . dns . bytes ) ,
85
+ IPAddress ( _settings.eth .gateway . type , _settings. eth . gateway . bytes ) ,
86
+ IPAddress ( _settings.eth .netmask . type , _settings. eth . netmask . bytes ) ,
97
87
_settings.eth .timeout ,
98
88
_settings.eth .response_timeout ) == 0 ) {
99
89
Debug.print (DBG_ERROR, F (" Failed to configure Ethernet, check cable connection" ));
0 commit comments