Merge branch 'v1.5_develop_416' into v1.5

v1.5
Michael Zillgith 1 year ago
commit 3c29e85b00

@ -17,6 +17,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <sys/select.h>
#include <poll.h>
#include "hal_serial.h"
#include "hal_time.h"
@ -29,11 +30,10 @@ struct sSerialPort {
char parity;
uint8_t stopBits;
uint64_t lastSentTime;
struct timeval timeout;
int timeout;
SerialPortError lastError;
};
SerialPort
SerialPort_create(const char* interfaceName, int baudRate, uint8_t dataBits, char parity, uint8_t stopBits)
{
@ -46,8 +46,7 @@ SerialPort_create(const char* interfaceName, int baudRate, uint8_t dataBits, cha
self->stopBits = stopBits;
self->parity = parity;
self->lastSentTime = 0;
self->timeout.tv_sec = 0;
self->timeout.tv_usec = 100000; /* 100 ms */
self->timeout = 100; /* 100 ms */
strncpy(self->interfaceName, interfaceName, 99);
self->lastError = SERIAL_PORT_ERROR_NONE;
}
@ -212,8 +211,7 @@ SerialPort_discardInBuffer(SerialPort self)
void
SerialPort_setTimeout(SerialPort self, int timeout)
{
self->timeout.tv_sec = timeout / 1000;
self->timeout.tv_usec = (timeout % 1000) * 1000;
self->timeout = timeout;
}
SerialPortError
@ -226,14 +224,14 @@ int
SerialPort_readByte(SerialPort self)
{
uint8_t buf[1];
fd_set set;
struct pollfd fds[1];
self->lastError = SERIAL_PORT_ERROR_NONE;
FD_ZERO(&set);
FD_SET(self->fd, &set);
fds[0].fd = self->fd;
fds[0].events = POLLIN;
int ret = select(self->fd + 1, &set, NULL, NULL, &(self->timeout));
int ret = poll(fds, 1, self->timeout);
if (ret == -1) {
self->lastError = SERIAL_PORT_ERROR_UNKNOWN;

@ -478,10 +478,6 @@ Socket_connectAsync(Socket self, const char* address, int port)
if (!prepareAddress(address, port, &serverAddress))
return false;
fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(self->fd, &fdSet);
activateTcpNoDelay(self);
fcntl(self->fd, F_SETFL, O_NONBLOCK);
@ -505,17 +501,14 @@ Socket_connectAsync(Socket self, const char* address, int port)
SocketState
Socket_checkAsyncConnectState(Socket self)
{
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
struct pollfd fds[1];
fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(self->fd, &fdSet);
fds[0].fd = self->fd;
fds[0].events = POLLOUT;
int selectVal = select(self->fd + 1, NULL, &fdSet , NULL, &timeout);
int result = poll(fds, 1, 0);
if (selectVal == 1) {
if (result == 1) {
/* Check if connection is established */
@ -530,7 +523,7 @@ Socket_checkAsyncConnectState(Socket self)
return SOCKET_STATE_FAILED;
}
else if (selectVal == 0) {
else if (result == 0) {
return SOCKET_STATE_CONNECTING;
}
else {
@ -544,15 +537,14 @@ Socket_connect(Socket self, const char* address, int port)
if (Socket_connectAsync(self, address, port) == false)
return false;
struct timeval timeout;
timeout.tv_sec = self->connectTimeout / 1000;
timeout.tv_usec = (self->connectTimeout % 1000) * 1000;
struct pollfd fds[1];
fds[0].fd = self->fd;
fds[0].events = POLLOUT;
fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(self->fd, &fdSet);
int result = poll(fds, 1, self->connectTimeout);
if (select(self->fd + 1, NULL, &fdSet , NULL, &timeout) == 1) {
if (result == 1) {
/* Check if connection is established */

Loading…
Cancel
Save