Harness::Harness(QObject *parent) : QObject(parent)
{
	settingsManager.loadSavedSettings();

	gui = new MainWindow;
	serialManager = new SerialManager;
	packetReceiver = new PacketReceiver;
	windDataAnalyzer = new WindDataAnalyzer;
	dataLogger = new DataLogger;
	systemTimer = new QTimer;
	batteryChargeCalculator = new BatteryChargeCalculator;
	loggingData = false;

	connect(serialManager, SIGNAL(onNewDataReady(QByteArray)), packetReceiver, SLOT(onNewDataReceived(QByteArray)));
	connect(serialManager, SIGNAL(serialPortError(QString)), this, SLOT(onSerialPortError(QString)));
	connect(packetReceiver, SIGNAL(validPacketReceived()), this, SLOT(onValidPacketReceived()));
	connect(packetReceiver, SIGNAL(invalidPacketReceived()), this, SLOT(onInvalidPacketReceived()));
	connect(gui, SIGNAL(connectSerialButtonClicked(QString)), this, SLOT(onConnectSerialButtonClicked(QString)));
	connect(gui, SIGNAL(saveDataLogButtonClicked()), this, SLOT(onSaveDataLogButtonClicked()));
	connect(gui, SIGNAL(startLoggingButtonClicked()), this, SLOT(onStartLoggingButtonClicked()));
	connect(gui, SIGNAL(clearLogButtonClicked()), this, SLOT(onClearLogButtonClicked()));
	connect(gui, SIGNAL(settingsChanged()), this, SLOT(onSettingsChanged()));
	connect(systemTimer, SIGNAL(timeout()), this, SLOT(onSystemTimerTimeout()));

	compassOffset = settingsManager.getSettings().compassOffset;
	loadGUIDefaultValues();
	gui->show();
	systemTimer->start(SYSTEM_TIMER_INTERVAL_MS);
}
int main(int argc, char *argv[])
{
	settingsManager.loadSavedSettings();
	QApplication a(argc, argv);
	Harness* harness = new Harness;

	return a.exec();
}