Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
CanBusManager.cpp
Go to the documentation of this file.
1
22
23#include "CanBusManager.hpp"
24#include <QDebug>
25#include "MCP2515Controller.hpp"
26
36CanBusManager::CanBusManager(const std::string &spi_device, QObject *parent)
37 : QObject(parent)
38{
39 m_controller = new MCP2515Controller(spi_device);
42}
43
54 : QObject(parent)
55 , m_controller(controller)
56{
59}
60
68{
69 if (m_thread) {
70 m_controller->stopReading();
71 m_thread->disconnect();
72 m_thread->quit();
73 m_thread->wait();
74
75 delete m_thread;
76 m_thread = nullptr;
77 }
78
80 delete m_controller;
81 }
82}
83
96
105{
106 if (!m_controller->init()) {
107 return false;
108 }
109
110 m_thread = new QThread(this);
111 m_controller->moveToThread(m_thread);
112
113 connect(m_thread, &QThread::started, m_controller, &IMCP2515Controller::processReading);
114 connect(m_thread, &QThread::finished, m_controller, &QObject::deleteLater);
115 connect(m_thread, &QThread::finished, m_thread, &QObject::deleteLater);
116
117 m_thread->start();
118 return true;
119}
Definition of the CanBusManager class.
Definition of the MCP2515Controller class.
void rpmUpdated(int newRpm)
Signal emitted when the RPM is updated.
void speedUpdated(float newSpeed)
Signal emitted when the speed is updated.
void connectSignals()
Method to connect signals.
bool ownsMCP2515Controller
Flag to indicate if the MCP2515 controller is owned by the CanBusManager.
QThread * m_thread
Pointer to the QThread object.
bool initialize()
Initializes the CanBusManager.
~CanBusManager()
Destroy the CanBusManager::CanBusManager object.
IMCP2515Controller * m_controller
Pointer to the IMCP2515Controller object.
CanBusManager(const std::string &spi_device, QObject *parent=nullptr)
Construct a new CanBusManager::CanBusManager object.
Interface for the MCP2515 CAN controller. QObject.
void rpmUpdated(int newRpm)
Signal emitted when the RPM is updated.
virtual void processReading()=0
void speedUpdated(float newSpeed)
Signal emitted when the speed is updated.
Class that controls the MCP2515 CAN controller. IMCP2515Controller.