- #include "ESP8266.h"
- #include "ESP8266Config.h"
- //#########################################################################################################
- bool Wifi_SendRaw(uint8_t *data,uint16_t len)
- {
- if(len <= _WIFI_TX_SIZE)
- {
- // Send the information in data through the UART of the ESP8266
- memcpy(Wifi.TxBuffer,data,len);
- if(HAL_UART_Transmit(&_WIFI_USART,data,len,900) == HAL_OK)
- return true;
- else
- return false;
- }
- else
- return false;
- }
- //#########################################################################################################
- bool Wifi_SendString(char *data)
- {
- return Wifi_SendRaw((uint8_t*)data,strlen(data));
- }
- //#########################################################################################################
- bool Wifi_SendStringAndWait(char *data,uint16_t DelayUs)
- {
- if(Wifi_SendRaw((uint8_t*)data,strlen(data))==false)
- return false;
- DWT_Delay_us(DelayUs);
- return true;
- }
- //#########################################################################################################
- bool Wifi_WaitForString(uint32_t TimeOut_ms,uint8_t *result,uint8_t CountOfParameter,...)
- {
- /*
- * It uses the CountOfParameter and the Parameters after that to compare with the
- * information that it was received in the UART RX. If the parameter is in the
- * received string the functions return a true value and the position of the
- * parameter (according to the position in the function)
- *
- * Ex:
- * Wifi_WaitForString(_WIFI_WAIT_TIME_LOW,&result,2,"OK","ERROR")
- *
- * If the ESP8266 return a AT+OK after the last command, the function is going to
- * return a true value and the result number would be 1.
- */
- if(result == NULL)
- return false;
- if(CountOfParameter == 0)
- return false;
- *result=0;
- va_list tag;
- va_start (tag,CountOfParameter);
- char *arg[CountOfParameter];
- for(uint8_t i=0; i arg = va_arg (tag, char *);
- va_end (tag);
- for(uint32_t t=0 ; t
- {
- DWT_Delay_us(20000);
- for(uint8_t mx=0 ; mx
- {
- if(strstr((char*)Wifi.RxBuffer,arg[mx])!=NULL)
- {
- *result = mx+1;
- return true;
- }
- }
- }
- // timeout
- return false;
- }
- //#########################################################################################################
- bool Wifi_ReturnString(char *result,uint8_t WantWhichOne,char *SplitterChars)
- {
- if(result == NULL)
- return false;
- if(WantWhichOne==0)
- return false;
- char *str = (char*)Wifi.RxBuffer;
- str = strtok (str,SplitterChars);
- if(str == NULL)
- {
- strcpy(result,"");
- return false;
- }
- while (str != NULL)
- {
- str = strtok (NULL,SplitterChars);
- if(str != NULL)
- WantWhichOne--;
- if(WantWhichOne==0)
- {
- strcpy(result,str);
- return true;
- }
- }
- strcpy(result,"");
- return false;
- }
- //#########################################################################################################
- bool Wifi_ReturnStrings(char *InputString,char *SplitterChars,uint8_t CountOfParameter,...)
- {
- if(CountOfParameter == 0)
- return false;
- va_list tag;
- va_start (tag,CountOfParameter);
- char *arg[CountOfParameter];
- for(uint8_t i=0; i
- arg = va_arg (tag, char *);
- va_end (tag);
- char *str;
- str = strtok (InputString,SplitterChars);
- if(str == NULL)
- return false;
- uint8_t i=0;
- while (str != NULL)
- {
- str = strtok (NULL,SplitterChars);
- if(str != NULL)
- CountOfParameter--;
- strcpy(arg,str);
- i++;
- if(CountOfParameter==0)
- {
- return true;
- }
- }
- return false;
- }
0
|
1个回答
|
|
|