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/Socket/Endpoint.cpp@7:a94ba2e0cd04, 2014-09-25 (annotated)
- Committer:
- SeanNewton
- Date:
- Thu Sep 25 16:36:51 2014 +0000
- Revision:
- 7:a94ba2e0cd04
CHange WIZnet_Library to folder to keep configuration changes
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 | #include "Socket.h" |
SeanNewton | 7:a94ba2e0cd04 | 19 | #include "Endpoint.h" |
SeanNewton | 7:a94ba2e0cd04 | 20 | |
SeanNewton | 7:a94ba2e0cd04 | 21 | Endpoint::Endpoint() { |
SeanNewton | 7:a94ba2e0cd04 | 22 | reset_address(); |
SeanNewton | 7:a94ba2e0cd04 | 23 | } |
SeanNewton | 7:a94ba2e0cd04 | 24 | Endpoint::~Endpoint() {} |
SeanNewton | 7:a94ba2e0cd04 | 25 | |
SeanNewton | 7:a94ba2e0cd04 | 26 | void Endpoint::reset_address(void) { |
SeanNewton | 7:a94ba2e0cd04 | 27 | _ipAddress[0] = '\0'; |
SeanNewton | 7:a94ba2e0cd04 | 28 | _port = 0; |
SeanNewton | 7:a94ba2e0cd04 | 29 | } |
SeanNewton | 7:a94ba2e0cd04 | 30 | |
SeanNewton | 7:a94ba2e0cd04 | 31 | int Endpoint::set_address(const char* host, const int port) { |
SeanNewton | 7:a94ba2e0cd04 | 32 | //Resolve DNS address or populate hard-coded IP address |
SeanNewton | 7:a94ba2e0cd04 | 33 | WIZnet_Chip* eth = WIZnet_Chip::getInstance(); |
SeanNewton | 7:a94ba2e0cd04 | 34 | if (eth == NULL) { |
SeanNewton | 7:a94ba2e0cd04 | 35 | return -1; |
SeanNewton | 7:a94ba2e0cd04 | 36 | } |
SeanNewton | 7:a94ba2e0cd04 | 37 | uint32_t addr; |
SeanNewton | 7:a94ba2e0cd04 | 38 | if (!eth->gethostbyname(host, &addr)) { |
SeanNewton | 7:a94ba2e0cd04 | 39 | return -1; |
SeanNewton | 7:a94ba2e0cd04 | 40 | } |
SeanNewton | 7:a94ba2e0cd04 | 41 | snprintf(_ipAddress, sizeof(_ipAddress), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff); |
SeanNewton | 7:a94ba2e0cd04 | 42 | _port = port; |
SeanNewton | 7:a94ba2e0cd04 | 43 | return 0; |
SeanNewton | 7:a94ba2e0cd04 | 44 | } |
SeanNewton | 7:a94ba2e0cd04 | 45 | |
SeanNewton | 7:a94ba2e0cd04 | 46 | char* Endpoint::get_address() { |
SeanNewton | 7:a94ba2e0cd04 | 47 | return _ipAddress; |
SeanNewton | 7:a94ba2e0cd04 | 48 | } |
SeanNewton | 7:a94ba2e0cd04 | 49 | |
SeanNewton | 7:a94ba2e0cd04 | 50 | int Endpoint::get_port() { |
SeanNewton | 7:a94ba2e0cd04 | 51 | return _port; |
SeanNewton | 7:a94ba2e0cd04 | 52 | } |
SeanNewton | 7:a94ba2e0cd04 | 53 |