Skip to content
Snippets Groups Projects
Commit db2530e3 authored by Christian Mauch's avatar Christian Mauch
Browse files

Robustify ARQStream reset response handling

Buffered data from previous runs, e.g. lots of spike data,  is now dropped more vigorously.
* different packets in-between potential multiple response packets are
  dropped
* modify drop_receive_queue behaviour in case of loopback packet to
  switch to timeout mode if packets are still available in rx buffer after
  loopback packet was received.

Change-Id: Ib83ba819df71db58bd606d97220abb24478aa10a
parent a0370693
No related branches found
No related tags found
No related merge requests found
......@@ -110,10 +110,11 @@ public:
// throws if no unique queue present for given pid
bool received_packet_available(packetid_t pid) const;
// drops all incoming packets. Returns when timeout since last received packet is reached
// returned value is number of dropped words
// if control packet is set, a loopback packet will be sent to FPGA and checked if packet is
// received
// Blocks until we don't receive any more data within a `timeout` time frame while the data
// received is discarded. The `timeout` restarts for every packet received.
// When `with_control_packet` is set, we send a loopback packet to the FPGA and wait for it to
// be received again; if we still see traffic we continue to drop data until timeout is
// reached. Returns the number of dropped words.
size_t drop_receive_queue(
std::chrono::microseconds timeout = std::chrono::microseconds(10000),
bool with_control_packet = false);
......
......@@ -456,7 +456,7 @@ size_t ARQStream<P>::drop_receive_queue(microseconds timeout, bool with_control_
sleep_interval_idx = 0;
accumulated_sleep = 0ms;
bool loopback_found = false;
while (!loopback_found && accumulated_sleep < timeout) {
while (accumulated_sleep < timeout) {
if (received_packet_available()) {
// fetch packet, analyse if loopback else drop
sleep_interval_idx = 0;
......@@ -472,12 +472,11 @@ size_t ARQStream<P>::drop_receive_queue(microseconds timeout, bool with_control_
name + ": received magic word " + std::to_string(my_packet.pdu[0]) +
" differs from sent word " + std::to_string(magic_number));
}
if (received_packet_available()) {
throw std::runtime_error(
name + ": still packets available after loopback received");
}
loopback_found = true;
break;
// if no further packets available exit else continue dropping until timeout
if (!received_packet_available()) {
break;
}
}
dropped_words += my_packet.len;
} else {
......@@ -588,12 +587,17 @@ void ARQStream<P>::parse_response()
remainder -= my_packet.len - payload_start_index;
if (remainder > 0) {
// end of current packet but still info remaining -> next packet
if (!received_packet_available()) {
throw std::runtime_error("No packets available");
}
receive(my_packet);
if (my_packet.pid != PTYPE_CFG_TYPE) {
throw std::runtime_error("Response packet has wrong packet type");
// other packets from previous experiments could still be buffered, need to drop them
// run until next remainder of response packet is found or no packets available anymore
bool got_remainder = false;
while (!got_remainder) {
if (!received_packet_available()) {
throw std::runtime_error("No reset response remainder packets available");
}
receive(my_packet);
if (my_packet.pid == PTYPE_CFG_TYPE) {
got_remainder = true;
}
}
payload_start_index = 0;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment