Skip to content

Commit 8b0daea

Browse files
clang format
1 parent c2096be commit 8b0daea

File tree

8 files changed

+472
-450
lines changed

8 files changed

+472
-450
lines changed

wifibroadcast/executables/unit_test.cpp

Lines changed: 292 additions & 281 deletions
Large diffs are not rendered by default.

wifibroadcast/src/HelperSources/SchedulingHelper.hpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
#include <sys/resource.h>
1010
#include <unistd.h>
1111

12+
#include <fstream>
1213
#include <iostream>
1314
#include <sstream>
1415
#include <string>
1516

16-
#include <fstream>
17-
1817
namespace SchedulingHelper {
1918

2019
// Only 'low' in comparison to other realtime tasks
@@ -35,27 +34,23 @@ static void set_thread_params_max_realtime(const std::string& tag,
3534
param.sched_priority = priority;
3635
auto result = pthread_setschedparam(target, policy, &param);
3736

38-
39-
std::ifstream file("/usr/share/openhd/debug.txt");
40-
if (file.good()) {
41-
42-
43-
44-
if (result != 0) {
45-
std::stringstream ss;
46-
ss << "Cannot setThreadParamsMaxRealtime " << result;
47-
std::cerr << ss.str() << std::endl;
48-
} else {
49-
std::stringstream ss;
50-
ss << "Changed prio ";
51-
if (!tag.empty()) {
52-
ss << "for " << tag << " ";
37+
std::ifstream file("/usr/share/openhd/debug.txt");
38+
if (file.good()) {
39+
if (result != 0) {
40+
std::stringstream ss;
41+
ss << "Cannot setThreadParamsMaxRealtime " << result;
42+
std::cerr << ss.str() << std::endl;
43+
} else {
44+
std::stringstream ss;
45+
ss << "Changed prio ";
46+
if (!tag.empty()) {
47+
ss << "for " << tag << " ";
48+
}
49+
ss << "to SCHED_FIFO:" << param.sched_priority;
50+
std::cout << ss.str() << std::endl;
5351
}
54-
ss << "to SCHED_FIFO:" << param.sched_priority;
55-
std::cout << ss.str() << std::endl;
5652
}
5753
}
58-
}
5954

6055
static bool check_root() {
6156
const auto uid = getuid();

wifibroadcast/src/WBPacketHeader.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
// Header structure close to Ruby's implementation but simplified for this task
1616
struct WBPacketHeader {
17-
uint8_t packet_flags; // Flags (e.g., retransmitted)
18-
uint8_t packet_type; // Type (Video, Telemetry, RC, etc.)
19-
uint32_t stream_packet_idx; // Sequence number for the stream
20-
uint16_t total_length; // Total length of the packet including header
21-
// Additional fields can be added here to match Ruby's t_packet_header if needed
22-
// u16 radio_link_packet_index;
23-
// u32 vehicle_id_src;
24-
// u32 vehicle_id_dest;
17+
uint8_t packet_flags; // Flags (e.g., retransmitted)
18+
uint8_t packet_type; // Type (Video, Telemetry, RC, etc.)
19+
uint32_t stream_packet_idx; // Sequence number for the stream
20+
uint16_t total_length; // Total length of the packet including header
21+
// Additional fields can be added here to match Ruby's t_packet_header if
22+
// needed u16 radio_link_packet_index; u32 vehicle_id_src; u32
23+
// vehicle_id_dest;
2524
} __attribute__((packed));

wifibroadcast/src/WBStreamRx.cpp

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
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

1414
WBStreamRx::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) {
158158
void 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

199203
void 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

229235
void 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

Comments
 (0)