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/WIZnetInterface.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 | /* Copyright (C) 2012 mbed.org, MIT License |
SeanNewton | 7:a94ba2e0cd04 | 2 | * |
SeanNewton | 7:a94ba2e0cd04 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
SeanNewton | 7:a94ba2e0cd04 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
SeanNewton | 7:a94ba2e0cd04 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
SeanNewton | 7:a94ba2e0cd04 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
SeanNewton | 7:a94ba2e0cd04 | 7 | * furnished to do so, subject to the following conditions: |
SeanNewton | 7:a94ba2e0cd04 | 8 | * |
SeanNewton | 7:a94ba2e0cd04 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
SeanNewton | 7:a94ba2e0cd04 | 10 | * substantial portions of the Software. |
SeanNewton | 7:a94ba2e0cd04 | 11 | * |
SeanNewton | 7:a94ba2e0cd04 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
SeanNewton | 7:a94ba2e0cd04 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
SeanNewton | 7:a94ba2e0cd04 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
SeanNewton | 7:a94ba2e0cd04 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SeanNewton | 7:a94ba2e0cd04 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
SeanNewton | 7:a94ba2e0cd04 | 17 | */ |
SeanNewton | 7:a94ba2e0cd04 | 18 | |
SeanNewton | 7:a94ba2e0cd04 | 19 | #pragma once |
SeanNewton | 7:a94ba2e0cd04 | 20 | #include "wiznet.h" |
SeanNewton | 7:a94ba2e0cd04 | 21 | |
SeanNewton | 7:a94ba2e0cd04 | 22 | /** Interface using Wiznet chip to connect to an IP-based network |
SeanNewton | 7:a94ba2e0cd04 | 23 | * |
SeanNewton | 7:a94ba2e0cd04 | 24 | */ |
SeanNewton | 7:a94ba2e0cd04 | 25 | class WIZnetInterface: public WIZnet_Chip { |
SeanNewton | 7:a94ba2e0cd04 | 26 | public: |
SeanNewton | 7:a94ba2e0cd04 | 27 | |
SeanNewton | 7:a94ba2e0cd04 | 28 | /** |
SeanNewton | 7:a94ba2e0cd04 | 29 | * Constructor |
SeanNewton | 7:a94ba2e0cd04 | 30 | * |
SeanNewton | 7:a94ba2e0cd04 | 31 | * \param mosi mbed pin to use for SPI |
SeanNewton | 7:a94ba2e0cd04 | 32 | * \param miso mbed pin to use for SPI |
SeanNewton | 7:a94ba2e0cd04 | 33 | * \param sclk mbed pin to use for SPI |
SeanNewton | 7:a94ba2e0cd04 | 34 | * \param cs chip select of the WIZnet_Chip |
SeanNewton | 7:a94ba2e0cd04 | 35 | * \param reset reset pin of the WIZnet_Chip |
SeanNewton | 7:a94ba2e0cd04 | 36 | */ |
SeanNewton | 7:a94ba2e0cd04 | 37 | WIZnetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); |
SeanNewton | 7:a94ba2e0cd04 | 38 | WIZnetInterface(SPI* spi, PinName cs, PinName reset); |
SeanNewton | 7:a94ba2e0cd04 | 39 | |
SeanNewton | 7:a94ba2e0cd04 | 40 | /** Initialize the interface with DHCP. |
SeanNewton | 7:a94ba2e0cd04 | 41 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
SeanNewton | 7:a94ba2e0cd04 | 42 | * \return 0 on success, a negative number on failure |
SeanNewton | 7:a94ba2e0cd04 | 43 | */ |
SeanNewton | 7:a94ba2e0cd04 | 44 | int init(uint8_t * mac); //With DHCP |
SeanNewton | 7:a94ba2e0cd04 | 45 | |
SeanNewton | 7:a94ba2e0cd04 | 46 | /** Initialize the interface with a static IP address. |
SeanNewton | 7:a94ba2e0cd04 | 47 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
SeanNewton | 7:a94ba2e0cd04 | 48 | * \param ip the IP address to use |
SeanNewton | 7:a94ba2e0cd04 | 49 | * \param mask the IP address mask |
SeanNewton | 7:a94ba2e0cd04 | 50 | * \param gateway the gateway to use |
SeanNewton | 7:a94ba2e0cd04 | 51 | * \return 0 on success, a negative number on failure |
SeanNewton | 7:a94ba2e0cd04 | 52 | */ |
SeanNewton | 7:a94ba2e0cd04 | 53 | int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway); |
SeanNewton | 7:a94ba2e0cd04 | 54 | |
SeanNewton | 7:a94ba2e0cd04 | 55 | /** Connect |
SeanNewton | 7:a94ba2e0cd04 | 56 | * Bring the interface up, start DHCP if needed. |
SeanNewton | 7:a94ba2e0cd04 | 57 | * \return 0 on success, a negative number on failure |
SeanNewton | 7:a94ba2e0cd04 | 58 | */ |
SeanNewton | 7:a94ba2e0cd04 | 59 | int connect(); |
SeanNewton | 7:a94ba2e0cd04 | 60 | |
SeanNewton | 7:a94ba2e0cd04 | 61 | /** Disconnect |
SeanNewton | 7:a94ba2e0cd04 | 62 | * Bring the interface down |
SeanNewton | 7:a94ba2e0cd04 | 63 | * \return 0 on success, a negative number on failure |
SeanNewton | 7:a94ba2e0cd04 | 64 | */ |
SeanNewton | 7:a94ba2e0cd04 | 65 | int disconnect(); |
SeanNewton | 7:a94ba2e0cd04 | 66 | |
SeanNewton | 7:a94ba2e0cd04 | 67 | /** Get IP address & MAC address |
SeanNewton | 7:a94ba2e0cd04 | 68 | * |
SeanNewton | 7:a94ba2e0cd04 | 69 | * @ returns ip address |
SeanNewton | 7:a94ba2e0cd04 | 70 | */ |
SeanNewton | 7:a94ba2e0cd04 | 71 | char* getIPAddress(); |
SeanNewton | 7:a94ba2e0cd04 | 72 | char* getNetworkMask(); |
SeanNewton | 7:a94ba2e0cd04 | 73 | char* getGateway(); |
SeanNewton | 7:a94ba2e0cd04 | 74 | char* getMACAddress(); |
SeanNewton | 7:a94ba2e0cd04 | 75 | |
SeanNewton | 7:a94ba2e0cd04 | 76 | int IPrenew(int timeout_ms = 15*1000); |
SeanNewton | 7:a94ba2e0cd04 | 77 | |
SeanNewton | 7:a94ba2e0cd04 | 78 | private: |
SeanNewton | 7:a94ba2e0cd04 | 79 | char ip_string[20]; |
SeanNewton | 7:a94ba2e0cd04 | 80 | char mask_string[20]; |
SeanNewton | 7:a94ba2e0cd04 | 81 | char gw_string[20]; |
SeanNewton | 7:a94ba2e0cd04 | 82 | char mac_string[20]; |
SeanNewton | 7:a94ba2e0cd04 | 83 | bool ip_set; |
SeanNewton | 7:a94ba2e0cd04 | 84 | }; |
SeanNewton | 7:a94ba2e0cd04 | 85 | |
SeanNewton | 7:a94ba2e0cd04 | 86 | #include "TCPSocketConnection.h" |
SeanNewton | 7:a94ba2e0cd04 | 87 | #include "TCPSocketServer.h" |
SeanNewton | 7:a94ba2e0cd04 | 88 | #include "UDPSocket.h" |