Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
smarttowel committed Nov 15, 2018
1 parent fa26754 commit e7df218
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 158 deletions.
56 changes: 56 additions & 0 deletions EscReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2011 Aliaksei Stratsilatau <[email protected]>
*
* This file is part of the UAV Open System Project
* http://www.uavos.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
*
*/
#include "EscReader.h"
//=============================================================================
EscReader::EscReader(QObject *parent)
: QObject(parent), _escaped()
{}
void EscReader::push(const QByteArray ba)
{
data.append(ba);
while(!data.isEmpty()){
uint cnt=readEscaped();
if(!cnt)continue;
emit packet_read(QByteArray((const char*)esc_rx,cnt));
//qDebug("pkt");
}
}
//_escaped override
uint EscReader::read(uint8_t *buf,uint sz)
{
if(data.isEmpty())return 0;
if((int)sz>data.size())sz=data.size();
memcpy(buf,data.data(),sz);
data=data.mid(sz);
return sz;
}
bool EscReader::write_byte(const uint8_t v)
{
Q_UNUSED(v);
return true;
}
void EscReader::escError(void)
{
//qWarning("ESC reader error");
}
//=============================================================================
44 changes: 44 additions & 0 deletions EscReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2011 Aliaksei Stratsilatau <[email protected]>
*
* This file is part of the UAV Open System Project
* http://www.uavos.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef EscReader_H
#define EscReader_H
#include <QtCore>
#include "escaped.h"
//=============================================================================
class EscReader: public QObject, public _escaped
{
Q_OBJECT
public:
explicit EscReader(QObject *parent=0);
void push(const QByteArray ba);
//_escaped override
uint read(uint8_t *buf,uint sz);
bool write_byte(const uint8_t v);
void escError(void);
private:
QByteArray data;
signals:
void packet_read(const QByteArray &ba);
};
//=============================================================================
#endif
4 changes: 2 additions & 2 deletions bbreader.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RCC_DIR = $$OBJ_DIR
SOURCES += \
mainwindow.cpp \
bbreaderplugin.cpp \
escparser.cpp
EscReader.cpp

INCLUDEPATH += /usr/share/uavos/gcu/sdk/inc/
INCLUDEPATH += ../../share/tcpclient
Expand All @@ -35,7 +35,7 @@ HEADERS += \
/usr/share/uavos/gcu/sdk/inc/plugin_interface.h \
mainwindow.h \
bbreaderplugin.h \
escparser.h
EscReader.h

FORMS += \
mainwindow.ui
76 changes: 0 additions & 76 deletions escparser.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions escparser.h

This file was deleted.

51 changes: 15 additions & 36 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QFileDialog>

#include <QMandala.h>
#include "escparser.h"
#include "EscReader.h"

#include <iostream>

Expand All @@ -27,53 +27,32 @@ void MainWindow::on_pushButton_clicked()
if(filename.isEmpty())
return;

ui->labelErrorsCount->setText(QString("Errors: %1").arg(0));
ui->labelPacketsCount->setText(QString("Packets: %1").arg(0));

QFile file(filename);
file.open(QIODevice::ReadOnly);

EscParser parser;
QByteArray data = file.readAll();
EscParser::DataBuffer dataBuffer;
std::copy(data.begin(), data.end(), std::back_inserter(dataBuffer));
EscReader reader;
QMandalaItem m(nullptr, true);
connect(&reader, &EscReader::packet_read, &m, &QMandalaItem::downlinkReceived);

m.rec->setRecording(true);

var->rec->setRecording(true);
int errorsCount = 0;
int packetsCount = 0;
int packetsMeasure = 0;
auto tp1 = std::chrono::high_resolution_clock::now();
while(true)
size_t bytesReaded = 0;
while(!file.atEnd())
{
EscParser::DataBuffer packet;
auto result = parser.extractData(dataBuffer, packet);
if(result == EscParser::erDataEnd)
break;
else if(result == EscParser::erCrcError || result == EscParser::erUnknownError)
errorsCount++;
else if(result == EscParser::erOk)
{
if(packet[0] == idx_downstream)
{
packetsCount++;
packetsMeasure++;
QByteArray ba;
std::copy(packet.begin(), packet.end(), std::back_inserter(ba));
mandala->downlinkReceived(ba);
}
}
QByteArray data = file.read(512);
bytesReaded += data.size();
reader.push(data);

auto tp2 = std::chrono::high_resolution_clock::now();
if(std::chrono::duration_cast<std::chrono::milliseconds>(tp2 - tp1).count() > 100)
{
tp1 = tp2;
qApp->processEvents();
packetsMeasure = 0;
}
ui->labelErrorsCount->setText(QString("Errors: %1").arg(errorsCount));
ui->labelPacketsCount->setText(QString("Packets: %1").arg(packetsCount));
ui->labelBytes->setText(QString("Bytes processed: %1/%2").arg(file.size() - dataBuffer.size()).arg(file.size()));
ui->labelBytes->setText(QString("Bytes processed: %1/%2").arg(bytesReaded).arg(file.size()));
}
var->rec->setRecording(false);
var->rec->close();
m.rec->setRecording(false);
m.rec->close();
ui->labelBytes->setText("FINISHED");
}
22 changes: 4 additions & 18 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>591</width>
<height>281</height>
<width>608</width>
<height>231</height>
</rect>
</property>
<property name="windowTitle">
<string>BlackBox Reader</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item>
<widget class="QLabel" name="labelErrorsCount">
<property name="text">
<string>Errors: 0</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelPacketsCount">
<property name="text">
<string>Packets: 0</string>
</property>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<item>
<widget class="QLabel" name="labelBytes">
<property name="text">
Expand All @@ -53,7 +39,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>591</width>
<width>608</width>
<height>31</height>
</rect>
</property>
Expand Down

0 comments on commit e7df218

Please sign in to comment.