Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 committed Oct 15, 2023
1 parent 5775b53 commit df01dca
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions client/src/uart/uart_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin

// Reset file descriptor
FD_ZERO(&rfds);
FD_SET(((serial_port_unix_t_t *)sp)->fd, &rfds);
FD_SET(spu->fd, &rfds);
tv = timeout;
res = select(((serial_port_unix_t_t *)sp)->fd + 1, &rfds, NULL, NULL, &tv);
res = select(spu->fd + 1, &rfds, NULL, NULL, &tv);

// Read error
if (res < 0) {
Expand All @@ -491,7 +491,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}

// Retrieve the count of the incoming bytes
res = ioctl(((serial_port_unix_t_t *)sp)->fd, FIONREAD, &byteCount);
res = ioctl((spu->fd, FIONREAD, &byteCount);
// PrintAndLogEx(ERR, "UART:: RX ioctl res %d byteCount %u", res, byteCount);
if (res < 0) return PM3_ENOTTY;

Expand All @@ -510,7 +510,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}

// There is something available, read the data
res = read(((serial_port_unix_t_t *)sp)->fd, pbtRx + (*pszRxLen), byteCount);
res = read(spu->fd, pbtRx + (*pszRxLen), byteCount);

// Stop if the OS has some troubles reading the data
if (res <= 0) {
Expand All @@ -532,13 +532,14 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
uint32_t pos = 0;
fd_set rfds;
struct timeval tv;
const serial_port_unix_t_t *spu = (serial_port_unix_t_t *)sp;

while (pos < len) {
// Reset file descriptor
FD_ZERO(&rfds);
FD_SET(((serial_port_unix_t_t *)sp)->fd, &rfds);
FD_SET(spu->fd, &rfds);
tv = timeout;
int res = select(((serial_port_unix_t_t *)sp)->fd + 1, NULL, &rfds, NULL, &tv);
int res = select(spu->fd + 1, NULL, &rfds, NULL, &tv);

// Write error
if (res < 0) {
Expand All @@ -553,7 +554,7 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
}

// Send away the bytes
res = write(((serial_port_unix_t_t *)sp)->fd, pbtTx + pos, len - pos);
res = write(spu->fd, pbtTx + pos, len - pos);

// Stop if the OS has some troubles sending the data
if (res <= 0)
Expand Down

0 comments on commit df01dca

Please sign in to comment.