M2X Ethernet demo using Seeed Ethernet W5200 Shield
Dependencies: LM75B M2XStreamClient jsonlite mbed-rtos mbed Nucleo_Sensor_Shield
Fork of m2x-seeed_ethernet_demo by
WIZnet_Library/WIZnetInterface/DHCPClient/DHCPClient.h@11:40d8cfc941ed, 2014-12-17 (annotated)
- Committer:
- dangriffin
- Date:
- Wed Dec 17 20:45:13 2014 +0000
- Revision:
- 11:40d8cfc941ed
- Parent:
- 7:a94ba2e0cd04
Use the public Nucleo Sensor Shield library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SeanNewton | 7:a94ba2e0cd04 | 1 | // DHCPClient.h 2013/4/10 |
SeanNewton | 7:a94ba2e0cd04 | 2 | #ifndef DHCPCLIENT_H |
SeanNewton | 7:a94ba2e0cd04 | 3 | #define DHCPCLIENT_H |
SeanNewton | 7:a94ba2e0cd04 | 4 | #include "wiznet.h" |
SeanNewton | 7:a94ba2e0cd04 | 5 | #include "UDPSocket.h" |
SeanNewton | 7:a94ba2e0cd04 | 6 | |
SeanNewton | 7:a94ba2e0cd04 | 7 | #define DHCP_OFFSET_OP 0 |
SeanNewton | 7:a94ba2e0cd04 | 8 | #define DHCP_OFFSET_XID 4 |
SeanNewton | 7:a94ba2e0cd04 | 9 | #define DHCP_OFFSET_YIADDR 16 |
SeanNewton | 7:a94ba2e0cd04 | 10 | #define DHCP_OFFSET_SIADDR 20 |
SeanNewton | 7:a94ba2e0cd04 | 11 | #define DHCP_OFFSET_OPTIONS 240 |
SeanNewton | 7:a94ba2e0cd04 | 12 | #define DHCP_MAX_PACKET_SIZE 600 |
SeanNewton | 7:a94ba2e0cd04 | 13 | |
SeanNewton | 7:a94ba2e0cd04 | 14 | // DHCP Message Type |
SeanNewton | 7:a94ba2e0cd04 | 15 | #define DHCPDISCOVER 1 |
SeanNewton | 7:a94ba2e0cd04 | 16 | #define DHCPOFFER 2 |
SeanNewton | 7:a94ba2e0cd04 | 17 | #define DHCPREQUEST 3 |
SeanNewton | 7:a94ba2e0cd04 | 18 | #define DHCPDECLINE 4 |
SeanNewton | 7:a94ba2e0cd04 | 19 | #define DHCPACK 5 |
SeanNewton | 7:a94ba2e0cd04 | 20 | #define DHCPNAK 6 |
SeanNewton | 7:a94ba2e0cd04 | 21 | #define DHCPRELEASE 7 |
SeanNewton | 7:a94ba2e0cd04 | 22 | #define DHCPINFORM 8 |
SeanNewton | 7:a94ba2e0cd04 | 23 | |
SeanNewton | 7:a94ba2e0cd04 | 24 | class DHCPClient { |
SeanNewton | 7:a94ba2e0cd04 | 25 | public: |
SeanNewton | 7:a94ba2e0cd04 | 26 | DHCPClient(); |
SeanNewton | 7:a94ba2e0cd04 | 27 | int setup(int timeout_ms = 15*1000); |
SeanNewton | 7:a94ba2e0cd04 | 28 | uint8_t chaddr[6]; // MAC |
SeanNewton | 7:a94ba2e0cd04 | 29 | uint8_t yiaddr[4]; // IP |
SeanNewton | 7:a94ba2e0cd04 | 30 | uint8_t dnsaddr[4]; // DNS |
SeanNewton | 7:a94ba2e0cd04 | 31 | uint8_t gateway[4]; |
SeanNewton | 7:a94ba2e0cd04 | 32 | uint8_t netmask[4]; |
SeanNewton | 7:a94ba2e0cd04 | 33 | uint8_t siaddr[4]; |
SeanNewton | 7:a94ba2e0cd04 | 34 | private: |
SeanNewton | 7:a94ba2e0cd04 | 35 | int discover(); |
SeanNewton | 7:a94ba2e0cd04 | 36 | int request(); |
SeanNewton | 7:a94ba2e0cd04 | 37 | int offer(uint8_t buf[], int size); |
SeanNewton | 7:a94ba2e0cd04 | 38 | void add_buf(uint8_t* buf, int len); |
SeanNewton | 7:a94ba2e0cd04 | 39 | void fill_buf(int len, uint8_t data = 0x00); |
SeanNewton | 7:a94ba2e0cd04 | 40 | void add_buf(uint8_t c); |
SeanNewton | 7:a94ba2e0cd04 | 41 | void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0); |
SeanNewton | 7:a94ba2e0cd04 | 42 | bool verify(uint8_t buf[], int len); |
SeanNewton | 7:a94ba2e0cd04 | 43 | void callback(); |
SeanNewton | 7:a94ba2e0cd04 | 44 | UDPSocket* m_udp; |
SeanNewton | 7:a94ba2e0cd04 | 45 | Endpoint m_server; |
SeanNewton | 7:a94ba2e0cd04 | 46 | uint8_t xid[4]; |
SeanNewton | 7:a94ba2e0cd04 | 47 | bool exit_flag; |
SeanNewton | 7:a94ba2e0cd04 | 48 | Timer m_interval; |
SeanNewton | 7:a94ba2e0cd04 | 49 | int m_retry; |
SeanNewton | 7:a94ba2e0cd04 | 50 | uint8_t m_buf[DHCP_MAX_PACKET_SIZE]; |
SeanNewton | 7:a94ba2e0cd04 | 51 | int m_pos; |
SeanNewton | 7:a94ba2e0cd04 | 52 | WIZnet_Chip* eth; |
SeanNewton | 7:a94ba2e0cd04 | 53 | }; |
SeanNewton | 7:a94ba2e0cd04 | 54 | #endif //DHCPCLIENT_H |
SeanNewton | 7:a94ba2e0cd04 | 55 |