BACnetConfigurator.cpp 2.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * BACnetConfigurator.cpp
 *
 *  Created on: 14.04.2018
 *      Author: Micha Mueller
 */

#include "BACnetConfigurator.h"

#include <boost/optional.hpp>
#include <iostream>

BACnetConfigurator::BACnetConfigurator() {
	_bacClient = nullptr;

	_groupName = "group";
	_baseName = "property";
}

BACnetConfigurator::~BACnetConfigurator() {}

void BACnetConfigurator::sensorBase(BACnetSensorBase& s, CFG_VAL config) {
	ADD {
		ATTRIBUTE("objectInstance", setObjectInstance);
		ATTRIBUTE("objectType", setObjectType);
		ATTRIBUTE("id", setPropertyId);
		ATTRIBUTE("factor", setFactor);
	}
}

void BACnetConfigurator::sensorGroup(BACnetSensorGroup& s, CFG_VAL config) {
	ADD {
		ATTRIBUTE("deviceInstance", setDeviceInstance);
	}
	s.setBACnetClient(_bacClient);
}

void BACnetConfigurator::global(CFG_VAL config) {
	_bacClient = std::make_shared<BACnetClient>();

	std::string address_cache, interface;
	unsigned port = 47808, timeout = 1000, apdu_timeout = 200, apdu_retries = 0;

	ADD {
		SETTING("address_cache") {
			address_cache = val.second.data();
			LOG(debug) << "  Address Cache: " << address_cache;
		} SETTING("interface") {
			interface = val.second.data();
			LOG(debug) << "  Interface " << interface;
		} SETTING("port") {
			port = stoul(val.second.data());
			LOG(debug) << "  Port " << port;
		} SETTING("timeout") {
			timeout = stoul(val.second.data());
			LOG(debug) << "  Timeout " << timeout;
		} SETTING("apdu_timeout") {
			apdu_timeout = stoul(val.second.data());
			LOG(debug) << "  apdu_timeout " << apdu_timeout;
		} SETTING("apdu_retries") {
			apdu_retries = stoul(val.second.data());
			LOG(debug) << "  apdu_retries " << apdu_retries;
		}
	}

	try {
		_bacClient->init(interface, address_cache, port, timeout, apdu_timeout, apdu_retries);
	} catch (const std::exception& e) {
		LOG(error) << "Could not initialize BACnetClient: " << e.what();
		_bacClient = nullptr;
		return;
	}
}

void BACnetConfigurator::printConfiguratorConfig(LOG_LEVEL ll) {
  LOG_VAR(ll) << "  No other plugin specific general attributes";

  if (_bacClient) {
    _bacClient->printConfig(ll);
  } else {
    LOG_VAR(ll) << " No BACClient present!";
  }
}