BACnetConfigurator.cpp 2.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
 * BACnetConfigurator.cpp
 *
 *  Created on: 14.04.2018
 *      Author: Micha Mueller
 */

#include "BACnetConfigurator.h"

10
11
12
#include <boost/optional.hpp>
#include <iostream>

13
BACnetConfigurator::BACnetConfigurator() {
14
15
16
17
	_bacClient = nullptr;

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

20
BACnetConfigurator::~BACnetConfigurator() {}
21

22
23
24
25
26
27
28
29
30
31
32
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 {
33
		ATTRIBUTE("deviceInstance", setDeviceInstance);
34
35
36
37
38
	}
	s.setBACnetClient(_bacClient);
}

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

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

44
45
46
	ADD {
		SETTING("address_cache") {
			address_cache = val.second.data();
47
			LOG(debug) << "  Address Cache: " << address_cache;
48
49
		} SETTING("interface") {
			interface = val.second.data();
50
			LOG(debug) << "  Interface " << interface;
51
52
		} SETTING("port") {
			port = stoul(val.second.data());
53
			LOG(debug) << "  Port " << port;
54
55
		} SETTING("timeout") {
			timeout = stoul(val.second.data());
56
			LOG(debug) << "  Timeout " << timeout;
57
58
		} SETTING("apdu_timeout") {
			apdu_timeout = stoul(val.second.data());
59
			LOG(debug) << "  apdu_timeout " << apdu_timeout;
60
61
		} SETTING("apdu_retries") {
			apdu_retries = stoul(val.second.data());
62
63
64
65
66
			LOG(debug) << "  apdu_retries " << apdu_retries;
		}
	}

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

void BACnetConfigurator::printConfiguratorConfig(LOG_LEVEL ll) {
Micha Mueller's avatar
Micha Mueller committed
76
  LOG_VAR(ll) << "  No other plugin specific general attributes";
77
78
79
80
81
82
83

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