Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1
switches 0:5c4d7b2438d3 2 /** \addtogroup netsocket */
switches 0:5c4d7b2438d3 3 /** @{*/
switches 0:5c4d7b2438d3 4 /* SocketAddress
switches 0:5c4d7b2438d3 5 * Copyright (c) 2015 ARM Limited
switches 0:5c4d7b2438d3 6 *
switches 0:5c4d7b2438d3 7 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 8 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 9 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 12 *
switches 0:5c4d7b2438d3 13 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 14 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 16 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 17 * limitations under the License.
switches 0:5c4d7b2438d3 18 */
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 #ifndef SOCKET_ADDRESS_H
switches 0:5c4d7b2438d3 21 #define SOCKET_ADDRESS_H
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 #include "nsapi_types.h"
switches 0:5c4d7b2438d3 24 #include "toolchain.h"
switches 0:5c4d7b2438d3 25
switches 0:5c4d7b2438d3 26 // Predeclared classes
switches 0:5c4d7b2438d3 27 class NetworkStack;
switches 0:5c4d7b2438d3 28 class NetworkInterface;
switches 0:5c4d7b2438d3 29
switches 0:5c4d7b2438d3 30
switches 0:5c4d7b2438d3 31 /** SocketAddress class
switches 0:5c4d7b2438d3 32 *
switches 0:5c4d7b2438d3 33 * Representation of an IP address and port pair.
switches 0:5c4d7b2438d3 34 */
switches 0:5c4d7b2438d3 35 class SocketAddress {
switches 0:5c4d7b2438d3 36 public:
switches 0:5c4d7b2438d3 37 /** Create a SocketAddress from a hostname and port
switches 0:5c4d7b2438d3 38 *
switches 0:5c4d7b2438d3 39 * The hostname may be either a domain name or an IP address. If the
switches 0:5c4d7b2438d3 40 * hostname is an IP address, no network transactions will be performed.
switches 0:5c4d7b2438d3 41 *
switches 0:5c4d7b2438d3 42 * On failure, the IP address and port will be set to zero
switches 0:5c4d7b2438d3 43 *
switches 0:5c4d7b2438d3 44 * @param stack Network stack to use for DNS resolution
switches 0:5c4d7b2438d3 45 * @param host Hostname to resolve
switches 0:5c4d7b2438d3 46 * @param port Optional 16-bit port
switches 0:5c4d7b2438d3 47 * @deprecated
switches 0:5c4d7b2438d3 48 * Constructors hide possible errors. Replaced by
switches 0:5c4d7b2438d3 49 * NetworkInterface::gethostbyname.
switches 0:5c4d7b2438d3 50 */
switches 0:5c4d7b2438d3 51 template <typename S>
switches 0:5c4d7b2438d3 52 MBED_DEPRECATED_SINCE("mbed-os-5.1.3",
switches 0:5c4d7b2438d3 53 "Constructors hide possible errors. Replaced by "
switches 0:5c4d7b2438d3 54 "NetworkInterface::gethostbyname.")
switches 0:5c4d7b2438d3 55 SocketAddress(S *stack, const char *host, uint16_t port = 0)
switches 0:5c4d7b2438d3 56 {
switches 0:5c4d7b2438d3 57 _SocketAddress(nsapi_create_stack(stack), host, port);
switches 0:5c4d7b2438d3 58 }
switches 0:5c4d7b2438d3 59
switches 0:5c4d7b2438d3 60 /** Create a SocketAddress from a raw IP address and port
switches 0:5c4d7b2438d3 61 *
switches 0:5c4d7b2438d3 62 * @param addr Raw IP address
switches 0:5c4d7b2438d3 63 * @param port Optional 16-bit port
switches 0:5c4d7b2438d3 64 */
switches 0:5c4d7b2438d3 65 SocketAddress(nsapi_addr_t addr = nsapi_addr_t(), uint16_t port = 0);
switches 0:5c4d7b2438d3 66
switches 0:5c4d7b2438d3 67 /** Create a SocketAddress from an IP address and port
switches 0:5c4d7b2438d3 68 *
switches 0:5c4d7b2438d3 69 * @param host Null-terminated representation of the IP address
switches 0:5c4d7b2438d3 70 * @param port Optional 16-bit port
switches 0:5c4d7b2438d3 71 */
switches 0:5c4d7b2438d3 72 SocketAddress(const char *addr, uint16_t port = 0);
switches 0:5c4d7b2438d3 73
switches 0:5c4d7b2438d3 74 /** Create a SocketAddress from raw IP bytes, IP version, and port
switches 0:5c4d7b2438d3 75 *
switches 0:5c4d7b2438d3 76 * @param bytes Raw IP address in big-endian order
switches 0:5c4d7b2438d3 77 * @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6
switches 0:5c4d7b2438d3 78 * @param port Optional 16-bit port
switches 0:5c4d7b2438d3 79 */
switches 0:5c4d7b2438d3 80 SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port = 0);
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 /** Create a SocketAddress from another SocketAddress
switches 0:5c4d7b2438d3 83 *
switches 0:5c4d7b2438d3 84 * @param address SocketAddress to copy
switches 0:5c4d7b2438d3 85 */
switches 0:5c4d7b2438d3 86 SocketAddress(const SocketAddress &addr);
switches 0:5c4d7b2438d3 87
switches 0:5c4d7b2438d3 88 /** Set the IP address
switches 0:5c4d7b2438d3 89 *
switches 0:5c4d7b2438d3 90 * @param addr Null-terminated represention of the IP address
switches 0:5c4d7b2438d3 91 * @return True if address is a valid representation of an IP address,
switches 0:5c4d7b2438d3 92 * otherwise False and SocketAddress is set to null
switches 0:5c4d7b2438d3 93 */
switches 0:5c4d7b2438d3 94 bool set_ip_address(const char *addr);
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96 /** Set the raw IP bytes and IP version
switches 0:5c4d7b2438d3 97 *
switches 0:5c4d7b2438d3 98 * @param bytes Raw IP address in big-endian order
switches 0:5c4d7b2438d3 99 * @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6
switches 0:5c4d7b2438d3 100 */
switches 0:5c4d7b2438d3 101 void set_ip_bytes(const void *bytes, nsapi_version_t version);
switches 0:5c4d7b2438d3 102
switches 0:5c4d7b2438d3 103 /** Set the raw IP address
switches 0:5c4d7b2438d3 104 *
switches 0:5c4d7b2438d3 105 * @param addr Raw IP address
switches 0:5c4d7b2438d3 106 */
switches 0:5c4d7b2438d3 107 void set_addr(nsapi_addr_t addr);
switches 0:5c4d7b2438d3 108
switches 0:5c4d7b2438d3 109 /** Set the port
switches 0:5c4d7b2438d3 110 *
switches 0:5c4d7b2438d3 111 * @param port 16-bit port
switches 0:5c4d7b2438d3 112 */
switches 0:5c4d7b2438d3 113 void set_port(uint16_t port);
switches 0:5c4d7b2438d3 114
switches 0:5c4d7b2438d3 115 /** Get the IP address
switches 0:5c4d7b2438d3 116 *
switches 0:5c4d7b2438d3 117 * @return Null-terminated representation of the IP Address
switches 0:5c4d7b2438d3 118 */
switches 0:5c4d7b2438d3 119 const char *get_ip_address() const;
switches 0:5c4d7b2438d3 120
switches 0:5c4d7b2438d3 121 /* Get the raw IP bytes
switches 0:5c4d7b2438d3 122 *
switches 0:5c4d7b2438d3 123 * @return Raw IP address in big-endian order
switches 0:5c4d7b2438d3 124 */
switches 0:5c4d7b2438d3 125 const void *get_ip_bytes() const;
switches 0:5c4d7b2438d3 126
switches 0:5c4d7b2438d3 127 /** Get the IP address version
switches 0:5c4d7b2438d3 128 *
switches 0:5c4d7b2438d3 129 * @return IP address version, NSAPI_IPv4 or NSAPI_IPv6
switches 0:5c4d7b2438d3 130 */
switches 0:5c4d7b2438d3 131 nsapi_version_t get_ip_version() const;
switches 0:5c4d7b2438d3 132
switches 0:5c4d7b2438d3 133 /** Get the raw IP address
switches 0:5c4d7b2438d3 134 *
switches 0:5c4d7b2438d3 135 * @return Raw IP address
switches 0:5c4d7b2438d3 136 */
switches 0:5c4d7b2438d3 137 nsapi_addr_t get_addr() const;
switches 0:5c4d7b2438d3 138
switches 0:5c4d7b2438d3 139 /** Get the port
switches 0:5c4d7b2438d3 140 *
switches 0:5c4d7b2438d3 141 * @return The 16-bit port
switches 0:5c4d7b2438d3 142 */
switches 0:5c4d7b2438d3 143 uint16_t get_port() const;
switches 0:5c4d7b2438d3 144
switches 0:5c4d7b2438d3 145 /** Test if address is zero
switches 0:5c4d7b2438d3 146 *
switches 0:5c4d7b2438d3 147 * @return True if address is not zero
switches 0:5c4d7b2438d3 148 */
switches 0:5c4d7b2438d3 149 operator bool() const;
switches 0:5c4d7b2438d3 150
switches 0:5c4d7b2438d3 151 /** Compare two addresses for equality
switches 0:5c4d7b2438d3 152 *
switches 0:5c4d7b2438d3 153 * @return True if both addresses are equal
switches 0:5c4d7b2438d3 154 */
switches 0:5c4d7b2438d3 155 friend bool operator==(const SocketAddress &a, const SocketAddress &b);
switches 0:5c4d7b2438d3 156
switches 0:5c4d7b2438d3 157 /** Compare two addresses for equality
switches 0:5c4d7b2438d3 158 *
switches 0:5c4d7b2438d3 159 * @return True if both addresses are not equal
switches 0:5c4d7b2438d3 160 */
switches 0:5c4d7b2438d3 161 friend bool operator!=(const SocketAddress &a, const SocketAddress &b);
switches 0:5c4d7b2438d3 162
switches 0:5c4d7b2438d3 163 private:
switches 0:5c4d7b2438d3 164 void _SocketAddress(NetworkStack *iface, const char *host, uint16_t port);
switches 0:5c4d7b2438d3 165
switches 0:5c4d7b2438d3 166 mutable char _ip_address[NSAPI_IP_SIZE];
switches 0:5c4d7b2438d3 167 nsapi_addr_t _addr;
switches 0:5c4d7b2438d3 168 uint16_t _port;
switches 0:5c4d7b2438d3 169 };
switches 0:5c4d7b2438d3 170
switches 0:5c4d7b2438d3 171
switches 0:5c4d7b2438d3 172 #endif
switches 0:5c4d7b2438d3 173
switches 0:5c4d7b2438d3 174 /** @}*/