diff --git a/client/comms.c b/client/comms.c index 8e9eb0a64..038e90fea 100644 --- a/client/comms.c +++ b/client/comms.c @@ -319,7 +319,7 @@ __attribute__((force_align_arg_pointer)) #endif *uart_communication(void *targ) { communication_arg_t *connection = (communication_arg_t *)targ; - size_t rxlen; + uint32_t rxlen; PacketResponseNG rx; PacketResponseNGRaw rx_raw; diff --git a/uart/uart.h b/uart/uart.h index 49900be39..4cbea26c8 100644 --- a/uart/uart.h +++ b/uart/uart.h @@ -88,13 +88,13 @@ void uart_close(const serial_port sp); * partial read may have completed into the buffer by the corresponding * implementation, so pszRxLen should be checked to see if any data was written. */ -bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size_t *pszRxLen); +bool uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen); /* Sends a buffer to a given serial port. * pbtTx: A pointer to a buffer containing the data to send. * len: The amount of data to be sent. */ -bool uart_send(const serial_port sp, const uint8_t *pbtTx, const size_t len); +bool uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len); /* Sets the current speed of the serial port, in baud. */ diff --git a/uart/uart_posix.c b/uart/uart_posix.c index e3b7c56b8..177088d05 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -234,8 +234,8 @@ void uart_close(const serial_port sp) { free(sp); } -bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size_t *pszRxLen) { - size_t byteCount; +bool uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) { + uint32_t byteCount; // FIONREAD returns size on 32b fd_set rfds; struct timeval tv; @@ -267,10 +267,12 @@ bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size // Retrieve the count of the incoming bytes res = ioctl(((serial_port_unix *)sp)->fd, FIONREAD, &byteCount); + printf("UART:: RX ioctl res %d byteCount %u\n", res, byteCount); if (res < 0) return false; // Cap the number of bytes, so we don't overrun the buffer if (pszMaxRxLen - (*pszRxLen) < byteCount) { + printf("UART:: RX buffer overrun (have %u, need %u)\n", pszMaxRxLen - (*pszRxLen), byteCount); byteCount = pszMaxRxLen - (*pszRxLen); } @@ -292,8 +294,8 @@ bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size return true; } -bool uart_send(const serial_port sp, const uint8_t *pbtTx, const size_t len) { - size_t pos = 0; +bool uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) { + uint32_t pos = 0; fd_set rfds; struct timeval tv; diff --git a/uart/uart_win32.c b/uart/uart_win32.c index c6e3142cf..36a10731a 100644 --- a/uart/uart_win32.c +++ b/uart/uart_win32.c @@ -169,11 +169,11 @@ uint32_t uart_get_speed(const serial_port sp) { return 0; } -bool uart_receive(const serial_port sp, uint8_t *p_rx, size_t pszMaxRxLen, size_t *len) { - return ReadFile(((serial_port_windows *)sp)->hPort, p_rx, pszMaxRxLen, (LPDWORD)len, NULL); +bool uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) { + return ReadFile(((serial_port_windows *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL); } -bool uart_send(const serial_port sp, const uint8_t *p_tx, const size_t len) { +bool uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) { DWORD txlen = 0; return WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL); }