formatting, remove unused
This commit is contained in:
@@ -784,7 +784,7 @@ result_t BusHandler::handleSymbol() {
|
|||||||
// check arbitration
|
// check arbitration
|
||||||
if (recvSymbol == sendSymbol) { // arbitration successful
|
if (recvSymbol == sendSymbol) { // arbitration successful
|
||||||
// measure arbitration delay
|
// measure arbitration delay
|
||||||
long long latencyLong = (sentTime.tv_sec*1000000000 + sentTime.tv_nsec
|
int64_t latencyLong = (sentTime.tv_sec*1000000000 + sentTime.tv_nsec
|
||||||
- m_lastSynReceiveTime.tv_sec*1000000000 - m_lastSynReceiveTime.tv_nsec)/1000;
|
- m_lastSynReceiveTime.tv_sec*1000000000 - m_lastSynReceiveTime.tv_nsec)/1000;
|
||||||
if (latencyLong >= 0 && latencyLong <= 10000) { // skip clock skew or out of reasonable range
|
if (latencyLong >= 0 && latencyLong <= 10000) { // skip clock skew or out of reasonable range
|
||||||
auto latency = static_cast<int>(latencyLong);
|
auto latency = static_cast<int>(latencyLong);
|
||||||
@@ -1113,7 +1113,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BusHandler::measureLatency(struct timespec* sentTime, struct timespec* recvTime) {
|
void BusHandler::measureLatency(struct timespec* sentTime, struct timespec* recvTime) {
|
||||||
long long latencyLong = (recvTime->tv_sec*1000000000 + recvTime->tv_nsec
|
int64_t latencyLong = (recvTime->tv_sec*1000000000 + recvTime->tv_nsec
|
||||||
- sentTime->tv_sec*1000000000 - sentTime->tv_nsec)/1000000;
|
- sentTime->tv_sec*1000000000 - sentTime->tv_nsec)/1000000;
|
||||||
if (latencyLong < 0 || latencyLong > 1000) {
|
if (latencyLong < 0 || latencyLong > 1000) {
|
||||||
return; // clock skew or out of reasonable range
|
return; // clock skew or out of reasonable range
|
||||||
|
|||||||
@@ -59,8 +59,10 @@ static const struct argp_option g_knx_argp_options[] = {
|
|||||||
" or \"ip:host[:port]\" / \"local:/socketpath\" for knxd"
|
" or \"ip:host[:port]\" / \"local:/socketpath\" for knxd"
|
||||||
#endif
|
#endif
|
||||||
") []", 0 },
|
") []", 0 },
|
||||||
{"knxrage", O_AGR, "SEC", 0, "Maximum age in seconds for using the last value of read messages (0=disable) [5]", 0 },
|
{"knxrage", O_AGR, "SEC", 0, "Maximum age in seconds for using the last value of read messages (0=disable)"
|
||||||
{"knxwage", O_AGW, "SEC", 0, "Maximum age in seconds for using the last value for reads on write messages (0=disable), [99999999]", 0 },
|
" [5]", 0 },
|
||||||
|
{"knxwage", O_AGW, "SEC", 0, "Maximum age in seconds for using the last value for reads on write messages"
|
||||||
|
" (0=disable), [99999999]", 0 },
|
||||||
{"knxint", O_INT, "FILE", 0, "Read KNX integration settings from FILE [/etc/ebusd/knx.cfg]", 0 },
|
{"knxint", O_INT, "FILE", 0, "Read KNX integration settings from FILE [/etc/ebusd/knx.cfg]", 0 },
|
||||||
{"knxvar", O_VAR, "NAME=VALUE", 0, "Add a variable to the read KNX integration settings", 0 },
|
{"knxvar", O_VAR, "NAME=VALUE", 0, "Add a variable to the read KNX integration settings", 0 },
|
||||||
|
|
||||||
@@ -69,7 +71,8 @@ static const struct argp_option g_knx_argp_options[] = {
|
|||||||
|
|
||||||
static const char* g_url = nullptr; //!< URL of KNX daemon
|
static const char* g_url = nullptr; //!< URL of KNX daemon
|
||||||
static unsigned int g_maxReadAge = 5; //!< max age in seconds for using the last value of read messages
|
static unsigned int g_maxReadAge = 5; //!< max age in seconds for using the last value of read messages
|
||||||
static unsigned int g_maxWriteAge = 99999999; //!< max age in seconds for using the last value for reads on write messages
|
// max age in seconds for using the last value for reads on write messages
|
||||||
|
static unsigned int g_maxWriteAge = 99999999;
|
||||||
static const char* g_integrationFile = nullptr; //!< the integration settings file
|
static const char* g_integrationFile = nullptr; //!< the integration settings file
|
||||||
static vector<string>* g_integrationVars = nullptr; //!< the integration settings variables
|
static vector<string>* g_integrationVars = nullptr; //!< the integration settings variables
|
||||||
|
|
||||||
@@ -347,7 +350,8 @@ float int16ToFloat(uint16_t val) {
|
|||||||
return static_cast<float>(sig * exp2(exp) * (negative ? -0.01 : 0.01));
|
return static_cast<float>(sig * exp2(exp) * (negative ? -0.01 : 0.01));
|
||||||
}
|
}
|
||||||
|
|
||||||
result_t KnxHandler::sendGroupValue(knx_addr_t dest, apci_t apci, dtlf_t& lengthFlag, unsigned int value, const SingleDataField *field) const {
|
result_t KnxHandler::sendGroupValue(knx_addr_t dest, apci_t apci, dtlf_t& lengthFlag, unsigned int value,
|
||||||
|
const SingleDataField *field) const {
|
||||||
if (!m_con || !m_con->isConnected() || !m_con->getAddress()) {
|
if (!m_con || !m_con->isConnected() || !m_con->getAddress()) {
|
||||||
return RESULT_EMPTY;
|
return RESULT_EMPTY;
|
||||||
}
|
}
|
||||||
@@ -520,7 +524,8 @@ void printResponse(knx_addr_t src, knx_addr_t dest, int len, const uint8_t *data
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void KnxHandler::handleReceivedTelegram(knx_transfer_t typ, knx_addr_t src, knx_addr_t dest, int len, const uint8_t *data) {
|
void KnxHandler::handleReceivedTelegram(knx_transfer_t typ, knx_addr_t src, knx_addr_t dest, int len,
|
||||||
|
const uint8_t *data) {
|
||||||
if (typ == KNX_TRANSFER_GROUP) {
|
if (typ == KNX_TRANSFER_GROUP) {
|
||||||
handleGroupTelegram(src, dest, len, data);
|
handleGroupTelegram(src, dest, len, data);
|
||||||
return;
|
return;
|
||||||
@@ -542,7 +547,8 @@ void KnxHandler::sendNonGroupDisconnect(knx_addr_t dest) {
|
|||||||
// the connection timeout in millis (6 seconds)
|
// the connection timeout in millis (6 seconds)
|
||||||
#define CONNECTION_TIMEOUT 6000
|
#define CONNECTION_TIMEOUT 6000
|
||||||
|
|
||||||
void KnxHandler::handleNonGroupTelegram(knx_transfer_t typ, knx_addr_t src, knx_addr_t dest, int len, const uint8_t *data) {
|
void KnxHandler::handleNonGroupTelegram(knx_transfer_t typ, knx_addr_t src, knx_addr_t dest, int len,
|
||||||
|
const uint8_t *data) {
|
||||||
if (typ == KNX_TRANSFER_NONE) {
|
if (typ == KNX_TRANSFER_NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -569,7 +575,7 @@ void KnxHandler::handleGroupTelegram(knx_addr_t src, knx_addr_t dest, int len, c
|
|||||||
m_lastIndividualAddressResponseTime = now;
|
m_lastIndividualAddressResponseTime = now;
|
||||||
}
|
}
|
||||||
} else if (apci == APCI_INDIVIDUALADDRESS_WRITE && len == 4 && !m_con->getAddress() && (data[2]|data[3])) {
|
} else if (apci == APCI_INDIVIDUALADDRESS_WRITE && len == 4 && !m_con->getAddress() && (data[2]|data[3])) {
|
||||||
m_con->setAddress((data[2]<<8)|data[3]);
|
m_con->setAddress(static_cast<knx_addr_t>((data[2] << 8)|data[3]));
|
||||||
m_lastIndividualAddressResponseTime = 0;
|
m_lastIndividualAddressResponseTime = 0;
|
||||||
logOtherNotice("knx", "received new address %x", m_con->getAddress());
|
logOtherNotice("knx", "received new address %x", m_con->getAddress());
|
||||||
}
|
}
|
||||||
@@ -606,7 +612,8 @@ void KnxHandler::handleGroupTelegram(knx_addr_t src, knx_addr_t dest, int len, c
|
|||||||
sendGlobalValue(GLOBAL_SCAN, m_lastScanStatus == SCAN_STATUS_RUNNING ? 1 : 0, true);
|
sendGlobalValue(GLOBAL_SCAN, m_lastScanStatus == SCAN_STATUS_RUNNING ? 1 : 0, true);
|
||||||
break;
|
break;
|
||||||
case GLOBAL_UPDATECHECK:
|
case GLOBAL_UPDATECHECK:
|
||||||
sendGlobalValue(GLOBAL_UPDATECHECK, m_lastUpdateCheckResult.empty() || m_lastUpdateCheckResult=="OK" || m_lastUpdateCheckResult=="." ? 0 : 1, true);
|
sendGlobalValue(GLOBAL_UPDATECHECK, m_lastUpdateCheckResult.empty() || m_lastUpdateCheckResult == "OK"
|
||||||
|
|| m_lastUpdateCheckResult == "." ? 0 : 1, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return; // ignore
|
return; // ignore
|
||||||
|
|||||||
@@ -155,7 +155,8 @@ class KnxHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
* @param field the message field or nullptr for non field related.
|
* @param field the message field or nullptr for non field related.
|
||||||
* @return the result code.
|
* @return the result code.
|
||||||
*/
|
*/
|
||||||
result_t sendGroupValue(knx_addr_t dest, apci_t apci, dtlf_t& lengthFlag, unsigned int value, const SingleDataField *field = nullptr) const;
|
result_t sendGroupValue(knx_addr_t dest, apci_t apci, dtlf_t& lengthFlag, unsigned int value,
|
||||||
|
const SingleDataField *field = nullptr) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a global value to the registered group address.
|
* Send a global value to the registered group address.
|
||||||
@@ -175,7 +176,8 @@ class KnxHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
* @return the result code, either RESULT_OK on success, RESULT_ERR_GENERIC_IO on I/O error (e.g. socket closed),
|
* @return the result code, either RESULT_OK on success, RESULT_ERR_GENERIC_IO on I/O error (e.g. socket closed),
|
||||||
* or RESULT_ERR_TIMEOUT if no data is available.
|
* or RESULT_ERR_TIMEOUT if no data is available.
|
||||||
*/
|
*/
|
||||||
result_t receiveTelegram(int maxlen, knx_transfer_t* typ, uint8_t *buf, int *recvlen, knx_addr_t *src, knx_addr_t *dest);
|
result_t receiveTelegram(int maxlen, knx_transfer_t* typ, uint8_t *buf, int *recvlen, knx_addr_t *src,
|
||||||
|
knx_addr_t *dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a received KNX telegram.
|
* Handle a received KNX telegram.
|
||||||
@@ -252,7 +254,7 @@ class KnxHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
time_t m_lastIndividualAddressResponseTime = 0;
|
time_t m_lastIndividualAddressResponseTime = 0;
|
||||||
|
|
||||||
/** the time of the last connection, or 0 if not connected. */
|
/** the time of the last connection, or 0 if not connected. */
|
||||||
long long m_lastConnectTime = 0;
|
uint64_t m_lastConnectTime = 0;
|
||||||
|
|
||||||
/** the source address of the last connection, or 0. */
|
/** the source address of the last connection, or 0. */
|
||||||
knx_addr_t m_lastConnectSource = 0;
|
knx_addr_t m_lastConnectSource = 0;
|
||||||
@@ -276,7 +278,7 @@ class KnxHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
bool m_scanFinishReceived;
|
bool m_scanFinishReceived;
|
||||||
|
|
||||||
/** the last system time when a communication error was logged. */
|
/** the last system time when a communication error was logged. */
|
||||||
long long m_lastErrorLogTime;
|
time_t m_lastErrorLogTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|||||||
+4
-2
@@ -222,7 +222,8 @@ static const struct argp_option argpoptions[] = {
|
|||||||
{"inject", 'i', "stop", OPTION_ARG_OPTIONAL, "Inject remaining arguments as already seen messages (e.g. "
|
{"inject", 'i', "stop", OPTION_ARG_OPTIONAL, "Inject remaining arguments as already seen messages (e.g. "
|
||||||
"\"FF08070400/0AB5454850303003277201\"), optionally stop afterwards", 0 },
|
"\"FF08070400/0AB5454850303003277201\"), optionally stop afterwards", 0 },
|
||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
{"cafile", O_CAFILE, "FILE", 0, "Use CA FILE for checking certificates (uses defaults, \"#\" for insecure)", 0 },
|
{"cafile", O_CAFILE, "FILE", 0, "Use CA FILE for checking certificates (uses defaults,"
|
||||||
|
" \"#\" for insecure)", 0 },
|
||||||
{"capath", O_CAPATH, "PATH", 0, "Use CA PATH for checking certificates (uses defaults)", 0 },
|
{"capath", O_CAPATH, "PATH", 0, "Use CA PATH for checking certificates (uses defaults)", 0 },
|
||||||
#endif // HAVE_SSL
|
#endif // HAVE_SSL
|
||||||
|
|
||||||
@@ -1371,7 +1372,8 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
size_t pos = s_configPath.find(PREVIOUS_CONFIG_PATH_SUFFIX);
|
size_t pos = s_configPath.find(PREVIOUS_CONFIG_PATH_SUFFIX);
|
||||||
if (pos != string::npos) {
|
if (pos != string::npos) {
|
||||||
string newPath = s_configPath.substr(0, pos) + CONFIG_PATH_SUFFIX + s_configPath.substr(pos+strlen(PREVIOUS_CONFIG_PATH_SUFFIX));
|
string newPath = s_configPath.substr(0, pos) + CONFIG_PATH_SUFFIX
|
||||||
|
+ s_configPath.substr(pos+strlen(PREVIOUS_CONFIG_PATH_SUFFIX));
|
||||||
logNotice(lf_main, "replaced old configPath %s with new one: %s", s_configPath.c_str(), newPath.c_str());
|
logNotice(lf_main, "replaced old configPath %s with new one: %s", s_configPath.c_str(), newPath.c_str());
|
||||||
s_configPath = newPath;
|
s_configPath = newPath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,7 +374,8 @@ bool mqtthandler_register(UserInfo* userInfo, BusHandler* busHandler, MessageMap
|
|||||||
int revision = -1;
|
int revision = -1;
|
||||||
mosquitto_lib_version(&major, &minor, &revision);
|
mosquitto_lib_version(&major, &minor, &revision);
|
||||||
if (major < LIBMOSQUITTO_MAJOR) {
|
if (major < LIBMOSQUITTO_MAJOR) {
|
||||||
logOtherError("mqtt", "invalid mosquitto version %d instead of %d, will try connecting anyway", major, LIBMOSQUITTO_MAJOR);
|
logOtherError("mqtt", "invalid mosquitto version %d instead of %d, will try connecting anyway", major,
|
||||||
|
LIBMOSQUITTO_MAJOR);
|
||||||
}
|
}
|
||||||
logOtherInfo("mqtt", "mosquitto version %d.%d.%d (compiled with %d.%d.%d)", major, minor, revision,
|
logOtherInfo("mqtt", "mosquitto version %d.%d.%d (compiled with %d.%d.%d)", major, minor, revision,
|
||||||
LIBMOSQUITTO_MAJOR, LIBMOSQUITTO_MINOR, LIBMOSQUITTO_REVISION);
|
LIBMOSQUITTO_MAJOR, LIBMOSQUITTO_MINOR, LIBMOSQUITTO_REVISION);
|
||||||
@@ -482,7 +483,8 @@ string removeTrailingNonTopicPart(const string& str) {
|
|||||||
|
|
||||||
MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages)
|
MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages)
|
||||||
: DataSink(userInfo, "mqtt"), DataSource(busHandler), WaitThread(), m_messages(messages), m_connected(false),
|
: DataSink(userInfo, "mqtt"), DataSource(busHandler), WaitThread(), m_messages(messages), m_connected(false),
|
||||||
m_initialConnectFailed(false), m_lastUpdateCheckResult("."), m_lastScanStatus(SCAN_STATUS_NONE), m_lastErrorLogTime(0) {
|
m_initialConnectFailed(false), m_lastUpdateCheckResult("."), m_lastScanStatus(SCAN_STATUS_NONE),
|
||||||
|
m_lastErrorLogTime(0) {
|
||||||
m_definitionsSince = 0;
|
m_definitionsSince = 0;
|
||||||
m_mosquitto = nullptr;
|
m_mosquitto = nullptr;
|
||||||
bool hasIntegration = false;
|
bool hasIntegration = false;
|
||||||
|
|||||||
@@ -20,9 +20,10 @@
|
|||||||
#define EBUSD_MQTTHANDLER_H_
|
#define EBUSD_MQTTHANDLER_H_
|
||||||
|
|
||||||
#include <mosquitto.h>
|
#include <mosquitto.h>
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ebusd/datahandler.h"
|
#include "ebusd/datahandler.h"
|
||||||
#include "ebusd/bushandler.h"
|
#include "ebusd/bushandler.h"
|
||||||
@@ -36,6 +37,7 @@ namespace ebusd {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
|
using std::pair;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
@@ -185,7 +187,7 @@ class MqttHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
bool m_hasDefinitionFieldsPayload;
|
bool m_hasDefinitionFieldsPayload;
|
||||||
|
|
||||||
/** map of type name to a list of pairs of wildcard string and mapped value. */
|
/** map of type name to a list of pairs of wildcard string and mapped value. */
|
||||||
map<string, vector<std::pair<string, string>>> m_typeSwitches;
|
map<string, vector<pair<string, string>>> m_typeSwitches;
|
||||||
|
|
||||||
/** the subscribed configuration restart topic, or empty. */
|
/** the subscribed configuration restart topic, or empty. */
|
||||||
string m_subscribeConfigRestartTopic;
|
string m_subscribeConfigRestartTopic;
|
||||||
|
|||||||
@@ -465,7 +465,8 @@ bool Device::available() {
|
|||||||
ch = m_buffer[(pos+m_bufPos+1)%m_bufSize];
|
ch = m_buffer[(pos+m_bufPos+1)%m_bufSize];
|
||||||
if (!(ch&ENH_BYTE_FLAG) || (ch&ENH_BYTE_MASK) != ENH_BYTE2) {
|
if (!(ch&ENH_BYTE_FLAG) || (ch&ENH_BYTE_MASK) != ENH_BYTE2) {
|
||||||
#ifdef DEBUG_RAW_TRAFFIC
|
#ifdef DEBUG_RAW_TRAFFIC
|
||||||
fprintf(stdout, "raw avail enhanced following bad @%d+%d %2.2x %2.2x\n", m_bufPos, pos, m_buffer[(pos+m_bufPos)%m_bufSize], ch);
|
fprintf(stdout, "raw avail enhanced following bad @%d+%d %2.2x %2.2x\n", m_bufPos, pos,
|
||||||
|
m_buffer[(pos+m_bufPos)%m_bufSize], ch);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
if (m_listener != nullptr) {
|
if (m_listener != nullptr) {
|
||||||
|
|||||||
@@ -352,7 +352,8 @@ class SerialDevice : public Device {
|
|||||||
*/
|
*/
|
||||||
SerialDevice(const char* name, bool checkDevice, unsigned int extraLatency, bool readOnly, bool initialSend,
|
SerialDevice(const char* name, bool checkDevice, unsigned int extraLatency, bool readOnly, bool initialSend,
|
||||||
bool enhancedProto = false, bool enhancedHighSpeed = false)
|
bool enhancedProto = false, bool enhancedHighSpeed = false)
|
||||||
: Device(name, checkDevice, extraLatency, readOnly, initialSend, enhancedProto), m_enhancedHighSpeed(enhancedHighSpeed) {
|
: Device(name, checkDevice, extraLatency, readOnly, initialSend, enhancedProto),
|
||||||
|
m_enhancedHighSpeed(enhancedHighSpeed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "lib/ebus/stringhelper.h"
|
#include "lib/ebus/stringhelper.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
namespace ebusd {
|
namespace ebusd {
|
||||||
|
|
||||||
@@ -296,7 +297,8 @@ bool StringReplacer::checkMatchability() const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t StringReplacer::match(const string& str, string* circuit, string* name, string* field, const string& separator) const {
|
ssize_t StringReplacer::match(const string& str, string* circuit, string* name, string* field,
|
||||||
|
const string& separator) const {
|
||||||
size_t last = 0;
|
size_t last = 0;
|
||||||
size_t count = m_parts.size();
|
size_t count = m_parts.size();
|
||||||
size_t idx;
|
size_t idx;
|
||||||
@@ -442,7 +444,8 @@ StringReplacer StringReplacers::get(const string& key) const {
|
|||||||
return StringReplacer();
|
return StringReplacer();
|
||||||
}
|
}
|
||||||
|
|
||||||
string StringReplacers::get(const string& key, bool untilFirstEmpty, bool onlyAlphanum, const string& fallbackKey) const {
|
string StringReplacers::get(const string& key, bool untilFirstEmpty, bool onlyAlphanum,
|
||||||
|
const string& fallbackKey) const {
|
||||||
auto itc = m_constants.find(key);
|
auto itc = m_constants.find(key);
|
||||||
if (itc != m_constants.end()) {
|
if (itc != m_constants.end()) {
|
||||||
return itc->second;
|
return itc->second;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "lib/ebus/message.h"
|
#include "lib/ebus/message.h"
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ namespace ebusd {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
|
using std::pair;
|
||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
@@ -172,7 +174,7 @@ class StringReplacer {
|
|||||||
* @param isField true when it is a field.
|
* @param isField true when it is a field.
|
||||||
* @return the created pair.
|
* @return the created pair.
|
||||||
*/
|
*/
|
||||||
static std::pair<string, int> makeField(const string& name, bool isField);
|
static pair<string, int> makeField(const string& name, bool isField);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a part to the list of parts.
|
* Add a part to the list of parts.
|
||||||
@@ -180,7 +182,6 @@ class StringReplacer {
|
|||||||
* @param inField 1 after '%', 2 after '%{', 0 otherwise.
|
* @param inField 1 after '%', 2 after '%{', 0 otherwise.
|
||||||
*/
|
*/
|
||||||
void addPart(ostringstream& stack, int inField);
|
void addPart(ostringstream& stack, int inField);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -20,6 +20,8 @@
|
|||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "lib/knx/knx.h"
|
#include "lib/knx/knx.h"
|
||||||
|
|
||||||
#ifdef HAVE_KNXD
|
#ifdef HAVE_KNXD
|
||||||
@@ -27,8 +29,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "lib/knx/knxnet.h"
|
#include "lib/knx/knxnet.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
namespace ebusd {
|
namespace ebusd {
|
||||||
|
|
||||||
unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned int maxValue,
|
unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned int maxValue,
|
||||||
|
|||||||
+4
-3
@@ -150,12 +150,12 @@ class KnxConnection {
|
|||||||
/**
|
/**
|
||||||
* @return true if connection allows programming via ETS.
|
* @return true if connection allows programming via ETS.
|
||||||
*/
|
*/
|
||||||
virtual bool isProgrammable() const { return false; };
|
virtual bool isProgrammable() const { return false; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the individual address, or 0 if not programmed yet, or any non-zero value if not programmable.
|
* @return the individual address, or 0 if not programmed yet, or any non-zero value if not programmable.
|
||||||
*/
|
*/
|
||||||
virtual knx_addr_t getAddress() { return DEFAULT_ADDRESS; };
|
virtual knx_addr_t getAddress() const { return DEFAULT_ADDRESS; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param address the individual address to set.
|
* @param address the individual address to set.
|
||||||
@@ -168,7 +168,7 @@ class KnxConnection {
|
|||||||
* Get the programming mode.
|
* Get the programming mode.
|
||||||
* @return true when in programming mode, false if not.
|
* @return true when in programming mode, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool isProgrammingMode() {
|
virtual bool isProgrammingMode() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,3 +184,4 @@ class KnxConnection {
|
|||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|
||||||
#endif // LIB_KNX_KNX_H_
|
#endif // LIB_KNX_KNX_H_
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ class KnxdConnection : public KnxConnection {
|
|||||||
/**
|
/**
|
||||||
* Construct a new instance.
|
* Construct a new instance.
|
||||||
*/
|
*/
|
||||||
KnxdConnection(const char *url)
|
explicit KnxdConnection(const char *url)
|
||||||
: KnxConnection(), m_url(url), m_con(nullptr) {}
|
: KnxConnection(), m_url(url), m_con(nullptr) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+14
-11
@@ -19,7 +19,6 @@
|
|||||||
#ifndef LIB_KNX_KNXNET_H_
|
#ifndef LIB_KNX_KNXNET_H_
|
||||||
#define LIB_KNX_KNXNET_H_
|
#define LIB_KNX_KNXNET_H_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@@ -33,6 +32,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
|
#include <string>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "lib/knx/knx.h"
|
#include "lib/knx/knx.h"
|
||||||
|
|
||||||
@@ -92,7 +92,8 @@ typedef enum {
|
|||||||
// cEMI frame header (external message interface)
|
// cEMI frame header (external message interface)
|
||||||
typedef struct __attribute__ ((packed)) {
|
typedef struct __attribute__ ((packed)) {
|
||||||
uint8_t messageCode;
|
uint8_t messageCode;
|
||||||
uint8_t additionalInfoLength; // optional immediately following additional bytes, usually =0. fixed to 0 in cEMI management messages
|
// optional immediately following additional bytes, usually =0. fixed to 0 in cEMI management messages
|
||||||
|
uint8_t additionalInfoLength;
|
||||||
} knxnet_cemi_header_t;
|
} knxnet_cemi_header_t;
|
||||||
|
|
||||||
/* cEMI message codes. */
|
/* cEMI message codes. */
|
||||||
@@ -328,7 +329,8 @@ class LastFrames {
|
|||||||
// helper method to log received/sent telegrams
|
// helper method to log received/sent telegrams
|
||||||
void logTelegram(bool sent, knxnet_cemi_header_t* c, knxnet_l_data_header_t* l, uint8_t* d) {
|
void logTelegram(bool sent, knxnet_cemi_header_t* c, knxnet_l_data_header_t* l, uint8_t* d) {
|
||||||
bool isGrp = l->controlField2.addressType;
|
bool isGrp = l->controlField2.addressType;
|
||||||
PRINTF("%s msgcode=%2.2x, %d.%d.%d > %d%c%d%c%d, repeat=%s, ack=%s, hopcnt=%d, prio=%s, frame=%s, %sbroad, confirm=%s, tpci/apci=%2.2x",
|
PRINTF("%s msgcode=%2.2x, %d.%d.%d > %d%c%d%c%d, repeat=%s, ack=%s, hopcnt=%d, prio=%s, frame=%s, %sbroad, "
|
||||||
|
"confirm=%s, tpci/apci=%2.2x",
|
||||||
sent ? "send" : "recv",
|
sent ? "send" : "recv",
|
||||||
c->messageCode,
|
c->messageCode,
|
||||||
l->sourceAddress.high>>4,
|
l->sourceAddress.high>>4,
|
||||||
@@ -342,12 +344,12 @@ void logTelegram(bool sent, knxnet_cemi_header_t* c, knxnet_l_data_header_t* l,
|
|||||||
l->controlField1.repeat ? "yes" : "no",
|
l->controlField1.repeat ? "yes" : "no",
|
||||||
l->controlField1.acknowledgeRequest ? "yes" : "no",
|
l->controlField1.acknowledgeRequest ? "yes" : "no",
|
||||||
l->controlField2.hopCount,
|
l->controlField2.hopCount,
|
||||||
l->controlField1.priority==1 ? "normal" : l->controlField1.priority==2 ? "urgent" : l->controlField1.priority==3 ? "low" : "system",
|
l->controlField1.priority == 1 ? "normal" : l->controlField1.priority == 2 ? "urgent" :
|
||||||
|
l->controlField1.priority == 3 ? "low" : "system",
|
||||||
l->controlField1.frameType ? "std" : "ext",
|
l->controlField1.frameType ? "std" : "ext",
|
||||||
l->controlField1.systemBroadcast ? "" : "sys ",
|
l->controlField1.systemBroadcast ? "" : "sys ",
|
||||||
l->controlField1.confirm ? "error" : "no err",
|
l->controlField1.confirm ? "error" : "no err",
|
||||||
d[0]
|
d[0]);
|
||||||
);
|
|
||||||
if (d) {
|
if (d) {
|
||||||
PRINTF(", data=");
|
PRINTF(", data=");
|
||||||
for (int i=0; i < l->informationLength; i++) {
|
for (int i=0; i < l->informationLength; i++) {
|
||||||
@@ -371,7 +373,7 @@ class KnxNetConnection : public KnxConnection {
|
|||||||
/**
|
/**
|
||||||
* Construct a new instance.
|
* Construct a new instance.
|
||||||
*/
|
*/
|
||||||
KnxNetConnection(const char* url)
|
explicit KnxNetConnection(const char* url)
|
||||||
: KnxConnection(), m_url(url), m_sock(0), m_programmingMode(false), m_addr(0) {}
|
: KnxConnection(), m_url(url), m_sock(0), m_programmingMode(false), m_addr(0) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -504,11 +506,12 @@ class KnxNetConnection : public KnxConnection {
|
|||||||
// @copydoc
|
// @copydoc
|
||||||
knx_transfer_t getPollData(int size, uint8_t* data, int* recvlen, knx_addr_t* src, knx_addr_t* dst) override {
|
knx_transfer_t getPollData(int size, uint8_t* data, int* recvlen, knx_addr_t* src, knx_addr_t* dst) override {
|
||||||
uint8_t buf[128];
|
uint8_t buf[128];
|
||||||
ssize_t len = recv(m_sock, buf, sizeof(buf), 0);
|
ssize_t slen = recv(m_sock, buf, sizeof(buf), 0);
|
||||||
if (len < sizeof(knxnet_header_t)) {
|
if (slen < 0 || static_cast<unsigned>(slen) < sizeof(knxnet_header_t)) {
|
||||||
PRINTF("#skip recv short hdr len=%d\n", len);
|
PRINTF("#skip recv short hdr len=%d\n", len);
|
||||||
return KNX_TRANSFER_NONE;
|
return KNX_TRANSFER_NONE;
|
||||||
}
|
}
|
||||||
|
size_t len = static_cast<unsigned>(slen);
|
||||||
auto h = (knxnet_header_t*)buf;
|
auto h = (knxnet_header_t*)buf;
|
||||||
if (h->headerLength != sizeof(knxnet_header_t) || h->protocolVersion != 0x10) {
|
if (h->headerLength != sizeof(knxnet_header_t) || h->protocolVersion != 0x10) {
|
||||||
PRINTF("#skip recv short/proto len=%d\n", len);
|
PRINTF("#skip recv short/proto len=%d\n", len);
|
||||||
@@ -673,7 +676,7 @@ class KnxNetConnection : public KnxConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copydoc
|
// copydoc
|
||||||
knx_addr_t getAddress() override {
|
knx_addr_t getAddress() const override {
|
||||||
return m_addr;
|
return m_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,7 +689,7 @@ class KnxNetConnection : public KnxConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copydoc
|
// copydoc
|
||||||
bool isProgrammingMode() override {
|
bool isProgrammingMode() const override {
|
||||||
return m_programmingMode;
|
return m_programmingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void clockGettime(struct timespec* t) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
long long clockGetMillis() {
|
uint64_t clockGetMillis() {
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
clockGettime(&t);
|
clockGettime(&t);
|
||||||
return t.tv_sec*1000LL + t.tv_nsec / 1000000;
|
return t.tv_sec*1000LL + t.tv_nsec / 1000000;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#ifndef LIB_UTILS_CLOCK_H_
|
#ifndef LIB_UTILS_CLOCK_H_
|
||||||
#define LIB_UTILS_CLOCK_H_
|
#define LIB_UTILS_CLOCK_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
namespace ebusd {
|
namespace ebusd {
|
||||||
@@ -34,7 +35,7 @@ void clockGettime(struct timespec* t);
|
|||||||
/**
|
/**
|
||||||
* Get the current system time in milliseconds since the Epoch.
|
* Get the current system time in milliseconds since the Epoch.
|
||||||
*/
|
*/
|
||||||
long long clockGetMillis();
|
uint64_t clockGetMillis();
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ bool WaitThread::Wait(int seconds, int millis) {
|
|||||||
struct timespec t;
|
struct timespec t;
|
||||||
clockGettime(&t);
|
clockGettime(&t);
|
||||||
t.tv_sec += seconds;
|
t.tv_sec += seconds;
|
||||||
long newMillis = t.tv_nsec/1000000 + millis;
|
long int newMillis = t.tv_nsec/1000000 + millis;
|
||||||
if (newMillis >= 1000) {
|
if (newMillis >= 1000) {
|
||||||
t.tv_sec += newMillis / 1000;
|
t.tv_sec += newMillis / 1000;
|
||||||
t.tv_nsec = (newMillis%1000) * 1000000; // rounds down to whole millis
|
t.tv_nsec = (newMillis%1000) * 1000000; // rounds down to whole millis
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ const char *argp_program_version = "eBUS adapter PIC firmware loader";
|
|||||||
/** the documentation of the program. */
|
/** the documentation of the program. */
|
||||||
static const char argpdoc[] =
|
static const char argpdoc[] =
|
||||||
"A tool for loading firmware to the eBUS adapter PIC."
|
"A tool for loading firmware to the eBUS adapter PIC."
|
||||||
"\vPORT is either the serial port to use (e.g./dev/ttyUSB0) that also supports a trailing wildcard '*' for testing multiple ports,"
|
"\vPORT is either the serial port to use (e.g./dev/ttyUSB0) that also supports a trailing wildcard '*' for testing"
|
||||||
"or a network port as \"ip:port\" for use with e.g. socat.";
|
" multiple ports, or a network port as \"ip:port\" for use with e.g. socat.";
|
||||||
|
|
||||||
static const char argpargsdoc[] = "PORT";
|
static const char argpargsdoc[] = "PORT";
|
||||||
|
|
||||||
@@ -265,12 +265,6 @@ static bool isSerial = true;
|
|||||||
static int timeoutFactor = 1;
|
static int timeoutFactor = 1;
|
||||||
static int timeoutAddend = 0;
|
static int timeoutAddend = 0;
|
||||||
|
|
||||||
long long getTime() {
|
|
||||||
struct timespec ts;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
return ts.tv_sec*1000+ts.tv_nsec/1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t waitWrite(int fd, uint8_t *data, size_t len, int timeoutMillis) {
|
ssize_t waitWrite(int fd, uint8_t *data, size_t len, int timeoutMillis) {
|
||||||
int ret;
|
int ret;
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
|
|||||||
Reference in New Issue
Block a user