Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1
marcozecchini 0:9fca2b23d0ba 2 /* WiFiInterface
marcozecchini 0:9fca2b23d0ba 3 * Copyright (c) 2015 - 2016 ARM Limited
marcozecchini 0:9fca2b23d0ba 4 *
marcozecchini 0:9fca2b23d0ba 5 * Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 6 * you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 7 * You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 8 *
marcozecchini 0:9fca2b23d0ba 9 * http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 10 *
marcozecchini 0:9fca2b23d0ba 11 * Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 12 * distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 14 * See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 15 * limitations under the License.
marcozecchini 0:9fca2b23d0ba 16 */
marcozecchini 0:9fca2b23d0ba 17
marcozecchini 0:9fca2b23d0ba 18 #ifndef WIFI_INTERFACE_H
marcozecchini 0:9fca2b23d0ba 19 #define WIFI_INTERFACE_H
marcozecchini 0:9fca2b23d0ba 20
marcozecchini 0:9fca2b23d0ba 21 #include <string.h>
marcozecchini 0:9fca2b23d0ba 22 #include "netsocket/NetworkInterface.h"
marcozecchini 0:9fca2b23d0ba 23 #include "netsocket/WiFiAccessPoint.h"
marcozecchini 0:9fca2b23d0ba 24
marcozecchini 0:9fca2b23d0ba 25 /** WiFiInterface class
marcozecchini 0:9fca2b23d0ba 26 *
marcozecchini 0:9fca2b23d0ba 27 * Common interface that is shared between WiFi devices
marcozecchini 0:9fca2b23d0ba 28 * @addtogroup netsocket
marcozecchini 0:9fca2b23d0ba 29 */
marcozecchini 0:9fca2b23d0ba 30 class WiFiInterface: public NetworkInterface
marcozecchini 0:9fca2b23d0ba 31 {
marcozecchini 0:9fca2b23d0ba 32 public:
marcozecchini 0:9fca2b23d0ba 33 /** WiFiInterface lifetime
marcozecchini 0:9fca2b23d0ba 34 */
marcozecchini 0:9fca2b23d0ba 35 virtual ~WiFiInterface() {};
marcozecchini 0:9fca2b23d0ba 36
marcozecchini 0:9fca2b23d0ba 37 /** Set the WiFi network credentials
marcozecchini 0:9fca2b23d0ba 38 *
marcozecchini 0:9fca2b23d0ba 39 * @param ssid Name of the network to connect to
marcozecchini 0:9fca2b23d0ba 40 * @param pass Security passphrase to connect to the network
marcozecchini 0:9fca2b23d0ba 41 * @param security Type of encryption for connection
marcozecchini 0:9fca2b23d0ba 42 * (defaults to NSAPI_SECURITY_NONE)
marcozecchini 0:9fca2b23d0ba 43 * @return 0 on success, or error code on failure
marcozecchini 0:9fca2b23d0ba 44 */
marcozecchini 0:9fca2b23d0ba 45 virtual nsapi_error_t set_credentials(const char *ssid, const char *pass,
marcozecchini 0:9fca2b23d0ba 46 nsapi_security_t security = NSAPI_SECURITY_NONE) = 0;
marcozecchini 0:9fca2b23d0ba 47
marcozecchini 0:9fca2b23d0ba 48 /** Set the WiFi network channel
marcozecchini 0:9fca2b23d0ba 49 *
marcozecchini 0:9fca2b23d0ba 50 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
marcozecchini 0:9fca2b23d0ba 51 * @return 0 on success, or error code on failure
marcozecchini 0:9fca2b23d0ba 52 */
marcozecchini 0:9fca2b23d0ba 53 virtual nsapi_error_t set_channel(uint8_t channel) = 0;
marcozecchini 0:9fca2b23d0ba 54
marcozecchini 0:9fca2b23d0ba 55 /** Gets the current radio signal strength for active connection
marcozecchini 0:9fca2b23d0ba 56 *
marcozecchini 0:9fca2b23d0ba 57 * @return Connection strength in dBm (negative value),
marcozecchini 0:9fca2b23d0ba 58 * or 0 if measurement impossible
marcozecchini 0:9fca2b23d0ba 59 */
marcozecchini 0:9fca2b23d0ba 60 virtual int8_t get_rssi() = 0;
marcozecchini 0:9fca2b23d0ba 61
marcozecchini 0:9fca2b23d0ba 62 /** Start the interface
marcozecchini 0:9fca2b23d0ba 63 *
marcozecchini 0:9fca2b23d0ba 64 * Attempts to connect to a WiFi network.
marcozecchini 0:9fca2b23d0ba 65 *
marcozecchini 0:9fca2b23d0ba 66 * @param ssid Name of the network to connect to
marcozecchini 0:9fca2b23d0ba 67 * @param pass Security passphrase to connect to the network
marcozecchini 0:9fca2b23d0ba 68 * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
marcozecchini 0:9fca2b23d0ba 69 * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
marcozecchini 0:9fca2b23d0ba 70 * @return 0 on success, or error code on failure
marcozecchini 0:9fca2b23d0ba 71 */
marcozecchini 0:9fca2b23d0ba 72 virtual nsapi_error_t connect(const char *ssid, const char *pass,
marcozecchini 0:9fca2b23d0ba 73 nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0) = 0;
marcozecchini 0:9fca2b23d0ba 74
marcozecchini 0:9fca2b23d0ba 75 /** Start the interface
marcozecchini 0:9fca2b23d0ba 76 *
marcozecchini 0:9fca2b23d0ba 77 * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
marcozecchini 0:9fca2b23d0ba 78 * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
marcozecchini 0:9fca2b23d0ba 79 *
marcozecchini 0:9fca2b23d0ba 80 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 81 */
marcozecchini 0:9fca2b23d0ba 82 virtual nsapi_error_t connect() = 0;
marcozecchini 0:9fca2b23d0ba 83
marcozecchini 0:9fca2b23d0ba 84 /** Stop the interface
marcozecchini 0:9fca2b23d0ba 85 *
marcozecchini 0:9fca2b23d0ba 86 * @return 0 on success, or error code on failure
marcozecchini 0:9fca2b23d0ba 87 */
marcozecchini 0:9fca2b23d0ba 88 virtual nsapi_error_t disconnect() = 0;
marcozecchini 0:9fca2b23d0ba 89
marcozecchini 0:9fca2b23d0ba 90 /** Scan for available networks
marcozecchini 0:9fca2b23d0ba 91 *
marcozecchini 0:9fca2b23d0ba 92 * This function will block. If the @a count is 0, function will only return count of available networks, so that
marcozecchini 0:9fca2b23d0ba 93 * user can allocated necessary memory. If the \p count is grater than 0 and the a \p res is not NULL it'll be populated
marcozecchini 0:9fca2b23d0ba 94 * with discovered networks up to value of \p count.
marcozecchini 0:9fca2b23d0ba 95 *
marcozecchini 0:9fca2b23d0ba 96 * @param res Pointer to allocated array to store discovered AP
marcozecchini 0:9fca2b23d0ba 97 * @param count Size of allocated @a res array, or 0 to only count available AP
marcozecchini 0:9fca2b23d0ba 98 * @return Number of entries in \p count, or if \p count was 0 number of available networks,
marcozecchini 0:9fca2b23d0ba 99 * negative on error see @a nsapi_error
marcozecchini 0:9fca2b23d0ba 100 */
marcozecchini 0:9fca2b23d0ba 101 virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, nsapi_size_t count) = 0;
marcozecchini 0:9fca2b23d0ba 102 };
marcozecchini 0:9fca2b23d0ba 103
marcozecchini 0:9fca2b23d0ba 104 #endif
marcozecchini 0:9fca2b23d0ba 105
marcozecchini 0:9fca2b23d0ba 106 /** @}*/