Permalink
Browse files

implement threading

... and lots of cleanup necessary to do it.
  • Loading branch information...
resfilter committed Feb 2, 2016
1 parent 7ed83ca commit ebae2cec682f16f4629e504fb2460eb79ca97f05
Showing with 3,997 additions and 3,568 deletions.
  1. +9 −0 CHANGELOG.txt
  2. +19 −23 analysis.cpp
  3. +3 −4 analysis.h
  4. +8 −0 autospark.cpp
  5. +8 −0 autospark.h
  6. +111 −4 patches.cpp → bin_file.cpp
  7. +47 −0 bin_file.h
  8. +3 −3 config.h
  9. +148 −193 controls.cpp
  10. +228 −0 datalog.cpp
  11. +68 −13 parser.h → datalog.h
  12. +71 −64 parser.cpp → datalog_parser.cpp
  13. +382 −381 datastream.cpp
  14. +178 −141 datastream.h
  15. +35 −0 datastream_control.cpp
  16. +226 −0 datastream_eventloop.cpp
  17. +41 −2 debuglog_window.cpp
  18. +14 −5 debuglog_window.h
  19. +8 −1 debuglog_window.ui
  20. +11 −7 eehack.pro
  21. +5 −5 eehack.pro.user
  22. +0 −349 eventloop.cpp
  23. +15 −15 flash.cpp
  24. +310 −316 flash_routine.cpp
  25. +49 −6 flashprogress.cpp
  26. +12 −1 flashprogress.h
  27. +4 −4 flashprogress.ui
  28. +53 −57 graphing.cpp
  29. +14 −25 logfile.cpp
  30. +0 −4 main.cpp
  31. +490 −275 mainwindow.cpp
  32. +49 −44 mainwindow.h
  33. +1,054 −1,095 mainwindow.ui
  34. +15 −36 mode3.cpp
  35. +131 −101 mode4.cpp
  36. +90 −0 safetypes.cpp
  37. +59 −0 safetypes.h
  38. +0 −349 serial.cpp
  39. +3 −3 settings.cpp
  40. +26 −42 tests.cpp
