Commit af576287 authored by Micha Mueller's avatar Micha Mueller
Browse files

BACnet: make timeout when receiving configurable

parent d6c46ac1
......@@ -404,6 +404,7 @@ global {
mqttPrefix /FF112233445566778899FFFF
interface eth0
port 22222
timeout 1000
apdu_timeout 200
apdu_retries 1
}
......@@ -456,6 +457,7 @@ Explanation of the values specific for the BACnet plugin:
|:----- |:----------- |
| interface | Network interface (IPv4) which is to be used by the plugin to send its "Read Property" requests.
| port | Port to use on the interface
| timeout | Value of µ-seconds to wait for a response packet.
| apdu_timeout | Value of µ-seconds before sending a request times out.
| apdu_retries | How often should sending a request be retried.
| templates | One can define template properties in this section for convenience.
......
......@@ -2,6 +2,7 @@ global {
mqttPrefix /FF112233445566778899FFFF
interface eth0
port 22222
timeout 1000
apdu_timeout 200
apdu_retries 1
}
......
......@@ -32,7 +32,9 @@ BACnetClient::~BACnetClient() {
datalink_cleanup();
}
void BACnetClient::init(std::string interface, unsigned port, unsigned timeout, unsigned retries) {
void BACnetClient::init(std::string interface, unsigned port, unsigned timeout, unsigned apdu_timeout, unsigned retries) {
_timeout = timeout;
//compile BACnet stack with BACNET_ADDRESS_CACHE_FILE for initialization from file address_cache
address_init();
......@@ -41,7 +43,7 @@ void BACnetClient::init(std::string interface, unsigned port, unsigned timeout,
//#if defined(BACDL_BIP)
bip_set_port(port);
//#endif
apdu_timeout_set(timeout);
apdu_timeout_set(apdu_timeout);
apdu_retries_set(retries);
if (!datalink_init(&interface[0])) {
......
......@@ -37,9 +37,13 @@ public:
* We assume BACnet/IP protocol is used. Also you need to compile with environment variable BACNET_ADDRESS_CACHE_FILE set
* to enable initialization of address cache from file "address_cache".
*
* @param port
* @param interface Name of network interface to use
* @param port Which port to use of the interface
* @param timeout Number of milliseconds to wait for a packet when receiving
* @param apdu_timeout Number of milliseconds before timeout when sending
* @param retries Number of retries after an apdu timeout occurs
*/
void init(std::string interface, unsigned port = 47808, unsigned timeout = 200, unsigned retries = 0);
void init(std::string interface, unsigned port = 47808, unsigned timeout = 1000, unsigned apdu_timeout = 200, unsigned retries = 0);
/**
* Sends a READ_PROPERTY request for PROP_PRESENT_VALUE to specified device and decodes the response (READ_PROPERTY_ACK).
......
......@@ -30,7 +30,7 @@ std::vector<Sensor*>& BACnetConfigurator::readConfig(std::string cfgPath) {
_bacClient = new BACnetClient();
std::string interface, mqttPartDevice, mqttPartObject;
unsigned port = 47808, apdu_timeout = 200, apdu_retries = 0;
unsigned port = 47808, timeout = 1000, apdu_timeout = 200, apdu_retries = 0;
unsigned deviceInstance = 0, objInstance = 0;
BACNET_OBJECT_TYPE objType = OBJECT_DEVICE; /* = 8 */
......@@ -42,6 +42,9 @@ std::vector<Sensor*>& BACnetConfigurator::readConfig(std::string cfgPath) {
} else if (boost::iequals(global.first, "port")) {
port = stoul(global.second.data());
LOG(debug) << " Port " << port;
} else if (boost::iequals(global.first, "timeout")) {
timeout = stoul(global.second.data());
LOG(debug) << " Timeout " << timeout;
} else if (boost::iequals(global.first, "apdu_timeout")) {
apdu_timeout = stoul(global.second.data());
LOG(debug) << " apdu_timeout " << apdu_timeout;
......@@ -57,7 +60,7 @@ std::vector<Sensor*>& BACnetConfigurator::readConfig(std::string cfgPath) {
}
try {
_bacClient->init(interface, port, apdu_timeout, apdu_retries);
_bacClient->init(interface, port, timeout, apdu_timeout, apdu_retries);
} catch (const std::exception& e) {
LOG(error) << "Could not initialize BACnetClient: " << e.what();
return _sensors;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment