From c5165a7e51ed12bfe4d12e7a111d45aa70fd00f7 Mon Sep 17 00:00:00 2001 From: Rodrigo Alfonso Date: Fri, 17 Nov 2023 21:11:30 -0300 Subject: [PATCH] Always syncing before measuring --- examples/LinkCable_stress/src/main.cpp | 38 ++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/examples/LinkCable_stress/src/main.cpp b/examples/LinkCable_stress/src/main.cpp index a3ae5d4..56990ef 100644 --- a/examples/LinkCable_stress/src/main.cpp +++ b/examples/LinkCable_stress/src/main.cpp @@ -23,6 +23,7 @@ void test(bool withSync); void measureLatency(bool withPong); +void forceSync(); void log(std::string text); void waitFor(u16 key); void wait(u32 verticalLines); @@ -224,7 +225,7 @@ void test(bool withSync) { void measureLatency(bool withPong) { log("Waiting for data..."); - bool didFinishInitialSync = false; + bool didInitialize = false; u32 counter = 0; u32 samples = 0; u32 totalMs = 0; @@ -240,22 +241,13 @@ void measureLatency(bool withPong) { auto currentPlayerId = link->currentPlayerId(); auto remotePlayerId = !currentPlayerId; - if (!didFinishInitialSync) { + if (!didInitialize) { counter = 11 + link->currentPlayerId() * 10; - if (currentPlayerId == 0) - if (!link->waitFor(remotePlayerId, needsReset)) { - log("Sync failed! Press DOWN"); - waitFor(KEY_DOWN); - return; - } - - link->send(10); - link->waitFor(remotePlayerId); - while (link->peek(remotePlayerId) == 10) - link->read(remotePlayerId); - didFinishInitialSync = true; + didInitialize = true; } + forceSync(); + u32 sentPacket = ++counter; profileStart(); @@ -304,6 +296,24 @@ void measureLatency(bool withPong) { } } +void forceSync() { + auto currentPlayerId = link->currentPlayerId(); + auto remotePlayerId = !link->currentPlayerId(); + + if (currentPlayerId == 0) + if (!link->waitFor(remotePlayerId, needsReset)) { + log("Sync failed! Press DOWN"); + waitFor(KEY_DOWN); + return; + } + + link->send(10); + while (link->isConnected() && !needsReset() && + link->peek(remotePlayerId) != 10) + link->waitFor(remotePlayerId); + link->read(remotePlayerId); +} + void log(std::string text) { tte_erase_screen(); tte_write("#{P:0,0}");