Updates and additions required by mbed-os 5.2.2
Dependents: x-nucleo-iks01a1-test x-nucleo-iks01a1-test
Fork of X_NUCLEO_IDW01M1v2 by
Revision 13:3d28a8c18182, committed 2016-11-20
- Comitter:
- lapi
- Date:
- Sun Nov 20 20:31:30 2016 +0000
- Parent:
- 12:1f2aba8a1b00
- Child:
- 14:aadc322f10db
- Commit message:
- Changes required by the current version of the mbed-os: some missing virtual functions added and prototypes corrected.
Changed in this revision
--- a/SPWF01SA.lib Thu Nov 03 06:57:03 2016 +0000 +++ b/SPWF01SA.lib Sun Nov 20 20:31:30 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/SPWF01SA/#0b01aa59bb6f +https://developer.mbed.org/teams/ST/code/SPWF01SA/#b9f7b00b2635
--- a/SpwfInterface.cpp Thu Nov 03 06:57:03 2016 +0000
+++ b/SpwfInterface.cpp Sun Nov 20 20:31:30 2016 +0000
@@ -34,6 +34,7 @@
*/
#include "SpwfInterface.h"
+#include <string.h>
// Various timeouts for different SPWF operations
#define SPWF_CONNECT_TIMEOUT 20000
@@ -63,7 +64,7 @@
* @retval none
*/
SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, bool debug)
- : _spwf(tx, rx, debug)
+ : _spwf(tx, rx, debug), _ssid(0), _pass(0), _channel(0)
{
memset(_ids, 0, sizeof(_ids));
isInitialized = false;
@@ -80,6 +81,16 @@
}
/**
+* @brief Get the RSSI of the last packet
+* @param none
+* @retval RSSI of the last packet (dBm)
+*/
+int8_t SpwfSAInterface::get_rssi()
+{
+ return _spwf.getRSSI();
+}
+
+/**
* @brief init function
initializes SPWF FW and module
* @param none
@@ -90,29 +101,40 @@
_spwf.setTimeout(SPWF_MISC_TIMEOUT);
if(_spwf.startup(0)) {
isInitialized=true;
- return true;
+ return NSAPI_ERROR_OK;
}
else return NSAPI_ERROR_DEVICE_ERROR;
}
+nsapi_error_t SpwfSAInterface::set_credentials(
+ const char *ssid, const char *pass, nsapi_security_t security) {
+ _ssid = ssid; // TODO! Copy of the string preferred!
+ _pass = pass;
+ _security = security;
+ return NSAPI_ERROR_OK;
+
+}
+
/**
* @brief network connect
connects to Access Point
* @param ap: Access Point (AP) Name String
* pass_phrase: Password String for AP
* security: type of NSAPI security supported
+* channel: the WiFi channel number
* @retval NSAPI Error Type
*/
-int SpwfSAInterface::connect(const char *ap,
+nsapi_error_t SpwfSAInterface::connect(const char *ap,
const char *pass_phrase,
- nsapi_security_t security)
+ nsapi_security_t security,
+ uint8_t channel)
{
int mode;
//initialize the device before connecting
if(!isInitialized)
{
- if(!init())
+ if (init() != NSAPI_ERROR_OK)
return NSAPI_ERROR_DEVICE_ERROR;
}
@@ -135,7 +157,11 @@
mode = 2;
break;
}
- return (_spwf.connect((char*)ap, (char*)pass_phrase, mode));
+ if (_spwf.connect((char*)ap, (char*)pass_phrase, mode, channel)) {
+ return NSAPI_ERROR_NO_CONNECTION;
+ } else {
+ return NSAPI_ERROR_OK;
+ }
}
/**
@@ -257,7 +283,8 @@
* proto: handle of server socket which will accept connections
* @retval NSAPI Error Type
*/
-int SpwfSAInterface::socket_accept(void **handle, void *server)
+nsapi_error_t SpwfSAInterface::socket_accept(nsapi_socket_t server,
+ nsapi_socket_t *handle, SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
}
--- a/SpwfInterface.h Thu Nov 03 06:57:03 2016 +0000
+++ b/SpwfInterface.h Sun Nov 20 20:31:30 2016 +0000
@@ -50,41 +50,61 @@
public:
SpwfSAInterface(PinName tx, PinName rx, bool debug = false);
- virtual ~SpwfSAInterface();
+ virtual ~SpwfSAInterface();
// Implementation of WiFiInterface
- virtual int connect(const char *ssid,
+ virtual nsapi_error_t set_credentials(const char *ssid, const char *pass,
+ nsapi_security_t security = NSAPI_SECURITY_NONE);
+ virtual nsapi_error_t connect(const char *ssid,
const char *pass,
- nsapi_security_t security = NSAPI_SECURITY_NONE);
-
- virtual int disconnect();
- virtual const char *get_mac_address();
- void debug(const char * string);
+ nsapi_security_t security = NSAPI_SECURITY_NONE,
+ uint8_t channel = 0);
+ virtual nsapi_error_t connect() {
+ if (_ssid == 0 || _pass == 0) return NSAPI_ERROR_PARAMETER;
+ return connect(_ssid, _pass, _security, _channel);
+ }
+ virtual nsapi_error_t set_channel(uint8_t channel) {
+ _channel = channel;
+ return NSAPI_ERROR_OK;
+ }
+ virtual int8_t get_rssi();
+ virtual int disconnect();
+ virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, nsapi_size_t count) {
+ return NSAPI_ERROR_UNSUPPORTED; // TODO! Add scan support
+ }
+
+ virtual const char *get_mac_address();
+ void debug(const char * string);
//Implementation of NetworkStack
- virtual const char *get_ip_address();
+ virtual const char *get_ip_address();
protected:
//Implementation of NetworkStack
- virtual int socket_open(void **handle, nsapi_protocol_t proto);
- virtual int socket_close(void *handle);
- virtual int socket_bind(void *handle, const SocketAddress &address); //not supported
- virtual int socket_listen(void *handle, int backlog);
- virtual int socket_connect(void *handle, const SocketAddress &address);
- virtual int socket_accept(void **handle, void *server);
- virtual int socket_send(void *handle, const void *data, unsigned size);
- virtual int socket_recv(void *handle, void *data, unsigned size);
- virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size);
- virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
- virtual void socket_attach(void *handle, void (*callback)(void *), void *data);
-
+ virtual int socket_open(void **handle, nsapi_protocol_t proto);
+ virtual int socket_close(void *handle);
+ virtual int socket_bind(void *handle, const SocketAddress &address); //not supported
+ virtual int socket_listen(void *handle, int backlog);
+ virtual int socket_connect(void *handle, const SocketAddress &address);
+ virtual nsapi_error_t socket_accept(nsapi_socket_t server,
+ nsapi_socket_t *handle, SocketAddress *address=0);
+ virtual int socket_send(void *handle, const void *data, unsigned size);
+ virtual int socket_recv(void *handle, void *data, unsigned size);
+ virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size);
+ virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
+ virtual void socket_attach(void *handle, void (*callback)(void *), void *data);
+ virtual NetworkStack* get_stack() {return this;}
private:
- int init(void);
+ int init(void);
SPWFSA01 _spwf;
bool _ids[SPWFSA_SOCKET_COUNT];
bool isListening;
- bool isInitialized;
+ bool isInitialized;
+ const char *_ssid;
+ const char *_pass;
+ nsapi_security_t _security;
+ uint8_t _channel;
};
