USB comms refactoring

* make storeCommand() and getCommand() static in comms.c
* don't assume a port to be defined by a name. Change parameter in OpenProxmark() to void*
This commit is contained in:
pwpiwi 2018-05-22 07:58:19 +02:00
commit 823eadfa5b
2 changed files with 6 additions and 5 deletions

View file

@ -115,7 +115,7 @@ void clearCommandBuffer()
* @brief storeCommand stores a USB command in a circular buffer * @brief storeCommand stores a USB command in a circular buffer
* @param UC * @param UC
*/ */
void storeCommand(UsbCommand *command) static void storeCommand(UsbCommand *command)
{ {
pthread_mutex_lock(&rxBufferMutex); pthread_mutex_lock(&rxBufferMutex);
if( (cmd_head+1) % CMD_BUFFER_SIZE == cmd_tail) if( (cmd_head+1) % CMD_BUFFER_SIZE == cmd_tail)
@ -139,7 +139,7 @@ void storeCommand(UsbCommand *command)
* @param response location to write command * @param response location to write command
* @return 1 if response was returned, 0 if nothing has been received * @return 1 if response was returned, 0 if nothing has been received
*/ */
int getCommand(UsbCommand* response) static int getCommand(UsbCommand* response)
{ {
pthread_mutex_lock(&rxBufferMutex); pthread_mutex_lock(&rxBufferMutex);
//If head == tail, there's nothing to read, or if we just got initialized //If head == tail, there's nothing to read, or if we just got initialized
@ -295,8 +295,9 @@ bool GetFromBigBuf(uint8_t *dest, int bytes, int start_index, UsbCommand *respon
} }
bool OpenProxmark(char *portname, bool waitCOMPort, int timeout, bool flash_mode) { bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode) {
if (!waitCOMPort) { char *portname = (char *)port;
if (!wait_for_port) {
sp = uart_open(portname); sp = uart_open(portname);
} else { } else {
printf("Waiting for Proxmark to appear on %s ", portname); printf("Waiting for Proxmark to appear on %s ", portname);

View file

@ -25,7 +25,7 @@
void SetOffline(bool new_offline); void SetOffline(bool new_offline);
bool IsOffline(); bool IsOffline();
bool OpenProxmark(char *portname, bool waitCOMPort, int timeout, bool flash_mode); bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode);
void CloseProxmark(void); void CloseProxmark(void);
void SendCommand(UsbCommand *c); void SendCommand(UsbCommand *c);