Skip to content

Commit c5ed3b1

Browse files
committed
Fix ESP_NOW_Serial
1 parent 1f34934 commit c5ed3b1

File tree

2 files changed

+8
-64
lines changed

2 files changed

+8
-64
lines changed

libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp

+6-56
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t chan
1515
: ESP_NOW_Peer(mac_addr, channel, iface, lmk){
1616
tx_ring_buf = NULL;
1717
rx_queue = NULL;
18-
rx2_queue = NULL;
1918
tx_sem = NULL;
20-
last_tx_result = false;
2119
queued_size = 0;
2220
queued_buff = NULL;
2321
resend_count = 0;
2422
}
2523

2624
ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class(){
27-
25+
end();
2826
}
2927

3028
size_t ESP_NOW_Serial_Class::setTxBufferSize(size_t tx_queue_len){
@@ -57,22 +55,6 @@ size_t ESP_NOW_Serial_Class::setRxBufferSize(size_t rx_queue_len){
5755
return rx_queue_len;
5856
}
5957

60-
size_t ESP_NOW_Serial_Class::setRx2BufferSize(size_t rx_queue_len){
61-
if(rx2_queue){
62-
if(!rx_queue_len){
63-
vQueueDelete(rx2_queue);
64-
rx_queue = NULL;
65-
}
66-
return 0;
67-
} else if(rx_queue_len){
68-
rx2_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
69-
if(!rx2_queue){
70-
return 0;
71-
}
72-
}
73-
return rx_queue_len;
74-
}
75-
7658
bool ESP_NOW_Serial_Class::begin(unsigned long baud){
7759
if(!ESP_NOW.begin() || !add()){
7860
return false;
@@ -83,15 +65,13 @@ bool ESP_NOW_Serial_Class::begin(unsigned long baud){
8365
xSemaphoreGive(tx_sem);
8466
}
8567
setRxBufferSize(1024);//default if not preset
86-
setRx2BufferSize(0);//default if not preset
8768
setTxBufferSize(1024);//default if not preset
8869
return true;
8970
}
9071

9172
void ESP_NOW_Serial_Class::end(){
9273
remove();
9374
setRxBufferSize(0);
94-
setRx2BufferSize(0);
9575
setTxBufferSize(0);
9676
if (tx_sem != NULL) {
9777
vSemaphoreDelete(tx_sem);
@@ -158,47 +138,17 @@ void ESP_NOW_Serial_Class::flush(){
158138
vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting);
159139
}
160140
}
161-
//Upper chars
162-
int ESP_NOW_Serial_Class::available2(void){
163-
if(rx2_queue == NULL){
164-
return -1;
165-
}
166-
return uxQueueMessagesWaiting(rx2_queue);
167-
}
168-
169-
int ESP_NOW_Serial_Class::read2(void){
170-
if(rx2_queue == NULL){
171-
return -1;
172-
}
173-
uint8_t c = 0;
174-
if(xQueueReceive(rx2_queue, &c, 0)) {
175-
return c;
176-
}
177-
return -1;
178-
}
179141

180142
//RX callback
181143
void ESP_NOW_Serial_Class::_onReceive(const uint8_t * data, size_t len){
182-
if(rx_queue == NULL && rx2_queue == NULL){
144+
if(rx_queue == NULL){
183145
return;
184146
}
185-
log_v(MACSTR", data lenght : %u", MAC2STR(addr()), len);
147+
log_v(MACSTR ", data lenght : %u", MAC2STR(addr()), len);
186148
for(uint32_t i=0; i<len; i++){
187-
if(rx2_queue != NULL && (data[i] & 0x80)){
188-
//it's upper char and rx2_queue exists
189-
if(!xQueueSend(rx2_queue, data+i, 0)){
190-
return;
191-
}
192-
} else if(rx_queue != NULL){
193-
//either normal char or rx2_queue does not exist
194-
if(!xQueueSend(rx_queue, data+i, 0)){
195-
return;
196-
}
197-
} else if(rx2_queue != NULL){
198-
//we have disabled rx_queue and are forwarding all to rx2
199-
if(!xQueueSend(rx2_queue, data+i, 0)){
200-
return;
201-
}
149+
if(!xQueueSend(rx_queue, data+i, 0)){
150+
log_e("RX Overflow!");
151+
return;
202152
}
203153
}
204154
// Now trigger the ISR to read data from the ring buffer.

libraries/ESP_NOW/src/ESP32_NOW_Serial.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer {
1313
private:
1414
RingbufHandle_t tx_ring_buf;
15-
xQueueHandle rx_queue;
16-
xQueueHandle rx2_queue;
17-
xSemaphoreHandle tx_sem;
18-
bool last_tx_result;
15+
QueueHandle_t rx_queue;
16+
SemaphoreHandle_t tx_sem;
1917
size_t queued_size;
2018
uint8_t *queued_buff;
2119
size_t resend_count;
@@ -26,7 +24,6 @@ class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer {
2624
ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface=WIFI_IF_AP, const uint8_t *lmk=NULL);
2725
~ESP_NOW_Serial_Class();
2826
size_t setRxBufferSize(size_t);
29-
size_t setRx2BufferSize(size_t);
3027
size_t setTxBufferSize(size_t);
3128
bool begin(unsigned long baud=0);
3229
void end();
@@ -36,9 +33,6 @@ class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer {
3633
size_t read(uint8_t *buffer, size_t size);
3734
int peek();
3835
void flush();
39-
//Upper chars
40-
int available2();
41-
int read2();
4236
//Print
4337
int availableForWrite();
4438
size_t write(const uint8_t *buffer, size_t size, uint32_t timeout_ms);

0 commit comments

Comments
 (0)