emw3162 driver for mbed os 5

Fork of emw3162-driver by Maggie Mei

Files at this revision

API Documentation at this revision

Comitter:
Maggie17
Date:
Thu Nov 17 03:52:22 2016 +0000
Parent:
2:fb6251306b21
Commit message:
emw3162 driver for mbed os 5

Changed in this revision

EMW3162Interface.cpp Show annotated file Show diff for this revision Revisions of this file
EMW3162Interface.h Show annotated file Show diff for this revision Revisions of this file
--- a/EMW3162Interface.cpp	Mon Nov 14 02:30:49 2016 +0000
+++ b/EMW3162Interface.cpp	Thu Nov 17 03:52:22 2016 +0000
@@ -34,10 +34,12 @@
     _esp.attach(this, &EMW3162Interface::event);
 }
 
-int EMW3162Interface::connect(
-    const char *ssid,
-    const char *pass,
-    nsapi_security_t security)
+int EMW3162Interface::connect()
+{
+    return 0;
+}
+int EMW3162Interface::connect(const char *ssid, const char *pass, nsapi_security_t security,
+                                        uint8_t channel)
 {
     _esp.setTimeout(EMW3162_CONNECT_TIMEOUT);
 
@@ -57,9 +59,19 @@
         return NSAPI_ERROR_DHCP_FAILURE;
     }
 
+    return NSAPI_ERROR_OK;
+}
+
+int EMW3162Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
+{
     return 0;
 }
 
+int EMW3162Interface::set_channel(uint8_t channel)
+{
+    return NSAPI_ERROR_UNSUPPORTED;
+}
+
 int EMW3162Interface::disconnect()
 {
     _esp.setTimeout(EMW3162_MISC_TIMEOUT);
@@ -81,6 +93,26 @@
     return _esp.getMACAddress();
 }
 
+const char *EMW3162Interface::get_gateway()
+{
+    return NULL;
+}
+
+const char *EMW3162Interface::get_netmask()
+{
+    return NULL;
+}
+
+int8_t EMW3162Interface::get_rssi()
+{
+    return 0;
+}
+
+int EMW3162Interface::scan(WiFiAccessPoint *res, unsigned count)
+{
+    return 0;
+}
+
 struct EMW3162_socket {
     int id;
     int socketId;
@@ -158,7 +190,7 @@
     return 0;
 }
     
-int EMW3162Interface::socket_accept(void **handle, void *server)
+int EMW3162Interface::socket_accept(void *handle, void **socket, SocketAddress *address)
 {
     return NSAPI_ERROR_UNSUPPORTED;
 }
--- a/EMW3162Interface.h	Mon Nov 14 02:30:49 2016 +0000
+++ b/EMW3162Interface.h	Thu Nov 17 03:52:22 2016 +0000
@@ -17,8 +17,9 @@
 #ifndef EMW3162_INTERFACE_H
 #define EMW3162_INTERFACE_H
 
-#include "NetworkSocketAPI/NetworkStack.h"
-#include "NetworkSocketAPI/WiFiInterface.h"
+#include "mbed.h"
+//#include "NetworkSocketAPI/NetworkStack.h"
+//#include "NetworkSocketAPI/WiFiInterface.h"
 #include "EMW3162.h"
 
 
@@ -39,18 +40,44 @@
 
     /** Start the interface
      *
-     *  Attempts to connect to a WiFi network. If passphrase is invalid,
-     *  NSAPI_ERROR_AUTH_ERROR is returned.
+     *  Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
+     *  If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
+     *
+     *  @return         0 on success, negative error code on failure
+     */
+    virtual int connect();
+
+    /** Start the interface
+     *
+     *  Attempts to connect to a WiFi network.
+     *
+     *  @param ssid      Name of the network to connect to
+     *  @param pass      Security passphrase to connect to the network
+     *  @param security  Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
+     *  @param channel   This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
+     *  @return          0 on success, or error code on failure
+     */
+    virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE,
+                                  uint8_t channel = 0);
+
+    /** Set the WiFi network credentials
      *
      *  @param ssid      Name of the network to connect to
      *  @param pass      Security passphrase to connect to the network
      *  @param security  Type of encryption for connection
-     *  @return          0 on success, negative error code on failure
+     *                   (defaults to NSAPI_SECURITY_NONE)
+     *  @return          0 on success, or error code on failure
      */
-    virtual int connect(
-        const char *ssid,
-        const char *pass,
-        nsapi_security_t security = NSAPI_SECURITY_NONE);
+    virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
+
+    /** Set the WiFi network channel - NOT SUPPORTED
+     *
+     * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
+     *
+     *  @param channel   Channel on which the connection is to be made, or 0 for any (Default: 0)
+     *  @return          Not supported, returns NSAPI_ERROR_UNSUPPORTED
+     */
+    virtual int set_channel(uint8_t channel);
 
     /** Stop the interface
      *  @return             0 on success, negative on failure
@@ -67,6 +94,38 @@
      */
     virtual const char *get_mac_address();
 
+    /** Get the local gateway
+     *
+     *  @return         Null-terminated representation of the local gateway
+     *                  or null if no network mask has been recieved
+     */
+    virtual const char *get_gateway();
+
+    /** Get the local network mask
+     *
+     *  @return         Null-terminated representation of the local network mask
+     *                  or null if no network mask has been recieved
+     */
+    virtual const char *get_netmask();
+
+    /** Gets the current radio signal strength for active connection
+     *
+     * @return          Connection strength in dBm (negative value)
+     */
+    virtual int8_t get_rssi();
+
+    /** Scan for available networks
+     *
+     * This function will block.
+     *
+     * @param  ap       Pointer to allocated array to store discovered AP
+     * @param  count    Size of allocated @a res array, or 0 to only count available AP
+     * @param  timeout  Timeout in milliseconds; 0 for no timeout (Default: 0)
+     * @return          Number of entries in @a, or if @a count was 0 number of available networks, negative on error
+     *                  see @a nsapi_error
+     */
+    virtual int scan(WiFiAccessPoint *res, unsigned count);
+    
 protected:
     /** Open a socket
      *  @param handle       Handle in which to store new socket
@@ -112,7 +171,7 @@
      *  @note This call is not-blocking, if this call would block, must
      *        immediately return NSAPI_ERROR_WOULD_WAIT
      */
-    virtual int socket_accept(void **handle, void *server);
+    virtual int socket_accept(void *handle, void **socket, SocketAddress *address);
 
     /** Send data to the remote host
      *  @param handle       Socket handle
@@ -179,6 +238,11 @@
     EMW3162 _esp;
     bool _ids[EMW3162_SOCKET_COUNT];
 
+    char ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
+    nsapi_security_t ap_sec;
+    uint8_t ap_ch;
+    char ap_pass[64]; /* The longest allowed passphrase */
+
     void event();
     struct {
         void (*callback)(void *);