BACnetConfigurator.cpp 3.3 KB
Newer Older
1
2
3
//================================================================================
// Name        : BACnetConfigurator.cpp
// Author      : Micha Mueller
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright   : Leibniz Supercomputing Centre
// Description : Source file for BACnet plugin configurator class.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
27
28
29

#include "BACnetConfigurator.h"

30
31
32
#include <boost/optional.hpp>
#include <iostream>

33
BACnetConfigurator::BACnetConfigurator() {
34
35
36
37
	_bacClient = nullptr;

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

40
BACnetConfigurator::~BACnetConfigurator() {}
41

42
void BACnetConfigurator::sensorBase(BACnetSensorBase &s, CFG_VAL config) {
43
44
45
46
47
48
49
	ADD {
		ATTRIBUTE("objectInstance", setObjectInstance);
		ATTRIBUTE("objectType", setObjectType);
		ATTRIBUTE("id", setPropertyId);
	}
}

50
void BACnetConfigurator::sensorGroup(BACnetSensorGroup &s, CFG_VAL config) {
51
	ADD {
52
		ATTRIBUTE("deviceInstance", setDeviceInstance);
53
	}
54
	s.setEntity(_bacClient.get());
55
56
57
}

void BACnetConfigurator::global(CFG_VAL config) {
Micha Müller's avatar
Micha Müller committed
58
	_bacClient = std::make_shared<BACnetClient>("BACnetClient");
59
60

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

63
64
65
	ADD {
		SETTING("address_cache") {
			address_cache = val.second.data();
66
			LOG(debug) << "  Address Cache: " << address_cache;
67
68
		}
		SETTING("interface") {
69
			interface = val.second.data();
70
			LOG(debug) << "  Interface " << interface;
71
72
		}
		SETTING("port") {
73
			port = stoul(val.second.data());
74
			LOG(debug) << "  Port " << port;
75
76
		}
		SETTING("timeout") {
77
			timeout = stoul(val.second.data());
78
			LOG(debug) << "  Timeout " << timeout;
79
80
		}
		SETTING("apdu_timeout") {
81
			apdu_timeout = stoul(val.second.data());
82
			LOG(debug) << "  apdu_timeout " << apdu_timeout;
83
84
		}
		SETTING("apdu_retries") {
85
			apdu_retries = stoul(val.second.data());
86
87
88
89
90
			LOG(debug) << "  apdu_retries " << apdu_retries;
		}
	}

	try {
91
		_bacClient->init(interface, address_cache, port, timeout, apdu_timeout, apdu_retries);
92
	} catch (const std::exception &e) {
93
		LOG(error) << "Could not initialize BACnetClient: " << e.what();
94
95
		_bacClient = nullptr;
		return;
96
	}
97
}
98
void BACnetConfigurator::printConfiguratorConfig(LOG_LEVEL ll) {
99
100
101
102
103
	if (_bacClient) {
		_bacClient->printConfig(ll, 8);
	} else {
		LOG_VAR(ll) << "        No BACClient present!";
	}
104
}