This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathWiznetTCP.h
85 lines (73 loc) · 2.67 KB
/
WiznetTCP.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
77
78
79
80
81
82
83
84
85
#ifndef _WIZNET_TCP
#define _WIZNET_TCP
/*
TCP driver for Wiznet W5100 chip via SPI interface
This supports client and server connections. For server, the
listen method waits until a client connects to the socket.
The server thus can only process one connection at a time.
*/
// W5100 Socket status
#define SOCK_CLOSED 0
#define SOCK_INIT 19
#define SOCK_LISTEN 20
#define SOCK_SYNSENT 21
#define SOCK_SYNRECV 22
#define SOCK_ESTABLISHED 23
#define SOCK_FIN_WAIT 24
#define SOCK_CLOSING 26
#define SOCK_TIME_WAIT 27
#define SOCK_CLOSE_WAIT 28
#define SOCK_LAST_ACK 29
#define SOCK_UDP 34
#define SOCK_IPRAW 50
#define SOCK_MACRAW 66
#define SOCK_PPPOE 95
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
class WiznetTCP
{
private:
uint32_t gateway_ip;
uint16_t gateway_port;
void spi_init();
void get_data(uint16_t ptr, uint8_t *buffer, uint16_t length);
void put_data(uint16_t ptr, uint8_t *buffer, uint16_t length);
uint8_t run_DHCP_client(void);
uint8_t handle_mDNS_response(uint8_t *query);
uint16_t get_link(uint16_t offset);
uint16_t parse_name(uint16_t offset, uint8_t *buffer,
uint8_t *sn, uint8_t *matched);
void dump_buffer(uint8_t *buffer, uint16_t length);
public:
WiznetTCP();
~WiznetTCP();
void begin(uint16_t port);
void begin(uint8_t n0, uint8_t n1, uint8_t n2, uint8_t n3, uint16_t port);
bool listen();
void disconnect();
bool connect(uint8_t n0, uint8_t n1, uint8_t n2, uint8_t n3, uint16_t port);
void open();
void close();
void discover_gateway();
void print_mac_address();
uint8_t get_socket_status();
uint16_t send_available();
uint16_t send(char *buffer, uint16_t length);
uint16_t send_mac(char *buffer, uint16_t length);
uint16_t receive_available();
uint16_t receive_available(uint16_t ms);
uint16_t flush_receive();
uint16_t skip(uint16_t length);
uint16_t peek(uint16_t offset, char *buffer, uint16_t length);
uint16_t receive(char *buffer, uint16_t length);
uint16_t receive(char *buffer, uint16_t length, uint32_t *ip, uint16_t *port);
void set_ip(uint32_t ip);
void set_ip(uint8_t n0, uint8_t n1, uint8_t n2, uint8_t n3);
void get_ip(uint8_t *n0, uint8_t *n1, uint8_t *n2, uint8_t *n3);
void get_local_ip(uint8_t *n0, uint8_t *n1, uint8_t *n2, uint8_t *n3);
void set_port(uint16_t port);
uint16_t get_port();
uint16_t get_local_port();
};
#endif