for EthernetInterface library compatibility.\\ ** Unoffical fix. may be a problem. **

Dependents:   SNIC-httpclient-example SNIC-ntpclient-example

Fork of SNICInterface by muRata

Files at this revision

API Documentation at this revision

Comitter:
kishino
Date:
Thu Mar 13 10:33:18 2014 +0000
Parent:
5:ef3befe3edad
Child:
7:e88ccbe0225f
Commit message:
Create get status command

Changed in this revision

YDwifi/YDwifi.cpp Show annotated file Show diff for this revision Revisions of this file
YDwifi/YDwifi.h Show annotated file Show diff for this revision Revisions of this file
YDwifiInterface.cpp Show annotated file Show diff for this revision Revisions of this file
YDwifiInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/YDwifi/YDwifi.cpp	Thu Mar 13 08:44:33 2014 +0000
+++ b/YDwifi/YDwifi.cpp	Thu Mar 13 10:33:18 2014 +0000
@@ -19,7 +19,7 @@
 C_YDwifi *C_YDwifi::mInstance_p;
 
 C_YDwifi::C_YDwifi(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud):
-    mUart(tx, rx), mModuleReset(reset)
+    mUart(tx, rx)
 {
     mUartRecvThread_p = NULL;
     mInstance_p       = this;
--- a/YDwifi/YDwifi.h	Thu Mar 13 08:44:33 2014 +0000
+++ b/YDwifi/YDwifi.h	Thu Mar 13 10:33:18 2014 +0000
@@ -43,6 +43,19 @@
         e_ADHOC = 1
     }E_NETWORK_TYPE;
 
+    /** Wi-Fi status
+     */
+    typedef enum WIFI_STATUS {
+        /** Wi-Fi OFF */
+        e_STATUS_OFF = 0,
+        /** No network */
+        e_NO_NETWORK,
+        /** Connected to AP (STA mode) */
+        e_STA_JOINED,
+        /** Started  on AP mode */
+        e_AP_STARTED
+    }E_WIFI_STATUS;
+
 protected:
     /** GEN_FW_VER_GET_REQ Command */
     typedef struct 
@@ -80,6 +93,14 @@
         unsigned char seq;
     }tagWIFI_GET_STA_RSSI_REQ_T;
 
+    /** WIFI_GET_STATUS_REQ Command */
+    typedef struct 
+    {
+        unsigned char cmd_sid;
+        unsigned char seq;
+        unsigned char interface;
+    }tagWIFI_GET_STATUS_REQ_T;
+
     /** WIFI_SCAN_REQ Command */
     typedef struct 
     {
@@ -95,7 +116,7 @@
     static C_YDwifi     *mInstance_p;
     Thread              *mUartRecvThread_p;
     Mutex               mUartMutex;
-    DigitalInOut        mModuleReset;
+//    DigitalInOut        mModuleReset;
     C_YDwifiUartCommand mUartCommand;
     RawSerial           mUart;
     
--- a/YDwifiInterface.cpp	Thu Mar 13 08:44:33 2014 +0000
+++ b/YDwifiInterface.cpp	Thu Mar 13 10:33:18 2014 +0000
@@ -475,3 +475,72 @@
     gMEMPOOL_PAYLOAD.free( payload_buf );
     return 0;
 }
+
+int C_YDwifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p)
+{
+    if( status_p == NULL )
+    {
+        printf("getWifiStatus parameter error\r\n");
+        return -1;
+    }
+    
+    // Get buffer for response payload from MemoryPool
+    tagMEMPOOL_BLOCK_T *payload_buf = gMEMPOOL_PAYLOAD.alloc();
+    if( payload_buf == NULL )
+    {
+        printf("getWifiStatus payload_buf NULL\r\n");
+        return -1;
+    }
+
+    tagWIFI_GET_STATUS_REQ_T req;
+    unsigned char  payload_array[UART_REQUEST_PAYLOAD_MAX];
+    unsigned char  command_array[UART_REQUEST_PAYLOAD_MAX];
+    unsigned short payload_len;
+    unsigned int   command_len;
+    int ret;
+    
+    // Make request
+    req.cmd_sid = UART_CMD_SID_WIFI_GET_STATUS_REQ;
+    req.seq     = mUartRequestSeq++;
+    req.interface = 0;
+    
+    // Make command payload
+    payload_len = C_YD_UartMsg::makePayload( sizeof(tagWIFI_GET_STATUS_REQ_T), (unsigned char *)&req, payload_array );
+    // Make all command request
+    command_len = C_YD_UartMsg::makeRequest( UART_CMD_ID_WIFI, payload_array, payload_len, command_array );
+
+    // Set data for response
+    mUartCommand.setCommandID( UART_CMD_ID_WIFI );
+    mUartCommand.setCommandSID( req.cmd_sid );
+    mUartCommand.setResponseBuf( payload_buf->buf );
+    
+    // Send uart command request
+    sendUart( command_len, command_array );
+    
+    // Wait UART response
+    ret = mUartCommand.wait();
+    if( ret != 0 )
+    {
+        printf( "getWifiStatus failed\r\n" );
+        gMEMPOOL_PAYLOAD.free( payload_buf );
+        return -1;
+    }
+    
+    // set status
+    status_p->status = (E_WIFI_STATUS)payload_buf->buf[2];
+    
+    // set Mac address
+    if( status_p->status != e_STATUS_OFF )
+    {
+        memcpy( status_p->mac_address, &payload_buf->buf[3], BSSID_MAC_LENTH );
+    } 
+
+    // set SSID
+    if( ( status_p->status == e_STA_JOINED ) == ( status_p->status == e_AP_STARTED ) )
+    {
+        memcpy( status_p->ssid, &payload_buf->buf[9], strlen( (char *)&payload_buf->buf[9]) );
+    } 
+
+    gMEMPOOL_PAYLOAD.free( payload_buf );
+    return 0;
+}
--- a/YDwifiInterface.h	Thu Mar 13 08:44:33 2014 +0000
+++ b/YDwifiInterface.h	Thu Mar 13 10:33:18 2014 +0000
@@ -10,6 +10,17 @@
  */
 class C_YDwifiInterface: public C_YDwifi {
 public:
+    /** Wi-Fi status */
+    typedef struct
+    {
+        /** status */
+        E_WIFI_STATUS status;
+        /** Mac address */
+        char mac_address[BSSID_MAC_LENTH];
+        /** SSID */
+        char ssid[SSID_MAX_LENGTH+1];
+    }tagWIFI_STATUS_T;
+
     /** Constructor
         @param tx mbed pin to use for tx line of Serial interface
         @param rx mbed pin to use for rx line of Serial interface
@@ -90,6 +101,14 @@
     */
     int getRssi( signed char *rssi_p );
 
+    /** Get Wi-Fi status
+        @param status_p Pointer of status structure.[output]
+        @return 0 on success, a negative number on failure
+        @note   This function is blocked until a returns.
+                When you use it by UI thread, be careful. 
+    */
+    int getWifiStatus( tagWIFI_STATUS_T *status_p);
+
 #if 0  
   /** Get the MAC address of your Ethernet interface
    * \return a pointer to a string containing the MAC address