Example #1
0
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();
}
Example #2
0
int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);
	Arguments arg;

	usage(arg);
	if (arg.contains("h")) {
		arg.help();
		exit(0);
	}

	QsLogging::Level logLevel = QsLogging::InfoLevel;
	if (arg.contains("d"))
		logLevel = static_cast<QsLogging::Level>(arg.value("d").toInt());
	initLogger(logLevel);

	QDBusConnection dbus = QDBusConnection::systemBus();
	if (arg.contains("dbus")) {
		QString dbusAddress = arg.value("dbus");
		if (dbusAddress != "system") {
			if (dbusAddress == "session")
				dbus = QDBusConnection::sessionBus();
			else
				dbus = QDBusConnection::connectToBus(dbusAddress, "modbus_tcp");
		}
	}

	if (!dbus.isConnected()) {
		QLOG_ERROR() << "DBus connection failed.";
		exit(EXIT_FAILURE);
	}

	App dbusModbusApp(dbus);

	return app.exec();
}