mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
CAN
Move from src to tools
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#include "CAN_interface.hpp"
|
||||
|
||||
CAN_Interface::CAN_Interface(QString dev, QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
if (!QCanBus::instance()->plugins().contains(QStringLiteral("socketcan"))) {
|
||||
throw std::runtime_error("CAN Interface: socketcan plugin not found");
|
||||
}
|
||||
QString errorString;
|
||||
m_canDevice = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), dev, &errorString);
|
||||
if (!m_canDevice)
|
||||
{
|
||||
// Error handling goes here
|
||||
throw std::runtime_error("CAN Interface: " + errorString.toStdString());
|
||||
}
|
||||
|
||||
m_canDevice->connectDevice();
|
||||
connect(m_canDevice, &QCanBusDevice::framesReceived, this, [this] {
|
||||
emit frames_received();
|
||||
});
|
||||
}
|
||||
|
||||
CAN_Interface::~CAN_Interface()
|
||||
{
|
||||
m_canDevice->disconnectDevice();
|
||||
delete m_canDevice;
|
||||
}
|
||||
|
||||
void CAN_Interface::send_frame(const QCanBusFrame &frame)
|
||||
{
|
||||
m_canDevice->writeFrame(frame);
|
||||
}
|
||||
|
||||
QCanBusFrame CAN_Interface::read_frame()
|
||||
{
|
||||
return m_canDevice->readFrame();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <ctime>
|
||||
#include <cstdint>
|
||||
#include <QObject>
|
||||
#include <QCanBus>
|
||||
#include <QCanBusDevice>
|
||||
#include <QCanBusFrame>
|
||||
|
||||
class CAN_Interface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CAN_Interface(QString dev, QObject *parent = nullptr);
|
||||
~CAN_Interface();
|
||||
|
||||
void send_frame(const QCanBusFrame &frame);
|
||||
QCanBusFrame read_frame();
|
||||
signals:
|
||||
void frames_received();
|
||||
private:
|
||||
QCanBusDevice *m_canDevice;
|
||||
};
|
||||
@@ -4,8 +4,9 @@ endif()
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS WebSockets)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core WebSockets SerialBus)
|
||||
|
||||
qt_standard_project_setup()
|
||||
qt_add_executable(server)
|
||||
|
||||
include(FetchContent)
|
||||
@@ -14,6 +15,7 @@ FetchContent_Declare(magic_enum URL https://github.com/Neargye/magic_enum/releas
|
||||
FetchContent_MakeAvailable(magic_enum)
|
||||
|
||||
file(GLOB_RECURSE SIM_SOURCES "simulators/*.[hc]pp")
|
||||
file(GLOB_RECURSE CAN_SOURCES "CAN/*.[hc]pp")
|
||||
|
||||
target_sources(server PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
||||
@@ -25,6 +27,7 @@ target_sources(server PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/websocket.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/websocket.hpp
|
||||
${SIM_SOURCES}
|
||||
${CAN_SOURCES}
|
||||
)
|
||||
|
||||
target_compile_options(server PRIVATE $<$<CONFIG:Debug>:
|
||||
@@ -40,8 +43,8 @@ target_include_directories(server
|
||||
|
||||
target_link_libraries(server PRIVATE
|
||||
Qt::WebSockets
|
||||
Qt::SerialBus
|
||||
magic_enum::magic_enum
|
||||
spdlog
|
||||
UI
|
||||
CAN
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user