This commit is contained in:
2026-02-14 14:30:58 +01:00
parent d03bc91fb3
commit d885b36c71
11 changed files with 75 additions and 37 deletions
+11 -7
View File
@@ -2,13 +2,23 @@
#include "spdlog/spdlog.h"
#include <magic_enum/magic_enum.hpp>
CAN_Interface::CAN_Interface(QString dev, QObject *parent) : QObject(parent)
CAN_Interface::CAN_Interface(QObject *parent) : QObject(parent)
{
if (!QCanBus::instance()->plugins().contains(QStringLiteral("socketcan")))
{
SPDLOG_CRITICAL("Runtime error: CAN Interface: socketcan plugin not found");
throw std::runtime_error("CAN Interface: socketcan plugin not found");
}
}
CAN_Interface::~CAN_Interface()
{
m_canDevice->disconnectDevice();
delete m_canDevice;
}
void CAN_Interface::connect_to_dev(QString dev)
{
QString errorString;
m_canDevice = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), dev, &errorString);
if (!m_canDevice)
@@ -30,12 +40,6 @@ CAN_Interface::CAN_Interface(QString dev, QObject *parent) : QObject(parent)
});
}
CAN_Interface::~CAN_Interface()
{
m_canDevice->disconnectDevice();
delete m_canDevice;
}
void CAN_Interface::send_frame(const QCanBusFrame frame)
{
m_canDevice->writeFrame(frame);