View
@@ -1,3 +1,12 @@
4.4
New threaded model insanely fast UI response and consistent datalogging
Reworked serial comms for optimal performance
Enabled many features to be used while connected
New "Info" screen on extended
4.3:
Internal transitional release into threading
4.2:
Improve flash write checksum verification
Major update to how timing is handled for improved stability
View
@@ -5,27 +5,27 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "datastream.h"
#include "parser.h"
#include "datalog.h"
#include "config.h"
#include "analysis.h"
//--------------------------------------------
void mainWindow::on_analyzeDataBtn_clicked() {
if(connection_state != STATE_DISCONNECTED) return;
if(aldl->oldest_packet() == NULL) {
if(control->is_connected() == false) return;
if(log->is_data() == false) {
info_dialog("No data to analyze.\nUse the LOAD button on the MAIN page to load log data.");
return;
}
anl->reset_analyzer();
lock_connection(true);
ui->analyzeDataBtn->setEnabled(false);
QProgressDialog progress("Analyzing data...","ABORT",0,aldl->n_packets() / 2);
QProgressDialog progress("Analyzing data...","ABORT",0,log->n_packets() / 2);
progress.setWindowModality(Qt::WindowModal);
// iterate
packet *x = aldl->oldest_packet();
packet *x = log->oldest_packet();
while(x->next != NULL) {
anl->analyze_segment(x);
x = x->next;
@@ -34,7 +34,7 @@ void mainWindow::on_analyzeDataBtn_clicked() {
}
draw_analysis_results(); // set fields
progress.setValue(aldl->n_packets() / 2);
progress.setValue(log->n_packets() / 2);
ui->analyzeDataBtn->setEnabled(true);
@@ -84,7 +84,6 @@ void fcell::add_data(float value) {
//--------------------------------------------
analysis::analysis() {
parse_record = new ee_parser();
min_cooltmp = 50;
min_timestamp = 60;
knock_display = new QGraphicsScene;
@@ -130,12 +129,11 @@ void analysis::reset_analyzer() {
}
void analysis::analyze_segment(packet *p) {
parse_data = p; // move iterator
parse_record->data = parse_data->data; // move parser
parse_record = p;
// bail if out of global thresholds
if(parse_record->get_cooltmp() < min_cooltmp) return;
if(parse_data->timestamp < min_timestamp * 1000) return;
if(parse_record->timestamp < min_timestamp * 1000) return;
if(parse_record->get_rpm() < 200) return; // eng probably not running
// run various analyzers
@@ -295,14 +293,14 @@ void analysis::analyze_wb_afr() {
}
float current_target;
if(wblag == true) { // search back
if(parse_data->prev != NULL &&
parse_data->prev->prev != NULL &&
parse_data->prev->prev->prev != NULL) { // there is a record
quint64 current_time = parse_data->timestamp;
quint64 previous_time = parse_data->prev->prev->prev->timestamp;
if(parse_record->prev != NULL &&
parse_record->prev->prev != NULL &&
parse_record->prev->prev->prev != NULL) { // there is a record
quint64 current_time = parse_record->timestamp;
quint64 previous_time = parse_record->prev->prev->prev->timestamp;
if(previous_time > current_time - 250) {
ee_parser prev(parse_data->prev->prev->prev->data);
current_target = prev.get_afr_target(); // use prev target
packet *prev = parse_record->prev->prev->prev;
current_target = prev->get_afr_target(); // use prev target
} else { // use current target
current_target = parse_record->get_afr_target();
}
@@ -359,13 +357,11 @@ void analysis::add_knock_point(int rpm, int map, int count, bool wot, int spark,
}
void analysis::analyze_knock() {
if(parse_data->prev != NULL) { // need a previous event to check for incremented knock count
parse_record->data = parse_data->prev->data;
int prev_knock = parse_record->get_kcount();
float prev_timestamp = parse_data->prev->timestamp;
parse_record->data = parse_data->data;
if(parse_record->prev != NULL) { // need a previous event to check for incremented knock count
int prev_knock = parse_record->prev->get_kcount();
float prev_timestamp = parse_record->prev->timestamp;
int current_knock = parse_record->get_kcount();
float current_timestamp = parse_data->timestamp;
float current_timestamp = parse_record->timestamp;
if(current_knock > prev_knock &&
current_timestamp - prev_timestamp < 500) { // reject large rec gap
if(total_knock_events >= 800) return; // bail if tons of records
View
@@ -3,7 +3,7 @@
#include "config.h"
#include "settings.h"
#include "parser.h"
#include "datalog.h"
#include <QGraphicsScene>
@@ -22,7 +22,7 @@ class fcell { // floating point analysis
float average_accumulator;
};
class analysis : public ee_parser {
class analysis {
public:
analysis();
void reset_analyzer();
@@ -62,8 +62,7 @@ class analysis : public ee_parser {
// blm avg
fcell blm[19][3]; // 0=rpm 1=map 2=trim
private:
ee_parser *parse_record;
packet *parse_data;
packet *parse_record; // current working record
// internal analyzers
void analyze_o2();
void analyze_knock();
View
@@ -27,6 +27,14 @@ int autospark::get_spk_mod(int rpm, int map) {
return spark_matrix[rpm_cell][map_cell];
}
void autospark::recv_new_sample(packet *pkt, datastream_control *control) {
int aspkadvance = get_spk_mod(pkt->get_rpm(),pkt->get_map());
int m4spark = control->m4_get_spark();
if(aspkadvance != m4spark) {
emit(send_new_advance(aspkadvance));
}
}
int autospark::select_cell(int range, int cells, float data) {
float interval = range / cells;
int cell = floor((data/(float)range)*(float(range)/interval));
View
@@ -2,6 +2,8 @@
#define AUTOSPARK_H
#include <QDialog>
#include "datalog.h"
#include "datastream.h"
namespace Ui {
class autospark;
@@ -16,6 +18,12 @@ class autospark : public QDialog
~autospark();
int get_spk_mod(int rpm, int map);
public slots:
void recv_new_sample(packet *pkt, datastream_control *control);
signals:
void send_new_advance(int);
private slots:
void on_as_cell_1_1_valueChanged(int arg1);
void on_as_cell_1_2_valueChanged(int arg1);
@@ -3,18 +3,119 @@
#include <QtDebug>
#include "datastream.h"
#include "parser.h"
#include "datalog.h"
#include "config.h"
#include "bin_file.h"
// patch details
#define PATCH_VERSION_BYTE 0x3CB3
bin_file::bin_file() {
// zero out the bin
for(int x=0x00;x<=0xFFFF;x++) {
eside[x] = 0x00;
tside[x] = 0x00;
}
}
void bin_file::zero_ram() {
for(int x=0;x<0x0E00;x++) { // before aux eeprom
tside[x] = 0x00;
eside[x] = 0x00;
}
for(int x=0x1001;x<0x2000;x++) { // between eeprom and main eeprom
tside[x] = 0x00;
eside[x] = 0x00;
}
}
bool bin_file::test_checksum(byte *data) {
quint64 temp_sum = 0;
for(int x=0x2018;x<=0xffff;x++) temp_sum += data[x];
quint16 t_sum = (quint16)temp_sum;
byte low_byte = t_sum & 0xFF;
byte high_byte = t_sum >> 8;
if(data[0x2015] == high_byte &&
data[0x2016] == low_byte) return true;
return false;
}
bool bin_file::test_checksum() {
if(test_checksum(tside) == false) return false;
if(test_checksum(eside) == false) return false;
return true;
}
void bin_file::reset_checksums() {
set_checksum(tside);
set_checksum(eside);
}
bool bin_file::set_checksum(byte *data) {
quint64 temp_sum = 0;
for(int x=0x2018;x<=0xffff;x++) temp_sum += data[x];
quint16 t_sum = (quint16)temp_sum;
byte low_byte = t_sum & 0xFF;
byte high_byte = t_sum >> 8;
data[0x2015] = high_byte;
data[0x2016] = low_byte;
return true;
}
bool bin_file::load_file(QString path) {
QFile f(path);
if(f.exists() == false) return false;
f.open( QIODevice::ReadOnly );
if(f.isReadable() == false) { // can't open
return false;
}
QByteArray unsplit_bin = f.readAll();
if(f.size() != 0x20000) return false;
for(int x=0;x<=0xFFFF;x++) {
tside[x] = unsplit_bin.at(x);
eside[x] = unsplit_bin.at(x + 0x10000);
}
if(test_checksum() == false) return false;
return true;
}
bool bin_file::compare_tside(bin_file comp) {
for(int x=0x2000;x<=0xFFFF;x++) {
if(tside[x] != comp.tside[x]) return false;
}
return true;
}
bool bin_file::compare_eside(bin_file comp) {
for(int x=0x2000;x<=0xFFFF;x++) {
if(eside[x] != comp.eside[x]) return false;
}
return true;
}
bool bin_file::copy_to(bin_file *cp) {
for(int x=0x00;x<=0xFFFF;x++) {
cp->eside[x] = eside[x];
cp->tside[x] = tside[x];
}
return true; // can't fail ...
}
void bin_file::zero_bin() {
for(int x=0x0000;x<=0xFFFF;x++) {
tside[x] = 0x00;
eside[x] = 0x00;
}
}
bool bin_file::apply_patches() {
int success = true;
if(tside[PATCH_VERSION_BYTE] != 0x00) return false;
if(patch_enhanced_logging() == false) return false;
if(patch_afr_msg0() == false) return false;
if(patch_enhanced_logging() == false) success = false;
if(patch_afr_msg0() == false) success = false;
if(patch_eside_comms() == false) success = false;
set_patch_version();
return true;
return success;
}
bool bin_file::is_automatic_transmission() {
@@ -136,6 +237,12 @@ bool bin_file::patch_afr_msg0() {
return true;
}
bool bin_file::patch_eside_comms() {
eside[0x8256] = 0x11;
eside[0x824C] = 0x41;
return true;
}
void bin_file::set_patch_version() {
tside[PATCH_VERSION_BYTE] = CURRENT_PATCH_VERSION;
}
View
@@ -0,0 +1,47 @@
#ifndef BIN_FILE_H
#define BIN_FILE_H
#include <QApplication>
typedef unsigned char byte;
// stores an $EE memory dump and modifies it appropriately...
class bin_file {
public:
bin_file();
byte eside[0x10000];
byte tside[0x10000];
void zero_ram();
bool test_checksum(byte *data);
bool test_checksum();
void reset_checksums();
bool set_checksum(byte *data);
bool load_file(QString path);
bool compare_tside(bin_file comp);
bool compare_eside(bin_file comp);
bool copy_to(bin_file *cp);
void zero_bin();
bool apply_patches(); // apply all patches
// patches
int ff_unused_regions();
bool patch_enhanced_logging();
bool patch_afr_msg0();
void set_patch_version();
// patch utilities
int fill_0xff(byte *data, int offset, int size);
void install_patch(byte *bin, int offset, byte *patch, int size);
bool compare_patch(byte *bin, int offset, byte *patch, int size);
// bin info
bool is_automatic_transmission();
bool is_maf_enabled();
bool is_data_in_blank_eside_region_a();
bool is_data_in_blank_eside_region_b();
bool is_tunercat_notes_blank();
QString ecm_info_string();
bool patch_eside_comms();
private:
QString bool_to_enabled(bool x);
QString bool_to_present(bool x);
};
#endif // BIN_FILE_H
View
@@ -4,11 +4,11 @@
#include <qglobal.h>
// versioning
#define VERSION_CODE 420
//#define BETA_VERSION
#define VERSION_CODE 440
#define BETA_VERSION
// current patch version for versioning against the ecm bin.
#define CURRENT_PATCH_VERSION 0x01
#define CURRENT_PATCH_VERSION 0x02
#define MAX_READ_BUF 1024
#define MAX_WRITE_BUF 512
Oops, something went wrong.

1 comment on commit ebae2ce

@resfilter

This comment has been minimized.

Show comment
Hide comment
@resfilter

resfilter Feb 2, 2016

Owner

this is a gigantic fundamental change that probably breaks a lot of features. use with caution.

Owner

resfilter commented on ebae2ce Feb 2, 2016

this is a gigantic fundamental change that probably breaks a lot of features. use with caution.

Please sign in to comment.