For test

Dependencies:   mbed

Revision:
35:90be2bc2a492
Parent:
34:65cd9c6eedb8
--- a/ESP8266.h	Thu Feb 05 03:38:10 2015 +0000
+++ b/ESP8266.h	Thu Feb 05 06:48:45 2015 +0000
@@ -28,7 +28,7 @@
 typedef enum {
     ESP8266_COMM_UDP              = 0, /**< UPD */
     ESP8266_COMM_TCP              = 1, /**< TCP */
-} ESP8266CommMode; 
+} ESP8266CommType; 
 
 /**
  * The work mode. 
@@ -42,26 +42,12 @@
 } ESP8266WorkMode;
 
 /**
- * The channel for SoftAP. 
- * 
- * Only 1 - 13 acceptable. 
+ * Mux single or multiple connection mode. 
  */
 typedef enum {
-    ESP8266_CHANNEL_1 = 1,
-    ESP8266_CHANNEL_2,
-    ESP8266_CHANNEL_3,
-    ESP8266_CHANNEL_4,
-    ESP8266_CHANNEL_5,
-    ESP8266_CHANNEL_6,
-    ESP8266_CHANNEL_7,
-    ESP8266_CHANNEL_8,
-    ESP8266_CHANNEL_9,
-    ESP8266_CHANNEL_10,
-    ESP8266_CHANNEL_11,
-    ESP8266_CHANNEL_12,
-    ESP8266_CHANNEL_13,
-} ESP8266Channel;
-
+    ESP8266_MUX_SINGLE      = 0,   /**< Single mode */
+    ESP8266_MUX_MULTIPLE    = 1,   /**< Multiple mode */
+} ESP8266Mux;
 
 /**
  * Provide methods to manipulate ESP8266 for internet access via WiFi. 
@@ -95,12 +81,12 @@
      *
      * @param sap_ssid - SSID of its self softap. 
      * @param sap_pwd - PASSWORD of its self softap. 
-     * @param chl - the channel can be 1, 2, 3, ..., 13. 
-     * @param enc - the method of encrypstion. 
+     * @param chl - the channel can be 1, 2, 3, ..., 13(default: 7).  
+     * @param enc - the method of encrypstion(default: ESP8266_ECN_WAP_WAP2_PSK). 
      * @return true if success, false for failure. 
      */
     bool setSoftAPMode(String sap_ssid, String sap_pwd,
-        ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
+        int chl = 7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
     
     /**
      * Set as softap + station mode and start softap and join in ssid with pwd. 
@@ -109,52 +95,177 @@
      * @param pwd - PASSWORD of AP to join in. 
      * @param sap_ssid - SSID of its self softap. 
      * @param sap_pwd - PASSWORD of its self softap. 
-     * @param chl - the channel can be 1, 2, 3, ..., 13. 
-     * @param enc - the method of encrypstion. 
+     * @param chl - the channel can be 1, 2, 3, ..., 13(default: 7).  
+     * @param enc - the method of encrypstion(default: ESP8266_ECN_WAP_WAP2_PSK). 
      * @return true if success, false for failure. 
      */
     bool setStationSoftAPMode(String ssid, String pwd, String sap_ssid, String sap_pwd ,
-        ESP8266Channel chl = ESP8266_CHANNEL_7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
+        int chl = 7, ESP8266Encrypstion ecn = ESP8266_ECN_WAP_WAP2_PSK);
     
     /**
      * Start a TCP connection to server or init UDP communication. 
+     * 
+     * @param type - TCP or UDP.
+     * @param addr - ip address or domain name of server to connect. 
+     * @param port - the port number of server to connect. 
+     * @param mux - single or mulitple connection mode(default: ESP8266_MUX_SINGLE). 
+     * @param id - id number when mux is multiple(default: 0). 
+     * @return true for success, false for failure.
      */
-    bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0);
+    bool ipConfig(ESP8266CommType type, String addr, int port, ESP8266Mux mux = ESP8266_MUX_SINGLE, int id = 0);
     
+    /**
+     * Set the connection mode(sigle or multiple)
+     *
+     * @param mux - single or multiple. 
+     * @return true for success, false for failure.
+     */
+    bool confMux(ESP8266Mux mux);    
+    
+    /**
+     * Start or stop the TCP server.
+     * 
+     * @param mode - 1 to start, 0 to stop (restart needed). 
+     * @param port - the port to listen. 
+     * @return true for success, false for failure.
+     */
+    bool confServer(int mode, int port);  
     
     /**
      * Send data in sigle connection mode(mux = 0). 
      * 
+     * @param str - string to send. 
+     * @return true for success, false for failure.
      */
     bool send(String str);  
     
     /**
      * Send data in multiple connection mode(mux = 1). 
      *
+     * @param id - id number. 
+     * @param str - string to send by id connection. 
+     * @return true for success, false for failure.
      */
