fix stupid merge

This commit is contained in:
John
2021-01-10 14:13:07 +01:00
parent 248e8d65a7
commit cff4e4a8cb
18 changed files with 100 additions and 78 deletions
-1
View File
@@ -30,7 +30,6 @@ app.info
/src/lib/utils/libutils.a
/src/lib/ebus/libebus.a
/src/lib/ebus/contrib/test/test_tem
/src/lib/ebus/test/test_device
/src/lib/ebus/test/test_symbol
/src/lib/ebus/test/test_data
/src/lib/ebus/test/test_message
+3
View File
@@ -59,6 +59,9 @@
* added support for single quotes to all commands
* added "--mqttlog" and "--mqttversion" options
## Breaking Changes
* added support for enhanced network protocol mode for recent [ebusd-esp firmware](https://github.com/john30/ebusd-esp/) that allows the arbitration to be done directly by the Wemos
# 3.2 (2018-05-10)
+1 -1
View File
@@ -14,7 +14,7 @@ Features
The main features of the daemon are:
* use USB serial, TCP connected, or UDP device
* use USB serial, TCP connected or UDP device, or enhanced ebusd protocol for recent [ebus adapter 3](https://adapter.ebusd.eu/) or [ebusd-esp firmware](https://github.com/john30/ebusd-esp/) (allows arbitration to be done directly by the hardware)
* actively send messages to and receive answers from the eBUS
* passively listen to messages sent on the eBUS
* regularly poll for messages
+1 -1
View File
@@ -41,7 +41,7 @@ Using a network device
----------------------
When using a network device, the "--device" argument to docker can be omitted, but the device information has to be passed on to ebusd:
> docker run --rm -it -p 8888 john30/ebusd -f --scanconfig -d udp:192.168.178.123:10000 --latency=80000
> docker run --rm -it -p 8888 john30/ebusd -f --scanconfig -d udp:192.168.178.123:10000 --latency=80
Note: the "-f" and "--scanconfig" arguments are only passed to ebusd if it is called without any additional arguments. So when passing further arguments, these two usually need to be added as well.
-6
View File
@@ -478,12 +478,6 @@ result_t BusHandler::handleSymbol() {
}
break;
case bs_ready:
if (m_currentRequest != nullptr) {
setState(bs_ready, RESULT_ERR_TIMEOUT); // just to be sure an old BusRequest is cleaned up
}
break;
case bs_recvCmd:
case bs_recvCmdCrc:
timeout = m_slaveRecvTimeout;
+19 -20
View File
@@ -45,20 +45,23 @@ namespace ebusd {
using std::string;
/** the default time [us] for retrieving a symbol from an addressed slave. */
#define SLAVE_RECV_TIMEOUT 15000
/** the default time [ms] for retrieving a symbol from an addressed slave. */
#define SLAVE_RECV_TIMEOUT 15
/** the maximum allowed time [us] for retrieving the AUTO-SYN symbol (45ms + 2*1,2% + 1 Symbol). */
#define SYN_TIMEOUT 50800
/** the maximum allowed time [ms] for retrieving the AUTO-SYN symbol (45ms + 2*1,2% + 1 Symbol). */
#define SYN_TIMEOUT 51
/** the time [us] for determining bus signal availability (AUTO-SYN timeout * 5). */
#define SIGNAL_TIMEOUT 250000
/** the time [ms] for determining bus signal availability (AUTO-SYN timeout * 5). */
#define SIGNAL_TIMEOUT 250
/** the maximum duration [us] of a single symbol (Start+8Bit+Stop+Extra @ 2400Bd-2*1,2%). */
#define SYMBOL_DURATION 4700
#define SYMBOL_DURATION_MICROS 4700
/** the maximum allowed time [us] for retrieving back a sent symbol (2x symbol duration). */
#define SEND_TIMEOUT (2*SYMBOL_DURATION)
/** the maximum duration [ms] of a single symbol (Start+8Bit+Stop+Extra @ 2400Bd-2*1,2%). */
#define SYMBOL_DURATION 5
/** the maximum allowed time [ms] for retrieving back a sent symbol (2x symbol duration). */
#define SEND_TIMEOUT ((int)((2*SYMBOL_DURATION_MICROS+999)/1000))
/** the possible bus states. */
enum BusState {
@@ -368,9 +371,8 @@ class BusHandler : public WaitThread {
* @param answer whether to answer queries for the own master/slave address.
* @param busLostRetries the number of times a send is repeated due to lost arbitration.
* @param failedSendRetries the number of times a failed send is repeated (other than lost arbitration).
* @param transferLatency the bus transfer latency in microseconds.
* @param busAcquireTimeout the maximum time in microseconds for bus acquisition.
* @param slaveRecvTimeout the maximum time in microseconds an addressed slave is expected to acknowledge.
* @param busAcquireTimeout the maximum time in milliseconds for bus acquisition.
* @param slaveRecvTimeout the maximum time in milliseconds an addressed slave is expected to acknowledge.
* @param lockCount the number of AUTO-SYN symbols before sending is allowed after lost arbitration, or 0 for auto detection.
* @param generateSyn whether to enable AUTO-SYN symbol generation.
* @param pollInterval the interval in seconds in which poll messages are cycled, or 0 if disabled.
@@ -378,14 +380,14 @@ class BusHandler : public WaitThread {
BusHandler(Device* device, MessageMap* messages,
symbol_t ownAddress, bool answer,
unsigned int busLostRetries, unsigned int failedSendRetries,
unsigned int transferLatency, unsigned int busAcquireTimeout, unsigned int slaveRecvTimeout,
unsigned int busAcquireTimeout, unsigned int slaveRecvTimeout,
unsigned int lockCount, bool generateSyn,
unsigned int pollInterval)
: WaitThread(), m_device(device), m_reconnect(false), m_messages(messages),
m_ownMasterAddress(ownAddress), m_ownSlaveAddress(getSlaveAddress(ownAddress)),
m_answer(answer), m_addressConflict(false),
m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries),
m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout),
m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout),
m_masterCount(device->isReadOnly()?0:1), m_autoLockCount(lockCount == 0),
m_lockCount(lockCount <= 3 ? 3 : lockCount), m_remainLockCount(m_autoLockCount ? 1 : 0),
m_generateSynInterval(generateSyn ? SYN_TIMEOUT*getMasterNumber(ownAddress)+SYMBOL_DURATION : 0),
@@ -686,13 +688,10 @@ class BusHandler : public WaitThread {
/** the number of times a failed send is repeated (other than lost arbitration). */
const unsigned int m_failedSendRetries;
/** the bus transfer latency in microseconds. */
const unsigned int m_transferLatency;
/** the maximum time in microseconds for bus acquisition. */
/** the maximum time in milliseconds for bus acquisition. */
const unsigned int m_busAcquireTimeout;
/** the maximum time in microseconds an addressed slave is expected to acknowledge. */
/** the maximum time in milliseconds an addressed slave is expected to acknowledge. */
const unsigned int m_slaveRecvTimeout;
/** the number of masters already seen. */
@@ -707,7 +706,7 @@ class BusHandler : public WaitThread {
/** the remaining number of AUTO-SYN symbols before sending is allowed again. */
unsigned int m_remainLockCount;
/** the interval in microseconds after which to generate an AUTO-SYN symbol, or 0 if disabled. */
/** the interval in milliseconds after which to generate an AUTO-SYN symbol, or 0 if disabled. */
unsigned int m_generateSynInterval;
/** the interval in seconds in which poll messages are cycled, or 0 if disabled. */
+19 -15
View File
@@ -79,7 +79,7 @@ static struct options opt = {
false, // noDeviceCheck
false, // readOnly
false, // initialSend
-1, // latency
0, // extraLatency
CONFIG_PATH, // configPath
false, // scanConfig
@@ -92,7 +92,7 @@ static struct options opt = {
0x31, // address
false, // answer
9400, // acquireTimeout
10, // acquireTimeout
3, // acquireRetries
2, // sendRetries
SLAVE_RECV_TIMEOUT*5/3, // receiveTimeout
@@ -184,7 +184,7 @@ static const struct argp_option argpoptions[] = {
{"nodevicecheck", 'n', nullptr, 0, "Skip serial eBUS device test", 0 },
{"readonly", 'r', nullptr, 0, "Only read from device, never write to it", 0 },
{"initsend", O_INISND, nullptr, 0, "Send an initial escape symbol after connecting device", 0 },
{"latency", O_DEVLAT, "USEC", 0, "Transfer latency in us [0 for USB, 10000 for IP]", 0 },
{"latency", O_DEVLAT, "MSEC", 0, "Extra transfer latency in ms [0]", 0 },
{nullptr, 0, nullptr, 0, "Message configuration options:", 2 },
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH
@@ -204,10 +204,10 @@ static const struct argp_option argpoptions[] = {
{nullptr, 0, nullptr, 0, "eBUS options:", 3 },
{"address", 'a', "ADDR", 0, "Use ADDR as own bus address [31]", 0 },
{"answer", O_ANSWER, nullptr, 0, "Actively answer to requests from other masters", 0 },
{"acquiretimeout", O_ACQTIM, "USEC", 0, "Stop bus acquisition after USEC us [9400]", 0 },
{"acquiretimeout", O_ACQTIM, "MSEC", 0, "Stop bus acquisition after MSEC ms [10]", 0 },
{"acquireretries", O_ACQRET, "COUNT", 0, "Retry bus acquisition COUNT times [3]", 0 },
{"sendretries", O_SNDRET, "COUNT", 0, "Repeat failed sends COUNT times [2]", 0 },
{"receivetimeout", O_RCVTIM, "USEC", 0, "Expect a slave to answer within USEC us [25000]", 0 },
{"receivetimeout", O_RCVTIM, "MSEC", 0, "Expect a slave to answer within MSEC us [25]", 0 },
{"numbermasters", O_MASCNT, "COUNT", 0, "Expect COUNT masters on the bus, 0 for auto detection [0]", 0 },
{"generatesyn", O_GENSYN, nullptr, 0, "Enable AUTO-SYN symbol generation", 0 },
@@ -267,6 +267,7 @@ static map<string, DataFieldTemplates*> s_templatesByPath;
error_t parse_opt(int key, char *arg, struct argp_state *state) {
struct options *opt = (struct options*)state->input;
result_t result = RESULT_OK;
unsigned int value;
switch (key) {
// Device options:
@@ -295,12 +296,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
}
opt->initialSend = true;
break;
case O_DEVLAT: // --latency=10000
opt->latency = parseInt(arg, 10, 0, 200000, &result);
if (result != RESULT_OK) {
case O_DEVLAT: // --latency=10
value = parseInt(arg, 10, 0, 200000, &result); // backwards compatible (micros)
if (result != RESULT_OK || (value<=1000 && value>200)) { // backwards compatible (micros)
argp_error(state, "invalid latency");
return EINVAL;
}
opt->extraLatency = value > 1000 ? value/1000 : value; // backwards compatible (micros)
break;
// Message configuration options:
@@ -376,12 +378,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
}
opt->answer = true;
break;
case O_ACQTIM: // --acquiretimeout=9400
opt->acquireTimeout = parseInt(arg, 10, 1000, 100000, &result);
if (result != RESULT_OK) {
case O_ACQTIM: // --acquiretimeout=10
value = parseInt(arg, 10, 1, 100000, &result); // backwards compatible (micros)
if (result != RESULT_OK || (value<=1000 && value>100)) { // backwards compatible (micros)
argp_error(state, "invalid acquiretimeout");
return EINVAL;
}
opt->acquireTimeout = value > 1000 ? value/1000 : value; // backwards compatible (micros)
break;
case O_ACQRET: // --acquireretries=3
opt->acquireRetries = parseInt(arg, 10, 0, 10, &result);
@@ -397,12 +400,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
return EINVAL;
}
break;
case O_RCVTIM: // --receivetimeout=25000
opt->receiveTimeout = parseInt(arg, 10, 1000, 100000, &result);
if (result != RESULT_OK) {
case O_RCVTIM: // --receivetimeout=25
value = parseInt(arg, 10, 1, 100000, &result); // backwards compatible (micros)
if (result != RESULT_OK || (value<=1000 && value>100)) { // backwards compatible (micros)
argp_error(state, "invalid receivetimeout");
return EINVAL;
}
opt->receiveTimeout = value > 1000 ? value/1000 : value; // backwards compatible (micros)
break;
case O_MASCNT: // --numbermasters=0
opt->masterCount = parseInt(arg, 10, 0, 25, &result);
@@ -1306,7 +1310,7 @@ int main(int argc, char* argv[]) {
}
// open the device
Device *device = Device::create(opt.device, !opt.noDeviceCheck, opt.readOnly, opt.initialSend);
Device *device = Device::create(opt.device, opt.extraLatency, !opt.noDeviceCheck, opt.readOnly, opt.initialSend);
if (device == nullptr) {
logError(lf_main, "unable to create device %s", opt.device);
return EINVAL;
+3 -3
View File
@@ -39,7 +39,7 @@ struct options {
bool noDeviceCheck; //!< skip serial eBUS device test
bool readOnly; //!< read-only access to the device
bool initialSend; //!< send an initial escape symbol after connecting device
int latency; //!< transfer latency in us [0 for USB, 10000 for IP]
unsigned int extraLatency; //!< extra transfer latency in ms [0 for USB, 10 for IP]
const char* configPath; //!< path to CSV configuration files [http://ebusd.eu/config/]
bool scanConfig; //!< pick configuration files matching initial scan
@@ -54,10 +54,10 @@ struct options {
symbol_t address; //!< own bus address [31]
bool answer; //!< answer to requests from other masters
unsigned int acquireTimeout; //!< bus acquisition timeout in us [9400]
unsigned int acquireTimeout; //!< bus acquisition timeout in ms [10]
unsigned int acquireRetries; //!< number of retries for bus acquisition [3]
unsigned int sendRetries; //!< number of retries for failed sends [2]
unsigned int receiveTimeout; //!< timeout for receiving answer from slave in us [25000]
unsigned int receiveTimeout; //!< timeout for receiving answer from slave in ms [25]
unsigned int masterCount; //!< expected number of masters for arbitration [0]
bool generateSyn; //!< enable AUTO-SYN symbol generation
+17 -9
View File
@@ -141,16 +141,10 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
}
}
// create BusHandler
unsigned int latency;
if (opt.latency < 0) {
latency = device->getLatency();
} else {
latency = (unsigned int)opt.latency;
}
m_busHandler = new BusHandler(m_device, m_messages,
m_address, opt.answer,
opt.acquireRetries, opt.sendRetries,
latency, opt.acquireTimeout, opt.receiveTimeout,
opt.acquireTimeout, opt.receiveTimeout,
opt.masterCount, opt.generateSyn,
opt.pollInterval);
m_busHandler->start("bushandler");
@@ -473,12 +467,18 @@ void MainLoop::notifyDeviceData(symbol_t symbol, bool received) {
}
if (m_logRawBuffer.tellp() == 0 || received != m_logRawLastReceived) {
m_logRawLastReceived = received;
if (m_logRawBuffer.tellp() == 0 && m_logRawLastSymbol != SYN) {
m_logRawBuffer << "...";
}
m_logRawBuffer << (received ? "<" : ">");
}
m_logRawBuffer << setw(2) << setfill('0') << hex << static_cast<unsigned>(symbol);
m_logRawLastSymbol = symbol;
}
if (symbol == SYN && m_logRawBuffer.tellp() > 0) { // flush
m_logRawLastSymbol = symbol;
if (m_logRawBuffer.tellp() > (symbol == SYN ? 0 : 64)) { // flush: direction+5 hdr+24 max data+crc+direction+ack+1
if (symbol != SYN) {
m_logRawBuffer << "...";
}
const string bufStr = m_logRawBuffer.str();
const char* str = bufStr.c_str();
if (m_logRawFile) {
@@ -490,6 +490,14 @@ void MainLoop::notifyDeviceData(symbol_t symbol, bool received) {
}
}
void MainLoop::notifyStatus(bool error, const char* message) {
if (error) {
logError(lf_bus, "device status: %s", message);
} else {
logNotice(lf_bus, "device status: %s", message);
}
}
result_t MainLoop::decodeMessage(const string &data, bool isHttp, bool* connected, ClientSettings* settings,
string* user, bool* reload, ostringstream* ostream) {
string token, previous;
+3
View File
@@ -132,6 +132,9 @@ class MainLoop : public Thread, DeviceListener {
// @copydoc
void notifyDeviceData(symbol_t symbol, bool received) override;
// @copydoc
void notifyStatus(bool error, const char* message) override;
protected:
// @copydoc
+1
View File
@@ -44,6 +44,7 @@ const char* getResultCode(result_t resultCode) {
case RESULT_ERR_DUPLICATE: return "ERR: duplicate entry";
case RESULT_ERR_DUPLICATE_NAME: return "ERR: duplicate name";
case RESULT_ERR_BUS_LOST: return "ERR: arbitration lost";
case RESULT_ERR_ARB_RUNNING: return "ERR: arbitration running";
case RESULT_ERR_CRC: return "ERR: CRC error";
case RESULT_ERR_ACK: return "ERR: ACK error";
case RESULT_ERR_NAK: return "ERR: NAK received";
+8 -7
View File
@@ -56,15 +56,16 @@ enum result_t {
RESULT_ERR_DUPLICATE_NAME = -17, //!< duplicate entry (name)
RESULT_ERR_BUS_LOST = -18, //!< arbitration lost
RESULT_ERR_CRC = -19, //!< CRC error
RESULT_ERR_ACK = -20, //!< ACK error
RESULT_ERR_NAK = -21, //!< NAK received
RESULT_ERR_ARB_RUNNING = -19, //!< arbitration running
RESULT_ERR_CRC = -20, //!< CRC error
RESULT_ERR_ACK = -21, //!< ACK error
RESULT_ERR_NAK = -22, //!< NAK received
RESULT_ERR_NO_SIGNAL = -22, //!< no signal found on the bus
RESULT_ERR_SYN = -23, //!< SYN received instead of answer
RESULT_ERR_SYMBOL = -24, //!< wrong symbol received instead of sent symbol
RESULT_ERR_NO_SIGNAL = -23, //!< no signal found on the bus
RESULT_ERR_SYN = -24, //!< SYN received instead of answer
RESULT_ERR_SYMBOL = -25, //!< wrong symbol received instead of sent symbol
RESULT_ERR_NOTAUTHORIZED = -25 //!< not authorized for this action
RESULT_ERR_NOTAUTHORIZED = -26 //!< not authorized for this action
};
+5 -5
View File
@@ -72,19 +72,19 @@ using std::vector;
typedef unsigned char symbol_t;
/** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA. */
#define ESC 0xA9
#define ESC ((symbol_t)0xA9)
/** synchronization symbol. */
#define SYN 0xAA
#define SYN ((symbol_t)0xAA)
/** positive acknowledge symbol. */
#define ACK 0x00
#define ACK ((symbol_t)0x00)
/** negative acknowledge symbol. */
#define NAK 0xFF
#define NAK ((symbol_t)0xFF)
/** the broadcast destination address. */
#define BROADCAST 0xFE
#define BROADCAST ((symbol_t)0xFE)
/**
* Parse an unsigned int value.
-4
View File
@@ -11,10 +11,6 @@ add_executable(test_filereader test_filereader.cpp)
target_link_libraries(test_filereader ebus pthread)
add_test(filereader test_filereader)
add_executable(test_device test_device.cpp)
target_link_libraries(test_device ebus pthread ${test_LIBS})
add_test(device test_device)
add_executable(test_symbol test_symbol.cpp)
target_link_libraries(test_symbol ebus pthread)
add_test(symbol test_symbol)
-5
View File
@@ -3,7 +3,6 @@ AM_CXXFLAGS = -I$(top_srcdir)/src \
-Wno-unused-parameter
noinst_PROGRAMS = test_filereader \
test_device \
test_symbol \
test_data \
test_message
@@ -11,9 +10,6 @@ noinst_PROGRAMS = test_filereader \
test_filereader_SOURCES = test_filereader.cpp
test_filereader_LDADD = ../libebus.a -lpthread
test_device_SOURCES = test_device.cpp
test_device_LDADD = ../libebus.a -lpthread
test_symbol_SOURCES = test_symbol.cpp
test_symbol_LDADD = ../libebus.a -lpthread
@@ -24,7 +20,6 @@ test_message_SOURCES = test_message.cpp
test_message_LDADD = ../libebus.a -lpthread
if CONTRIB
test_device_LDADD += ../contrib/libebuscontrib.a
test_data_LDADD += ../contrib/libebuscontrib.a
test_message_LDADD += ../contrib/libebuscontrib.a
endif
+3
View File
@@ -175,6 +175,9 @@ void closeLogFile() {
}
bool needsLog(const LogFacility facility, const LogLevel level) {
if (s_logFile == nullptr && !s_useSyslog) {
return false;
}
return s_facilityLogLevel[facility] >= level;
}
+16
View File
@@ -50,6 +50,22 @@ bool RotateFile::setEnabled(bool enabled) {
if (enabled) {
m_stream = fopen(m_fileName.c_str(), m_textMode ? "w" : "wb");
m_fileSize = 0;
#ifdef FORWARD_RAW_TTY
if (!m_textMode && isatty(fileno(m_stream)) == 1) {
int fd = fileno(m_stream);
struct termios newSettings;
memset(&newSettings, 0, sizeof(newSettings));
cfsetspeed(&newSettings, B2400);
newSettings.c_cflag |= (CS8 | CLOCAL);
newSettings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // non-canonical mode
newSettings.c_iflag |= IGNPAR; // ignore parity errors
newSettings.c_oflag &= ~OPOST;
// activate new settings of serial device
tcsetattr(fd, TCSANOW, &newSettings);
}
#endif
}
return true;
}
+1 -1
View File
@@ -207,7 +207,7 @@ r,,SoftwareVersion,,,,,"0000",,,HEX:4,,,
EOF
echo "test,testpass,installer" > ./passwd
#ebusd:
./src/ebusd/ebusd -d tcp:127.0.0.1:8876 --initsend --latency 10000 -n -c "$PWD/contrib/etc/ebusd" --pollinterval=10 -s -a 31 --acquireretries 3 --answer --generatesyn --receivetimeout 40000 --sendretries 1 --enablehex --htmlpath "$PWD/contrib/html" --httpport 8878 --pidfile "$PWD/ebusd.pid" --localhost -p 8877 -l "$PWD/ebusd.log" --logareas all --loglevel debug --lograwdata=bytes --lograwdatafile "$PWD/ebusd.raw" --lograwdatasize 1 --dumpfile "$PWD/ebusd.dump" --dumpsize 100 -D --scanconfig --aclfile=./passwd --mqttport=1883
./src/ebusd/ebusd -d tcp:127.0.0.1:8876 --initsend --latency 10 -n -c "$PWD/contrib/etc/ebusd" --pollinterval=10 -s -a 31 --acquireretries 3 --answer --generatesyn --receivetimeout 40000 --sendretries 1 --enablehex --htmlpath "$PWD/contrib/html" --httpport 8878 --pidfile "$PWD/ebusd.pid" --localhost -p 8877 -l "$PWD/ebusd.log" --logareas all --loglevel debug --lograwdata=bytes --lograwdatafile "$PWD/ebusd.raw" --lograwdatasize 1 --dumpfile "$PWD/ebusd.dump" --dumpsize 100 -D --scanconfig --aclfile=./passwd --mqttport=1883
sleep 3
pid=`head -n 1 "$PWD/ebusd.pid"`
if [ -z "$pid" ]; then