Updates and additions required by mbed-os 5.2.2

Dependencies:   SPWF01SA-lapi-1

Dependents:   x-nucleo-iks01a1-test x-nucleo-iks01a1-test

Fork of X_NUCLEO_IDW01M1v2 by ST

Revision:
13:3d28a8c18182
Parent:
9:4cd89586b370
--- 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;
 }