Add debug logging to overflow/error paths, fix pipeline=2 drop
This commit is contained in:
@@ -13,15 +13,17 @@ struct ring_buffer {
|
|||||||
uint16_t free() const { return N - used(); }
|
uint16_t free() const { return N - used(); }
|
||||||
bool empty() const { return head == tail; }
|
bool empty() const { return head == tail; }
|
||||||
|
|
||||||
void push(std::span<const T> src) {
|
bool push(std::span<const T> src) {
|
||||||
if (src.size() > free()) return;
|
if (src.size() > free()) return false;
|
||||||
for (auto& v : src)
|
for (auto& v : src)
|
||||||
data[(tail++) % N] = v;
|
data[(tail++) % N] = v;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(const T& v) {
|
bool push(const T& v) {
|
||||||
if (free() == 0) return;
|
if (free() == 0) return false;
|
||||||
data[(tail++) % N] = v;
|
data[(tail++) % N] = v;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_overwrite(const T& v) {
|
void push_overwrite(const T& v) {
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
struct usb_cdc {
|
struct usb_cdc {
|
||||||
ring_buffer<uint8_t, 8192> tx;
|
ring_buffer<uint8_t, 8192> tx;
|
||||||
|
|
||||||
void send(std::span<const uint8_t> data) {
|
bool send(std::span<const uint8_t> data) {
|
||||||
tx.push(data);
|
if (!tx.push(data)) return false;
|
||||||
drain();
|
drain();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(const std::vector<uint8_t>& data) {
|
void send(const std::vector<uint8_t>& data) {
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ void dispatch_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timer_handle dispatch_schedule_ms(uint32_t ms, std::function<void()> fn) {
|
timer_handle dispatch_schedule_ms(uint32_t ms, std::function<void()> fn) {
|
||||||
return timers.schedule_ms(ms, std::move(fn));
|
auto h = timers.schedule_ms(ms, std::move(fn));
|
||||||
|
if (!h) dlogf("timer alloc failed: %lu ms", static_cast<unsigned long>(ms));
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dispatch_cancel_timer(timer_handle h) {
|
bool dispatch_cancel_timer(timer_handle h) {
|
||||||
@@ -45,7 +47,10 @@ bool dispatch_cancel_timer(timer_handle h) {
|
|||||||
|
|
||||||
auto dispatch_msg = [&](const DecodedMessage& msg, std::function<void(std::span<const uint8_t>)> send) {
|
auto dispatch_msg = [&](const DecodedMessage& msg, std::function<void(std::span<const uint8_t>)> send) {
|
||||||
auto it = handler_map.find(msg.type_id);
|
auto it = handler_map.find(msg.type_id);
|
||||||
if (it == handler_map.end()) return;
|
if (it == handler_map.end()) {
|
||||||
|
dlogf("dispatch: unknown type_id %d", msg.type_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
responder resp{msg.message_id, std::move(send)};
|
responder resp{msg.message_id, std::move(send)};
|
||||||
it->second(resp, msg.payload);
|
it->second(resp, msg.payload);
|
||||||
};
|
};
|
||||||
@@ -79,8 +84,10 @@ bool dispatch_cancel_timer(timer_handle h) {
|
|||||||
|
|
||||||
dispatch_msg(*msg, [&](std::span<const uint8_t> data) {
|
dispatch_msg(*msg, [&](std::span<const uint8_t> data) {
|
||||||
if (data.size() <= usb.tx.free()) {
|
if (data.size() <= usb.tx.free()) {
|
||||||
usb.send(data);
|
if (!usb.send(data))
|
||||||
|
dlogf("usb send failed: %zu bytes, %u free", data.size(), usb.tx.free());
|
||||||
} else {
|
} else {
|
||||||
|
dlogf("usb response too large: %zu bytes, %u free", data.size(), usb.tx.free());
|
||||||
uint8_t err_buf[256];
|
uint8_t err_buf[256];
|
||||||
span_writer err_out(err_buf, sizeof(err_buf));
|
span_writer err_out(err_buf, sizeof(err_buf));
|
||||||
auto err = encode_response_into(err_out, msg->message_id,
|
auto err = encode_response_into(err_out, msg->message_id,
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ static std::vector<net_frame_callback> frame_callbacks;
|
|||||||
|
|
||||||
void net_send_raw(std::span<const uint8_t> data) {
|
void net_send_raw(std::span<const uint8_t> data) {
|
||||||
dlog_if_slow("net_send_raw", 1000, [&]{
|
dlog_if_slow("net_send_raw", 1000, [&]{
|
||||||
w6300::send(raw_socket, data);
|
auto result = w6300::send(raw_socket, data);
|
||||||
|
if (!result)
|
||||||
|
dlogf("w6300 send failed: %zu bytes, err %d",
|
||||||
|
data.size(), static_cast<int>(result.error()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ static void start_ping_rate(const responder& resp, uint16_t target,
|
|||||||
ping_rate_send_one(st);
|
ping_rate_send_one(st);
|
||||||
net_add_frame_callback(*cb);
|
net_add_frame_callback(*cb);
|
||||||
|
|
||||||
st->timer = dispatch_schedule_ms(60000, [st]() {
|
st->timer = dispatch_schedule_ms(10000, [st]() {
|
||||||
uint32_t elapsed_us = time_us_32() - st->start_us;
|
uint32_t elapsed_us = time_us_32() - st->start_us;
|
||||||
char msg[64];
|
char msg[64];
|
||||||
snprintf(msg, sizeof(msg), "timeout after %u/%u rt in %lu ms",
|
snprintf(msg, sizeof(msg), "timeout after %u/%u rt in %lu ms",
|
||||||
|
|||||||
Reference in New Issue
Block a user