Merge remote-tracking branch 'origin/master' into enhanced_device

# Conflicts:
#	src/lib/ebus/device.cpp
This commit is contained in:
john30
2020-01-25 15:27:11 +01:00
13 changed files with 103 additions and 35 deletions
+2 -2
View File
@@ -66,7 +66,7 @@ result_t TemParamDataType::readSymbols(size_t offset, size_t length, const Symbo
if (outputFormat & OF_JSON) {
*output << "null";
} else {
*output << nullptr_VALUE;
*output << NULL_VALUE;
}
return RESULT_OK;
}
@@ -94,7 +94,7 @@ result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length
unsigned int value;
unsigned int grp, num;
if (input->str() == nullptr_VALUE) {
if (input->str() == NULL_VALUE) {
value = m_replacement; // replacement value
} else {
string token;
+5 -4
View File
@@ -752,7 +752,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
if (outputFormat & OF_JSON) {
*output << "null";
} else if (value == m_dataType->getReplacement()) {
*output << nullptr_VALUE;
*output << NULL_VALUE;
}
} else if (outputFormat & OF_NUMERIC) {
*output << setw(0) << dec << value;
@@ -775,17 +775,18 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
result_t ValueListDataField::writeSymbols(size_t offset, istringstream* input,
SymbolString* output, size_t* usedLength) const {
const NumberDataType* numType = reinterpret_cast<const NumberDataType*>(m_dataType);
if (isIgnored() || input->str() == nullptr_VALUE) {
const string inputStr = input->str();
if (isIgnored() || inputStr == NULL_VALUE) {
// replacement value
return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength);
}
const char* str = input->str().c_str();
for (map<unsigned int, string>::const_iterator it = m_values.begin(); it != m_values.end(); ++it) {
if (it->second.compare(str) == 0) {
if (it->second == inputStr) {
return numType->writeRawValue(it->first, offset, m_length, output, usedLength);
}
}
const char* str = inputStr.c_str();
char* strEnd = nullptr; // fall back to raw value in input
unsigned int value;
value = (unsigned int)strtoul(str, &strEnd, 10);
+14 -13
View File
@@ -243,13 +243,13 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo
case 2: // date only
if (!hasFlag(REQ) && symbol == m_replacement) {
if (i + 1 != length) {
*output << nullptr_VALUE << ".";
*output << NULL_VALUE << ".";
break;
} else if (last == m_replacement) {
if (length == 2) { // number of days since 01.01.1900
*output << nullptr_VALUE << ".";
*output << NULL_VALUE << ".";
}
*output << nullptr_VALUE;
*output << NULL_VALUE;
break;
}
}
@@ -282,13 +282,13 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo
case 1: // time only
if (!hasFlag(REQ) && symbol == m_replacement) {
if (length == 1) { // truncated time
*output << nullptr_VALUE << ":" << nullptr_VALUE;
*output << NULL_VALUE << ":" << NULL_VALUE;
break;
}
if (i > 0) {
*output << ":";
}
*output << nullptr_VALUE;
*output << NULL_VALUE;
break;
}
if (hasFlag(SPE)) { // minutes since midnight
@@ -378,7 +378,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
if (input->eof() || !getline(*input, token, '.')) {
return RESULT_ERR_EOF; // incomplete
}
if (!hasFlag(REQ) && token == nullptr_VALUE) {
if (!hasFlag(REQ) && token == NULL_VALUE) {
value = m_replacement;
break;
}
@@ -431,7 +431,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
if (input->eof() || !getline(*input, token, LENGTH_SEPARATOR)) {
return RESULT_ERR_EOF; // incomplete
}
if (!hasFlag(REQ) && token == nullptr_VALUE) {
if (!hasFlag(REQ) && token == NULL_VALUE) {
value = m_replacement;
if (length == 1) { // truncated time
if (i == 0) {
@@ -654,7 +654,7 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS
if (outputFormat & OF_JSON) {
*output << "null";
} else {
*output << nullptr_VALUE;
*output << NULL_VALUE;
}
return RESULT_OK;
}
@@ -700,7 +700,7 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS
if (outputFormat & OF_JSON) {
*output << "null";
} else {
*output << nullptr_VALUE;
*output << NULL_VALUE;
}
return RESULT_OK;
}
@@ -805,12 +805,13 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
SymbolString* output, size_t* usedLength) const {
unsigned int value;
if (!hasFlag(REQ) && (isIgnored() || input->str() == nullptr_VALUE)) {
const string inputStr = input->str();
if (!hasFlag(REQ) && (isIgnored() || inputStr == NULL_VALUE)) {
value = m_replacement; // replacement value
} else if (input->str().empty()) {
} else if (inputStr.empty()) {
return RESULT_ERR_EOF; // input too short
} else if (hasFlag(EXP)) { // IEEE 754 binary32
const char* str = input->str().c_str();
const char* str = inputStr.c_str();
char* strEnd = nullptr;
double dvalue = strtod(str, &strEnd);
if (strEnd == nullptr || strEnd == str || *strEnd != 0) {
@@ -849,7 +850,7 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
}
#endif
} else {
const char* str = input->str().c_str();
const char* str = inputStr.c_str();
char* strEnd = nullptr;
if (m_divisor == 1) {
if (hasFlag(SIG)) {
+2 -2
View File
@@ -58,7 +58,7 @@ using std::ostringstream;
#define LENGTH_SEPARATOR ':'
/** the replacement string for undefined values (in UI and CSV). */
#define nullptr_VALUE "-"
#define NULL_VALUE "-"
/** the separator character used between fields (in UI only). */
#define UI_FIELD_SEPARATOR ';'
@@ -134,7 +134,7 @@ enum PartType {
/** bit flag for @a DataType: fixed width formatting. */
#define FIX 0x20
/** bit flag for @a DataType: value may not be nullptr. */
/** bit flag for @a DataType: value may not be NULL. */
#define REQ 0x40
/** bit flag for @a DataType: binary representation is hex converted to decimal and interpreted as 2 digits
+30 -1
View File
@@ -515,6 +515,17 @@ void SerialDevice::checkDevice() {
}
}
#ifdef __CYGWIN__
#ifndef TCP_KEEPCNT
#define TCP_KEEPCNT 8
#endif
#ifndef TCP_KEEPINTVL
#define TCP_KEEPINTVL 150
#endif
#ifndef TCP_KEEPIDLE
#define TCP_KEEPIDLE 14400
#endif
#endif
result_t NetworkDevice::open() {
result_t result = Device::open();
@@ -535,6 +546,12 @@ result_t NetworkDevice::open() {
ret = setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<void*>(&value), sizeof(value));
value = 1;
setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<void*>(&value), sizeof(value));
value = 3; // send keepalive after 3 seconds of silence
setsockopt(m_fd, IPPROTO_TCP, TCP_KEEPIDLE, reinterpret_cast<void*>(&value), sizeof(value));
value = 2; // send keepalive in interval of 2 seconds
setsockopt(m_fd, IPPROTO_TCP, TCP_KEEPINTVL, reinterpret_cast<void*>(&value), sizeof(value));
value = 2; // drop connection after 2 failed keep alive sends
setsockopt(m_fd, IPPROTO_TCP, TCP_KEEPCNT, reinterpret_cast<void*>(&value), sizeof(value));
}
if (ret >= 0) {
ret = connect(m_fd, (struct sockaddr*)&m_address, sizeof(m_address));
@@ -548,13 +565,25 @@ result_t NetworkDevice::open() {
}
int cnt;
symbol_t buf[MTU];
while (ioctl(m_fd, FIONREAD, &cnt) >= 0 && cnt > 1) {
int ioerr;
while ((ioerr=ioctl(m_fd, FIONREAD, &cnt)) >= 0 && cnt > 1) {
// skip buffered input
ssize_t read = ::read(m_fd, &buf, MTU);
if (read <= 0) {
break;
}
}
if (ioerr < 0) {
close();
return RESULT_ERR_GENERIC_IO;
}
if (m_bufSize == 0) {
m_bufSize = MAX_LEN+1;
m_buffer = reinterpret_cast<symbol_t*>(malloc(m_bufSize));
if (!m_buffer) {
m_bufSize = 0;
}
}
m_bufLen = 0;
if (m_initialSend && !write(ESC)) {
return RESULT_ERR_SEND;
+1 -1
View File
@@ -82,7 +82,7 @@ void RotateFile::write(const unsigned char* value, const size_t size, const bool
fwrite(value, (streamsize)size, 1, m_stream);
m_fileSize += size;
m_flushSize += size;
if (m_flushSize > 16) {
if (m_flushSize >= m_flushBuffer) {
fflush(m_stream);
m_flushSize = 0;
}
+6 -2
View File
@@ -43,10 +43,11 @@ class RotateFile {
* @param fileName the name of the file write to.
* @param maxSize the maximum size of the file to write to.
* @param textMode whether to write each byte with prefixed timestamp and direction as text.
* @param flushBuffer the size of the flush buffer.
*/
RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false)
RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false, const unsigned int flushBuffer = 16)
: m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0),
m_flushSize(0) {}
m_flushSize(0), m_flushBuffer(flushBuffer) {}
/**
* Destructor.
@@ -98,6 +99,9 @@ class RotateFile {
/** the number of bytes written to @a m_file since the last flush. */
uint64_t m_flushSize;
/** the size of the flush buffer. */
const unsigned int m_flushBuffer;
};
} // namespace ebusd