diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-09 10:51:32 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-09 10:51:32 +0200 |
commit | 2db4accd652a3a156046c373355535247b2ea7aa (patch) | |
tree | a5acf0ed02608ea36e2c0b5cd921bc0500fc2c6e /tracker-hatire | |
parent | 469371da434e1fcd1cbe51ce8b7e493ea7580a7f (diff) |
tracker/hatire: remove min length check duplication
The api callee already takes care of that so remove the "ok" argument.
Diffstat (limited to 'tracker-hatire')
-rwxr-xr-x | tracker-hatire/ftnoir_tracker_hat.cpp | 66 | ||||
-rwxr-xr-x | tracker-hatire/thread.cpp | 12 | ||||
-rwxr-xr-x | tracker-hatire/thread.hpp | 2 |
3 files changed, 31 insertions, 49 deletions
diff --git a/tracker-hatire/ftnoir_tracker_hat.cpp b/tracker-hatire/ftnoir_tracker_hat.cpp index 25f0b903..2dc35b3b 100755 --- a/tracker-hatire/ftnoir_tracker_hat.cpp +++ b/tracker-hatire/ftnoir_tracker_hat.cpp @@ -88,54 +88,46 @@ void hatire::data(double *data) { QMutexLocker l(&t.data_mtx); - bool ok = false; + QByteArray& data_read = t.send_data_read_nolock(); - QByteArray& data_read = t.send_data_read_nolock(ok); - - if (ok) + while (data_read.length() >= 30) { - while (data_read.length() >= 30) + //t.Log(data_read.toHex()); + // .Begin==0xAAAA .End==0x5555 + if (data_read[0] == Begin[0] && data_read[1] == Begin[1] && + data_read[28] == End[0] && data_read[29] == End[1]) { - //t.Log(data_read.toHex()); - // .Begin==0xAAAA .End==0x5555 - if (data_read[0] == Begin[0] && data_read[1] == Begin[1] && - data_read[28] == End[0] && data_read[29] == End[1]) - { - QDataStream stream(&data_read, QIODevice::ReadOnly); + QDataStream stream(&data_read, QIODevice::ReadOnly); - if (ts.bBigEndian) - stream.setByteOrder(QDataStream::BigEndian); - else - stream.setByteOrder(QDataStream::LittleEndian); + if (ts.bBigEndian) + stream.setByteOrder(QDataStream::BigEndian); + else + stream.setByteOrder(QDataStream::LittleEndian); - stream >> ArduinoData; + stream >> ArduinoData; - frame_cnt++; + frame_cnt++; - if (ArduinoData.Code <= 1000) - HAT = ArduinoData; - else - emit t.serial_debug_info(data_read.mid(4,24)) ; - data_read.remove(0, 30); - } + if (ArduinoData.Code <= 1000) + HAT = ArduinoData; else + emit t.serial_debug_info(data_read.mid(4,24)) ; + data_read.remove(0, 30); + } + else + { + // resync frame + int index = data_read.indexOf(Begin, 1); + if (index == -1) + { + index = data_read.length(); + } + + if (data_read.length() != 0) { - // resync frame - int index = data_read.indexOf(Begin, 1); - if (index == -1) - { - index = data_read.length(); - } emit t.serial_debug_info(data_read.mid(0,index)); - if (!ok) - { - data_read.clear(); - } - else - { - data_read.remove(0, index); - } + data_read.remove(0, index); CptError++; diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp index dbb146ee..e4ce8044 100755 --- a/tracker-hatire/thread.cpp +++ b/tracker-hatire/thread.cpp @@ -325,17 +325,7 @@ void hatire_thread::on_serial_read() portable::sleep(ms); } -QByteArray& hatire_thread::send_data_read_nolock(bool& ret) +QByteArray& hatire_thread::send_data_read_nolock() { - constexpr int packet_len = 30; - - if (data_read.length() < packet_len) - { - // we're requesting more than packet length to help resync the stream if needed - ret = false; - } - else - ret = true; - return data_read; } diff --git a/tracker-hatire/thread.hpp b/tracker-hatire/thread.hpp index 44866e51..1a3f2b09 100755 --- a/tracker-hatire/thread.hpp +++ b/tracker-hatire/thread.hpp @@ -132,7 +132,7 @@ public: ~hatire_thread() override; hatire_thread(); - QByteArray& send_data_read_nolock(bool& ret); + QByteArray& send_data_read_nolock(); void Log(const QString& message); |