From b9ae38f88808b26be0e68ffa2475e9629d8e0e1b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 20 Oct 2023 00:33:58 +0200 Subject: [PATCH] Add timing to hw ping, reduce sleep to 1ms in WaitForResponse, no impact on CPU --- client/src/cmdhw.c | 11 +++++++++-- client/src/comms.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 7cef9fa81..7b2693781 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -35,6 +35,7 @@ #include "pmflash.h" // rdv40validation_t #include "cmdflashmem.h" // get_signature.. #include "uart/uart.h" // configure timeout +#include "util_posix.h" static int CmdHelp(const char *Cmd); @@ -979,6 +980,7 @@ static int CmdPing(const char *Cmd) { arg_u64_0("l", "len", "", "length of payload to send"), arg_param_end }; + CLIExecWithReturn(ctx, Cmd, argtable, true); uint32_t len = arg_get_u32_def(ctx, 1, 32); CLIParserFree(ctx); @@ -1000,13 +1002,18 @@ static int CmdPing(const char *Cmd) { data[i] = i & 0xFF; } + uint64_t tms = msclock(); SendCommandNG(CMD_PING, data, len); if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) { + tms = msclock() - tms; if (len) { bool error = (memcmp(data, resp.data.asBytes, len) != 0); - PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") " and content ( %s )", error ? _RED_("fail") : _GREEN_("ok")); + PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") + " in " _YELLOW_("%" PRIu64) " ms and content ( %s )", + tms, error ? _RED_("fail") : _GREEN_("ok")); } else { - PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received")); + PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received") + " in " _YELLOW_("%" PRIu64) " ms", tms); } } else PrintAndLogEx(WARNING, "Ping response " _RED_("timeout")); diff --git a/client/src/comms.c b/client/src/comms.c index 4d65fd5f9..269e75a1d 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -802,7 +802,7 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms show_warning = false; } // just to avoid CPU busy loop: - msleep(10); + msleep(1); } return false; }