Add GPS Parsing
This commit is contained in:
@@ -1,33 +1,78 @@
|
||||
#include "FaultManager.hpp"
|
||||
|
||||
FaultManager::FaultManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
bool res;
|
||||
|
||||
res = OpenDatabase();
|
||||
|
||||
if (!res) {
|
||||
qCritical() << "Failed to open database connection.";
|
||||
exit(15);
|
||||
}
|
||||
|
||||
res = OpenSerial();
|
||||
|
||||
if (!res) {
|
||||
qCritical() << "Failure to open GPS serial device.";
|
||||
exit(16);
|
||||
}
|
||||
|
||||
StartGPS();
|
||||
}
|
||||
|
||||
FaultManager::~FaultManager()
|
||||
{
|
||||
db.close();
|
||||
gps->stopUpdates();
|
||||
serial->close();
|
||||
}
|
||||
|
||||
bool FaultManager::OpenDatabase()
|
||||
{
|
||||
db = QSqlDatabase::addDatabase("QMYSQL");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("FaultDatabase");
|
||||
db.setUserName("user");
|
||||
db.setPassword("faultfinder");
|
||||
bool success = db.open();
|
||||
|
||||
if (!success) {
|
||||
qCritical() << "Failed to open database connection.";
|
||||
exit(15);
|
||||
}
|
||||
return db.open();
|
||||
}
|
||||
|
||||
FaultManager::~FaultManager()
|
||||
bool FaultManager::OpenSerial()
|
||||
{
|
||||
db.close();
|
||||
serial = new QSerialPort();
|
||||
serial->setPortName("ttyUSB0");
|
||||
serial->setBaudRate(QSerialPort::Baud4800);
|
||||
serial->setDataBits(QSerialPort::Data8);
|
||||
serial->setParity(QSerialPort::NoParity);
|
||||
serial->setStopBits(QSerialPort::OneStop);
|
||||
serial->setFlowControl(QSerialPort::NoFlowControl);
|
||||
return serial->open(QIODevice::ReadOnly);
|
||||
}
|
||||
|
||||
void FaultManager::StartGPS()
|
||||
{
|
||||
gps = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMode);
|
||||
gps->setDevice((QIODevice *)serial);
|
||||
gps->startUpdates();
|
||||
}
|
||||
|
||||
void FaultManager::SaveImage()
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
||||
// Get GPS Location
|
||||
QGeoPositionInfo position = gps->lastKnownPosition(true);
|
||||
QGeoCoordinate coorinate = position.coordinate();
|
||||
|
||||
qInfo() << coorinate.isValid();
|
||||
qInfo() << coorinate.longitude();
|
||||
qInfo() << coorinate.latitude();
|
||||
qInfo() << coorinate.altitude();
|
||||
|
||||
// Save Image to Filesystem
|
||||
//QSaveFile
|
||||
|
||||
// Save to Database
|
||||
query.exec("INSERT");
|
||||
//query.exec("INSERT");
|
||||
}
|
||||
Reference in New Issue
Block a user