LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / experimental / SerialLogger / main.cpp
blob1d4e651c9d9c86e3d627e6547370568c3a3ebfaa
1 #include <QtCore/QCoreApplication>
2 #include <QDebug>
3 #include <QThread>
4 #include <QString>
5 #include <QFile>
6 #include <QTextStream>
7 #include <qextserialport.h>
9 #include <iostream>
11 class pollSerialPort : public QThread {
12 public:
13 pollSerialPort(QString dn, QString fn) : device(dn), outFile(fn)
14 {};
16 void run()
18 QByteArray dat;
19 // const char framingRaw[16] = {7,9,3,15,193,130,150,10,7,9,3,15,193,130,150,10};
20 const char framingRaw[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
21 QByteArray framing(framingRaw, 16);
23 PortSettings Settings;
25 Settings.BaudRate = BAUD115200;
26 Settings.DataBits = DATA_8;
27 Settings.Parity = PAR_NONE;
28 Settings.StopBits = STOP_1;
29 Settings.FlowControl = FLOW_OFF;
30 Settings.Timeout_Millisec = 500;
32 QextSerialPort serialPort(device, Settings);
33 serialPort.open(QIODevice::ReadOnly);
35 QFile file(outFile);
36 if (!file.open(QIODevice::WriteOnly)) {
37 qDebug() << "Failed to open file: " << outFile;
38 return;
41 QTextStream ts(&file);
43 while (1) {
44 dat = serialPort.read(500);
45 if (dat.contains(framing)) {
46 int start = dat.indexOf(framing);
47 int count = *((int *)(dat.data() + start + 16));
48 qDebug() << "Found frame start at " << start << " count " << count;
49 } else if (dat.size() == 0) {
50 qDebug() << "No data";
51 } else {
52 qDebug() << "No frame start";
54 ts << dat;
55 usleep(100000);
59 protected:
60 QString device;
61 QString outFile;
64 int main(int argc, char *argv[])
66 QCoreApplication a(argc, argv);
67 QString device;
68 QString log;
70 if (argc < 2) {
71 device = "/dev/tty.usbserial-000014FAB";
72 } else {
73 device = QString(argv[1]);
76 if (argc < 3) {
77 log = "log.dat";
78 } else {
79 log = QString(argv[2]);
82 pollSerialPort thread(device, log);
83 thread.start();
84 return a.exec();