Index: CMakeLists.txt =================================================================== diff -u -rcfc0df719cb5033078d0cac45ce0f6243810f2e7 -r6b422c15085ed605d40cb5dd70177e4657a0ca7e --- CMakeLists.txt (.../CMakeLists.txt) (revision cfc0df719cb5033078d0cac45ce0f6243810f2e7) +++ CMakeLists.txt (.../CMakeLists.txt) (revision 6b422c15085ed605d40cb5dd70177e4657a0ca7e) @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.16) -project(CloudSync +project(RtCDT + DESCRIPTION "Real-time Cloud Data Transmission" LANGUAGES CXX ) @@ -40,6 +41,6 @@ add_subdirectory(lib) add_subdirectory(tools) -add_subdirectory(CloudSyncRt) +add_subdirectory(LeahiRt) # dump_cmake_variables() Fisheye: Tag 6b422c15085ed605d40cb5dd70177e4657a0ca7e refers to a dead (removed) revision in file `CloudSyncRt/CMakeLists.txt'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6b422c15085ed605d40cb5dd70177e4657a0ca7e refers to a dead (removed) revision in file `CloudSyncRt/CloudSyncRtController.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6b422c15085ed605d40cb5dd70177e4657a0ca7e refers to a dead (removed) revision in file `CloudSyncRt/CloudSyncRtController.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6b422c15085ed605d40cb5dd70177e4657a0ca7e refers to a dead (removed) revision in file `CloudSyncRt/main.cpp'. Fisheye: No comparison available. Pass `N' to diff? Index: LeahiRt/CMakeLists.txt =================================================================== diff -u --- LeahiRt/CMakeLists.txt (revision 0) +++ LeahiRt/CMakeLists.txt (revision 6b422c15085ed605d40cb5dd70177e4657a0ca7e) @@ -0,0 +1,43 @@ +project(LeahiRt + DESCRIPTION "Leahi Real-time Cloud Data Transmission" + LANGUAGES CXX +) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_AUTOMOC ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core WebSockets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core WebSockets) + +find_package(Comms HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../lib/Comms REQUIRED) +find_package(MsgUtils HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../lib/MsgUtils REQUIRED) + +set(INCLUDES + LeahiRtController.h +) + +set(SRCS + LeahiRtController.cpp + main.cpp +) + +add_executable(${PROJECT_NAME}) + +target_sources(${PROJECT_NAME} PRIVATE ${INCLUDES} ${SRCS}) + +set_target_properties(${PROJECT_NAME} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin" + ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../bin" +) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Comms + MsgUtils + Qt${QT_VERSION_MAJOR}::WebSockets + Qt${QT_VERSION_MAJOR}::Core +) Index: LeahiRt/LeahiRtController.cpp =================================================================== diff -u --- LeahiRt/LeahiRtController.cpp (revision 0) +++ LeahiRt/LeahiRtController.cpp (revision 6b422c15085ed605d40cb5dd70177e4657a0ca7e) @@ -0,0 +1,52 @@ +#include +#include // SQ +#include + +#include "AlphaOmega.h" // SQ +#include "LeahiRtController.h" +#include "LeahiMsgDefs.h" + +LeahiRtController::LeahiRtController(QObject *parent) : + QObject(parent), + _canInterface(), + _canThread(this), + _clientSocket(QString(), QWebSocketProtocol::VersionLatest, this), + _msgBuilder(this) + // SQ _protoInterface(), + // SQ _protoThread(this) +{ + _canInterface.init(_canThread); + connect(&_canInterface, &Can::CanInterface::didFrameReceive, this, &LeahiRtController::onFrameReceive); + + // SQ _protoInterface.init(_protoThread); + // SQ connect(this, &LeahiRtController::didCanMessageReceive, &_protoInterface, &proto::ProtoInterface::onCanMessageReceive); + + connect(&_clientSocket, &QWebSocket::connected, [&]() { qDebug().noquote() << "Socket connected"; }); +} + +LeahiRtController::~LeahiRtController() +{ + _clientSocket.close(); +} + +void LeahiRtController::openSocket(const QString host, const unsigned int port) +{ + AO_BEGIN_END_CLASS(ao) // SQ + _clientSocket.close(); + _clientSocket.open(QUrl(QString("ws://%1:%2").arg(host).arg(port))); +} + +void LeahiRtController::onFrameReceive(const QCanBusFrame frame) +{ + const Can::CanId canId = Can::CanId(frame.frameId()); + Can::Message &msg = _messages[canId]; + // construct the message from the received frame and determine if a complete message has been received + if (_msgBuilder.buildMessage(frame.payload(), msg, canId) && msg.isComplete()) { + // SQ Q_EMIT didCanMessageReceive(QDateTime::currentDateTime(), msg); + // if (_clientSocket.isValid()) { + qDebug().noquote() << QString("Received message with MsgId=0x%1").arg(QString("%1").arg(msg.msgId, 4, 16, QChar('0')).toUpper()); + _clientSocket.sendBinaryMessage(leahi::canMessageToProtobufByteArray(QDateTime::currentDateTime(), QStringLiteral("test_device"), msg)); + // } + msg.clear(); + } +} Index: LeahiRt/LeahiRtController.h =================================================================== diff -u --- LeahiRt/LeahiRtController.h (revision 0) +++ LeahiRt/LeahiRtController.h (revision 6b422c15085ed605d40cb5dd70177e4657a0ca7e) @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "CanInterface.h" +#include "CanMessage.h" +#include "MessageBuilder.h" +// SQ #include "ProtoInterface.h" + +using namespace Can; + +class LeahiRtController : public QObject +{ + Q_OBJECT + +public: + explicit LeahiRtController(QObject *parent = nullptr); + ~LeahiRtController(); + + void openSocket(const QString host, const unsigned int port=80); + +private: + Can::CanInterface _canInterface; + QThread _canThread; + QWebSocket _clientSocket; + Can::MessageBuilder _msgBuilder; + QMap _messages; + // SQ proto::ProtoInterface _protoInterface; + // SQ QThread _protoThread; + +Q_SIGNALS: + void didCanMessageReceive(const QDateTime timestamp, const Can::Message msg); + +private Q_SLOTS: + void onFrameReceive(const QCanBusFrame frame); +}; Index: LeahiRt/main.cpp =================================================================== diff -u --- LeahiRt/main.cpp (revision 0) +++ LeahiRt/main.cpp (revision 6b422c15085ed605d40cb5dd70177e4657a0ca7e) @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include + +#include "LeahiRtController.h" + +#define log qDebug().noquote() + +/*! + * \brief signalHandler + * \details When application terminates it quits gracefully. + * \param[in] sig - The Linux signal causes the termination. + */ +void signalHandler(int sig) +{ + if (sig == SIGINT) { + log << "Application terminated by SIGINT"; + qApp->quit(); + } + else if (sig == SIGTERM) { + log << "Application terminated by SIGTERM"; + qApp->quit(); + } +} + +int main(int argc, char *argv[]) +{ + signal(SIGINT , signalHandler); + signal(SIGTERM, signalHandler); + + QCoreApplication app(argc, argv); + app.setApplicationName("LeahiRt"); + app.setApplicationVersion("1.0"); + + LeahiRtController rtController; + rtController.openSocket("localhost", 80); + + return app.exec(); +}