Extending the X_NUCLEO_IDW01M1 to allow configuration of the board as an access point

Dependents:   X_NUCLEO_IDW01M1_AP_Test

Fork of X_NUCLEO_IDW01M1 by ST

Revision:
7:0fdd186a7d90
Parent:
6:e7a3fca2df10
Child:
8:0f302a13e21b
--- a/Spwf_API/SpwfSADevice.cpp	Mon May 09 10:38:22 2016 +0000
+++ b/Spwf_API/SpwfSADevice.cpp	Wed May 11 06:12:16 2016 +0000
@@ -61,6 +61,7 @@
     setSpwfSADevice(this);
     sync_wait_signal = false;
     wait_for_incoming_client = false;
+    wait_for_socket_data = false;
 }
 
 SpwfSADevice::~SpwfSADevice(void)
@@ -186,7 +187,7 @@
     status = wifi_socket_client_open(hostname, port_number, protocol, sock_id);
     if(status!=WiFi_MODULE_SUCCESS)
     {
-        *sock_id = 9;//make sure socket id is not set(set to out of bounds of SPWFSA_SOCKET_COUNT range)
+        *sock_id = 99;//make sure socket id is not set(set to out of bounds of SPWFSA_SOCKET_COUNT range)
         return -1;
     }
     
@@ -211,34 +212,40 @@
 
 int SpwfSADevice::socket_client_recv(uint8_t sock_id, uint16_t RecvLength,char * pData)
 {
-    Timer timer;
-    //char debug_str[10];
-    timer.start();
-    bytes_to_read = RecvLength;
-
-    __disable_irq();
-    bytes_read=0;
-    sync_wait_signal = false;
-    recv_buff = (uint8_t*)pData;
-    __enable_irq();
-            
-    while(!sync_wait_signal)
+    static Timer recv_timer;
+    //char debug_str[10];    
+    static bool recv_call = true;
+    
+    if(recv_call)
     {
-      if (timer.read_ms() > _timeout) {
-            //debug_print("\r\n SpwfSADevice:: Timeout!\r\n");
-            sync_wait_signal = true;            
-            //if(bytes_read==0) return -1;//return error if no bytes are read!
-            //sprintf((char*)debug_str,"bytes_read: %d\r\n",bytes_read); 
-            //debug_print(debug_str);
+        __disable_irq();
+        wait_for_socket_data = false;
+        if(_timeout>0)
+        recv_timer.start();
+        recv_call = false;
+        bytes_to_read = RecvLength;        
+        bytes_read=0;
+        recv_buff = (uint8_t*)pData;
+        __enable_irq();
+    }
+            
+    
+    if(wait_for_socket_data || recv_timer.read_ms() >= _timeout)
+    {      
+        recv_call = true;
+        _timeout = 0;
+        wait_for_socket_data = true;
+        recv_timer.stop();
+        recv_timer.reset();
+        if(bytes_read == 0) //<bytes_to_read?? 
+            return -1;//return error if no bytes are read!
+        else 
             return bytes_read;//return amount of data arrived so far
-            //when do we return NS_ERROR_WOULD_BLOCK??
-        }
-      __NOP();
     }
+    
+    return -1;    
+}
 
-    return bytes_read;
-    
-}
 
 void SpwfSADevice::network_scan(wifi_scan *scan_result, uint16_t max_scan_number)
 {
@@ -280,7 +287,7 @@
     //Copy data to pData
     //sprintf((char*)debug_str,"sock_id: %d, size: %d\r\n",socket_id, message_size); 
             
-    if(recv_buff && !sync_wait_signal)
+    if(recv_buff && !wait_for_socket_data)
     {
         if((bytes_read + message_size)<= bytes_to_read)
         {
@@ -297,7 +304,7 @@
         if(bytes_read >= bytes_to_read)
         {
             __disable_irq();
-            sync_wait_signal = true;
+            wait_for_socket_data = true;
             __enable_irq();
         }
     }
@@ -307,7 +314,7 @@
         sprintf((char*)debug_str,"%d\r\n",message_size); 
         debug_print(debug_str);
         __disable_irq();
-        sync_wait_signal = true;
+        wait_for_socket_data = true;
         __enable_irq();
     }