66
77#include < utility>
88
9+ #include " ../radiotap/RadiotapHeaderTx.hpp"
10+ #include " ../radiotap/RadiotapHeaderTxHolder.hpp"
911#include " SchedulingHelper.hpp"
1012#include " WBPacketHeader.h"
11- #include " ../radiotap/RadiotapHeaderTxHolder.hpp"
12- #include " ../radiotap/RadiotapHeaderTx.hpp"
1313
1414WBStreamRx::WBStreamRx (std::shared_ptr<WBTxRx> txrx, Options options1)
1515 : m_txrx(txrx), m_options(options1) {
@@ -158,28 +158,32 @@ void WBStreamRx::set_on_fec_block_done_cb(WBStreamRx::ON_BLOCK_DONE_CB cb) {
158158void WBStreamRx::internal_process_packet (const uint8_t *data, int data_len) {
159159 // Strip WBPacketHeader if present
160160 if (data_len < (int )sizeof (WBPacketHeader)) {
161- m_console->debug (" Packet too short for header: {}" , data_len);
162- return ;
161+ m_console->debug (" Packet too short for header: {}" , data_len);
162+ return ;
163163 }
164164
165- const WBPacketHeader* header = (const WBPacketHeader*)data;
166- const uint8_t * payload = data + sizeof (WBPacketHeader);
165+ const WBPacketHeader * header = (const WBPacketHeader *)data;
166+ const uint8_t * payload = data + sizeof (WBPacketHeader);
167167 int payload_len = data_len - sizeof (WBPacketHeader);
168168
169- // Handle Retransmission Request (if we are the TX side listening to RX side requests)
170- // NOTE: This logic is usually on the TX side. But if we reuse WBStreamRx for receiving telemetry on AIR, we might see this.
171- // However, WBStreamTx logic added previously handles listening for requests.
169+ // Handle Retransmission Request (if we are the TX side listening to RX side
170+ // requests) NOTE: This logic is usually on the TX side. But if we reuse
171+ // WBStreamRx for receiving telemetry on AIR, we might see this. However,
172+ // WBStreamTx logic added previously handles listening for requests.
172173 // WBStreamRx is primarily for receiving data.
173174
174175 if (header->packet_type == WB_PACKET_TYPE_RETRANSMISSION_REQ) {
175- // This is a request. If we are an RX stream, we shouldn't really receive this unless we are debugging or in a loopback.
176- // Or if this WBStreamRx is used on the Air Unit to receive Uplink data, and the Uplink data contains Retransmission Requests.
177- // But typically Retransmission Requests are handled by the callback registered in WBStreamTx.
178- return ;
176+ // This is a request. If we are an RX stream, we shouldn't really receive
177+ // this unless we are debugging or in a loopback. Or if this WBStreamRx is
178+ // used on the Air Unit to receive Uplink data, and the Uplink data contains
179+ // Retransmission Requests. But typically Retransmission Requests are
180+ // handled by the callback registered in WBStreamTx.
181+ return ;
179182 }
180183
181184 if (header->packet_flags & WB_PACKET_FLAG_RETRANSMITTED) {
182- m_console->debug (" Received retransmitted packet, seq: {}" , header->stream_packet_idx );
185+ m_console->debug (" Received retransmitted packet, seq: {}" ,
186+ header->stream_packet_idx );
183187 }
184188
185189 // Gap detection
@@ -197,61 +201,65 @@ void WBStreamRx::internal_process_packet(const uint8_t *data, int data_len) {
197201}
198202
199203void WBStreamRx::check_gap_and_request (uint32_t current_seq_num) {
200- if (!m_first_packet_received) {
201- m_first_packet_received = true ;
202- m_last_seq_num = current_seq_num;
203- return ;
204- }
204+ if (!m_first_packet_received) {
205+ m_first_packet_received = true ;
206+ m_last_seq_num = current_seq_num;
207+ return ;
208+ }
205209
206- // Handle wrap-around using int32_t logic
207- int32_t diff = (int32_t )(current_seq_num - m_last_seq_num);
210+ // Handle wrap-around using int32_t logic
211+ int32_t diff = (int32_t )(current_seq_num - m_last_seq_num);
208212
209- if (diff > 1 ) {
210- // Gap detected
211- // Limit number of requests or range to avoid flooding
212- uint32_t missing_count = diff - 1 ;
213- if (missing_count > 10 ) missing_count = 10 ; // Cap at 10 to avoid huge bursts
213+ if (diff > 1 ) {
214+ // Gap detected
215+ // Limit number of requests or range to avoid flooding
216+ uint32_t missing_count = diff - 1 ;
217+ if (missing_count > 10 )
218+ missing_count = 10 ; // Cap at 10 to avoid huge bursts
214219
215- for (uint32_t i = 1 ; i <= missing_count; i++) {
216- uint32_t missing_seq = m_last_seq_num + i;
217- m_console->debug (" Detected gap. Requesting seq: {}" , missing_seq);
218- send_retransmission_request (missing_seq);
219- }
220+ for (uint32_t i = 1 ; i <= missing_count; i++) {
221+ uint32_t missing_seq = m_last_seq_num + i;
222+ m_console->debug (" Detected gap. Requesting seq: {}" , missing_seq);
223+ send_retransmission_request (missing_seq);
220224 }
225+ }
221226
222- // Update last sequence number
223- // Handle reordered packets? If current < last (diff <= 0), we might have received an old packet (or retransmission).
224- if (diff > 0 ) {
225- m_last_seq_num = current_seq_num;
226- }
227+ // Update last sequence number
228+ // Handle reordered packets? If current < last (diff <= 0), we might have
229+ // received an old packet (or retransmission).
230+ if (diff > 0 ) {
231+ m_last_seq_num = current_seq_num;
232+ }
227233}
228234
229235void WBStreamRx::send_retransmission_request (uint32_t seq_num) {
230- // Construct packet
231- WBPacketHeader header;
232- header.packet_type = WB_PACKET_TYPE_RETRANSMISSION_REQ;
233- header.packet_flags = 0 ;
234- header.stream_packet_idx = seq_num; // Use this field to convey the requested sequence number
235- header.total_length = sizeof (WBPacketHeader);
236-
237- // Create buffer
238- std::vector<uint8_t > packet (sizeof (WBPacketHeader));
239- memcpy (packet.data (), &header, sizeof (WBPacketHeader));
240-
241- // Send using WBTxRx
242- // Need a RadiotapHeaderTx. We can use a default one or create one.
243- // WBTxRx::tx_inject_packet requires a RadiotapHeaderTx.
244- // We can't easily get one here without storing it or creating a default.
245- // Let's create a default one.
246-
247- // Need a RadiotapHeaderTx.
248- RadiotapHeaderTx::UserSelectableParams params{};
249- // Default params usually fine for control packets
250- params.bandwidth = 20 ;
251- params.mcs_index = 0 ; // Low MCS for reliability
252-
253- RadiotapHeaderTx radiotap_header (params);
254-
255- // Use m_options.radio_port for sending?
256- m_txrx->tx_inject_packet (m_options.radio_port , packet.data (), packet.size (), radiotap_header, false );
236+ // Construct packet
237+ WBPacketHeader header;
238+ header.packet_type = WB_PACKET_TYPE_RETRANSMISSION_REQ;
239+ header.packet_flags = 0 ;
240+ header.stream_packet_idx =
241+ seq_num; // Use this field to convey the requested sequence number
242+ header.total_length = sizeof (WBPacketHeader);
243+
244+ // Create buffer
245+ std::vector<uint8_t > packet (sizeof (WBPacketHeader));
246+ memcpy (packet.data (), &header, sizeof (WBPacketHeader));
247+
248+ // Send using WBTxRx
249+ // Need a RadiotapHeaderTx. We can use a default one or create one.
250+ // WBTxRx::tx_inject_packet requires a RadiotapHeaderTx.
251+ // We can't easily get one here without storing it or creating a default.
252+ // Let's create a default one.
253+
254+ // Need a RadiotapHeaderTx.
255+ RadiotapHeaderTx::UserSelectableParams params{};
256+ // Default params usually fine for control packets
257+ params.bandwidth = 20 ;
258+ params.mcs_index = 0 ; // Low MCS for reliability
259+
260+ RadiotapHeaderTx radiotap_header (params);
261+
262+ // Use m_options.radio_port for sending?
263+ m_txrx->tx_inject_packet (m_options.radio_port , packet.data (), packet.size (),
264+ radiotap_header, false );
257265}
0 commit comments