esp8266: make received data available
This commit is contained in:
parent
462a65cb92
commit
24cec3850d
@ -32,13 +32,15 @@
|
||||
/** @} */
|
||||
|
||||
/* input and output buffers and used memory */
|
||||
static uint8_t rx_buffer[24] = {0}; /**< buffer for received data (we only expect AT responses) */
|
||||
static uint8_t rx_buffer[24 + 530] = {0}; /**< buffer for received data */
|
||||
static volatile uint16_t rx_used = 0; /**< number of byte in receive buffer */
|
||||
static uint8_t tx_buffer[256] = {0}; /**< buffer for data to transmit */
|
||||
static volatile uint16_t tx_used = 0; /**< number of bytes used in transmit buffer */
|
||||
|
||||
volatile bool radio_esp8266_activity = false;
|
||||
volatile bool radio_esp8266_success = false;
|
||||
uint8_t radio_esp8266_received[512 + 18];
|
||||
uint16_t radio_esp8266_received_len = 0;
|
||||
|
||||
/** transmit data to radio
|
||||
* @param[in] data data to transmit
|
||||
@ -180,6 +182,24 @@ void USART_ISR(RADIO_ESP8266_USART)(void)
|
||||
radio_esp8266_activity = true; // response received
|
||||
radio_esp8266_success = false; // command failed
|
||||
rx_used = 0; // reset buffer
|
||||
} else if (rx_used >= 7 && memcmp((char*)&rx_buffer[0], "\r\n+IPD,", 7) == 0) { // IP data being received
|
||||
// find if we received the length
|
||||
int32_t data_length = 0;
|
||||
uint32_t data_start = 0;
|
||||
for (uint16_t i = 7; i < rx_used; i++) {
|
||||
if (':' == rx_buffer[i]) {
|
||||
data_start = i + 1;
|
||||
data_length = atoi((char*)&rx_buffer[7]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (data_length > 0 && rx_used >= data_start + data_length) {
|
||||
if ((uint32_t)data_length <= LENGTH(radio_esp8266_received)) {
|
||||
memcpy(radio_esp8266_received, &rx_buffer[data_start], data_length);
|
||||
radio_esp8266_received_len = data_length;
|
||||
}
|
||||
rx_used = 0; // reset buffer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,10 @@
|
||||
extern volatile bool radio_esp8266_activity;
|
||||
/** the last command has succeeded */
|
||||
extern volatile bool radio_esp8266_success;
|
||||
/** data received (overwritten upon next receive) */
|
||||
extern uint8_t radio_esp8266_received[];
|
||||
/** length of receive data */
|
||||
extern uint16_t radio_esp8266_received_len;
|
||||
|
||||
/** setup peripherals to communicate with radio
|
||||
* @note this is blocking to ensure we are connected to the WiFi network
|
||||
|
Loading…
Reference in New Issue
Block a user