diff --git a/src/Arduino_10BASE_T1S_UDP.cpp b/src/Arduino_10BASE_T1S_UDP.cpp index 7b7a105..2f40838 100644 --- a/src/Arduino_10BASE_T1S_UDP.cpp +++ b/src/Arduino_10BASE_T1S_UDP.cpp @@ -235,8 +235,12 @@ void Arduino_10BASE_T1S_UDP::onUdpRawRecv(struct udp_pcb *pcb, struct pbuf *p, c (uint8_t const *)p->payload, p->len); - _rx_pkt_list.push_back(rx_pkt); + // drop the oldest packet if the list is full + if(_rx_pkt_list.size() > _rx_pkt_list_size) { + _rx_pkt_list.pop_front(); + } + _rx_pkt_list.push_back(rx_pkt); /* Free pbuf */ pbuf_free(p); } diff --git a/src/Arduino_10BASE_T1S_UDP.h b/src/Arduino_10BASE_T1S_UDP.h index 399a15f..8f96cab 100644 --- a/src/Arduino_10BASE_T1S_UDP.h +++ b/src/Arduino_10BASE_T1S_UDP.h @@ -66,7 +66,9 @@ class Arduino_10BASE_T1S_UDP : public UDP * it's used for internal purposes only. */ void onUdpRawRecv(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, uint16_t port); - + void bufferSize(int size) { + _rx_pkt_list_size = size; + } private: /* LWIP */ @@ -76,7 +78,7 @@ class Arduino_10BASE_T1S_UDP : public UDP IPAddress _send_to_ip; uint16_t _send_to_port; std::vector _tx_data; - + int _rx_pkt_list_size = 10; /* UDP RECEPTION */ class UdpRxPacket {