STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
Ethernet.h
Go to the documentation of this file.
1
// Stub: Ethernet.h — for native tests
2
// Provides EthernetServer/Client/UDP stubs, plus enough of EthernetClass for
3
// board_net.h: DHCP can be made to succeed or fail, and every address write is
4
// recorded so a test can assert what the board pushed into the W5500.
5
#pragma once
6
#include <
Arduino.h
>
// IPAddress
7
8
#include <cstdint>
9
#include <cstring>
10
11
class
EthernetClient
{
12
public
:
13
operator
bool() {
14
return
false
;
15
}
16
int
available
() {
17
return
0;
18
}
19
int
read
() {
20
return
-1;
21
}
22
int
read
(uint8_t*,
int
) {
23
return
0;
24
}
25
void
stop
() {
26
}
27
void
flush
() {
28
}
29
void
println
(
const
char
*) {
30
}
31
};
32
33
class
EthernetServer
{
34
public
:
35
EthernetServer
(uint16_t) {
36
}
37
virtual
void
begin
() {
38
}
39
EthernetClient
available
() {
40
return
EthernetClient
();
41
}
42
};
43
44
// Records what board_net.h writes into the chip, so tests can inspect it.
45
class
EthernetClass
{
46
public
:
47
IPAddress
local_ip
;
48
IPAddress
subnet_mask
;
49
int
set_local_ip_calls
= 0;
50
int
set_subnet_calls
= 0;
51
52
// --- DHCP, scripted by the test ---
53
bool
dhcp_should_succeed
=
false
;
54
IPAddress
dhcp_assigned
;
55
int
maintain_calls
= 0;
56
// --- static configuration, recorded so a test can prove it did or did
57
// not happen ---
58
int
static_begin_calls
= 0;
59
IPAddress
static_ip
;
60
IPAddress
static_subnet
;
61
62
int
dhcp_begin_calls
= 0;
63
64
/** DHCP form: returns 1 on success, 0 on failure, like Ethernet 2.x —
65
* which zeroes the address before asking, so a failure leaves 0.0.0.0. */
66
int
begin
(uint8_t*,
unsigned
long
,
unsigned
long
) {
67
dhcp_begin_calls
++;
68
local_ip
=
IPAddress
(0, 0, 0, 0);
69
if
(!
dhcp_should_succeed
)
70
return
0;
71
local_ip
=
dhcp_assigned
;
72
return
1;
73
}
74
/** Static form. */
75
void
begin
(uint8_t*,
IPAddress
ip,
IPAddress
,
IPAddress
,
IPAddress
mask) {
76
static_begin_calls
++;
77
static_ip
= ip;
78
static_subnet
= mask;
79
local_ip
= ip;
80
subnet_mask
= mask;
81
}
82
83
void
setLocalIP
(
const
IPAddress
ip) {
84
local_ip
= ip;
85
set_local_ip_calls
++;
86
}
87
void
setSubnetMask
(
const
IPAddress
mask) {
88
subnet_mask
= mask;
89
set_subnet_calls
++;
90
}
91
IPAddress
localIP
()
const
{
92
return
local_ip
;
93
}
94
IPAddress
subnetMask
()
const
{
95
return
subnet_mask
;
96
}
97
int
maintain
() {
98
maintain_calls
++;
99
return
0;
100
}
101
void
reset
() {
102
local_ip
=
IPAddress
();
103
subnet_mask
=
IPAddress
();
104
set_local_ip_calls
= 0;
105
set_subnet_calls
= 0;
106
dhcp_should_succeed
=
false
;
107
dhcp_assigned
=
IPAddress
();
108
maintain_calls
= 0;
109
static_begin_calls
= 0;
110
static_ip
=
IPAddress
();
111
static_subnet
=
IPAddress
();
112
dhcp_begin_calls
= 0;
113
}
114
};
115
116
static
EthernetClass
Ethernet
;
Arduino.h
Ethernet
static EthernetClass Ethernet
Definition
Ethernet.h:116
IPAddress
const int IPAddress
Definition
actuator_nc.cpp:11
EthernetClass
Definition
Ethernet.h:45
EthernetClass::setSubnetMask
void setSubnetMask(const IPAddress mask)
Definition
Ethernet.h:87
EthernetClass::dhcp_assigned
IPAddress dhcp_assigned
Definition
Ethernet.h:54
EthernetClass::static_ip
IPAddress static_ip
Definition
Ethernet.h:59
EthernetClass::subnetMask
IPAddress subnetMask() const
Definition
Ethernet.h:94
EthernetClass::local_ip
IPAddress local_ip
Definition
Ethernet.h:47
EthernetClass::set_local_ip_calls
int set_local_ip_calls
Definition
Ethernet.h:49
EthernetClass::static_subnet
IPAddress static_subnet
Definition
Ethernet.h:60
EthernetClass::maintain
int maintain()
Definition
Ethernet.h:97
EthernetClass::localIP
IPAddress localIP() const
Definition
Ethernet.h:91
EthernetClass::set_subnet_calls
int set_subnet_calls
Definition
Ethernet.h:50
EthernetClass::subnet_mask
IPAddress subnet_mask
Definition
Ethernet.h:48
EthernetClass::dhcp_begin_calls
int dhcp_begin_calls
Definition
Ethernet.h:62
EthernetClass::maintain_calls
int maintain_calls
Definition
Ethernet.h:55
EthernetClass::reset
void reset()
Definition
Ethernet.h:101
EthernetClass::dhcp_should_succeed
bool dhcp_should_succeed
Definition
Ethernet.h:53
EthernetClass::begin
int begin(uint8_t *, unsigned long, unsigned long)
DHCP form: returns 1 on success, 0 on failure, like Ethernet 2.x — which zeroes the address before as...
Definition
Ethernet.h:66
EthernetClass::begin
void begin(uint8_t *, IPAddress ip, IPAddress, IPAddress, IPAddress mask)
Static form.
Definition
Ethernet.h:75
EthernetClass::setLocalIP
void setLocalIP(const IPAddress ip)
Definition
Ethernet.h:83
EthernetClass::static_begin_calls
int static_begin_calls
Definition
Ethernet.h:58
EthernetClient
Definition
Ethernet.h:11
EthernetClient::flush
void flush()
Definition
Ethernet.h:27
EthernetClient::read
int read(uint8_t *, int)
Definition
Ethernet.h:22
EthernetClient::stop
void stop()
Definition
Ethernet.h:25
EthernetClient::available
int available()
Definition
Ethernet.h:16
EthernetClient::println
void println(const char *)
Definition
Ethernet.h:29
EthernetClient::read
int read()
Definition
Ethernet.h:19
EthernetServer::available
EthernetClient available()
Definition
Ethernet.h:39
EthernetServer::EthernetServer
EthernetServer(uint16_t)
Definition
Ethernet.h:35
EthernetServer::begin
virtual void begin()
Definition
Ethernet.h:37
IPAddress
Definition
Arduino.h:63
firmware
Hotfire_Code
Hotfire_Tests
stubs
Ethernet.h
Generated by
1.15.0