changed serial reading from lowlevel to boost with hope for more stability, changed a lot of smart pointers to unique_ptr, added fmt for logging

This commit is contained in:
2019-01-06 14:57:27 +01:00
parent bc27278ffb
commit 58f44dc957
21 changed files with 281 additions and 173 deletions

View File

@@ -18,6 +18,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
#find_package(Boost REQUIRED COMPONENTS iostreams system filesystem) #find_package(Boost REQUIRED COMPONENTS iostreams system filesystem)
find_package(Boost REQUIRED COMPONENTS iostreams system filesystem) find_package(Boost REQUIRED COMPONENTS iostreams system filesystem)
find_package(fmt)
include_directories(${CMAKE_SOURCE_DIR}/gnuplot-iostream) include_directories(${CMAKE_SOURCE_DIR}/gnuplot-iostream)
# Find includes in corresponding build directories # Find includes in corresponding build directories
@@ -92,6 +94,7 @@ set(helloworld_SRCS
datahelper.cpp datahelper.cpp
colorwidget.cpp colorwidget.cpp
qrc_resource.cpp qrc_resource.cpp
serial_port.cpp
mainwindow.ui mainwindow.ui
windowrace.ui windowrace.ui
@@ -105,5 +108,5 @@ set(helloworld_SRCS
add_executable(Rennbahn ${helloworld_SRCS} ) add_executable(Rennbahn ${helloworld_SRCS} )
# Use the Widgets module from Qt 5 # Use the Widgets module from Qt 5
target_link_libraries(Rennbahn Qt5::Widgets Qt5::Core Qt5::Sql ${LIBUSB_LIBRARY}) target_link_libraries(Rennbahn Qt5::Widgets Qt5::Core Qt5::Sql ${LIBUSB_LIBRARY} pthread fmt::fmt)
target_link_libraries(Rennbahn ${Boost_LIBRARIES}) target_link_libraries(Rennbahn ${Boost_LIBRARIES})

31
datatypes.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef DATATYPES_H
#define DATATYPES_H
#include <fmt/format.h>
#include <inttypes.h>
struct TransStruct {
uint16_t time;
uint8_t id;
uint8_t update;
};
struct TransCheck {
char begin;
struct TransStruct data[6];
char end;
};
template <> struct fmt::formatter<TransStruct> {
template <typename ParseContext> constexpr auto parse(ParseContext & ctx) {
return ctx.begin();
}
template <typename FormatContext>
auto format(const TransStruct & t, FormatContext & ctx) {
return format_to(ctx.out(), "id {}; time {}; update {}", t.id, t.time,
t.update);
}
};
#endif // DATATYPES_H

View File

@@ -10,7 +10,7 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
Evaluation::Evaluation(std::shared_ptr<DataBase> db, QWidget * parent) Evaluation::Evaluation(DataBase * db, QWidget * parent)
: QWidget(parent), ui(new Ui::Evaluation) { : QWidget(parent), ui(new Ui::Evaluation) {
ui->setupUi(this); ui->setupUi(this);
this->db = db; this->db = db;

View File

@@ -19,14 +19,13 @@ class Evaluation : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit Evaluation(std::shared_ptr<DataBase> db, explicit Evaluation(DataBase * db, QWidget * parent = nullptr);
QWidget * parent = nullptr);
~Evaluation(); ~Evaluation();
private: private:
Ui::Evaluation * ui; Ui::Evaluation * ui;
std::shared_ptr<Result> interfaceResult; std::shared_ptr<Result> interfaceResult;
std::shared_ptr<DataBase> db; DataBase * db;
vector<vector<QString>> result; vector<vector<QString>> result;
public slots: public slots:

View File

@@ -1,7 +1,10 @@
#include "hardwaresetup.h" #include "hardwaresetup.h"
#include "sys/io.h" #include "sys/io.h"
// filecontrol // filecontrol
#include "datatypes.h"
#include <boost/asio/serial_port.hpp>
#include <fcntl.h> #include <fcntl.h>
#include <fmt/format.h>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <stdint.h> #include <stdint.h>
@@ -39,7 +42,7 @@ HardwareSetup::HardwareSetup() {
this->handle = nullptr; this->handle = nullptr;
#endif #endif
this->fd = 0; this->fd = -1;
} }
void HardwareSetup::setStop() { void HardwareSetup::setStop() {
this->stop = 1; this->stop = 1;
@@ -262,34 +265,31 @@ void HardwareSetup::run() {
} // end HARDWARE_VERSION 2 } // end HARDWARE_VERSION 2
else if (HARDWARE_VERSION == 3) { else if (HARDWARE_VERSION == 3) {
uint8_t dummy[sizeof(struct TransCheck)] = {0}; TransCheck * received;
sport = std::make_unique<serial_port>(PORT_PATH);
this->connectSTM32(); TransCheck buffer = sport->read_frame();
// prepare buffer
std::shared_ptr<struct TransCheck> received =
std::make_shared<struct TransCheck>();
uint8_t uintBuf[sizeof(struct TransCheck)];
while (!this->stop) { while (!this->stop) {
// read data usleep(100000); // 150ms
cout << "try to read data" << endl; buffer = sport->read_frame();
read(this->fd, uintBuf, sizeof(struct TransCheck)); received = &buffer;
cout << "data read" << endl;
// voidBuf = static_cast<void *>(uintBuf);
memcpy(received.get(), uintBuf, sizeof(struct TransCheck));
// voidBuf = static_cast<void *>(uintBuf);
// received = static_cast<struct TransCheck *>(voidBuf); /*
cout << buffer.begin << endl;
usleep(50000); // 150ms
if (received->begin == '#' && received->end == '!') {
// flash data
tcflush(fd, TCIFLUSH);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
cout << "i: " << i << " time: " cout << "time: " << static_cast<int>(buffer.data[i].time)
<< static_cast<int>(received->data[i].time) << endl;
cout << "id: " << static_cast<int>(buffer.data[i].id) << endl;
cout << "update: " << static_cast<int>(buffer.data[i].update)
<< endl;
}
cout << static_cast<char>(buffer.end) << endl;
*/
for (int i = 0; i < 6; i++) {
fmt::print("{} ", TransStruct{buffer.data[i]});
cout << "i: " << i
<< " time: " << static_cast<int>(received->data[i].time)
<< " update: " << " update: "
<< static_cast<int>(received->data[i].update) << endl; << static_cast<int>(received->data[i].update) << endl;
if (received->data[i].update != 0) { if (received->data[i].update != 0) {
@@ -298,70 +298,69 @@ void HardwareSetup::run() {
cout << "Shell Zeit 1: " cout << "Shell Zeit 1: "
<< static_cast<int>(received->data[i].time) << static_cast<int>(received->data[i].time)
<< endl; << endl;
emit Shell(static_cast<int>(received->data[i].time), emit Shell(static_cast<int>(received->data[i].time), 1);
1);
break; break;
case 1: case 1:
cout << "Dea Zeit 1: " cout << "Dea Zeit 1: "
<< static_cast<int>(received->data[i].time) << static_cast<int>(received->data[i].time)
<< endl; << endl;
emit Dea(static_cast<int>(received->data[i].time), emit Dea(static_cast<int>(received->data[i].time), 1);
1);
break; break;
case 2: case 2:
cout << "Shell Zeit 2: " cout << "Shell Zeit 2: "
<< static_cast<int>(received->data[i].time) << static_cast<int>(received->data[i].time)
<< endl; << endl;
emit Shell(static_cast<int>(received->data[i].time), emit Shell(static_cast<int>(received->data[i].time), 2);
2);
break; break;
case 3: case 3:
cout << "Dea Zeit 2: " cout << "Dea Zeit 2: "
<< static_cast<int>(received->data[i].time) << static_cast<int>(received->data[i].time)
<< endl; << endl;
emit Dea(static_cast<int>(received->data[i].time), emit Dea(static_cast<int>(received->data[i].time), 2);
2);
break; break;
case 4: case 4:
cout << "Shell Zeit 3: " cout << "Shell Zeit 3: "
<< static_cast<int>(received->data[i].time) << static_cast<int>(received->data[i].time)
<< endl; << endl;
emit Shell(static_cast<int>(received->data[i].time), emit Shell(static_cast<int>(received->data[i].time), 3);
3);
break; break;
case 5: case 5:
cout << "Dea Zeit 3: " cout << "Dea Zeit 3: "
<< static_cast<int>(received->data[i].time) << static_cast<int>(received->data[i].time)
<< endl; << endl;
emit Dea(static_cast<int>(received->data[i].time), emit Dea(static_cast<int>(received->data[i].time), 3);
3);
break; break;
} }
} }
} }
} // dataframe ok
else {
// dataframe not ok
tcflush(fd, TCIFLUSH);
cout << "reconnect controller" << endl;
this->connectSTM32();
}
if (fd < 0) {
// connection lost
this->connectSTM32();
}
// overwrite received data to prevent same data gets read one more // overwrite received data to prevent same data gets read one more
// time; dummy data is array of zeros // time; dummy data is array of zeros
memcpy(received.get(), dummy, sizeof(struct TransCheck));
} }
} }
else { else {
cout << "unknown hardware version" << endl; cout << "unknown hardware version" << endl;
} }
} }
/*
void HardwareSetup::connectSTM32Boost() {
// serialPort.
boost::asio::serial_port port(this->context);
try {
port.open(PORT_PATH);
port.set_option(boost::asio::serial_port::baud_rate(9600));
port.set_option(boost::asio::serial_port::service_type());
} catch (boost::system::system_error & e) {
Q_UNUSED(e);
cout << "port could not be opened" << endl;
}
}
*/
void HardwareSetup::connectSTM32() { void HardwareSetup::connectSTM32() {
if (fd >= 0) { // fd is already in use
close(fd);
}
usleep(10000);
fd = open(PORT_PATH, O_RDONLY); fd = open(PORT_PATH, O_RDONLY);
while (this->fd < 0) { while (this->fd < 0) {
// wait 1 second // wait 1 second

View File

@@ -2,6 +2,7 @@
#define HARDWARESETUP_H #define HARDWARESETUP_H
#include <QtCore> #include <QtCore>
#include <boost/asio/serial_port.hpp>
#include <memory> #include <memory>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -9,17 +10,9 @@
#ifdef ATMEGA #ifdef ATMEGA
#include <libusb.h> #include <libusb.h>
#endif #endif
struct TransStruct {
uint16_t time;
uint8_t id;
uint8_t update;
};
struct TransCheck { #include "datatypes.h"
char begin; #include "serial_port.h"
struct TransStruct data[6];
char end;
};
class HardwareSetup : public QThread { class HardwareSetup : public QThread {
Q_OBJECT Q_OBJECT
@@ -37,13 +30,15 @@ class HardwareSetup : public QThread {
libusb_device_handle * usbOpenDevice(int vendor, int product); libusb_device_handle * usbOpenDevice(int vendor, int product);
#endif #endif
int fd; int fd;
bool stop;
boost::asio::io_context context;
// boost::asio::serial_port serialPort{};
void connectSTM32(); void connectSTM32();
void connectSTM32Boost();
bool getShell(); bool getShell();
bool getDea(); bool getDea();
int * findBit(int * array, int zahl); int * findBit(int * array, int zahl);
bool stop; std::unique_ptr<serial_port> sport;
public: public:
void setStop(); void setStop();

View File

@@ -13,6 +13,12 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <boost/asio/read.hpp>
#include <boost/asio/serial_port.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <string>
using std::vector; using std::vector;
MainWindow::MainWindow(QWidget * parent) MainWindow::MainWindow(QWidget * parent)
@@ -43,9 +49,7 @@ MainWindow::MainWindow(QWidget * parent)
QObject::connect(startRennen.get(), SIGNAL(activated()), this, QObject::connect(startRennen.get(), SIGNAL(activated()), this,
SLOT(WindowRennen())); SLOT(WindowRennen()));
this->db = std::make_shared<DataBase>(); this->db = std::make_unique<DataBase>();
// vector<vector<QString>> daten = db->getData("select * from Fahrer", 2);
} }
void MainWindow::closeEvent(QCloseEvent * event) { void MainWindow::closeEvent(QCloseEvent * event) {
Q_UNUSED(event); Q_UNUSED(event);
@@ -57,13 +61,15 @@ MainWindow::~MainWindow() {
void MainWindow::WindowTraining() { void MainWindow::WindowTraining() {
{ {
this->interfaceTraining = std::make_shared<Training>(this, this->db); this->interfaceTraining =
std::make_unique<Training>(this, this->db.get());
this->interfaceTraining->show(); this->interfaceTraining->show();
} }
} }
void MainWindow::NewWindowSettings() { void MainWindow::NewWindowSettings() {
this->interfaceSettings = std::make_shared<WindowsSettings>(this->db, this); this->interfaceSettings =
std::make_unique<WindowsSettings>(this->db.get(), this);
this->interfaceSettings->show(); this->interfaceSettings->show();
} }
@@ -108,16 +114,16 @@ void MainWindow::WindowRennen() {
Q_UNUSED(e); Q_UNUSED(e);
} }
this->interfaceRace = std::make_shared<WindowRace>(this->db, this); this->interfaceRace = std::make_unique<WindowRace>(this->db.get(), this);
this->interfaceRace->show(); this->interfaceRace->show();
this->interfaceRennliste = this->interfaceRennliste =
std::make_shared<WindowRennliste>(this->db, this); std::make_unique<WindowRennliste>(this->db.get(), this);
this->interfaceRennliste->show(); this->interfaceRennliste->show();
this->interfaceRace->setWindowRennliste(this->interfaceRennliste); this->interfaceRace->setWindowRennliste(this->interfaceRennliste.get());
this->interfaceRennliste->setWindowRace(this->interfaceRace); this->interfaceRennliste->setWindowRace(this->interfaceRace.get());
} }
void MainWindow::WindowEvaluation() { void MainWindow::WindowEvaluation() {
this->interfaceEvaluation = std::make_shared<Evaluation>(this->db); this->interfaceEvaluation = std::make_unique<Evaluation>(this->db.get());
this->interfaceEvaluation->show(); this->interfaceEvaluation->show();
} }

View File

@@ -31,14 +31,14 @@ class MainWindow : public QMainWindow {
void WindowEvaluation(); void WindowEvaluation();
private: private:
std::shared_ptr<Training> interfaceTraining; std::unique_ptr<Training> interfaceTraining;
void closeEvent(QCloseEvent * event); void closeEvent(QCloseEvent * event);
std::shared_ptr<DataBase> db; std::unique_ptr<DataBase> db;
Ui::MainWindow * ui; Ui::MainWindow * ui;
std::shared_ptr<WindowRace> interfaceRace; std::unique_ptr<WindowRace> interfaceRace;
std::shared_ptr<WindowsSettings> interfaceSettings; std::unique_ptr<WindowsSettings> interfaceSettings;
std::shared_ptr<WindowRennliste> interfaceRennliste; std::unique_ptr<WindowRennliste> interfaceRennliste;
std::shared_ptr<Evaluation> interfaceEvaluation; std::unique_ptr<Evaluation> interfaceEvaluation;
std::shared_ptr<QShortcut> startTraining; std::shared_ptr<QShortcut> startTraining;
std::shared_ptr<QShortcut> startRennen; std::shared_ptr<QShortcut> startRennen;

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>512</width> <width>512</width>
<height>235</height> <height>244</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">

View File

@@ -22,7 +22,7 @@ using std::endl;
using std::string; using std::string;
using std::vector; using std::vector;
Result::Result(std::shared_ptr<DataBase> db, int rennid, QWidget * parent) Result::Result(DataBase * db, int rennid, QWidget * parent)
: QWidget(parent), ui(new Ui::Result) { : QWidget(parent), ui(new Ui::Result) {
ui->setupUi(this); ui->setupUi(this);
this->db = db; this->db = db;

View File

@@ -24,8 +24,7 @@ class Result : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit Result(std::shared_ptr<DataBase> db, int rennid, explicit Result(DataBase * db, int rennid, QWidget * parent = nullptr);
QWidget * parent = nullptr);
~Result(); ~Result();
public slots: public slots:
void closeWindow(); void closeWindow();
@@ -49,7 +48,7 @@ class Result : public QWidget {
Ui::Result * ui; Ui::Result * ui;
std::shared_ptr<ResultModel> model; std::shared_ptr<ResultModel> model;
std::shared_ptr<DataBase> db; DataBase * db;
int rennid; int rennid;
int minimumTime; int minimumTime;
QString renndatum; QString renndatum;

53
serial_port.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "serial_port.h"
serial_port::serial_port(const std::string & device) {
try {
this->port.open(device);
this->port.set_option(boost::asio::serial_port::baud_rate(9600));
this->port.set_option(boost::asio::serial_port::parity(
boost::asio::serial_port::parity::none));
this->port.set_option(boost::asio::serial_port::character_size(
boost::asio::serial_port::character_size(8)));
this->port.set_option(boost::asio::serial_port::stop_bits(
boost::asio::serial_port::stop_bits::one));
this->flush();
} catch (const boost::system::system_error & e) {
throw std::system_error{
e.code(), std::string("Could not open serial port ") + device};
}
std::cout << "Port opened" << std::endl;
}
void serial_port::flush() {
auto handle = this->port.native_handle();
if (tcflush(handle, TCIOFLUSH) == -1) {
throw std::system_error(std::error_code(errno, std::system_category()));
}
}
TransCheck serial_port::read_frame() {
// buffer.reserve(1);
TransCheck buffer;
boost::asio::read(port, boost::asio::buffer(&buffer, sizeof(buffer)));
/*
async_read(
port, boost::asio::buffer(&buffer, sizeof(buffer)),
[&buffer, this](auto error, auto) { std::cout << error << std::endl; });
*/
// this->ioContext.run();
// check for valid data
if (buffer.begin == '#' && buffer.end == '!') {
std::cout << "vaild data" << std::endl;
return buffer;
}
else {
std::cout << "Fehler: \n" << std::endl;
for (int i = 0; i < 6; i++) {
buffer.data[i].update = 0;
}
this->flush();
return buffer;
}
}

27
serial_port.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef SERIAL_PORT_H
#define SERIAL_PORT_H
#include <boost/asio/read.hpp>
#include <boost/asio/serial_port.hpp>
#include <string>
#include <iostream>
#include "datatypes.h"
using boost::asio::async_read;
using boost::asio::dynamic_buffer;
class serial_port
{
public:
serial_port(const std::string & device);
TransCheck read_frame();
private:
void flush();
boost::asio::io_context ioContext;
boost::asio::serial_port port{ioContext};
};
#endif // SERIAL_PORT_H

View File

@@ -16,7 +16,7 @@ using std::endl;
using std::string; using std::string;
using std::vector; using std::vector;
Training::Training(QWidget * parent, std::shared_ptr<DataBase> db) Training::Training(QWidget * parent, DataBase * db)
: QMainWindow(parent), ui(new Ui::Training) { : QMainWindow(parent), ui(new Ui::Training) {
ui->setupUi(this); ui->setupUi(this);
this->db = db; this->db = db;
@@ -93,7 +93,7 @@ void Training::ResetShell() {
this->VecShell.clear(); this->VecShell.clear();
// this->ui->lWShellTime->clear(); // this->ui->lWShellTime->clear();
timeModelShell = std::make_shared<TimeModel>(VecShell, minSecTime, this); timeModelShell = std::make_unique<TimeModel>(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell.get()); this->ui->lWShellTime->setModel(timeModelShell.get());
this->ui->lBestZeitShell->setText(""); this->ui->lBestZeitShell->setText("");
@@ -111,7 +111,7 @@ void Training::ResetDea() {
this->VecDea.clear(); this->VecDea.clear();
// this->ui->lWDeaTime->clear(); // this->ui->lWDeaTime->clear();
timeModelDea = std::make_shared<TimeModel>(VecDea, minSecTime, this); timeModelDea = std::make_unique<TimeModel>(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lBestZeitDea->setText(""); this->ui->lBestZeitDea->setText("");
@@ -175,7 +175,7 @@ void Training::shellSlot(int time, int sector) {
VecShell.last().push_back(time); VecShell.last().push_back(time);
timeModelShell = timeModelShell =
std::make_shared<TimeModel>(VecShell, minSecTime, this); std::make_unique<TimeModel>(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell.get()); this->ui->lWShellTime->setModel(timeModelShell.get());
this->ui->lBridgeShellTop->setText(QString::number( this->ui->lBridgeShellTop->setText(QString::number(
@@ -189,7 +189,7 @@ void Training::shellSlot(int time, int sector) {
// cout << time << sector << // cout << time << sector <<
// endl; // endl;
VecShell.last().push_back(time); VecShell.last().push_back(time);
timeModelShell = std::make_shared<TimeModel>( timeModelShell = std::make_unique<TimeModel>(
VecShell, minSecTime, this); VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell.get()); this->ui->lWShellTime->setModel(timeModelShell.get());
} }
@@ -211,7 +211,7 @@ void Training::shellSlot(int time, int sector) {
VecShell.last().push_back( VecShell.last().push_back(
QVectorHelper::getCurTime(VecShell.last())); QVectorHelper::getCurTime(VecShell.last()));
timeModelShell = std::make_shared<TimeModel>( timeModelShell = std::make_unique<TimeModel>(
VecShell, minSecTime, this); VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell.get()); this->ui->lWShellTime->setModel(timeModelShell.get());
} }
@@ -281,7 +281,7 @@ void Training::deaSlot(int time, int sector) {
VecDea.last().push_back(time); VecDea.last().push_back(time);
// cout << "Dea Sektor 1" << endl; // cout << "Dea Sektor 1" << endl;
timeModelDea = timeModelDea =
std::make_shared<TimeModel>(VecDea, minSecTime, this); std::make_unique<TimeModel>(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lBridgeDeaTop->setText(QString::number( this->ui->lBridgeDeaTop->setText(QString::number(
static_cast<double>(QVectorHelper::getMinSec1(VecDea)) / static_cast<double>(QVectorHelper::getMinSec1(VecDea)) /
@@ -293,7 +293,7 @@ void Training::deaSlot(int time, int sector) {
// cout << time << sector << // cout << time << sector <<
// endl; // endl;
VecDea[VecDea.size() - 1].push_back(time); VecDea[VecDea.size() - 1].push_back(time);
timeModelDea = std::make_shared<TimeModel>( timeModelDea = std::make_unique<TimeModel>(
VecDea, minSecTime, this); VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
} }
@@ -317,7 +317,7 @@ void Training::deaSlot(int time, int sector) {
VecDea.last().push_back( VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last())); QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = std::make_shared<TimeModel>( timeModelDea = std::make_unique<TimeModel>(
VecDea, minSecTime, this); VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
} }

View File

@@ -18,7 +18,7 @@ class Training : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit Training(QWidget * parent, std::shared_ptr<DataBase> db); explicit Training(QWidget * parent, DataBase * db);
~Training(); ~Training();
private: private:
@@ -39,7 +39,7 @@ class Training : public QMainWindow {
bool finished; bool finished;
Counter counterShell; Counter counterShell;
Counter counterDea; Counter counterDea;
std::shared_ptr<DataBase> db; DataBase * db;
long minTimeOneRound; long minTimeOneRound;
int minimumTime; int minimumTime;
@@ -50,8 +50,8 @@ class Training : public QMainWindow {
int deltaDea; int deltaDea;
// timeModel // timeModel
std::shared_ptr<TimeModel> timeModelDea; std::unique_ptr<TimeModel> timeModelDea;
std::shared_ptr<TimeModel> timeModelShell; std::unique_ptr<TimeModel> timeModelShell;
QVector<int> minSecTime; QVector<int> minSecTime;
// shortcuts // shortcuts

View File

@@ -15,7 +15,7 @@ using std::endl;
using std::string; using std::string;
using std::vector; using std::vector;
WindowRace::WindowRace(std::shared_ptr<DataBase> db, QWidget * parent) WindowRace::WindowRace(DataBase * db, QWidget * parent)
: QMainWindow(parent), ui(new Ui::WindowRace) { : QMainWindow(parent), ui(new Ui::WindowRace) {
ui->setupUi(this); ui->setupUi(this);
this->ui->pBNextRace->setEnabled(false); this->ui->pBNextRace->setEnabled(false);
@@ -55,16 +55,16 @@ WindowRace::WindowRace(std::shared_ptr<DataBase> db, QWidget * parent)
firstTimeShell = true; firstTimeShell = true;
started = false; started = false;
countdownValue = this->fahrzeit; countdownValue = this->fahrzeit;
countdown = std::make_shared<Countdown>(); countdown = std::make_unique<Countdown>();
startAmpelThread = std::make_shared<Ampel>(); startAmpelThread = std::make_unique<Ampel>();
ampelCounter = 0; ampelCounter = 0;
ui->pBStart->setFocus(); ui->pBStart->setFocus();
paused = false; paused = false;
Hardware = std::make_shared<HardwareSetup>(); Hardware = std::make_unique<HardwareSetup>();
Hardware->start(); Hardware->start();
QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this, QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this,
@@ -211,11 +211,11 @@ void WindowRace::prepareNextRace() {
this->VecDea.clear(); this->VecDea.clear();
// clear tableview shell // clear tableview shell
timeModelShell = std::make_shared<TimeModel>(VecShell, minSecTime); timeModelShell = std::make_unique<TimeModel>(VecShell, minSecTime);
ui->lWShellTime->setModel(timeModelShell.get()); ui->lWShellTime->setModel(timeModelShell.get());
// clear tableview dea // clear tableview dea
timeModelDea = std::make_shared<TimeModel>(VecDea, minSecTime); timeModelDea = std::make_unique<TimeModel>(VecDea, minSecTime);
ui->lWDeaTime->setModel(timeModelDea.get()); ui->lWDeaTime->setModel(timeModelDea.get());
this->finished = false; this->finished = false;
@@ -265,13 +265,12 @@ void WindowRace::stopClicked() {
this->prepareNextRace(); this->prepareNextRace();
} }
void WindowRace::setWindowRennliste( void WindowRace::setWindowRennliste(WindowRennliste * ptrInstance) {
std::shared_ptr<WindowRennliste> ptrInstance) {
this->wRennliste = ptrInstance; this->wRennliste = ptrInstance;
this->wRennlisteSeted = true; this->wRennlisteSeted = true;
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste,
this->wRennliste.get(), SLOT(changeSelection())); SLOT(changeSelection()));
} }
void WindowRace::setDriverAndCarId(vector<QString> vec) { void WindowRace::setDriverAndCarId(vector<QString> vec) {
this->shellDriverId = vec.at(0).toInt(); this->shellDriverId = vec.at(0).toInt();
@@ -384,7 +383,7 @@ void WindowRace::shellSlot(int time, int sector) {
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = std::make_shared<TimeModel>( this->timeModelShell = std::make_unique<TimeModel>(
VecShell, minSecTime, test, this); VecShell, minSecTime, test, this);
// this->ui->lWShellTime->setModel(this->timeModelShell); // this->ui->lWShellTime->setModel(this->timeModelShell);
ui->lWShellTime->setModel(this->timeModelShell.get()); ui->lWShellTime->setModel(this->timeModelShell.get());
@@ -404,7 +403,7 @@ void WindowRace::shellSlot(int time, int sector) {
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = std::make_shared<TimeModel>( this->timeModelShell = std::make_unique<TimeModel>(
VecShell, minSecTime, test, this); VecShell, minSecTime, test, this);
// timeModelShell = new // timeModelShell = new
// TimeModel(VecShell, this); // TimeModel(VecShell, this);
@@ -439,7 +438,7 @@ void WindowRace::shellSlot(int time, int sector) {
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = std::make_shared<TimeModel>( this->timeModelShell = std::make_unique<TimeModel>(
VecShell, minSecTime, test, this); VecShell, minSecTime, test, this);
// timeModelShell = new // timeModelShell = new
// TimeModel(VecShell, this); // TimeModel(VecShell, this);
@@ -507,7 +506,7 @@ void WindowRace::deaSlot(int time, int sector) {
VecDea.last().push_back(time); VecDea.last().push_back(time);
cout << "Dea Sektor 1" << endl; cout << "Dea Sektor 1" << endl;
timeModelDea = timeModelDea =
std::make_shared<TimeModel>(VecDea, minSecTime, this); std::make_unique<TimeModel>(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lBridgeDea->setText(QString::number( this->ui->lBridgeDea->setText(QString::number(
@@ -520,7 +519,7 @@ void WindowRace::deaSlot(int time, int sector) {
if (VecDea.last().size() == 1) { if (VecDea.last().size() == 1) {
cout << time << sector << endl; cout << time << sector << endl;
VecDea[VecDea.size() - 1].push_back(time); VecDea[VecDea.size() - 1].push_back(time);
timeModelDea = std::make_shared<TimeModel>( timeModelDea = std::make_unique<TimeModel>(
VecDea, minSecTime, this); VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lStraightDea->setText(QString::number( this->ui->lStraightDea->setText(QString::number(
@@ -545,7 +544,7 @@ void WindowRace::deaSlot(int time, int sector) {
VecDea.last().push_back( VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last())); QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = std::make_shared<TimeModel>( timeModelDea = std::make_unique<TimeModel>(
VecDea, minSecTime, this); VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lWDeaTime->setModel(timeModelDea.get());
} }

View File

@@ -25,10 +25,9 @@ class WindowRace : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit WindowRace(std::shared_ptr<DataBase> db, explicit WindowRace(DataBase * db, QWidget * parent = nullptr);
QWidget * parent = nullptr);
~WindowRace(); ~WindowRace();
void setWindowRennliste(std::shared_ptr<WindowRennliste> ptrInstance); void setWindowRennliste(WindowRennliste * ptrInstance);
void setDriverAndCar(vector<QString> vec); void setDriverAndCar(vector<QString> vec);
void setDriverAndCarId(vector<QString> vec); void setDriverAndCarId(vector<QString> vec);
@@ -40,8 +39,8 @@ class WindowRace : public QMainWindow {
void closeEvent(QCloseEvent * event); void closeEvent(QCloseEvent * event);
bool started; bool started;
std::shared_ptr<Countdown> countdown; std::unique_ptr<Countdown> countdown;
std::shared_ptr<HardwareSetup> Hardware; std::unique_ptr<HardwareSetup> Hardware;
Ui::WindowRace * ui; Ui::WindowRace * ui;
Counter counterShell; Counter counterShell;
Counter counterDea; Counter counterDea;
@@ -49,17 +48,17 @@ class WindowRace : public QMainWindow {
bool firstTimeDea; bool firstTimeDea;
QVector<QVector<int>> VecShell; QVector<QVector<int>> VecShell;
QVector<QVector<int>> VecDea; QVector<QVector<int>> VecDea;
std::shared_ptr<TimeModel> timeModelShell; std::unique_ptr<TimeModel> timeModelShell;
std::shared_ptr<TimeModel> timeModelDea; std::unique_ptr<TimeModel> timeModelDea;
long getMinimum(std::vector<long> a); long getMinimum(std::vector<long> a);
QString timeWrapper(long zahl); QString timeWrapper(long zahl);
long countdownValue; // in sec long countdownValue; // in sec
std::shared_ptr<Ampel> startAmpelThread; std::unique_ptr<Ampel> startAmpelThread;
int ampelCounter; int ampelCounter;
bool paused; bool paused;
std::shared_ptr<DataBase> db; DataBase * db;
bool finished; bool finished;
std::shared_ptr<WindowRennliste> wRennliste; WindowRennliste * wRennliste;
bool wRennlisteSeted; bool wRennlisteSeted;
int fahrzeit; int fahrzeit;
int renn_id; int renn_id;

View File

@@ -11,7 +11,7 @@ using std::endl;
using std::string; using std::string;
using std::vector; using std::vector;
WindowRennliste::WindowRennliste(std::shared_ptr<DataBase> db, QWidget * parent) WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent)
: QMainWindow(parent), ui(new Ui::WindowRennliste) { : QMainWindow(parent), ui(new Ui::WindowRennliste) {
ui->setupUi(this); ui->setupUi(this);
@@ -99,7 +99,7 @@ WindowRennliste::WindowRennliste(std::shared_ptr<DataBase> db, QWidget * parent)
this->ui->tWRennliste->item(0, i)->setBackground(Qt::green); this->ui->tWRennliste->item(0, i)->setBackground(Qt::green);
} }
} }
void WindowRennliste::setWindowRace(std::shared_ptr<WindowRace> instance) { void WindowRennliste::setWindowRace(WindowRace * instance) {
this->instanceWindowRace = instance; this->instanceWindowRace = instance;
} }
vector<QString> WindowRennliste::getDriverAndCarSettings() { vector<QString> WindowRennliste::getDriverAndCarSettings() {

View File

@@ -19,11 +19,10 @@ class WindowRennliste : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit WindowRennliste(std::shared_ptr<DataBase> db, explicit WindowRennliste(DataBase * db, QWidget * parent = nullptr);
QWidget * parent = nullptr);
~WindowRennliste(); ~WindowRennliste();
void closeRaceList(); void closeRaceList();
void setWindowRace(std::shared_ptr<WindowRace> instance); void setWindowRace(WindowRace * instance);
vector<QString> getDriverAndCarSettings(); vector<QString> getDriverAndCarSettings();
vector<QString> getDriverAndCarId(); vector<QString> getDriverAndCarId();
void sendIds(); void sendIds();
@@ -33,10 +32,10 @@ class WindowRennliste : public QMainWindow {
bool windowClose; bool windowClose;
void closeEvent(QCloseEvent * event); void closeEvent(QCloseEvent * event);
void setSelection(int row); void setSelection(int row);
std::shared_ptr<WindowRace> instanceWindowRace; WindowRace * instanceWindowRace;
unsigned int selectedRow; unsigned int selectedRow;
vector<vector<QString>> tableData; vector<vector<QString>> tableData;
std::shared_ptr<DataBase> db; DataBase * db;
Ui::WindowRennliste * ui; Ui::WindowRennliste * ui;
public slots: public slots:

View File

@@ -17,7 +17,7 @@ using std::endl;
using std::string; using std::string;
using std::vector; using std::vector;
WindowsSettings::WindowsSettings(std::shared_ptr<DataBase> db, QWidget * parent) WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
: QMainWindow(parent), ui(new Ui::WindowsSettings) { : QMainWindow(parent), ui(new Ui::WindowsSettings) {
ui->setupUi(this); ui->setupUi(this);

View File

@@ -17,14 +17,13 @@ class WindowsSettings : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit WindowsSettings(std::shared_ptr<DataBase> db, explicit WindowsSettings(DataBase * db, QWidget * parent = nullptr);
QWidget * parent = nullptr);
~WindowsSettings(); ~WindowsSettings();
private: private:
Ui::WindowsSettings * ui; Ui::WindowsSettings * ui;
string currentDateTime(); string currentDateTime();
std::shared_ptr<DataBase> db; DataBase * db;
int rennId; int rennId;
vector<vector<QString>> carIds; vector<vector<QString>> carIds;
vector<vector<QString>> driversList; vector<vector<QString>> driversList;