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