From 58f44dc9579c853880d23d669dee36b169a669fb Mon Sep 17 00:00:00 2001 From: Johannes Paehr Date: Sun, 6 Jan 2019 14:57:27 +0100 Subject: [PATCH] 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 --- CMakeLists.txt | 5 +- datatypes.h | 31 ++++++++ evaluation.cpp | 2 +- evaluation.h | 5 +- hardwaresetup.cpp | 167 ++++++++++++++++++++++---------------------- hardwaresetup.h | 21 +++--- mainwindow.cpp | 26 ++++--- mainwindow.h | 12 ++-- mainwindow.ui | 2 +- result.cpp | 2 +- result.h | 5 +- serial_port.cpp | 53 ++++++++++++++ serial_port.h | 27 +++++++ training.cpp | 18 ++--- training.h | 8 +-- windowrace.cpp | 31 ++++---- windowrace.h | 19 +++-- windowrennliste.cpp | 4 +- windowrennliste.h | 9 ++- windowssettings.cpp | 2 +- windowssettings.h | 5 +- 21 files changed, 281 insertions(+), 173 deletions(-) create mode 100644 datatypes.h create mode 100644 serial_port.cpp create mode 100644 serial_port.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ca722b7..de018bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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(fmt) + include_directories(${CMAKE_SOURCE_DIR}/gnuplot-iostream) # Find includes in corresponding build directories @@ -92,6 +94,7 @@ set(helloworld_SRCS datahelper.cpp colorwidget.cpp qrc_resource.cpp + serial_port.cpp mainwindow.ui windowrace.ui @@ -105,5 +108,5 @@ set(helloworld_SRCS add_executable(Rennbahn ${helloworld_SRCS} ) # 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}) diff --git a/datatypes.h b/datatypes.h new file mode 100644 index 0000000..cecd4eb --- /dev/null +++ b/datatypes.h @@ -0,0 +1,31 @@ +#ifndef DATATYPES_H +#define DATATYPES_H + +#include +#include + +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 { + template constexpr auto parse(ParseContext & ctx) { + return ctx.begin(); + } + + template + auto format(const TransStruct & t, FormatContext & ctx) { + return format_to(ctx.out(), "id {}; time {}; update {}", t.id, t.time, + t.update); + } +}; + +#endif // DATATYPES_H diff --git a/evaluation.cpp b/evaluation.cpp index 9b2da39..8ba38c7 100644 --- a/evaluation.cpp +++ b/evaluation.cpp @@ -10,7 +10,7 @@ using std::cout; using std::endl; -Evaluation::Evaluation(std::shared_ptr db, QWidget * parent) +Evaluation::Evaluation(DataBase * db, QWidget * parent) : QWidget(parent), ui(new Ui::Evaluation) { ui->setupUi(this); this->db = db; diff --git a/evaluation.h b/evaluation.h index 1d51c6f..8552e63 100644 --- a/evaluation.h +++ b/evaluation.h @@ -19,14 +19,13 @@ class Evaluation : public QWidget { Q_OBJECT public: - explicit Evaluation(std::shared_ptr db, - QWidget * parent = nullptr); + explicit Evaluation(DataBase * db, QWidget * parent = nullptr); ~Evaluation(); private: Ui::Evaluation * ui; std::shared_ptr interfaceResult; - std::shared_ptr db; + DataBase * db; vector> result; public slots: diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index 123f1c9..aa933f1 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -1,7 +1,10 @@ #include "hardwaresetup.h" #include "sys/io.h" // filecontrol +#include "datatypes.h" +#include #include +#include #include #include #include @@ -39,7 +42,7 @@ HardwareSetup::HardwareSetup() { this->handle = nullptr; #endif - this->fd = 0; + this->fd = -1; } void HardwareSetup::setStop() { this->stop = 1; @@ -262,106 +265,102 @@ void HardwareSetup::run() { } // end HARDWARE_VERSION 2 else if (HARDWARE_VERSION == 3) { - uint8_t dummy[sizeof(struct TransCheck)] = {0}; - - this->connectSTM32(); - // prepare buffer - std::shared_ptr received = - std::make_shared(); - uint8_t uintBuf[sizeof(struct TransCheck)]; + TransCheck * received; + sport = std::make_unique(PORT_PATH); + TransCheck buffer = sport->read_frame(); while (!this->stop) { - // read data - cout << "try to read data" << endl; - read(this->fd, uintBuf, sizeof(struct TransCheck)); - cout << "data read" << endl; - // voidBuf = static_cast(uintBuf); - memcpy(received.get(), uintBuf, sizeof(struct TransCheck)); - // voidBuf = static_cast(uintBuf); + usleep(100000); // 150ms + buffer = sport->read_frame(); + received = &buffer; - // received = static_cast(voidBuf); - - usleep(50000); // 150ms - - if (received->begin == '#' && received->end == '!') { - // flash data - tcflush(fd, TCIFLUSH); - for (int i = 0; i < 6; i++) { - cout << "i: " << i << " time: " - << static_cast(received->data[i].time) - << " update: " - << static_cast(received->data[i].update) << endl; - if (received->data[i].update != 0) { - switch (received->data[i].id) { - case 0: - cout << "Shell Zeit 1: " - << static_cast(received->data[i].time) - << endl; - emit Shell(static_cast(received->data[i].time), - 1); - break; - case 1: - cout << "Dea Zeit 1: " - << static_cast(received->data[i].time) - << endl; - emit Dea(static_cast(received->data[i].time), - 1); - break; - case 2: - cout << "Shell Zeit 2: " - << static_cast(received->data[i].time) - << endl; - emit Shell(static_cast(received->data[i].time), - 2); - break; - case 3: - cout << "Dea Zeit 2: " - << static_cast(received->data[i].time) - << endl; - emit Dea(static_cast(received->data[i].time), - 2); - break; - case 4: - cout << "Shell Zeit 3: " - << static_cast(received->data[i].time) - << endl; - emit Shell(static_cast(received->data[i].time), - 3); - break; - case 5: - cout << "Dea Zeit 3: " - << static_cast(received->data[i].time) - << endl; - emit Dea(static_cast(received->data[i].time), - 3); - break; - } + /* + cout << buffer.begin << endl; + for (int i = 0; i < 6; i++) { + cout << "time: " << static_cast(buffer.data[i].time) + << endl; + cout << "id: " << static_cast(buffer.data[i].id) << endl; + cout << "update: " << static_cast(buffer.data[i].update) + << endl; + } + cout << static_cast(buffer.end) << endl; +*/ + for (int i = 0; i < 6; i++) { + fmt::print("{} ", TransStruct{buffer.data[i]}); + cout << "i: " << i + << " time: " << static_cast(received->data[i].time) + << " update: " + << static_cast(received->data[i].update) << endl; + if (received->data[i].update != 0) { + switch (received->data[i].id) { + case 0: + cout << "Shell Zeit 1: " + << static_cast(received->data[i].time) + << endl; + emit Shell(static_cast(received->data[i].time), 1); + break; + case 1: + cout << "Dea Zeit 1: " + << static_cast(received->data[i].time) + << endl; + emit Dea(static_cast(received->data[i].time), 1); + break; + case 2: + cout << "Shell Zeit 2: " + << static_cast(received->data[i].time) + << endl; + emit Shell(static_cast(received->data[i].time), 2); + break; + case 3: + cout << "Dea Zeit 2: " + << static_cast(received->data[i].time) + << endl; + emit Dea(static_cast(received->data[i].time), 2); + break; + case 4: + cout << "Shell Zeit 3: " + << static_cast(received->data[i].time) + << endl; + emit Shell(static_cast(received->data[i].time), 3); + break; + case 5: + cout << "Dea Zeit 3: " + << static_cast(received->data[i].time) + << endl; + emit Dea(static_cast(received->data[i].time), 3); + 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 // time; dummy data is array of zeros - memcpy(received.get(), dummy, sizeof(struct TransCheck)); } } else { 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() { + if (fd >= 0) { // fd is already in use + close(fd); + } + usleep(10000); fd = open(PORT_PATH, O_RDONLY); while (this->fd < 0) { // wait 1 second diff --git a/hardwaresetup.h b/hardwaresetup.h index be6cf07..4703fff 100644 --- a/hardwaresetup.h +++ b/hardwaresetup.h @@ -2,6 +2,7 @@ #define HARDWARESETUP_H #include +#include #include #include #include @@ -9,17 +10,9 @@ #ifdef ATMEGA #include #endif -struct TransStruct { - uint16_t time; - uint8_t id; - uint8_t update; -}; -struct TransCheck { - char begin; - struct TransStruct data[6]; - char end; -}; +#include "datatypes.h" +#include "serial_port.h" class HardwareSetup : public QThread { Q_OBJECT @@ -37,13 +30,15 @@ class HardwareSetup : public QThread { libusb_device_handle * usbOpenDevice(int vendor, int product); #endif int fd; - + bool stop; + boost::asio::io_context context; + // boost::asio::serial_port serialPort{}; void connectSTM32(); - + void connectSTM32Boost(); bool getShell(); bool getDea(); int * findBit(int * array, int zahl); - bool stop; + std::unique_ptr sport; public: void setStop(); diff --git a/mainwindow.cpp b/mainwindow.cpp index e9ff070..b7f2f6b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,6 +13,12 @@ #include #include +#include +#include +#include +#include +#include + using std::vector; MainWindow::MainWindow(QWidget * parent) @@ -43,9 +49,7 @@ MainWindow::MainWindow(QWidget * parent) QObject::connect(startRennen.get(), SIGNAL(activated()), this, SLOT(WindowRennen())); - this->db = std::make_shared(); - - // vector> daten = db->getData("select * from Fahrer", 2); + this->db = std::make_unique(); } void MainWindow::closeEvent(QCloseEvent * event) { Q_UNUSED(event); @@ -57,13 +61,15 @@ MainWindow::~MainWindow() { void MainWindow::WindowTraining() { { - this->interfaceTraining = std::make_shared(this, this->db); + this->interfaceTraining = + std::make_unique(this, this->db.get()); this->interfaceTraining->show(); } } void MainWindow::NewWindowSettings() { - this->interfaceSettings = std::make_shared(this->db, this); + this->interfaceSettings = + std::make_unique(this->db.get(), this); this->interfaceSettings->show(); } @@ -108,16 +114,16 @@ void MainWindow::WindowRennen() { Q_UNUSED(e); } - this->interfaceRace = std::make_shared(this->db, this); + this->interfaceRace = std::make_unique(this->db.get(), this); this->interfaceRace->show(); this->interfaceRennliste = - std::make_shared(this->db, this); + std::make_unique(this->db.get(), this); this->interfaceRennliste->show(); - this->interfaceRace->setWindowRennliste(this->interfaceRennliste); - this->interfaceRennliste->setWindowRace(this->interfaceRace); + this->interfaceRace->setWindowRennliste(this->interfaceRennliste.get()); + this->interfaceRennliste->setWindowRace(this->interfaceRace.get()); } void MainWindow::WindowEvaluation() { - this->interfaceEvaluation = std::make_shared(this->db); + this->interfaceEvaluation = std::make_unique(this->db.get()); this->interfaceEvaluation->show(); } diff --git a/mainwindow.h b/mainwindow.h index 4351151..a4f6002 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -31,14 +31,14 @@ class MainWindow : public QMainWindow { void WindowEvaluation(); private: - std::shared_ptr interfaceTraining; + std::unique_ptr interfaceTraining; void closeEvent(QCloseEvent * event); - std::shared_ptr db; + std::unique_ptr db; Ui::MainWindow * ui; - std::shared_ptr interfaceRace; - std::shared_ptr interfaceSettings; - std::shared_ptr interfaceRennliste; - std::shared_ptr interfaceEvaluation; + std::unique_ptr interfaceRace; + std::unique_ptr interfaceSettings; + std::unique_ptr interfaceRennliste; + std::unique_ptr interfaceEvaluation; std::shared_ptr startTraining; std::shared_ptr startRennen; diff --git a/mainwindow.ui b/mainwindow.ui index 50ff8e9..aed48fb 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 512 - 235 + 244 diff --git a/result.cpp b/result.cpp index d1fcfdd..2444d29 100644 --- a/result.cpp +++ b/result.cpp @@ -22,7 +22,7 @@ using std::endl; using std::string; using std::vector; -Result::Result(std::shared_ptr db, int rennid, QWidget * parent) +Result::Result(DataBase * db, int rennid, QWidget * parent) : QWidget(parent), ui(new Ui::Result) { ui->setupUi(this); this->db = db; diff --git a/result.h b/result.h index ef48309..0615363 100644 --- a/result.h +++ b/result.h @@ -24,8 +24,7 @@ class Result : public QWidget { Q_OBJECT public: - explicit Result(std::shared_ptr db, int rennid, - QWidget * parent = nullptr); + explicit Result(DataBase * db, int rennid, QWidget * parent = nullptr); ~Result(); public slots: void closeWindow(); @@ -49,7 +48,7 @@ class Result : public QWidget { Ui::Result * ui; std::shared_ptr model; - std::shared_ptr db; + DataBase * db; int rennid; int minimumTime; QString renndatum; diff --git a/serial_port.cpp b/serial_port.cpp new file mode 100644 index 0000000..12966b8 --- /dev/null +++ b/serial_port.cpp @@ -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; + } +} diff --git a/serial_port.h b/serial_port.h new file mode 100644 index 0000000..43bd5cf --- /dev/null +++ b/serial_port.h @@ -0,0 +1,27 @@ +#ifndef SERIAL_PORT_H +#define SERIAL_PORT_H + +#include +#include +#include +#include +#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 diff --git a/training.cpp b/training.cpp index 9cebafc..8bd4861 100644 --- a/training.cpp +++ b/training.cpp @@ -16,7 +16,7 @@ using std::endl; using std::string; using std::vector; -Training::Training(QWidget * parent, std::shared_ptr db) +Training::Training(QWidget * parent, DataBase * db) : QMainWindow(parent), ui(new Ui::Training) { ui->setupUi(this); this->db = db; @@ -93,7 +93,7 @@ void Training::ResetShell() { this->VecShell.clear(); // this->ui->lWShellTime->clear(); - timeModelShell = std::make_shared(VecShell, minSecTime, this); + timeModelShell = std::make_unique(VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell.get()); this->ui->lBestZeitShell->setText("∞"); @@ -111,7 +111,7 @@ void Training::ResetDea() { this->VecDea.clear(); // this->ui->lWDeaTime->clear(); - timeModelDea = std::make_shared(VecDea, minSecTime, this); + timeModelDea = std::make_unique(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lBestZeitDea->setText("∞"); @@ -175,7 +175,7 @@ void Training::shellSlot(int time, int sector) { VecShell.last().push_back(time); timeModelShell = - std::make_shared(VecShell, minSecTime, this); + std::make_unique(VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell.get()); this->ui->lBridgeShellTop->setText(QString::number( @@ -189,7 +189,7 @@ void Training::shellSlot(int time, int sector) { // cout << time << sector << // endl; VecShell.last().push_back(time); - timeModelShell = std::make_shared( + timeModelShell = std::make_unique( VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell.get()); } @@ -211,7 +211,7 @@ void Training::shellSlot(int time, int sector) { VecShell.last().push_back( QVectorHelper::getCurTime(VecShell.last())); - timeModelShell = std::make_shared( + timeModelShell = std::make_unique( VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell.get()); } @@ -281,7 +281,7 @@ void Training::deaSlot(int time, int sector) { VecDea.last().push_back(time); // cout << "Dea Sektor 1" << endl; timeModelDea = - std::make_shared(VecDea, minSecTime, this); + std::make_unique(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lBridgeDeaTop->setText(QString::number( static_cast(QVectorHelper::getMinSec1(VecDea)) / @@ -293,7 +293,7 @@ void Training::deaSlot(int time, int sector) { // cout << time << sector << // endl; VecDea[VecDea.size() - 1].push_back(time); - timeModelDea = std::make_shared( + timeModelDea = std::make_unique( VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); } @@ -317,7 +317,7 @@ void Training::deaSlot(int time, int sector) { VecDea.last().push_back( QVectorHelper::getCurTime(VecDea.last())); - timeModelDea = std::make_shared( + timeModelDea = std::make_unique( VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); } diff --git a/training.h b/training.h index 180682d..63baafe 100644 --- a/training.h +++ b/training.h @@ -18,7 +18,7 @@ class Training : public QMainWindow { Q_OBJECT public: - explicit Training(QWidget * parent, std::shared_ptr db); + explicit Training(QWidget * parent, DataBase * db); ~Training(); private: @@ -39,7 +39,7 @@ class Training : public QMainWindow { bool finished; Counter counterShell; Counter counterDea; - std::shared_ptr db; + DataBase * db; long minTimeOneRound; int minimumTime; @@ -50,8 +50,8 @@ class Training : public QMainWindow { int deltaDea; // timeModel - std::shared_ptr timeModelDea; - std::shared_ptr timeModelShell; + std::unique_ptr timeModelDea; + std::unique_ptr timeModelShell; QVector minSecTime; // shortcuts diff --git a/windowrace.cpp b/windowrace.cpp index 6303935..1387d5f 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -15,7 +15,7 @@ using std::endl; using std::string; using std::vector; -WindowRace::WindowRace(std::shared_ptr db, QWidget * parent) +WindowRace::WindowRace(DataBase * db, QWidget * parent) : QMainWindow(parent), ui(new Ui::WindowRace) { ui->setupUi(this); this->ui->pBNextRace->setEnabled(false); @@ -55,16 +55,16 @@ WindowRace::WindowRace(std::shared_ptr db, QWidget * parent) firstTimeShell = true; started = false; countdownValue = this->fahrzeit; - countdown = std::make_shared(); + countdown = std::make_unique(); - startAmpelThread = std::make_shared(); + startAmpelThread = std::make_unique(); ampelCounter = 0; ui->pBStart->setFocus(); paused = false; - Hardware = std::make_shared(); + Hardware = std::make_unique(); Hardware->start(); QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this, @@ -211,11 +211,11 @@ void WindowRace::prepareNextRace() { this->VecDea.clear(); // clear tableview shell - timeModelShell = std::make_shared(VecShell, minSecTime); + timeModelShell = std::make_unique(VecShell, minSecTime); ui->lWShellTime->setModel(timeModelShell.get()); // clear tableview dea - timeModelDea = std::make_shared(VecDea, minSecTime); + timeModelDea = std::make_unique(VecDea, minSecTime); ui->lWDeaTime->setModel(timeModelDea.get()); this->finished = false; @@ -265,13 +265,12 @@ void WindowRace::stopClicked() { this->prepareNextRace(); } -void WindowRace::setWindowRennliste( - std::shared_ptr ptrInstance) { +void WindowRace::setWindowRennliste(WindowRennliste * ptrInstance) { this->wRennliste = ptrInstance; this->wRennlisteSeted = true; - QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), - this->wRennliste.get(), SLOT(changeSelection())); + QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste, + SLOT(changeSelection())); } void WindowRace::setDriverAndCarId(vector vec) { this->shellDriverId = vec.at(0).toInt(); @@ -384,7 +383,7 @@ void WindowRace::shellSlot(int time, int sector) { test.append(1); test.append(2); test.append(3); - this->timeModelShell = std::make_shared( + this->timeModelShell = std::make_unique( VecShell, minSecTime, test, this); // this->ui->lWShellTime->setModel(this->timeModelShell); ui->lWShellTime->setModel(this->timeModelShell.get()); @@ -404,7 +403,7 @@ void WindowRace::shellSlot(int time, int sector) { test.append(1); test.append(2); test.append(3); - this->timeModelShell = std::make_shared( + this->timeModelShell = std::make_unique( VecShell, minSecTime, test, this); // timeModelShell = new // TimeModel(VecShell, this); @@ -439,7 +438,7 @@ void WindowRace::shellSlot(int time, int sector) { test.append(1); test.append(2); test.append(3); - this->timeModelShell = std::make_shared( + this->timeModelShell = std::make_unique( VecShell, minSecTime, test, this); // timeModelShell = new // TimeModel(VecShell, this); @@ -507,7 +506,7 @@ void WindowRace::deaSlot(int time, int sector) { VecDea.last().push_back(time); cout << "Dea Sektor 1" << endl; timeModelDea = - std::make_shared(VecDea, minSecTime, this); + std::make_unique(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lBridgeDea->setText(QString::number( @@ -520,7 +519,7 @@ void WindowRace::deaSlot(int time, int sector) { if (VecDea.last().size() == 1) { cout << time << sector << endl; VecDea[VecDea.size() - 1].push_back(time); - timeModelDea = std::make_shared( + timeModelDea = std::make_unique( VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lStraightDea->setText(QString::number( @@ -545,7 +544,7 @@ void WindowRace::deaSlot(int time, int sector) { VecDea.last().push_back( QVectorHelper::getCurTime(VecDea.last())); - timeModelDea = std::make_shared( + timeModelDea = std::make_unique( VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea.get()); } diff --git a/windowrace.h b/windowrace.h index e5dcf2b..acaad76 100644 --- a/windowrace.h +++ b/windowrace.h @@ -25,10 +25,9 @@ class WindowRace : public QMainWindow { Q_OBJECT public: - explicit WindowRace(std::shared_ptr db, - QWidget * parent = nullptr); + explicit WindowRace(DataBase * db, QWidget * parent = nullptr); ~WindowRace(); - void setWindowRennliste(std::shared_ptr ptrInstance); + void setWindowRennliste(WindowRennliste * ptrInstance); void setDriverAndCar(vector vec); void setDriverAndCarId(vector vec); @@ -40,8 +39,8 @@ class WindowRace : public QMainWindow { void closeEvent(QCloseEvent * event); bool started; - std::shared_ptr countdown; - std::shared_ptr Hardware; + std::unique_ptr countdown; + std::unique_ptr Hardware; Ui::WindowRace * ui; Counter counterShell; Counter counterDea; @@ -49,17 +48,17 @@ class WindowRace : public QMainWindow { bool firstTimeDea; QVector> VecShell; QVector> VecDea; - std::shared_ptr timeModelShell; - std::shared_ptr timeModelDea; + std::unique_ptr timeModelShell; + std::unique_ptr timeModelDea; long getMinimum(std::vector a); QString timeWrapper(long zahl); long countdownValue; // in sec - std::shared_ptr startAmpelThread; + std::unique_ptr startAmpelThread; int ampelCounter; bool paused; - std::shared_ptr db; + DataBase * db; bool finished; - std::shared_ptr wRennliste; + WindowRennliste * wRennliste; bool wRennlisteSeted; int fahrzeit; int renn_id; diff --git a/windowrennliste.cpp b/windowrennliste.cpp index 2a4fec9..75ec41e 100644 --- a/windowrennliste.cpp +++ b/windowrennliste.cpp @@ -11,7 +11,7 @@ using std::endl; using std::string; using std::vector; -WindowRennliste::WindowRennliste(std::shared_ptr db, QWidget * parent) +WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent) : QMainWindow(parent), ui(new Ui::WindowRennliste) { ui->setupUi(this); @@ -99,7 +99,7 @@ WindowRennliste::WindowRennliste(std::shared_ptr db, QWidget * parent) this->ui->tWRennliste->item(0, i)->setBackground(Qt::green); } } -void WindowRennliste::setWindowRace(std::shared_ptr instance) { +void WindowRennliste::setWindowRace(WindowRace * instance) { this->instanceWindowRace = instance; } vector WindowRennliste::getDriverAndCarSettings() { diff --git a/windowrennliste.h b/windowrennliste.h index 5db444c..3402320 100644 --- a/windowrennliste.h +++ b/windowrennliste.h @@ -19,11 +19,10 @@ class WindowRennliste : public QMainWindow { Q_OBJECT public: - explicit WindowRennliste(std::shared_ptr db, - QWidget * parent = nullptr); + explicit WindowRennliste(DataBase * db, QWidget * parent = nullptr); ~WindowRennliste(); void closeRaceList(); - void setWindowRace(std::shared_ptr instance); + void setWindowRace(WindowRace * instance); vector getDriverAndCarSettings(); vector getDriverAndCarId(); void sendIds(); @@ -33,10 +32,10 @@ class WindowRennliste : public QMainWindow { bool windowClose; void closeEvent(QCloseEvent * event); void setSelection(int row); - std::shared_ptr instanceWindowRace; + WindowRace * instanceWindowRace; unsigned int selectedRow; vector> tableData; - std::shared_ptr db; + DataBase * db; Ui::WindowRennliste * ui; public slots: diff --git a/windowssettings.cpp b/windowssettings.cpp index 6d89de5..4385950 100644 --- a/windowssettings.cpp +++ b/windowssettings.cpp @@ -17,7 +17,7 @@ using std::endl; using std::string; using std::vector; -WindowsSettings::WindowsSettings(std::shared_ptr db, QWidget * parent) +WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent) : QMainWindow(parent), ui(new Ui::WindowsSettings) { ui->setupUi(this); diff --git a/windowssettings.h b/windowssettings.h index 8b731ea..0c4b4c5 100644 --- a/windowssettings.h +++ b/windowssettings.h @@ -17,14 +17,13 @@ class WindowsSettings : public QMainWindow { Q_OBJECT public: - explicit WindowsSettings(std::shared_ptr db, - QWidget * parent = nullptr); + explicit WindowsSettings(DataBase * db, QWidget * parent = nullptr); ~WindowsSettings(); private: Ui::WindowsSettings * ui; string currentDateTime(); - std::shared_ptr db; + DataBase * db; int rennId; vector> carIds; vector> driversList;