CAN debuger

This commit is contained in:
2026-02-01 18:42:24 +01:00
parent 10604e4b03
commit e7f13d9965
6 changed files with 86 additions and 25 deletions
+2 -1
View File
@@ -18,7 +18,7 @@ target_compile_options(UI PRIVATE $<$<CONFIG:Debug>:
-Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion
>)
file(GLOB_RECURSE CUSTOM_UI_SOURCES "custom/*.cpp")
file(GLOB_RECURSE CUSTOM_UI_SOURCES "custom/*.?pp")
target_sources(UI
PRIVATE
@@ -51,6 +51,7 @@ target_sources(UI
target_include_directories(UI
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/custom/**
PRIVATE
${PROJECT_DIR}/external/**
${PROJECT_DIR}/src/CAN/
+3 -1
View File
@@ -8,4 +8,6 @@
#include "UI_led.hpp"
#include "UI_slider.hpp"
#include "UI_textbox.hpp"
#include "UI_thermo.hpp"
#include "UI_thermo.hpp"
#include "custom/UI_can.hpp"
+51 -13
View File
@@ -14,48 +14,86 @@ template <class T> T ByteArrayToStdArray(const QByteArray &byteArray)
return stdArray;
}
UI_can::UI_can(std::string text, Color fg_color, Color bg_color)
: UI_item(UI_CAN_TYPE, text, 12, fg_color, bg_color)
UI_can::UI_can(Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_CAN_TYPE, "", 12, fg_color, bg_color, parent)
{
}
UI_can::UI_can(const json &j) : UI_item(UI_CAN_TYPE)
UI_can::UI_can(const json &j, QObject *parent) : UI_item(UI_CAN_TYPE, parent)
{
from_json(j);
}
void UI_can::add_can_message(QCanBusFrame& msg)
void UI_can::add_send_message(QCanBusFrame& msg)
{
m_can_messages.push_back(msg);
m_can_send_messages.push_back(msg);
emit value_changed();
}
void UI_can::add_received_message(QCanBusFrame& msg)
{
m_can_received_messages.push_back(msg);
emit value_changed();
}
void UI_can::clear_send_buffer()
{
m_can_send_messages.clear();
emit value_changed();
}
void UI_can::clear_receive_buffer()
{
m_can_received_messages.clear();
emit value_changed();
}
void UI_can::from_json(const json &j)
{
UI_item::from_json(j);
m_can_messages.clear();
for (const auto &msg : j.at("can_messages"))
m_can_send_messages.clear();
m_can_received_messages.clear();
for (const auto &msg : j.at("can_send_messages"))
{
QCanBusFrame can_msg;
can_msg.setFrameId(msg.at("id"));
can_msg.setPayload(QByteArray(msg.at("bytes"), msg.at("dlc")));
m_can_messages.push_back(can_msg);
m_can_send_messages.push_back(can_msg);
}
for (const auto &msg : j.at("can_received_messages"))
{
QCanBusFrame can_msg;
can_msg.setFrameId(msg.at("id"));
can_msg.setPayload(QByteArray(msg.at("bytes"), msg.at("dlc")));
m_can_received_messages.push_back(can_msg);
}
}
json UI_can::to_json(size_t id) const
{
json j = UI_item::to_json(id);
json can_messages = json::array();
for (const auto &msg : m_can_messages)
json can_send_messages = json::array();
json can_received_messages = json::array();
for (const auto &msg : m_can_send_messages)
{
json can_msg;
can_msg["id"] = (uint32_t)msg.frameId();
can_msg["dlc"] = msg.payload().size();
can_msg["bytes"] = ByteArrayToStdArray<std::array<uint8_t, 8>>(msg.payload());
can_messages.push_back(can_msg);
can_send_messages.push_back(can_msg);
}
j["can_messages"] = can_messages;
j["can_send_messages"] = can_send_messages;
for (const auto &msg : m_can_received_messages)
{
json can_msg;
can_msg["id"] = (uint32_t)msg.frameId();
can_msg["dlc"] = msg.payload().size();
can_msg["bytes"] = ByteArrayToStdArray<std::array<uint8_t, 8>>(msg.payload());
can_received_messages.push_back(can_msg);
}
j["can_received_messages"] = can_received_messages;
return j;
}
@@ -66,4 +104,4 @@ void UI_can::can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload)
frame.setPayload(QByteArray::fromRawData((const char *)(payload.data()), dlc));
emit on_send(frame);
}
}
+9 -4
View File
@@ -7,11 +7,15 @@
class UI_can : public UI_item
{
Q_OBJECT
public:
UI_can(std::string text, Color fg_color, Color bg_color);
UI_can(const json &j);
UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr);
UI_can(const json &j, QObject *parent = nullptr);
void add_can_message(QCanBusFrame& msg);
void add_send_message(QCanBusFrame& msg);
void add_received_message(QCanBusFrame& msg);
void clear_send_buffer();
void clear_receive_buffer();
void from_json(const json &j) override;
json to_json(size_t id) const override;
@@ -20,5 +24,6 @@ class UI_can : public UI_item
signals:
void on_send(QCanBusFrame msg);
private:
std::vector<QCanBusFrame> m_can_messages;
std::vector<QCanBusFrame> m_can_send_messages;
std::vector<QCanBusFrame> m_can_received_messages;
};