-    bool send(uint8_t id, String str);  
+    bool send(int id, String str);  
     
     /**
      * Start to receive data from network. 
+     * 
+     * @param buf - buffer for storing data from network. 
+     * @return the size of data received.
      */
     int recvData(char *buf);
     
     /**
      * Get the current id of data received via member method:recvData in multiple connection mode.
+     *
+     * @return the id of connection which data received from. 
      */
     int getMuxID(void);
     
     /** 
      * Reset the module. 
+     *
+     * @return true for success, false for failure.
      */
     bool reset(void);    
     
+    /**
+     * Get current work mode. 
+     * 
+     * @return the mode. 
+     */
+    String showMode(void);   
     
+    
+    /**
+     * Get the list of Access Points available. 
+     *
+     * @return the list of SSID. 
+     */
+    String showAP(void);   
+    
+    /**
+     * Get the SSID of AP joined already. 
+     * 
+     * @return the SSID joined. 
+     */
+    String showJAP(void);  
+    
+    /**
+     * Quit the AP joined before. 
+     * 
+     * @return true for success, false for failure.
+     */
+    bool quitAP(void);    
+    
+    
+    /**
+     * Get SoftAP Parameters. 
+     *
+     * @return the parameters of SoftAP.
+     */
+    String showSAP(void);     
+
+    /**
+     * Get the status of connection. 
+     *
+     * @return the status. 
+     */
+    String showStatus(void);  
+    
+    /**
+     * Get the connection mode(sigle or multiple)
+     * 
+     * @return the mux string. 
+     */
+    String showMux(void);  
+    
+    /**
+     * Show the current ip address. 
+     * 
+     * @return the ip address. 
+     */
+    String showIP(void);    
+    
+    /**
+     * Create new tcp or udp connection in sigle connection mode. 
+     *
+     * @param type - UDP or TCP.
+     * @param addr - the ip or domain name of server. 
+     * @param port - the port number. 
+     */
+    bool newMux(ESP8266CommType type, String addr, int port);   
+    
+    /**
+     * Create new tcp or udp connection in multiple connection mode)(id:0-4). 
+     *
+     * @param id - the id number. 
+     * @param type - UDP or TCP.
+     * @param addr - the ip or domain name of server. 
+     * @param port - the port number.      
+     */
+    bool newMux(int id, ESP8266CommType type, String addr, int port);   
+    
+    /**
+     * Close tcp or udp in sigle connection mode.  
+     */
+    void closeMux(void);   
+    
+    /**
+     * Close tcp or udp in multiple connection mode. 
+     *
+     * @param id - the id number.
+     */
+    void closeMux(int id); 
+
+private:
+
     /**
      * Set work mode. 
      * 
      */
-    bool confMode(uint8_t mode);   
+    bool confMode(ESP8266WorkMode mode);   
     
     
     /**
@@ -168,86 +279,9 @@
      * Set SoftAP Parameters. 
      *
      */
-    bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn);       
-    
-    
-    /**
-     * Get current work mode. 
-     *
-     */
-    String showMode(void);   
-    
-    
-    /**
-     * Get the list of Access Points available. 
-     *
-     */
-    String showAP(void);   
-    
-    /**
-     * Get the SSID of AP joined already. 
-     */
-    String showJAP(void);  
-    
-    /**
-     * Quit the AP joined before. 
-     */
-    bool quitAP(void);    
-    
-    
-    /**
-     * Get SoftAP Parameters. 
-     *
-     */
-    String showSAP(void);     
-
-    /**
-     * Get the status of connection. 
-     *
-     */
-    String showStatus(void);  
-    
-    /**
-     * Get the connection mode(sigle or multiple)
-     */
-    String showMux(void);  
-    
-    /**
-     * Set the connection mode(sigle or multiple)
-     */
-    bool confMux(int mux);    
-    
-    /**
-     * Create new tcp or udp connection in sigle connection mode. 
-     */
-    bool newMux(uint8_t type, String addr, int port);   
-    
-    /**
-     * Create new tcp or udp connection in multiple connection mode)(id:0-4). 
-     */
-    bool newMux(uint8_t id, uint8_t type, String addr, int port);   
-    
-    /**
-     * Close tcp or udp in sigle connection mode.  
-     */
-    void closeMux(void);   
-    
-    /**
-     * Close tcp or udp in multiple connection mode. 
-     */
-    void closeMux(uint8_t id); 
-    
-    /**
-     * Show the current ip address. 
-     */
-    String showIP(void);    
-    
-    /**
-     * Start or stop the TCP server.
-     */
-    bool confServer(uint8_t mode, int port);  
-
-private:
+    bool confSAP(String ssid , String pwd , int chl , int ecn);      
+        
+     
     ArduinoSerial m_uart; /* The UART to communicate with ESP8266 */
     int m_mux_id;
 };