Delay remote ACK delivery independently in the BLE fixture
This commit is contained in:
1 parent
46f2137f06
commit
b31b772e66
1 file changed
+8
-3
@@ -9,7 +9,7 @@
|
||||
#define CHECK(v) do { if (!(v)) { fprintf(stderr, "FAIL line=%d: %s\n", __LINE__, #v); exit(1); } } while (0)
|
||||
struct fake_link {
|
||||
ble_link_id id, other; struct ble_backend* peer; uint8_t data[512]; size_t len; int pending;
|
||||
enum ble_wire_channel channel; uint64_t ack_at; uint16_t ack_id, ack_delivered;
|
||||
enum ble_wire_channel channel; uint64_t ack_at; uint16_t ack_id, ack_delivered; int ack_held;
|
||||
};
|
||||
struct ble_backend { struct ble_transport* owner; struct UASYNC* ua; void* task; int index, started; struct fake_link links[16]; };
|
||||
static struct ble_backend* backends[3];
|
||||
@@ -63,13 +63,18 @@ static void run(void* arg) {
|
||||
if (!b->started) { b->started = 1; ble_backend_status(b->owner, 1, "fake ready"); }
|
||||
for (int i = 0; i < 16; i++) {
|
||||
struct fake_link* f = &b->links[i]; if (!f->id) continue;
|
||||
if (!hold_ack && f->ack_held) {
|
||||
uint8_t ack[2] = {f->ack_id >> 8, f->ack_id}; f->ack_held = 0; f->ack_delivered = f->ack_id;
|
||||
if (f->peer && slot(f->peer, f->other)) ble_backend_received(f->peer->owner, f->other, BLE_WIRE_ACK, ack, 2);
|
||||
}
|
||||
if (!f->len) { f->len = 1; ble_backend_opened(b->owner, f->id, mtu); }
|
||||
if (!f->pending || hold || (hold_ack && f->channel == BLE_WIRE_ACK)) continue;
|
||||
if (!f->pending || hold) continue;
|
||||
ble_link_id id = f->id, other = f->other;
|
||||
struct ble_backend* peer = f->peer;
|
||||
uint8_t data[512]; size_t len = f->len; memcpy(data, f->data, len); f->pending = 0;
|
||||
int dropped = f->channel != BLE_WIRE_ACK && data[f->channel == BLE_WIRE_DATA ? 2 : 0] == 3 && drop && --drop == 0;
|
||||
if (!dropped && peer && slot(peer, other)) {
|
||||
if (hold_ack && f->channel == BLE_WIRE_ACK) f->ack_held = 1;
|
||||
else if (!dropped && peer && slot(peer, other)) {
|
||||
if (f->channel == BLE_WIRE_ACK) f->ack_delivered = f->ack_id;
|
||||
ble_backend_received(peer->owner, other, f->channel, data, len);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user