wifly/socket interface for wifly modules

Dependents:   WiFi neurGAI_WIFI thingspeak thingspeak2

Committer:
samux
Date:
Fri Aug 24 13:25:55 2012 +0000
Revision:
13:108340829acc
Parent:
11:b912f91e3212
reduce buffer size

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 3:10b3866f0ea2 1 /* Copyright (C) 2012 mbed.org, MIT License
samux 3:10b3866f0ea2 2 *
samux 3:10b3866f0ea2 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 3:10b3866f0ea2 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
samux 3:10b3866f0ea2 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
samux 3:10b3866f0ea2 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
samux 3:10b3866f0ea2 7 * furnished to do so, subject to the following conditions:
samux 3:10b3866f0ea2 8 *
samux 3:10b3866f0ea2 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 3:10b3866f0ea2 10 * substantial portions of the Software.
samux 3:10b3866f0ea2 11 *
samux 3:10b3866f0ea2 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 3:10b3866f0ea2 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 3:10b3866f0ea2 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 3:10b3866f0ea2 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 3:10b3866f0ea2 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 3:10b3866f0ea2 17 */
samux 3:10b3866f0ea2 18 #include "Socket/Socket.h"
samux 3:10b3866f0ea2 19 #include "Socket/Endpoint.h"
samux 3:10b3866f0ea2 20 #include <cstring>
samux 3:10b3866f0ea2 21
samux 3:10b3866f0ea2 22 using std::memset;
samux 3:10b3866f0ea2 23
samux 3:10b3866f0ea2 24 Endpoint::Endpoint() {
samux 3:10b3866f0ea2 25 wifly = Wifly::getInstance();
samux 10:81445de1fe27 26 if (wifly == NULL)
samux 11:b912f91e3212 27 error("Endpoint constructor error: no wifly instance available!\r\n");
samux 3:10b3866f0ea2 28 reset_address();
samux 3:10b3866f0ea2 29 }
samux 3:10b3866f0ea2 30 Endpoint::~Endpoint() {}
samux 3:10b3866f0ea2 31
samux 3:10b3866f0ea2 32 void Endpoint::reset_address(void) {
samux 3:10b3866f0ea2 33 _ipAddress[0] = '\0';
samux 3:10b3866f0ea2 34 _port = 0;
samux 3:10b3866f0ea2 35 }
samux 3:10b3866f0ea2 36
samux 3:10b3866f0ea2 37 int Endpoint::set_address(const char* host, const int port) {
samux 3:10b3866f0ea2 38 //Resolve DNS address or populate hard-coded IP address
samux 11:b912f91e3212 39 wifly->gethostbyname(host, _ipAddress);
samux 3:10b3866f0ea2 40 _port = port;
samux 3:10b3866f0ea2 41 return 0;
samux 3:10b3866f0ea2 42 }
samux 3:10b3866f0ea2 43
samux 3:10b3866f0ea2 44 char* Endpoint::get_address() {
samux 3:10b3866f0ea2 45 return _ipAddress;
samux 3:10b3866f0ea2 46 }
samux 3:10b3866f0ea2 47
samux 3:10b3866f0ea2 48 int Endpoint::get_port() {
samux 3:10b3866f0ea2 49 return _port;
samux 3:10b3866f0ea2 50 }