mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
lint
This commit is contained in:
+38
-20
@@ -25,17 +25,24 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define ITERABLE_ENUM_BEGIN(name) enum class name : int {
|
#define ITERABLE_ENUM_BEGIN(name) \
|
||||||
#define ITERABLE_ENUM_END ,end, begin = 0 }
|
enum class name : int \
|
||||||
|
{
|
||||||
|
#define ITERABLE_ENUM_END \
|
||||||
|
, end, begin = 0 \
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T> class Iterable
|
||||||
class Iterable
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Iterable(T value = T::begin) : mValue(value) {}
|
Iterable(T value = T::begin) : mValue(value)
|
||||||
Iterable(const Iterable& other) : mValue(other.mValue) {}
|
{
|
||||||
|
}
|
||||||
|
Iterable(const Iterable &other) : mValue(other.mValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Iterable& operator++()
|
Iterable &operator++()
|
||||||
{
|
{
|
||||||
assert(mValue >= T::begin && mValue < T::end);
|
assert(mValue >= T::begin && mValue < T::end);
|
||||||
mValue = static_cast<T>(static_cast<int>(mValue) + 1);
|
mValue = static_cast<T>(static_cast<int>(mValue) + 1);
|
||||||
@@ -49,7 +56,7 @@ public:
|
|||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable& operator--()
|
Iterable &operator--()
|
||||||
{
|
{
|
||||||
assert(mValue >= T::end && mValue < T::begin);
|
assert(mValue >= T::end && mValue < T::begin);
|
||||||
mValue = static_cast<T>(static_cast<int>(mValue) - 1);
|
mValue = static_cast<T>(static_cast<int>(mValue) - 1);
|
||||||
@@ -83,38 +90,49 @@ public:
|
|||||||
return static_cast<T>(static_cast<int>(mValue) - static_cast<int>(i));
|
return static_cast<T>(static_cast<int>(mValue) - static_cast<int>(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator>(const T &other) const
|
||||||
bool operator >(const T& other) const
|
|
||||||
{
|
{
|
||||||
return static_cast<int>(mValue) > static_cast<int>(other);
|
return static_cast<int>(mValue) > static_cast<int>(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator >=(const T& other) const
|
bool operator>=(const T &other) const
|
||||||
{
|
{
|
||||||
return static_cast<int>(mValue) >= static_cast<int>(other);
|
return static_cast<int>(mValue) >= static_cast<int>(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator <(const T& other) const
|
bool operator<(const T &other) const
|
||||||
{
|
{
|
||||||
return static_cast<int>(mValue) < static_cast<int>(other);
|
return static_cast<int>(mValue) < static_cast<int>(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator <=(const T& other) const
|
bool operator<=(const T &other) const
|
||||||
{
|
{
|
||||||
return static_cast<int>(mValue) <= static_cast<int>(other);
|
return static_cast<int>(mValue) <= static_cast<int>(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(const T& other) const
|
bool operator==(const T &other) const
|
||||||
{
|
{
|
||||||
return static_cast<int>(mValue) == static_cast<int>(other);
|
return static_cast<int>(mValue) == static_cast<int>(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool valid() const { return mValue != T::end; }
|
bool valid() const
|
||||||
|
{
|
||||||
|
return mValue != T::end;
|
||||||
|
}
|
||||||
|
|
||||||
operator T() const { return mValue; }
|
operator T() const
|
||||||
operator T&() { return mValue; }
|
{
|
||||||
T val() const { return mValue; }
|
return mValue;
|
||||||
|
}
|
||||||
|
operator T &()
|
||||||
|
{
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
T val() const
|
||||||
|
{
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T mValue;
|
T mValue;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
#include "better_radiobutton.h"
|
#include "better_radiobutton.h"
|
||||||
|
|
||||||
Better_Radiobutton::Better_Radiobutton(QWidget* parent) :
|
Better_Radiobutton::Better_Radiobutton(QWidget *parent) : QWidget{parent}, m_radiobuttons{}
|
||||||
QWidget{parent},
|
|
||||||
m_radiobuttons{}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Better_Radiobutton::Better_Radiobutton(std::vector<QString> names, QWidget* parent) :
|
Better_Radiobutton::Better_Radiobutton(std::vector<QString> names, QWidget *parent)
|
||||||
QWidget{parent},
|
: QWidget{parent}, m_v_layout{new QVBoxLayout(this)}, m_radiobuttons{}, m_checked{""}
|
||||||
m_v_layout{new QVBoxLayout(this)},
|
|
||||||
m_radiobuttons{},
|
|
||||||
m_checked{""}
|
|
||||||
{
|
{
|
||||||
for (const auto& name : names) {
|
for (const auto &name : names)
|
||||||
|
{
|
||||||
add_radiobutton(name);
|
add_radiobutton(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +21,8 @@ void Better_Radiobutton::add_radiobutton(QString name)
|
|||||||
|
|
||||||
connect(radiobutton, &QRadioButton::toggled, this, [this, name, radiobutton] {
|
connect(radiobutton, &QRadioButton::toggled, this, [this, name, radiobutton] {
|
||||||
emit toggled(name);
|
emit toggled(name);
|
||||||
if (radiobutton->isChecked()) {
|
if (radiobutton->isChecked())
|
||||||
|
{
|
||||||
m_checked = name;
|
m_checked = name;
|
||||||
emit checked(name);
|
emit checked(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#ifndef BETTER_RADIOBUTTON_H
|
#ifndef BETTER_RADIOBUTTON_H
|
||||||
#define BETTER_RADIOBUTTON_H
|
#define BETTER_RADIOBUTTON_H
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
class Better_Radiobutton : public QWidget {
|
class Better_Radiobutton : public QWidget
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Better_Radiobutton(QWidget* parent = nullptr);
|
explicit Better_Radiobutton(QWidget *parent = nullptr);
|
||||||
explicit Better_Radiobutton(std::vector<QString>names, QWidget* partent = nullptr);
|
explicit Better_Radiobutton(std::vector<QString> names, QWidget *partent = nullptr);
|
||||||
|
|
||||||
void add_radiobutton(QString name);
|
void add_radiobutton(QString name);
|
||||||
QString isChecked() const;
|
QString isChecked() const;
|
||||||
@@ -16,9 +17,10 @@ class Better_Radiobutton : public QWidget {
|
|||||||
signals:
|
signals:
|
||||||
void toggled(QString name);
|
void toggled(QString name);
|
||||||
void checked(QString name);
|
void checked(QString name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* m_v_layout;
|
QVBoxLayout *m_v_layout;
|
||||||
std::vector<QRadioButton*> m_radiobuttons;
|
std::vector<QRadioButton *> m_radiobuttons;
|
||||||
QString m_checked;
|
QString m_checked;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+17
-13
@@ -1,27 +1,31 @@
|
|||||||
#include "can_transceive.h"
|
#include "can_transceive.h"
|
||||||
#include "ui_can_transceive.h"
|
#include "ui_can_transceive.h"
|
||||||
|
|
||||||
Can_Transceive::Can_Transceive(QWidget* parent) : QWidget(parent), ui(new Ui::Can_Transceive) {
|
Can_Transceive::Can_Transceive(QWidget *parent) : QWidget(parent), ui(new Ui::Can_Transceive)
|
||||||
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
can_send_hexspinboxes = {
|
can_send_hexspinboxes = {
|
||||||
ui->s_can_send_data0,
|
ui->s_can_send_data0, ui->s_can_send_data1, ui->s_can_send_data2, ui->s_can_send_data3,
|
||||||
ui->s_can_send_data1,
|
ui->s_can_send_data4, ui->s_can_send_data5, ui->s_can_send_data6, ui->s_can_send_data7,
|
||||||
ui->s_can_send_data2,
|
|
||||||
ui->s_can_send_data3,
|
|
||||||
ui->s_can_send_data4,
|
|
||||||
ui->s_can_send_data5,
|
|
||||||
ui->s_can_send_data6,
|
|
||||||
ui->s_can_send_data7,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enable_can_send_data();
|
enable_can_send_data();
|
||||||
connect(ui->c_can_send_dlc, &QComboBox::currentIndexChanged, this, [=, this]{enable_can_send_data();});
|
connect(ui->c_can_send_dlc, &QComboBox::currentIndexChanged, this, [=, this] { enable_can_send_data(); });
|
||||||
connect(ui->b_can_send_send, &QPushButton::clicked, this, [=, this]{emit send_can_message(ui->s_can_send_sid->value(), ui->c_can_send_dlc->currentIndex(), std::array<uint8_t, 8>({(uint8_t)(can_send_hexspinboxes[0]->value()), (uint8_t)(can_send_hexspinboxes[1]->value()),(uint8_t)(can_send_hexspinboxes[2]->value()),(uint8_t)(can_send_hexspinboxes[3]->value()),(uint8_t)(can_send_hexspinboxes[4]->value()),(uint8_t)(can_send_hexspinboxes[5]->value()),(uint8_t)(can_send_hexspinboxes[6]->value()),(uint8_t)(can_send_hexspinboxes[7]->value())}));});
|
connect(ui->b_can_send_send, &QPushButton::clicked, this, [=, this] {
|
||||||
connect(ui->b_clear, &QPushButton::clicked, this, [=, this]{emit can_clear();});
|
emit send_can_message(
|
||||||
|
ui->s_can_send_sid->value(), ui->c_can_send_dlc->currentIndex(),
|
||||||
|
std::array<uint8_t, 8>(
|
||||||
|
{(uint8_t)(can_send_hexspinboxes[0]->value()), (uint8_t)(can_send_hexspinboxes[1]->value()),
|
||||||
|
(uint8_t)(can_send_hexspinboxes[2]->value()), (uint8_t)(can_send_hexspinboxes[3]->value()),
|
||||||
|
(uint8_t)(can_send_hexspinboxes[4]->value()), (uint8_t)(can_send_hexspinboxes[5]->value()),
|
||||||
|
(uint8_t)(can_send_hexspinboxes[6]->value()), (uint8_t)(can_send_hexspinboxes[7]->value())}));
|
||||||
|
});
|
||||||
|
connect(ui->b_clear, &QPushButton::clicked, this, [=, this] { emit can_clear(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
Can_Transceive::~Can_Transceive() {
|
Can_Transceive::~Can_Transceive()
|
||||||
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
#ifndef CAN_TRANSCEIVE_H
|
#ifndef CAN_TRANSCEIVE_H
|
||||||
#define CAN_TRANSCEIVE_H
|
#define CAN_TRANSCEIVE_H
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include "hex_spinbox.h"
|
#include "hex_spinbox.h"
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class Can_Transceive;
|
class Can_Transceive;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Can_Transceive : public QWidget {
|
class Can_Transceive : public QWidget
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Can_Transceive(QWidget* parent = nullptr);
|
explicit Can_Transceive(QWidget *parent = nullptr);
|
||||||
~Can_Transceive();
|
~Can_Transceive();
|
||||||
void enable_can_send_data();
|
void enable_can_send_data();
|
||||||
void clear();
|
void clear();
|
||||||
@@ -24,8 +26,8 @@ class Can_Transceive : public QWidget {
|
|||||||
void can_clear();
|
void can_clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Can_Transceive* ui;
|
Ui::Can_Transceive *ui;
|
||||||
std::vector<HexSpinBox*> can_send_hexspinboxes;
|
std::vector<HexSpinBox *> can_send_hexspinboxes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CAN_TRANSCEIVE_H
|
#endif // CAN_TRANSCEIVE_H
|
||||||
|
|||||||
+21
-16
@@ -1,40 +1,42 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
void create_dial_needle(QwtDial* dial)
|
void create_dial_needle(QwtDial *dial)
|
||||||
{
|
{
|
||||||
QwtDialSimpleNeedle* needle = new QwtDialSimpleNeedle(
|
QwtDialSimpleNeedle *needle =
|
||||||
QwtDialSimpleNeedle::Arrow, true, Qt::yellow,
|
new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::yellow, QColor(Qt::gray).lighter(130));
|
||||||
QColor( Qt::gray ).lighter( 130 ) );
|
|
||||||
needle->setWidth(2);
|
needle->setWidth(2);
|
||||||
dial->setNeedle( needle );
|
dial->setNeedle(needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_widget_color(QWidget* widget, QColor color, QColor bg)
|
void set_widget_color(QWidget *widget, QColor color, QColor bg)
|
||||||
{
|
{
|
||||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(widget->objectName(), bg.name(), color.name());
|
QString style =
|
||||||
|
QString("#%1 { background-color: %2; color: %3;}").arg(widget->objectName(), bg.name(), color.name());
|
||||||
|
|
||||||
widget->setStyleSheet(style);
|
widget->setStyleSheet(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_widget_color(QWidget* widget, QString color, QString bg)
|
void set_widget_color(QWidget *widget, QString color, QString bg)
|
||||||
{
|
{
|
||||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(widget->objectName(), bg, color);
|
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(widget->objectName(), bg, color);
|
||||||
|
|
||||||
widget->setStyleSheet(style);
|
widget->setStyleSheet(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor widget_bg_color(QWidget* widget)
|
QColor widget_bg_color(QWidget *widget)
|
||||||
{
|
{
|
||||||
std::string input = widget->styleSheet().toStdString();
|
std::string input = widget->styleSheet().toStdString();
|
||||||
QColor background_color;
|
QColor background_color;
|
||||||
|
|
||||||
// Find the position of "background-color:"
|
// Find the position of "background-color:"
|
||||||
size_t bg_pos = input.find("background-color:");
|
size_t bg_pos = input.find("background-color:");
|
||||||
if (bg_pos != std::string::npos) {
|
if (bg_pos != std::string::npos)
|
||||||
|
{
|
||||||
// Find the end position of the background color value
|
// Find the end position of the background color value
|
||||||
size_t bg_value_start = bg_pos + 17; // Length of "background-color:" is 17
|
size_t bg_value_start = bg_pos + 17; // Length of "background-color:" is 17
|
||||||
size_t bg_value_end = input.find(";", bg_value_start);
|
size_t bg_value_end = input.find(";", bg_value_start);
|
||||||
if (bg_value_end != std::string::npos) {
|
if (bg_value_end != std::string::npos)
|
||||||
|
{
|
||||||
background_color = QColor(input.substr(bg_value_start, bg_value_end - bg_value_start).c_str());
|
background_color = QColor(input.substr(bg_value_start, bg_value_end - bg_value_start).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,32 +44,35 @@ QColor widget_bg_color(QWidget* widget)
|
|||||||
return background_color;
|
return background_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor widget_color(QWidget* widget)
|
QColor widget_color(QWidget *widget)
|
||||||
{
|
{
|
||||||
std::string input = widget->styleSheet().toStdString();
|
std::string input = widget->styleSheet().toStdString();
|
||||||
QColor color;
|
QColor color;
|
||||||
|
|
||||||
// Find the position of "color:"
|
// Find the position of "color:"
|
||||||
size_t color_pos = input.find(" color:");
|
size_t color_pos = input.find(" color:");
|
||||||
if (color_pos != std::string::npos) {
|
if (color_pos != std::string::npos)
|
||||||
|
{
|
||||||
// Find the end position of the text color value
|
// Find the end position of the text color value
|
||||||
size_t color_value_start = color_pos + 7; // Length of "color:" is 7
|
size_t color_value_start = color_pos + 7; // Length of "color:" is 7
|
||||||
size_t color_value_end = input.find(";", color_value_start);
|
size_t color_value_end = input.find(";", color_value_start);
|
||||||
if (color_value_end != std::string::npos) {
|
if (color_value_end != std::string::npos)
|
||||||
|
{
|
||||||
color = QColor(input.substr(color_value_start, color_value_end - color_value_start).c_str());
|
color = QColor(input.substr(color_value_start, color_value_end - color_value_start).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_widget_color(QWidget* widget)
|
void reset_widget_color(QWidget *widget)
|
||||||
{
|
{
|
||||||
widget->setStyleSheet("");
|
widget->setStyleSheet("");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString network_reply_to_fix(QNetworkReply::NetworkError error)
|
QString network_reply_to_fix(QNetworkReply::NetworkError error)
|
||||||
{
|
{
|
||||||
switch (error) {
|
switch (error)
|
||||||
|
{
|
||||||
case QNetworkReply::NetworkError::ConnectionRefusedError:
|
case QNetworkReply::NetworkError::ConnectionRefusedError:
|
||||||
return "Make sure the server is started ($ systemctl status unocan_server)";
|
return "Make sure the server is started ($ systemctl status unocan_server)";
|
||||||
break;
|
break;
|
||||||
|
|||||||
+8
-8
@@ -1,24 +1,24 @@
|
|||||||
#ifndef HELPERS_H
|
#ifndef HELPERS_H
|
||||||
#define HELPERS_H
|
#define HELPERS_H
|
||||||
|
|
||||||
|
#include <QNetworkReply>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <qwt_color_map.h>
|
#include <qwt_color_map.h>
|
||||||
#include <qwt_dial.h>
|
#include <qwt_dial.h>
|
||||||
#include <qwt_dial_needle.h>
|
#include <qwt_dial_needle.h>
|
||||||
#include <qwt_plot.h>
|
#include <qwt_plot.h>
|
||||||
#include <qwt_plot_curve.h>
|
#include <qwt_plot_curve.h>
|
||||||
#include <qwt_slider.h>
|
|
||||||
#include <qwt_series_data.h>
|
#include <qwt_series_data.h>
|
||||||
|
#include <qwt_slider.h>
|
||||||
#include <qwt_thermo.h>
|
#include <qwt_thermo.h>
|
||||||
#include <QNetworkReply>
|
|
||||||
|
|
||||||
void create_dial_needle(QwtDial* dial);
|
void create_dial_needle(QwtDial *dial);
|
||||||
|
|
||||||
void set_widget_color(QWidget* widget, QColor color, QColor bg);
|
void set_widget_color(QWidget *widget, QColor color, QColor bg);
|
||||||
void set_widget_color(QWidget* widget, QString color, QString bg);
|
void set_widget_color(QWidget *widget, QString color, QString bg);
|
||||||
QColor widget_bg_color(QWidget* widget);
|
QColor widget_bg_color(QWidget *widget);
|
||||||
QColor widget_color(QWidget* widget);
|
QColor widget_color(QWidget *widget);
|
||||||
void reset_widget_color(QWidget* widget);
|
void reset_widget_color(QWidget *widget);
|
||||||
QString network_reply_to_fix(QNetworkReply::NetworkError error);
|
QString network_reply_to_fix(QNetworkReply::NetworkError error);
|
||||||
|
|
||||||
#endif // HELPERS_H
|
#endif // HELPERS_H
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#include "hex_spinbox.h"
|
#include "hex_spinbox.h"
|
||||||
|
|
||||||
HexSpinBox::HexSpinBox(QWidget *parent,
|
HexSpinBox::HexSpinBox(QWidget *parent, bool showPrefix, const QString &format) : QSpinBox(parent), format(format)
|
||||||
bool showPrefix,
|
|
||||||
const QString &format) :
|
|
||||||
QSpinBox(parent),
|
|
||||||
format(format)
|
|
||||||
{
|
{
|
||||||
// Validates hex strings up to 8 chars with or w/out leading "0x" prefix.
|
// Validates hex strings up to 8 chars with or w/out leading "0x" prefix.
|
||||||
// For arbitrary prefix/suffix, the regex could be built dynamically
|
// For arbitrary prefix/suffix, the regex could be built dynamically
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#ifndef _HEXSPINBOX_H_
|
#ifndef _HEXSPINBOX_H_
|
||||||
#define _HEXSPINBOX_H_
|
#define _HEXSPINBOX_H_
|
||||||
|
|
||||||
#include <QSpinBox>
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QRegularExpressionValidator>
|
#include <QRegularExpressionValidator>
|
||||||
|
#include <QSpinBox>
|
||||||
|
|
||||||
// NOTE: Since QSpinBox uses int as the storage type, the effective editing range
|
// NOTE: Since QSpinBox uses int as the storage type, the effective editing range
|
||||||
// is +/- 0x7FFF FFFF, so it can't handle a full unsigned int.
|
// is +/- 0x7FFF FFFF, so it can't handle a full unsigned int.
|
||||||
@@ -13,9 +13,7 @@ class HexSpinBox : public QSpinBox
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HexSpinBox(QWidget *parent = nullptr,
|
HexSpinBox(QWidget *parent = nullptr, bool showPrefix = false, const QString &format = QStringLiteral("%X"));
|
||||||
bool showPrefix = false,
|
|
||||||
const QString &format = QStringLiteral("%X"));
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setShowPrefix(bool show);
|
void setShowPrefix(bool show);
|
||||||
|
|||||||
+4
-6
@@ -1,7 +1,6 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
Led::Led(QWidget* parrent)
|
Led::Led(QWidget *parrent) : QPushButton(parrent)
|
||||||
: QPushButton(parrent)
|
|
||||||
{
|
{
|
||||||
set_read_only(this, true);
|
set_read_only(this, true);
|
||||||
}
|
}
|
||||||
@@ -11,22 +10,21 @@ Led::Led(const QString &text, QWidget *parent)
|
|||||||
set_read_only(this, true);
|
set_read_only(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Led::Led(const QIcon& icon, const QString &text, QWidget *parent)
|
Led::Led(const QIcon &icon, const QString &text, QWidget *parent)
|
||||||
{
|
{
|
||||||
set_read_only(this, true);
|
set_read_only(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Led::~Led()
|
Led::~Led()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Led::is_read_only(QWidget* widget)
|
bool Led::is_read_only(QWidget *widget)
|
||||||
{
|
{
|
||||||
return widget->testAttribute(Qt::WA_TransparentForMouseEvents) || (widget->focusPolicy() == Qt::NoFocus);
|
return widget->testAttribute(Qt::WA_TransparentForMouseEvents) || (widget->focusPolicy() == Qt::NoFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Led::set_read_only(QWidget* widget, bool read_only)
|
void Led::set_read_only(QWidget *widget, bool read_only)
|
||||||
{
|
{
|
||||||
widget->setAttribute(Qt::WA_TransparentForMouseEvents, read_only);
|
widget->setAttribute(Qt::WA_TransparentForMouseEvents, read_only);
|
||||||
widget->setFocusPolicy(read_only ? Qt::NoFocus : Qt::StrongFocus);
|
widget->setFocusPolicy(read_only ? Qt::NoFocus : Qt::StrongFocus);
|
||||||
|
|||||||
+6
-4
@@ -3,16 +3,18 @@
|
|||||||
|
|
||||||
#include "QPushButton"
|
#include "QPushButton"
|
||||||
|
|
||||||
class Led : public QPushButton {
|
class Led : public QPushButton
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Led(QWidget *parent = nullptr);
|
explicit Led(QWidget *parent = nullptr);
|
||||||
explicit Led(const QString &text, QWidget *parent = nullptr);
|
explicit Led(const QString &text, QWidget *parent = nullptr);
|
||||||
Led(const QIcon& icon, const QString &text, QWidget *parent = nullptr);
|
Led(const QIcon &icon, const QString &text, QWidget *parent = nullptr);
|
||||||
~Led();
|
~Led();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_read_only(QWidget* widget);
|
bool is_read_only(QWidget *widget);
|
||||||
void set_read_only(QWidget* widget, bool read_only);
|
void set_read_only(QWidget *widget, bool read_only);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LED_H
|
#endif // LED_H
|
||||||
|
|||||||
+4
-3
@@ -1,15 +1,16 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include <QApplication>
|
|
||||||
#include "spdlog/async.h"
|
#include "spdlog/async.h"
|
||||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
void init_logger()
|
void init_logger()
|
||||||
{
|
{
|
||||||
spdlog::init_thread_pool(8192, 1);
|
spdlog::init_thread_pool(8192, 1);
|
||||||
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
//auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("log-sim_us.txt", 1024 * 1024 * 10, 3);
|
// auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("log-sim_us.txt", 1024 * 1024 * 10,
|
||||||
std::vector<spdlog::sink_ptr> sinks{stdout_sink/*, rotating_sink*/};
|
// 3);
|
||||||
|
std::vector<spdlog::sink_ptr> sinks{stdout_sink /*, rotating_sink*/};
|
||||||
auto logger = std::make_shared<spdlog::async_logger>("sim_us", sinks.begin(), sinks.end(), spdlog::thread_pool(),
|
auto logger = std::make_shared<spdlog::async_logger>("sim_us", sinks.begin(), sinks.end(), spdlog::thread_pool(),
|
||||||
spdlog::async_overflow_policy::block);
|
spdlog::async_overflow_policy::block);
|
||||||
spdlog::set_default_logger(logger);
|
spdlog::set_default_logger(logger);
|
||||||
|
|||||||
+23
-20
@@ -1,17 +1,15 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#include "sim-scope_mux_tester.h"
|
|
||||||
#include "sim-can_debugger.h"
|
#include "sim-can_debugger.h"
|
||||||
#include "sim-cvs_i10.h"
|
#include "sim-cvs_i10.h"
|
||||||
|
#include "sim-scope_mux_tester.h"
|
||||||
#include "sim-test.h"
|
#include "sim-test.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QString host, uint16_t port, QWidget *parent) :
|
MainWindow::MainWindow(QString host, uint16_t port, QWidget *parent)
|
||||||
QMainWindow(parent),
|
: QMainWindow(parent), ui(new Ui::MainWindow),
|
||||||
ui(new Ui::MainWindow),
|
|
||||||
m_web_socket(new Web_socket_wrapper(QUrl("ws://" + host + ":" + QString::number(port)), this)),
|
m_web_socket(new Web_socket_wrapper(QUrl("ws://" + host + ":" + QString::number(port)), this)),
|
||||||
m_error_dialog(new NetworkError(this)),
|
m_error_dialog(new NetworkError(this)), m_sims{{"Can_Debugger", new Can_Debugger(m_web_socket, this)},
|
||||||
m_sims{{"Can_Debugger", new Can_Debugger(m_web_socket, this)},
|
|
||||||
{"Scope_Mux_Tester", new Scope_Mux_Tester(m_web_socket, this)},
|
{"Scope_Mux_Tester", new Scope_Mux_Tester(m_web_socket, this)},
|
||||||
{"CVS_I10", new CVS_I10(m_web_socket, this)},
|
{"CVS_I10", new CVS_I10(m_web_socket, this)},
|
||||||
{"Test_Sim", new Test_Sim(m_web_socket, this)}}
|
{"Test_Sim", new Test_Sim(m_web_socket, this)}}
|
||||||
@@ -21,10 +19,10 @@ MainWindow::MainWindow(QString host, uint16_t port, QWidget *parent) :
|
|||||||
|
|
||||||
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
||||||
ui->connection->setText("Connected to ws://" + host + ":" + QString::number(port));
|
ui->connection->setText("Connected to ws://" + host + ":" + QString::number(port));
|
||||||
//Default sim
|
// Default sim
|
||||||
//defaultSim("CVS_I10");
|
// defaultSim("CVS_I10");
|
||||||
|
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, [=, this]{open_sim(ui->comboBox->currentText());});
|
connect(ui->pushButton, &QPushButton::clicked, this, [=, this] { open_sim(ui->comboBox->currentText()); });
|
||||||
connect(this, &MainWindow::quit, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
connect(this, &MainWindow::quit, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,18 +35,22 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
void MainWindow::setup_cb(void)
|
void MainWindow::setup_cb(void)
|
||||||
{
|
{
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json& j){on_cmd_cb(j);});
|
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_connected, this, [=, this]{m_web_socket->send_command(Web_socket_wrapper::Command::get_simulators);});
|
connect(m_web_socket, &Web_socket_wrapper::on_connected, this,
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this]{m_error_dialog->open(); ui->connection->setText("Could not connect to the server");});
|
[=, this] { m_web_socket->send_command(Web_socket_wrapper::Command::get_simulators); });
|
||||||
|
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this] {
|
||||||
|
m_error_dialog->open();
|
||||||
|
ui->connection->setText("Could not connect to the server");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showEvent( QShowEvent* event )
|
void MainWindow::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::showEvent( event );
|
QWidget::showEvent(event);
|
||||||
setup_cb();
|
setup_cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::hideEvent(QHideEvent* event)
|
void MainWindow::hideEvent(QHideEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::hideEvent(event);
|
QWidget::hideEvent(event);
|
||||||
disconnect(m_web_socket, nullptr, nullptr, nullptr);
|
disconnect(m_web_socket, nullptr, nullptr, nullptr);
|
||||||
@@ -60,9 +62,9 @@ void MainWindow::defaultSim(QString name)
|
|||||||
this->m_default_sim = true;
|
this->m_default_sim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::pase_sim_names(json& sims)
|
void MainWindow::pase_sim_names(json &sims)
|
||||||
{
|
{
|
||||||
for (json& item : sims)
|
for (json &item : sims)
|
||||||
{
|
{
|
||||||
ui->comboBox->addItem(QString::fromStdString(item));
|
ui->comboBox->addItem(QString::fromStdString(item));
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ void MainWindow::open_sim(QString sim_name)
|
|||||||
m_selected_sim = m_sims.at(sim_name);
|
m_selected_sim = m_sims.at(sim_name);
|
||||||
this->m_selected_sim_name = sim_name;
|
this->m_selected_sim_name = sim_name;
|
||||||
}
|
}
|
||||||
catch (const std::out_of_range& ex)
|
catch (const std::out_of_range &ex)
|
||||||
{
|
{
|
||||||
SPDLOG_CRITICAL("out_of_range: {}", ex.what());
|
SPDLOG_CRITICAL("out_of_range: {}", ex.what());
|
||||||
return;
|
return;
|
||||||
@@ -120,9 +122,10 @@ void MainWindow::check_active_sim(QString name)
|
|||||||
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, m_selected_sim_name);
|
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, m_selected_sim_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_cmd_cb(json& j)
|
void MainWindow::on_cmd_cb(json &j)
|
||||||
{
|
{
|
||||||
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type"))).value_or(Web_socket_wrapper::Command::end);
|
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type")))
|
||||||
|
.value_or(Web_socket_wrapper::Command::end);
|
||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case Web_socket_wrapper::Command::get_simulators:
|
case Web_socket_wrapper::Command::get_simulators:
|
||||||
|
|||||||
+15
-13
@@ -1,13 +1,14 @@
|
|||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include "web_socket_wrapper.h"
|
|
||||||
#include "networkerror.h"
|
#include "networkerror.h"
|
||||||
#include "simulator_base.h"
|
#include "simulator_base.h"
|
||||||
|
#include "web_socket_wrapper.h"
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ class MainWindow : public QMainWindow
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
void defaultSim(QString name);
|
void defaultSim(QString name);
|
||||||
void pase_sim_names(json& sims);
|
void pase_sim_names(json &sims);
|
||||||
void open_sim_window(void);
|
void open_sim_window(void);
|
||||||
void check_active_sim(QString name);
|
void check_active_sim(QString name);
|
||||||
void open_sim(QString sim_name);
|
void open_sim(QString sim_name);
|
||||||
@@ -28,20 +29,21 @@ class MainWindow : public QMainWindow
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void quit(void);
|
void quit(void);
|
||||||
private:
|
|
||||||
void showEvent(QShowEvent* event);
|
|
||||||
void hideEvent(QHideEvent* event);
|
|
||||||
|
|
||||||
void on_cmd_cb(json& j);
|
private:
|
||||||
|
void showEvent(QShowEvent *event);
|
||||||
|
void hideEvent(QHideEvent *event);
|
||||||
|
|
||||||
|
void on_cmd_cb(json &j);
|
||||||
|
|
||||||
bool m_default_sim = false;
|
bool m_default_sim = false;
|
||||||
QString m_selected_sim_name;
|
QString m_selected_sim_name;
|
||||||
QMainWindow* m_selected_sim;
|
QMainWindow *m_selected_sim;
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow *ui;
|
||||||
Web_socket_wrapper *m_web_socket;
|
Web_socket_wrapper *m_web_socket;
|
||||||
NetworkError* m_error_dialog;
|
NetworkError *m_error_dialog;
|
||||||
|
|
||||||
std::map<QString, SimulatorBase*> m_sims;
|
std::map<QString, SimulatorBase *> m_sims;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include "networkerror.h"
|
#include "networkerror.h"
|
||||||
#include "ui_networkerror.h"
|
#include "ui_networkerror.h"
|
||||||
|
|
||||||
NetworkError::NetworkError(QWidget* parent) : QDialog(parent), ui(new Ui::NetworkError) {
|
NetworkError::NetworkError(QWidget *parent) : QDialog(parent), ui(new Ui::NetworkError)
|
||||||
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->exit, &QPushButton::clicked, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
connect(ui->exit, &QPushButton::clicked, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
||||||
connect(ui->close, &QPushButton::clicked, this, [=, this]{this->close();});
|
connect(ui->close, &QPushButton::clicked, this, [=, this] { this->close(); });
|
||||||
|
|
||||||
this->setWindowTitle("Error");
|
this->setWindowTitle("Error");
|
||||||
}
|
}
|
||||||
@@ -14,6 +15,7 @@ void NetworkError::set_error(QString error)
|
|||||||
ui->Error->setText(error);
|
ui->Error->setText(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkError::~NetworkError() {
|
NetworkError::~NetworkError()
|
||||||
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,22 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class NetworkError;
|
class NetworkError;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkError : public QDialog {
|
class NetworkError : public QDialog
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NetworkError(QWidget* parent = nullptr);
|
explicit NetworkError(QWidget *parent = nullptr);
|
||||||
void set_error(QString error);
|
void set_error(QString error);
|
||||||
~NetworkError();
|
~NetworkError();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::NetworkError* ui;
|
Ui::NetworkError *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETWORKERROR_H
|
#endif // NETWORKERROR_H
|
||||||
|
|||||||
+74
-77
@@ -1,36 +1,34 @@
|
|||||||
#include "simulator_base.h"
|
#include "simulator_base.h"
|
||||||
#include "can_transceive.h"
|
#include "can_transceive.h"
|
||||||
|
|
||||||
SimulatorBase::SimulatorBase(Web_socket_wrapper* web_socket, QWidget* parent) :
|
SimulatorBase::SimulatorBase(Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
QMainWindow{parent},
|
: QMainWindow{parent}, m_error_dialog(new NetworkError(this)), m_timer_update(new QTimer()),
|
||||||
m_error_dialog(new NetworkError(this)),
|
|
||||||
m_timer_update(new QTimer()),
|
|
||||||
m_web_socket(web_socket)
|
m_web_socket(web_socket)
|
||||||
{
|
{
|
||||||
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
m_error_dialog->set_error("Connection timed out\nCheck if the server is running");
|
||||||
m_ui_lookup.reserve(40);
|
m_ui_lookup.reserve(40);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* SimulatorBase::id_to_ui(size_t id)
|
QWidget *SimulatorBase::id_to_ui(size_t id)
|
||||||
{
|
{
|
||||||
return m_ui_lookup.at(id);
|
return m_ui_lookup.at(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::showEvent( QShowEvent* event )
|
void SimulatorBase::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::showEvent( event );
|
QWidget::showEvent(event);
|
||||||
SPDLOG_DEBUG("Connecting callbacks");
|
SPDLOG_DEBUG("Connecting callbacks");
|
||||||
|
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json& j){on_cmd_cb(j);});
|
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json &j) { on_cmd_cb(j); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json& j){on_event_cb(j);});
|
connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json &j) { on_event_cb(j); });
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this]{m_error_dialog->open();});
|
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this] { m_error_dialog->open(); });
|
||||||
|
|
||||||
m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements);
|
m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements);
|
||||||
this->m_timer_update->start(m_refresh_rate);
|
this->m_timer_update->start(m_refresh_rate);
|
||||||
m_open = true;
|
m_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::closeEvent(QCloseEvent* event)
|
void SimulatorBase::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
if (m_open == true)
|
if (m_open == true)
|
||||||
{
|
{
|
||||||
@@ -43,9 +41,10 @@ void SimulatorBase::closeEvent(QCloseEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::on_cmd_cb(json& j)
|
void SimulatorBase::on_cmd_cb(json &j)
|
||||||
{
|
{
|
||||||
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type"))).value_or(Web_socket_wrapper::Command::end);
|
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type")))
|
||||||
|
.value_or(Web_socket_wrapper::Command::end);
|
||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case Web_socket_wrapper::Command::get_UI_elements:
|
case Web_socket_wrapper::Command::get_UI_elements:
|
||||||
@@ -57,9 +56,10 @@ void SimulatorBase::on_cmd_cb(json& j)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::on_event_cb(json& j)
|
void SimulatorBase::on_event_cb(json &j)
|
||||||
{
|
{
|
||||||
auto response = magic_enum::enum_cast<Web_socket_wrapper::Event>(std::string(j.at("type"))).value_or(Web_socket_wrapper::Event::end);
|
auto response = magic_enum::enum_cast<Web_socket_wrapper::Event>(std::string(j.at("type")))
|
||||||
|
.value_or(Web_socket_wrapper::Event::end);
|
||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case Web_socket_wrapper::Event::ui_changed:
|
case Web_socket_wrapper::Event::ui_changed:
|
||||||
@@ -70,15 +70,15 @@ void SimulatorBase::on_event_cb(json& j)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::push_ui_item(QWidget* item)
|
void SimulatorBase::push_ui_item(QWidget *item)
|
||||||
{
|
{
|
||||||
m_ui_lookup.emplace_back(item);
|
m_ui_lookup.emplace_back(item);
|
||||||
setup_ui_item(item, m_ui_lookup.size() - 1);
|
setup_ui_item(item, m_ui_lookup.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::UI_item_parser(json& input)
|
void SimulatorBase::UI_item_parser(json &input)
|
||||||
{
|
{
|
||||||
for (auto& uiItem : input["UI_items"])
|
for (auto &uiItem : input["UI_items"])
|
||||||
{
|
{
|
||||||
if (uiItem["type"] == "UI_button")
|
if (uiItem["type"] == "UI_button")
|
||||||
{
|
{
|
||||||
@@ -133,16 +133,16 @@ void SimulatorBase::UI_item_parser(json& input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_label(json& uiItem)
|
void SimulatorBase::process_ui_label(json &uiItem)
|
||||||
{
|
{
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto label = qobject_cast<QLabel*>(widget);
|
auto label = qobject_cast<QLabel *>(widget);
|
||||||
if (label == nullptr)
|
if (label == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type QLabel");
|
SPDLOG_WARN("widget is not of type QLabel");
|
||||||
@@ -157,17 +157,17 @@ void SimulatorBase::process_ui_label(json& uiItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_slider(json& uiItem)
|
void SimulatorBase::process_ui_slider(json &uiItem)
|
||||||
{
|
{
|
||||||
QLabel* label = id_to_label(uiItem["id"]);
|
QLabel *label = id_to_label(uiItem["id"]);
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto slider = qobject_cast<QwtSlider*>(widget);
|
auto slider = qobject_cast<QwtSlider *>(widget);
|
||||||
if (slider == nullptr)
|
if (slider == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type QwtSlider");
|
SPDLOG_WARN("widget is not of type QwtSlider");
|
||||||
@@ -197,21 +197,21 @@ void SimulatorBase::process_ui_slider(json& uiItem)
|
|||||||
{
|
{
|
||||||
slider->setVisible(visible);
|
slider->setVisible(visible);
|
||||||
}
|
}
|
||||||
//TODO: Add color for scale
|
// TODO: Add color for scale
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_dial(json& uiItem)
|
void SimulatorBase::process_ui_dial(json &uiItem)
|
||||||
{
|
{
|
||||||
QLabel* label = id_to_label(uiItem["id"]);
|
QLabel *label = id_to_label(uiItem["id"]);
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dial = qobject_cast<QwtDial*>(widget);
|
auto dial = qobject_cast<QwtDial *>(widget);
|
||||||
if (dial == nullptr)
|
if (dial == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type QwtDial");
|
SPDLOG_WARN("widget is not of type QwtDial");
|
||||||
@@ -231,7 +231,6 @@ void SimulatorBase::process_ui_dial(json& uiItem)
|
|||||||
dial->setValue(value);
|
dial->setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dial->isVisible() != visible)
|
if (dial->isVisible() != visible)
|
||||||
{
|
{
|
||||||
dial->setVisible(visible);
|
dial->setVisible(visible);
|
||||||
@@ -239,17 +238,17 @@ void SimulatorBase::process_ui_dial(json& uiItem)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_thermo(json& uiItem)
|
void SimulatorBase::process_ui_thermo(json &uiItem)
|
||||||
{
|
{
|
||||||
QLabel* label = id_to_label(uiItem["id"]);
|
QLabel *label = id_to_label(uiItem["id"]);
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto thermo = qobject_cast<QwtThermo*>(widget);
|
auto thermo = qobject_cast<QwtThermo *>(widget);
|
||||||
if (thermo == nullptr)
|
if (thermo == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type QwtThermo");
|
SPDLOG_WARN("widget is not of type QwtThermo");
|
||||||
@@ -269,7 +268,6 @@ void SimulatorBase::process_ui_thermo(json& uiItem)
|
|||||||
thermo->setValue(value);
|
thermo->setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (thermo->isVisible() != visible)
|
if (thermo->isVisible() != visible)
|
||||||
{
|
{
|
||||||
thermo->setVisible(visible);
|
thermo->setVisible(visible);
|
||||||
@@ -277,21 +275,21 @@ void SimulatorBase::process_ui_thermo(json& uiItem)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_textbox(json& uiItem)
|
void SimulatorBase::process_ui_textbox(json &uiItem)
|
||||||
{
|
{
|
||||||
SPDLOG_CRITICAL("Not implemented");
|
SPDLOG_CRITICAL("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_combobox(json& uiItem)
|
void SimulatorBase::process_ui_combobox(json &uiItem)
|
||||||
{
|
{
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto combobox = qobject_cast<QComboBox*>(widget);
|
auto combobox = qobject_cast<QComboBox *>(widget);
|
||||||
if (combobox == nullptr)
|
if (combobox == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type QComboBox");
|
SPDLOG_WARN("widget is not of type QComboBox");
|
||||||
@@ -300,7 +298,7 @@ void SimulatorBase::process_ui_combobox(json& uiItem)
|
|||||||
|
|
||||||
QString selected = QString::fromStdString(uiItem["selected"]);
|
QString selected = QString::fromStdString(uiItem["selected"]);
|
||||||
|
|
||||||
for (json& item : uiItem["options"])
|
for (json &item : uiItem["options"])
|
||||||
{
|
{
|
||||||
if (combobox->findText(QString::fromStdString(item)) == -1)
|
if (combobox->findText(QString::fromStdString(item)) == -1)
|
||||||
combobox->addItem(QString::fromStdString(item));
|
combobox->addItem(QString::fromStdString(item));
|
||||||
@@ -312,22 +310,22 @@ void SimulatorBase::process_ui_combobox(json& uiItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_radiobutton(json& uiItem)
|
void SimulatorBase::process_ui_radiobutton(json &uiItem)
|
||||||
{
|
{
|
||||||
SPDLOG_CRITICAL("Not implemented");
|
SPDLOG_CRITICAL("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_button(json& uiItem)
|
void SimulatorBase::process_ui_button(json &uiItem)
|
||||||
{
|
{
|
||||||
//TODO: fix bgcolor and color
|
// TODO: fix bgcolor and color
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto button = qobject_cast<QPushButton*>(widget);
|
auto button = qobject_cast<QPushButton *>(widget);
|
||||||
if (button == nullptr)
|
if (button == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type QPushButton");
|
SPDLOG_WARN("widget is not of type QPushButton");
|
||||||
@@ -379,16 +377,16 @@ void SimulatorBase::process_ui_button(json& uiItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_led(json& uiItem)
|
void SimulatorBase::process_ui_led(json &uiItem)
|
||||||
{
|
{
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto led = qobject_cast<Led*>(widget);
|
auto led = qobject_cast<Led *>(widget);
|
||||||
if (led == nullptr)
|
if (led == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type led");
|
SPDLOG_WARN("widget is not of type led");
|
||||||
@@ -434,16 +432,16 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_can(json& uiItem)
|
void SimulatorBase::process_ui_can(json &uiItem)
|
||||||
{
|
{
|
||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget *widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto can_ui = qobject_cast<Can_Transceive*>(widget);
|
auto can_ui = qobject_cast<Can_Transceive *>(widget);
|
||||||
if (can_ui == nullptr)
|
if (can_ui == nullptr)
|
||||||
{
|
{
|
||||||
SPDLOG_WARN("widget is not of type led");
|
SPDLOG_WARN("widget is not of type led");
|
||||||
@@ -451,19 +449,18 @@ void SimulatorBase::process_ui_can(json& uiItem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
can_ui->clear();
|
can_ui->clear();
|
||||||
for (auto& send_item : uiItem["send_msgs"])
|
for (auto &send_item : uiItem["send_msgs"])
|
||||||
{
|
{
|
||||||
can_ui->add_send_item(send_item["id"], send_item["dlc"], send_item["payload"]);
|
can_ui->add_send_item(send_item["id"], send_item["dlc"], send_item["payload"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& recvd_item : uiItem["rcvd_msgs"])
|
for (auto &recvd_item : uiItem["rcvd_msgs"])
|
||||||
{
|
{
|
||||||
can_ui->add_receive_item(recvd_item["id"], recvd_item["dlc"], recvd_item["payload"]);
|
can_ui->add_receive_item(recvd_item["id"], recvd_item["dlc"], recvd_item["payload"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_ui_item(QWidget* item, size_t index)
|
void SimulatorBase::setup_ui_item(QWidget *item, size_t index)
|
||||||
{
|
{
|
||||||
setup_button(item, index);
|
setup_button(item, index);
|
||||||
setup_combobox(item, index);
|
setup_combobox(item, index);
|
||||||
@@ -472,55 +469,55 @@ void SimulatorBase::setup_ui_item(QWidget* item, size_t index)
|
|||||||
setup_can_ui(item, index);
|
setup_can_ui(item, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_button(QWidget* item, size_t index)
|
void SimulatorBase::setup_button(QWidget *item, size_t index)
|
||||||
{
|
{
|
||||||
QPushButton* button = qobject_cast<QPushButton*>(item);
|
QPushButton *button = qobject_cast<QPushButton *>(item);
|
||||||
if (button == nullptr)
|
if (button == nullptr)
|
||||||
return;
|
return;
|
||||||
connect(button, &QPushButton::clicked, this, [=, this]{m_web_socket->send_event(Web_socket_wrapper::Event::clicked, index);});
|
connect(button, &QPushButton::clicked, this,
|
||||||
|
[=, this] { m_web_socket->send_event(Web_socket_wrapper::Event::clicked, index); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_combobox(QWidget* item, size_t index)
|
void SimulatorBase::setup_combobox(QWidget *item, size_t index)
|
||||||
{
|
{
|
||||||
QComboBox* combobox = qobject_cast<QComboBox*>(item);
|
QComboBox *combobox = qobject_cast<QComboBox *>(item);
|
||||||
if (combobox == nullptr)
|
if (combobox == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connect(combobox, &QComboBox::currentIndexChanged, this, [=, this]{
|
connect(combobox, &QComboBox::currentIndexChanged, this, [=, this] {
|
||||||
m_web_socket->send_event(Web_socket_wrapper::Event::selected, index,
|
m_web_socket->send_event(Web_socket_wrapper::Event::selected, index, combobox->currentText());
|
||||||
combobox->currentText());});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_dial(QWidget* item, size_t index)
|
void SimulatorBase::setup_dial(QWidget *item, size_t index)
|
||||||
{
|
{
|
||||||
QwtDial* dial = qobject_cast<QwtDial*>(item);
|
QwtDial *dial = qobject_cast<QwtDial *>(item);
|
||||||
if (dial == nullptr)
|
if (dial == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
create_dial_needle(dial);
|
create_dial_needle(dial);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_slider(QWidget* item, size_t index)
|
void SimulatorBase::setup_slider(QWidget *item, size_t index)
|
||||||
{
|
{
|
||||||
QwtSlider* slider = qobject_cast<QwtSlider*>(item);
|
QwtSlider *slider = qobject_cast<QwtSlider *>(item);
|
||||||
if (slider == nullptr)
|
if (slider == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connect(slider, &QwtSlider::sliderMoved, this, [=, this]{
|
connect(slider, &QwtSlider::sliderMoved, this,
|
||||||
m_web_socket->send_event(Web_socket_wrapper::Event::value_changed, index,
|
[=, this] { m_web_socket->send_event(Web_socket_wrapper::Event::value_changed, index, slider->value()); });
|
||||||
slider->value());});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_can_ui(QWidget* item, size_t index)
|
void SimulatorBase::setup_can_ui(QWidget *item, size_t index)
|
||||||
{
|
{
|
||||||
Can_Transceive* can = qobject_cast<Can_Transceive*>(item);
|
Can_Transceive *can = qobject_cast<Can_Transceive *>(item);
|
||||||
if (can == nullptr)
|
if (can == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connect(can, &Can_Transceive::send_can_message, this, [=, this](uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload){
|
connect(can, &Can_Transceive::send_can_message, this,
|
||||||
|
[=, this](uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload) {
|
||||||
m_web_socket->send_event(Web_socket_wrapper::Event::can_send, index, id, dlc, payload);
|
m_web_socket->send_event(Web_socket_wrapper::Event::can_send, index, id, dlc, payload);
|
||||||
});
|
});
|
||||||
connect(can, &Can_Transceive::can_clear, this, [=, this]{
|
connect(can, &Can_Transceive::can_clear, this,
|
||||||
m_web_socket->send_event(Web_socket_wrapper::Event::can_clear, index);
|
[=, this] { m_web_socket->send_event(Web_socket_wrapper::Event::can_clear, index); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-36
@@ -1,64 +1,69 @@
|
|||||||
#ifndef SIMULATOR_BASE_H
|
#ifndef SIMULATOR_BASE_H
|
||||||
#define SIMULATOR_BASE_H
|
#define SIMULATOR_BASE_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include "IterableEnum.hpp"
|
||||||
#include <QWidget>
|
|
||||||
#include "web_socket_wrapper.h"
|
|
||||||
#include "networkerror.h"
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include <magic_enum.hpp>
|
#include "networkerror.h"
|
||||||
#include "IterableEnum.hpp"
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "web_socket_wrapper.h"
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <magic_enum.hpp>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
class SimulatorBase : public QMainWindow {
|
class SimulatorBase : public QMainWindow
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SimulatorBase(Web_socket_wrapper* api, QWidget* parent = nullptr);
|
explicit SimulatorBase(Web_socket_wrapper *api, QWidget *parent = nullptr);
|
||||||
void sim_update(void);
|
void sim_update(void);
|
||||||
QWidget* id_to_ui(size_t id);
|
QWidget *id_to_ui(size_t id);
|
||||||
virtual QLabel* id_to_label(size_t name) {return nullptr;}
|
virtual QLabel *id_to_label(size_t name)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void on_event_cb(json& j);
|
void on_event_cb(json &j);
|
||||||
void on_cmd_cb(json& j);
|
void on_cmd_cb(json &j);
|
||||||
|
|
||||||
void push_ui_item(QWidget* item);
|
void push_ui_item(QWidget *item);
|
||||||
|
|
||||||
void UI_item_parser(json& input);
|
void UI_item_parser(json &input);
|
||||||
virtual void process_ui_label(json& uiItem);
|
virtual void process_ui_label(json &uiItem);
|
||||||
virtual void process_ui_slider(json& uiItem);
|
virtual void process_ui_slider(json &uiItem);
|
||||||
virtual void process_ui_dial(json& uiItem);
|
virtual void process_ui_dial(json &uiItem);
|
||||||
virtual void process_ui_thermo(json& uiItem);
|
virtual void process_ui_thermo(json &uiItem);
|
||||||
virtual void process_ui_textbox(json& uiItem);
|
virtual void process_ui_textbox(json &uiItem);
|
||||||
virtual void process_ui_combobox(json& uiItem);
|
virtual void process_ui_combobox(json &uiItem);
|
||||||
virtual void process_ui_radiobutton(json& uiItem);
|
virtual void process_ui_radiobutton(json &uiItem);
|
||||||
virtual void process_ui_button(json& uiItem);
|
virtual void process_ui_button(json &uiItem);
|
||||||
virtual void process_ui_led(json& uiItem);
|
virtual void process_ui_led(json &uiItem);
|
||||||
virtual void process_ui_can(json& uiItem);
|
virtual void process_ui_can(json &uiItem);
|
||||||
|
|
||||||
void setup_ui_item(QWidget* item, size_t index);
|
void setup_ui_item(QWidget *item, size_t index);
|
||||||
void setup_button(QWidget* item, size_t index);
|
void setup_button(QWidget *item, size_t index);
|
||||||
void setup_combobox(QWidget* item, size_t index);
|
void setup_combobox(QWidget *item, size_t index);
|
||||||
void setup_dial(QWidget* item, size_t index);
|
void setup_dial(QWidget *item, size_t index);
|
||||||
void setup_slider(QWidget* item, size_t index);
|
void setup_slider(QWidget *item, size_t index);
|
||||||
void setup_can_ui(QWidget* item, size_t index);
|
void setup_can_ui(QWidget *item, size_t index);
|
||||||
|
|
||||||
void showEvent(QShowEvent* event);
|
void showEvent(QShowEvent *event);
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Web_socket_wrapper* m_web_socket;
|
Web_socket_wrapper *m_web_socket;
|
||||||
|
|
||||||
QTimer* m_timer_update;
|
QTimer *m_timer_update;
|
||||||
uint32_t m_refresh_rate;
|
uint32_t m_refresh_rate;
|
||||||
NetworkError* m_error_dialog;
|
NetworkError *m_error_dialog;
|
||||||
bool m_open = false;
|
bool m_open = false;
|
||||||
std::vector<QWidget*>m_ui_lookup;
|
std::vector<QWidget *> m_ui_lookup;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIMULATOR_BASE_H
|
#endif // SIMULATOR_BASE_H
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
#include "sim-can_debugger.h"
|
#include "sim-can_debugger.h"
|
||||||
#include "ui_sim-can_debugger.h"
|
#include "ui_sim-can_debugger.h"
|
||||||
|
|
||||||
Can_Debugger::Can_Debugger(Web_socket_wrapper* web_socket, QWidget *parent) :
|
Can_Debugger::Can_Debugger(Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
SimulatorBase(web_socket, parent),
|
: SimulatorBase(web_socket, parent), ui(new Ui::Can_Debugger)
|
||||||
ui(new Ui::Can_Debugger) {
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("CAN Debugger");
|
this->setWindowTitle("CAN Debugger");
|
||||||
|
|
||||||
this->push_ui_item(ui->can_transceive);
|
this->push_ui_item(ui->can_transceive);
|
||||||
}
|
}
|
||||||
|
|
||||||
Can_Debugger::~Can_Debugger() {
|
Can_Debugger::~Can_Debugger()
|
||||||
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
#ifndef SIM_CAN_DEBUGGER_H
|
#ifndef SIM_CAN_DEBUGGER_H
|
||||||
#define SIM_CAN_DEBUGGER_H
|
#define SIM_CAN_DEBUGGER_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include "simulator_base.h"
|
#include "simulator_base.h"
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class Can_Debugger;
|
class Can_Debugger;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Can_Debugger : public SimulatorBase {
|
class Can_Debugger : public SimulatorBase
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Can_Debugger(Web_socket_wrapper* web_socket, QWidget *parent = nullptr);
|
explicit Can_Debugger(Web_socket_wrapper *web_socket, QWidget *parent = nullptr);
|
||||||
~Can_Debugger();
|
~Can_Debugger();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Can_Debugger* ui;
|
Ui::Can_Debugger *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIM_CAN_DEBUGGER_H
|
#endif // SIM_CAN_DEBUGGER_H
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "sim-test.h"
|
#include "sim-test.h"
|
||||||
#include "ui_sim-test.h"
|
#include "ui_sim-test.h"
|
||||||
|
|
||||||
Test_Sim::Test_Sim(Web_socket_wrapper* web_socket, QWidget* parent) :
|
Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent)
|
||||||
SimulatorBase(web_socket, parent),
|
: SimulatorBase(web_socket, parent), ui(new Ui::Test_Sim)
|
||||||
ui(new Ui::Test_Sim)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("Test Sim");
|
this->setWindowTitle("Test Sim");
|
||||||
@@ -18,13 +17,14 @@ Test_Sim::Test_Sim(Web_socket_wrapper* web_socket, QWidget* parent) :
|
|||||||
push_ui_item(ui->led);
|
push_ui_item(ui->led);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test_Sim::~Test_Sim() {
|
Test_Sim::~Test_Sim()
|
||||||
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel* Test_Sim::id_to_label(size_t id)
|
QLabel *Test_Sim::id_to_label(size_t id)
|
||||||
{
|
{
|
||||||
QWidget* widget = id_to_ui(id);
|
QWidget *widget = id_to_ui(id);
|
||||||
if (widget == ui->slider)
|
if (widget == ui->slider)
|
||||||
return ui->slider_label;
|
return ui->slider_label;
|
||||||
if (widget == ui->thermo)
|
if (widget == ui->thermo)
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
#ifndef SIM_TEST_H
|
#ifndef SIM_TEST_H
|
||||||
#define SIM_TEST_H
|
#define SIM_TEST_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include "simulator_base.h"
|
#include "simulator_base.h"
|
||||||
#include "web_socket_wrapper.h"
|
#include "web_socket_wrapper.h"
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class Test_Sim;
|
class Test_Sim;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Test_Sim : public SimulatorBase {
|
class Test_Sim : public SimulatorBase
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Test_Sim(Web_socket_wrapper* web_socket, QWidget* parent = nullptr);
|
explicit Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent = nullptr);
|
||||||
~Test_Sim();
|
~Test_Sim();
|
||||||
|
|
||||||
QLabel* id_to_label(size_t name) override;
|
QLabel *id_to_label(size_t name) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Test_Sim* ui;
|
Ui::Test_Sim *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIM_TEST_H
|
#endif // SIM_TEST_H
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
#include "web_socket_wrapper.h"
|
#include "web_socket_wrapper.h"
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "magic_enum.hpp"
|
#include "magic_enum.hpp"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
Web_socket_wrapper::Web_socket_wrapper(const QUrl &url, QObject *parent) :
|
Web_socket_wrapper::Web_socket_wrapper(const QUrl &url, QObject *parent)
|
||||||
QObject(parent),
|
: QObject(parent), m_web_socket(new QWebSocket("", QWebSocketProtocol::VersionLatest, this)),
|
||||||
m_web_socket(new QWebSocket("", QWebSocketProtocol::VersionLatest, this)),
|
m_ping_timer(new QTimer(this)), m_pong_timer(new QTimer(this))
|
||||||
m_ping_timer(new QTimer(this)),
|
|
||||||
m_pong_timer(new QTimer(this))
|
|
||||||
{
|
{
|
||||||
connect(m_web_socket, &QWebSocket::connected, this, &Web_socket_wrapper::m_on_connected);
|
connect(m_web_socket, &QWebSocket::connected, this, &Web_socket_wrapper::m_on_connected);
|
||||||
connect(m_web_socket, &QWebSocket::disconnected, this, &Web_socket_wrapper::on_closed);
|
connect(m_web_socket, &QWebSocket::disconnected, this, &Web_socket_wrapper::on_closed);
|
||||||
connect(m_web_socket, &QWebSocket::pong, this, &Web_socket_wrapper::m_on_pong);
|
connect(m_web_socket, &QWebSocket::pong, this, &Web_socket_wrapper::m_on_pong);
|
||||||
connect(m_ping_timer, &QTimer::timeout, this, [=, this]{
|
connect(m_ping_timer, &QTimer::timeout, this, [=, this] {
|
||||||
m_web_socket->ping();
|
m_web_socket->ping();
|
||||||
m_pong_timer->start(500);
|
m_pong_timer->start(500);
|
||||||
});
|
});
|
||||||
@@ -149,8 +147,7 @@ void Web_socket_wrapper::close()
|
|||||||
void Web_socket_wrapper::m_on_connected()
|
void Web_socket_wrapper::m_on_connected()
|
||||||
{
|
{
|
||||||
m_connected = true;
|
m_connected = true;
|
||||||
connect(m_web_socket, &QWebSocket::textMessageReceived,
|
connect(m_web_socket, &QWebSocket::textMessageReceived, this, &Web_socket_wrapper::m_on_received);
|
||||||
this, &Web_socket_wrapper::m_on_received);
|
|
||||||
|
|
||||||
m_ping_timer->start(1000);
|
m_ping_timer->start(1000);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef WEB_SOCKET_WRAPPER_H
|
#ifndef WEB_SOCKET_WRAPPER_H
|
||||||
#define WEB_SOCKET_WRAPPER_H
|
#define WEB_SOCKET_WRAPPER_H
|
||||||
|
|
||||||
#include <QtWebSockets/QWebSocket>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtWebSockets/QWebSocket>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ class Web_socket_wrapper : public QObject
|
|||||||
end,
|
end,
|
||||||
begin = 0
|
begin = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Web_socket_wrapper(const QUrl &url, QObject *parent = nullptr);
|
explicit Web_socket_wrapper(const QUrl &url, QObject *parent = nullptr);
|
||||||
~Web_socket_wrapper();
|
~Web_socket_wrapper();
|
||||||
@@ -47,8 +48,8 @@ class Web_socket_wrapper : public QObject
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void on_connected();
|
void on_connected();
|
||||||
void on_closed();
|
void on_closed();
|
||||||
void on_command_cb(json& data);
|
void on_command_cb(json &data);
|
||||||
void on_event_cb(json& data);
|
void on_event_cb(json &data);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void m_on_connected();
|
void m_on_connected();
|
||||||
@@ -58,9 +59,9 @@ class Web_socket_wrapper : public QObject
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_connected = false;
|
bool m_connected = false;
|
||||||
QWebSocket* m_web_socket;
|
QWebSocket *m_web_socket;
|
||||||
QTimer* m_ping_timer;
|
QTimer *m_ping_timer;
|
||||||
QTimer* m_pong_timer;
|
QTimer *m_pong_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEB_SOCKET_WRAPPER_H
|
#endif // WEB_SOCKET_WRAPPER_H
|
||||||
|
|||||||
Vendored
+1
-1
Submodule external/color updated: adc825ce65...c1bc9f3c20
Vendored
+1
-1
Submodule external/cpp-templates updated: 4ddbc6da93...e0ccbd6a67
@@ -1,11 +1,11 @@
|
|||||||
#include "CAN_interface.hpp"
|
#include "CAN_interface.hpp"
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "magic_enum.hpp"
|
#include "magic_enum.hpp"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
CAN_Interface::CAN_Interface(QString dev, QObject *parent)
|
CAN_Interface::CAN_Interface(QString dev, QObject *parent) : QObject(parent)
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
if (!QCanBus::instance()->plugins().contains(QStringLiteral("socketcan"))) {
|
if (!QCanBus::instance()->plugins().contains(QStringLiteral("socketcan")))
|
||||||
|
{
|
||||||
SPDLOG_CRITICAL("Runtime error: CAN Interface: socketcan plugin not found");
|
SPDLOG_CRITICAL("Runtime error: CAN Interface: socketcan plugin not found");
|
||||||
throw std::runtime_error("CAN Interface: socketcan plugin not found");
|
throw std::runtime_error("CAN Interface: socketcan plugin not found");
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,8 @@ CAN_Interface::CAN_Interface(QString dev, QObject *parent)
|
|||||||
throw std::runtime_error("CAN Interface: " + errorString.toStdString());
|
throw std::runtime_error("CAN Interface: " + errorString.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_canDevice, &QCanBusDevice::errorOccurred,
|
connect(m_canDevice, &QCanBusDevice::errorOccurred, this,
|
||||||
this, [=, this](QCanBusDevice::CanBusError error){processErrors(error);});
|
[=, this](QCanBusDevice::CanBusError error) { processErrors(error); });
|
||||||
|
|
||||||
m_canDevice->connectDevice();
|
m_canDevice->connectDevice();
|
||||||
connect(m_canDevice, &QCanBusDevice::framesReceived, this, [this] {
|
connect(m_canDevice, &QCanBusDevice::framesReceived, this, [this] {
|
||||||
@@ -44,13 +44,15 @@ void CAN_Interface::send_frame(const QCanBusFrame frame)
|
|||||||
|
|
||||||
void CAN_Interface::processErrors(QCanBusDevice::CanBusError error) const
|
void CAN_Interface::processErrors(QCanBusDevice::CanBusError error) const
|
||||||
{
|
{
|
||||||
switch (error) {
|
switch (error)
|
||||||
|
{
|
||||||
case QCanBusDevice::ReadError:
|
case QCanBusDevice::ReadError:
|
||||||
case QCanBusDevice::WriteError:
|
case QCanBusDevice::WriteError:
|
||||||
case QCanBusDevice::ConnectionError:
|
case QCanBusDevice::ConnectionError:
|
||||||
case QCanBusDevice::ConfigurationError:
|
case QCanBusDevice::ConfigurationError:
|
||||||
case QCanBusDevice::UnknownError:
|
case QCanBusDevice::UnknownError:
|
||||||
SPDLOG_CRITICAL("CAN Interface: {} {}", magic_enum::enum_name<QCanBusDevice::CanBusError>(error), m_canDevice->errorString().toStdString());
|
SPDLOG_CRITICAL("CAN Interface: {} {}", magic_enum::enum_name<QCanBusDevice::CanBusError>(error),
|
||||||
|
m_canDevice->errorString().toStdString());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QObject>
|
|
||||||
#include <QCanBus>
|
#include <QCanBus>
|
||||||
#include <QCanBusDevice>
|
#include <QCanBusDevice>
|
||||||
#include <QCanBusFrame>
|
#include <QCanBusFrame>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class CAN_Interface : public QObject
|
class CAN_Interface : public QObject
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-2
@@ -13,8 +13,9 @@ void init_logger()
|
|||||||
{
|
{
|
||||||
spdlog::init_thread_pool(8192, 1);
|
spdlog::init_thread_pool(8192, 1);
|
||||||
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
//auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("log-sim_us.txt", 1024 * 1024 * 10, 3);
|
// auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("log-sim_us.txt", 1024 * 1024 * 10,
|
||||||
std::vector<spdlog::sink_ptr> sinks{stdout_sink/*, rotating_sink*/};
|
// 3);
|
||||||
|
std::vector<spdlog::sink_ptr> sinks{stdout_sink /*, rotating_sink*/};
|
||||||
auto logger = std::make_shared<spdlog::async_logger>("sim_us", sinks.begin(), sinks.end(), spdlog::thread_pool(),
|
auto logger = std::make_shared<spdlog::async_logger>("sim_us", sinks.begin(), sinks.end(), spdlog::thread_pool(),
|
||||||
spdlog::async_overflow_policy::block);
|
spdlog::async_overflow_policy::block);
|
||||||
spdlog::set_default_logger(logger);
|
spdlog::set_default_logger(logger);
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ json Simulators::command_parser(json command)
|
|||||||
case Command::get_UI_element:
|
case Command::get_UI_element:
|
||||||
SPDLOG_INFO("Command {}: {}", type, (size_t)command.at("id"));
|
SPDLOG_INFO("Command {}: {}", type, (size_t)command.at("id"));
|
||||||
j["response"]["type"] = type;
|
j["response"]["type"] = type;
|
||||||
j["response"]["UI_item"] = invoke_active_simulator()->get_UI_item(command.at("id"))->to_json(command.at("id"));
|
j["response"]["UI_item"] =
|
||||||
|
invoke_active_simulator()->get_UI_item(command.at("id"))->to_json(command.at("id"));
|
||||||
break;
|
break;
|
||||||
case Command::get_UI_elements:
|
case Command::get_UI_elements:
|
||||||
SPDLOG_INFO("Command {}", type);
|
SPDLOG_INFO("Command {}", type);
|
||||||
@@ -91,23 +92,20 @@ void Simulators::event_handler(json event)
|
|||||||
}
|
}
|
||||||
case Event::text_changed: {
|
case Event::text_changed: {
|
||||||
SPDLOG_DEBUG("Event {}: {} {}", type, (size_t)event.at("id"), std::string(event.at("text")));
|
SPDLOG_DEBUG("Event {}: {} {}", type, (size_t)event.at("id"), std::string(event.at("text")));
|
||||||
invoke_active_simulator()
|
invoke_active_simulator()->get_UI_item(event.at("id"))->set_text(std::string(event.at("text")));
|
||||||
->get_UI_item(event.at("id"))
|
|
||||||
->set_text(std::string(event.at("text")));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::selected: {
|
case Event::selected: {
|
||||||
SPDLOG_DEBUG("Event {}: {} {}", type, (size_t)event.at("id"), std::string(event.at("selected")));
|
SPDLOG_DEBUG("Event {}: {} {}", type, (size_t)event.at("id"), std::string(event.at("selected")));
|
||||||
invoke_active_simulator()
|
invoke_active_simulator()->get_UI_item(event.at("id"))->set_selected(std::string(event.at("selected")));
|
||||||
->get_UI_item(event.at("id"))
|
|
||||||
->set_selected(std::string(event.at("selected")));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::can_send: {
|
case Event::can_send: {
|
||||||
SPDLOG_DEBUG("Event {}: {}", type, (size_t)event.at("id"));
|
SPDLOG_DEBUG("Event {}: {}", type, (size_t)event.at("id"));
|
||||||
invoke_active_simulator()
|
invoke_active_simulator()
|
||||||
->get_UI_item(event.at("id"))
|
->get_UI_item(event.at("id"))
|
||||||
->can_send((uint32_t)event.at("sid"), (uint8_t)event.at("dlc"), (std::array<uint8_t, 8>)event.at("payload"));
|
->can_send((uint32_t)event.at("sid"), (uint8_t)event.at("dlc"),
|
||||||
|
(std::array<uint8_t, 8>)event.at("payload"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::can_clear: {
|
case Event::can_clear: {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "CAN_wrapper.hpp"
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
#include "websocket.hpp"
|
#include "websocket.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#include "can_debugger.hpp"
|
#include "can_debugger.hpp"
|
||||||
|
|
||||||
Can_Debugger::Can_Debugger(CAN_Wrapper* can_wrapper, QObject* parent) :
|
Can_Debugger::Can_Debugger(CAN_Wrapper *can_wrapper, QObject *parent)
|
||||||
Simulator_base("Can_Debugger", can_wrapper, std::chrono::milliseconds(100), parent),
|
: Simulator_base("Can_Debugger", can_wrapper, std::chrono::milliseconds(100), parent), m_wrapper(can_wrapper),
|
||||||
m_wrapper(can_wrapper),
|
|
||||||
m_can_ui(Color::Black, Color::White)
|
m_can_ui(Color::Black, Color::White)
|
||||||
{
|
{
|
||||||
this->add_UI_item(&this->m_can_ui);
|
this->add_UI_item(&this->m_can_ui);
|
||||||
|
|
||||||
connect(&m_can_ui, &UI_can::on_send, this, [=, this](QCanBusFrame frame){m_wrapper->send_can_message(frame);});
|
connect(&m_can_ui, &UI_can::on_send, this, [=, this](QCanBusFrame frame) { m_wrapper->send_can_message(frame); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Can_Debugger::timer()
|
void Can_Debugger::timer()
|
||||||
@@ -17,8 +16,10 @@ void Can_Debugger::timer()
|
|||||||
|
|
||||||
void Can_Debugger::run_at_startup()
|
void Can_Debugger::run_at_startup()
|
||||||
{
|
{
|
||||||
connect(m_wrapper, &CAN_Wrapper::on_can_message, this, [=, this](QCanBusFrame frame){this->m_can_ui.add_received_message(frame);});
|
connect(m_wrapper, &CAN_Wrapper::on_can_message, this,
|
||||||
connect(m_wrapper, &CAN_Wrapper::on_can_send, this, [=, this](QCanBusFrame frame){this->m_can_ui.add_send_message(frame);});
|
[=, this](QCanBusFrame frame) { this->m_can_ui.add_received_message(frame); });
|
||||||
|
connect(m_wrapper, &CAN_Wrapper::on_can_send, this,
|
||||||
|
[=, this](QCanBusFrame frame) { this->m_can_ui.add_send_message(frame); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Can_Debugger::run_at_stop()
|
void Can_Debugger::run_at_stop()
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
|
|
||||||
class Can_Debugger : public Simulator_base {
|
class Can_Debugger : public Simulator_base
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Can_Debugger();
|
explicit Can_Debugger(QObject* parent = nullptr);
|
||||||
void timer() override;
|
void timer() override;
|
||||||
void run_at_startup() override;
|
void run_at_startup() override;
|
||||||
void run_at_stop() override;
|
void run_at_stop() override;
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ m_led("Led", Color(Color::White), Color(Color::Black), Color(Color::Red))
|
|||||||
this->add_UI_item(&this->m_checkbox);
|
this->add_UI_item(&this->m_checkbox);
|
||||||
|
|
||||||
QObject::connect(&m_button, &UI_button::on_click, this, [=, this] { button_clicked(&m_button); });
|
QObject::connect(&m_button, &UI_button::on_click, this, [=, this] { button_clicked(&m_button); });
|
||||||
QObject::connect(&m_slider, &UI_slider::on_change, this, [=, this](double value) { slider_changed(&m_slider, value); });
|
QObject::connect(&m_slider, &UI_slider::on_change, this,
|
||||||
|
[=, this](double value) { slider_changed(&m_slider, value); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Sim::timer()
|
void Test_Sim::timer()
|
||||||
@@ -47,7 +48,7 @@ void Test_Sim::run_at_startup()
|
|||||||
SPDLOG_INFO("Test_Sim started");
|
SPDLOG_INFO("Test_Sim started");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Sim::button_clicked(UI_button* id)
|
void Test_Sim::button_clicked(UI_button *id)
|
||||||
{
|
{
|
||||||
if (id == &this->m_button)
|
if (id == &this->m_button)
|
||||||
{
|
{
|
||||||
@@ -60,7 +61,7 @@ void Test_Sim::button_clicked(UI_button* id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Sim::slider_changed(UI_slider* id, double value)
|
void Test_Sim::slider_changed(UI_slider *id, double value)
|
||||||
{
|
{
|
||||||
if (id == &this->m_slider)
|
if (id == &this->m_slider)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
|
|
||||||
class Test_Sim : public Simulator_base {
|
class Test_Sim : public Simulator_base
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Test_Sim(QObject* parent = nullptr);
|
Test_Sim(QObject* parent = nullptr);
|
||||||
void timer() override;
|
void timer() override;
|
||||||
void run_at_startup() override;
|
void run_at_startup() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void button_clicked(UI_button* id);
|
void button_clicked(UI_button *id);
|
||||||
void slider_changed(UI_slider* id, double value);
|
void slider_changed(UI_slider *id, double value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UI_button m_button;
|
UI_button m_button;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m
|
|||||||
UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent)
|
UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent)
|
||||||
: UI_item(UI_CHECKBOX_TYPE, text, 0, fg_color, bg_color, parent), m_selected(false)
|
: UI_item(UI_CHECKBOX_TYPE, text, 0, fg_color, bg_color, parent), m_selected(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_checkbox::UI_checkbox(const json &j, QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_selected()
|
UI_checkbox::UI_checkbox(const json &j, QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_selected()
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ class UI_checkbox : public UI_item
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_checkbox(QObject *parent = nullptr);
|
UI_checkbox(QObject *parent = nullptr);
|
||||||
UI_checkbox(std::string text, Color fg_color, Color bg_color,
|
UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
|
||||||
QObject *parent = nullptr);
|
|
||||||
UI_checkbox(const json &j, QObject *parent = nullptr);
|
UI_checkbox(const json &j, QObject *parent = nullptr);
|
||||||
|
|
||||||
void toggle_selected();
|
void toggle_selected();
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ UI_combobox::UI_combobox(QObject *parent) : UI_x_boxes(UI_COMBOBOX_TYPE, parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_combobox::UI_combobox(Color fg_color, Color bg_color,
|
UI_combobox::UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected,
|
||||||
std::vector<std::string> options, size_t selected, QObject *parent)
|
QObject *parent)
|
||||||
: UI_x_boxes(UI_COMBOBOX_TYPE, "", fg_color, bg_color, options, parent), m_selected(selected)
|
: UI_x_boxes(UI_COMBOBOX_TYPE, "", fg_color, bg_color, options, parent), m_selected(selected)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class UI_combobox : public UI_x_boxes
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_combobox(QObject *parent = nullptr);
|
UI_combobox(QObject *parent = nullptr);
|
||||||
UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options,
|
UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected = 0,
|
||||||
size_t selected = 0, QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
UI_combobox(const json &j, QObject *parent = nullptr);
|
UI_combobox(const json &j, QObject *parent = nullptr);
|
||||||
|
|
||||||
void set_selected(size_t selected);
|
void set_selected(size_t selected);
|
||||||
|
|||||||
+5
-7
@@ -1,20 +1,18 @@
|
|||||||
#include "UI_dial.hpp"
|
#include "UI_dial.hpp"
|
||||||
|
|
||||||
UI_dial::UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value,
|
UI_dial::UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
|
||||||
QObject *parent)
|
double value, QObject *parent)
|
||||||
: UI_item(UI_DIAL_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
|
: UI_item(UI_DIAL_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_dial::UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max,
|
UI_dial::UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value,
|
||||||
double value, QObject *parent)
|
QObject *parent)
|
||||||
: UI_dial(text, "", fg_color, bg_color, min, max, value, parent)
|
: UI_dial(text, "", fg_color, bg_color, min, max, value, parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_dial::UI_dial(const json &j, QObject *parent)
|
UI_dial::UI_dial(const json &j, QObject *parent) : UI_item(UI_DIAL_TYPE, parent)
|
||||||
: UI_item(UI_DIAL_TYPE, parent)
|
|
||||||
{
|
{
|
||||||
from_json(j);
|
from_json(j);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,6 @@
|
|||||||
#include "UI_item.hpp"
|
#include "UI_item.hpp"
|
||||||
|
|
||||||
UI_item::UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color,
|
UI_item::UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color, QObject *parent)
|
||||||
QObject *parent)
|
|
||||||
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color),
|
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color),
|
||||||
m_bg_color(bg_color), enabled(true), visible(true)
|
m_bg_color(bg_color), enabled(true), visible(true)
|
||||||
{
|
{
|
||||||
@@ -171,5 +170,4 @@ void UI_item::can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload)
|
|||||||
|
|
||||||
void UI_item::can_clear()
|
void UI_item::can_clear()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -6,8 +6,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QCanBusFrame>
|
#include <QCanBusFrame>
|
||||||
|
#include <QObject>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
#define UNUSED(x) (void)(x)
|
#define UNUSED(x) (void)(x)
|
||||||
@@ -17,8 +17,8 @@ class UI_item : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit UI_item(std::string type, QObject *parent = nullptr);
|
explicit UI_item(std::string type, QObject *parent = nullptr);
|
||||||
explicit UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color,
|
explicit UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color,
|
||||||
Color bg_color, QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
explicit UI_item(const json &j, QObject *parent = nullptr);
|
explicit UI_item(const json &j, QObject *parent = nullptr);
|
||||||
~UI_item();
|
~UI_item();
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -8,8 +8,7 @@ class UI_led : public UI_item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_led(std::string text, Color fg_color, Color bg_color, Color led_color,
|
UI_led(std::string text, Color fg_color, Color bg_color, Color led_color, QObject *parent = nullptr);
|
||||||
QObject *parent = nullptr);
|
|
||||||
UI_led(const json &j, QObject *parent = nullptr);
|
UI_led(const json &j, QObject *parent = nullptr);
|
||||||
|
|
||||||
Color led_color() const;
|
Color led_color() const;
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
UI_slider::UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
|
UI_slider::UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
|
||||||
double value, QObject *parent)
|
double value, QObject *parent)
|
||||||
: UI_item(UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
|
: UI_item(UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value),
|
||||||
|
m_unit(unit)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,7 +11,6 @@ UI_slider::UI_slider(std::string text, Color fg_color, Color bg_color, double mi
|
|||||||
QObject *parent)
|
QObject *parent)
|
||||||
: UI_slider(text, "", fg_color, bg_color, min, max, value, parent)
|
: UI_slider(text, "", fg_color, bg_color, min, max, value, parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_slider::UI_slider(const json &j, QObject *parent) : UI_item(UI_SLIDER_TYPE, parent)
|
UI_slider::UI_slider(const json &j, QObject *parent) : UI_item(UI_SLIDER_TYPE, parent)
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
UI_thermo::UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
|
UI_thermo::UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
|
||||||
double value, QObject *parent)
|
double value, QObject *parent)
|
||||||
: UI_item(UI_THERMO_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
|
: UI_item(UI_THERMO_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value),
|
||||||
|
m_unit(unit)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class UI_x_boxes : public UI_item
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UI_x_boxes(std::string type, QObject *parent = nullptr);
|
UI_x_boxes(std::string type, QObject *parent = nullptr);
|
||||||
UI_x_boxes(std::string type, std::string text, Color fg_color, Color bg_color,
|
UI_x_boxes(std::string type, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
|
||||||
std::vector<std::string> options, QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
void from_json(const json &j) override;
|
void from_json(const json &j) override;
|
||||||
json to_json(size_t id) const override;
|
json to_json(size_t id) const override;
|
||||||
|
|||||||
@@ -24,14 +24,16 @@ UI_can::UI_can(const json &j, QObject *parent) : UI_item(UI_CAN_TYPE, parent)
|
|||||||
|
|
||||||
void UI_can::add_send_message(QCanBusFrame msg)
|
void UI_can::add_send_message(QCanBusFrame msg)
|
||||||
{
|
{
|
||||||
CanFrame frame(msg.frameId(), (uint8_t)msg.payload().size(), ByteArrayToStdArray<std::array<uint8_t, 8>>(msg.payload()));
|
CanFrame frame(msg.frameId(), (uint8_t)msg.payload().size(),
|
||||||
|
ByteArrayToStdArray<std::array<uint8_t, 8>>(msg.payload()));
|
||||||
m_can_send_messages.push_back(frame);
|
m_can_send_messages.push_back(frame);
|
||||||
emit value_changed();
|
emit value_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI_can::add_received_message(QCanBusFrame msg)
|
void UI_can::add_received_message(QCanBusFrame msg)
|
||||||
{
|
{
|
||||||
CanFrame frame(msg.frameId(), (uint8_t)msg.payload().size(), ByteArrayToStdArray<std::array<uint8_t, 8>>(msg.payload()));
|
CanFrame frame(msg.frameId(), (uint8_t)msg.payload().size(),
|
||||||
|
ByteArrayToStdArray<std::array<uint8_t, 8>>(msg.payload()));
|
||||||
m_can_received_messages.push_back(frame);
|
m_can_received_messages.push_back(frame);
|
||||||
emit value_changed();
|
emit value_changed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,8 @@
|
|||||||
class CanFrame
|
class CanFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CanFrame(uint32_t sid, uint8_t dlc, std::array<uint8_t, 8> payload)
|
CanFrame(uint32_t sid, uint8_t dlc, std::array<uint8_t, 8> payload) : m_SID(sid), m_DLC(dlc), m_payload(payload)
|
||||||
: m_SID(sid), m_DLC(dlc), m_payload(payload)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
uint32_t m_SID;
|
uint32_t m_SID;
|
||||||
uint8_t m_DLC;
|
uint8_t m_DLC;
|
||||||
@@ -37,6 +35,7 @@ class UI_can : public UI_item
|
|||||||
void can_clear() override;
|
void can_clear() override;
|
||||||
signals:
|
signals:
|
||||||
void on_send(QCanBusFrame msg);
|
void on_send(QCanBusFrame msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<CanFrame> m_can_send_messages;
|
std::vector<CanFrame> m_can_send_messages;
|
||||||
std::vector<CanFrame> m_can_received_messages;
|
std::vector<CanFrame> m_can_received_messages;
|
||||||
|
|||||||
Reference in New Issue
Block a user