data processing
This commit is contained in:
parent
e526ddbc05
commit
c6db7dc49e
101
main_window.cpp
101
main_window.cpp
@ -18,6 +18,9 @@ static bool check_exist(QString str) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTextStream receivefileStream;
|
||||||
|
|
||||||
|
|
||||||
void main_window::config_enable(bool ena) {
|
void main_window::config_enable(bool ena) {
|
||||||
portsComboBox->setEnabled(ena);
|
portsComboBox->setEnabled(ena);
|
||||||
stopbitsComboBox->setEnabled(ena);
|
stopbitsComboBox->setEnabled(ena);
|
||||||
@ -29,11 +32,18 @@ void main_window::config_enable(bool ena) {
|
|||||||
portOpenBtn->setText("open"), is_open = false;
|
portOpenBtn->setText("open"), is_open = false;
|
||||||
if (receivefile.isOpen())
|
if (receivefile.isOpen())
|
||||||
receivefile.close();
|
receivefile.close();
|
||||||
|
if (rawDataFile.isOpen())
|
||||||
|
rawDataFile.close();
|
||||||
} else {
|
} else {
|
||||||
portOpenBtn->setText("close"), is_open = true;
|
portOpenBtn->setText("close"), is_open = true;
|
||||||
auto filename = tmpFilenameEdit->text();
|
auto filename = tmpFilenameEdit->text();
|
||||||
receivefile.setFileName(filename);
|
receivefile.setFileName(filename);
|
||||||
receivefile.open(QIODevice::Append);
|
receivefile.open(QIODevice::Append);
|
||||||
|
receivefileStream.setDevice(&receivefile);
|
||||||
|
rawDataFile.setFileName(filename + "raw");
|
||||||
|
rawDataFile.open(QIODevice::Append);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -174,61 +184,78 @@ void main_window::open_port() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint64_t rest = 0;
|
|
||||||
static int cnt = 0;
|
static int cnt = 0;
|
||||||
static long long line_cnt = 0;
|
QByteArray first_frame;
|
||||||
QByteArray zero_finder;
|
bool first = true;
|
||||||
int zero_pos = -1;
|
|
||||||
int buf_cnt = 0;
|
|
||||||
int receive_cnt = 0;
|
|
||||||
|
|
||||||
void main_window::read_data() {
|
void main_window::read_data() {
|
||||||
auto data = port.readAll();
|
static int receive_num_cnt = 0;
|
||||||
|
static int receive_byte_cnt = 0;
|
||||||
static int val = 0;
|
static int val = 0;
|
||||||
if (zero_pos == -1) {
|
auto data = port.readAll();
|
||||||
if (zero_finder.size() < 10)
|
if (first) {
|
||||||
zero_finder += data;
|
if (data.length() < 10) {
|
||||||
if (zero_finder.size() < 10) {
|
first_frame += data;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
while (first_frame[0] != 0) {
|
||||||
|
first_frame.remove(0, 1);
|
||||||
|
}
|
||||||
int zero_cnt = 0;
|
int zero_cnt = 0;
|
||||||
|
do {
|
||||||
|
zero_cnt = 0;
|
||||||
|
while (first_frame[0] != 0) {
|
||||||
|
first_frame.remove(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (zero_finder[i] == 0) {
|
zero_cnt += first_frame[i] == 0 ? 1 : 0;
|
||||||
zero_cnt++;
|
|
||||||
zero_pos = i;
|
|
||||||
}
|
}
|
||||||
|
first_frame.remove(0, 1);
|
||||||
|
} while (zero_cnt != 0);
|
||||||
|
data = first_frame;
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
for (int i = 4; i < zero_finder.size(); i++) {
|
rawDataFile.write(data);
|
||||||
if (zero_cnt == 1) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
break;
|
if (receive_byte_cnt % 4 == 0) {
|
||||||
|
if (data[i] != 0) {
|
||||||
|
// TODO: raise error
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (zero_finder[i - 4] == 0)
|
receive_num_cnt++;
|
||||||
zero_cnt--;
|
int real_number = val;
|
||||||
if (zero_finder[i] == 0) {
|
if (real_number & 0x800000) {
|
||||||
zero_cnt++;
|
// negtive number
|
||||||
zero_pos = i;
|
real_number = -(~real_number & 0x7fffff + 1);
|
||||||
}
|
}
|
||||||
|
receivefileStream << real_number << " ";
|
||||||
|
double scaled = (double) real_number / (double) (0x7fffff) * 2.5;
|
||||||
|
lineChart.data->append((double) receive_byte_cnt / 1000.0, scaled);
|
||||||
|
while (lineChart.data->count() > 5000) {
|
||||||
|
// data more than 5000 second, remove first data
|
||||||
|
lineChart.data->remove(0);
|
||||||
}
|
}
|
||||||
|
val = 0;
|
||||||
for (int i = zero_pos+1; i < zero_finder.size(); i++) {
|
continue;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
val <<= 8;
|
||||||
|
val |= data[i];
|
||||||
|
receive_byte_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
asciiTextEdit->append(QString(data));
|
|
||||||
cnt += data.size();
|
|
||||||
QString new_text = QString(data.toHex(' ').toUpper()) + " ";
|
QString new_text = QString(data.toHex(' ').toUpper()) + " ";
|
||||||
hexTextEdit->moveCursor(QTextCursor::End);
|
hexTextEdit->moveCursor(QTextCursor::End);
|
||||||
hexTextEdit->insertPlainText(new_text);
|
hexTextEdit->insertPlainText(new_text);
|
||||||
auto val = hexTextEdit->toPlainText();
|
auto tmp = hexTextEdit->toPlainText();
|
||||||
receivefile.write(val.toUtf8());
|
if (tmp.length() > 1e3) {
|
||||||
if (hexTextEdit->toPlainText().length() > 1e3) {
|
hexTextEdit->setPlainText(tmp.last((int) 1e3));
|
||||||
hexTextEdit->clear();
|
hexTextEdit->moveCursor(QTextCursor::End);
|
||||||
asciiTextEdit->clear();
|
}
|
||||||
|
tmp = asciiTextEdit->toPlainText();
|
||||||
|
if (tmp.length() > 1e3) {
|
||||||
|
asciiTextEdit->setPlainText(tmp.last(int(1e3)));
|
||||||
|
asciiTextEdit->moveCursor(QTextCursor::End);
|
||||||
}
|
}
|
||||||
lineChart.data->append(0, 0.5);
|
|
||||||
lineChart.data->append(0.5, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ private:
|
|||||||
bool is_open = false;
|
bool is_open = false;
|
||||||
QSerialPort port;
|
QSerialPort port;
|
||||||
QFile receivefile;
|
QFile receivefile;
|
||||||
|
QFile rawDataFile;
|
||||||
|
|
||||||
QWidget *centralwidget;
|
QWidget *centralwidget;
|
||||||
QHBoxLayout *horizontalLayout;
|
QHBoxLayout *horizontalLayout;
|
||||||
@ -64,8 +65,6 @@ private:
|
|||||||
QChartView *plotChartView;
|
QChartView *plotChartView;
|
||||||
|
|
||||||
QMessageBox box;
|
QMessageBox box;
|
||||||
// QChart* chart;
|
|
||||||
// QLineSeries* linedata;
|
|
||||||
GLineChart lineChart;
|
GLineChart lineChart;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user