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
Diff: Spwf_API/SpwfSADevice.cpp
- Revision:
- 8:0f302a13e21b
- Parent:
- 7:0fdd186a7d90
- Child:
- 9:d2dfbf8e7f49
diff -r 0fdd186a7d90 -r 0f302a13e21b Spwf_API/SpwfSADevice.cpp --- a/Spwf_API/SpwfSADevice.cpp Wed May 11 06:12:16 2016 +0000 +++ b/Spwf_API/SpwfSADevice.cpp Thu May 12 07:36:13 2016 +0000 @@ -96,7 +96,7 @@ //UART error not evident but characters are sometimes missing in pipeline(ring_buffer)\ //specifically in the +WIND:25:WiFi Association with 'STM' successful WIND (why specifically this?) - wifi_callback.attach_us(Wifi_scheduler, 2000);//How low can we go? + wifi_callback.attach_us(Wifi_scheduler, 5000);//How low can we go? sync_wait_signal = false; status = wifi_init(&config); @@ -197,14 +197,14 @@ int SpwfSADevice::socket_client_write(uint8_t sock_id, uint16_t DataLength,char * pData) { - WiFi_Status_t status = WiFi_MODULE_SUCCESS; + int status=0;//number of bytes status = wifi_socket_client_write(sock_id, DataLength, pData); //map error to enum ns_error_t - if(status!=WiFi_MODULE_SUCCESS) + if(status > 0) { - return -1; + return status; } return 0; } @@ -218,15 +218,16 @@ if(recv_call) { - __disable_irq(); + //debug_print("\r\nrecv_call\r\n"); + //__disable_irq(); wait_for_socket_data = false; + recv_buff = (uint8_t*)pData; + //__enable_irq(); if(_timeout>0) recv_timer.start(); recv_call = false; bytes_to_read = RecvLength; bytes_read=0; - recv_buff = (uint8_t*)pData; - __enable_irq(); } @@ -237,12 +238,13 @@ wait_for_socket_data = true; recv_timer.stop(); recv_timer.reset(); + wait_ms(10); 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 } - + wait_ms(10); //CHECK:TODO: Need to wait to allow other IRQ's to run in case of non-blocking call? return -1; } @@ -282,23 +284,24 @@ void SpwfSADevice::signal_data_receive(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size) { - char debug_str[10]; + char debug_str[50]; //Data will be copied or returned to user only if there is a pending request //Copy data to pData - //sprintf((char*)debug_str,"sock_id: %d, size: %d\r\n",socket_id, message_size); + //sprintf((char*)debug_str,"sock_id: %d, size: %d, chunk: %d\r\n",socket_id, message_size, chunk_size); + //debug_print(debug_str); if(recv_buff && !wait_for_socket_data) { - if((bytes_read + message_size)<= bytes_to_read) + if((bytes_read + chunk_size)<= bytes_to_read) { - memcpy(recv_buff + bytes_read, data_ptr, message_size);//only copy bytes_to_read asked by user//rest of the data is lost!! - bytes_read += message_size; + memcpy(recv_buff + bytes_read, data_ptr, chunk_size);//only copy bytes_to_read asked by user//rest of the data is lost!! + bytes_read += chunk_size; } else { - uint32_t x_size = (bytes_read + message_size) - bytes_to_read; - memcpy(recv_buff + bytes_read, data_ptr, message_size-x_size); - bytes_read += (message_size-x_size); + uint32_t x_size = (bytes_read + chunk_size) - bytes_to_read; + memcpy(recv_buff + bytes_read, data_ptr, chunk_size-x_size); + bytes_read += (chunk_size-x_size); } if(bytes_read >= bytes_to_read) @@ -311,13 +314,12 @@ else { debug_print("\r\n Socket:: Data Dropped: "); - sprintf((char*)debug_str,"%d\r\n",message_size); + sprintf((char*)debug_str,"%d\r\n",chunk_size); debug_print(debug_str); __disable_irq(); wait_for_socket_data = true; __enable_irq(); } - } void SpwfSADevice::signal_synch_wait(WiFi_Status_t code) @@ -365,15 +367,14 @@ int SpwfSADevice::socket_server_write(uint16_t data_length,char * pdata) { - WiFi_Status_t status = WiFi_MODULE_SUCCESS; + int status = 0;//number of bytes status = wifi_socket_server_write(data_length, pdata); //map error to enum ns_error_t - if(status!=WiFi_MODULE_SUCCESS) + if(status > 0) { - return -1; - } - + return status; + } return 0; } @@ -403,10 +404,10 @@ } } -void SpwfSADevice::spwf_send(const char * cmd, uint16_t size) +int SpwfSADevice::spwf_send(const char * cmd, uint16_t size) { Timer timer; - int i; + int i, bytes; //timer.start(); //uart_.puts(cmd);//string may contain '\0' character in between hence not used @@ -418,6 +419,9 @@ //return -1; //} } + + bytes = (int) size - 2;//we send 2 bytes extra for module + return bytes; } char SpwfSADevice::spwf_get(void)