This commit is contained in:
iceman1001 2019-02-17 16:06:27 +01:00
commit fdabfc09d2

View file

@ -68,12 +68,13 @@ typedef struct {
} serial_port_unix; } serial_port_unix;
// Set time-out on 30 miliseconds // Set time-out on 30 miliseconds
const struct timeval timeout = { struct timeval timeout = {
.tv_sec = 0, // 0 second .tv_sec = 0, // 0 second
.tv_usec = 30000 // 30000 micro seconds .tv_usec = 30000 // 30000 micro seconds
}; };
serial_port uart_open(const char* pcPortName) { serial_port uart_open(const char* pcPortName)
{
serial_port_unix* sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t)); serial_port_unix* sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t));
if (sp == 0) return INVALID_SERIAL_PORT; if (sp == 0) return INVALID_SERIAL_PORT;
@ -86,10 +87,12 @@ serial_port uart_open(const char* pcPortName) {
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
timeout.tv_usec = 300000 // 300 000 micro seconds
char *colon = strrchr(addrstr, ':'); char *colon = strrchr(addrstr, ':');
char *portstr; char *portstr;
// Set time-out to 300 miliseconds only for TCP port
timeout.tv_usec = 300000;
if (colon) { if (colon) {
portstr = colon + 1; portstr = colon + 1;
*colon = '\0'; *colon = '\0';
@ -366,10 +369,7 @@ uint32_t uart_get_speed(const serial_port sp) {
struct termios ti; struct termios ti;
uint32_t uiPortSpeed; uint32_t uiPortSpeed;
const serial_port_unix* spu = (serial_port_unix*)sp; const serial_port_unix* spu = (serial_port_unix*)sp;
if (tcgetattr(spu->fd, &ti) == -1) return 0;
if (tcgetattr(spu->fd, &ti) == -1)
return 0;
// Set port speed (Input) // Set port speed (Input)
speed_t stPortSpeed = cfgetispeed(&ti); speed_t stPortSpeed = cfgetispeed(&ti);
switch (stPortSpeed) { switch (stPortSpeed) {
@ -407,4 +407,5 @@ uint32_t uart_get_speed(const serial_port sp) {
}; };
return uiPortSpeed; return uiPortSpeed;
} }
#endif #endif