Esempio n. 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();
}
Esempio n. 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();
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	QCoreApplication::setApplicationName("Vincent Tim");
	QCoreApplication::setApplicationVersion("1.2");
#ifdef Q_OS_WIN
	QTextCodec::setCodecForLocale(QTextCodec::codecForName("IBM 850"));
#endif
	
#ifdef TESTS_ENABLED
	qDebug() << "Running tests...";
	
	Collect c("tests/tim/files");
	c.textureData("tim");
#endif

	Arguments args;

	if (args.help() || args.paths().isEmpty()) {
		args.showHelp();
	} else {
		foreach (const QString &path, args.paths()) {
			TextureFile *texture;

			if (args.inputFormat(path) == args.outputFormat()) {
				qWarning() << "Error: input and output formats are not different";
				a.exit(1);
			}

			QFile f(path);
			if (f.open(QIODevice::ReadOnly)) {

				if (!args.analysis()) {
					texture = TextureFile::factory(args.inputFormat(path));

					if (texture->open(f.readAll())) {
						if (TextureFile::supportedTextureFormats().contains(args.outputFormat(), Qt::CaseInsensitive)) {
							if (!toTexture(texture, path, args)) {
								break;
							}
						} else if (TextureFile::supportedTextureFormats().contains(args.inputFormat(path), Qt::CaseInsensitive)) {
							fromTexture(texture, path, args);
						} else {
							qWarning() << "Error: input format or output format must be a supported texture format" << TextureFile::supportedTextureFormats();
							a.exit(1);
						}
					} else {
						qWarning() << "Error: Cannot open Texture file";
						a.exit(1);
					}

					f.close();

					delete texture;
				} else { // Search tim files
					QList<PosSize> positions = TimFile::findTims(&f);

					int num = 0;
					foreach (const PosSize &pos, positions) {
						texture = new TimFile();
						f.seek(pos.first);
						if (texture->open(f.read(pos.second))) {
							if (args.outputFormat().compare("tim", Qt::CaseInsensitive) == 0) {
								if (!texture->saveToFile(args.destination(path, num))) {
									qWarning() << "Error: Cannot save Texture file from" << QDir::toNativeSeparators(path) << "to" << args.destination(path, num);
									continue;
								} else {
									printf("%s\n", qPrintable(QDir::toNativeSeparators(args.destination(path, num))));
								}
							} else {
								fromTexture(texture, path, args, num);
							}
							num++;
						} else {
							qWarning() << "Error: Cannot open Texture file from" << QDir::toNativeSeparators(path);
							a.exit(1);
						}
						delete texture;
					}
				}
			} else {
				qWarning() << "Error: cannot open file" << QDir::toNativeSeparators(path) << f.errorString();
				a.exit(1);
			}
		}