BACnetConfigurator.cpp 3.34 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
43
44
45
46
47
48
49
50
51
52
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 {
53
		ATTRIBUTE("deviceInstance", setDeviceInstance);
54
	}
55
	s.setEntity(_bacClient.get());
56
57
58
}

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

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

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

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