Skip to content

Commit d339fb8

Browse files
committed
udp_model.c: enforce minimum spacing between Rx packets in raw mode
that was effectively zero also slightly increase lead-time for packets in badger-client mode 28 cycles is still lower than will be seen in real life
1 parent b94ba1f commit d339fb8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

badger/tests/udp_model.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ struct udp_state *udp_setup_r(unsigned short udp_port_, int badger_client_)
132132
exit(1);
133133
}
134134
setup_receive(ust->udpfd, INADDR_ANY, udp_port_);
135-
/* setup_transmit(udpfd, lskdjfsdlj, 2000); */
136135
fcntl(ust->udpfd, F_SETFL, O_NONBLOCK);
137136
return ust;
138137
}
@@ -164,14 +163,14 @@ void udp_receiver_r(struct udp_state *ust, int *in_octet, int *in_valid, int *in
164163
inbuf->len = rc;
165164
inbuf->cur = 0;
166165
ust->sleepctr = 0;
167-
ust->preamble_cnt = 18; /* should be 44(?) but I'm easily bored. */
166+
ust->preamble_cnt = 28; /* should be 44(?) but I'm easily bored. */
168167
if (udp_model_debug) {
169168
fputs("Rx:", stderr);
170169
print_buf(stderr, inbuf);
171170
}
172171
}
173172
}
174-
if (ust->badger_client) { // Badger client interface
173+
if (ust->badger_client) { /* Badger client interface */
175174
if (ust->preamble_cnt > 0) {
176175
--(ust->preamble_cnt);
177176
if (in_valid) *in_valid = 1;
@@ -184,6 +183,15 @@ void udp_receiver_r(struct udp_state *ust, int *in_octet, int *in_valid, int *in
184183
if (in_count) *in_count = 0;
185184
return;
186185
}
186+
} else {
187+
/* Even Raw mode needs a well-defined minimum time between packets */
188+
if (ust->preamble_cnt > 0) {
189+
--(ust->preamble_cnt);
190+
if (in_valid) *in_valid = 0;
191+
if (in_count) *in_count = 0;
192+
if (in_octet) *in_octet = 0;
193+
return;
194+
}
187195
}
188196
if (inbuf->cur < inbuf->len) {
189197
if (in_octet) *in_octet = inbuf->buf[inbuf->cur];

0 commit comments

Comments
 (0)