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
Spwf/wifi_module.c@7:0fdd186a7d90, 2016-05-11 (annotated)
- Committer:
- mridup
- Date:
- Wed May 11 06:12:16 2016 +0000
- Revision:
- 7:0fdd186a7d90
- Parent:
- 5:c83ffd44f40a
- Child:
- 8:0f302a13e21b
fix recv, server sock, \r\n..\r\n issue in FW.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 0:dc55f40eb04f | 1 | /** |
mridup | 0:dc55f40eb04f | 2 | ****************************************************************************** |
mridup | 0:dc55f40eb04f | 3 | * @file wifi_module.c |
mridup | 0:dc55f40eb04f | 4 | * @author Central LAB |
mridup | 0:dc55f40eb04f | 5 | * @version V2.0.0 |
mridup | 0:dc55f40eb04f | 6 | * @date 10-February-2016 |
mridup | 0:dc55f40eb04f | 7 | * @brief Enable Wi-Fi functionality using AT cmd set |
mridup | 0:dc55f40eb04f | 8 | ****************************************************************************** |
mridup | 0:dc55f40eb04f | 9 | * @attention |
mridup | 0:dc55f40eb04f | 10 | * |
mridup | 0:dc55f40eb04f | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mridup | 0:dc55f40eb04f | 12 | * |
mridup | 0:dc55f40eb04f | 13 | * Redistribution and use in source and binary forms, with or without modification, |
mridup | 0:dc55f40eb04f | 14 | * are permitted provided that the following conditions are met: |
mridup | 0:dc55f40eb04f | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
mridup | 0:dc55f40eb04f | 16 | * this list of conditions and the following disclaimer. |
mridup | 0:dc55f40eb04f | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mridup | 0:dc55f40eb04f | 18 | * this list of conditions and the following disclaimer in the documentation |
mridup | 0:dc55f40eb04f | 19 | * and/or other materials provided with the distribution. |
mridup | 0:dc55f40eb04f | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mridup | 0:dc55f40eb04f | 21 | * may be used to endorse or promote products derived from this software |
mridup | 0:dc55f40eb04f | 22 | * without specific prior written permission. |
mridup | 0:dc55f40eb04f | 23 | * |
mridup | 0:dc55f40eb04f | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mridup | 0:dc55f40eb04f | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mridup | 0:dc55f40eb04f | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mridup | 0:dc55f40eb04f | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mridup | 0:dc55f40eb04f | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mridup | 0:dc55f40eb04f | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mridup | 0:dc55f40eb04f | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mridup | 0:dc55f40eb04f | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mridup | 0:dc55f40eb04f | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mridup | 0:dc55f40eb04f | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mridup | 0:dc55f40eb04f | 34 | * |
mridup | 0:dc55f40eb04f | 35 | ****************************************************************************** |
mridup | 0:dc55f40eb04f | 36 | */ |
mridup | 0:dc55f40eb04f | 37 | /* Includes ------------------------------------------------------------------*/ |
mridup | 0:dc55f40eb04f | 38 | #include "wifi_module.h" |
mridup | 0:dc55f40eb04f | 39 | //#include "stm32_spwf_wifi.h" |
mridup | 0:dc55f40eb04f | 40 | #include "ring_buffer.h" |
mridup | 0:dc55f40eb04f | 41 | #include "stdio.h" |
mridup | 0:dc55f40eb04f | 42 | #include "string.h" |
mridup | 0:dc55f40eb04f | 43 | #include "event_buffer.h" |
mridup | 0:dc55f40eb04f | 44 | #include "device.h" |
mridup | 0:dc55f40eb04f | 45 | #include "wait_api.h" |
mridup | 0:dc55f40eb04f | 46 | #include <stddef.h> |
mridup | 0:dc55f40eb04f | 47 | |
mridup | 0:dc55f40eb04f | 48 | |
mridup | 0:dc55f40eb04f | 49 | /** @addtogroup MIDDLEWARES |
mridup | 0:dc55f40eb04f | 50 | * @{ |
mridup | 0:dc55f40eb04f | 51 | */ |
mridup | 0:dc55f40eb04f | 52 | |
mridup | 0:dc55f40eb04f | 53 | |
mridup | 0:dc55f40eb04f | 54 | /** @defgroup NUCLEO_WIFI_MODULE |
mridup | 0:dc55f40eb04f | 55 | * @brief Wi-Fi driver modules |
mridup | 0:dc55f40eb04f | 56 | * @{ |
mridup | 0:dc55f40eb04f | 57 | */ |
mridup | 0:dc55f40eb04f | 58 | |
mridup | 0:dc55f40eb04f | 59 | |
mridup | 0:dc55f40eb04f | 60 | /** @defgroup NUCLEO_WIFI_MODULE_Private_Defines |
mridup | 0:dc55f40eb04f | 61 | * @{ |
mridup | 0:dc55f40eb04f | 62 | */ |
mridup | 0:dc55f40eb04f | 63 | |
mridup | 0:dc55f40eb04f | 64 | |
mridup | 0:dc55f40eb04f | 65 | /** |
mridup | 0:dc55f40eb04f | 66 | * @} |
mridup | 0:dc55f40eb04f | 67 | */ |
mridup | 0:dc55f40eb04f | 68 | |
mridup | 0:dc55f40eb04f | 69 | |
mridup | 0:dc55f40eb04f | 70 | /** @addtogroup NUCLEO_WIFI_MODULE_Private_Variables |
mridup | 0:dc55f40eb04f | 71 | * @{ |
mridup | 0:dc55f40eb04f | 72 | */ |
mridup | 0:dc55f40eb04f | 73 | /* Private variables ---------------------------------------------------------*/ |
mridup | 0:dc55f40eb04f | 74 | |
mridup | 0:dc55f40eb04f | 75 | /*All Buffers*/ |
mridup | 0:dc55f40eb04f | 76 | //uint8_t WiFi_AT_Cmd_Buff[1024]; |
mridup | 0:dc55f40eb04f | 77 | uint8_t process_buffer[MAX_BUFFER_GLOBAL]; |
mridup | 0:dc55f40eb04f | 78 | char UserDataBuff[MAX_BUFFER_GLOBAL]; |
mridup | 0:dc55f40eb04f | 79 | uint8_t USART_RxBuffer[64];//This buffer is only used in the Init phase (to receive "\r\nOK\r\n") |
mridup | 0:dc55f40eb04f | 80 | char print_msg_buff[MAX_BUFFER_GLOBAL]; |
mridup | 0:dc55f40eb04f | 81 | volatile uint8_t ring_buffer[RINGBUF_SIZE];/* Default size for ring buffer */ |
mridup | 0:dc55f40eb04f | 82 | |
mridup | 0:dc55f40eb04f | 83 | #ifdef USE_STM32L0XX_NUCLEO |
mridup | 0:dc55f40eb04f | 84 | event_s_TypeDef event_buffer[10]; |
mridup | 0:dc55f40eb04f | 85 | #else |
mridup | 0:dc55f40eb04f | 86 | event_s_TypeDef event_buffer[50]; |
mridup | 0:dc55f40eb04f | 87 | #endif |
mridup | 0:dc55f40eb04f | 88 | |
mridup | 0:dc55f40eb04f | 89 | volatile uint8_t pop_buffer[MAX_BUFFER_GLOBAL]; |
mridup | 0:dc55f40eb04f | 90 | volatile uint8_t prefetch_buffer[20]; |
mridup | 0:dc55f40eb04f | 91 | uint8_t uart_byte[1]; |
mridup | 0:dc55f40eb04f | 92 | buffer_td big_buff; |
mridup | 0:dc55f40eb04f | 93 | buffer_e event_buff; |
mridup | 0:dc55f40eb04f | 94 | event_s_TypeDef element; |
mridup | 0:dc55f40eb04f | 95 | uint8_t HTTP_Runway_Buff[6];//Used to store the last 6 bytes in between User Callbacks during HTTP tx |
mridup | 0:dc55f40eb04f | 96 | wifi_scan *wifi_scanned_list; //[MAX_WIFI_SCAN_NETWORK]; |
mridup | 0:dc55f40eb04f | 97 | |
mridup | 0:dc55f40eb04f | 98 | volatile Wifi_Status_Var status_flag; |
mridup | 0:dc55f40eb04f | 99 | |
mridup | 0:dc55f40eb04f | 100 | uint32_t wind64_DQ_wait = 0; |
mridup | 0:dc55f40eb04f | 101 | uint32_t UserDataBuff_index; |
mridup | 0:dc55f40eb04f | 102 | volatile uint32_t tickcount; |
mridup | 0:dc55f40eb04f | 103 | uint8_t SocketId; |
mridup | 0:dc55f40eb04f | 104 | uint32_t SockON_Data_Len; |
mridup | 0:dc55f40eb04f | 105 | uint32_t Socket_Data_Length =0; |
mridup | 0:dc55f40eb04f | 106 | uint8_t Socket_Open_ID, sockon_query_id,sockon_id_user; |
mridup | 0:dc55f40eb04f | 107 | uint32_t SockON_Data_Length; |
mridup | 0:dc55f40eb04f | 108 | uint8_t enable_pending_data =0; |
mridup | 0:dc55f40eb04f | 109 | |
mridup | 0:dc55f40eb04f | 110 | volatile WiFi_WIND_State_TypeDef WiFi_WIND_State;//describes the current WIND number in processing |
mridup | 0:dc55f40eb04f | 111 | |
mridup | 0:dc55f40eb04f | 112 | uint8_t WiFi_Resp_OK = 0; |
mridup | 0:dc55f40eb04f | 113 | uint32_t number_of_bytes=0; |
mridup | 0:dc55f40eb04f | 114 | uint32_t interim_number_of_bytes=0; |
mridup | 0:dc55f40eb04f | 115 | uint32_t Interim_SockON_Data_Len=0; |
mridup | 0:dc55f40eb04f | 116 | uint32_t bytes_to_be_read = 0; |
mridup | 0:dc55f40eb04f | 117 | uint32_t sock_total_count=0; |
mridup | 0:dc55f40eb04f | 118 | uint32_t sockD_total_count=0; |
mridup | 0:dc55f40eb04f | 119 | uint32_t ip_fragment_count=0; |
mridup | 0:dc55f40eb04f | 120 | uint32_t chunk_size; |
mridup | 0:dc55f40eb04f | 121 | uint32_t message_size; |
mridup | 0:dc55f40eb04f | 122 | uint32_t WIND55_count=0; |
mridup | 0:dc55f40eb04f | 123 | volatile uint32_t WIND64_count=0; |
mridup | 0:dc55f40eb04f | 124 | uint8_t user_scan_number; |
mridup | 0:dc55f40eb04f | 125 | uint32_t pop_queue_length; |
mridup | 0:dc55f40eb04f | 126 | uint32_t pop_buffer_size=0; |
mridup | 0:dc55f40eb04f | 127 | uint32_t process_buffer_index = 5; |
mridup | 0:dc55f40eb04f | 128 | uint32_t epoch_time = 0; |
mridup | 0:dc55f40eb04f | 129 | |
mridup | 0:dc55f40eb04f | 130 | volatile WiFi_AT_CMD_Response_t WiFi_Module_State; |
mridup | 0:dc55f40eb04f | 131 | |
mridup | 0:dc55f40eb04f | 132 | uint8_t *WiFi_Scan_Buffer; |
mridup | 0:dc55f40eb04f | 133 | uint8_t * curr_hostname; |
mridup | 0:dc55f40eb04f | 134 | uint8_t * curr_path; |
mridup | 0:dc55f40eb04f | 135 | uint8_t * curr_pURL; |
mridup | 0:dc55f40eb04f | 136 | uint8_t * curr_protocol; |
mridup | 0:dc55f40eb04f | 137 | uint32_t curr_port_number; |
mridup | 0:dc55f40eb04f | 138 | char * curr_data; |
mridup | 0:dc55f40eb04f | 139 | uint8_t curr_sockID; |
mridup | 0:dc55f40eb04f | 140 | uint8_t * curr_filename; |
mridup | 0:dc55f40eb04f | 141 | uint16_t curr_DataLength; |
mridup | 0:dc55f40eb04f | 142 | uint16_t sock_server_write_datalength; |
mridup | 0:dc55f40eb04f | 143 | char *sock_server_write_pdata; |
mridup | 0:dc55f40eb04f | 144 | |
mridup | 0:dc55f40eb04f | 145 | uint8_t socket_closed_id_callback; |
mridup | 0:dc55f40eb04f | 146 | uint8_t remote_socket_closed_id; |
mridup | 0:dc55f40eb04f | 147 | uint8_t client_socket_close_id; |
mridup | 0:dc55f40eb04f | 148 | volatile uint8_t wifi_ready = WIFI_FALSE;//Set once if wifi is ready for first time |
mridup | 0:dc55f40eb04f | 149 | volatile uint8_t wifi_connected = WIFI_FALSE;//Set once if wifi is connected for first time |
mridup | 0:dc55f40eb04f | 150 | volatile uint8_t wifi_client_connected = 0;//Set once if client is connected |
mridup | 0:dc55f40eb04f | 151 | volatile uint8_t wifi_client_disconnected = 0;//Set once if client is dis-connected |
mridup | 0:dc55f40eb04f | 152 | uint8_t gpio_value, gpio_direc, get_cfg_value[64]; |
mridup | 0:dc55f40eb04f | 153 | WiFi_Status_t user_error_code = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 154 | |
mridup | 0:dc55f40eb04f | 155 | uint8_t no_of_open_client_sockets = 0; |
mridup | 0:dc55f40eb04f | 156 | wifi_bool open_sockets[8]; //Max open sockets allowed is 8. Each array element depicts one socket (true=open, false=closed) |
mridup | 0:dc55f40eb04f | 157 | uint8_t client_MAC_address[17];//current client MAC address store |
mridup | 0:dc55f40eb04f | 158 | |
mridup | 0:dc55f40eb04f | 159 | uint8_t enable_uart_byte_data_receive=1; |
mridup | 0:dc55f40eb04f | 160 | uint8_t uart_data_receive_ready=1; |
mridup | 0:dc55f40eb04f | 161 | |
mridup | 0:dc55f40eb04f | 162 | WiFi_Status_t AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 163 | uint32_t sleep_count = 0; |
mridup | 0:dc55f40eb04f | 164 | uint32_t standby_time = 0; |
mridup | 0:dc55f40eb04f | 165 | uint8_t scanned_ssids = 0; |
mridup | 0:dc55f40eb04f | 166 | char * prefetch_str; |
mridup | 0:dc55f40eb04f | 167 | |
mridup | 0:dc55f40eb04f | 168 | #if defined (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO) |
mridup | 0:dc55f40eb04f | 169 | uint8_t WiFi_AT_Cmd_Buff[2048]; |
mridup | 0:dc55f40eb04f | 170 | #else |
mridup | 0:dc55f40eb04f | 171 | uint8_t WiFi_AT_Cmd_Buff[1024]; |
mridup | 0:dc55f40eb04f | 172 | #endif |
mridup | 0:dc55f40eb04f | 173 | |
mridup | 0:dc55f40eb04f | 174 | #ifdef USART_PRINT_MSG |
mridup | 0:dc55f40eb04f | 175 | #define printf(arg) {sprintf((char*)print_msg_buff,arg); \ |
mridup | 0:dc55f40eb04f | 176 | HAL_UART_Transmit(&UartMsgHandle, (uint8_t*)print_msg_buff, strlen(print_msg_buff), 1000);} |
mridup | 0:dc55f40eb04f | 177 | #endif |
mridup | 0:dc55f40eb04f | 178 | |
mridup | 0:dc55f40eb04f | 179 | void * spwf_dev_; |
mridup | 0:dc55f40eb04f | 180 | |
mridup | 0:dc55f40eb04f | 181 | extern void callSpwfSADevice_debug(void* object, const char * string); |
mridup | 0:dc55f40eb04f | 182 | extern void callSpwfSADevice_attach(wifi_bool attach); |
mridup | 0:dc55f40eb04f | 183 | |
mridup | 0:dc55f40eb04f | 184 | #if defined (__CC_ARM) |
mridup | 0:dc55f40eb04f | 185 | size_t strnlen (const char* s, size_t maxlen); |
mridup | 0:dc55f40eb04f | 186 | |
mridup | 0:dc55f40eb04f | 187 | size_t strnlen (const char* s, size_t maxlen) |
mridup | 0:dc55f40eb04f | 188 | { |
mridup | 0:dc55f40eb04f | 189 | size_t len = 0; |
mridup | 0:dc55f40eb04f | 190 | |
mridup | 0:dc55f40eb04f | 191 | while ((len <= maxlen) && (*s)) |
mridup | 0:dc55f40eb04f | 192 | { |
mridup | 0:dc55f40eb04f | 193 | s++; |
mridup | 0:dc55f40eb04f | 194 | len++; |
mridup | 0:dc55f40eb04f | 195 | } |
mridup | 0:dc55f40eb04f | 196 | |
mridup | 0:dc55f40eb04f | 197 | return len; |
mridup | 0:dc55f40eb04f | 198 | } |
mridup | 0:dc55f40eb04f | 199 | #endif |
mridup | 0:dc55f40eb04f | 200 | |
mridup | 0:dc55f40eb04f | 201 | event_s_TypeDef event_s; |
mridup | 0:dc55f40eb04f | 202 | event_s_TypeDef * event_pop_s; |
mridup | 0:dc55f40eb04f | 203 | |
mridup | 0:dc55f40eb04f | 204 | // [DLI] |
mridup | 0:dc55f40eb04f | 205 | #ifdef WIFI_USE_VCOM |
mridup | 0:dc55f40eb04f | 206 | |
mridup | 0:dc55f40eb04f | 207 | uint8_t console_listen_char[1]; |
mridup | 0:dc55f40eb04f | 208 | uint8_t console_input_char[1]; |
mridup | 0:dc55f40eb04f | 209 | uint8_t console_send_char[1]; |
mridup | 0:dc55f40eb04f | 210 | uint8_t console_echo_char[1]; |
mridup | 0:dc55f40eb04f | 211 | uint8_t console_send_ready = 0; |
mridup | 0:dc55f40eb04f | 212 | uint8_t console_echo_ready = 1; |
mridup | 0:dc55f40eb04f | 213 | uint8_t console_push_ready = 0; |
mridup | 0:dc55f40eb04f | 214 | |
mridup | 0:dc55f40eb04f | 215 | // Virtual-COM UART |
mridup | 0:dc55f40eb04f | 216 | void console_input() { |
mridup | 0:dc55f40eb04f | 217 | //HAL_UART_Receive_IT(&UartMsgHandle, (uint8_t *)console_input_char, 1); |
mridup | 0:dc55f40eb04f | 218 | } |
mridup | 0:dc55f40eb04f | 219 | |
mridup | 0:dc55f40eb04f | 220 | void wifi_vcom() { |
mridup | 0:dc55f40eb04f | 221 | |
mridup | 0:dc55f40eb04f | 222 | uint8_t * temp; |
mridup | 0:dc55f40eb04f | 223 | |
mridup | 0:dc55f40eb04f | 224 | if (console_push_ready == 1) { |
mridup | 0:dc55f40eb04f | 225 | push_buffer(&big_buff, uart_byte); |
mridup | 0:dc55f40eb04f | 226 | console_push_ready = 0; |
mridup | 0:dc55f40eb04f | 227 | //HAL_UART_Receive_IT(&UartWiFiHandle, (uint8_t *)uart_byte, 1); |
mridup | 0:dc55f40eb04f | 228 | } |
mridup | 0:dc55f40eb04f | 229 | if(console_echo_ready == 0) { |
mridup | 0:dc55f40eb04f | 230 | temp = pop_buffer_queue(&big_buff); |
mridup | 0:dc55f40eb04f | 231 | if(temp != NULL) { |
mridup | 0:dc55f40eb04f | 232 | console_echo_ready = 1; |
mridup | 0:dc55f40eb04f | 233 | //HAL_UART_Transmit_IT(&UartMsgHandle, temp, 1); |
mridup | 0:dc55f40eb04f | 234 | } |
mridup | 0:dc55f40eb04f | 235 | } |
mridup | 0:dc55f40eb04f | 236 | } |
mridup | 0:dc55f40eb04f | 237 | |
mridup | 0:dc55f40eb04f | 238 | #endif |
mridup | 0:dc55f40eb04f | 239 | |
mridup | 0:dc55f40eb04f | 240 | /** |
mridup | 0:dc55f40eb04f | 241 | * @} |
mridup | 0:dc55f40eb04f | 242 | */ |
mridup | 0:dc55f40eb04f | 243 | |
mridup | 0:dc55f40eb04f | 244 | /** @defgroup NUCLEO_WIFI_MODULE_Private_Functions |
mridup | 0:dc55f40eb04f | 245 | * @{ |
mridup | 0:dc55f40eb04f | 246 | */ |
mridup | 0:dc55f40eb04f | 247 | |
mridup | 0:dc55f40eb04f | 248 | /** |
mridup | 0:dc55f40eb04f | 249 | *Changed/introduced functions for MBED implementation: |
mridup | 0:dc55f40eb04f | 250 | |
mridup | 0:dc55f40eb04f | 251 | - void Wifi_TIM_Handler(void); - new fn |
mridup | 0:dc55f40eb04f | 252 | - void Rx_irq_handler(void); - new fn - in place of HAL_UART_RxCpltCallback |
mridup | 0:dc55f40eb04f | 253 | - Receive_Data(); - modified fn |
mridup | 0:dc55f40eb04f | 254 | - void wifi_reset(void) - modified fn |
mridup | 0:dc55f40eb04f | 255 | - void PowerUp_WiFi_Module(void) - modified fn |
mridup | 0:dc55f40eb04f | 256 | - void RX_EXTI_Isr(uint16_t GPIO_Pin) - removed fn |
mridup | 0:dc55f40eb04f | 257 | - void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandleArg) - removed fn |
mridup | 0:dc55f40eb04f | 258 | - void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandleArg) - removed fn |
mridup | 0:dc55f40eb04f | 259 | - void HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle) - removed fn |
mridup | 0:dc55f40eb04f | 260 | - WiFi_Status_t USART_Transmit_AT_Cmd(uint16_t size)- modified fn |
mridup | 0:dc55f40eb04f | 261 | */ |
mridup | 0:dc55f40eb04f | 262 | |
mridup | 0:dc55f40eb04f | 263 | |
mridup | 0:dc55f40eb04f | 264 | |
mridup | 0:dc55f40eb04f | 265 | /** |
mridup | 0:dc55f40eb04f | 266 | * @brief WiFi_Module_Init |
mridup | 0:dc55f40eb04f | 267 | * Initialize wifi module |
mridup | 0:dc55f40eb04f | 268 | * @param None |
mridup | 0:dc55f40eb04f | 269 | * @retval None |
mridup | 0:dc55f40eb04f | 270 | */ |
mridup | 0:dc55f40eb04f | 271 | void WiFi_Module_Init(void) |
mridup | 0:dc55f40eb04f | 272 | { |
mridup | 0:dc55f40eb04f | 273 | #ifdef WIFI_USE_VCOM |
mridup | 0:dc55f40eb04f | 274 | console_input(); |
mridup | 0:dc55f40eb04f | 275 | #else |
mridup | 0:dc55f40eb04f | 276 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 277 | #endif |
mridup | 0:dc55f40eb04f | 278 | |
mridup | 0:dc55f40eb04f | 279 | initialize_status_flags(); |
mridup | 0:dc55f40eb04f | 280 | init(&big_buff, RINGBUF_SIZE);//Init the ring buffer |
mridup | 0:dc55f40eb04f | 281 | wifi_ready = 0; //reset to get user callback on HW started |
mridup | 0:dc55f40eb04f | 282 | wifi_connected = 0; //reset to get user callback on WiFi UP |
mridup | 0:dc55f40eb04f | 283 | Receive_Data(); |
mridup | 0:dc55f40eb04f | 284 | |
mridup | 0:dc55f40eb04f | 285 | #ifdef USE_STM32L0XX_NUCLEO |
mridup | 0:dc55f40eb04f | 286 | event_init(&event_buff, 10); //max 15 events can be Q'ed (Event Buffer is of size 15) |
mridup | 0:dc55f40eb04f | 287 | #else |
mridup | 0:dc55f40eb04f | 288 | event_init(&event_buff, 50); //max 50 events can be Q'ed (Event Buffer is of size 50) |
mridup | 0:dc55f40eb04f | 289 | #endif |
mridup | 0:dc55f40eb04f | 290 | |
mridup | 0:dc55f40eb04f | 291 | #ifndef WIFI_USE_VCOM |
mridup | 0:dc55f40eb04f | 292 | Start_Timer(); |
mridup | 0:dc55f40eb04f | 293 | memset(open_sockets,0x00, 8); //init the open socket array |
mridup | 0:dc55f40eb04f | 294 | |
mridup | 0:dc55f40eb04f | 295 | #endif |
mridup | 0:dc55f40eb04f | 296 | } |
mridup | 0:dc55f40eb04f | 297 | |
mridup | 0:dc55f40eb04f | 298 | /** |
mridup | 0:dc55f40eb04f | 299 | * @brief initialize_status_flags |
mridup | 0:dc55f40eb04f | 300 | * Default Wifi status values |
mridup | 0:dc55f40eb04f | 301 | * @param None |
mridup | 0:dc55f40eb04f | 302 | * @retval None |
mridup | 0:dc55f40eb04f | 303 | */ |
mridup | 0:dc55f40eb04f | 304 | void initialize_status_flags() |
mridup | 0:dc55f40eb04f | 305 | { |
mridup | 0:dc55f40eb04f | 306 | status_flag.Single_Digit_Indication = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 307 | status_flag.WiFi_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 308 | status_flag.http_req_pending = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 309 | status_flag.WiFi_Configuration_Done = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 310 | status_flag.Timer_Running = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 311 | status_flag.resume_receive_data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 312 | status_flag.enable_dequeue = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 313 | status_flag.stop_event_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 314 | status_flag.Standby_Timer_Running = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 315 | status_flag.trigger_wakeup_callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 316 | status_flag.Deep_Sleep_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 317 | status_flag.Standby_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 318 | status_flag.Low_Power_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 319 | status_flag.command_mode=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 320 | status_flag.data_mode=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 321 | status_flag.Scan_Ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 322 | status_flag.AT_Cmd_Ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 323 | status_flag.AT_Cmd_Processing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 324 | status_flag.Uartx_Rx_Processing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 325 | status_flag.Client_Connected = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 326 | status_flag.Client_Disconnected = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 327 | status_flag.switch_by_default_to_command_mode = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 328 | status_flag.start_sock_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 329 | status_flag.enable_receive_data_chunk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 330 | status_flag.data_pending_sockD=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 331 | status_flag.enable_sock_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 332 | status_flag.enable_query = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 333 | status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 334 | status_flag.enable_fw_update_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 335 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 336 | status_flag.Q_Contains_Data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 337 | status_flag.enable_receive_http_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 338 | status_flag.enable_receive_file_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 339 | status_flag.enable_receive_wifi_scan_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 340 | status_flag.prevent_push_OK_event = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 341 | status_flag.client_socket_close_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 342 | status_flag.prevent_push_WIFI_event = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 343 | status_flag.sock_read_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 344 | status_flag.enable_client_socket_write = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 345 | status_flag.event_deQ_x_wind64 = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 346 | status_flag.do_not_reset_push_WIFI_event = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 347 | status_flag.message_pending = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 348 | status_flag.Pending_SockON_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 349 | status_flag.Pending_SockD_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 350 | status_flag.SockON_Server_Closed_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 351 | status_flag.Client_Socket_Close_Cmd = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 352 | status_flag.standby_resume_callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 353 | status_flag.HTTP_Data_available = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 354 | status_flag.FILE_Data_available = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 355 | status_flag.AT_Response_Received = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 356 | status_flag.Deep_Sleep_Timer = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 357 | status_flag.Deep_Sleep_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 358 | } |
mridup | 0:dc55f40eb04f | 359 | |
mridup | 0:dc55f40eb04f | 360 | |
mridup | 0:dc55f40eb04f | 361 | /** |
mridup | 0:dc55f40eb04f | 362 | * @brief Period elapsed callback in non blocking mode |
mridup | 0:dc55f40eb04f | 363 | * This timer is used for calling back User registered functions with information |
mridup | 0:dc55f40eb04f | 364 | * @param htim : TIM handle |
mridup | 0:dc55f40eb04f | 365 | * @retval None |
mridup | 0:dc55f40eb04f | 366 | */ |
mridup | 0:dc55f40eb04f | 367 | |
mridup | 0:dc55f40eb04f | 368 | void Wifi_TIM_Handler(void) |
mridup | 0:dc55f40eb04f | 369 | { |
mridup | 0:dc55f40eb04f | 370 | /********************************************************************** |
mridup | 0:dc55f40eb04f | 371 | * * |
mridup | 0:dc55f40eb04f | 372 | * Be careful not to make a blocking * |
mridup | 0:dc55f40eb04f | 373 | * call from this function, see * |
mridup | 0:dc55f40eb04f | 374 | * example Socket_Read() and Socket_Close() * |
mridup | 0:dc55f40eb04f | 375 | * * |
mridup | 0:dc55f40eb04f | 376 | **********************************************************************/ |
mridup | 0:dc55f40eb04f | 377 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 378 | |
mridup | 0:dc55f40eb04f | 379 | if(status_flag.stop_event_dequeue == WIFI_FALSE /*&& !status_flag.enable_receive_data_chunk*/) |
mridup | 0:dc55f40eb04f | 380 | { |
mridup | 0:dc55f40eb04f | 381 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 382 | event_pop_s = pop_eventbuffer_queue(&event_buff); |
mridup | 0:dc55f40eb04f | 383 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 384 | |
mridup | 0:dc55f40eb04f | 385 | if(event_pop_s!=NULL && event_pop_s->event_pop == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 386 | { |
mridup | 0:dc55f40eb04f | 387 | switch(event_pop_s->event) |
mridup | 0:dc55f40eb04f | 388 | { |
mridup | 0:dc55f40eb04f | 389 | case WIFI_WIND_EVENT: |
mridup | 0:dc55f40eb04f | 390 | Process_WiFi_Indication_Cmd(event_pop_s); |
mridup | 0:dc55f40eb04f | 391 | break; |
mridup | 0:dc55f40eb04f | 392 | |
mridup | 0:dc55f40eb04f | 393 | case WIFI_OK_EVENT: |
mridup | 0:dc55f40eb04f | 394 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 395 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 396 | if(status_flag.Set_AT_Cmd_Response_False == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 397 | { |
mridup | 0:dc55f40eb04f | 398 | status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 399 | status_flag.AT_Response_Received = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 400 | } |
mridup | 0:dc55f40eb04f | 401 | if(status_flag.enable_client_socket_write) //allows the OK received after socket client write to be processed |
mridup | 0:dc55f40eb04f | 402 | { |
mridup | 0:dc55f40eb04f | 403 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 404 | status_flag.enable_client_socket_write = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 405 | } |
mridup | 0:dc55f40eb04f | 406 | break; |
mridup | 0:dc55f40eb04f | 407 | |
mridup | 0:dc55f40eb04f | 408 | case WIFI_SOCK_ID_EVENT: |
mridup | 0:dc55f40eb04f | 409 | /*check ID and update SocketID array*/ |
mridup | 0:dc55f40eb04f | 410 | no_of_open_client_sockets++; |
mridup | 0:dc55f40eb04f | 411 | |
mridup | 0:dc55f40eb04f | 412 | if(no_of_open_client_sockets > 8) //Max number of clients is 8 |
mridup | 0:dc55f40eb04f | 413 | { |
mridup | 0:dc55f40eb04f | 414 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 415 | AT_RESPONSE = WiFi_NOT_SUPPORTED; |
mridup | 0:dc55f40eb04f | 416 | break; |
mridup | 0:dc55f40eb04f | 417 | } |
mridup | 0:dc55f40eb04f | 418 | |
mridup | 0:dc55f40eb04f | 419 | open_sockets[event_pop_s->socket_id] = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 420 | Socket_Open_ID = event_pop_s->socket_id; |
mridup | 0:dc55f40eb04f | 421 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 422 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 423 | break; |
mridup | 0:dc55f40eb04f | 424 | |
mridup | 0:dc55f40eb04f | 425 | case WIFI_HTTP_EVENT: |
mridup | 0:dc55f40eb04f | 426 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 427 | memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer |
mridup | 0:dc55f40eb04f | 428 | |
mridup | 0:dc55f40eb04f | 429 | if(curr_pURL) { |
mridup | 0:dc55f40eb04f | 430 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_HTTPPOST_REQUEST,curr_pURL); |
mridup | 0:dc55f40eb04f | 431 | } |
mridup | 0:dc55f40eb04f | 432 | else { |
mridup | 0:dc55f40eb04f | 433 | if(curr_port_number!=0) |
mridup | 0:dc55f40eb04f | 434 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.HTTPGET=%s,%s,%d\r",curr_hostname, curr_path, (int)curr_port_number); |
mridup | 0:dc55f40eb04f | 435 | else |
mridup | 0:dc55f40eb04f | 436 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.HTTPGET=%s,%s\r",curr_hostname, curr_path); |
mridup | 0:dc55f40eb04f | 437 | } |
mridup | 0:dc55f40eb04f | 438 | |
mridup | 0:dc55f40eb04f | 439 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 440 | if(status == WiFi_MODULE_SUCCESS) { |
mridup | 0:dc55f40eb04f | 441 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 442 | status_flag.stop_event_dequeue = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 443 | status_flag.http_req_pending = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 444 | } |
mridup | 0:dc55f40eb04f | 445 | else { |
mridup | 0:dc55f40eb04f | 446 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 447 | printf("\r\n ERROR IN HTTP \r\n"); |
mridup | 0:dc55f40eb04f | 448 | #endif |
mridup | 0:dc55f40eb04f | 449 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 450 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 451 | } |
mridup | 0:dc55f40eb04f | 452 | break; |
mridup | 0:dc55f40eb04f | 453 | |
mridup | 0:dc55f40eb04f | 454 | case WIFI_CLIENT_SOCKET_WRITE_EVENT: |
mridup | 0:dc55f40eb04f | 455 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 456 | /* AT+S.SOCKW=00,11<cr> */ |
mridup | 0:dc55f40eb04f | 457 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_WRITE,curr_sockID,curr_DataLength); |
mridup | 0:dc55f40eb04f | 458 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 459 | |
mridup | 0:dc55f40eb04f | 460 | if(status == WiFi_MODULE_SUCCESS) { |
mridup | 0:dc55f40eb04f | 461 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 462 | memcpy((char*)(char*)WiFi_AT_Cmd_Buff, (char*)curr_data,curr_DataLength); |
mridup | 0:dc55f40eb04f | 463 | WiFi_AT_Cmd_Buff[curr_DataLength]='\r'; |
mridup | 0:dc55f40eb04f | 464 | |
mridup | 0:dc55f40eb04f | 465 | status = USART_Transmit_AT_Cmd(curr_DataLength+2); |
mridup | 0:dc55f40eb04f | 466 | if(status == WiFi_MODULE_SUCCESS) { |
mridup | 0:dc55f40eb04f | 467 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 468 | } |
mridup | 0:dc55f40eb04f | 469 | else { |
mridup | 0:dc55f40eb04f | 470 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 471 | printf("\r\n ERROR IN SOCKET\r\n"); |
mridup | 0:dc55f40eb04f | 472 | #endif |
mridup | 0:dc55f40eb04f | 473 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 474 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 475 | } |
mridup | 0:dc55f40eb04f | 476 | } |
mridup | 0:dc55f40eb04f | 477 | else { |
mridup | 0:dc55f40eb04f | 478 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 479 | printf("\r\n ERROR In Socket\r\n"); |
mridup | 0:dc55f40eb04f | 480 | #endif |
mridup | 0:dc55f40eb04f | 481 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 482 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 483 | } |
mridup | 0:dc55f40eb04f | 484 | break; |
mridup | 0:dc55f40eb04f | 485 | |
mridup | 0:dc55f40eb04f | 486 | case WIFI_CLIENT_SOCKET_OPEN_EVENT: |
mridup | 5:c83ffd44f40a | 487 | |
mridup | 5:c83ffd44f40a | 488 | if(!open_sockets[event_pop_s->socket_id])//make sure socket is closed |
mridup | 0:dc55f40eb04f | 489 | { |
mridup | 5:c83ffd44f40a | 490 | Reset_AT_CMD_Buffer(); |
mridup | 5:c83ffd44f40a | 491 | |
mridup | 5:c83ffd44f40a | 492 | /* AT+S.SOCKON = myserver,1234,t <cr> */ |
mridup | 5:c83ffd44f40a | 493 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_OPEN,curr_hostname,(int)curr_port_number,curr_protocol); |
mridup | 5:c83ffd44f40a | 494 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 5:c83ffd44f40a | 495 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 5:c83ffd44f40a | 496 | { |
mridup | 5:c83ffd44f40a | 497 | #if DEBUG_PRINT |
mridup | 5:c83ffd44f40a | 498 | printf("\r\n ERROR During Socket Open \r\n"); |
mridup | 5:c83ffd44f40a | 499 | #endif |
mridup | 5:c83ffd44f40a | 500 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 5:c83ffd44f40a | 501 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 5:c83ffd44f40a | 502 | } |
mridup | 0:dc55f40eb04f | 503 | } |
mridup | 0:dc55f40eb04f | 504 | break; |
mridup | 0:dc55f40eb04f | 505 | |
mridup | 0:dc55f40eb04f | 506 | case WIFI_CLIENT_SOCKET_CLOSE_EVENT: |
mridup | 5:c83ffd44f40a | 507 | |
mridup | 5:c83ffd44f40a | 508 | if(open_sockets[event_pop_s->socket_id])//make sure socket is open |
mridup | 0:dc55f40eb04f | 509 | { |
mridup | 5:c83ffd44f40a | 510 | Reset_AT_CMD_Buffer(); |
mridup | 5:c83ffd44f40a | 511 | |
mridup | 5:c83ffd44f40a | 512 | /* AT+S.SOCKC=00<cr> */ |
mridup | 5:c83ffd44f40a | 513 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SOCKET_CLOSE,event_pop_s->socket_id); |
mridup | 5:c83ffd44f40a | 514 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 5:c83ffd44f40a | 515 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 5:c83ffd44f40a | 516 | { |
mridup | 5:c83ffd44f40a | 517 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 5:c83ffd44f40a | 518 | status_flag.prevent_push_OK_event = WIFI_TRUE; //prevent the OK received after socket close command to be Q'ed |
mridup | 5:c83ffd44f40a | 519 | status_flag.stop_event_dequeue = WIFI_TRUE; |
mridup | 5:c83ffd44f40a | 520 | remote_socket_closed_id = event_pop_s->socket_id; |
mridup | 5:c83ffd44f40a | 521 | status_flag.client_socket_close_ongoing = WIFI_TRUE; //used for making changes in the value of open_sockets[sock_id] if no error is returned |
mridup | 5:c83ffd44f40a | 522 | // status_flag.SockON_Server_Closed_Callback = WIFI_TRUE; |
mridup | 5:c83ffd44f40a | 523 | } |
mridup | 5:c83ffd44f40a | 524 | else |
mridup | 5:c83ffd44f40a | 525 | { |
mridup | 5:c83ffd44f40a | 526 | #if DEBUG_PRINT |
mridup | 5:c83ffd44f40a | 527 | printf("\r\n ERROR During Socket Close \r\n"); |
mridup | 5:c83ffd44f40a | 528 | #endif |
mridup | 5:c83ffd44f40a | 529 | } |
mridup | 0:dc55f40eb04f | 530 | } |
mridup | 0:dc55f40eb04f | 531 | break; |
mridup | 0:dc55f40eb04f | 532 | |
mridup | 0:dc55f40eb04f | 533 | |
mridup | 0:dc55f40eb04f | 534 | case WIFI_FILE_EVENT: |
mridup | 0:dc55f40eb04f | 535 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 536 | |
mridup | 0:dc55f40eb04f | 537 | if(curr_filename == NULL) |
mridup | 0:dc55f40eb04f | 538 | { |
mridup | 0:dc55f40eb04f | 539 | /* AT+S.FSL */ |
mridup | 0:dc55f40eb04f | 540 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_DISPLAY_FILE_NAME); |
mridup | 0:dc55f40eb04f | 541 | } |
mridup | 0:dc55f40eb04f | 542 | else if(curr_hostname == NULL) |
mridup | 0:dc55f40eb04f | 543 | { |
mridup | 0:dc55f40eb04f | 544 | /* AT+S.FSP=/index.html */ |
mridup | 0:dc55f40eb04f | 545 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_DISPLAY_FILE_CONTENT,curr_filename); |
mridup | 0:dc55f40eb04f | 546 | } |
mridup | 0:dc55f40eb04f | 547 | else |
mridup | 0:dc55f40eb04f | 548 | { |
mridup | 0:dc55f40eb04f | 549 | /* AT+S.HTTPDFSUPDATE=%s,/outfile.img */ |
mridup | 0:dc55f40eb04f | 550 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_DOWNLOAD_IMAGE_FILE,curr_hostname,curr_filename,(int)curr_port_number); |
mridup | 0:dc55f40eb04f | 551 | } |
mridup | 0:dc55f40eb04f | 552 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 553 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 554 | { |
mridup | 0:dc55f40eb04f | 555 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 556 | status_flag.enable_receive_http_response = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 557 | status_flag.enable_receive_data_chunk = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 558 | status_flag.enable_receive_file_response = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 559 | } |
mridup | 0:dc55f40eb04f | 560 | else { |
mridup | 0:dc55f40eb04f | 561 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 562 | printf("\r\n ERROR in FILE \r\n"); |
mridup | 0:dc55f40eb04f | 563 | #endif |
mridup | 0:dc55f40eb04f | 564 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 565 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 566 | } |
mridup | 0:dc55f40eb04f | 567 | break; |
mridup | 0:dc55f40eb04f | 568 | |
mridup | 0:dc55f40eb04f | 569 | case WIFI_FW_UPDATE_EVENT: |
mridup | 0:dc55f40eb04f | 570 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 571 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.FWUPDATE=%s,/%s,%d\r",curr_hostname,curr_filename,(int)curr_port_number); |
mridup | 0:dc55f40eb04f | 572 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 573 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 574 | { |
mridup | 0:dc55f40eb04f | 575 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 576 | status_flag.enable_fw_update_read = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 577 | status_flag.enable_receive_data_chunk = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 578 | } |
mridup | 0:dc55f40eb04f | 579 | else |
mridup | 0:dc55f40eb04f | 580 | { |
mridup | 0:dc55f40eb04f | 581 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 582 | printf("\r\n ERROR in Firmware \r\n"); |
mridup | 0:dc55f40eb04f | 583 | #endif |
mridup | 0:dc55f40eb04f | 584 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 585 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 586 | } |
mridup | 0:dc55f40eb04f | 587 | break; |
mridup | 0:dc55f40eb04f | 588 | |
mridup | 0:dc55f40eb04f | 589 | case WIFI_ERROR_EVENT: |
mridup | 0:dc55f40eb04f | 590 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 591 | printf("\r\n ERROR!\r\n"); |
mridup | 0:dc55f40eb04f | 592 | #endif |
mridup | 0:dc55f40eb04f | 593 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 594 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 595 | break; |
mridup | 0:dc55f40eb04f | 596 | |
mridup | 0:dc55f40eb04f | 597 | case WIFI_GCFG_EVENT: |
mridup | 0:dc55f40eb04f | 598 | case WIFI_GPIO_EVENT: |
mridup | 0:dc55f40eb04f | 599 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 600 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 601 | break; |
mridup | 0:dc55f40eb04f | 602 | |
mridup | 0:dc55f40eb04f | 603 | case WIFI_STANDBY_CONFIG_EVENT: |
mridup | 0:dc55f40eb04f | 604 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 605 | printf("\r\nGoing into standby..\r\n"); |
mridup | 0:dc55f40eb04f | 606 | #endif |
mridup | 0:dc55f40eb04f | 607 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 608 | break; |
mridup | 0:dc55f40eb04f | 609 | |
mridup | 0:dc55f40eb04f | 610 | case WIFI_RESUME_CONFIG_EVENT: |
mridup | 0:dc55f40eb04f | 611 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 612 | printf("\r\nResuming from standby..\r\n"); |
mridup | 0:dc55f40eb04f | 613 | #endif |
mridup | 0:dc55f40eb04f | 614 | status_flag.AT_Response_Received = WIFI_TRUE;//let main run-on |
mridup | 0:dc55f40eb04f | 615 | break; |
mridup | 0:dc55f40eb04f | 616 | |
mridup | 0:dc55f40eb04f | 617 | case WIFI_NO_EVENT: |
mridup | 0:dc55f40eb04f | 618 | break; |
mridup | 0:dc55f40eb04f | 619 | } |
mridup | 0:dc55f40eb04f | 620 | } |
mridup | 0:dc55f40eb04f | 621 | } |
mridup | 0:dc55f40eb04f | 622 | /* If data is pending on client socket SOCKON, make read requests*/ |
mridup | 0:dc55f40eb04f | 623 | if(status_flag.start_sock_read == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 624 | { |
mridup | 0:dc55f40eb04f | 625 | //flush_buffer_queue(&big_buff); |
mridup | 0:dc55f40eb04f | 626 | Socket_Read(Socket_Data_Length); |
mridup | 0:dc55f40eb04f | 627 | status_flag.start_sock_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 628 | } |
mridup | 0:dc55f40eb04f | 629 | |
mridup | 0:dc55f40eb04f | 630 | /* Call Query, after notification for TLS is received */ |
mridup | 0:dc55f40eb04f | 631 | else if(status_flag.enable_query == WIFI_TRUE && status_flag.enable_dequeue == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 632 | { |
mridup | 0:dc55f40eb04f | 633 | //@TBD: Flushing the buffer may be detrimental if we have genuine follow on WIND55? |
mridup | 0:dc55f40eb04f | 634 | //flush_buffer_queue(&big_buff); //Flush the buffer to remove WIND:55 in pipeline (This maybe a problem) |
mridup | 0:dc55f40eb04f | 635 | Socket_Pending_Data(); |
mridup | 0:dc55f40eb04f | 636 | status_flag.enable_query = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 637 | } |
mridup | 0:dc55f40eb04f | 638 | |
mridup | 0:dc55f40eb04f | 639 | else if(status_flag.Pending_SockON_Callback==WIFI_TRUE)//for client socket |
mridup | 0:dc55f40eb04f | 640 | { |
mridup | 0:dc55f40eb04f | 641 | //Now callback to user with user_data pointer <UserDataBuff> |
mridup | 0:dc55f40eb04f | 642 | ind_wifi_socket_data_received(sockon_id_user, (uint8_t *)UserDataBuff, message_size, chunk_size); |
mridup | 0:dc55f40eb04f | 643 | memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer |
mridup | 0:dc55f40eb04f | 644 | Resume_Dequeue(); |
mridup | 0:dc55f40eb04f | 645 | status_flag.Pending_SockON_Callback=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 646 | } |
mridup | 0:dc55f40eb04f | 647 | |
mridup | 0:dc55f40eb04f | 648 | else if(status_flag.Pending_SockD_Callback == WIFI_TRUE)//for server socket |
mridup | 0:dc55f40eb04f | 649 | { |
mridup | 0:dc55f40eb04f | 650 | //if(status_flag.command_mode)//if command_mode is achieved then callback else loop in this state |
mridup | 0:dc55f40eb04f | 651 | { |
mridup | 0:dc55f40eb04f | 652 | //Now callback to user with user_data pointer <UserDataBuff> |
mridup | 0:dc55f40eb04f | 653 | ind_wifi_socket_data_received(9, (uint8_t *)UserDataBuff, message_size, chunk_size); |
mridup | 0:dc55f40eb04f | 654 | memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer |
mridup | 0:dc55f40eb04f | 655 | Resume_Dequeue(); |
mridup | 0:dc55f40eb04f | 656 | status_flag.Pending_SockD_Callback=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 657 | } |
mridup | 0:dc55f40eb04f | 658 | } |
mridup | 0:dc55f40eb04f | 659 | |
mridup | 0:dc55f40eb04f | 660 | else if(status_flag.Client_Socket_Close_Cmd==WIFI_TRUE)//for client socket |
mridup | 0:dc55f40eb04f | 661 | { |
mridup | 0:dc55f40eb04f | 662 | //Close the socket |
mridup | 0:dc55f40eb04f | 663 | //Change State to AT_Cmd_Response before calling socket_close() |
mridup | 0:dc55f40eb04f | 664 | WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 665 | wifi_socket_client_close(client_socket_close_id); |
mridup | 0:dc55f40eb04f | 666 | status_flag.Client_Socket_Close_Cmd = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 667 | // status_flag.SockON_Server_Closed_Callback = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 668 | } |
mridup | 0:dc55f40eb04f | 669 | |
mridup | 0:dc55f40eb04f | 670 | else if(status_flag.SockON_Server_Closed_Callback==WIFI_TRUE)//for client socket |
mridup | 0:dc55f40eb04f | 671 | { |
mridup | 0:dc55f40eb04f | 672 | //callback the user |
mridup | 0:dc55f40eb04f | 673 | ind_wifi_socket_client_remote_server_closed(&socket_closed_id_callback); |
mridup | 0:dc55f40eb04f | 674 | status_flag.SockON_Server_Closed_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 675 | } |
mridup | 0:dc55f40eb04f | 676 | |
mridup | 0:dc55f40eb04f | 677 | else if(status_flag.HTTP_Data_available == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 678 | { |
mridup | 0:dc55f40eb04f | 679 | ind_wifi_http_data_available((uint8_t *)UserDataBuff,UserDataBuff_index); |
mridup | 0:dc55f40eb04f | 680 | memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer |
mridup | 0:dc55f40eb04f | 681 | // memcpy(&UserDataBuff, &HTTP_Runway_Buff, 6); |
mridup | 0:dc55f40eb04f | 682 | // memset(HTTP_Runway_Buff, 0x00, 6); |
mridup | 0:dc55f40eb04f | 683 | Resume_Dequeue(); |
mridup | 0:dc55f40eb04f | 684 | status_flag.HTTP_Data_available=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 685 | } |
mridup | 0:dc55f40eb04f | 686 | |
mridup | 0:dc55f40eb04f | 687 | else if (status_flag.FILE_Data_available == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 688 | { |
mridup | 0:dc55f40eb04f | 689 | ind_wifi_file_data_available((uint8_t *) UserDataBuff); |
mridup | 0:dc55f40eb04f | 690 | memset(UserDataBuff, 0x00, MAX_BUFFER_GLOBAL);//Flush the buffer |
mridup | 0:dc55f40eb04f | 691 | Resume_Dequeue(); |
mridup | 0:dc55f40eb04f | 692 | status_flag.FILE_Data_available = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 693 | } |
mridup | 0:dc55f40eb04f | 694 | else if(status_flag.Client_Connected == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 695 | { |
mridup | 0:dc55f40eb04f | 696 | ind_socket_server_client_joined(); |
mridup | 0:dc55f40eb04f | 697 | status_flag.Client_Connected = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 698 | } |
mridup | 0:dc55f40eb04f | 699 | |
mridup | 0:dc55f40eb04f | 700 | else if(status_flag.Client_Disconnected == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 701 | { |
mridup | 0:dc55f40eb04f | 702 | ind_socket_server_client_left(); |
mridup | 0:dc55f40eb04f | 703 | status_flag.Client_Disconnected = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 704 | } |
mridup | 0:dc55f40eb04f | 705 | |
mridup | 0:dc55f40eb04f | 706 | //Make callbacks from here to user for pending events |
mridup | 0:dc55f40eb04f | 707 | |
mridup | 0:dc55f40eb04f | 708 | if(WiFi_WIND_State.WiFiHWStarted==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 709 | { |
mridup | 0:dc55f40eb04f | 710 | if(wifi_ready == 2)//Twice reset for User Callback |
mridup | 0:dc55f40eb04f | 711 | { |
mridup | 0:dc55f40eb04f | 712 | wifi_ready++; |
mridup | 0:dc55f40eb04f | 713 | ind_wifi_on();//Call this once only...This if for wifi_on (instead of console active |
mridup | 0:dc55f40eb04f | 714 | } |
mridup | 0:dc55f40eb04f | 715 | } |
mridup | 0:dc55f40eb04f | 716 | |
mridup | 0:dc55f40eb04f | 717 | if(WiFi_WIND_State.WiFiUp == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 718 | { |
mridup | 0:dc55f40eb04f | 719 | if(wifi_connected == 0) |
mridup | 0:dc55f40eb04f | 720 | { |
mridup | 0:dc55f40eb04f | 721 | wifi_connected = 1; |
mridup | 0:dc55f40eb04f | 722 | ind_wifi_connected();//wifi connected |
mridup | 0:dc55f40eb04f | 723 | } |
mridup | 0:dc55f40eb04f | 724 | WiFi_WIND_State.WiFiUp = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 725 | } |
mridup | 0:dc55f40eb04f | 726 | |
mridup | 0:dc55f40eb04f | 727 | else if(WiFi_WIND_State.WiFiStarted_MiniAPMode == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 728 | { |
mridup | 0:dc55f40eb04f | 729 | ind_wifi_ap_ready(); |
mridup | 0:dc55f40eb04f | 730 | WiFi_WIND_State.WiFiStarted_MiniAPMode = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 731 | } |
mridup | 0:dc55f40eb04f | 732 | |
mridup | 0:dc55f40eb04f | 733 | else if(WiFi_WIND_State.WiFiAPClientJoined == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 734 | { |
mridup | 0:dc55f40eb04f | 735 | ind_wifi_ap_client_joined(client_MAC_address); |
mridup | 0:dc55f40eb04f | 736 | WiFi_WIND_State.WiFiAPClientJoined = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 737 | } |
mridup | 0:dc55f40eb04f | 738 | |
mridup | 0:dc55f40eb04f | 739 | else if(WiFi_WIND_State.WiFiAPClientLeft == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 740 | { |
mridup | 0:dc55f40eb04f | 741 | ind_wifi_ap_client_left(client_MAC_address); |
mridup | 0:dc55f40eb04f | 742 | WiFi_WIND_State.WiFiAPClientLeft = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 743 | } |
mridup | 0:dc55f40eb04f | 744 | |
mridup | 0:dc55f40eb04f | 745 | else if(status_flag.Deep_Sleep_Callback == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 746 | { |
mridup | 0:dc55f40eb04f | 747 | ind_wifi_resuming(); |
mridup | 0:dc55f40eb04f | 748 | status_flag.Deep_Sleep_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 749 | } |
mridup | 0:dc55f40eb04f | 750 | |
mridup | 0:dc55f40eb04f | 751 | else if(status_flag.standby_resume_callback == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 752 | { |
mridup | 0:dc55f40eb04f | 753 | ind_wifi_resuming(); |
mridup | 0:dc55f40eb04f | 754 | status_flag.standby_resume_callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 755 | } |
mridup | 0:dc55f40eb04f | 756 | |
mridup | 0:dc55f40eb04f | 757 | else if(WiFi_WIND_State.WiFiHWFailure==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 758 | { |
mridup | 0:dc55f40eb04f | 759 | WiFi_WIND_State.WiFiHWFailure=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 760 | ind_wifi_error(WiFi_HW_FAILURE_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 761 | } |
mridup | 0:dc55f40eb04f | 762 | |
mridup | 0:dc55f40eb04f | 763 | else if(WiFi_WIND_State.HardFault==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 764 | { |
mridup | 0:dc55f40eb04f | 765 | WiFi_WIND_State.HardFault=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 766 | ind_wifi_error(WiFi_HARD_FAULT_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 767 | } |
mridup | 0:dc55f40eb04f | 768 | |
mridup | 0:dc55f40eb04f | 769 | else if(WiFi_WIND_State.StackOverflow==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 770 | { |
mridup | 0:dc55f40eb04f | 771 | WiFi_WIND_State.StackOverflow=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 772 | ind_wifi_error(WiFi_STACK_OVERFLOW_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 773 | } |
mridup | 0:dc55f40eb04f | 774 | |
mridup | 0:dc55f40eb04f | 775 | else if(WiFi_WIND_State.MallocFailed==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 776 | { |
mridup | 0:dc55f40eb04f | 777 | WiFi_WIND_State.MallocFailed=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 778 | ind_wifi_error(WiFi_MALLOC_FAILED_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 779 | } |
mridup | 0:dc55f40eb04f | 780 | |
mridup | 0:dc55f40eb04f | 781 | else if(WiFi_WIND_State.InitFailure==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 782 | { |
mridup | 0:dc55f40eb04f | 783 | WiFi_WIND_State.InitFailure=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 784 | ind_wifi_error(WiFi_INIT_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 785 | } |
mridup | 0:dc55f40eb04f | 786 | |
mridup | 0:dc55f40eb04f | 787 | else if(WiFi_WIND_State.StartFailed==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 788 | { |
mridup | 0:dc55f40eb04f | 789 | WiFi_WIND_State.StartFailed=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 790 | ind_wifi_error(WiFi_START_FAILED_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 791 | } |
mridup | 0:dc55f40eb04f | 792 | |
mridup | 0:dc55f40eb04f | 793 | else if(WiFi_WIND_State.WiFiException==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 794 | { |
mridup | 0:dc55f40eb04f | 795 | WiFi_WIND_State.WiFiException=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 796 | ind_wifi_error(WiFi_EXCEPTION_ERROR);//call with error number |
mridup | 0:dc55f40eb04f | 797 | } |
mridup | 0:dc55f40eb04f | 798 | |
mridup | 0:dc55f40eb04f | 799 | else if(WiFi_WIND_State.PS_Mode_Failure==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 800 | { |
mridup | 0:dc55f40eb04f | 801 | WiFi_WIND_State.PS_Mode_Failure=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 802 | ind_wifi_warning(WiFi_POWER_SAVE_WARNING);//call with error number |
mridup | 0:dc55f40eb04f | 803 | } |
mridup | 0:dc55f40eb04f | 804 | |
mridup | 0:dc55f40eb04f | 805 | else if(WiFi_WIND_State.HeapTooSmall==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 806 | { |
mridup | 0:dc55f40eb04f | 807 | WiFi_WIND_State.HeapTooSmall=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 808 | ind_wifi_warning(WiFi_HEAP_TOO_SMALL_WARNING);//call with error number |
mridup | 0:dc55f40eb04f | 809 | } |
mridup | 0:dc55f40eb04f | 810 | |
mridup | 0:dc55f40eb04f | 811 | else if(WiFi_WIND_State.WiFiSignalLOW==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 812 | { |
mridup | 0:dc55f40eb04f | 813 | WiFi_WIND_State.WiFiSignalLOW=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 814 | ind_wifi_warning(WiFi_SIGNAL_LOW_WARNING);//call with error number |
mridup | 0:dc55f40eb04f | 815 | } |
mridup | 0:dc55f40eb04f | 816 | |
mridup | 0:dc55f40eb04f | 817 | else if(WiFi_WIND_State.WiFiDeauthentication == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 818 | { |
mridup | 0:dc55f40eb04f | 819 | WiFi_WIND_State.WiFiDeauthentication = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 820 | ind_wifi_connection_error(WiFi_DE_AUTH); |
mridup | 0:dc55f40eb04f | 821 | } |
mridup | 0:dc55f40eb04f | 822 | |
mridup | 0:dc55f40eb04f | 823 | else if(WiFi_WIND_State.WiFiDisAssociation == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 824 | { |
mridup | 0:dc55f40eb04f | 825 | WiFi_WIND_State.WiFiDisAssociation = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 826 | ind_wifi_connection_error(WiFi_DISASSOCIATION); |
mridup | 0:dc55f40eb04f | 827 | } |
mridup | 0:dc55f40eb04f | 828 | |
mridup | 0:dc55f40eb04f | 829 | else if(WiFi_WIND_State.WiFiJoinFailed == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 830 | { |
mridup | 0:dc55f40eb04f | 831 | WiFi_WIND_State.WiFiJoinFailed = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 832 | ind_wifi_connection_error(WiFi_JOIN_FAILED); |
mridup | 0:dc55f40eb04f | 833 | } |
mridup | 0:dc55f40eb04f | 834 | |
mridup | 0:dc55f40eb04f | 835 | else if(WiFi_WIND_State.WiFiScanBlewUp == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 836 | { |
mridup | 0:dc55f40eb04f | 837 | WiFi_WIND_State.WiFiScanBlewUp = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 838 | ind_wifi_connection_error(WiFi_SCAN_BLEWUP); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 839 | } |
mridup | 0:dc55f40eb04f | 840 | |
mridup | 0:dc55f40eb04f | 841 | else if(WiFi_WIND_State.WiFiScanFailed == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 842 | { |
mridup | 0:dc55f40eb04f | 843 | WiFi_WIND_State.WiFiScanFailed = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 844 | ind_wifi_connection_error(WiFi_SCAN_FAILED); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 845 | } |
mridup | 0:dc55f40eb04f | 846 | |
mridup | 0:dc55f40eb04f | 847 | else if(WiFi_WIND_State.WiFiUnHandledInd == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 848 | { |
mridup | 0:dc55f40eb04f | 849 | WiFi_WIND_State.WiFiUnHandledInd = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 850 | ind_wifi_packet_lost(WiFi_UNHANDLED_IND_ERROR); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 851 | } |
mridup | 0:dc55f40eb04f | 852 | |
mridup | 0:dc55f40eb04f | 853 | else if(WiFi_WIND_State.WiFiRXMgmt == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 854 | { |
mridup | 0:dc55f40eb04f | 855 | WiFi_WIND_State.WiFiRXMgmt = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 856 | ind_wifi_packet_lost(WiFi_RX_MGMT); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 857 | } |
mridup | 0:dc55f40eb04f | 858 | |
mridup | 0:dc55f40eb04f | 859 | else if(WiFi_WIND_State.WiFiRXData == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 860 | { |
mridup | 0:dc55f40eb04f | 861 | WiFi_WIND_State.WiFiRXData = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 862 | ind_wifi_packet_lost(WiFi_RX_DATA); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 863 | } |
mridup | 0:dc55f40eb04f | 864 | |
mridup | 0:dc55f40eb04f | 865 | else if(WiFi_WIND_State.WiFiRxUnk == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 866 | { |
mridup | 0:dc55f40eb04f | 867 | WiFi_WIND_State.WiFiRxUnk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 868 | ind_wifi_packet_lost(WiFi_RX_UNK); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 869 | } |
mridup | 0:dc55f40eb04f | 870 | |
mridup | 0:dc55f40eb04f | 871 | else if(WiFi_WIND_State.WiFiSockdDataLost == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 872 | { |
mridup | 0:dc55f40eb04f | 873 | WiFi_WIND_State.WiFiSockdDataLost = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 874 | ind_wifi_socket_server_data_lost(); //@TBD to check if user made call, so not call callback if true |
mridup | 0:dc55f40eb04f | 875 | } |
mridup | 0:dc55f40eb04f | 876 | |
mridup | 0:dc55f40eb04f | 877 | } |
mridup | 0:dc55f40eb04f | 878 | |
mridup | 0:dc55f40eb04f | 879 | |
mridup | 0:dc55f40eb04f | 880 | /** |
mridup | 0:dc55f40eb04f | 881 | * @brief Start_Timer |
mridup | 0:dc55f40eb04f | 882 | * Start Timer |
mridup | 0:dc55f40eb04f | 883 | * @param None |
mridup | 0:dc55f40eb04f | 884 | * @retval None |
mridup | 0:dc55f40eb04f | 885 | */ |
mridup | 0:dc55f40eb04f | 886 | void Start_Timer() |
mridup | 0:dc55f40eb04f | 887 | { |
mridup | 0:dc55f40eb04f | 888 | //tickcount = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 889 | status_flag.Timer_Running = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 890 | } |
mridup | 0:dc55f40eb04f | 891 | |
mridup | 0:dc55f40eb04f | 892 | /** |
mridup | 0:dc55f40eb04f | 893 | * @brief Stop_Timer |
mridup | 0:dc55f40eb04f | 894 | * Stop Timer request |
mridup | 0:dc55f40eb04f | 895 | * @param None |
mridup | 0:dc55f40eb04f | 896 | * @retval None |
mridup | 0:dc55f40eb04f | 897 | */ |
mridup | 0:dc55f40eb04f | 898 | void Stop_Timer() |
mridup | 0:dc55f40eb04f | 899 | { |
mridup | 0:dc55f40eb04f | 900 | //tickcount = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 901 | status_flag.Timer_Running = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 902 | //UartReady = SET; |
mridup | 0:dc55f40eb04f | 903 | } |
mridup | 0:dc55f40eb04f | 904 | |
mridup | 0:dc55f40eb04f | 905 | /** |
mridup | 0:dc55f40eb04f | 906 | * @brief Stop_Dequeue |
mridup | 0:dc55f40eb04f | 907 | * Stop dequeuing data from the ring buffer |
mridup | 0:dc55f40eb04f | 908 | * @param None |
mridup | 0:dc55f40eb04f | 909 | * @retval None |
mridup | 0:dc55f40eb04f | 910 | */ |
mridup | 0:dc55f40eb04f | 911 | void Stop_Dequeue() |
mridup | 0:dc55f40eb04f | 912 | { |
mridup | 0:dc55f40eb04f | 913 | status_flag.enable_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 914 | } |
mridup | 0:dc55f40eb04f | 915 | |
mridup | 0:dc55f40eb04f | 916 | /** |
mridup | 0:dc55f40eb04f | 917 | * @brief Resume_Dequeue |
mridup | 0:dc55f40eb04f | 918 | * Resume dequeuing data from the ring buffer |
mridup | 0:dc55f40eb04f | 919 | * @param None |
mridup | 0:dc55f40eb04f | 920 | * @retval None |
mridup | 0:dc55f40eb04f | 921 | */ |
mridup | 0:dc55f40eb04f | 922 | void Resume_Dequeue() |
mridup | 0:dc55f40eb04f | 923 | { |
mridup | 0:dc55f40eb04f | 924 | status_flag.enable_dequeue = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 925 | } |
mridup | 0:dc55f40eb04f | 926 | |
mridup | 0:dc55f40eb04f | 927 | /** |
mridup | 0:dc55f40eb04f | 928 | * @brief Wifi_SysTick_Isr |
mridup | 0:dc55f40eb04f | 929 | * Function called every SysTick to process buffer |
mridup | 0:dc55f40eb04f | 930 | * @param None |
mridup | 0:dc55f40eb04f | 931 | * @retval None |
mridup | 0:dc55f40eb04f | 932 | */ |
mridup | 0:dc55f40eb04f | 933 | void Wifi_SysTick_Isr() |
mridup | 0:dc55f40eb04f | 934 | { |
mridup | 0:dc55f40eb04f | 935 | //Check if Data is Paused |
mridup | 0:dc55f40eb04f | 936 | if((status_flag.Timer_Running) && (status_flag.enable_dequeue==WIFI_TRUE)) |
mridup | 0:dc55f40eb04f | 937 | { |
mridup | 0:dc55f40eb04f | 938 | Process_WiFi(); |
mridup | 0:dc55f40eb04f | 939 | } |
mridup | 0:dc55f40eb04f | 940 | |
mridup | 0:dc55f40eb04f | 941 | if(status_flag.Timeout_Timer) tickcount++; |
mridup | 0:dc55f40eb04f | 942 | |
mridup | 0:dc55f40eb04f | 943 | /*if(status_flag.resume_receive_data == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 944 | { |
mridup | 0:dc55f40eb04f | 945 | if(is_half_empty(&big_buff)) |
mridup | 0:dc55f40eb04f | 946 | { |
mridup | 0:dc55f40eb04f | 947 | status_flag.resume_receive_data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 948 | //callSpwfSADevice_attach(1); |
mridup | 0:dc55f40eb04f | 949 | Receive_Data(); |
mridup | 0:dc55f40eb04f | 950 | |
mridup | 0:dc55f40eb04f | 951 | } |
mridup | 0:dc55f40eb04f | 952 | }*/ |
mridup | 0:dc55f40eb04f | 953 | |
mridup | 0:dc55f40eb04f | 954 | |
mridup | 0:dc55f40eb04f | 955 | if(status_flag.Standby_Timer_Running) // module is in sleep and after expiry RX will be conf as EXTI |
mridup | 0:dc55f40eb04f | 956 | { |
mridup | 0:dc55f40eb04f | 957 | if((standby_time++) >= EXTI_CONF_TIMER) |
mridup | 0:dc55f40eb04f | 958 | { |
mridup | 0:dc55f40eb04f | 959 | status_flag.Standby_Timer_Running=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 960 | standby_time = 0; |
mridup | 0:dc55f40eb04f | 961 | //configure_to_exti(); |
mridup | 0:dc55f40eb04f | 962 | } |
mridup | 0:dc55f40eb04f | 963 | } |
mridup | 0:dc55f40eb04f | 964 | |
mridup | 0:dc55f40eb04f | 965 | /*A Resume WIND:70 has come and triggered this |
mridup | 0:dc55f40eb04f | 966 | So checking here if after that resume we fall back to sleep (another WIND69) within SLEEP_RESUME_PREVENT time. |
mridup | 0:dc55f40eb04f | 967 | If yes, we assume it is a false resume and hence do nothing and go back to sleep |
mridup | 0:dc55f40eb04f | 968 | If no WIND69 (going into sleep) has come, we can assume the resume was genuine and then enable the callback |
mridup | 0:dc55f40eb04f | 969 | */ |
mridup | 0:dc55f40eb04f | 970 | if((status_flag.Deep_Sleep_Timer) && ( sleep_count++) >= SLEEP_RESUME_PREVENT) |
mridup | 0:dc55f40eb04f | 971 | { |
mridup | 0:dc55f40eb04f | 972 | if(status_flag.Deep_Sleep_Enabled == WIFI_TRUE)//which means we have received another WIND69 in the 2 seconds |
mridup | 0:dc55f40eb04f | 973 | { |
mridup | 0:dc55f40eb04f | 974 | //do nothing, go back to sleep |
mridup | 0:dc55f40eb04f | 975 | status_flag.Deep_Sleep_Enabled = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 976 | status_flag.Deep_Sleep_Callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 977 | } |
mridup | 0:dc55f40eb04f | 978 | else if (status_flag.Deep_Sleep_Enabled == WIFI_FALSE) //which means we have not received any WIND69 during the last 2 seconds |
mridup | 0:dc55f40eb04f | 979 | { |
mridup | 0:dc55f40eb04f | 980 | //enable the user callback as it is a genuine WIND70 |
mridup | 0:dc55f40eb04f | 981 | status_flag.Deep_Sleep_Callback = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 982 | } |
mridup | 0:dc55f40eb04f | 983 | Stop_DeepSleep_Timer(); |
mridup | 0:dc55f40eb04f | 984 | } |
mridup | 0:dc55f40eb04f | 985 | } |
mridup | 0:dc55f40eb04f | 986 | |
mridup | 0:dc55f40eb04f | 987 | |
mridup | 0:dc55f40eb04f | 988 | /** |
mridup | 0:dc55f40eb04f | 989 | * @brief USART_Receive_AT_Resp |
mridup | 0:dc55f40eb04f | 990 | * Receive and check AT cmd response |
mridup | 0:dc55f40eb04f | 991 | * @param WiFi_AT_CMD_Response_t : WIFi module next state |
mridup | 0:dc55f40eb04f | 992 | * @retval WiFi_Status_t : Response of AT cmd |
mridup | 0:dc55f40eb04f | 993 | */ |
mridup | 0:dc55f40eb04f | 994 | |
mridup | 0:dc55f40eb04f | 995 | WiFi_Status_t USART_Receive_AT_Resp(WiFi_AT_CMD_Response_t state) |
mridup | 0:dc55f40eb04f | 996 | { |
mridup | 0:dc55f40eb04f | 997 | WiFi_Module_State = state; |
mridup | 0:dc55f40eb04f | 998 | tickcount=0;//reset timer |
mridup | 0:dc55f40eb04f | 999 | status_flag.Timeout_Timer = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1000 | while(status_flag.AT_Response_Received != WIFI_TRUE) { |
mridup | 0:dc55f40eb04f | 1001 | if(tickcount >=20000)//20 sec wait |
mridup | 0:dc55f40eb04f | 1002 | { |
mridup | 0:dc55f40eb04f | 1003 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 1004 | break; |
mridup | 0:dc55f40eb04f | 1005 | } |
mridup | 0:dc55f40eb04f | 1006 | __NOP(); |
mridup | 0:dc55f40eb04f | 1007 | } |
mridup | 0:dc55f40eb04f | 1008 | status_flag.Timeout_Timer = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1009 | status_flag.AT_Response_Received = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1010 | return AT_RESPONSE; |
mridup | 0:dc55f40eb04f | 1011 | } |
mridup | 0:dc55f40eb04f | 1012 | |
mridup | 0:dc55f40eb04f | 1013 | |
mridup | 0:dc55f40eb04f | 1014 | /** |
mridup | 0:dc55f40eb04f | 1015 | * @brief Process_WiFi |
mridup | 0:dc55f40eb04f | 1016 | * Pop a byte from the circular buffer and send the byte for processing |
mridup | 0:dc55f40eb04f | 1017 | * This function should be called from main or should be run with a periodic timer |
mridup | 0:dc55f40eb04f | 1018 | * @param None |
mridup | 0:dc55f40eb04f | 1019 | * @retval None |
mridup | 0:dc55f40eb04f | 1020 | */ |
mridup | 0:dc55f40eb04f | 1021 | void Process_WiFi(void) |
mridup | 0:dc55f40eb04f | 1022 | { |
mridup | 0:dc55f40eb04f | 1023 | uint8_t * temp;//pop buffer temporary |
mridup | 0:dc55f40eb04f | 1024 | |
mridup | 0:dc55f40eb04f | 1025 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1026 | temp=pop_buffer_queue(&big_buff); //contents of temp(pop_buffer) will not change till another de-queue is made |
mridup | 0:dc55f40eb04f | 1027 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1028 | |
mridup | 0:dc55f40eb04f | 1029 | if(temp!=NULL) |
mridup | 0:dc55f40eb04f | 1030 | { |
mridup | 0:dc55f40eb04f | 1031 | Process_Buffer(temp); |
mridup | 0:dc55f40eb04f | 1032 | } |
mridup | 0:dc55f40eb04f | 1033 | |
mridup | 0:dc55f40eb04f | 1034 | if(status_flag.event_deQ_x_wind64)//if de-Q is stopped due to WIND64 wait |
mridup | 0:dc55f40eb04f | 1035 | { |
mridup | 0:dc55f40eb04f | 1036 | wind64_DQ_wait++;//1ms for each count |
mridup | 0:dc55f40eb04f | 1037 | if(wind64_DQ_wait>200)//wait for 50ms for example |
mridup | 0:dc55f40eb04f | 1038 | { |
mridup | 0:dc55f40eb04f | 1039 | wind64_DQ_wait=0; |
mridup | 0:dc55f40eb04f | 1040 | status_flag.event_deQ_x_wind64 = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1041 | //re-enable event Q after 200ms |
mridup | 0:dc55f40eb04f | 1042 | status_flag.stop_event_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1043 | } |
mridup | 0:dc55f40eb04f | 1044 | } |
mridup | 0:dc55f40eb04f | 1045 | } |
mridup | 0:dc55f40eb04f | 1046 | |
mridup | 0:dc55f40eb04f | 1047 | /** |
mridup | 0:dc55f40eb04f | 1048 | * @brief Process_Buffer |
mridup | 0:dc55f40eb04f | 1049 | * Process and construct a Wind Line buffer |
mridup | 0:dc55f40eb04f | 1050 | * @param ptr: pointer to one single byte |
mridup | 0:dc55f40eb04f | 1051 | * @retval None |
mridup | 0:dc55f40eb04f | 1052 | */ |
mridup | 0:dc55f40eb04f | 1053 | |
mridup | 0:dc55f40eb04f | 1054 | void Process_Buffer(uint8_t * ptr) |
mridup | 0:dc55f40eb04f | 1055 | { |
mridup | 0:dc55f40eb04f | 1056 | static uint32_t Fillptr=0;//count=0; |
mridup | 0:dc55f40eb04f | 1057 | static uint8_t index, chan_value; |
mridup | 0:dc55f40eb04f | 1058 | unsigned char rxdata = 0; |
mridup | 0:dc55f40eb04f | 1059 | int rssi_value = 0; |
mridup | 0:dc55f40eb04f | 1060 | char SocketId_No[2]; |
mridup | 0:dc55f40eb04f | 1061 | char databytes_No[4]; |
mridup | 0:dc55f40eb04f | 1062 | char * pStr; |
mridup | 0:dc55f40eb04f | 1063 | |
mridup | 0:dc55f40eb04f | 1064 | rxdata = *(ptr+0); |
mridup | 0:dc55f40eb04f | 1065 | //printf(&rxdata);//check prints for debug...to be removed or kept in DEBUG statement |
mridup | 0:dc55f40eb04f | 1066 | if(status_flag.enable_receive_data_chunk == WIFI_FALSE) |
mridup | 0:dc55f40eb04f | 1067 | process_buffer[Fillptr++] = rxdata; |
mridup | 0:dc55f40eb04f | 1068 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1069 | switch (WiFi_Module_State) |
mridup | 0:dc55f40eb04f | 1070 | { |
mridup | 0:dc55f40eb04f | 1071 | case Process_Event: |
mridup | 0:dc55f40eb04f | 1072 | |
mridup | 0:dc55f40eb04f | 1073 | if((process_buffer[Fillptr-2]==0xD) && (process_buffer[Fillptr-1]==0xA) && !status_flag.enable_receive_http_response && !status_flag.sock_read_ongoing) |
mridup | 0:dc55f40eb04f | 1074 | { |
mridup | 0:dc55f40eb04f | 1075 | if((strstr((const char *)process_buffer,"WIND:")) != NULL) |
mridup | 0:dc55f40eb04f | 1076 | { |
mridup | 0:dc55f40eb04f | 1077 | if((strstr((const char *)process_buffer,"+WIND:67:")) !=NULL) |
mridup | 0:dc55f40eb04f | 1078 | event_s.event = WIFI_STANDBY_CONFIG_EVENT; |
mridup | 0:dc55f40eb04f | 1079 | |
mridup | 0:dc55f40eb04f | 1080 | else if ((strstr((const char *)process_buffer,"+WIND:68:"))!= NULL) |
mridup | 0:dc55f40eb04f | 1081 | event_s.event = WIFI_RESUME_CONFIG_EVENT; |
mridup | 0:dc55f40eb04f | 1082 | |
mridup | 0:dc55f40eb04f | 1083 | else |
mridup | 0:dc55f40eb04f | 1084 | { |
mridup | 0:dc55f40eb04f | 1085 | //end of msg received. Will not receive any other msg till we process this. |
mridup | 0:dc55f40eb04f | 1086 | //Stop_Timer(); |
mridup | 0:dc55f40eb04f | 1087 | //#if defined (USE_STM32L0XX_NUCLEO) || (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO) |
mridup | 0:dc55f40eb04f | 1088 | //__disable_irq(); |
mridup | 0:dc55f40eb04f | 1089 | //#endif |
mridup | 0:dc55f40eb04f | 1090 | Process_Wind_Indication(&process_buffer[0]); |
mridup | 0:dc55f40eb04f | 1091 | //#if defined (USE_STM32L0XX_NUCLEO) || (USE_STM32F4XX_NUCLEO) || (USE_STM32L4XX_NUCLEO) |
mridup | 0:dc55f40eb04f | 1092 | //__enable_irq(); |
mridup | 0:dc55f40eb04f | 1093 | //#endif |
mridup | 0:dc55f40eb04f | 1094 | //Start_Timer(); |
mridup | 0:dc55f40eb04f | 1095 | sock_total_count=0; |
mridup | 0:dc55f40eb04f | 1096 | } |
mridup | 0:dc55f40eb04f | 1097 | |
mridup | 0:dc55f40eb04f | 1098 | if(!status_flag.prevent_push_WIFI_event) |
mridup | 0:dc55f40eb04f | 1099 | { |
mridup | 0:dc55f40eb04f | 1100 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1101 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 1102 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1103 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1104 | } |
mridup | 0:dc55f40eb04f | 1105 | |
mridup | 0:dc55f40eb04f | 1106 | if (!status_flag.do_not_reset_push_WIFI_event) status_flag.prevent_push_WIFI_event = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1107 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1108 | { |
mridup | 0:dc55f40eb04f | 1109 | status_flag.sock_read_ongoing = WIFI_FALSE;//we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1110 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1111 | } |
mridup | 0:dc55f40eb04f | 1112 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1113 | memset(process_buffer, 0x00, strlen((const char*)process_buffer)); |
mridup | 0:dc55f40eb04f | 1114 | } |
mridup | 0:dc55f40eb04f | 1115 | |
mridup | 0:dc55f40eb04f | 1116 | else if((strstr((const char *)process_buffer,"\r\nOK\r\n")) != NULL) |
mridup | 0:dc55f40eb04f | 1117 | { |
mridup | 0:dc55f40eb04f | 1118 | /*Now Check to which AT Cmd response this OK belongs to so that correct parsing can be done*/ |
mridup | 0:dc55f40eb04f | 1119 | |
mridup | 0:dc55f40eb04f | 1120 | // SOCKON ID (Open a client socket) |
mridup | 0:dc55f40eb04f | 1121 | if(((pStr=(strstr((const char *)process_buffer,"ID: "))) != NULL)) |
mridup | 0:dc55f40eb04f | 1122 | { |
mridup | 0:dc55f40eb04f | 1123 | SocketId_No[0] = *(pStr + 4) ; |
mridup | 0:dc55f40eb04f | 1124 | SocketId_No[1] = *(pStr + 5) ; |
mridup | 0:dc55f40eb04f | 1125 | SocketId = (((SocketId_No[0] - '0') * 10 ) + (SocketId_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1126 | event_s.socket_id = SocketId; |
mridup | 0:dc55f40eb04f | 1127 | event_s.event = WIFI_SOCK_ID_EVENT; |
mridup | 0:dc55f40eb04f | 1128 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1129 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 1130 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1131 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1132 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1133 | { |
mridup | 0:dc55f40eb04f | 1134 | status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1135 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1136 | } |
mridup | 0:dc55f40eb04f | 1137 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1138 | sock_total_count=0; |
mridup | 0:dc55f40eb04f | 1139 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1140 | } |
mridup | 0:dc55f40eb04f | 1141 | |
mridup | 0:dc55f40eb04f | 1142 | // DATALEN from SOCKQ |
mridup | 0:dc55f40eb04f | 1143 | else if((pStr=(strstr((const char *)process_buffer,"DATALEN: "))) != NULL) |
mridup | 0:dc55f40eb04f | 1144 | { |
mridup | 0:dc55f40eb04f | 1145 | //Find the DataLength and do a socket read |
mridup | 0:dc55f40eb04f | 1146 | databytes_No[0] = *(pStr + 9); |
mridup | 0:dc55f40eb04f | 1147 | databytes_No[1] = *(pStr + 10); |
mridup | 0:dc55f40eb04f | 1148 | databytes_No[2] = *(pStr + 11); |
mridup | 0:dc55f40eb04f | 1149 | databytes_No[3] = *(pStr + 12); |
mridup | 0:dc55f40eb04f | 1150 | |
mridup | 0:dc55f40eb04f | 1151 | if( databytes_No[1] == '\r') |
mridup | 0:dc55f40eb04f | 1152 | { |
mridup | 0:dc55f40eb04f | 1153 | SockON_Data_Len = databytes_No[0] - '0'; |
mridup | 0:dc55f40eb04f | 1154 | } |
mridup | 0:dc55f40eb04f | 1155 | else if( databytes_No[2] == '\r') |
mridup | 0:dc55f40eb04f | 1156 | { |
mridup | 0:dc55f40eb04f | 1157 | SockON_Data_Len = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1158 | } |
mridup | 0:dc55f40eb04f | 1159 | else if( databytes_No[3] == '\r') |
mridup | 0:dc55f40eb04f | 1160 | { |
mridup | 0:dc55f40eb04f | 1161 | SockON_Data_Len = (((databytes_No[0] - '0') * 100 ) + ((databytes_No[1] - '0') * 10 ) + (databytes_No[2] - '0')); |
mridup | 0:dc55f40eb04f | 1162 | } |
mridup | 0:dc55f40eb04f | 1163 | else //it's a 4-digit number |
mridup | 0:dc55f40eb04f | 1164 | { |
mridup | 0:dc55f40eb04f | 1165 | SockON_Data_Len = ((databytes_No[0] - '0') * 1000 ) + ((databytes_No[1] - '0') * 100 ) + ((databytes_No[2] - '0') * 10) + (databytes_No[3] - '0'); |
mridup | 0:dc55f40eb04f | 1166 | } |
mridup | 0:dc55f40eb04f | 1167 | Socket_Data_Length = SockON_Data_Len; |
mridup | 0:dc55f40eb04f | 1168 | if(Socket_Data_Length != 0) |
mridup | 0:dc55f40eb04f | 1169 | { |
mridup | 0:dc55f40eb04f | 1170 | status_flag.start_sock_read = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1171 | } |
mridup | 0:dc55f40eb04f | 1172 | else if(Socket_Data_Length == 0) |
mridup | 0:dc55f40eb04f | 1173 | { |
mridup | 0:dc55f40eb04f | 1174 | status_flag.stop_event_dequeue = WIFI_FALSE; //continue popping events if nothing to read |
mridup | 0:dc55f40eb04f | 1175 | status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1176 | } |
mridup | 0:dc55f40eb04f | 1177 | Fillptr = 0; |
mridup | 0:dc55f40eb04f | 1178 | sock_total_count = 0; |
mridup | 0:dc55f40eb04f | 1179 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1180 | { |
mridup | 0:dc55f40eb04f | 1181 | status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1182 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1183 | pop_buffer_size = 0; |
mridup | 0:dc55f40eb04f | 1184 | pop_buffer[0]='\0'; // required as this byte is already used in process_buffer |
mridup | 0:dc55f40eb04f | 1185 | } |
mridup | 0:dc55f40eb04f | 1186 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1187 | } |
mridup | 0:dc55f40eb04f | 1188 | |
mridup | 0:dc55f40eb04f | 1189 | else if((((strstr((const char *)process_buffer," = "))) != NULL)) |
mridup | 0:dc55f40eb04f | 1190 | { |
mridup | 0:dc55f40eb04f | 1191 | // AT command GCFG |
mridup | 0:dc55f40eb04f | 1192 | pStr = (char *) strstr((const char *)process_buffer," = "); |
mridup | 0:dc55f40eb04f | 1193 | event_s.event = WIFI_GCFG_EVENT; |
mridup | 0:dc55f40eb04f | 1194 | memcpy(get_cfg_value, pStr+2, (strlen(pStr)-2)); |
mridup | 0:dc55f40eb04f | 1195 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1196 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 1197 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1198 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1199 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1200 | { |
mridup | 0:dc55f40eb04f | 1201 | status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1202 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1203 | } |
mridup | 0:dc55f40eb04f | 1204 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1205 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1206 | } |
mridup | 0:dc55f40eb04f | 1207 | |
mridup | 0:dc55f40eb04f | 1208 | else |
mridup | 0:dc55f40eb04f | 1209 | { |
mridup | 0:dc55f40eb04f | 1210 | //This is a standalone OK |
mridup | 0:dc55f40eb04f | 1211 | /*Cases possible |
mridup | 0:dc55f40eb04f | 1212 | - TLSCERT,TLSCERT2, TLSDOMAIN, SETTIME |
mridup | 0:dc55f40eb04f | 1213 | - S.SOCKW, SOCKR, S.SOCKC, S.SOCKD (open a server socket) |
mridup | 0:dc55f40eb04f | 1214 | - File Operations |
mridup | 0:dc55f40eb04f | 1215 | - S.GPIOC and S.GPIOW |
mridup | 0:dc55f40eb04f | 1216 | */ |
mridup | 0:dc55f40eb04f | 1217 | //Push a simple OK Event, if this is an OK event required to be pushed to Q |
mridup | 0:dc55f40eb04f | 1218 | if(status_flag.prevent_push_OK_event) |
mridup | 0:dc55f40eb04f | 1219 | { |
mridup | 0:dc55f40eb04f | 1220 | //This OK is not to be handled, hence the pop action on OK completion to be done here |
mridup | 0:dc55f40eb04f | 1221 | //since pop will not happen |
mridup | 0:dc55f40eb04f | 1222 | // stop_event_dequeue=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1223 | |
mridup | 0:dc55f40eb04f | 1224 | if(status_flag.client_socket_close_ongoing) |
mridup | 0:dc55f40eb04f | 1225 | { |
mridup | 0:dc55f40eb04f | 1226 | if(no_of_open_client_sockets > 0) |
mridup | 0:dc55f40eb04f | 1227 | no_of_open_client_sockets--; |
mridup | 0:dc55f40eb04f | 1228 | status_flag.prevent_push_OK_event = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1229 | open_sockets[remote_socket_closed_id] = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1230 | socket_closed_id_callback = remote_socket_closed_id; |
mridup | 0:dc55f40eb04f | 1231 | status_flag.Set_AT_Cmd_Response_False = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1232 | status_flag.client_socket_close_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1233 | status_flag.SockON_Server_Closed_Callback = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1234 | status_flag.stop_event_dequeue=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1235 | } |
mridup | 0:dc55f40eb04f | 1236 | |
mridup | 0:dc55f40eb04f | 1237 | } |
mridup | 0:dc55f40eb04f | 1238 | |
mridup | 0:dc55f40eb04f | 1239 | else |
mridup | 0:dc55f40eb04f | 1240 | { |
mridup | 0:dc55f40eb04f | 1241 | event_s.ok_eval = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1242 | event_s.event = WIFI_OK_EVENT; |
mridup | 0:dc55f40eb04f | 1243 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1244 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 1245 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1246 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1247 | } |
mridup | 0:dc55f40eb04f | 1248 | status_flag.prevent_push_OK_event = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1249 | memset(process_buffer, 0x00, Fillptr); |
mridup | 0:dc55f40eb04f | 1250 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1251 | sock_total_count=0; |
mridup | 0:dc55f40eb04f | 1252 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1253 | { |
mridup | 0:dc55f40eb04f | 1254 | status_flag.sock_read_ongoing = WIFI_FALSE;//we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1255 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1256 | } |
mridup | 0:dc55f40eb04f | 1257 | break; |
mridup | 0:dc55f40eb04f | 1258 | } |
mridup | 0:dc55f40eb04f | 1259 | } |
mridup | 0:dc55f40eb04f | 1260 | |
mridup | 0:dc55f40eb04f | 1261 | else if((((strstr((const char *)process_buffer,"ERROR"))) != NULL)) |
mridup | 0:dc55f40eb04f | 1262 | { |
mridup | 0:dc55f40eb04f | 1263 | //This is an ERROR |
mridup | 0:dc55f40eb04f | 1264 | //There can be only ONE outstanding AT command and hence this ERROR belongs to that |
mridup | 0:dc55f40eb04f | 1265 | //HTTP -> ERROR: host not found |
mridup | 0:dc55f40eb04f | 1266 | //@TBD: Check all Errors Possible here??? |
mridup | 0:dc55f40eb04f | 1267 | if((strstr((const char *)process_buffer,"\r\nERROR: Pending data\r\n")) != NULL) //if Error after sock close command and not 'OK' |
mridup | 0:dc55f40eb04f | 1268 | { |
mridup | 0:dc55f40eb04f | 1269 | printf("\r\nERROR: Socket could not be closed..PENDING DATA\r\n"); |
mridup | 0:dc55f40eb04f | 1270 | status_flag.prevent_push_OK_event = WIFI_FALSE; //prevent the OK received after socket close command to be Q'ed |
mridup | 0:dc55f40eb04f | 1271 | status_flag.client_socket_close_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1272 | status_flag.stop_event_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1273 | } |
mridup | 0:dc55f40eb04f | 1274 | else |
mridup | 0:dc55f40eb04f | 1275 | { |
mridup | 0:dc55f40eb04f | 1276 | event_s.event = WIFI_ERROR_EVENT; |
mridup | 0:dc55f40eb04f | 1277 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1278 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 1279 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1280 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1281 | if(status_flag.stop_event_dequeue) |
mridup | 0:dc55f40eb04f | 1282 | /*ERROR:Illegal Socket ID*/ |
mridup | 0:dc55f40eb04f | 1283 | status_flag.stop_event_dequeue= WIFI_FALSE;//continue popping events if nothing to read |
mridup | 0:dc55f40eb04f | 1284 | } |
mridup | 0:dc55f40eb04f | 1285 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1286 | sock_total_count=0; |
mridup | 0:dc55f40eb04f | 1287 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1288 | { |
mridup | 0:dc55f40eb04f | 1289 | status_flag.sock_read_ongoing = WIFI_FALSE;//we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1290 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1291 | } |
mridup | 0:dc55f40eb04f | 1292 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1293 | } |
mridup | 0:dc55f40eb04f | 1294 | |
mridup | 0:dc55f40eb04f | 1295 | else if((((strstr((const char *)process_buffer,"GPIO "))) != NULL)) |
mridup | 0:dc55f40eb04f | 1296 | { |
mridup | 0:dc55f40eb04f | 1297 | // Receive GPIO Read |
mridup | 0:dc55f40eb04f | 1298 | pStr = (char *) strstr((const char *)process_buffer,"= 0,"); |
mridup | 0:dc55f40eb04f | 1299 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1300 | { |
mridup | 0:dc55f40eb04f | 1301 | gpio_value = 0; |
mridup | 0:dc55f40eb04f | 1302 | } |
mridup | 0:dc55f40eb04f | 1303 | else |
mridup | 0:dc55f40eb04f | 1304 | gpio_value = 1; |
mridup | 0:dc55f40eb04f | 1305 | |
mridup | 0:dc55f40eb04f | 1306 | pStr = (char *) strstr((const char *)process_buffer,"out"); |
mridup | 0:dc55f40eb04f | 1307 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1308 | { |
mridup | 0:dc55f40eb04f | 1309 | gpio_direc= 0; //out |
mridup | 0:dc55f40eb04f | 1310 | } |
mridup | 0:dc55f40eb04f | 1311 | else |
mridup | 0:dc55f40eb04f | 1312 | { |
mridup | 0:dc55f40eb04f | 1313 | gpio_direc= 1; //in |
mridup | 0:dc55f40eb04f | 1314 | } |
mridup | 0:dc55f40eb04f | 1315 | //Push GPIO Read Event on Event_Queue |
mridup | 0:dc55f40eb04f | 1316 | event_s.event = WIFI_GPIO_EVENT; |
mridup | 0:dc55f40eb04f | 1317 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1318 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 1319 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1320 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 1321 | if(status_flag.enable_sock_read) |
mridup | 0:dc55f40eb04f | 1322 | { |
mridup | 0:dc55f40eb04f | 1323 | status_flag.sock_read_ongoing = WIFI_FALSE; //we finished processing a message and now sock read will commence |
mridup | 0:dc55f40eb04f | 1324 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1325 | } |
mridup | 0:dc55f40eb04f | 1326 | Fillptr = 0; |
mridup | 0:dc55f40eb04f | 1327 | memset(process_buffer, 0x00, strlen((const char*)process_buffer)); |
mridup | 0:dc55f40eb04f | 1328 | break; |
mridup | 0:dc55f40eb04f | 1329 | } |
mridup | 0:dc55f40eb04f | 1330 | |
mridup | 0:dc55f40eb04f | 1331 | else |
mridup | 0:dc55f40eb04f | 1332 | { |
mridup | 0:dc55f40eb04f | 1333 | if(status_flag.enable_sock_read && status_flag.Q_Contains_Message && !status_flag.message_pending) |
mridup | 0:dc55f40eb04f | 1334 | { |
mridup | 7:0fdd186a7d90 | 1335 | //printf((const char*)&process_buffer[0]); |
mridup | 7:0fdd186a7d90 | 1336 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 7:0fdd186a7d90 | 1337 | message_size = SockON_Data_Length;//Total size |
mridup | 7:0fdd186a7d90 | 1338 | chunk_size = Fillptr; |
mridup | 7:0fdd186a7d90 | 1339 | memcpy(UserDataBuff, process_buffer, Fillptr); |
mridup | 7:0fdd186a7d90 | 1340 | Fillptr = 0; |
mridup | 7:0fdd186a7d90 | 1341 | SockON_Data_Length = SockON_Data_Length - Fillptr; |
mridup | 7:0fdd186a7d90 | 1342 | process_buffer_index = 5; |
mridup | 7:0fdd186a7d90 | 1343 | pop_queue_length = 0; |
mridup | 7:0fdd186a7d90 | 1344 | Stop_Dequeue(); |
mridup | 7:0fdd186a7d90 | 1345 | memset(process_buffer, 0x00, Fillptr); |
mridup | 7:0fdd186a7d90 | 1346 | status_flag.Pending_SockON_Callback = WIFI_TRUE; //set this to callback to user with User Buffer pointer |
mridup | 7:0fdd186a7d90 | 1347 | |
mridup | 0:dc55f40eb04f | 1348 | } |
mridup | 0:dc55f40eb04f | 1349 | |
mridup | 0:dc55f40eb04f | 1350 | //if in data mode, reset on \r\n |
mridup | 0:dc55f40eb04f | 1351 | if(!status_flag.sock_read_ongoing && status_flag.data_mode) |
mridup | 0:dc55f40eb04f | 1352 | { |
mridup | 0:dc55f40eb04f | 1353 | Fillptr = 0; |
mridup | 0:dc55f40eb04f | 1354 | memset(process_buffer, 0x00, strlen((const char*)process_buffer)); |
mridup | 0:dc55f40eb04f | 1355 | } |
mridup | 0:dc55f40eb04f | 1356 | } |
mridup | 0:dc55f40eb04f | 1357 | } |
mridup | 0:dc55f40eb04f | 1358 | |
mridup | 0:dc55f40eb04f | 1359 | else if (status_flag.http_req_pending) //HTTP Response Check |
mridup | 0:dc55f40eb04f | 1360 | { |
mridup | 0:dc55f40eb04f | 1361 | if((strstr((const char *)&process_buffer[0],"200 OK\r")) != NULL || (strstr((const char *)&process_buffer[0],"400 Bad Request\r")) != NULL |
mridup | 0:dc55f40eb04f | 1362 | || (strstr((const char *)&process_buffer[0],"401 Unauthorized\r")) != NULL || (strstr((const char *)&process_buffer[0],"403 Forbidden\r")) != NULL |
mridup | 0:dc55f40eb04f | 1363 | || (strstr((const char *)&process_buffer[0],"404 Not Found\r")) != NULL || (strstr((const char *)&process_buffer[0],"408 Request Timeout\r")) != NULL |
mridup | 0:dc55f40eb04f | 1364 | || (strstr((const char *)&process_buffer[0],"500 Internal Server Error\r")) != NULL || (strstr((const char *)&process_buffer[0],"502 Bad Gateway\r")) != NULL |
mridup | 0:dc55f40eb04f | 1365 | || (strstr((const char *)&process_buffer[0],"504 Gateway Timeout\r")) != NULL) |
mridup | 0:dc55f40eb04f | 1366 | { |
mridup | 0:dc55f40eb04f | 1367 | status_flag.enable_receive_http_response = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1368 | status_flag.enable_receive_data_chunk = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1369 | status_flag.http_req_pending = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1370 | pop_buffer[0]='\0'; |
mridup | 0:dc55f40eb04f | 1371 | pop_buffer_size=0; |
mridup | 0:dc55f40eb04f | 1372 | process_buffer_index =6; |
mridup | 0:dc55f40eb04f | 1373 | } |
mridup | 0:dc55f40eb04f | 1374 | } |
mridup | 0:dc55f40eb04f | 1375 | |
mridup | 0:dc55f40eb04f | 1376 | else if ((process_buffer[Fillptr-1]==0x09) && (process_buffer[Fillptr-2]==':') && (process_buffer[Fillptr-3]=='1'))//<ht> Horizontal Tab for Scan Result? |
mridup | 0:dc55f40eb04f | 1377 | { |
mridup | 0:dc55f40eb04f | 1378 | status_flag.enable_receive_wifi_scan_response = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1379 | } |
mridup | 0:dc55f40eb04f | 1380 | |
mridup | 0:dc55f40eb04f | 1381 | if(!status_flag.Pending_SockON_Callback && !status_flag.HTTP_Data_available && !status_flag.FILE_Data_available) |
mridup | 0:dc55f40eb04f | 1382 | { |
mridup | 0:dc55f40eb04f | 1383 | //Check Process Buffer for any pending message |
mridup | 0:dc55f40eb04f | 1384 | if(status_flag.enable_receive_data_chunk) |
mridup | 0:dc55f40eb04f | 1385 | { |
mridup | 7:0fdd186a7d90 | 1386 | if(pop_buffer_size) |
mridup | 0:dc55f40eb04f | 1387 | { |
mridup | 0:dc55f40eb04f | 1388 | pop_queue_length = pop_buffer_size; |
mridup | 0:dc55f40eb04f | 1389 | if(Fillptr + pop_queue_length > 511) |
mridup | 0:dc55f40eb04f | 1390 | { |
mridup | 0:dc55f40eb04f | 1391 | uint32_t length = (Fillptr + pop_queue_length) - 511; |
mridup | 0:dc55f40eb04f | 1392 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1393 | rewind_buffer_queue(&big_buff,length); |
mridup | 0:dc55f40eb04f | 1394 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1395 | memset(ptr+(511 - Fillptr), 0x00, length); |
mridup | 0:dc55f40eb04f | 1396 | pop_queue_length = 511 - Fillptr; |
mridup | 0:dc55f40eb04f | 1397 | } |
mridup | 0:dc55f40eb04f | 1398 | memcpy(process_buffer+Fillptr,(char const *)pop_buffer, pop_queue_length); |
mridup | 0:dc55f40eb04f | 1399 | Fillptr = Fillptr + pop_queue_length; |
mridup | 0:dc55f40eb04f | 1400 | |
mridup | 0:dc55f40eb04f | 1401 | if(Fillptr > 512) |
mridup | 0:dc55f40eb04f | 1402 | { |
mridup | 0:dc55f40eb04f | 1403 | printf("\r\nFillptr corrupted!!\r\n"); |
mridup | 0:dc55f40eb04f | 1404 | } |
mridup | 0:dc55f40eb04f | 1405 | |
mridup | 0:dc55f40eb04f | 1406 | if((strstr((const char *)process_buffer,"ERROR: ")) != NULL) |
mridup | 0:dc55f40eb04f | 1407 | { |
mridup | 0:dc55f40eb04f | 1408 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1409 | status_flag.message_pending = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1410 | } |
mridup | 0:dc55f40eb04f | 1411 | else if(!status_flag.sock_read_ongoing && !status_flag.enable_receive_http_response) |
mridup | 0:dc55f40eb04f | 1412 | { |
mridup | 0:dc55f40eb04f | 1413 | if(process_buffer[0]!='\0') |
mridup | 0:dc55f40eb04f | 1414 | { |
mridup | 7:0fdd186a7d90 | 1415 | if(((process_buffer[0]==0xD) && (process_buffer[1]==0xA)) && process_buffer[2] != 0xD && SockON_Data_Length != 2) |
mridup | 0:dc55f40eb04f | 1416 | { |
mridup | 0:dc55f40eb04f | 1417 | status_flag.message_pending = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1418 | if((pStr = (strstr((const char *)process_buffer+2,"\r\n"))) != NULL) |
mridup | 0:dc55f40eb04f | 1419 | { // process buffer has complete message |
mridup | 0:dc55f40eb04f | 1420 | int wind_length = ((uint8_t *)pStr - (uint8_t *)process_buffer)+2; |
mridup | 0:dc55f40eb04f | 1421 | |
mridup | 0:dc55f40eb04f | 1422 | if(strstr((const char *)process_buffer+2,"DATALEN:")) |
mridup | 0:dc55f40eb04f | 1423 | { |
mridup | 0:dc55f40eb04f | 1424 | pStr = strstr((const char *)process_buffer + wind_length,"\r\nOK\r\n"); //find OK, as DATALEN has to be terminated by OK |
mridup | 0:dc55f40eb04f | 1425 | if(pStr!=NULL) |
mridup | 0:dc55f40eb04f | 1426 | { |
mridup | 0:dc55f40eb04f | 1427 | wind_length = ((uint8_t *)pStr-(uint8_t *)process_buffer)+6; |
mridup | 0:dc55f40eb04f | 1428 | } |
mridup | 0:dc55f40eb04f | 1429 | } |
mridup | 0:dc55f40eb04f | 1430 | |
mridup | 0:dc55f40eb04f | 1431 | if(Fillptr-wind_length) |
mridup | 0:dc55f40eb04f | 1432 | { |
mridup | 0:dc55f40eb04f | 1433 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1434 | rewind_buffer_queue(&big_buff, Fillptr - wind_length); |
mridup | 0:dc55f40eb04f | 1435 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1436 | memset(process_buffer + wind_length,0x00,Fillptr - wind_length); |
mridup | 0:dc55f40eb04f | 1437 | Fillptr = wind_length; |
mridup | 0:dc55f40eb04f | 1438 | } |
mridup | 0:dc55f40eb04f | 1439 | status_flag.message_pending = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1440 | } |
mridup | 0:dc55f40eb04f | 1441 | status_flag.Q_Contains_Message = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1442 | } |
mridup | 0:dc55f40eb04f | 1443 | } |
mridup | 0:dc55f40eb04f | 1444 | } |
mridup | 0:dc55f40eb04f | 1445 | } |
mridup | 0:dc55f40eb04f | 1446 | } |
mridup | 0:dc55f40eb04f | 1447 | |
mridup | 0:dc55f40eb04f | 1448 | if(!status_flag.Q_Contains_Message && status_flag.enable_sock_read && pop_buffer_size) /*read is enabled*/ |
mridup | 0:dc55f40eb04f | 1449 | { |
mridup | 0:dc55f40eb04f | 1450 | status_flag.sock_read_ongoing = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1451 | sock_total_count = sock_total_count + pop_queue_length; |
mridup | 0:dc55f40eb04f | 1452 | |
mridup | 0:dc55f40eb04f | 1453 | /* Check for "ERROR: Not enough data in buffer " */ |
mridup | 0:dc55f40eb04f | 1454 | pStr = (char *) strstr((const char *)&process_buffer,"ERROR: "); |
mridup | 0:dc55f40eb04f | 1455 | |
mridup | 0:dc55f40eb04f | 1456 | if (pStr != NULL) |
mridup | 0:dc55f40eb04f | 1457 | { |
mridup | 0:dc55f40eb04f | 1458 | if((process_buffer[Fillptr-2]==0xD) && (process_buffer[Fillptr-1]==0xA)) |
mridup | 0:dc55f40eb04f | 1459 | { |
mridup | 0:dc55f40eb04f | 1460 | if((pStr = (char *)strstr((const char *)&process_buffer,"\r\nERROR: Too many sockets\r\n")) !=NULL) |
mridup | 0:dc55f40eb04f | 1461 | { |
mridup | 0:dc55f40eb04f | 1462 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1463 | printf("\r\nERROR: TOO MANY SOCKETS \r\n"); |
mridup | 0:dc55f40eb04f | 1464 | #endif |
mridup | 0:dc55f40eb04f | 1465 | |
mridup | 0:dc55f40eb04f | 1466 | if(*(pStr+27)!='\0') |
mridup | 0:dc55f40eb04f | 1467 | { |
mridup | 0:dc55f40eb04f | 1468 | int len = (uint8_t *)pStr - (uint8_t *)process_buffer; |
mridup | 0:dc55f40eb04f | 1469 | int extra_bytes = Fillptr - (len+27); |
mridup | 0:dc55f40eb04f | 1470 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1471 | rewind_buffer_queue(&big_buff, extra_bytes); |
mridup | 0:dc55f40eb04f | 1472 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1473 | } |
mridup | 0:dc55f40eb04f | 1474 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1475 | sock_total_count =0; |
mridup | 0:dc55f40eb04f | 1476 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1477 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1478 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 1479 | break; |
mridup | 0:dc55f40eb04f | 1480 | } |
mridup | 0:dc55f40eb04f | 1481 | else if((pStr = (char *)strstr((const char *)&process_buffer,"\r\nERROR: Pending data\r\n")) !=NULL) |
mridup | 0:dc55f40eb04f | 1482 | { |
mridup | 0:dc55f40eb04f | 1483 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1484 | printf("\r\nERROR: PENDING DATA \r\n"); |
mridup | 0:dc55f40eb04f | 1485 | #endif |
mridup | 0:dc55f40eb04f | 1486 | |
mridup | 0:dc55f40eb04f | 1487 | if(*(pStr+23)!='\0') |
mridup | 0:dc55f40eb04f | 1488 | { |
mridup | 0:dc55f40eb04f | 1489 | int len = (uint8_t *)pStr - (uint8_t *)process_buffer; |
mridup | 0:dc55f40eb04f | 1490 | int extra_bytes = Fillptr - (len+23); |
mridup | 0:dc55f40eb04f | 1491 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1492 | rewind_buffer_queue(&big_buff, extra_bytes); |
mridup | 0:dc55f40eb04f | 1493 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1494 | } |
mridup | 0:dc55f40eb04f | 1495 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1496 | sock_total_count =0; |
mridup | 0:dc55f40eb04f | 1497 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1498 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1499 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 1500 | break; |
mridup | 0:dc55f40eb04f | 1501 | } |
mridup | 0:dc55f40eb04f | 1502 | |
mridup | 0:dc55f40eb04f | 1503 | printf("\rERROR DURING SOCK READ\r\n"); |
mridup | 0:dc55f40eb04f | 1504 | sock_total_count=0; |
mridup | 0:dc55f40eb04f | 1505 | SockON_Data_Len=0; |
mridup | 0:dc55f40eb04f | 1506 | SockON_Data_Length=0; |
mridup | 0:dc55f40eb04f | 1507 | status_flag.enable_sock_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1508 | status_flag.stop_event_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1509 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1510 | status_flag.Q_Contains_Data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1511 | enable_pending_data = 0; |
mridup | 0:dc55f40eb04f | 1512 | status_flag.enable_receive_data_chunk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1513 | WIND64_count=0; |
mridup | 0:dc55f40eb04f | 1514 | process_buffer_index =5; |
mridup | 0:dc55f40eb04f | 1515 | //status_flag.enable_query = TRUE; //do we have more data? |
mridup | 0:dc55f40eb04f | 1516 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1517 | status_flag.sock_read_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1518 | if(status_flag.data_pending_sockD) |
mridup | 0:dc55f40eb04f | 1519 | { |
mridup | 0:dc55f40eb04f | 1520 | status_flag.data_pending_sockD=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1521 | number_of_bytes=0; |
mridup | 0:dc55f40eb04f | 1522 | status_flag.switch_by_default_to_command_mode=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1523 | WiFi_switch_to_command_mode(); //switch by default |
mridup | 0:dc55f40eb04f | 1524 | } |
mridup | 0:dc55f40eb04f | 1525 | |
mridup | 0:dc55f40eb04f | 1526 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1527 | break; |
mridup | 0:dc55f40eb04f | 1528 | } |
mridup | 0:dc55f40eb04f | 1529 | } |
mridup | 0:dc55f40eb04f | 1530 | |
mridup | 0:dc55f40eb04f | 1531 | /*now check if end of msg received*/ |
mridup | 0:dc55f40eb04f | 1532 | if(sock_total_count >= SockON_Data_Length) |
mridup | 0:dc55f40eb04f | 1533 | { |
mridup | 0:dc55f40eb04f | 1534 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1535 | printf("\nReached SockON_Data_Len \r\n"); |
mridup | 0:dc55f40eb04f | 1536 | #endif |
mridup | 0:dc55f40eb04f | 1537 | |
mridup | 0:dc55f40eb04f | 1538 | if(sock_total_count > SockON_Data_Length) |
mridup | 0:dc55f40eb04f | 1539 | { |
mridup | 0:dc55f40eb04f | 1540 | int databytes = sock_total_count - SockON_Data_Length; |
mridup | 0:dc55f40eb04f | 1541 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1542 | rewind_buffer_queue(&big_buff, databytes); |
mridup | 0:dc55f40eb04f | 1543 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1544 | memset(process_buffer+(Fillptr - databytes), 0x00, databytes); |
mridup | 0:dc55f40eb04f | 1545 | Fillptr = Fillptr - databytes; |
mridup | 0:dc55f40eb04f | 1546 | } |
mridup | 0:dc55f40eb04f | 1547 | chunk_size = Fillptr; |
mridup | 0:dc55f40eb04f | 1548 | message_size = SockON_Data_Length; |
mridup | 0:dc55f40eb04f | 1549 | memcpy(UserDataBuff, process_buffer, Fillptr); |
mridup | 0:dc55f40eb04f | 1550 | Fillptr = 0; |
mridup | 0:dc55f40eb04f | 1551 | sock_total_count = 0; |
mridup | 0:dc55f40eb04f | 1552 | SockON_Data_Len = 0; |
mridup | 0:dc55f40eb04f | 1553 | status_flag.Q_Contains_Data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1554 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1555 | status_flag.enable_receive_data_chunk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1556 | enable_pending_data = 0; |
mridup | 0:dc55f40eb04f | 1557 | |
mridup | 0:dc55f40eb04f | 1558 | if(status_flag.data_pending_sockD) |
mridup | 0:dc55f40eb04f | 1559 | { |
mridup | 0:dc55f40eb04f | 1560 | // status_flag.data_pending_sockD=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1561 | number_of_bytes=0; |
mridup | 0:dc55f40eb04f | 1562 | sockon_id_user = 0; |
mridup | 0:dc55f40eb04f | 1563 | if(WIND64_count>0) |
mridup | 0:dc55f40eb04f | 1564 | WIND64_count--; //decrease the number of pending WIND:64 Events |
mridup | 0:dc55f40eb04f | 1565 | if(WIND64_count==0) { |
mridup | 0:dc55f40eb04f | 1566 | status_flag.switch_by_default_to_command_mode=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1567 | WiFi_switch_to_command_mode(); //switch by default |
mridup | 0:dc55f40eb04f | 1568 | } |
mridup | 0:dc55f40eb04f | 1569 | status_flag.enable_query = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1570 | } |
mridup | 0:dc55f40eb04f | 1571 | else |
mridup | 0:dc55f40eb04f | 1572 | { |
mridup | 0:dc55f40eb04f | 1573 | status_flag.enable_query = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1574 | sockon_id_user = sockon_query_id; |
mridup | 0:dc55f40eb04f | 1575 | /*@TODO: Do not need to prevent OK push in case of server socket*/ |
mridup | 0:dc55f40eb04f | 1576 | status_flag.prevent_push_OK_event = WIFI_TRUE; //prevent the qeueuing of the OK after this read operation |
mridup | 0:dc55f40eb04f | 1577 | } |
mridup | 0:dc55f40eb04f | 1578 | |
mridup | 0:dc55f40eb04f | 1579 | status_flag.enable_sock_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1580 | status_flag.sock_read_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1581 | Stop_Dequeue(); //Stop dequeue till user callback returns |
mridup | 0:dc55f40eb04f | 1582 | status_flag.Pending_SockON_Callback = WIFI_TRUE; //set this to callback to user with User Buffer pointer |
mridup | 0:dc55f40eb04f | 1583 | //do we have more data? |
mridup | 0:dc55f40eb04f | 1584 | if(status_flag.data_pending_sockD) |
mridup | 0:dc55f40eb04f | 1585 | { |
mridup | 0:dc55f40eb04f | 1586 | status_flag.stop_event_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1587 | status_flag.data_pending_sockD = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1588 | } |
mridup | 0:dc55f40eb04f | 1589 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1590 | break; |
mridup | 0:dc55f40eb04f | 1591 | } |
mridup | 0:dc55f40eb04f | 1592 | |
mridup | 0:dc55f40eb04f | 1593 | if(Fillptr >= MAX_BUFFER_GLOBAL-1) |
mridup | 0:dc55f40eb04f | 1594 | { |
mridup | 0:dc55f40eb04f | 1595 | message_size = SockON_Data_Length; |
mridup | 0:dc55f40eb04f | 1596 | chunk_size = 511; |
mridup | 0:dc55f40eb04f | 1597 | memcpy(UserDataBuff, process_buffer, Fillptr); |
mridup | 0:dc55f40eb04f | 1598 | Fillptr = 0; |
mridup | 0:dc55f40eb04f | 1599 | process_buffer_index = 5; |
mridup | 0:dc55f40eb04f | 1600 | Stop_Dequeue(); |
mridup | 0:dc55f40eb04f | 1601 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1602 | status_flag.Pending_SockON_Callback = WIFI_TRUE; //set this to callback to user with User Buffer pointer |
mridup | 0:dc55f40eb04f | 1603 | } |
mridup | 0:dc55f40eb04f | 1604 | break; |
mridup | 0:dc55f40eb04f | 1605 | } |
mridup | 0:dc55f40eb04f | 1606 | |
mridup | 0:dc55f40eb04f | 1607 | if (status_flag.enable_receive_http_response && pop_buffer_size) // http response enabled |
mridup | 0:dc55f40eb04f | 1608 | { |
mridup | 0:dc55f40eb04f | 1609 | status_flag.sock_read_ongoing = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1610 | if((pStr = (strstr((const char *)process_buffer + process_buffer_index - 6,"\r\nOK\r\n"))) != NULL) |
mridup | 0:dc55f40eb04f | 1611 | { |
mridup | 0:dc55f40eb04f | 1612 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1613 | printf("\r\nOK\r\n"); //http response completed |
mridup | 0:dc55f40eb04f | 1614 | #endif |
mridup | 0:dc55f40eb04f | 1615 | |
mridup | 0:dc55f40eb04f | 1616 | if(*(pStr+7) != '\0') |
mridup | 0:dc55f40eb04f | 1617 | { |
mridup | 0:dc55f40eb04f | 1618 | int len = (uint8_t *)pStr - (uint8_t *)process_buffer; |
mridup | 0:dc55f40eb04f | 1619 | int extra_bytes = Fillptr - (len+6); |
mridup | 0:dc55f40eb04f | 1620 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 1621 | rewind_buffer_queue(&big_buff, extra_bytes); |
mridup | 0:dc55f40eb04f | 1622 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 1623 | |
mridup | 0:dc55f40eb04f | 1624 | memset(process_buffer+len+7, 0x00, extra_bytes); |
mridup | 0:dc55f40eb04f | 1625 | Fillptr = Fillptr - extra_bytes; |
mridup | 0:dc55f40eb04f | 1626 | } |
mridup | 0:dc55f40eb04f | 1627 | |
mridup | 0:dc55f40eb04f | 1628 | memcpy(UserDataBuff, process_buffer, Fillptr); |
mridup | 0:dc55f40eb04f | 1629 | UserDataBuff_index = Fillptr; |
mridup | 0:dc55f40eb04f | 1630 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1631 | status_flag.enable_receive_data_chunk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1632 | status_flag.enable_receive_http_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1633 | Stop_Dequeue(); |
mridup | 0:dc55f40eb04f | 1634 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1635 | status_flag.sock_read_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1636 | status_flag.Q_Contains_Data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1637 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1638 | status_flag.stop_event_dequeue = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1639 | process_buffer_index = 6; |
mridup | 0:dc55f40eb04f | 1640 | memset(process_buffer, 0x00, Fillptr); |
mridup | 0:dc55f40eb04f | 1641 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1642 | |
mridup | 0:dc55f40eb04f | 1643 | if(status_flag.enable_receive_file_response) |
mridup | 0:dc55f40eb04f | 1644 | status_flag.FILE_Data_available = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1645 | else |
mridup | 0:dc55f40eb04f | 1646 | status_flag.HTTP_Data_available=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1647 | } |
mridup | 0:dc55f40eb04f | 1648 | |
mridup | 0:dc55f40eb04f | 1649 | else if(((strstr((const char *)process_buffer + process_buffer_index-6,"ERROR"))) != NULL) |
mridup | 0:dc55f40eb04f | 1650 | { |
mridup | 0:dc55f40eb04f | 1651 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1652 | printf("\r\nERROR\r\n"); |
mridup | 0:dc55f40eb04f | 1653 | #endif |
mridup | 0:dc55f40eb04f | 1654 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1655 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 1656 | status_flag.sock_read_ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1657 | status_flag.enable_receive_data_chunk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1658 | status_flag.Q_Contains_Data = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1659 | status_flag.Q_Contains_Message = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1660 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1661 | process_buffer_index=6; |
mridup | 0:dc55f40eb04f | 1662 | status_flag.enable_receive_http_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1663 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1664 | |
mridup | 0:dc55f40eb04f | 1665 | if(status_flag.enable_receive_file_response) |
mridup | 0:dc55f40eb04f | 1666 | status_flag.FILE_Data_available = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1667 | else |
mridup | 0:dc55f40eb04f | 1668 | status_flag.HTTP_Data_available=WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1669 | } |
mridup | 0:dc55f40eb04f | 1670 | |
mridup | 0:dc55f40eb04f | 1671 | process_buffer_index = Fillptr; |
mridup | 0:dc55f40eb04f | 1672 | if(Fillptr == MAX_BUFFER_GLOBAL-1 ) |
mridup | 0:dc55f40eb04f | 1673 | { |
mridup | 0:dc55f40eb04f | 1674 | memcpy(UserDataBuff, process_buffer, Fillptr); |
mridup | 0:dc55f40eb04f | 1675 | memcpy(&HTTP_Runway_Buff, &UserDataBuff[505], 6); |
mridup | 0:dc55f40eb04f | 1676 | memset(&UserDataBuff[505], 0x00, 6); |
mridup | 0:dc55f40eb04f | 1677 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1678 | memcpy(&process_buffer, &HTTP_Runway_Buff, 6); |
mridup | 0:dc55f40eb04f | 1679 | memset(HTTP_Runway_Buff, 0x00, 6); |
mridup | 0:dc55f40eb04f | 1680 | Fillptr = 6; |
mridup | 0:dc55f40eb04f | 1681 | process_buffer_index = 6; |
mridup | 0:dc55f40eb04f | 1682 | UserDataBuff_index = 505; |
mridup | 0:dc55f40eb04f | 1683 | Stop_Dequeue(); |
mridup | 0:dc55f40eb04f | 1684 | |
mridup | 0:dc55f40eb04f | 1685 | if(status_flag.enable_receive_file_response) |
mridup | 0:dc55f40eb04f | 1686 | status_flag.FILE_Data_available = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1687 | else |
mridup | 0:dc55f40eb04f | 1688 | status_flag.HTTP_Data_available=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1689 | } |
mridup | 0:dc55f40eb04f | 1690 | break; |
mridup | 0:dc55f40eb04f | 1691 | } |
mridup | 0:dc55f40eb04f | 1692 | } |
mridup | 0:dc55f40eb04f | 1693 | if((!status_flag.Q_Contains_Message) && status_flag.enable_receive_wifi_scan_response) |
mridup | 0:dc55f40eb04f | 1694 | { |
mridup | 0:dc55f40eb04f | 1695 | /*now check if end of msg received*/ |
mridup | 0:dc55f40eb04f | 1696 | if((process_buffer[Fillptr-2]==0xD) && (process_buffer[Fillptr-1]==0xA)) |
mridup | 0:dc55f40eb04f | 1697 | { |
mridup | 0:dc55f40eb04f | 1698 | if(scanned_ssids < user_scan_number) |
mridup | 0:dc55f40eb04f | 1699 | { |
mridup | 0:dc55f40eb04f | 1700 | pStr = (char *) strstr((const char *)&process_buffer,"CHAN:"); |
mridup | 0:dc55f40eb04f | 1701 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1702 | { |
mridup | 0:dc55f40eb04f | 1703 | databytes_No[0] = *(pStr + 6) ; |
mridup | 0:dc55f40eb04f | 1704 | databytes_No[1] = *(pStr + 7) ; |
mridup | 0:dc55f40eb04f | 1705 | |
mridup | 0:dc55f40eb04f | 1706 | chan_value = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1707 | } |
mridup | 0:dc55f40eb04f | 1708 | |
mridup | 0:dc55f40eb04f | 1709 | wifi_scanned_list[scanned_ssids].channel_num = chan_value; |
mridup | 0:dc55f40eb04f | 1710 | |
mridup | 0:dc55f40eb04f | 1711 | pStr = (char *) strstr((const char *)&process_buffer,"RSSI:"); |
mridup | 0:dc55f40eb04f | 1712 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1713 | { |
mridup | 0:dc55f40eb04f | 1714 | databytes_No[0] = *(pStr + 7) ; |
mridup | 0:dc55f40eb04f | 1715 | databytes_No[1] = *(pStr + 8) ; |
mridup | 0:dc55f40eb04f | 1716 | |
mridup | 0:dc55f40eb04f | 1717 | rssi_value = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1718 | } |
mridup | 0:dc55f40eb04f | 1719 | |
mridup | 0:dc55f40eb04f | 1720 | wifi_scanned_list[scanned_ssids].rssi = -(rssi_value); |
mridup | 0:dc55f40eb04f | 1721 | |
mridup | 0:dc55f40eb04f | 1722 | pStr = (char *) strstr((const char *)&process_buffer,"SSID:"); |
mridup | 0:dc55f40eb04f | 1723 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1724 | { |
mridup | 0:dc55f40eb04f | 1725 | index = 7; |
mridup | 0:dc55f40eb04f | 1726 | while(*(pStr + index) != 0x27) |
mridup | 0:dc55f40eb04f | 1727 | { |
mridup | 0:dc55f40eb04f | 1728 | wifi_scanned_list[scanned_ssids].ssid[index-7] = *(pStr + index); |
mridup | 0:dc55f40eb04f | 1729 | index++; |
mridup | 0:dc55f40eb04f | 1730 | if(index==35) break; //max ssid lenght is 30 characters |
mridup | 0:dc55f40eb04f | 1731 | } |
mridup | 0:dc55f40eb04f | 1732 | } |
mridup | 0:dc55f40eb04f | 1733 | |
mridup | 0:dc55f40eb04f | 1734 | pStr = (char *) strstr((const char *)&process_buffer,"WPA "); |
mridup | 0:dc55f40eb04f | 1735 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1736 | { |
mridup | 0:dc55f40eb04f | 1737 | wifi_scanned_list[scanned_ssids].sec_type.wpa = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1738 | } else |
mridup | 0:dc55f40eb04f | 1739 | wifi_scanned_list[scanned_ssids].sec_type.wpa = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1740 | |
mridup | 0:dc55f40eb04f | 1741 | pStr = (char *) strstr((const char *)&process_buffer,"WPA2 "); |
mridup | 0:dc55f40eb04f | 1742 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1743 | { |
mridup | 0:dc55f40eb04f | 1744 | wifi_scanned_list[scanned_ssids].sec_type.wpa2 = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1745 | } else |
mridup | 0:dc55f40eb04f | 1746 | wifi_scanned_list[scanned_ssids].sec_type.wpa2 = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1747 | |
mridup | 0:dc55f40eb04f | 1748 | pStr = (char *) strstr((const char *)&process_buffer,"WPS "); |
mridup | 0:dc55f40eb04f | 1749 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1750 | { |
mridup | 0:dc55f40eb04f | 1751 | wifi_scanned_list[scanned_ssids].sec_type.wps = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1752 | } else |
mridup | 0:dc55f40eb04f | 1753 | wifi_scanned_list[scanned_ssids].sec_type.wps = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1754 | |
mridup | 0:dc55f40eb04f | 1755 | scanned_ssids++;//increment total_networks |
mridup | 0:dc55f40eb04f | 1756 | //callSpwfSADevice_debug(spwf_dev_,(const char*)scanned_ssids); |
mridup | 0:dc55f40eb04f | 1757 | } |
mridup | 0:dc55f40eb04f | 1758 | |
mridup | 0:dc55f40eb04f | 1759 | //end of one line from SCAN result |
mridup | 0:dc55f40eb04f | 1760 | pStr = (char *) strstr((const char *)&process_buffer,"ERROR"); |
mridup | 0:dc55f40eb04f | 1761 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1762 | { |
mridup | 0:dc55f40eb04f | 1763 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1764 | printf("ERROR Scan Failed"); |
mridup | 0:dc55f40eb04f | 1765 | #endif |
mridup | 0:dc55f40eb04f | 1766 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1767 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1768 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1769 | status_flag.enable_receive_wifi_scan_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1770 | status_flag.Scan_Ongoing = WIFI_FALSE; //Enable next scan |
mridup | 0:dc55f40eb04f | 1771 | AT_RESPONSE = WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 1772 | break; |
mridup | 0:dc55f40eb04f | 1773 | } |
mridup | 0:dc55f40eb04f | 1774 | |
mridup | 0:dc55f40eb04f | 1775 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1776 | printf((const char*)process_buffer); |
mridup | 0:dc55f40eb04f | 1777 | #endif |
mridup | 0:dc55f40eb04f | 1778 | |
mridup | 0:dc55f40eb04f | 1779 | callSpwfSADevice_debug(spwf_dev_,(const char*)process_buffer); |
mridup | 0:dc55f40eb04f | 1780 | |
mridup | 0:dc55f40eb04f | 1781 | if(((strstr((const char *)process_buffer,"OK\r\n"))) != NULL /*|| scanned_ssids==10*/)/*Max 10 networks supported*/ |
mridup | 0:dc55f40eb04f | 1782 | { |
mridup | 0:dc55f40eb04f | 1783 | //print and go for next line |
mridup | 0:dc55f40eb04f | 1784 | //If Any part of scan line contains "OK" this will exit!! |
mridup | 0:dc55f40eb04f | 1785 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1786 | printf("\nOK\r\n"); |
mridup | 0:dc55f40eb04f | 1787 | #endif |
mridup | 0:dc55f40eb04f | 1788 | status_flag.Scan_Ongoing = WIFI_FALSE; //Enable next scan |
mridup | 0:dc55f40eb04f | 1789 | scanned_ssids=0; |
mridup | 0:dc55f40eb04f | 1790 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1791 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1792 | status_flag.enable_receive_wifi_scan_response = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1793 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1794 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1795 | break; |
mridup | 0:dc55f40eb04f | 1796 | } |
mridup | 0:dc55f40eb04f | 1797 | |
mridup | 0:dc55f40eb04f | 1798 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1799 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1800 | } |
mridup | 0:dc55f40eb04f | 1801 | |
mridup | 0:dc55f40eb04f | 1802 | if(Fillptr>=MAX_BUFFER_GLOBAL-1) |
mridup | 0:dc55f40eb04f | 1803 | { |
mridup | 0:dc55f40eb04f | 1804 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1805 | printf("\rHTTP: process_buffer Max Buffer Size reached\r\n"); |
mridup | 0:dc55f40eb04f | 1806 | #endif |
mridup | 0:dc55f40eb04f | 1807 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1808 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 1809 | } |
mridup | 0:dc55f40eb04f | 1810 | } |
mridup | 0:dc55f40eb04f | 1811 | |
mridup | 0:dc55f40eb04f | 1812 | if((!status_flag.Q_Contains_Message) && status_flag.enable_fw_update_read) |
mridup | 0:dc55f40eb04f | 1813 | { |
mridup | 0:dc55f40eb04f | 1814 | #ifdef DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1815 | printf("*"); //print * till finish |
mridup | 0:dc55f40eb04f | 1816 | #endif |
mridup | 0:dc55f40eb04f | 1817 | |
mridup | 0:dc55f40eb04f | 1818 | pStr = (char *) strstr((const char *)process_buffer,"Complete!"); |
mridup | 0:dc55f40eb04f | 1819 | |
mridup | 0:dc55f40eb04f | 1820 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1821 | { |
mridup | 0:dc55f40eb04f | 1822 | #ifdef DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1823 | printf("\r\nUpdate complete\r\n"); |
mridup | 0:dc55f40eb04f | 1824 | #endif |
mridup | 0:dc55f40eb04f | 1825 | status_flag.AT_Response_Received = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1826 | AT_RESPONSE = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 1827 | status_flag.enable_fw_update_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1828 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1829 | memset(process_buffer, 0x00, strlen((char const *)process_buffer)); |
mridup | 0:dc55f40eb04f | 1830 | } |
mridup | 0:dc55f40eb04f | 1831 | if(Fillptr>=MAX_BUFFER_GLOBAL) |
mridup | 0:dc55f40eb04f | 1832 | { |
mridup | 0:dc55f40eb04f | 1833 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1834 | memset(process_buffer, 0x00, strlen((char const *)process_buffer)); |
mridup | 0:dc55f40eb04f | 1835 | } |
mridup | 0:dc55f40eb04f | 1836 | |
mridup | 0:dc55f40eb04f | 1837 | //No change of state till we get "+WIND:17:F/W update complete!" |
mridup | 0:dc55f40eb04f | 1838 | } |
mridup | 0:dc55f40eb04f | 1839 | |
mridup | 0:dc55f40eb04f | 1840 | /*else no other case is satisfied at least do the following*/ |
mridup | 0:dc55f40eb04f | 1841 | { |
mridup | 0:dc55f40eb04f | 1842 | if(Fillptr>=MAX_BUFFER_GLOBAL-1) |
mridup | 0:dc55f40eb04f | 1843 | { |
mridup | 0:dc55f40eb04f | 1844 | Fillptr=0; |
mridup | 0:dc55f40eb04f | 1845 | memset(process_buffer, 0x00,MAX_BUFFER_GLOBAL-1); |
mridup | 0:dc55f40eb04f | 1846 | } |
mridup | 0:dc55f40eb04f | 1847 | } |
mridup | 0:dc55f40eb04f | 1848 | } |
mridup | 0:dc55f40eb04f | 1849 | } |
mridup | 0:dc55f40eb04f | 1850 | |
mridup | 0:dc55f40eb04f | 1851 | /** |
mridup | 0:dc55f40eb04f | 1852 | * @brief Process_Wind_Indication_Cmd |
mridup | 0:dc55f40eb04f | 1853 | * Process Wind indication command |
mridup | 0:dc55f40eb04f | 1854 | * @param process_buff_ptr: pointer of WiFi indication buffer |
mridup | 0:dc55f40eb04f | 1855 | * @retval None |
mridup | 0:dc55f40eb04f | 1856 | */ |
mridup | 0:dc55f40eb04f | 1857 | |
mridup | 0:dc55f40eb04f | 1858 | void Process_Wind_Indication(uint8_t *process_buff_ptr) |
mridup | 0:dc55f40eb04f | 1859 | { |
mridup | 0:dc55f40eb04f | 1860 | char * pStr = (char*)process_buff_ptr; |
mridup | 0:dc55f40eb04f | 1861 | char Indication_No[2]; |
mridup | 0:dc55f40eb04f | 1862 | char databytes_No[4]; |
mridup | 0:dc55f40eb04f | 1863 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1864 | printf((const char*)process_buff_ptr); |
mridup | 0:dc55f40eb04f | 1865 | #endif |
mridup | 0:dc55f40eb04f | 1866 | //callSpwfSADevice_debug(spwf_dev_,(const char*)process_buff_ptr); |
mridup | 0:dc55f40eb04f | 1867 | |
mridup | 0:dc55f40eb04f | 1868 | char * ptr_offset; |
mridup | 0:dc55f40eb04f | 1869 | int i; |
mridup | 0:dc55f40eb04f | 1870 | |
mridup | 0:dc55f40eb04f | 1871 | uint32_t wind55_data_len=0; |
mridup | 0:dc55f40eb04f | 1872 | WiFi_Indication_t Wind_No = Undefine_Indication; |
mridup | 0:dc55f40eb04f | 1873 | |
mridup | 0:dc55f40eb04f | 1874 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1875 | { |
mridup | 0:dc55f40eb04f | 1876 | pStr = (char *) strstr((const char *)(pStr),"WIND:");/////// |
mridup | 0:dc55f40eb04f | 1877 | |
mridup | 0:dc55f40eb04f | 1878 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 1879 | { |
mridup | 0:dc55f40eb04f | 1880 | Indication_No[0] = *(pStr + 5) ; |
mridup | 0:dc55f40eb04f | 1881 | Indication_No[1] = *(pStr + 6) ; |
mridup | 0:dc55f40eb04f | 1882 | |
mridup | 0:dc55f40eb04f | 1883 | if( Indication_No[1] == ':') |
mridup | 0:dc55f40eb04f | 1884 | { |
mridup | 0:dc55f40eb04f | 1885 | status_flag.Single_Digit_Indication = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1886 | /* Convert char to integer */ |
mridup | 0:dc55f40eb04f | 1887 | Wind_No = (WiFi_Indication_t)(Indication_No[0] - '0'); |
mridup | 0:dc55f40eb04f | 1888 | } |
mridup | 0:dc55f40eb04f | 1889 | else |
mridup | 0:dc55f40eb04f | 1890 | { |
mridup | 0:dc55f40eb04f | 1891 | status_flag.Single_Digit_Indication = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 1892 | /* Convert char to integer */ |
mridup | 0:dc55f40eb04f | 1893 | Wind_No = (WiFi_Indication_t)(((Indication_No[0] - '0') * 10 ) + (Indication_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1894 | } |
mridup | 0:dc55f40eb04f | 1895 | |
mridup | 0:dc55f40eb04f | 1896 | event_s.wind = Wind_No; |
mridup | 0:dc55f40eb04f | 1897 | event_s.event = WIFI_WIND_EVENT; |
mridup | 0:dc55f40eb04f | 1898 | |
mridup | 0:dc55f40eb04f | 1899 | switch (Wind_No) |
mridup | 0:dc55f40eb04f | 1900 | { |
mridup | 0:dc55f40eb04f | 1901 | case SockON_Data_Pending: /*WIND:55*/ |
mridup | 0:dc55f40eb04f | 1902 | |
mridup | 0:dc55f40eb04f | 1903 | /*+WIND:55:Pending Data:%d:%d*/ |
mridup | 0:dc55f40eb04f | 1904 | ptr_offset = (char *) strstr((const char *)&process_buffer,"Data:"); |
mridup | 0:dc55f40eb04f | 1905 | |
mridup | 0:dc55f40eb04f | 1906 | /*Need to find out which socket ID has data pending*/ |
mridup | 0:dc55f40eb04f | 1907 | databytes_No[0] = *(ptr_offset + 5); |
mridup | 0:dc55f40eb04f | 1908 | |
mridup | 0:dc55f40eb04f | 1909 | SocketId = (databytes_No[0] - '0');//Max number of sockets is 8 (so single digit) |
mridup | 0:dc55f40eb04f | 1910 | event_s.socket_id = SocketId; |
mridup | 0:dc55f40eb04f | 1911 | enable_pending_data = 1; |
mridup | 0:dc55f40eb04f | 1912 | |
mridup | 0:dc55f40eb04f | 1913 | /* EQ. Check for ENC string to identify TLS case. Set enable_query */ |
mridup | 0:dc55f40eb04f | 1914 | if ( (*(ptr_offset + 7) == 'E') && (*(ptr_offset + 8) == 'N') && (*(ptr_offset + 9) == 'C') ) |
mridup | 0:dc55f40eb04f | 1915 | { |
mridup | 0:dc55f40eb04f | 1916 | event_s.enc = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 1917 | } |
mridup | 0:dc55f40eb04f | 1918 | else |
mridup | 0:dc55f40eb04f | 1919 | { |
mridup | 0:dc55f40eb04f | 1920 | //And find the length of the data |
mridup | 0:dc55f40eb04f | 1921 | databytes_No[0] = *(ptr_offset + 7); |
mridup | 0:dc55f40eb04f | 1922 | databytes_No[1] = *(ptr_offset + 8); |
mridup | 0:dc55f40eb04f | 1923 | databytes_No[2] = *(ptr_offset + 9); |
mridup | 0:dc55f40eb04f | 1924 | databytes_No[3] = *(ptr_offset + 10); |
mridup | 0:dc55f40eb04f | 1925 | |
mridup | 0:dc55f40eb04f | 1926 | if( databytes_No[1] == '\r') |
mridup | 0:dc55f40eb04f | 1927 | { |
mridup | 0:dc55f40eb04f | 1928 | wind55_data_len = databytes_No[0] - '0'; |
mridup | 0:dc55f40eb04f | 1929 | } |
mridup | 0:dc55f40eb04f | 1930 | else if( databytes_No[2] == '\r') |
mridup | 0:dc55f40eb04f | 1931 | { |
mridup | 0:dc55f40eb04f | 1932 | wind55_data_len = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1933 | } |
mridup | 0:dc55f40eb04f | 1934 | else if( databytes_No[3] == '\r') //it's a 3-digit number |
mridup | 0:dc55f40eb04f | 1935 | { |
mridup | 0:dc55f40eb04f | 1936 | wind55_data_len = (((databytes_No[0] - '0') * 100 ) + ((databytes_No[1] - '0') * 10 ) + (databytes_No[2] - '0')); |
mridup | 0:dc55f40eb04f | 1937 | } |
mridup | 0:dc55f40eb04f | 1938 | else //it's a 4-digit number |
mridup | 0:dc55f40eb04f | 1939 | { |
mridup | 0:dc55f40eb04f | 1940 | wind55_data_len = ((databytes_No[0] - '0') * 1000 ) + ((databytes_No[1] - '0') * 100 ) + ((databytes_No[2] - '0') * 10) + (databytes_No[3] - '0'); |
mridup | 0:dc55f40eb04f | 1941 | } |
mridup | 0:dc55f40eb04f | 1942 | |
mridup | 0:dc55f40eb04f | 1943 | event_s.data_length = wind55_data_len; |
mridup | 0:dc55f40eb04f | 1944 | wind55_data_len = 0; |
mridup | 0:dc55f40eb04f | 1945 | } |
mridup | 0:dc55f40eb04f | 1946 | break; |
mridup | 0:dc55f40eb04f | 1947 | |
mridup | 0:dc55f40eb04f | 1948 | case SockON_Server_Socket_Closed: |
mridup | 0:dc55f40eb04f | 1949 | //Find the id of the socket closed |
mridup | 0:dc55f40eb04f | 1950 | //ptr_offset = (char *) strstr((const char *)pStr,"+WIND:58"); |
mridup | 0:dc55f40eb04f | 1951 | databytes_No[0] = *(pStr + 22) ; |
mridup | 0:dc55f40eb04f | 1952 | databytes_No[1] = *(pStr + 23) ; |
mridup | 0:dc55f40eb04f | 1953 | if( databytes_No[1] == '\r') |
mridup | 0:dc55f40eb04f | 1954 | { |
mridup | 0:dc55f40eb04f | 1955 | remote_socket_closed_id = databytes_No[0] - '0'; |
mridup | 0:dc55f40eb04f | 1956 | } |
mridup | 0:dc55f40eb04f | 1957 | else |
mridup | 0:dc55f40eb04f | 1958 | { |
mridup | 0:dc55f40eb04f | 1959 | remote_socket_closed_id = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 1960 | } |
mridup | 0:dc55f40eb04f | 1961 | event_s.socket_id = remote_socket_closed_id; |
mridup | 0:dc55f40eb04f | 1962 | break; |
mridup | 0:dc55f40eb04f | 1963 | |
mridup | 0:dc55f40eb04f | 1964 | case SockD_Pending_Data: |
mridup | 0:dc55f40eb04f | 1965 | if(status_flag.prevent_push_WIFI_event) |
mridup | 0:dc55f40eb04f | 1966 | { |
mridup | 0:dc55f40eb04f | 1967 | #ifdef DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 1968 | printf(">>IG\r\n"); |
mridup | 0:dc55f40eb04f | 1969 | #endif |
mridup | 0:dc55f40eb04f | 1970 | return; ///exit if push is prevented |
mridup | 0:dc55f40eb04f | 1971 | } |
mridup | 0:dc55f40eb04f | 1972 | |
mridup | 0:dc55f40eb04f | 1973 | /* @TODO: Do something to delay the de-Q of pending packets so that any further |
mridup | 0:dc55f40eb04f | 1974 | pending WIND64 packets are allowed to arrive and get Q-ed */ |
mridup | 0:dc55f40eb04f | 1975 | |
mridup | 0:dc55f40eb04f | 1976 | if(status_flag.event_deQ_x_wind64) //which means there is already a previous WIND64 |
mridup | 0:dc55f40eb04f | 1977 | { |
mridup | 0:dc55f40eb04f | 1978 | wind64_DQ_wait=0; //reset the timer |
mridup | 0:dc55f40eb04f | 1979 | } |
mridup | 0:dc55f40eb04f | 1980 | else |
mridup | 0:dc55f40eb04f | 1981 | { |
mridup | 0:dc55f40eb04f | 1982 | status_flag.stop_event_dequeue = WIFI_TRUE;//Stop the event de-Q |
mridup | 0:dc55f40eb04f | 1983 | status_flag.event_deQ_x_wind64 = WIFI_TRUE;//Set the flag |
mridup | 0:dc55f40eb04f | 1984 | } |
mridup | 0:dc55f40eb04f | 1985 | //Start Reading data from Client Here. |
mridup | 0:dc55f40eb04f | 1986 | // +WIND:64:Sockd Pending Data:1:130:130 |
mridup | 0:dc55f40eb04f | 1987 | ptr_offset = (char *) strstr((const char *)&process_buffer,"Data:"); |
mridup | 0:dc55f40eb04f | 1988 | |
mridup | 0:dc55f40eb04f | 1989 | //Store the packet number |
mridup | 0:dc55f40eb04f | 1990 | databytes_No[0] = *(ptr_offset + 5) ; |
mridup | 0:dc55f40eb04f | 1991 | event_s.wind64_pending_packet_no = databytes_No[0] - '0'; |
mridup | 0:dc55f40eb04f | 1992 | |
mridup | 0:dc55f40eb04f | 1993 | //And now find the data length |
mridup | 0:dc55f40eb04f | 1994 | databytes_No[0] = *(ptr_offset + 8) ;//points to number just after 2nd colon |
mridup | 0:dc55f40eb04f | 1995 | databytes_No[1] = *(ptr_offset + 9) ; |
mridup | 0:dc55f40eb04f | 1996 | databytes_No[2] = *(ptr_offset + 10) ; |
mridup | 0:dc55f40eb04f | 1997 | databytes_No[3] = *(ptr_offset + 11) ; |
mridup | 0:dc55f40eb04f | 1998 | |
mridup | 0:dc55f40eb04f | 1999 | if( databytes_No[0] == ':')//then it is a 1 digit number |
mridup | 0:dc55f40eb04f | 2000 | { |
mridup | 0:dc55f40eb04f | 2001 | databytes_No[0] = *(ptr_offset + 7) ; |
mridup | 0:dc55f40eb04f | 2002 | databytes_No[1] = *(ptr_offset + 8) ; |
mridup | 0:dc55f40eb04f | 2003 | } |
mridup | 0:dc55f40eb04f | 2004 | else if(databytes_No[1] == ':')//two digit number |
mridup | 0:dc55f40eb04f | 2005 | { |
mridup | 0:dc55f40eb04f | 2006 | databytes_No[0] = *(ptr_offset + 7) ; |
mridup | 0:dc55f40eb04f | 2007 | databytes_No[1] = *(ptr_offset + 8) ; |
mridup | 0:dc55f40eb04f | 2008 | databytes_No[2] = *(ptr_offset + 9) ; |
mridup | 0:dc55f40eb04f | 2009 | //databytes_No[3] = *(ptr_offset + 13) ; |
mridup | 0:dc55f40eb04f | 2010 | } |
mridup | 0:dc55f40eb04f | 2011 | else if(databytes_No[2] == ':')//three digit number |
mridup | 0:dc55f40eb04f | 2012 | { |
mridup | 0:dc55f40eb04f | 2013 | databytes_No[0] = *(ptr_offset + 7) ; |
mridup | 0:dc55f40eb04f | 2014 | databytes_No[1] = *(ptr_offset + 8) ; |
mridup | 0:dc55f40eb04f | 2015 | databytes_No[2] = *(ptr_offset + 9) ; |
mridup | 0:dc55f40eb04f | 2016 | databytes_No[3] = *(ptr_offset + 10) ; |
mridup | 0:dc55f40eb04f | 2017 | } |
mridup | 0:dc55f40eb04f | 2018 | else if(databytes_No[3] == ':')//four digit number |
mridup | 0:dc55f40eb04f | 2019 | { |
mridup | 0:dc55f40eb04f | 2020 | databytes_No[0] = *(ptr_offset + 7) ; |
mridup | 0:dc55f40eb04f | 2021 | databytes_No[1] = *(ptr_offset + 8) ; |
mridup | 0:dc55f40eb04f | 2022 | databytes_No[2] = *(ptr_offset + 9) ; |
mridup | 0:dc55f40eb04f | 2023 | databytes_No[3] = *(ptr_offset + 10) ; |
mridup | 0:dc55f40eb04f | 2024 | } |
mridup | 0:dc55f40eb04f | 2025 | |
mridup | 0:dc55f40eb04f | 2026 | if( databytes_No[1] == ':') |
mridup | 0:dc55f40eb04f | 2027 | { |
mridup | 0:dc55f40eb04f | 2028 | interim_number_of_bytes = databytes_No[0] - '0'; |
mridup | 0:dc55f40eb04f | 2029 | } |
mridup | 0:dc55f40eb04f | 2030 | else if( databytes_No[2] == ':') |
mridup | 0:dc55f40eb04f | 2031 | { |
mridup | 0:dc55f40eb04f | 2032 | interim_number_of_bytes = (((databytes_No[0] - '0') * 10 ) + (databytes_No[1] - '0')); |
mridup | 0:dc55f40eb04f | 2033 | } |
mridup | 0:dc55f40eb04f | 2034 | else if( databytes_No[3] == ':') |
mridup | 0:dc55f40eb04f | 2035 | { |
mridup | 0:dc55f40eb04f | 2036 | interim_number_of_bytes = (((databytes_No[0] - '0') * 100 ) + ((databytes_No[1] - '0') * 10 ) + (databytes_No[2] - '0')); |
mridup | 0:dc55f40eb04f | 2037 | } |
mridup | 0:dc55f40eb04f | 2038 | else //it's a 4-digit number |
mridup | 0:dc55f40eb04f | 2039 | { |
mridup | 0:dc55f40eb04f | 2040 | interim_number_of_bytes = (((databytes_No[0] - '0') * 1000 ) + ((databytes_No[1] - '0') * 100 ) + ((databytes_No[2] - '0') * 10 ) + (databytes_No[3] - '0')); |
mridup | 0:dc55f40eb04f | 2041 | } |
mridup | 0:dc55f40eb04f | 2042 | |
mridup | 0:dc55f40eb04f | 2043 | if(WIND64_count >= 1) /*WIND:64 came after pop of previous event and switch to data mode was issued*/ |
mridup | 0:dc55f40eb04f | 2044 | /*WIND:64 came before pop of previous event and switch to data mode was issued*/ |
mridup | 0:dc55f40eb04f | 2045 | { |
mridup | 0:dc55f40eb04f | 2046 | event_s.data_length = interim_number_of_bytes;// - (730*WIND64_count); |
mridup | 0:dc55f40eb04f | 2047 | WIND64_count++; //Count of the number of queued WIND:64 Events |
mridup | 0:dc55f40eb04f | 2048 | interim_number_of_bytes = 0; |
mridup | 0:dc55f40eb04f | 2049 | break; |
mridup | 0:dc55f40eb04f | 2050 | } |
mridup | 0:dc55f40eb04f | 2051 | else |
mridup | 0:dc55f40eb04f | 2052 | { |
mridup | 0:dc55f40eb04f | 2053 | event_s.data_length = interim_number_of_bytes; |
mridup | 0:dc55f40eb04f | 2054 | WIND64_count++; //Count of the number of queued WIND:64 Events |
mridup | 0:dc55f40eb04f | 2055 | interim_number_of_bytes = 0; |
mridup | 0:dc55f40eb04f | 2056 | } |
mridup | 0:dc55f40eb04f | 2057 | break; |
mridup | 0:dc55f40eb04f | 2058 | |
mridup | 0:dc55f40eb04f | 2059 | case In_Command_Mode: |
mridup | 0:dc55f40eb04f | 2060 | status_flag.command_mode= WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2061 | status_flag.data_mode= WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2062 | WIND64_count=0; //reset the WIND64 count since the previous data mode would have consumed all data |
mridup | 0:dc55f40eb04f | 2063 | break; |
mridup | 0:dc55f40eb04f | 2064 | |
mridup | 0:dc55f40eb04f | 2065 | case In_Data_Mode: |
mridup | 0:dc55f40eb04f | 2066 | status_flag.command_mode = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2067 | status_flag.data_mode = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2068 | |
mridup | 0:dc55f40eb04f | 2069 | if(status_flag.switch_by_default_to_command_mode == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 2070 | { |
mridup | 0:dc55f40eb04f | 2071 | if(!status_flag.command_mode) |
mridup | 0:dc55f40eb04f | 2072 | { |
mridup | 0:dc55f40eb04f | 2073 | WiFi_switch_to_command_mode();//switch by default |
mridup | 0:dc55f40eb04f | 2074 | } |
mridup | 0:dc55f40eb04f | 2075 | } |
mridup | 0:dc55f40eb04f | 2076 | if(status_flag.data_pending_sockD == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 2077 | { |
mridup | 0:dc55f40eb04f | 2078 | |
mridup | 0:dc55f40eb04f | 2079 | process_buffer_index =5; |
mridup | 0:dc55f40eb04f | 2080 | status_flag.enable_sock_read = WIFI_TRUE;//now data will start coming |
mridup | 0:dc55f40eb04f | 2081 | //Set the data-length to read |
mridup | 0:dc55f40eb04f | 2082 | SockON_Data_Length = number_of_bytes; |
mridup | 0:dc55f40eb04f | 2083 | } |
mridup | 0:dc55f40eb04f | 2084 | break; |
mridup | 0:dc55f40eb04f | 2085 | |
mridup | 0:dc55f40eb04f | 2086 | case WiFi__MiniAP_Associated: |
mridup | 0:dc55f40eb04f | 2087 | //Find out which client joined by parsing the WIND //+WIND:28 |
mridup | 0:dc55f40eb04f | 2088 | ptr_offset = (char *) strstr((const char *)&process_buffer,"+WIND:28"); |
mridup | 0:dc55f40eb04f | 2089 | for(i=17;i<=33;i++) |
mridup | 0:dc55f40eb04f | 2090 | client_MAC_address[i-17] = *(ptr_offset + i) ; |
mridup | 0:dc55f40eb04f | 2091 | WiFi_WIND_State.WiFiAPClientJoined = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2092 | break; |
mridup | 0:dc55f40eb04f | 2093 | |
mridup | 0:dc55f40eb04f | 2094 | case WiFi_MiniAP_Disassociated: |
mridup | 0:dc55f40eb04f | 2095 | //Find out which client left by parsing the WIND //+WIND:72 |
mridup | 0:dc55f40eb04f | 2096 | ptr_offset = (char *) strstr((const char *)&process_buffer,"+WIND:72"); |
mridup | 0:dc55f40eb04f | 2097 | for(i=17;i<=33;i++) |
mridup | 0:dc55f40eb04f | 2098 | client_MAC_address[i-17] = *(ptr_offset + i) ; |
mridup | 0:dc55f40eb04f | 2099 | WiFi_WIND_State.WiFiAPClientLeft = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2100 | break; |
mridup | 0:dc55f40eb04f | 2101 | |
mridup | 0:dc55f40eb04f | 2102 | case Console_Active: |
mridup | 0:dc55f40eb04f | 2103 | case Poweron : |
mridup | 0:dc55f40eb04f | 2104 | case WiFi_Reset: |
mridup | 0:dc55f40eb04f | 2105 | case Watchdog_Running: |
mridup | 0:dc55f40eb04f | 2106 | case Heap_Too_Small: |
mridup | 0:dc55f40eb04f | 2107 | case WiFi_Hardware_Dead: |
mridup | 0:dc55f40eb04f | 2108 | case Watchdog_Terminating: |
mridup | 0:dc55f40eb04f | 2109 | case SysTickConfigure: |
mridup | 0:dc55f40eb04f | 2110 | case Hard_Fault: |
mridup | 0:dc55f40eb04f | 2111 | case StackOverflow: |
mridup | 0:dc55f40eb04f | 2112 | case MallocFailed: |
mridup | 0:dc55f40eb04f | 2113 | case Error: |
mridup | 0:dc55f40eb04f | 2114 | case WiFi_PS_Mode_Failure: |
mridup | 0:dc55f40eb04f | 2115 | case CopyrightInfo: |
mridup | 0:dc55f40eb04f | 2116 | case WiFi_BSS_Regained: |
mridup | 0:dc55f40eb04f | 2117 | case WiFi_Signal_LOW: |
mridup | 0:dc55f40eb04f | 2118 | case WiFi_Signal_OK: |
mridup | 0:dc55f40eb04f | 2119 | case FW_update: |
mridup | 0:dc55f40eb04f | 2120 | case Encryption_key_Not_Recognized: |
mridup | 0:dc55f40eb04f | 2121 | case WiFi_Join: |
mridup | 0:dc55f40eb04f | 2122 | case JOINFAILED: |
mridup | 0:dc55f40eb04f | 2123 | case WiFi_Scanning: |
mridup | 0:dc55f40eb04f | 2124 | case SCANBLEWUP: |
mridup | 0:dc55f40eb04f | 2125 | case SCANFAILED: |
mridup | 0:dc55f40eb04f | 2126 | case WiFi_Up: |
mridup | 0:dc55f40eb04f | 2127 | case WiFi_Association_Successful: |
mridup | 0:dc55f40eb04f | 2128 | case WiFi_Started_MiniAP_Mode: |
mridup | 0:dc55f40eb04f | 2129 | case Start_Failed : |
mridup | 0:dc55f40eb04f | 2130 | case WiFi_EXCEPTION : |
mridup | 0:dc55f40eb04f | 2131 | case WiFi_Hardware_Started : |
mridup | 0:dc55f40eb04f | 2132 | case WiFi_BSS_LOST: |
mridup | 0:dc55f40eb04f | 2133 | case WiFi_Unhandled_Event: |
mridup | 0:dc55f40eb04f | 2134 | case Scan_Complete: |
mridup | 0:dc55f40eb04f | 2135 | case WiFi_UNHANDLED_IND: |
mridup | 0:dc55f40eb04f | 2136 | case WiFi_UNHANDLED: |
mridup | 0:dc55f40eb04f | 2137 | case WiFi_Powered_Down: |
mridup | 0:dc55f40eb04f | 2138 | case WiFi_MiniAP_Mode : |
mridup | 0:dc55f40eb04f | 2139 | case WiFi_Deauthentication: |
mridup | 0:dc55f40eb04f | 2140 | case WiFi_Disassociation: |
mridup | 0:dc55f40eb04f | 2141 | case RX_MGMT: |
mridup | 0:dc55f40eb04f | 2142 | case RX_DATA: |
mridup | 0:dc55f40eb04f | 2143 | case RX_UNK: |
mridup | 0:dc55f40eb04f | 2144 | case DOT11_AUTHILLEGAL: |
mridup | 0:dc55f40eb04f | 2145 | case Creating_PSK: |
mridup | 0:dc55f40eb04f | 2146 | case WPA_Terminated : |
mridup | 0:dc55f40eb04f | 2147 | case WPA_Supplicant_Failed: |
mridup | 0:dc55f40eb04f | 2148 | case WPA_Handshake_Complete: |
mridup | 0:dc55f40eb04f | 2149 | case GPIO_line: |
mridup | 0:dc55f40eb04f | 2150 | case Wakeup: |
mridup | 0:dc55f40eb04f | 2151 | case Factory_debug: |
mridup | 0:dc55f40eb04f | 2152 | case Remote_Configuration: |
mridup | 0:dc55f40eb04f | 2153 | break; |
mridup | 0:dc55f40eb04f | 2154 | default: |
mridup | 0:dc55f40eb04f | 2155 | break; |
mridup | 0:dc55f40eb04f | 2156 | } |
mridup | 0:dc55f40eb04f | 2157 | memset(process_buffer, 0x00, MAX_BUFFER_GLOBAL); |
mridup | 0:dc55f40eb04f | 2158 | } |
mridup | 0:dc55f40eb04f | 2159 | } |
mridup | 0:dc55f40eb04f | 2160 | } |
mridup | 0:dc55f40eb04f | 2161 | |
mridup | 0:dc55f40eb04f | 2162 | /** |
mridup | 0:dc55f40eb04f | 2163 | * @brief Process_Dequeued_Wind_Indication |
mridup | 0:dc55f40eb04f | 2164 | * Process Wind Indication after popping from Queue |
mridup | 0:dc55f40eb04f | 2165 | * @param event_pop_s1 popped event contents |
mridup | 0:dc55f40eb04f | 2166 | * @retval None |
mridup | 0:dc55f40eb04f | 2167 | */ |
mridup | 0:dc55f40eb04f | 2168 | |
mridup | 0:dc55f40eb04f | 2169 | void Process_WiFi_Indication_Cmd(event_s_TypeDef * event_pop_s1) |
mridup | 0:dc55f40eb04f | 2170 | { |
mridup | 0:dc55f40eb04f | 2171 | switch(event_pop_s1->wind) |
mridup | 0:dc55f40eb04f | 2172 | { |
mridup | 0:dc55f40eb04f | 2173 | case Console_Active: |
mridup | 0:dc55f40eb04f | 2174 | WiFi_WIND_State.ConsoleActive = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2175 | break; |
mridup | 0:dc55f40eb04f | 2176 | case Poweron : |
mridup | 0:dc55f40eb04f | 2177 | WiFi_WIND_State.WiFiPowerON = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2178 | break; |
mridup | 0:dc55f40eb04f | 2179 | case WiFi_Reset: |
mridup | 0:dc55f40eb04f | 2180 | WiFi_WIND_State.WiFiReset = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2181 | break; |
mridup | 0:dc55f40eb04f | 2182 | case Watchdog_Running: |
mridup | 0:dc55f40eb04f | 2183 | break; |
mridup | 0:dc55f40eb04f | 2184 | case Heap_Too_Small: |
mridup | 0:dc55f40eb04f | 2185 | WiFi_WIND_State.HeapTooSmall=WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2186 | break; |
mridup | 0:dc55f40eb04f | 2187 | case WiFi_Hardware_Dead: |
mridup | 0:dc55f40eb04f | 2188 | WiFi_WIND_State.WiFiHWFailure = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2189 | break; |
mridup | 0:dc55f40eb04f | 2190 | case Watchdog_Terminating: |
mridup | 0:dc55f40eb04f | 2191 | break; |
mridup | 0:dc55f40eb04f | 2192 | case SysTickConfigure: |
mridup | 0:dc55f40eb04f | 2193 | break; |
mridup | 0:dc55f40eb04f | 2194 | case Hard_Fault: |
mridup | 0:dc55f40eb04f | 2195 | WiFi_WIND_State.HardFault = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2196 | break; |
mridup | 0:dc55f40eb04f | 2197 | case StackOverflow: |
mridup | 0:dc55f40eb04f | 2198 | WiFi_WIND_State.StackOverflow = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2199 | break; |
mridup | 0:dc55f40eb04f | 2200 | case MallocFailed: |
mridup | 0:dc55f40eb04f | 2201 | WiFi_WIND_State.MallocFailed = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2202 | break; |
mridup | 0:dc55f40eb04f | 2203 | case Error: |
mridup | 0:dc55f40eb04f | 2204 | WiFi_WIND_State.InitFailure = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2205 | break; |
mridup | 0:dc55f40eb04f | 2206 | case WiFi_PS_Mode_Failure: |
mridup | 0:dc55f40eb04f | 2207 | WiFi_WIND_State.PS_Mode_Failure = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2208 | break; |
mridup | 0:dc55f40eb04f | 2209 | case CopyrightInfo: |
mridup | 0:dc55f40eb04f | 2210 | break; |
mridup | 0:dc55f40eb04f | 2211 | case WiFi_BSS_Regained: |
mridup | 0:dc55f40eb04f | 2212 | break; |
mridup | 0:dc55f40eb04f | 2213 | case WiFi_Signal_LOW: |
mridup | 0:dc55f40eb04f | 2214 | WiFi_WIND_State.WiFiSignalLOW = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2215 | break; |
mridup | 0:dc55f40eb04f | 2216 | case WiFi_Signal_OK : |
mridup | 0:dc55f40eb04f | 2217 | break; |
mridup | 0:dc55f40eb04f | 2218 | case FW_update: |
mridup | 0:dc55f40eb04f | 2219 | break; |
mridup | 0:dc55f40eb04f | 2220 | case Encryption_key_Not_Recognized: |
mridup | 0:dc55f40eb04f | 2221 | break; |
mridup | 0:dc55f40eb04f | 2222 | case WiFi_Join : |
mridup | 0:dc55f40eb04f | 2223 | WiFi_WIND_State.WiFiJoin = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2224 | break; |
mridup | 0:dc55f40eb04f | 2225 | case JOINFAILED : |
mridup | 0:dc55f40eb04f | 2226 | WiFi_WIND_State.WiFiJoinFailed = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2227 | break; |
mridup | 0:dc55f40eb04f | 2228 | case WiFi_Scanning : |
mridup | 0:dc55f40eb04f | 2229 | WiFi_WIND_State.WiFiScanning = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2230 | break; |
mridup | 0:dc55f40eb04f | 2231 | case SCANBLEWUP: |
mridup | 0:dc55f40eb04f | 2232 | WiFi_WIND_State.WiFiScanBlewUp = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2233 | break; |
mridup | 0:dc55f40eb04f | 2234 | case SCANFAILED: |
mridup | 0:dc55f40eb04f | 2235 | WiFi_WIND_State.WiFiScanFailed = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2236 | break; |
mridup | 0:dc55f40eb04f | 2237 | case WiFi_Up: |
mridup | 0:dc55f40eb04f | 2238 | WiFi_WIND_State.WiFiUp = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2239 | break; |
mridup | 0:dc55f40eb04f | 2240 | case WiFi_Association_Successful: |
mridup | 0:dc55f40eb04f | 2241 | WiFi_WIND_State.WiFiAssociation = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2242 | break; |
mridup | 0:dc55f40eb04f | 2243 | case WiFi_Started_MiniAP_Mode: |
mridup | 0:dc55f40eb04f | 2244 | WiFi_WIND_State.WiFiStarted_MiniAPMode = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2245 | break; |
mridup | 0:dc55f40eb04f | 2246 | case Start_Failed : |
mridup | 0:dc55f40eb04f | 2247 | WiFi_WIND_State.StartFailed = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2248 | break; |
mridup | 0:dc55f40eb04f | 2249 | case WiFi_EXCEPTION : |
mridup | 0:dc55f40eb04f | 2250 | WiFi_WIND_State.WiFiException = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2251 | break; |
mridup | 0:dc55f40eb04f | 2252 | case WiFi_Hardware_Started : |
mridup | 0:dc55f40eb04f | 2253 | wifi_ready++; |
mridup | 0:dc55f40eb04f | 2254 | status_flag.WiFi_Enabled = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2255 | WiFi_WIND_State.WiFiHWStarted = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2256 | /*If this is a start-up after standby*/ |
mridup | 0:dc55f40eb04f | 2257 | if(status_flag.trigger_wakeup_callback == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 2258 | { |
mridup | 0:dc55f40eb04f | 2259 | status_flag.trigger_wakeup_callback = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2260 | status_flag.Standby_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2261 | status_flag.standby_resume_callback = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2262 | } |
mridup | 0:dc55f40eb04f | 2263 | break; |
mridup | 0:dc55f40eb04f | 2264 | case WiFi_BSS_LOST: |
mridup | 0:dc55f40eb04f | 2265 | break; |
mridup | 0:dc55f40eb04f | 2266 | case WiFi_Unhandled_Event: |
mridup | 0:dc55f40eb04f | 2267 | break; |
mridup | 0:dc55f40eb04f | 2268 | case Scan_Complete: |
mridup | 0:dc55f40eb04f | 2269 | WiFi_WIND_State.WiFiScanComplete = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2270 | status_flag.Scan_Ongoing = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2271 | break; |
mridup | 0:dc55f40eb04f | 2272 | case WiFi_UNHANDLED_IND: |
mridup | 0:dc55f40eb04f | 2273 | WiFi_WIND_State.WiFiUnHandledInd = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2274 | break; |
mridup | 0:dc55f40eb04f | 2275 | case WiFi_UNHANDLED: |
mridup | 0:dc55f40eb04f | 2276 | break; |
mridup | 0:dc55f40eb04f | 2277 | case WiFi_Powered_Down: |
mridup | 0:dc55f40eb04f | 2278 | status_flag.WiFi_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2279 | //wifi_ready = 0; |
mridup | 0:dc55f40eb04f | 2280 | WiFi_WIND_State.WiFiHWStarted = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2281 | WiFi_WIND_State.WiFiPowerDown = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2282 | break; |
mridup | 0:dc55f40eb04f | 2283 | case WiFi_MiniAP_Mode : |
mridup | 0:dc55f40eb04f | 2284 | WiFi_WIND_State.WiFiMiniAPMode = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2285 | break; |
mridup | 0:dc55f40eb04f | 2286 | case WiFi_Deauthentication: |
mridup | 0:dc55f40eb04f | 2287 | WiFi_WIND_State.WiFiDeauthentication = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2288 | break; |
mridup | 0:dc55f40eb04f | 2289 | case WiFi_Disassociation: |
mridup | 0:dc55f40eb04f | 2290 | WiFi_WIND_State.WiFiDisAssociation = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2291 | break; |
mridup | 0:dc55f40eb04f | 2292 | case RX_MGMT: |
mridup | 0:dc55f40eb04f | 2293 | WiFi_WIND_State.WiFiRXMgmt = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2294 | break; |
mridup | 0:dc55f40eb04f | 2295 | case RX_DATA: |
mridup | 0:dc55f40eb04f | 2296 | WiFi_WIND_State.WiFiRXData = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2297 | break; |
mridup | 0:dc55f40eb04f | 2298 | case RX_UNK: |
mridup | 0:dc55f40eb04f | 2299 | WiFi_WIND_State.WiFiRxUnk = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2300 | break; |
mridup | 0:dc55f40eb04f | 2301 | case DOT11_AUTHILLEGAL: |
mridup | 0:dc55f40eb04f | 2302 | break; |
mridup | 0:dc55f40eb04f | 2303 | case Creating_PSK: |
mridup | 0:dc55f40eb04f | 2304 | break; |
mridup | 0:dc55f40eb04f | 2305 | case WPA_Terminated : |
mridup | 0:dc55f40eb04f | 2306 | break; |
mridup | 0:dc55f40eb04f | 2307 | case WPA_Supplicant_Failed: |
mridup | 0:dc55f40eb04f | 2308 | break; |
mridup | 0:dc55f40eb04f | 2309 | case WPA_Handshake_Complete: |
mridup | 0:dc55f40eb04f | 2310 | break; |
mridup | 0:dc55f40eb04f | 2311 | case GPIO_line: |
mridup | 0:dc55f40eb04f | 2312 | break; |
mridup | 0:dc55f40eb04f | 2313 | case Wakeup: |
mridup | 0:dc55f40eb04f | 2314 | break; |
mridup | 0:dc55f40eb04f | 2315 | case Factory_debug: |
mridup | 0:dc55f40eb04f | 2316 | break; |
mridup | 0:dc55f40eb04f | 2317 | |
mridup | 0:dc55f40eb04f | 2318 | case SockON_Data_Pending: |
mridup | 0:dc55f40eb04f | 2319 | |
mridup | 0:dc55f40eb04f | 2320 | /* +WIND:55:Pending Data:%d:%d */ |
mridup | 0:dc55f40eb04f | 2321 | if (status_flag.enable_sock_read == WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 2322 | { |
mridup | 0:dc55f40eb04f | 2323 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 2324 | printf ("\nAlert!\r\n"); |
mridup | 0:dc55f40eb04f | 2325 | #endif |
mridup | 0:dc55f40eb04f | 2326 | status_flag.enable_sock_read = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2327 | status_flag.enable_receive_data_chunk = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2328 | //break; |
mridup | 0:dc55f40eb04f | 2329 | } |
mridup | 0:dc55f40eb04f | 2330 | sockon_query_id = event_pop_s1->socket_id; |
mridup | 0:dc55f40eb04f | 2331 | if(open_sockets[sockon_query_id]) |
mridup | 0:dc55f40eb04f | 2332 | { |
mridup | 0:dc55f40eb04f | 2333 | status_flag.enable_query = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2334 | status_flag.stop_event_dequeue = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2335 | } |
mridup | 0:dc55f40eb04f | 2336 | |
mridup | 0:dc55f40eb04f | 2337 | break; |
mridup | 0:dc55f40eb04f | 2338 | |
mridup | 0:dc55f40eb04f | 2339 | case SockON_Server_Socket_Closed: |
mridup | 0:dc55f40eb04f | 2340 | client_socket_close_id = event_pop_s1->socket_id; |
mridup | 0:dc55f40eb04f | 2341 | status_flag.Client_Socket_Close_Cmd = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2342 | break; |
mridup | 0:dc55f40eb04f | 2343 | |
mridup | 0:dc55f40eb04f | 2344 | case SockD_Pending_Data: |
mridup | 0:dc55f40eb04f | 2345 | number_of_bytes = event_pop_s1->data_length; |
mridup | 0:dc55f40eb04f | 2346 | status_flag.data_pending_sockD = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2347 | status_flag.stop_event_dequeue = WIFI_TRUE; //Stop any more event de-queue |
mridup | 0:dc55f40eb04f | 2348 | status_flag.enable_receive_data_chunk = WIFI_TRUE; // read data in chunk now from ring buffer |
mridup | 0:dc55f40eb04f | 2349 | |
mridup | 0:dc55f40eb04f | 2350 | if(!status_flag.data_mode) |
mridup | 0:dc55f40eb04f | 2351 | { |
mridup | 0:dc55f40eb04f | 2352 | if(event_pop_s1->wind64_pending_packet_no == 1) { //If this is the first WIND64 pending event de-Q'ed |
mridup | 0:dc55f40eb04f | 2353 | status_flag.switch_by_default_to_command_mode = WIFI_FALSE; //we don't want to switch back to command mode after changing to data mode here |
mridup | 0:dc55f40eb04f | 2354 | WiFi_switch_to_data_mode(); //switch by default |
mridup | 0:dc55f40eb04f | 2355 | } |
mridup | 0:dc55f40eb04f | 2356 | } |
mridup | 0:dc55f40eb04f | 2357 | else //already data is coming from previous WIND:64 |
mridup | 0:dc55f40eb04f | 2358 | { |
mridup | 0:dc55f40eb04f | 2359 | process_buffer_index =5; |
mridup | 0:dc55f40eb04f | 2360 | status_flag.enable_sock_read = WIFI_TRUE;//n |
mridup | 0:dc55f40eb04f | 2361 | SockON_Data_Length = number_of_bytes; |
mridup | 0:dc55f40eb04f | 2362 | } |
mridup | 0:dc55f40eb04f | 2363 | break; |
mridup | 0:dc55f40eb04f | 2364 | |
mridup | 0:dc55f40eb04f | 2365 | case Incoming_socket_client: |
mridup | 0:dc55f40eb04f | 2366 | status_flag.Client_Connected = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2367 | wifi_client_connected=1; //Set this so that the callback can be made to the user |
mridup | 0:dc55f40eb04f | 2368 | break; |
mridup | 0:dc55f40eb04f | 2369 | |
mridup | 0:dc55f40eb04f | 2370 | case Outgoing_socket_client: |
mridup | 0:dc55f40eb04f | 2371 | status_flag.Client_Disconnected = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2372 | wifi_client_disconnected=0;//Set this so that the callback can be made to the user |
mridup | 0:dc55f40eb04f | 2373 | wifi_client_connected = 0; |
mridup | 0:dc55f40eb04f | 2374 | break; |
mridup | 0:dc55f40eb04f | 2375 | |
mridup | 0:dc55f40eb04f | 2376 | case SockD_Dropping_Data: |
mridup | 0:dc55f40eb04f | 2377 | WiFi_WIND_State.WiFiSockdDataLost = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2378 | break; |
mridup | 0:dc55f40eb04f | 2379 | |
mridup | 0:dc55f40eb04f | 2380 | case Low_Power_Mode_Enabled: |
mridup | 0:dc55f40eb04f | 2381 | status_flag.Low_Power_Enabled = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2382 | break; |
mridup | 0:dc55f40eb04f | 2383 | |
mridup | 0:dc55f40eb04f | 2384 | case Going_Into_Standby: |
mridup | 0:dc55f40eb04f | 2385 | status_flag.Standby_Enabled = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2386 | break; |
mridup | 0:dc55f40eb04f | 2387 | |
mridup | 0:dc55f40eb04f | 2388 | case Resuming_From_Standby: |
mridup | 0:dc55f40eb04f | 2389 | status_flag.Standby_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2390 | status_flag.standby_resume_callback = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2391 | break; |
mridup | 0:dc55f40eb04f | 2392 | case Going_Into_DeepSleep: |
mridup | 0:dc55f40eb04f | 2393 | status_flag.Deep_Sleep_Enabled = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2394 | break; |
mridup | 0:dc55f40eb04f | 2395 | case Resuming_From_DeepSleep: |
mridup | 0:dc55f40eb04f | 2396 | status_flag.Deep_Sleep_Enabled = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2397 | Start_DeepSleep_Timer(); |
mridup | 0:dc55f40eb04f | 2398 | break; |
mridup | 0:dc55f40eb04f | 2399 | default: |
mridup | 0:dc55f40eb04f | 2400 | break; |
mridup | 0:dc55f40eb04f | 2401 | } |
mridup | 0:dc55f40eb04f | 2402 | } |
mridup | 0:dc55f40eb04f | 2403 | |
mridup | 0:dc55f40eb04f | 2404 | /** |
mridup | 0:dc55f40eb04f | 2405 | * @brief Queue_Http_Get_ Event |
mridup | 0:dc55f40eb04f | 2406 | * Queue an HTTP-Request Event (GET/POST) |
mridup | 0:dc55f40eb04f | 2407 | * @param hostname hostname for HTTP-GET/POST |
mridup | 0:dc55f40eb04f | 2408 | * @param path path for HTTP-GET |
mridup | 0:dc55f40eb04f | 2409 | * @param port_number port_number for HTTP-GET |
mridup | 0:dc55f40eb04f | 2410 | * @param pURL_path full URL for HTTP-POST |
mridup | 0:dc55f40eb04f | 2411 | * @retval None |
mridup | 0:dc55f40eb04f | 2412 | */ |
mridup | 0:dc55f40eb04f | 2413 | |
mridup | 0:dc55f40eb04f | 2414 | void Queue_Http_Event(uint8_t * hostname, uint8_t * path, uint32_t port_number, uint8_t * pURL_path) |
mridup | 0:dc55f40eb04f | 2415 | { |
mridup | 0:dc55f40eb04f | 2416 | Wait_For_Sock_Read_To_Complete(); |
mridup | 0:dc55f40eb04f | 2417 | if(pURL_path == NULL) |
mridup | 0:dc55f40eb04f | 2418 | { |
mridup | 0:dc55f40eb04f | 2419 | curr_hostname = hostname; |
mridup | 0:dc55f40eb04f | 2420 | curr_path = path; |
mridup | 0:dc55f40eb04f | 2421 | curr_port_number = port_number; |
mridup | 0:dc55f40eb04f | 2422 | } |
mridup | 0:dc55f40eb04f | 2423 | else |
mridup | 0:dc55f40eb04f | 2424 | curr_pURL = pURL_path; |
mridup | 0:dc55f40eb04f | 2425 | |
mridup | 0:dc55f40eb04f | 2426 | event_s.event = WIFI_HTTP_EVENT; |
mridup | 0:dc55f40eb04f | 2427 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 2428 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 2429 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 2430 | |
mridup | 0:dc55f40eb04f | 2431 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 2432 | } |
mridup | 0:dc55f40eb04f | 2433 | |
mridup | 0:dc55f40eb04f | 2434 | /** |
mridup | 0:dc55f40eb04f | 2435 | * @brief Queue_Client_Write_Event |
mridup | 0:dc55f40eb04f | 2436 | * Queues a Client Socket write event. |
mridup | 0:dc55f40eb04f | 2437 | * @param sock_id socket ID to write to |
mridup | 0:dc55f40eb04f | 2438 | * @param DataLength length of the data to be written |
mridup | 0:dc55f40eb04f | 2439 | * @param pData pointer to data |
mridup | 0:dc55f40eb04f | 2440 | * @retval None |
mridup | 0:dc55f40eb04f | 2441 | */ |
mridup | 0:dc55f40eb04f | 2442 | void Queue_Client_Write_Event(uint8_t sock_id, uint16_t DataLength, char * pData) |
mridup | 0:dc55f40eb04f | 2443 | { |
mridup | 0:dc55f40eb04f | 2444 | Wait_For_Sock_Read_To_Complete(); |
mridup | 0:dc55f40eb04f | 2445 | curr_DataLength = DataLength; |
mridup | 0:dc55f40eb04f | 2446 | curr_data = pData; |
mridup | 0:dc55f40eb04f | 2447 | curr_sockID = sock_id; |
mridup | 0:dc55f40eb04f | 2448 | status_flag.enable_client_socket_write = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2449 | |
mridup | 0:dc55f40eb04f | 2450 | event_s.event = WIFI_CLIENT_SOCKET_WRITE_EVENT; |
mridup | 0:dc55f40eb04f | 2451 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 2452 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 2453 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 2454 | |
mridup | 0:dc55f40eb04f | 2455 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 2456 | } |
mridup | 0:dc55f40eb04f | 2457 | |
mridup | 0:dc55f40eb04f | 2458 | /** |
mridup | 0:dc55f40eb04f | 2459 | * @brief Queue_Wifi_File_Image_Create_Event |
mridup | 0:dc55f40eb04f | 2460 | * Queue a File Image Create Event |
mridup | 0:dc55f40eb04f | 2461 | * @param pHostName hostname |
mridup | 0:dc55f40eb04f | 2462 | * @param pFileName filename within host |
mridup | 0:dc55f40eb04f | 2463 | * @param port_number port number to connect to |
mridup | 0:dc55f40eb04f | 2464 | * @retval None |
mridup | 0:dc55f40eb04f | 2465 | */ |
mridup | 0:dc55f40eb04f | 2466 | void Queue_Wifi_File_Event(uint8_t * pHostName, uint8_t * pFileName, uint32_t port_number) |
mridup | 0:dc55f40eb04f | 2467 | { |
mridup | 0:dc55f40eb04f | 2468 | Wait_For_Sock_Read_To_Complete(); |
mridup | 0:dc55f40eb04f | 2469 | event_s.event = WIFI_FILE_EVENT; |
mridup | 0:dc55f40eb04f | 2470 | curr_filename = pFileName; |
mridup | 0:dc55f40eb04f | 2471 | curr_hostname = pHostName; |
mridup | 0:dc55f40eb04f | 2472 | curr_port_number = port_number; |
mridup | 0:dc55f40eb04f | 2473 | |
mridup | 0:dc55f40eb04f | 2474 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 2475 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 2476 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 2477 | |
mridup | 0:dc55f40eb04f | 2478 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 2479 | } |
mridup | 0:dc55f40eb04f | 2480 | |
mridup | 0:dc55f40eb04f | 2481 | /** |
mridup | 0:dc55f40eb04f | 2482 | * @brief Queue_Wifi_FW_Update_Event |
mridup | 0:dc55f40eb04f | 2483 | * Queue a Firmware update Event |
mridup | 0:dc55f40eb04f | 2484 | * @param hostname hostname |
mridup | 0:dc55f40eb04f | 2485 | * @param filename_path filename and path within host |
mridup | 0:dc55f40eb04f | 2486 | * @param port_number port number to connect to |
mridup | 0:dc55f40eb04f | 2487 | * @retval None |
mridup | 0:dc55f40eb04f | 2488 | */ |
mridup | 0:dc55f40eb04f | 2489 | void Queue_Wifi_FW_Update_Event(uint8_t * hostname, uint8_t * filename_path, uint32_t port_number) |
mridup | 0:dc55f40eb04f | 2490 | { |
mridup | 0:dc55f40eb04f | 2491 | Wait_For_Sock_Read_To_Complete(); |
mridup | 0:dc55f40eb04f | 2492 | event_s.event = WIFI_FW_UPDATE_EVENT; |
mridup | 0:dc55f40eb04f | 2493 | curr_filename = filename_path; |
mridup | 0:dc55f40eb04f | 2494 | curr_hostname = hostname; |
mridup | 0:dc55f40eb04f | 2495 | curr_port_number = port_number; |
mridup | 0:dc55f40eb04f | 2496 | |
mridup | 0:dc55f40eb04f | 2497 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 2498 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 2499 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 2500 | |
mridup | 0:dc55f40eb04f | 2501 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 2502 | } |
mridup | 0:dc55f40eb04f | 2503 | |
mridup | 0:dc55f40eb04f | 2504 | void Queue_Client_Open_Event(uint8_t * hostname, uint32_t port_number, uint8_t * protocol) |
mridup | 0:dc55f40eb04f | 2505 | { |
mridup | 0:dc55f40eb04f | 2506 | Wait_For_Sock_Read_To_Complete(); |
mridup | 0:dc55f40eb04f | 2507 | curr_hostname = hostname; |
mridup | 0:dc55f40eb04f | 2508 | curr_port_number = port_number; |
mridup | 0:dc55f40eb04f | 2509 | curr_protocol = protocol; |
mridup | 0:dc55f40eb04f | 2510 | |
mridup | 0:dc55f40eb04f | 2511 | event_s.event = WIFI_CLIENT_SOCKET_OPEN_EVENT; |
mridup | 0:dc55f40eb04f | 2512 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 2513 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 2514 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 2515 | |
mridup | 0:dc55f40eb04f | 2516 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 2517 | } |
mridup | 0:dc55f40eb04f | 2518 | |
mridup | 0:dc55f40eb04f | 2519 | void Queue_Client_Close_Event(uint8_t sock_id) |
mridup | 0:dc55f40eb04f | 2520 | { |
mridup | 0:dc55f40eb04f | 2521 | Wait_For_Sock_Read_To_Complete(); |
mridup | 0:dc55f40eb04f | 2522 | |
mridup | 0:dc55f40eb04f | 2523 | event_s.event = WIFI_CLIENT_SOCKET_CLOSE_EVENT; |
mridup | 0:dc55f40eb04f | 2524 | event_s.socket_id = sock_id; |
mridup | 0:dc55f40eb04f | 2525 | __disable_irq(); |
mridup | 0:dc55f40eb04f | 2526 | push_eventbuffer(&event_buff, event_s); |
mridup | 0:dc55f40eb04f | 2527 | __enable_irq(); |
mridup | 0:dc55f40eb04f | 2528 | |
mridup | 0:dc55f40eb04f | 2529 | reset_event(&event_s); |
mridup | 0:dc55f40eb04f | 2530 | } |
mridup | 0:dc55f40eb04f | 2531 | |
mridup | 0:dc55f40eb04f | 2532 | /** |
mridup | 0:dc55f40eb04f | 2533 | * @brief Wait_For_Sock_Read_To_Complete |
mridup | 0:dc55f40eb04f | 2534 | * Wait till sock is over and the OK of read arrives |
mridup | 0:dc55f40eb04f | 2535 | * @param None |
mridup | 0:dc55f40eb04f | 2536 | * @retval None |
mridup | 0:dc55f40eb04f | 2537 | */ |
mridup | 0:dc55f40eb04f | 2538 | void Wait_For_Sock_Read_To_Complete(void) |
mridup | 0:dc55f40eb04f | 2539 | { |
mridup | 0:dc55f40eb04f | 2540 | //wait if read is ongoing or read OK is yet to arrive |
mridup | 0:dc55f40eb04f | 2541 | while(status_flag.sock_read_ongoing==WIFI_TRUE || status_flag.prevent_push_OK_event==WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 2542 | { |
mridup | 0:dc55f40eb04f | 2543 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 2544 | } |
mridup | 0:dc55f40eb04f | 2545 | } |
mridup | 0:dc55f40eb04f | 2546 | |
mridup | 0:dc55f40eb04f | 2547 | /** |
mridup | 0:dc55f40eb04f | 2548 | * @brief Reset_AT_CMD_Buffer |
mridup | 0:dc55f40eb04f | 2549 | * Clear USART2 Rx buffer and Wi-Fi AT cmd buffer |
mridup | 0:dc55f40eb04f | 2550 | * @param None |
mridup | 0:dc55f40eb04f | 2551 | * @retval None |
mridup | 0:dc55f40eb04f | 2552 | */ |
mridup | 0:dc55f40eb04f | 2553 | void Reset_AT_CMD_Buffer() |
mridup | 0:dc55f40eb04f | 2554 | { |
mridup | 0:dc55f40eb04f | 2555 | memset(WiFi_AT_Cmd_Buff, 0x00, sizeof WiFi_AT_Cmd_Buff); |
mridup | 0:dc55f40eb04f | 2556 | } |
mridup | 0:dc55f40eb04f | 2557 | |
mridup | 0:dc55f40eb04f | 2558 | #ifdef USE_FULL_ASSERT |
mridup | 0:dc55f40eb04f | 2559 | |
mridup | 0:dc55f40eb04f | 2560 | /** |
mridup | 0:dc55f40eb04f | 2561 | * @brief Reports the name of the source file and the source line number |
mridup | 0:dc55f40eb04f | 2562 | * where the assert_param error has occurred. |
mridup | 0:dc55f40eb04f | 2563 | * @param file: pointer to the source file name |
mridup | 0:dc55f40eb04f | 2564 | * @param line: assert_param error line source number |
mridup | 0:dc55f40eb04f | 2565 | * @retval None |
mridup | 0:dc55f40eb04f | 2566 | */ |
mridup | 0:dc55f40eb04f | 2567 | void assert_failed(uint8_t* file, uint32_t line) |
mridup | 0:dc55f40eb04f | 2568 | { |
mridup | 0:dc55f40eb04f | 2569 | /* User can add his own implementation to report the file name and line number, |
mridup | 0:dc55f40eb04f | 2570 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
mridup | 0:dc55f40eb04f | 2571 | |
mridup | 0:dc55f40eb04f | 2572 | /* Infinite loop */ |
mridup | 0:dc55f40eb04f | 2573 | while (1) |
mridup | 0:dc55f40eb04f | 2574 | { |
mridup | 0:dc55f40eb04f | 2575 | } |
mridup | 0:dc55f40eb04f | 2576 | } |
mridup | 0:dc55f40eb04f | 2577 | |
mridup | 0:dc55f40eb04f | 2578 | #endif |
mridup | 0:dc55f40eb04f | 2579 | |
mridup | 0:dc55f40eb04f | 2580 | |
mridup | 0:dc55f40eb04f | 2581 | /** |
mridup | 0:dc55f40eb04f | 2582 | * @brief search_buffer |
mridup | 0:dc55f40eb04f | 2583 | * search for substring in a buffer that contains null |
mridup | 0:dc55f40eb04f | 2584 | * @param pSourceBuff : pointer of source buffer |
mridup | 0:dc55f40eb04f | 2585 | * sourceBuffLen : length of string buffer |
mridup | 0:dc55f40eb04f | 2586 | * pSearchStringBuff : pointer of search string buffer |
mridup | 0:dc55f40eb04f | 2587 | * seartchStringLen : length of search string buffer |
mridup | 0:dc55f40eb04f | 2588 | * @retval pointer of source buffer |
mridup | 0:dc55f40eb04f | 2589 | */ |
mridup | 0:dc55f40eb04f | 2590 | char *search_buffer(char *pSourceBuff, uint16_t sourceBuffLen, char *pSearchStringBuff, uint16_t seartchStringLen) |
mridup | 0:dc55f40eb04f | 2591 | { /* warning: O(n^2) */ |
mridup | 0:dc55f40eb04f | 2592 | int searchlen = sourceBuffLen - seartchStringLen + 1; |
mridup | 0:dc55f40eb04f | 2593 | for ( ; searchlen-- > 0; pSourceBuff++) |
mridup | 0:dc55f40eb04f | 2594 | if (!memcmp(pSourceBuff, pSearchStringBuff, seartchStringLen)) |
mridup | 0:dc55f40eb04f | 2595 | return pSourceBuff; |
mridup | 0:dc55f40eb04f | 2596 | return NULL; |
mridup | 0:dc55f40eb04f | 2597 | } |
mridup | 0:dc55f40eb04f | 2598 | |
mridup | 0:dc55f40eb04f | 2599 | /** |
mridup | 0:dc55f40eb04f | 2600 | * @brief Delete_Colon |
mridup | 0:dc55f40eb04f | 2601 | * delete colon from input buffer |
mridup | 0:dc55f40eb04f | 2602 | * @param input : pointer of input buffer |
mridup | 0:dc55f40eb04f | 2603 | * @retval return pointer of updated buffer |
mridup | 0:dc55f40eb04f | 2604 | */ |
mridup | 0:dc55f40eb04f | 2605 | char* Delete_Colon(char* input) |
mridup | 0:dc55f40eb04f | 2606 | { |
mridup | 0:dc55f40eb04f | 2607 | int i,j; |
mridup | 0:dc55f40eb04f | 2608 | char *output=input; |
mridup | 0:dc55f40eb04f | 2609 | |
mridup | 0:dc55f40eb04f | 2610 | /* Delete Colon */ |
mridup | 0:dc55f40eb04f | 2611 | for (i = 0, j = 0; i<strlen(input); i++,j++) |
mridup | 0:dc55f40eb04f | 2612 | { |
mridup | 0:dc55f40eb04f | 2613 | #if 0 |
mridup | 0:dc55f40eb04f | 2614 | if (input[i]!=':') && (input[i]!='\r')&& (input[i]!='\n')&& (input[i]!='O')&& (input[i]!='K')) |
mridup | 0:dc55f40eb04f | 2615 | output[j]=input[i]; |
mridup | 0:dc55f40eb04f | 2616 | else |
mridup | 0:dc55f40eb04f | 2617 | j--; |
mridup | 0:dc55f40eb04f | 2618 | #else |
mridup | 0:dc55f40eb04f | 2619 | if ((input[i] ==':') || (input[i]=='\r')|| (input[i]=='\n')|| (input[i]=='O')|| (input[i]=='K')) |
mridup | 0:dc55f40eb04f | 2620 | j--; |
mridup | 0:dc55f40eb04f | 2621 | else |
mridup | 0:dc55f40eb04f | 2622 | output[j]=input[i]; |
mridup | 0:dc55f40eb04f | 2623 | } |
mridup | 0:dc55f40eb04f | 2624 | //output[j]=NULL; |
mridup | 0:dc55f40eb04f | 2625 | #endif |
mridup | 0:dc55f40eb04f | 2626 | return output; |
mridup | 0:dc55f40eb04f | 2627 | } |
mridup | 0:dc55f40eb04f | 2628 | |
mridup | 0:dc55f40eb04f | 2629 | /** |
mridup | 0:dc55f40eb04f | 2630 | * @brief Read_WiFi_SSID |
mridup | 0:dc55f40eb04f | 2631 | * Read SSID of WiFi module store in flash |
mridup | 0:dc55f40eb04f | 2632 | * @param string : pointer of SSID |
mridup | 0:dc55f40eb04f | 2633 | * @retval return status of AT cmd request |
mridup | 0:dc55f40eb04f | 2634 | */ |
mridup | 0:dc55f40eb04f | 2635 | WiFi_Status_t Read_WiFi_SSID(char *string) |
mridup | 0:dc55f40eb04f | 2636 | { |
mridup | 0:dc55f40eb04f | 2637 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2638 | char * ssid = "wifi_ssid"; |
mridup | 0:dc55f40eb04f | 2639 | char * pStr; |
mridup | 0:dc55f40eb04f | 2640 | /* AT+S.GCFG=wifi_ssid read SSID */ |
mridup | 0:dc55f40eb04f | 2641 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2642 | |
mridup | 0:dc55f40eb04f | 2643 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 2644 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,ssid); |
mridup | 0:dc55f40eb04f | 2645 | |
mridup | 0:dc55f40eb04f | 2646 | /* |
mridup | 0:dc55f40eb04f | 2647 | Response : |
mridup | 0:dc55f40eb04f | 2648 | # wifi_ssid = 41:6E:53:53:49:44:00:00:00:00:00:00:00:00:00:00:00:00:00: |
mridup | 0:dc55f40eb04f | 2649 | 00:00:00:00:00:00:00:00:00:00:00:00:00<cr><lf> |
mridup | 0:dc55f40eb04f | 2650 | <cr><lf>OK<cr><lf> |
mridup | 0:dc55f40eb04f | 2651 | */ |
mridup | 0:dc55f40eb04f | 2652 | |
mridup | 0:dc55f40eb04f | 2653 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2654 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2655 | { |
mridup | 0:dc55f40eb04f | 2656 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 2657 | } |
mridup | 0:dc55f40eb04f | 2658 | |
mridup | 0:dc55f40eb04f | 2659 | /* find a substring (# wifi_ssid = )inside a USART2_RxBuffer that may contain nulls */ |
mridup | 0:dc55f40eb04f | 2660 | uint16_t sourceBuffLen = sizeof(get_cfg_value)-1; /* exclude null terminator from length */ |
mridup | 0:dc55f40eb04f | 2661 | char searchStringBuff[] = "# wifi_ssid = "; |
mridup | 0:dc55f40eb04f | 2662 | uint16_t stringBuffLen = sizeof(searchStringBuff)-1; /* exclude null terminator from length */ |
mridup | 0:dc55f40eb04f | 2663 | char *res = search_buffer((char *)&get_cfg_value, sourceBuffLen, searchStringBuff, stringBuffLen); |
mridup | 0:dc55f40eb04f | 2664 | |
mridup | 0:dc55f40eb04f | 2665 | pStr = (char *) (strstr((const char *)res,"= ")); |
mridup | 0:dc55f40eb04f | 2666 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 2667 | { |
mridup | 0:dc55f40eb04f | 2668 | strcat( string, (pStr + 2)); |
mridup | 0:dc55f40eb04f | 2669 | /* Remove colon,\r,\n,OK strings */ |
mridup | 0:dc55f40eb04f | 2670 | memcpy(string, Delete_Colon(string) , 32); |
mridup | 0:dc55f40eb04f | 2671 | } |
mridup | 0:dc55f40eb04f | 2672 | return status; |
mridup | 0:dc55f40eb04f | 2673 | } |
mridup | 0:dc55f40eb04f | 2674 | |
mridup | 0:dc55f40eb04f | 2675 | /** |
mridup | 0:dc55f40eb04f | 2676 | * @brief Read_WiFi_SecKey |
mridup | 0:dc55f40eb04f | 2677 | * Read Security key of WiFi module store in flash |
mridup | 0:dc55f40eb04f | 2678 | * @param string : pointer of Security key |
mridup | 0:dc55f40eb04f | 2679 | * @retval return status of AT cmd request |
mridup | 0:dc55f40eb04f | 2680 | */ |
mridup | 0:dc55f40eb04f | 2681 | WiFi_Status_t Read_WiFi_SecKey(char *string) |
mridup | 0:dc55f40eb04f | 2682 | { |
mridup | 0:dc55f40eb04f | 2683 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2684 | char *seckey = "wifi_wpa_psk_text"; |
mridup | 0:dc55f40eb04f | 2685 | char *pStr; |
mridup | 0:dc55f40eb04f | 2686 | |
mridup | 0:dc55f40eb04f | 2687 | /* AT+S.GCFG=wifi_ssid read SSID */ |
mridup | 0:dc55f40eb04f | 2688 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2689 | |
mridup | 0:dc55f40eb04f | 2690 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 2691 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,seckey); |
mridup | 0:dc55f40eb04f | 2692 | |
mridup | 0:dc55f40eb04f | 2693 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2694 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2695 | { |
mridup | 0:dc55f40eb04f | 2696 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 2697 | } |
mridup | 0:dc55f40eb04f | 2698 | |
mridup | 0:dc55f40eb04f | 2699 | |
mridup | 0:dc55f40eb04f | 2700 | /* find a substring (wifi_wpa_psk_text = )inside a USART2_RxBuffer that may contain nulls */ |
mridup | 0:dc55f40eb04f | 2701 | uint16_t sourceBuffLen = sizeof(get_cfg_value)-1; /* exclude null terminator from length */ |
mridup | 0:dc55f40eb04f | 2702 | char searchStringBuff[] = "wifi_wpa_psk_text = "; |
mridup | 0:dc55f40eb04f | 2703 | uint16_t stringBuffLen = sizeof(searchStringBuff)-1; /* exclude null terminator from length */ |
mridup | 0:dc55f40eb04f | 2704 | char *res = search_buffer((char *)&get_cfg_value, sourceBuffLen, searchStringBuff, stringBuffLen); |
mridup | 0:dc55f40eb04f | 2705 | |
mridup | 0:dc55f40eb04f | 2706 | pStr = (char *) (strstr((const char *)res,"= ")); |
mridup | 0:dc55f40eb04f | 2707 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 2708 | { |
mridup | 0:dc55f40eb04f | 2709 | strcat( string, (pStr + 2)); |
mridup | 0:dc55f40eb04f | 2710 | /* Remove colon,\r,\n,OK strings */ |
mridup | 0:dc55f40eb04f | 2711 | memcpy(string, Delete_Colon(string) , 32); |
mridup | 0:dc55f40eb04f | 2712 | } |
mridup | 0:dc55f40eb04f | 2713 | |
mridup | 0:dc55f40eb04f | 2714 | return status; |
mridup | 0:dc55f40eb04f | 2715 | } |
mridup | 0:dc55f40eb04f | 2716 | |
mridup | 0:dc55f40eb04f | 2717 | /** |
mridup | 0:dc55f40eb04f | 2718 | * @brief Read_WiFi_Mode |
mridup | 0:dc55f40eb04f | 2719 | * Read Wi-Fi mode 0: idle,1 =STA,2 =IBSS,3 =MiniAP |
mridup | 0:dc55f40eb04f | 2720 | * @param string : return wifi mode type |
mridup | 0:dc55f40eb04f | 2721 | * @retval return status of AT cmd request |
mridup | 0:dc55f40eb04f | 2722 | */ |
mridup | 0:dc55f40eb04f | 2723 | WiFi_Status_t Read_WiFi_Mode(char *string) |
mridup | 0:dc55f40eb04f | 2724 | { |
mridup | 0:dc55f40eb04f | 2725 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2726 | char *mode = "wifi_mode"; |
mridup | 0:dc55f40eb04f | 2727 | char *pStr; |
mridup | 0:dc55f40eb04f | 2728 | |
mridup | 0:dc55f40eb04f | 2729 | /* AT+S.GCFG=wifi_mode */ |
mridup | 0:dc55f40eb04f | 2730 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2731 | |
mridup | 0:dc55f40eb04f | 2732 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 2733 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,mode); |
mridup | 0:dc55f40eb04f | 2734 | |
mridup | 0:dc55f40eb04f | 2735 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2736 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2737 | { |
mridup | 0:dc55f40eb04f | 2738 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 2739 | } |
mridup | 0:dc55f40eb04f | 2740 | |
mridup | 0:dc55f40eb04f | 2741 | pStr = (char *) strstr((const char *)&get_cfg_value,"wifi_mode = "); |
mridup | 0:dc55f40eb04f | 2742 | if(pStr != NULL) |
mridup | 0:dc55f40eb04f | 2743 | { |
mridup | 0:dc55f40eb04f | 2744 | string[0] = *(pStr + 12) ; |
mridup | 0:dc55f40eb04f | 2745 | } |
mridup | 0:dc55f40eb04f | 2746 | |
mridup | 0:dc55f40eb04f | 2747 | return status ; |
mridup | 0:dc55f40eb04f | 2748 | } |
mridup | 0:dc55f40eb04f | 2749 | |
mridup | 0:dc55f40eb04f | 2750 | /** |
mridup | 0:dc55f40eb04f | 2751 | * @brief Write_WiFi_SSID |
mridup | 0:dc55f40eb04f | 2752 | * Store SSID in flash memory of WiFi module |
mridup | 0:dc55f40eb04f | 2753 | * @param string : pointer of SSID |
mridup | 0:dc55f40eb04f | 2754 | * @retval return status of AT cmd request |
mridup | 0:dc55f40eb04f | 2755 | */ |
mridup | 0:dc55f40eb04f | 2756 | WiFi_Status_t Write_WiFi_SSID(char *string) |
mridup | 0:dc55f40eb04f | 2757 | { |
mridup | 0:dc55f40eb04f | 2758 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2759 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2760 | |
mridup | 0:dc55f40eb04f | 2761 | /* AT+S.SSIDTXT=abcd <ExampleSSID> //set SSID */ |
mridup | 0:dc55f40eb04f | 2762 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_SSID,string); |
mridup | 0:dc55f40eb04f | 2763 | |
mridup | 0:dc55f40eb04f | 2764 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2765 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2766 | { |
mridup | 0:dc55f40eb04f | 2767 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 2768 | } |
mridup | 0:dc55f40eb04f | 2769 | |
mridup | 0:dc55f40eb04f | 2770 | /* AT&W :Save the settings on the flash memory */ |
mridup | 0:dc55f40eb04f | 2771 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2772 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 2773 | |
mridup | 0:dc55f40eb04f | 2774 | return status; |
mridup | 0:dc55f40eb04f | 2775 | |
mridup | 0:dc55f40eb04f | 2776 | } |
mridup | 0:dc55f40eb04f | 2777 | |
mridup | 0:dc55f40eb04f | 2778 | |
mridup | 0:dc55f40eb04f | 2779 | /** |
mridup | 0:dc55f40eb04f | 2780 | * @brief Write_WiFi_SecKey |
mridup | 0:dc55f40eb04f | 2781 | * Store security key in flash memory of WiFi module |
mridup | 0:dc55f40eb04f | 2782 | * @param string : pointer of security key |
mridup | 0:dc55f40eb04f | 2783 | * @retval return status of AT cmd request |
mridup | 0:dc55f40eb04f | 2784 | */ |
mridup | 0:dc55f40eb04f | 2785 | WiFi_Status_t Write_WiFi_SecKey(char *string) |
mridup | 0:dc55f40eb04f | 2786 | { |
mridup | 0:dc55f40eb04f | 2787 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2788 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2789 | |
mridup | 0:dc55f40eb04f | 2790 | /* AT+S.SCFG=wifi_wpa_psk_text,helloworld : set password */ |
mridup | 0:dc55f40eb04f | 2791 | sprintf((char*)WiFi_AT_Cmd_Buff,"AT+S.SCFG=wifi_wpa_psk_text,%s\r",string); |
mridup | 0:dc55f40eb04f | 2792 | |
mridup | 0:dc55f40eb04f | 2793 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2794 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2795 | { |
mridup | 0:dc55f40eb04f | 2796 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 2797 | } |
mridup | 0:dc55f40eb04f | 2798 | |
mridup | 0:dc55f40eb04f | 2799 | /* AT&W :Save the settings on the flash memory */ |
mridup | 0:dc55f40eb04f | 2800 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2801 | Save_Current_Setting(); |
mridup | 0:dc55f40eb04f | 2802 | |
mridup | 0:dc55f40eb04f | 2803 | return status; |
mridup | 0:dc55f40eb04f | 2804 | } |
mridup | 0:dc55f40eb04f | 2805 | |
mridup | 0:dc55f40eb04f | 2806 | |
mridup | 0:dc55f40eb04f | 2807 | |
mridup | 0:dc55f40eb04f | 2808 | /** |
mridup | 0:dc55f40eb04f | 2809 | * @brief PrintErrorMsg |
mridup | 0:dc55f40eb04f | 2810 | * Print error message on UART terminal |
mridup | 0:dc55f40eb04f | 2811 | * @param None |
mridup | 0:dc55f40eb04f | 2812 | * @retval None |
mridup | 0:dc55f40eb04f | 2813 | */ |
mridup | 0:dc55f40eb04f | 2814 | void PrintErrorMsg (void) |
mridup | 0:dc55f40eb04f | 2815 | { |
mridup | 0:dc55f40eb04f | 2816 | Print_Msg("error in AT cmd",sizeof("error in AT cmd")); |
mridup | 0:dc55f40eb04f | 2817 | } |
mridup | 0:dc55f40eb04f | 2818 | |
mridup | 0:dc55f40eb04f | 2819 | /** |
mridup | 0:dc55f40eb04f | 2820 | * @brief Print_Msg |
mridup | 0:dc55f40eb04f | 2821 | * Print messages on UART terminal |
mridup | 0:dc55f40eb04f | 2822 | * @param msgBuff : Contains data that need to be print |
mridup | 0:dc55f40eb04f | 2823 | * @param length : leghth of the data |
mridup | 0:dc55f40eb04f | 2824 | * @retval None |
mridup | 0:dc55f40eb04f | 2825 | */ |
mridup | 0:dc55f40eb04f | 2826 | void Print_Msg(char * msgBuff,uint8_t length) |
mridup | 0:dc55f40eb04f | 2827 | { |
mridup | 0:dc55f40eb04f | 2828 | |
mridup | 0:dc55f40eb04f | 2829 | } |
mridup | 0:dc55f40eb04f | 2830 | |
mridup | 0:dc55f40eb04f | 2831 | /** |
mridup | 0:dc55f40eb04f | 2832 | * @brief Error_Handler |
mridup | 0:dc55f40eb04f | 2833 | * This function is executed in case of error occurrence. |
mridup | 0:dc55f40eb04f | 2834 | * @param None |
mridup | 0:dc55f40eb04f | 2835 | * @retval None |
mridup | 0:dc55f40eb04f | 2836 | */ |
mridup | 0:dc55f40eb04f | 2837 | void Error_Handler(void) |
mridup | 0:dc55f40eb04f | 2838 | { |
mridup | 0:dc55f40eb04f | 2839 | /* Turn LED2 on */ |
mridup | 0:dc55f40eb04f | 2840 | //BSP_LED_On(LED2); |
mridup | 0:dc55f40eb04f | 2841 | //The following while(1) is commented as it prevents standby functionality |
mridup | 0:dc55f40eb04f | 2842 | /*while(1) |
mridup | 0:dc55f40eb04f | 2843 | { |
mridup | 0:dc55f40eb04f | 2844 | //Error if LED2 is slowly blinking (1 sec. period) |
mridup | 0:dc55f40eb04f | 2845 | BSP_LED_Toggle(LED2); |
mridup | 0:dc55f40eb04f | 2846 | HAL_Delay(1000); |
mridup | 0:dc55f40eb04f | 2847 | } */ |
mridup | 0:dc55f40eb04f | 2848 | Receive_Data(); |
mridup | 0:dc55f40eb04f | 2849 | } |
mridup | 0:dc55f40eb04f | 2850 | |
mridup | 0:dc55f40eb04f | 2851 | |
mridup | 0:dc55f40eb04f | 2852 | /** |
mridup | 0:dc55f40eb04f | 2853 | * @brief Start_DeepSleep_Timer |
mridup | 0:dc55f40eb04f | 2854 | * start the deep sleep timer. |
mridup | 0:dc55f40eb04f | 2855 | * @param None |
mridup | 0:dc55f40eb04f | 2856 | * @retval void |
mridup | 0:dc55f40eb04f | 2857 | */ |
mridup | 0:dc55f40eb04f | 2858 | void Start_DeepSleep_Timer(void) |
mridup | 0:dc55f40eb04f | 2859 | { |
mridup | 0:dc55f40eb04f | 2860 | status_flag.Deep_Sleep_Timer = WIFI_TRUE; |
mridup | 0:dc55f40eb04f | 2861 | sleep_count = 0; |
mridup | 0:dc55f40eb04f | 2862 | } |
mridup | 0:dc55f40eb04f | 2863 | |
mridup | 0:dc55f40eb04f | 2864 | /** |
mridup | 0:dc55f40eb04f | 2865 | * @brief Stop_DeepSleep_Timer |
mridup | 0:dc55f40eb04f | 2866 | * stop the deep sleep timer. |
mridup | 0:dc55f40eb04f | 2867 | * @param None |
mridup | 0:dc55f40eb04f | 2868 | * @retval void |
mridup | 0:dc55f40eb04f | 2869 | */ |
mridup | 0:dc55f40eb04f | 2870 | void Stop_DeepSleep_Timer() |
mridup | 0:dc55f40eb04f | 2871 | { |
mridup | 0:dc55f40eb04f | 2872 | status_flag.Deep_Sleep_Timer = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2873 | sleep_count = 0; |
mridup | 0:dc55f40eb04f | 2874 | } |
mridup | 0:dc55f40eb04f | 2875 | |
mridup | 0:dc55f40eb04f | 2876 | #if 0 |
mridup | 0:dc55f40eb04f | 2877 | /** |
mridup | 0:dc55f40eb04f | 2878 | * @brief configure_to_exti |
mridup | 0:dc55f40eb04f | 2879 | * Configured the USART Rx pin to EXTI pin to capture standby wakeup interrupt |
mridup | 0:dc55f40eb04f | 2880 | * @param None |
mridup | 0:dc55f40eb04f | 2881 | * @retval None |
mridup | 0:dc55f40eb04f | 2882 | */ |
mridup | 0:dc55f40eb04f | 2883 | void configure_to_exti() |
mridup | 0:dc55f40eb04f | 2884 | { |
mridup | 0:dc55f40eb04f | 2885 | /*configure the pin*/ |
mridup | 0:dc55f40eb04f | 2886 | |
mridup | 0:dc55f40eb04f | 2887 | HAL_NVIC_DisableIRQ(USARTx_IRQn);//Disable UART IRQ |
mridup | 0:dc55f40eb04f | 2888 | |
mridup | 0:dc55f40eb04f | 2889 | /* USART_RX Pin as EXTI IRQ*/ |
mridup | 0:dc55f40eb04f | 2890 | GPIO_InitTypeDef GPIO_InitStruct; |
mridup | 0:dc55f40eb04f | 2891 | GPIO_InitStruct.Pin = WiFi_USART_RX_PIN; |
mridup | 0:dc55f40eb04f | 2892 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; |
mridup | 0:dc55f40eb04f | 2893 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
mridup | 0:dc55f40eb04f | 2894 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
mridup | 0:dc55f40eb04f | 2895 | #if defined (USE_STM32L0XX_NUCLEO) || (USE_STM32F4XX_NUCLEO) |
mridup | 0:dc55f40eb04f | 2896 | GPIO_InitStruct.Alternate = 0; |
mridup | 0:dc55f40eb04f | 2897 | #endif |
mridup | 0:dc55f40eb04f | 2898 | HAL_GPIO_Init(WiFi_USART_RX_GPIO_PORT, &GPIO_InitStruct); |
mridup | 0:dc55f40eb04f | 2899 | |
mridup | 0:dc55f40eb04f | 2900 | /* Configure the NVIC for EXTI */ |
mridup | 0:dc55f40eb04f | 2901 | HAL_NVIC_SetPriority(USARTx_EXTI_IRQn, 3, 0); |
mridup | 0:dc55f40eb04f | 2902 | HAL_NVIC_EnableIRQ(USARTx_EXTI_IRQn); |
mridup | 0:dc55f40eb04f | 2903 | } |
mridup | 0:dc55f40eb04f | 2904 | #endif |
mridup | 0:dc55f40eb04f | 2905 | |
mridup | 0:dc55f40eb04f | 2906 | /** |
mridup | 0:dc55f40eb04f | 2907 | * @brief WiFi_switch_to_command_mode |
mridup | 0:dc55f40eb04f | 2908 | * switch to command mode from data mode |
mridup | 0:dc55f40eb04f | 2909 | * @param None |
mridup | 0:dc55f40eb04f | 2910 | * @retval None |
mridup | 0:dc55f40eb04f | 2911 | */ |
mridup | 0:dc55f40eb04f | 2912 | void WiFi_switch_to_command_mode(void) |
mridup | 0:dc55f40eb04f | 2913 | { |
mridup | 0:dc55f40eb04f | 2914 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2915 | |
mridup | 0:dc55f40eb04f | 2916 | /* AT+S.*/ |
mridup | 0:dc55f40eb04f | 2917 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2918 | |
mridup | 0:dc55f40eb04f | 2919 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_DATA_TO_CMD_MODE); //Notice the lower case |
mridup | 0:dc55f40eb04f | 2920 | |
mridup | 0:dc55f40eb04f | 2921 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2922 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2923 | { |
mridup | 0:dc55f40eb04f | 2924 | //nothing to do |
mridup | 0:dc55f40eb04f | 2925 | } |
mridup | 0:dc55f40eb04f | 2926 | } |
mridup | 0:dc55f40eb04f | 2927 | |
mridup | 0:dc55f40eb04f | 2928 | |
mridup | 0:dc55f40eb04f | 2929 | /** |
mridup | 0:dc55f40eb04f | 2930 | * @brief WiFi_switch_to_data_mode |
mridup | 0:dc55f40eb04f | 2931 | * switch to data mode from command mode |
mridup | 0:dc55f40eb04f | 2932 | * @param None |
mridup | 0:dc55f40eb04f | 2933 | * @retval None |
mridup | 0:dc55f40eb04f | 2934 | */ |
mridup | 0:dc55f40eb04f | 2935 | void WiFi_switch_to_data_mode(void) |
mridup | 0:dc55f40eb04f | 2936 | { |
mridup | 0:dc55f40eb04f | 2937 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2938 | |
mridup | 0:dc55f40eb04f | 2939 | /* AT+S.*/ |
mridup | 0:dc55f40eb04f | 2940 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2941 | |
mridup | 0:dc55f40eb04f | 2942 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_CMD_TO_DATA_MODE); //Notice the upper case |
mridup | 0:dc55f40eb04f | 2943 | |
mridup | 0:dc55f40eb04f | 2944 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2945 | |
mridup | 0:dc55f40eb04f | 2946 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2947 | { |
mridup | 0:dc55f40eb04f | 2948 | //nothing to do |
mridup | 0:dc55f40eb04f | 2949 | } |
mridup | 0:dc55f40eb04f | 2950 | |
mridup | 0:dc55f40eb04f | 2951 | } |
mridup | 0:dc55f40eb04f | 2952 | |
mridup | 0:dc55f40eb04f | 2953 | |
mridup | 0:dc55f40eb04f | 2954 | /** |
mridup | 0:dc55f40eb04f | 2955 | * @brief Attention_Cmd |
mridup | 0:dc55f40eb04f | 2956 | * Attention command |
mridup | 0:dc55f40eb04f | 2957 | * @param None |
mridup | 0:dc55f40eb04f | 2958 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 2959 | */ |
mridup | 0:dc55f40eb04f | 2960 | WiFi_Status_t Attention_Cmd() |
mridup | 0:dc55f40eb04f | 2961 | { |
mridup | 0:dc55f40eb04f | 2962 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2963 | |
mridup | 0:dc55f40eb04f | 2964 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2965 | |
mridup | 0:dc55f40eb04f | 2966 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 2967 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_ATTENTION); |
mridup | 0:dc55f40eb04f | 2968 | |
mridup | 0:dc55f40eb04f | 2969 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 2970 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 2971 | { |
mridup | 0:dc55f40eb04f | 2972 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 2973 | } |
mridup | 0:dc55f40eb04f | 2974 | return status; |
mridup | 0:dc55f40eb04f | 2975 | } |
mridup | 0:dc55f40eb04f | 2976 | |
mridup | 0:dc55f40eb04f | 2977 | |
mridup | 0:dc55f40eb04f | 2978 | /** |
mridup | 0:dc55f40eb04f | 2979 | * @brief SET_Power_State |
mridup | 0:dc55f40eb04f | 2980 | * SET power mode of wifi module |
mridup | 0:dc55f40eb04f | 2981 | * @param state : power mode of wi-fi module i.e active,sleep,standby,powersave |
mridup | 0:dc55f40eb04f | 2982 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 2983 | */ |
mridup | 0:dc55f40eb04f | 2984 | WiFi_Status_t SET_Power_State(WiFi_Power_State_t state) |
mridup | 0:dc55f40eb04f | 2985 | { |
mridup | 0:dc55f40eb04f | 2986 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 2987 | |
mridup | 0:dc55f40eb04f | 2988 | #if DEBUG_PRINT |
mridup | 0:dc55f40eb04f | 2989 | printf("\r\n >>Soft Reset Wi-Fi module\r\n"); |
mridup | 0:dc55f40eb04f | 2990 | #endif |
mridup | 0:dc55f40eb04f | 2991 | |
mridup | 0:dc55f40eb04f | 2992 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 2993 | |
mridup | 0:dc55f40eb04f | 2994 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 2995 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_POWER_STATE,state); |
mridup | 0:dc55f40eb04f | 2996 | // WiFi_Module_State = Process_Event; |
mridup | 0:dc55f40eb04f | 2997 | // WiFi_WIND_State.WiFiReset = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2998 | WiFi_WIND_State.WiFiHWStarted = WIFI_FALSE; |
mridup | 0:dc55f40eb04f | 2999 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3000 | if(status != WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3001 | return status; |
mridup | 0:dc55f40eb04f | 3002 | memset((void*)&WiFi_WIND_State,0x00,sizeof(WiFi_WIND_State)); /*reset the WIND State?*/ |
mridup | 0:dc55f40eb04f | 3003 | /* AT+CFUN=1 //Soft reset */ |
mridup | 0:dc55f40eb04f | 3004 | while(WiFi_WIND_State.WiFiHWStarted != WIFI_TRUE) |
mridup | 0:dc55f40eb04f | 3005 | { |
mridup | 0:dc55f40eb04f | 3006 | asm("NOP"); |
mridup | 0:dc55f40eb04f | 3007 | } |
mridup | 0:dc55f40eb04f | 3008 | return status; |
mridup | 0:dc55f40eb04f | 3009 | } |
mridup | 0:dc55f40eb04f | 3010 | |
mridup | 0:dc55f40eb04f | 3011 | |
mridup | 0:dc55f40eb04f | 3012 | /** |
mridup | 0:dc55f40eb04f | 3013 | * @brief Display_Help_Text |
mridup | 0:dc55f40eb04f | 3014 | * this function will print a list of all commands supported with a brief help text for each cmd |
mridup | 0:dc55f40eb04f | 3015 | * @param None |
mridup | 0:dc55f40eb04f | 3016 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3017 | */ |
mridup | 0:dc55f40eb04f | 3018 | WiFi_Status_t Display_Help_Text() |
mridup | 0:dc55f40eb04f | 3019 | { |
mridup | 0:dc55f40eb04f | 3020 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3021 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3022 | |
mridup | 0:dc55f40eb04f | 3023 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 3024 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_HELP_TEXT); |
mridup | 0:dc55f40eb04f | 3025 | |
mridup | 0:dc55f40eb04f | 3026 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3027 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3028 | { |
mridup | 0:dc55f40eb04f | 3029 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3030 | } |
mridup | 0:dc55f40eb04f | 3031 | return status; |
mridup | 0:dc55f40eb04f | 3032 | } |
mridup | 0:dc55f40eb04f | 3033 | |
mridup | 0:dc55f40eb04f | 3034 | /** |
mridup | 0:dc55f40eb04f | 3035 | * @brief WiFi_Get_IP_address |
mridup | 0:dc55f40eb04f | 3036 | * Get the ip address |
mridup | 0:dc55f40eb04f | 3037 | * @param ip_addr : pointer to ip address |
mridup | 0:dc55f40eb04f | 3038 | * @retval status : status of AT cmd request |
mridup | 0:dc55f40eb04f | 3039 | */ |
mridup | 0:dc55f40eb04f | 3040 | |
mridup | 0:dc55f40eb04f | 3041 | WiFi_Status_t WiFi_Get_IP_Address(uint8_t *ip_addr) |
mridup | 0:dc55f40eb04f | 3042 | { |
mridup | 0:dc55f40eb04f | 3043 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3044 | int cfg_value_length, i; |
mridup | 0:dc55f40eb04f | 3045 | |
mridup | 0:dc55f40eb04f | 3046 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 3047 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_STATUS_VALUE,"ip_ipaddr"); |
mridup | 0:dc55f40eb04f | 3048 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3049 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3050 | { |
mridup | 0:dc55f40eb04f | 3051 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3052 | cfg_value_length = strlen((const char*)get_cfg_value); |
mridup | 0:dc55f40eb04f | 3053 | |
mridup | 0:dc55f40eb04f | 3054 | //Optimise the following loop?? |
mridup | 0:dc55f40eb04f | 3055 | for(i=7; i<=16; i++)//0th index is always ' ' which we ignore |
mridup | 0:dc55f40eb04f | 3056 | if(get_cfg_value[i] == '\r')//find the first '\r' |
mridup | 0:dc55f40eb04f | 3057 | { |
mridup | 0:dc55f40eb04f | 3058 | get_cfg_value[i] = '\0'; //Terminate the string by NULL |
mridup | 0:dc55f40eb04f | 3059 | break; |
mridup | 0:dc55f40eb04f | 3060 | } |
mridup | 0:dc55f40eb04f | 3061 | |
mridup | 0:dc55f40eb04f | 3062 | /* copy user pointer to get_cfg_value */ |
mridup | 0:dc55f40eb04f | 3063 | memcpy(ip_addr,&get_cfg_value[1],i);//IP address will have max lenght fixed at 16 bytes (null terminated included). |
mridup | 0:dc55f40eb04f | 3064 | memset(get_cfg_value, 0x00,cfg_value_length); |
mridup | 0:dc55f40eb04f | 3065 | } |
mridup | 0:dc55f40eb04f | 3066 | return status; |
mridup | 0:dc55f40eb04f | 3067 | } |
mridup | 0:dc55f40eb04f | 3068 | |
mridup | 0:dc55f40eb04f | 3069 | /** |
mridup | 0:dc55f40eb04f | 3070 | * @brief WiFi_Get_MAC_address |
mridup | 0:dc55f40eb04f | 3071 | * Get the MAC address |
mridup | 0:dc55f40eb04f | 3072 | * @param ip_addr : pointer to MAC address |
mridup | 0:dc55f40eb04f | 3073 | * @retval status : status of AT cmd request |
mridup | 0:dc55f40eb04f | 3074 | */ |
mridup | 0:dc55f40eb04f | 3075 | |
mridup | 0:dc55f40eb04f | 3076 | WiFi_Status_t WiFi_Get_MAC_Address(uint8_t *mac_addr) |
mridup | 0:dc55f40eb04f | 3077 | { |
mridup | 0:dc55f40eb04f | 3078 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3079 | int cfg_value_length; |
mridup | 0:dc55f40eb04f | 3080 | |
mridup | 0:dc55f40eb04f | 3081 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 3082 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,"nv_wifi_macaddr"); |
mridup | 0:dc55f40eb04f | 3083 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3084 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3085 | { |
mridup | 0:dc55f40eb04f | 3086 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3087 | cfg_value_length = strlen((const char*)get_cfg_value); |
mridup | 0:dc55f40eb04f | 3088 | get_cfg_value[18] = '\0';//Terminate by NULL |
mridup | 0:dc55f40eb04f | 3089 | /* copy user pointer to get_cfg_value */ |
mridup | 0:dc55f40eb04f | 3090 | memcpy(mac_addr,&get_cfg_value[1],18);//IP address will have max lenght fixed at 18 bytes. |
mridup | 0:dc55f40eb04f | 3091 | memset(get_cfg_value, 0x00,cfg_value_length); |
mridup | 0:dc55f40eb04f | 3092 | } |
mridup | 0:dc55f40eb04f | 3093 | return status; |
mridup | 0:dc55f40eb04f | 3094 | } |
mridup | 0:dc55f40eb04f | 3095 | |
mridup | 0:dc55f40eb04f | 3096 | /** |
mridup | 0:dc55f40eb04f | 3097 | * @brief GET_Configuration_Value |
mridup | 0:dc55f40eb04f | 3098 | * Get a wifi configuration value from the module |
mridup | 0:dc55f40eb04f | 3099 | * @param sVar_name : Name of the config variable |
mridup | 0:dc55f40eb04f | 3100 | * aValue : value of config variable to be returned to user |
mridup | 0:dc55f40eb04f | 3101 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3102 | */ |
mridup | 0:dc55f40eb04f | 3103 | WiFi_Status_t GET_Configuration_Value(char* sVar_name,uint32_t *aValue) |
mridup | 0:dc55f40eb04f | 3104 | { |
mridup | 0:dc55f40eb04f | 3105 | int cfg_value_length; |
mridup | 0:dc55f40eb04f | 3106 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3107 | |
mridup | 0:dc55f40eb04f | 3108 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3109 | |
mridup | 0:dc55f40eb04f | 3110 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 3111 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_GET_CONFIGURATION_VALUE,sVar_name); |
mridup | 0:dc55f40eb04f | 3112 | |
mridup | 0:dc55f40eb04f | 3113 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3114 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3115 | { |
mridup | 0:dc55f40eb04f | 3116 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3117 | cfg_value_length = strlen((const char*)get_cfg_value); |
mridup | 0:dc55f40eb04f | 3118 | memcpy(aValue,get_cfg_value,cfg_value_length); //copy user pointer to get_cfg_value |
mridup | 0:dc55f40eb04f | 3119 | memset(get_cfg_value, 0x00,cfg_value_length); |
mridup | 0:dc55f40eb04f | 3120 | } |
mridup | 0:dc55f40eb04f | 3121 | return status; |
mridup | 0:dc55f40eb04f | 3122 | } |
mridup | 0:dc55f40eb04f | 3123 | |
mridup | 0:dc55f40eb04f | 3124 | /** |
mridup | 0:dc55f40eb04f | 3125 | * @brief SET_Configuration_Addr |
mridup | 0:dc55f40eb04f | 3126 | * Get a wifi configuration address from the module |
mridup | 0:dc55f40eb04f | 3127 | * @param sVar_name : Name of the config variable |
mridup | 0:dc55f40eb04f | 3128 | * addr : value of config address to be returned to user |
mridup | 0:dc55f40eb04f | 3129 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3130 | */ |
mridup | 0:dc55f40eb04f | 3131 | WiFi_Status_t SET_Configuration_Addr(char* sVar_name,char* addr) |
mridup | 0:dc55f40eb04f | 3132 | { |
mridup | 0:dc55f40eb04f | 3133 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3134 | |
mridup | 0:dc55f40eb04f | 3135 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3136 | |
mridup | 0:dc55f40eb04f | 3137 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 3138 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_ADDRESS,sVar_name,addr); |
mridup | 0:dc55f40eb04f | 3139 | |
mridup | 0:dc55f40eb04f | 3140 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3141 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3142 | { |
mridup | 0:dc55f40eb04f | 3143 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3144 | } |
mridup | 0:dc55f40eb04f | 3145 | return status; |
mridup | 0:dc55f40eb04f | 3146 | } |
mridup | 0:dc55f40eb04f | 3147 | |
mridup | 0:dc55f40eb04f | 3148 | /** |
mridup | 0:dc55f40eb04f | 3149 | * @brief SET_Configuration_Value |
mridup | 0:dc55f40eb04f | 3150 | * SET the value of configuration variable |
mridup | 0:dc55f40eb04f | 3151 | * @param sVar_name : Name of the config variable |
mridup | 0:dc55f40eb04f | 3152 | * aValue : value of config variable |
mridup | 0:dc55f40eb04f | 3153 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3154 | */ |
mridup | 0:dc55f40eb04f | 3155 | WiFi_Status_t SET_Configuration_Value(char* sVar_name,uint32_t aValue) |
mridup | 0:dc55f40eb04f | 3156 | { |
mridup | 0:dc55f40eb04f | 3157 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3158 | |
mridup | 0:dc55f40eb04f | 3159 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3160 | |
mridup | 0:dc55f40eb04f | 3161 | /* AT : send AT command */ |
mridup | 0:dc55f40eb04f | 3162 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_VALUE,sVar_name,(int)aValue); |
mridup | 0:dc55f40eb04f | 3163 | |
mridup | 0:dc55f40eb04f | 3164 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3165 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3166 | { |
mridup | 0:dc55f40eb04f | 3167 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3168 | } |
mridup | 0:dc55f40eb04f | 3169 | return status; |
mridup | 0:dc55f40eb04f | 3170 | } |
mridup | 0:dc55f40eb04f | 3171 | |
mridup | 0:dc55f40eb04f | 3172 | /** |
mridup | 0:dc55f40eb04f | 3173 | * @brief SET_SSID |
mridup | 0:dc55f40eb04f | 3174 | * SET SSID in flash memory of Wi-Fi module |
mridup | 0:dc55f40eb04f | 3175 | * @param ssid : pointer of SSID |
mridup | 0:dc55f40eb04f | 3176 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3177 | */ |
mridup | 0:dc55f40eb04f | 3178 | WiFi_Status_t SET_SSID(char* ssid) |
mridup | 0:dc55f40eb04f | 3179 | { |
mridup | 0:dc55f40eb04f | 3180 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3181 | |
mridup | 0:dc55f40eb04f | 3182 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3183 | |
mridup | 0:dc55f40eb04f | 3184 | /* AT+S.SSIDTXT=abcd <ExampleSSID> */ |
mridup | 0:dc55f40eb04f | 3185 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_SSID,ssid); |
mridup | 0:dc55f40eb04f | 3186 | |
mridup | 0:dc55f40eb04f | 3187 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3188 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3189 | { |
mridup | 0:dc55f40eb04f | 3190 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3191 | } |
mridup | 0:dc55f40eb04f | 3192 | return status; |
mridup | 0:dc55f40eb04f | 3193 | } |
mridup | 0:dc55f40eb04f | 3194 | |
mridup | 0:dc55f40eb04f | 3195 | |
mridup | 0:dc55f40eb04f | 3196 | /** |
mridup | 0:dc55f40eb04f | 3197 | * @brief SET_WiFi_SecKey |
mridup | 0:dc55f40eb04f | 3198 | * SET wifi security key |
mridup | 0:dc55f40eb04f | 3199 | * @param seckey : pointer of security key |
mridup | 0:dc55f40eb04f | 3200 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3201 | */ |
mridup | 0:dc55f40eb04f | 3202 | WiFi_Status_t SET_WiFi_SecKey(char* seckey) |
mridup | 0:dc55f40eb04f | 3203 | { |
mridup | 0:dc55f40eb04f | 3204 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3205 | |
mridup | 0:dc55f40eb04f | 3206 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3207 | |
mridup | 0:dc55f40eb04f | 3208 | /* AT+S.SCFG=wifi_wpa_psk_text,helloworld : set password */ |
mridup | 0:dc55f40eb04f | 3209 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_SEC_KEY,seckey); |
mridup | 0:dc55f40eb04f | 3210 | |
mridup | 0:dc55f40eb04f | 3211 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3212 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3213 | { |
mridup | 0:dc55f40eb04f | 3214 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3215 | } |
mridup | 0:dc55f40eb04f | 3216 | return status; |
mridup | 0:dc55f40eb04f | 3217 | } |
mridup | 0:dc55f40eb04f | 3218 | |
mridup | 0:dc55f40eb04f | 3219 | |
mridup | 0:dc55f40eb04f | 3220 | /** |
mridup | 0:dc55f40eb04f | 3221 | * @brief Restore_Default_Setting |
mridup | 0:dc55f40eb04f | 3222 | * Restore the factory default values of the configuration variables |
mridup | 0:dc55f40eb04f | 3223 | * and writes them to non volatile storage |
mridup | 0:dc55f40eb04f | 3224 | * @param None |
mridup | 0:dc55f40eb04f | 3225 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3226 | */ |
mridup | 0:dc55f40eb04f | 3227 | WiFi_Status_t Restore_Default_Setting() |
mridup | 0:dc55f40eb04f | 3228 | { |
mridup | 0:dc55f40eb04f | 3229 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3230 | |
mridup | 0:dc55f40eb04f | 3231 | //Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3232 | |
mridup | 0:dc55f40eb04f | 3233 | /* AT&F: restore default setting */ |
mridup | 0:dc55f40eb04f | 3234 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_RESTORE_DEFAULT_SETTING); |
mridup | 0:dc55f40eb04f | 3235 | |
mridup | 0:dc55f40eb04f | 3236 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3237 | |
mridup | 0:dc55f40eb04f | 3238 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3239 | { |
mridup | 0:dc55f40eb04f | 3240 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3241 | } |
mridup | 0:dc55f40eb04f | 3242 | return status; |
mridup | 0:dc55f40eb04f | 3243 | |
mridup | 0:dc55f40eb04f | 3244 | } |
mridup | 0:dc55f40eb04f | 3245 | |
mridup | 0:dc55f40eb04f | 3246 | /** |
mridup | 0:dc55f40eb04f | 3247 | * @brief Save_Current_Setting |
mridup | 0:dc55f40eb04f | 3248 | * Store the current RAM-based setting to non-volatile storage |
mridup | 0:dc55f40eb04f | 3249 | * @param None |
mridup | 0:dc55f40eb04f | 3250 | * @retval WiFi_Status_t : status of AT cmd Request |
mridup | 0:dc55f40eb04f | 3251 | */ |
mridup | 0:dc55f40eb04f | 3252 | WiFi_Status_t Save_Current_Setting() |
mridup | 0:dc55f40eb04f | 3253 | { |
mridup | 0:dc55f40eb04f | 3254 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3255 | |
mridup | 0:dc55f40eb04f | 3256 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3257 | |
mridup | 0:dc55f40eb04f | 3258 | /* AT&W :Save the settings on the flash memory */ |
mridup | 0:dc55f40eb04f | 3259 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SAVE_CURRENT_SETTING); |
mridup | 0:dc55f40eb04f | 3260 | |
mridup | 0:dc55f40eb04f | 3261 | status = USART_Transmit_AT_Cmd(strlen((char*)WiFi_AT_Cmd_Buff)); |
mridup | 0:dc55f40eb04f | 3262 | if(status == WiFi_MODULE_SUCCESS) |
mridup | 0:dc55f40eb04f | 3263 | { |
mridup | 0:dc55f40eb04f | 3264 | status = USART_Receive_AT_Resp(Process_Event); |
mridup | 0:dc55f40eb04f | 3265 | } |
mridup | 0:dc55f40eb04f | 3266 | return status; |
mridup | 0:dc55f40eb04f | 3267 | } |
mridup | 0:dc55f40eb04f | 3268 | |
mridup | 0:dc55f40eb04f | 3269 | |
mridup | 0:dc55f40eb04f | 3270 | /** |
mridup | 0:dc55f40eb04f | 3271 | * @brief ResetBuffer |
mridup | 0:dc55f40eb04f | 3272 | * Reset receive data/indication msg buffer |
mridup | 0:dc55f40eb04f | 3273 | * @param None |
mridup | 0:dc55f40eb04f | 3274 | * @retval None |
mridup | 0:dc55f40eb04f | 3275 | */ |
mridup | 0:dc55f40eb04f | 3276 | void ResetBuffer() |
mridup | 0:dc55f40eb04f | 3277 | { |
mridup | 0:dc55f40eb04f | 3278 | |
mridup | 0:dc55f40eb04f | 3279 | } |
mridup | 0:dc55f40eb04f | 3280 | |
mridup | 0:dc55f40eb04f | 3281 | |
mridup | 0:dc55f40eb04f | 3282 | /** |
mridup | 0:dc55f40eb04f | 3283 | * @brief config_init_value |
mridup | 0:dc55f40eb04f | 3284 | * initalize config values before reset |
mridup | 0:dc55f40eb04f | 3285 | * @param sVar_name : Name of the config variable |
mridup | 0:dc55f40eb04f | 3286 | * aValue : value of config variable |
mridup | 0:dc55f40eb04f | 3287 | * @retval None |
mridup | 0:dc55f40eb04f | 3288 | */ |
mridup | 0:dc55f40eb04f | 3289 | WiFi_Status_t config_init_value(char* sVar_name,uint8_t aValue) |
mridup | 0:dc55f40eb04f | 3290 | { |
mridup | 0:dc55f40eb04f | 3291 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3292 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3293 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_VALUE,sVar_name,aValue); |
mridup | 0:dc55f40eb04f | 3294 | /*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK) |
mridup | 0:dc55f40eb04f | 3295 | { |
mridup | 0:dc55f40eb04f | 3296 | Error_Handler(); |
mridup | 0:dc55f40eb04f | 3297 | return WiFi_HAL_UART_ERROR; |
mridup | 0:dc55f40eb04f | 3298 | }*/ |
mridup | 0:dc55f40eb04f | 3299 | |
mridup | 0:dc55f40eb04f | 3300 | status = WaitForResponse(AT_RESP_LEN_OK); |
mridup | 0:dc55f40eb04f | 3301 | return status; |
mridup | 0:dc55f40eb04f | 3302 | } |
mridup | 0:dc55f40eb04f | 3303 | |
mridup | 0:dc55f40eb04f | 3304 | /** |
mridup | 0:dc55f40eb04f | 3305 | * @brief config_init_addr |
mridup | 0:dc55f40eb04f | 3306 | * initalize config strings/addresses before reset |
mridup | 0:dc55f40eb04f | 3307 | * @param sVar_name : Name of the config variable |
mridup | 0:dc55f40eb04f | 3308 | * addr : value of config address to be returned to user |
mridup | 0:dc55f40eb04f | 3309 | * @retval None |
mridup | 0:dc55f40eb04f | 3310 | */ |
mridup | 0:dc55f40eb04f | 3311 | WiFi_Status_t config_init_addr(char* sVar_name,char* addr) |
mridup | 0:dc55f40eb04f | 3312 | { |
mridup | 0:dc55f40eb04f | 3313 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3314 | Reset_AT_CMD_Buffer(); |
mridup | 0:dc55f40eb04f | 3315 | sprintf((char*)WiFi_AT_Cmd_Buff,AT_SET_CONFIGURATION_ADDRESS,sVar_name,addr); |
mridup | 0:dc55f40eb04f | 3316 | /*if(HAL_UART_Transmit(&UartWiFiHandle, (uint8_t *)WiFi_AT_Cmd_Buff, strlen((char*)WiFi_AT_Cmd_Buff),1000)!= HAL_OK) |
mridup | 0:dc55f40eb04f | 3317 | { |
mridup | 0:dc55f40eb04f | 3318 | Error_Handler(); |
mridup | 0:dc55f40eb04f | 3319 | return WiFi_HAL_UART_ERROR; |
mridup | 0:dc55f40eb04f | 3320 | }*/ |
mridup | 0:dc55f40eb04f | 3321 | |
mridup | 0:dc55f40eb04f | 3322 | status = WaitForResponse(AT_RESP_LEN_OK); |
mridup | 0:dc55f40eb04f | 3323 | return status; |
mridup | 0:dc55f40eb04f | 3324 | |
mridup | 0:dc55f40eb04f | 3325 | } |
mridup | 0:dc55f40eb04f | 3326 | |
mridup | 0:dc55f40eb04f | 3327 | |
mridup | 0:dc55f40eb04f | 3328 | /** |
mridup | 0:dc55f40eb04f | 3329 | * @brief WaitForResponse |
mridup | 0:dc55f40eb04f | 3330 | * Wait for OK response |
mridup | 0:dc55f40eb04f | 3331 | * @param alength length of the data to be received |
mridup | 0:dc55f40eb04f | 3332 | * @retval None |
mridup | 0:dc55f40eb04f | 3333 | */ |
mridup | 0:dc55f40eb04f | 3334 | WiFi_Status_t WaitForResponse(uint16_t alength) |
mridup | 0:dc55f40eb04f | 3335 | { |
mridup | 0:dc55f40eb04f | 3336 | WiFi_Status_t status = WiFi_MODULE_SUCCESS; |
mridup | 0:dc55f40eb04f | 3337 | |
mridup | 0:dc55f40eb04f | 3338 | if(alength <= RxBufferSize) |
mridup | 0:dc55f40eb04f | 3339 | { |
mridup | 0:dc55f40eb04f | 3340 | /*if(HAL_UART_Receive(&UartWiFiHandle, (uint8_t *)USART_RxBuffer, alength,5000)!= HAL_OK) |
mridup | 0:dc55f40eb04f | 3341 | { |
mridup | 0:dc55f40eb04f | 3342 | Error_Handler(); |
mridup | 0:dc55f40eb04f | 3343 | return WiFi_HAL_UART_ERROR; |
mridup | 0:dc55f40eb04f | 3344 | }*/ |
mridup | 0:dc55f40eb04f | 3345 | |
mridup | 0:dc55f40eb04f | 3346 | if(((strstr((const char *)&USART_RxBuffer,"OK"))) == NULL) |
mridup | 0:dc55f40eb04f | 3347 | { |
mridup | 0:dc55f40eb04f | 3348 | return WiFi_AT_CMD_RESP_ERROR; |
mridup | 0:dc55f40eb04f | 3349 | } |
mridup | 0:dc55f40eb04f | 3350 | |
mridup | 0:dc55f40eb04f | 3351 | } |
mridup | 0:dc55f40eb04f | 3352 | |
mridup | 0:dc55f40eb04f | 3353 | return status; |
mridup | 0:dc55f40eb04f | 3354 | } |
mridup | 0:dc55f40eb04f | 3355 | /**** Wi-Fi indication call back *************/ |
mridup | 0:dc55f40eb04f | 3356 | __weak void ind_wifi_warning(WiFi_Status_t warning_code) |
mridup | 0:dc55f40eb04f | 3357 | { |
mridup | 0:dc55f40eb04f | 3358 | } |
mridup | 0:dc55f40eb04f | 3359 | |
mridup | 0:dc55f40eb04f | 3360 | __weak void ind_wifi_error(WiFi_Status_t error_code) |
mridup | 0:dc55f40eb04f | 3361 | { |
mridup | 0:dc55f40eb04f | 3362 | } |
mridup | 0:dc55f40eb04f | 3363 | |
mridup | 0:dc55f40eb04f | 3364 | __weak void ind_wifi_connection_error(WiFi_Status_t status_code) |
mridup | 0:dc55f40eb04f | 3365 | { |
mridup | 0:dc55f40eb04f | 3366 | } |
mridup | 0:dc55f40eb04f | 3367 | |
mridup | 0:dc55f40eb04f | 3368 | __weak void ind_wifi_connected(void) |
mridup | 0:dc55f40eb04f | 3369 | { |
mridup | 0:dc55f40eb04f | 3370 | } |
mridup | 0:dc55f40eb04f | 3371 | |
mridup | 0:dc55f40eb04f | 3372 | __weak void ind_wifi_ap_ready(void) |
mridup | 0:dc55f40eb04f | 3373 | { |
mridup | 0:dc55f40eb04f | 3374 | } |
mridup | 0:dc55f40eb04f | 3375 | |
mridup | 0:dc55f40eb04f | 3376 | __weak void ind_wifi_ap_client_joined(uint8_t * client_mac_address) |
mridup | 0:dc55f40eb04f | 3377 | { |
mridup | 0:dc55f40eb04f | 3378 | } |
mridup | 0:dc55f40eb04f | 3379 | |
mridup | 0:dc55f40eb04f | 3380 | __weak void ind_wifi_ap_client_left(uint8_t * client_mac_address) |
mridup | 0:dc55f40eb04f | 3381 | { |
mridup | 0:dc55f40eb04f | 3382 | } |
mridup | 0:dc55f40eb04f | 3383 | |
mridup | 0:dc55f40eb04f | 3384 | __weak void ind_wifi_on(void) |
mridup | 0:dc55f40eb04f | 3385 | { |
mridup | 0:dc55f40eb04f | 3386 | } |
mridup | 0:dc55f40eb04f | 3387 | |
mridup | 0:dc55f40eb04f | 3388 | __weak void ind_wifi_packet_lost(WiFi_Status_t status_code) |
mridup | 0:dc55f40eb04f | 3389 | { |
mridup | 0:dc55f40eb04f | 3390 | } |
mridup | 0:dc55f40eb04f | 3391 | |
mridup | 0:dc55f40eb04f | 3392 | __weak void ind_wifi_gpio_changed(void) |
mridup | 0:dc55f40eb04f | 3393 | { |
mridup | 0:dc55f40eb04f | 3394 | } |
mridup | 0:dc55f40eb04f | 3395 | |
mridup | 0:dc55f40eb04f | 3396 | __weak void ind_wifi_socket_data_received(uint8_t socket_id, uint8_t * data_ptr, uint32_t message_size, uint32_t chunk_size) |
mridup | 0:dc55f40eb04f | 3397 | { |
mridup | 0:dc55f40eb04f | 3398 | } |
mridup | 0:dc55f40eb04f | 3399 | |
mridup | 0:dc55f40eb04f | 3400 | __weak void ind_wifi_socket_client_remote_server_closed(uint8_t * socketID) |
mridup | 0:dc55f40eb04f | 3401 | { |
mridup | 0:dc55f40eb04f | 3402 | } |
mridup | 0:dc55f40eb04f | 3403 | |
mridup | 0:dc55f40eb04f | 3404 | __weak void ind_wifi_socket_server_data_lost(void) |
mridup | 0:dc55f40eb04f | 3405 | { |
mridup | 0:dc55f40eb04f | 3406 | } |
mridup | 0:dc55f40eb04f | 3407 | |
mridup | 0:dc55f40eb04f | 3408 | __weak void ind_socket_server_client_joined(void) |
mridup | 0:dc55f40eb04f | 3409 | { |
mridup | 0:dc55f40eb04f | 3410 | } |
mridup | 0:dc55f40eb04f | 3411 | |
mridup | 0:dc55f40eb04f | 3412 | __weak void ind_socket_server_client_left(void) |
mridup | 0:dc55f40eb04f | 3413 | { |
mridup | 0:dc55f40eb04f | 3414 | } |
mridup | 0:dc55f40eb04f | 3415 | |
mridup | 0:dc55f40eb04f | 3416 | __weak void ind_wifi_http_data_available(uint8_t * data_ptr,uint32_t message_size) |
mridup | 0:dc55f40eb04f | 3417 | { |
mridup | 0:dc55f40eb04f | 3418 | } |
mridup | 0:dc55f40eb04f | 3419 | |
mridup | 0:dc55f40eb04f | 3420 | __weak void ind_wifi_file_data_available(uint8_t * data_ptr) |
mridup | 0:dc55f40eb04f | 3421 | { |
mridup | 0:dc55f40eb04f | 3422 | } |
mridup | 0:dc55f40eb04f | 3423 | __weak void ind_wifi_resuming(void) |
mridup | 0:dc55f40eb04f | 3424 | { |
mridup | 0:dc55f40eb04f | 3425 | } |
mridup | 0:dc55f40eb04f | 3426 | |
mridup | 0:dc55f40eb04f | 3427 | |
mridup | 0:dc55f40eb04f | 3428 | |
mridup | 0:dc55f40eb04f | 3429 | /** |
mridup | 0:dc55f40eb04f | 3430 | * @} |
mridup | 0:dc55f40eb04f | 3431 | */ |
mridup | 0:dc55f40eb04f | 3432 | |
mridup | 0:dc55f40eb04f | 3433 | /** |
mridup | 0:dc55f40eb04f | 3434 | * @} |
mridup | 0:dc55f40eb04f | 3435 | */ |
mridup | 0:dc55f40eb04f | 3436 | |
mridup | 0:dc55f40eb04f | 3437 | |
mridup | 0:dc55f40eb04f | 3438 | /** |
mridup | 0:dc55f40eb04f | 3439 | * @} |
mridup | 0:dc55f40eb04f | 3440 | */ |
mridup | 0:dc55f40eb04f | 3441 | |
mridup | 0:dc55f40eb04f | 3442 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |
mridup | 0:dc55f40eb04f | 3443 |