fix uart_posix: bytecound must be 32b

This commit is contained in:
Philippe Teuwen 2019-04-21 01:05:02 +02:00
parent 6e744043f5
commit 4aa1b49493
4 changed files with 12 additions and 10 deletions

View file

@ -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;

View file

@ -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.
*/

View file

@ -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;

View file

@ -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);
}