diff --git a/client/cmdhw.c b/client/cmdhw.c index 99b8ea49b..6b4ec04bd 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -419,8 +419,7 @@ static int CmdStatus(const char *Cmd) { (void)Cmd; // Cmd is not used so far clearCommandBuffer(); PacketResponseNG resp; - PacketCommandOLD c = {CMD_STATUS, {0, 0, 0}, {{0}}}; - SendCommand(&c); + SendCommandOLD(CMD_STATUS, 0, 0, 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1900)) PrintAndLogEx(NORMAL, "Status command failed. USB Speed Test timed out"); return 0; @@ -430,12 +429,11 @@ static int CmdPing(const char *Cmd) { (void)Cmd; // Cmd is not used so far clearCommandBuffer(); PacketResponseNG resp; - PacketCommandOLD c = {CMD_PING, {0, 0, 0}, {{0}}}; - SendCommand(&c); + SendCommandOLD(CMD_PING, 0, 0, 0, NULL, 0); if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) - PrintAndLogEx(NORMAL, "Ping successful"); + PrintAndLogEx(NORMAL, "Ping " _GREEN_("successful")); else - PrintAndLogEx(NORMAL, "Ping failed"); + PrintAndLogEx(NORMAL, "Ping " _RED_("failed")); return 0; } @@ -447,10 +445,9 @@ static int CmdPingNG(const char *Cmd) { clearCommandBuffer(); PacketResponseNG resp; uint8_t data[USB_CMD_DATA_SIZE] = {0}; - uint16_t cmd = CMD_PING; for (uint16_t i = 0; i < len; i++) data[i] = i & 0xFF; - SendCommandNG(cmd, data, len); + SendCommandNG(CMD_PING, data, len); if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) { bool error = false; if (len) diff --git a/client/comms.c b/client/comms.c index 7244eae60..ccec1832b 100644 --- a/client/comms.c +++ b/client/comms.c @@ -94,6 +94,18 @@ void SendCommand(PacketCommandOLD *c) { //__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST); } +// Let's move slowly to an API closer to SendCommandNG +void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { + PacketCommandOLD c = {CMD_UNKNOWN, {0, 0, 0}, {{0}}}; + c.cmd = cmd; + c.arg[0] = arg0; + c.arg[1] = arg1; + c.arg[2] = arg2; + if (len && data) + memcpy(&c.d, data, len); + SendCommand(&c); +} + void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) { #ifdef COMMS_DEBUG diff --git a/client/comms.h b/client/comms.h index 32885994d..6034a5741 100644 --- a/client/comms.h +++ b/client/comms.h @@ -55,6 +55,7 @@ bool IsOffline(void); void *uart_receiver(void *targ); void SendCommand(PacketCommandOLD *c); +void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len); void clearCommandBuffer(void);