1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-22 07:52:12 +01:00
stac 7195862d77 build: Move openpilotgcs into its own subdirectory
This will allow us to build a parent project for
qt-creator that sits above both openpilotgcs and
uavobjgenerator so that we can build both projects
at the same time.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2528 ebee16cc-31ac-478f-84a7-5cbb03baadba
2011-01-22 17:40:26 +00:00

88 lines
2.1 KiB
C++

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QThread>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <qextserialport.h>
#include <iostream>
class pollSerialPort : public QThread
{
public:
pollSerialPort(QString dn, QString fn) : device(dn), outFile(fn)
{
};
void run()
{
QByteArray dat;
//const char framingRaw[16] = {7,9,3,15,193,130,150,10,7,9,3,15,193,130,150,10};
const char framingRaw[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
QByteArray framing(framingRaw,16);
PortSettings Settings;
Settings.BaudRate=BAUD115200;
Settings.DataBits=DATA_8;
Settings.Parity=PAR_NONE;
Settings.StopBits=STOP_1;
Settings.FlowControl=FLOW_OFF;
Settings.Timeout_Millisec=500;
QextSerialPort serialPort(device, Settings);
serialPort.open(QIODevice::ReadOnly);
QFile file(outFile);
if( !file.open( QIODevice::WriteOnly ) )
{
qDebug() << "Failed to open file: " << outFile;
return;
}
QTextStream ts( &file );
while(1)
{
dat = serialPort.read(500);
if(dat.contains(framing))
{
int start = dat.indexOf(framing);
int count = *((int *) (dat.data() + start+16));
qDebug() << "Found frame start at " << start << " count " << count;
}
else if (dat.size() == 0)
qDebug() << "No data";
else
qDebug() << "No frame start";
ts << dat;
usleep(100000);
}
};
protected:
QString device;
QString outFile;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString device;
QString log;
if(argc < 2)
device = "/dev/tty.usbserial-000014FAB";
else
device = QString(argv[1]);
if(argc < 3)
log = "log.dat";
else
log = QString(argv[2]);
pollSerialPort thread(device, log);
thread.start();
return a.exec();
}