// Code for communicating with the proxmark3 hardware.
//-----------------------------------------------------------------------------
+#define _POSIX_C_SOURCE 199309L // need clock_gettime()
+
#include "comms.h"
#include <stdio.h>
#include <pthread.h>
#include <inttypes.h>
#include <time.h>
+#include <sys/time.h>
#include "uart.h"
#include "ui.h"
// 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);
#endif
uint64_t start_time = msclock();
- uint64_t end_time = start_time + ms_timeout;
if (response == NULL) {
response = &resp;
// Wait until the command is received
while (true) {
- int32_t remaining_time = end_time - msclock();
- if (remaining_time <= 0) {
+ if (ms_timeout != -1 && msclock() > start_time + ms_timeout) {
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;
}