-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
82 lines (69 loc) · 2.22 KB
/
main.cpp
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
#include <unistd.h>
#include <QCoreApplication>
#include <velib/qt/v_busitems.h>
#include "busitem_cons.h"
#include "qwacs.h"
#include "QsLog.h"
#include "arguments.h"
QsLogging::Logger& logger = QsLogging::Logger::instance();
void initLogger(QsLogging::Level logLevel)
{
// init the logging mechanism
QsLogging::DestinationPtr debugDestination(
QsLogging::DestinationFactory::MakeDebugOutputDestination() );
logger.addDestination(debugDestination);
QLOG_INFO() << "dbus_qwacs" << "v" VERSION << "started";
QLOG_INFO() << "Built with Qt" << QT_VERSION_STR << "running on" << qVersion();
QLOG_INFO() << "Built on" << __DATE__ << "at" << __TIME__;
logger.setLoggingLevel(logLevel);
}
void usage(Arguments & arg)
{
arg.addArg("-h", "Print this help");
arg.addArg("-d level", "Debug level: 0=TRACE, 1=DEBUG, 2=INFO...");
arg.addArg("-g ip address", "IP address of gateway");
arg.addArg("--dbus address", "dbus address or 'session' or 'system'");
}
int main(int argc, char *argv[])
{
/*
* Description:
*
*This program tries to find the TIM gateway from Quby makeing use of Upnp.
*After this it will fetch the information from all sensors and publish it
*on the dbus
*
*UPNP code: https://garage.maemo.org/frs/download.php/8365/libbrisa_0.1.1.tar.gz
*/
QCoreApplication app(argc, argv);
Arguments arg;
usage(arg);
if (arg.contains("h")) {
arg.help();
exit(0);
}
initLogger(QsLogging::InfoLevel);
if (arg.contains("d"))
logger.setLoggingLevel((QsLogging::Level)arg.value("d").toInt());
if (arg.contains("dbus"))
VBusItems::setDBusAddress(arg.value("dbus"));
else
VBusItems::setConnectionType(QDBusConnection::SystemBus);
QDBusConnection dbus = VBusItems::getConnection("settings");
if (!dbus.isConnected()) {
QLOG_ERROR() << "DBus connection failed.";
exit(EXIT_FAILURE);
}
// Wait for local settings to become available on the DBus
QLOG_INFO() << "Wait for local settings on DBus... ";
BusItemCons settings("com.victronenergy.settings", "/Settings", dbus);
QVariant reply = settings.getValue();
while (reply.isValid() == false) {
reply = settings.getValue();
usleep(500000);
QLOG_INFO() << "Wait...";
}
QLOG_INFO() << "Local settings found!";
Qwacs qwacs(&app, arg.value("g"));
return app.exec();
}