// Used by UsbReceiveCommand as a ring buffer for messages that are yet to be
// processed by a command handler (WaitForResponse{,Timeout})
#define CMD_BUFFER_SIZE 50
+#define CMD_BUFFER_CHECK_TIME 10 // maximum time (in ms) to wait in getCommand()
+
static UsbCommand rxBuffer[CMD_BUFFER_SIZE];
// Points to the next empty position to write to
bool GetFromBigBuf(uint8_t *dest, int bytes, int start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
uint64_t start_time = msclock();
- uint32_t poll_time = 100; // loop every 100ms
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
SendCommand(&c);
PrintAndLog("You can cancel this operation by pressing the pm3 button");
show_warning = false;
}
- if (getCommand(response, poll_time)) {
+ if (getCommand(response, CMD_BUFFER_CHECK_TIME)) {
if (response->cmd == CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
int copy_bytes = MIN(bytes - bytes_completed, response->arg[1]);
memcpy(dest + response->arg[0], response->d.asBytes, copy_bytes);
bool GetFromFpgaRAM(uint8_t *dest, int bytes) {
uint64_t start_time = msclock();
- uint32_t poll_time = 100; // loop every 100ms
UsbCommand c = {CMD_HF_PLOT, {0, 0, 0}};
SendCommand(&c);
PrintAndLog("You can cancel this operation by pressing the pm3 button");
show_warning = false;
}
- if (getCommand(&response, poll_time)) {
+ if (getCommand(&response, CMD_BUFFER_CHECK_TIME)) {
if (response.cmd == CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
int copy_bytes = MIN(bytes - bytes_completed, response.arg[1]);
memcpy(dest + response.arg[0], response.d.asBytes, copy_bytes);
// Wait until the command is received
while (true) {
- int32_t remaining_time = end_time - msclock();
- if (remaining_time <= 0) {
+ if (msclock() > end_time) {
break; // timeout
}
if (msclock() - start_time > 2000 && show_warning) {
PrintAndLog("You can cancel this operation by pressing the pm3 button");
show_warning = false;
}
- if (getCommand(response, remaining_time)) {
+ if (getCommand(response, CMD_BUFFER_CHECK_TIME)) {
if (cmd == CMD_UNKNOWN || response->cmd == cmd) {
return true;
}