Record BLE negotiation evidence and retry pre-transfer radio connections
This commit is contained in:
1 parent
05d78c9960
commit
8081f94ebe
3 files changed
+116
-11
No files matched your search
@@ -12,7 +12,7 @@ static struct ble_transport* transport;
|
||||
static ble_link_id session;
|
||||
static unsigned sent, received_count, blocked;
|
||||
static int failed, dial, seen, radio_ready;
|
||||
static uint64_t peer, expected_peer, started, verified_bytes;
|
||||
static uint64_t peer, expected_peer, started, verified_bytes, retry;
|
||||
static const unsigned lengths[] = {1,13,14,20,244,512,1499,1500};
|
||||
static unsigned length(unsigned n) { return lengths[n % 8]; }
|
||||
static uint8_t probe_byte(unsigned n, unsigned i) { return (uint8_t)(n + i * 37); }
|
||||
@@ -46,7 +46,13 @@ static void connected(void* arg, ble_link_id id, uint64_t node, enum ble_state s
|
||||
(void)arg;
|
||||
printf("CONNECTION link=%llu peer=%016llx state=%d reason=%s\n", (unsigned long long)id, (unsigned long long)node, state, reason);
|
||||
if (state == BLE_READY) { session = id; peer = node; started = get_time_us(); send_more(NULL, id); }
|
||||
if (state == BLE_CLOSED && received_count < 96) failed = 1;
|
||||
if (state == BLE_CLOSED && received_count < 96) {
|
||||
if (started) failed = 1;
|
||||
else {
|
||||
session = 0; retry = get_time_us() + 1000000;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DISCOVERY, "BLE probe closed before transfer; retrying discovery");
|
||||
}
|
||||
}
|
||||
}
|
||||
static void status(void* arg, enum ble_state state, const char* reason) {
|
||||
(void)arg; printf("STATUS state=%d reason=%s\n", state, reason);
|
||||
@@ -63,7 +69,10 @@ static void broadcast(void* arg, const struct ble_endpoint* ep, const uint8_t* d
|
||||
if (!seen) printf("DISCOVER node=%016llx name=%s rssi=%d endpoint=%s\n",
|
||||
(unsigned long long)identity.node_id, identity.name, rssi, ep->id);
|
||||
seen = 1;
|
||||
if (dial && radio_ready && !session) { session = ble_connect(transport, ep, identity.node_id); if (!session) failed = 1; }
|
||||
if (dial && radio_ready && !session && get_time_us() >= retry) {
|
||||
session = ble_connect(transport, ep, identity.node_id);
|
||||
if (!session) { DEBUG_WARN(DEBUG_CATEGORY_DISCOVERY, "BLE probe connect refused; retrying discovery"); retry = get_time_us() + 1000000; }
|
||||
}
|
||||
}
|
||||
int main(int argc, char** argv) {
|
||||
dial = argc < 2 || !strcmp(argv[1], "connect");
|
||||
|
||||
Reference in new issue
Block a user