summaryrefslogtreecommitdiffhomepage
path: root/tracker-hatire/ftnoir_tracker_hat.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-04 07:22:13 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-04 07:22:13 +0200
commit7f1f658fec4a1f50d78dc8b8c4efe22bb6a9636b (patch)
tree74fb6dd72ef461e57d007676a72b34777e3e0309 /tracker-hatire/ftnoir_tracker_hat.cpp
parent38dd6e55d20adfd830d834c394fc6ce7373a4805 (diff)
tracker/hatire: remove race
Don't prepend existing remaining data racing with add new data. Expose the lock as a public member.
Diffstat (limited to 'tracker-hatire/ftnoir_tracker_hat.cpp')
-rwxr-xr-x[-rw-r--r--]tracker-hatire/ftnoir_tracker_hat.cpp72
1 files changed, 38 insertions, 34 deletions
diff --git a/tracker-hatire/ftnoir_tracker_hat.cpp b/tracker-hatire/ftnoir_tracker_hat.cpp
index 6b76ddba..48585f6c 100644..100755
--- a/tracker-hatire/ftnoir_tracker_hat.cpp
+++ b/tracker-hatire/ftnoir_tracker_hat.cpp
@@ -85,46 +85,50 @@ void hatire::send_serial_command(const QByteArray& x)
//
void hatire::data(double *data)
{
- QByteArray dataRead(t.flush_data_read());
-
- while (dataRead.length() >= 30)
{
- t.Log(dataRead.toHex());
- if (dataRead.startsWith(Begin) && dataRead.mid(28,2) == End)
- { // .Begin==0xAAAA .End==0x5555
- QDataStream datastream(dataRead.left(30));
- if (ts.bBigEndian) datastream.setByteOrder(QDataStream::BigEndian );
- else datastream.setByteOrder(QDataStream::LittleEndian);
- datastream>>ArduinoData;
- frame_cnt++;
- if (ArduinoData.Code <= 1000)
- {
- HAT=ArduinoData;
- new_frame=true;
+ QMutexLocker l(&t.data_mtx);
+
+ QByteArray dataRead(t.flush_data_read_nolock());
+
+ while (dataRead.length() >= 30)
+ {
+ t.Log(dataRead.toHex());
+ if (dataRead.startsWith(Begin) && dataRead.mid(28,2) == End)
+ { // .Begin==0xAAAA .End==0x5555
+ QDataStream datastream(dataRead.left(30));
+ if (ts.bBigEndian) datastream.setByteOrder(QDataStream::BigEndian );
+ else datastream.setByteOrder(QDataStream::LittleEndian);
+ datastream>>ArduinoData;
+ frame_cnt++;
+ if (ArduinoData.Code <= 1000)
+ {
+ HAT=ArduinoData;
+ new_frame=true;
+ }
+ else
+ {
+ emit t.serial_debug_info(dataRead.mid(4,24)) ;
+ }
+ dataRead.remove(0,30);
}
else
{
- emit t.serial_debug_info(dataRead.mid(4,24)) ;
- }
- dataRead.remove(0,30);
+ bool ok = true;
+ // resynchro trame
+ int index = dataRead.indexOf(Begin);
+ if (index==-1) {
+ ok = false;
+ index=dataRead.length();
+ }
+ emit t.serial_debug_info(dataRead.mid(0,index)) ;
+ dataRead.remove(0,index);
+ CptError++;
+ qDebug() << QTime::currentTime() << "hatire resync stream" << "index" << index << "ok" << ok;
+ }
}
- else
- {
- bool ok = true;
- // resynchro trame
- int index = dataRead.indexOf(Begin);
- if (index==-1) {
- ok = false;
- index=dataRead.length();
- }
- emit t.serial_debug_info(dataRead.mid(0,index)) ;
- dataRead.remove(0,index);
- CptError++;
- qDebug() << QTime::currentTime() << "hatire resync stream" << "index" << index << "ok" << ok;
- }
- }
- t.prepend_unread_data(dataRead);
+ t.prepend_unread_data_nolock(dataRead);
+ }
if (CptError > 50)
{