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(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})

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::endl;
Evaluation::Evaluation(std::shared_ptr<DataBase> db, QWidget * parent)
Evaluation::Evaluation(DataBase * db, QWidget * parent)
: QWidget(parent), ui(new Ui::Evaluation) {
ui->setupUi(this);
this->db = db;

View File

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

View File

@@ -1,7 +1,10 @@
#include "hardwaresetup.h"
#include "sys/io.h"
// filecontrol
#include "datatypes.h"
#include <boost/asio/serial_port.hpp>
#include <fcntl.h>
#include <fmt/format.h>
#include <iostream>
#include <memory>
#include <stdint.h>
@@ -39,7 +42,7 @@ HardwareSetup::HardwareSetup() {
this->handle = nullptr;
#endif
this->fd = 0;
this->fd = -1;
}
void HardwareSetup::setStop() {
this->stop = 1;
@@ -262,34 +265,31 @@ 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<struct TransCheck> received =
std::make_shared<struct TransCheck>();
uint8_t uintBuf[sizeof(struct TransCheck)];
TransCheck * received;
sport = std::make_unique<serial_port>(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<void *>(uintBuf);
memcpy(received.get(), uintBuf, sizeof(struct TransCheck));
// voidBuf = static_cast<void *>(uintBuf);
usleep(100000); // 150ms
buffer = sport->read_frame();
received = &buffer;
// received = static_cast<struct TransCheck *>(voidBuf);
usleep(50000); // 150ms
if (received->begin == '#' && received->end == '!') {
// flash data
tcflush(fd, TCIFLUSH);
/*
cout << buffer.begin << endl;
for (int i = 0; i < 6; i++) {
cout << "i: " << i << " time: "
<< static_cast<int>(received->data[i].time)
cout << "time: " << static_cast<int>(buffer.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: "
<< static_cast<int>(received->data[i].update) << endl;
if (received->data[i].update != 0) {
@@ -298,70 +298,69 @@ void HardwareSetup::run() {
cout << "Shell Zeit 1: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Shell(static_cast<int>(received->data[i].time),
1);
emit Shell(static_cast<int>(received->data[i].time), 1);
break;
case 1:
cout << "Dea Zeit 1: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Dea(static_cast<int>(received->data[i].time),
1);
emit Dea(static_cast<int>(received->data[i].time), 1);
break;
case 2:
cout << "Shell Zeit 2: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Shell(static_cast<int>(received->data[i].time),
2);
emit Shell(static_cast<int>(received->data[i].time), 2);
break;
case 3:
cout << "Dea Zeit 2: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Dea(static_cast<int>(received->data[i].time),
2);
emit Dea(static_cast<int>(received->data[i].time), 2);
break;
case 4:
cout << "Shell Zeit 3: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Shell(static_cast<int>(received->data[i].time),
3);
emit Shell(static_cast<int>(received->data[i].time), 3);
break;
case 5:
cout << "Dea Zeit 3: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Dea(static_cast<int>(received->data[i].time),
3);
emit Dea(static_cast<int>(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

View File

@@ -2,6 +2,7 @@
#define HARDWARESETUP_H
#include <QtCore>
#include <boost/asio/serial_port.hpp>
#include <memory>
#include <stdint.h>
#include <stdio.h>
@@ -9,17 +10,9 @@
#ifdef ATMEGA
#include <libusb.h>
#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<serial_port> sport;
public:
void setStop();

View File

@@ -13,6 +13,12 @@
#include <sstream>
#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;
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<DataBase>();
// vector<vector<QString>> daten = db->getData("select * from Fahrer", 2);
this->db = std::make_unique<DataBase>();
}
void MainWindow::closeEvent(QCloseEvent * event) {
Q_UNUSED(event);
@@ -57,13 +61,15 @@ MainWindow::~MainWindow() {
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();
}
}
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();
}
@@ -108,16 +114,16 @@ void MainWindow::WindowRennen() {
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->interfaceRennliste =
std::make_shared<WindowRennliste>(this->db, this);
std::make_unique<WindowRennliste>(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<Evaluation>(this->db);
this->interfaceEvaluation = std::make_unique<Evaluation>(this->db.get());
this->interfaceEvaluation->show();
}

View File

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

View File

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

View File

@@ -22,7 +22,7 @@ using std::endl;
using std::string;
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) {
ui->setupUi(this);
this->db = db;

View File

@@ -24,8 +24,7 @@ class Result : public QWidget {
Q_OBJECT
public:
explicit Result(std::shared_ptr<DataBase> 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<ResultModel> model;
std::shared_ptr<DataBase> db;
DataBase * db;
int rennid;
int minimumTime;
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::vector;
Training::Training(QWidget * parent, std::shared_ptr<DataBase> 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<TimeModel>(VecShell, minSecTime, this);
timeModelShell = std::make_unique<TimeModel>(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<TimeModel>(VecDea, minSecTime, this);
timeModelDea = std::make_unique<TimeModel>(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<TimeModel>(VecShell, minSecTime, this);
std::make_unique<TimeModel>(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<TimeModel>(
timeModelShell = std::make_unique<TimeModel>(
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<TimeModel>(
timeModelShell = std::make_unique<TimeModel>(
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<TimeModel>(VecDea, minSecTime, this);
std::make_unique<TimeModel>(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lBridgeDeaTop->setText(QString::number(
static_cast<double>(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<TimeModel>(
timeModelDea = std::make_unique<TimeModel>(
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<TimeModel>(
timeModelDea = std::make_unique<TimeModel>(
VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get());
}

View File

@@ -18,7 +18,7 @@ class Training : public QMainWindow {
Q_OBJECT
public:
explicit Training(QWidget * parent, std::shared_ptr<DataBase> 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<DataBase> db;
DataBase * db;
long minTimeOneRound;
int minimumTime;
@@ -50,8 +50,8 @@ class Training : public QMainWindow {
int deltaDea;
// timeModel
std::shared_ptr<TimeModel> timeModelDea;
std::shared_ptr<TimeModel> timeModelShell;
std::unique_ptr<TimeModel> timeModelDea;
std::unique_ptr<TimeModel> timeModelShell;
QVector<int> minSecTime;
// shortcuts

View File

@@ -15,7 +15,7 @@ using std::endl;
using std::string;
using std::vector;
WindowRace::WindowRace(std::shared_ptr<DataBase> 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<DataBase> db, QWidget * parent)
firstTimeShell = true;
started = false;
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;
ui->pBStart->setFocus();
paused = false;
Hardware = std::make_shared<HardwareSetup>();
Hardware = std::make_unique<HardwareSetup>();
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<TimeModel>(VecShell, minSecTime);
timeModelShell = std::make_unique<TimeModel>(VecShell, minSecTime);
ui->lWShellTime->setModel(timeModelShell.get());
// clear tableview dea
timeModelDea = std::make_shared<TimeModel>(VecDea, minSecTime);
timeModelDea = std::make_unique<TimeModel>(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<WindowRennliste> 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<QString> 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<TimeModel>(
this->timeModelShell = std::make_unique<TimeModel>(
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<TimeModel>(
this->timeModelShell = std::make_unique<TimeModel>(
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<TimeModel>(
this->timeModelShell = std::make_unique<TimeModel>(
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<TimeModel>(VecDea, minSecTime, this);
std::make_unique<TimeModel>(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<TimeModel>(
timeModelDea = std::make_unique<TimeModel>(
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<TimeModel>(
timeModelDea = std::make_unique<TimeModel>(
VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get());
}

View File

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

View File

@@ -11,7 +11,7 @@ using std::endl;
using std::string;
using std::vector;
WindowRennliste::WindowRennliste(std::shared_ptr<DataBase> 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<DataBase> db, QWidget * parent)
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;
}
vector<QString> WindowRennliste::getDriverAndCarSettings() {

View File

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

View File

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

View File

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