Move from src to tools
This commit is contained in:
2024-12-30 12:08:13 +01:00
parent 5fdfb765de
commit 6f72617371
7 changed files with 65 additions and 36 deletions
-1
View File
@@ -1 +0,0 @@
#include "CAN_interface.hpp"
-15
View File
@@ -1,15 +0,0 @@
#pragma once
#include <ctime>
#include <cstdint>
typedef struct can_message_s
{
time_t timestamp;
uint16_t id;
uint8_t dlc;
uint8_t data[8];
can_message_s() : timestamp(0), id(0), dlc(0), data{0}
{
}
} can_message_t;
-16
View File
@@ -1,16 +0,0 @@
add_library(CAN)
target_sources(CAN PRIVATE
CAN_interface.cpp
)
target_compile_options(CAN PRIVATE $<$<CONFIG:Debug>:
-Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion
>)
target_include_directories(CAN
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
PRIVATE
)
+1 -2
View File
@@ -1,2 +1 @@
add_subdirectory(CAN)
add_subdirectory(UI)
add_subdirectory(UI)
+37
View File
@@ -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();
}
+22
View File
@@ -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;
};
+5 -2
View File
@@ -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
)