-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.cpp
64 lines (52 loc) · 1.81 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
#include <QCoreApplication>
#include <veutil/qt/ve_qitems_dbus.hpp>
#include <veutil/qt/ve_qitem_exported_dbus_services.hpp>
#include "app.h"
#include "arguments.h"
#include "nostorage_qitem_producer.h"
#include "QsLog.h"
void initLogger(QsLogging::Level logLevel)
{
QsLogging::Logger &logger = QsLogging::Logger::instance();
QsLogging::DestinationPtr debugDestination(
QsLogging::DestinationFactory::MakeDebugOutputDestination() );
logger.addDestination(debugDestination);
logger.setIncludeTimestamp(false);
QLOG_INFO() << "dbus_modbustcp" << "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("--dbus", "D-Bus connection: session, system, ...");
arg.addArg("-p", "Modbus TCP port");
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Arguments arg;
usage(arg);
if (arg.contains("h")) {
arg.help();
exit(0);
}
int tcpPort = 502;
if (arg.contains("p"))
tcpPort = arg.value("p").toInt();
QsLogging::Level logLevel = QsLogging::InfoLevel;
if (arg.contains("d"))
logLevel = static_cast<QsLogging::Level>(arg.value("d").toInt());
initLogger(logLevel);
QString dbusConnection = arg.contains("dbus") ? arg.value("dbus") : "system";
NostorageQItemProducer producer(VeQItems::getRoot(), "sub", true, false);
producer.setAutoCreateItems(false);
producer.open(dbusConnection);
VeQItemProducer pub(VeQItems::getRoot(), "pub");
VeQItemExportedDbusServices publisher(pub.services());
publisher.open(dbusConnection);
App dbusModbusApp(producer.services(), pub.services(), tcpPort);
return app.exec();
}