Merge branch 'master' of github.com:john30/ebusd
This commit is contained in:
@@ -64,6 +64,7 @@ check_include_file(sys/time.h HAVE_SYS_TIME_H)
|
|||||||
check_include_file(syslog.h HAVE_SYSLOG_H)
|
check_include_file(syslog.h HAVE_SYSLOG_H)
|
||||||
check_include_file(time.h HAVE_TIME_H)
|
check_include_file(time.h HAVE_TIME_H)
|
||||||
check_include_file(termios.h HAVE_TERMIOS_H)
|
check_include_file(termios.h HAVE_TERMIOS_H)
|
||||||
|
check_function_exists(cfsetspeed HAVE_CFSETSPEED)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES pthread rt)
|
set(CMAKE_REQUIRED_LIBRARIES pthread rt)
|
||||||
check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
|
check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ AC_CHECK_HEADERS([arpa/inet.h \
|
|||||||
time.h \
|
time.h \
|
||||||
termios.h])
|
termios.h])
|
||||||
|
|
||||||
|
AC_CHECK_FUNC([cfsetspeed], [AC_DEFINE(HAVE_CFSETSPEED, [1], [Defined if cfsetspeed() is available.])])
|
||||||
|
|
||||||
AC_CHECK_LIB([pthread], [pthread_setname_np],
|
AC_CHECK_LIB([pthread], [pthread_setname_np],
|
||||||
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], [Defined if pthread_setname_np is available.]),
|
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], [Defined if pthread_setname_np is available.]),
|
||||||
AC_MSG_RESULT([Could not find pthread_setname_np in pthread.]))
|
AC_MSG_RESULT([Could not find pthread_setname_np in pthread.]))
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ ebusd_SOURCES = \
|
|||||||
datahandler.h datahandler.cpp \
|
datahandler.h datahandler.cpp \
|
||||||
network.h network.cpp \
|
network.h network.cpp \
|
||||||
mainloop.h mainloop.cpp \
|
mainloop.h mainloop.cpp \
|
||||||
|
scan.h scan.cpp \
|
||||||
main.h main.cpp
|
main.h main.cpp
|
||||||
|
|
||||||
if MQTT
|
if MQTT
|
||||||
|
|||||||
@@ -886,7 +886,12 @@ result_t SerialDevice::open() {
|
|||||||
// create new settings
|
// create new settings
|
||||||
memset(&newSettings, 0, sizeof(newSettings));
|
memset(&newSettings, 0, sizeof(newSettings));
|
||||||
|
|
||||||
|
#ifdef HAVE_CFSETSPEED
|
||||||
cfsetspeed(&newSettings, m_enhancedProto ? (m_enhancedHighSpeed ? B115200 : B9600) : B2400);
|
cfsetspeed(&newSettings, m_enhancedProto ? (m_enhancedHighSpeed ? B115200 : B9600) : B2400);
|
||||||
|
#else
|
||||||
|
cfsetispeed(&newSettings, m_enhancedProto ? (m_enhancedHighSpeed ? B115200 : B9600) : B2400);
|
||||||
|
cfsetospeed(&newSettings, m_enhancedProto ? (m_enhancedHighSpeed ? B115200 : B9600) : B2400);
|
||||||
|
#endif
|
||||||
newSettings.c_cflag |= (CS8 | CLOCAL | CREAD);
|
newSettings.c_cflag |= (CS8 | CLOCAL | CREAD);
|
||||||
newSettings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // non-canonical mode
|
newSettings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // non-canonical mode
|
||||||
newSettings.c_iflag |= IGNPAR; // ignore parity errors
|
newSettings.c_iflag |= IGNPAR; // ignore parity errors
|
||||||
@@ -924,8 +929,8 @@ void SerialDevice::close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SerialDevice::checkDevice() {
|
void SerialDevice::checkDevice() {
|
||||||
int port;
|
int cnt;
|
||||||
if (ioctl(m_fd, TIOCMGET, &port) == -1) {
|
if (ioctl(m_fd, FIONREAD, &cnt) == -1) {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -446,6 +446,7 @@ bool HttpClient::request(const string& method, const string& uri, const string&
|
|||||||
string headers = result.substr(0, pos+2); // including final \r\n
|
string headers = result.substr(0, pos+2); // including final \r\n
|
||||||
const char* hdrs = headers.c_str();
|
const char* hdrs = headers.c_str();
|
||||||
*response = result.substr(pos+4);
|
*response = result.substr(pos+4);
|
||||||
|
#ifdef HAVE_TIME_H
|
||||||
if (time) {
|
if (time) {
|
||||||
pos = headers.find("\r\nLast-Modified: ");
|
pos = headers.find("\r\nLast-Modified: ");
|
||||||
if (pos != string::npos && headers.substr(pos+42, 4) == " GMT") {
|
if (pos != string::npos && headers.substr(pos+42, 4) == " GMT") {
|
||||||
@@ -485,6 +486,7 @@ bool HttpClient::request(const string& method, const string& uri, const string&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
pos = headers.find("\r\nContent-Length: ");
|
pos = headers.find("\r\nContent-Length: ");
|
||||||
if (pos == string::npos) {
|
if (pos == string::npos) {
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|||||||
@@ -124,11 +124,6 @@ int tcpKeepAliveInterval) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifndef HAVE_PPOLL
|
|
||||||
#ifndef HAVE_PSELECT
|
|
||||||
timeout = 0;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
if (tcpConnectTimeout > 0 && fcntl(sfd, F_SETFL, O_NONBLOCK) < 0) { // set non-blocking
|
if (tcpConnectTimeout > 0 && fcntl(sfd, F_SETFL, O_NONBLOCK) < 0) { // set non-blocking
|
||||||
close(sfd);
|
close(sfd);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -140,9 +135,15 @@ int tcpKeepAliveInterval) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (tcpConnectTimeout > 0) {
|
if (tcpConnectTimeout > 0) {
|
||||||
|
#if defined(HAVE_PPOLL) || defined(HAVE_PSELECT)
|
||||||
struct timespec tdiff;
|
struct timespec tdiff;
|
||||||
tdiff.tv_sec = tcpConnectTimeout;
|
tdiff.tv_sec = tcpConnectTimeout;
|
||||||
tdiff.tv_nsec = 0;
|
tdiff.tv_nsec = 0;
|
||||||
|
#else
|
||||||
|
struct timeval tdiff;
|
||||||
|
tdiff.tv_sec = tcpConnectTimeout;
|
||||||
|
tdiff.tv_usec = 0;
|
||||||
|
#endif
|
||||||
#ifdef HAVE_PPOLL
|
#ifdef HAVE_PPOLL
|
||||||
nfds_t nfds = 1;
|
nfds_t nfds = 1;
|
||||||
struct pollfd fds[nfds];
|
struct pollfd fds[nfds];
|
||||||
@@ -159,7 +160,11 @@ int tcpKeepAliveInterval) {
|
|||||||
FD_ZERO(&writefds);
|
FD_ZERO(&writefds);
|
||||||
FD_ZERO(&exceptfds);
|
FD_ZERO(&exceptfds);
|
||||||
FD_SET(sfd, &readfds);
|
FD_SET(sfd, &readfds);
|
||||||
|
#ifdef HAVE_PSELECT
|
||||||
ret = pselect(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff, nullptr);
|
ret = pselect(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff, nullptr);
|
||||||
|
#else
|
||||||
|
ret = select(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff);
|
||||||
|
#endif
|
||||||
if (ret >= 1 && FD_ISSET(sfd, &exceptfds)) {
|
if (ret >= 1 && FD_ISSET(sfd, &exceptfds)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user