Index: denali.pro =================================================================== diff -u -rc5389647e2259e67f8e6d923f3481d7d3f4eab68 -rd3f98384e9400f8acb84c88dee75f1c480986998 --- denali.pro (.../denali.pro) (revision c5389647e2259e67f8e6d923f3481d7d3f4eab68) +++ denali.pro (.../denali.pro) (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -36,10 +36,10 @@ sources/applicationcontroller.h \ sources/applicationpost.h \ sources/canbus/caninterface.h \ + sources/canbus/frameinterface.h \ sources/canbus/messagebuilder.h \ sources/canbus/messagedispatcher.h \ sources/canbus/messageglobals.h \ - sources/canbus/messagehandler.h \ sources/canbus/messageinterpreter.h \ sources/configuration/display.h \ sources/configuration/sound.h \ @@ -60,9 +60,9 @@ sources/applicationcontroller.cpp \ sources/applicationpost.cpp \ sources/canbus/caninterface.cpp \ + sources/canbus/frameinterface.cpp \ sources/canbus/messagebuilder.cpp \ sources/canbus/messagedispatcher.cpp \ - sources/canbus/messagehandler.cpp \ sources/canbus/messageinterpreter.cpp \ sources/configuration/display.cpp \ sources/configuration/sound.cpp \ Index: main.cpp =================================================================== diff -u -r3a68ae894549f9b0664ddb817458ca771ec3dd30 -rd3f98384e9400f8acb84c88dee75f1c480986998 --- main.cpp (.../main.cpp) (revision 3a68ae894549f9b0664ddb817458ca771ec3dd30) +++ main.cpp (.../main.cpp) (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -30,7 +30,7 @@ // Project #include "maintimer.h" #include "caninterface.h" -#include "messagehandler.h" +#include "frameinterface.h" #include "messagedispatcher.h" #include "applicationcontroller.h" #include "guicontroller.h" @@ -55,11 +55,11 @@ QCoreApplication::setOrganizationName(QLatin1String("Diality Inc.")); // Test code for debugging can messages - bool _consoleoutMessageHandler = false; + bool _consoleoutFrameInterface = false; bool _consoleoutCanInterface = false; QStringList args = app.arguments(); if (args.length() >= 2) { - _consoleoutMessageHandler = args[1] == "1"; + _consoleoutFrameInterface = args[1] == "1"; } if (args.length() >= 3) { _consoleoutCanInterface = args[2] == "1"; @@ -90,11 +90,11 @@ _CanInterface->enableConsoleOut(_consoleoutCanInterface); //! - Initializing CanBus Message Handler - _MessageHandler->init(); + _FrameInterface->init(); //! - Initializing CanBus Message Dispatcher _MessageDispatcher->init(); - _MessageDispatcher->enableConsoleOut(_consoleoutMessageHandler); + _MessageDispatcher->enableConsoleOut(_consoleoutFrameInterface); //! - Initializing Application Controller _ApplicationController->init(); Index: sources/canbus/caninterface.cpp =================================================================== diff -u -rc5389647e2259e67f8e6d923f3481d7d3f4eab68 -rd3f98384e9400f8acb84c88dee75f1c480986998 --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision c5389647e2259e67f8e6d923f3481d7d3f4eab68) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -17,7 +17,7 @@ #include // Project -#include "messagehandler.h" +#include "frameinterface.h" // namespace using namespace Can; @@ -87,7 +87,7 @@ this , SLOT (onFrameWrittern(qint64))); } - connect(_MessageHandler, SIGNAL(didFrameTransmit(QCanBusFrame)), + connect(_FrameInterface, SIGNAL(didFrameTransmit(QCanBusFrame)), this , SLOT( onFrameTransmit(QCanBusFrame))); } Index: sources/canbus/frameinterface.cpp =================================================================== diff -u --- sources/canbus/frameinterface.cpp (revision 0) +++ sources/canbus/frameinterface.cpp (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -0,0 +1,168 @@ +/*! + * + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * file frameinterface.cpp + * date 10/26/2019 + * author Behrouz NematiPour + * + */ +#include "frameinterface.h" + +// Qt +#include +#include + +// Project +#include "maintimer.h" +#include "messagedispatcher.h" +#include "caninterface.h" +#include "format.h" + +// namespace +using namespace Can; + +// Singleton +SINGLETON_INIT(FrameInterface) + +/*! + * \brief FrameInterface Constructor + * \param parent + */ +FrameInterface::FrameInterface(QObject *parent) : QObject(parent) { } + +/*! + * \brief Message Handler initializer + */ +void FrameInterface::init() +{ + initConnections(); +} + +/*! + * \brief FrameInterface connections definition + * \details Initializes the required signal/slot connection between this class and other objects + * to be able to communicate. + */ +void FrameInterface::initConnections() +{ + // From GUI + connect(_MessageDispatcher, SIGNAL(didFrameTransmit(Can_Id, const QByteArray &)), + this , SLOT( onFrameTransmit(Can_Id, const QByteArray &))); + + // From CAN + connect(_CanInterface , SIGNAL( didFrameReceive( const QCanBusFrame &)), + this , SLOT( onFrameReceive( const QCanBusFrame &))); +} + +/*! + * \brief FrameInterface::transmitFrame + * \details Prepares a frame to be transmitted + * and emit signal didFrameTransmit with the frame as its argument + * \param vFrameId - Channel id of the CANBUS frame + * \param vData - The Data this frame is going to carry + * \note This frame is created by MessageBuilder + * and it can be one of the frames of a message + * which has been chopped into frames. + */ +void FrameInterface::transmitFrame(Can_Id vFrameId, const QByteArray &vData) +{ + QCanBusFrame mFrame; + mFrame.setFrameId(vFrameId); + if (vData.length() > Can::eLenCanFrame) { + qDebug() << "Error :" << tr("Payload can't be larger than %1 bytes").arg(Can::eLenCanFrame); + return; + } + mFrame.setPayload(vData); + emit didFrameTransmit(mFrame); +} + +/*! + * \brief FrameInterface::checkChannel + * \details Checks for the channel id of the received frame + * which needs to be handled or ignored. + * \param vFrameId - Channel id of the frame + * \param vOK - will be set to true if the channel + * is valid and a variable has been passed to + * \return The Category if the channels from the UI + * perspective FrameInterface::ChannelGroup + */ +FrameInterface::ChannelGroup FrameInterface::checkChannel(quint32 vFrameId, bool *vOK) +{ + bool ok = true; + FrameInterface::ChannelGroup channelGroup = ChannelGroup::eChannel_Unknown; + switch (vFrameId) { + case eChlid_HD_DG : + case eChlid_DG_HD : + channelGroup = ChannelGroup::eChannel_Ignores; + break; + + case eChlid_HD : + case eChlid_HD_Alarm : + case eChlid_DG_Alarm : + case eChlid_HD_Sync : + case eChlid_DG_Sync : + //case eChlid_DG_UI : // has duplicate value as eChlid_DG_Alarm + //case eChlid_UI_DG : // has duplicate value as eChlid_UI_Sync + channelGroup = ChannelGroup::eChannel_Listens; + break; + + case eChlid_UI_Alarm : + case eChlid_UI_Sync : + case eChlid_UI : + channelGroup = ChannelGroup::eChannel_Outputs; + break; + + default: + ok = false; + break; + } + + if (vOK) *vOK = ok; + return channelGroup; +} + +/*! + * \brief FrameInterface::onFrameTransmit + * \details This the slot connected to the MessageDispatcher didFrameTransmit signal. + * When a frame needs to be send to CANBUS, + * this slot will call transmitFrame method to do the job. + * \param vCan_ID - CANBUS Can Id target of the frame. + * \param vData - The data which this frame will carry. + */ +void FrameInterface::onFrameTransmit(Can_Id vCan_ID, const QByteArray &vData) +{ + transmitFrame(vCan_ID, vData); +} + +/*! + * \brief FrameInterface::onFrameReceive + * \details This the slot connected to the CanInterface didFrameReceive signal. + * When a frame received over the CANBUS, + * this slot will be called to check the channel if should be listened to. + * and will emit didFrameReceive if should be handled and ignored otherwise. + * \param vFrame - The frame has to be sent + */ +void FrameInterface::onFrameReceive(const QCanBusFrame &vFrame) +{ + bool ok = false; + quint32 mFrameId = vFrame.frameId(); + ChannelGroup channelGroup = checkChannel(mFrameId, &ok); + + if (!ok){ + qDebug() << "ERROR :" << "Unexpected Channel"; + qDebug() << Format::toHexString(mFrameId, false, 3) + " -- " + vFrame.payload().toHex(' '); + return; + } + + if ( channelGroup != ChannelGroup::eChannel_Listens) { + return; + } + + Can_Id mCanId = static_cast(mFrameId); + emit didFrameReceive(mCanId, vFrame.payload()); +} Index: sources/canbus/frameinterface.h =================================================================== diff -u --- sources/canbus/frameinterface.h (revision 0) +++ sources/canbus/frameinterface.h (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -0,0 +1,102 @@ +/*! + * + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * file frameinterface.h + * date 10/26/2019 + * author Behrouz NematiPour + * + */ +#pragma once + +// Qt +#include +#include +#include + +// Project +#include "main.h" +#include "guiglobals.h" +#include "messagebuilder.h" +#include "messageinterpreter.h" + +// Define +#define _FrameInterface FrameInterface::I() + +// forward declarations +class unittests; + +// namespace +using namespace Gui; +namespace Can { + +/*! + * \brief The FrameInterface class + * \details This class is an interface between QByteArray and QCanBusFrame + * and gets the data as QByteArray and creates a frame + * and sends it to the CanInterface to deal with the CANBUS. + * And does it in reverse when receives a frame from CanInterface. + */ +class FrameInterface : public QObject +{ + Q_OBJECT + + // friends + friend class ::unittests; + + /*! + * \brief The ChannelGroup enum + * \details The enum which represent the categories of the CANBUS channel + */ + enum class ChannelGroup { + eChannel_Unknown, ///< An Unknown channels category + eChannel_Ignores, ///< The Channels which will be ignored by UI + eChannel_Listens, ///< The Channels that UI is listening to + eChannel_Outputs, ///< The Channels that are related to UI frames out. + }; + + // Singleton + SINGLETON_DECL(FrameInterface) +public: + void init(); + +private: + void initConnections(); + void transmitFrame(Can_Id vCan_Id, const QByteArray &vData = 0); + ChannelGroup checkChannel(quint32 vFrameId, bool *vOK = nullptr); + +private slots: // Should be private for thread safety and is connected internally. + void onFrameTransmit(Can_Id vCan_ID, const QByteArray &vData ); // GUI => CAN + void onFrameReceive ( const QCanBusFrame &vFrame ); // GUI <= CAN + +signals: + /*! + * \brief didFrameReceive + * \details After CanInterface receives a frame notifies FrameInterface + * by emitting CanInterface::didFrameReceive signal, + * then Message Handler calls its slot FrameInterface::onFrameReceive to handle the message, + * And when the message has been processed vCan_Id of type Can_Id which is the Channel ID of the frame + * and vPayload of the frame of type QByteArray has been extracted, + * This signal will be emitted to notify MessageDispatcher to start collecting data + * for this message over this channel. + * \param vCan_ID - Channel Id of the frame. + * \param vPayload - Payload of the frame. + */ + void didFrameReceive (Can_Id vCan_Id, const QByteArray &vPayload); // GUI <= CAN + + /*! + * \brief didFrameTransmit + * \details After MessageDispatcher requests FrameInterface to transmit a message, + * And FrameInterface calls its slot FrameInterface::onFrameTransmit to handle the message, + * And when the message has been processed and a Frame has been created, + * this signal will be emitted to notify CanInterface to send the frame. + * \ref CanInterface::onFrameTransmit + * \param vFrame - The frame which has been created to be transmitted. + */ + void didFrameTransmit( const QCanBusFrame &vFrame ); // GUI => CAN +}; +} Index: sources/canbus/messagedispatcher.cpp =================================================================== diff -u -r4b9619614f0a9deb0438a803c057918b94aacbec -rd3f98384e9400f8acb84c88dee75f1c480986998 --- sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision 4b9619614f0a9deb0438a803c057918b94aacbec) +++ sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -17,7 +17,7 @@ // Project #include "applicationcontroller.h" -#include "messagehandler.h" +#include "frameinterface.h" using namespace Can; @@ -50,14 +50,14 @@ this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); // From HD - connect(_MessageHandler , SIGNAL(didFrameReceive ( Can_Id, const QByteArray &)), + connect(_FrameInterface , SIGNAL(didFrameReceive ( Can_Id, const QByteArray &)), this , SLOT( onFrameReceive ( Can_Id, const QByteArray &))); } /*! * \brief MessageDispatcher::onFrameReceive * \details Upon message has been received over CANBUS this slot will be called - * by MessageHandler::didFrameReceive signal to process the frame + * by FrameInterface::didFrameReceive signal to process the frame * Upon completion of collected all the required frames * on successful interpretation of the message, emits didActionReceived signal. * The message will be removed from list of the channel vCan_Id messages. Fisheye: Tag d3f98384e9400f8acb84c88dee75f1c480986998 refers to a dead (removed) revision in file `sources/canbus/messagehandler.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag d3f98384e9400f8acb84c88dee75f1c480986998 refers to a dead (removed) revision in file `sources/canbus/messagehandler.h'. Fisheye: No comparison available. Pass `N' to diff? Index: unittests/unittests.cpp =================================================================== diff -u -rfee7fabf49befb065c89248c19e15efc9ca194e4 -rd3f98384e9400f8acb84c88dee75f1c480986998 --- unittests/unittests.cpp (.../unittests.cpp) (revision fee7fabf49befb065c89248c19e15efc9ca194e4) +++ unittests/unittests.cpp (.../unittests.cpp) (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -17,7 +17,7 @@ // Project #include "guiglobals.h" #include "caninterface.h" -#include "messagehandler.h" +#include "frameinterface.h" #include "applicationcontroller.h" #include "guicontroller.h" #include "maintimer.h" @@ -55,66 +55,66 @@ Can::_CanInterface->onFrameReceive (); } -void unittests::tst_MessageHandler_Init() +void unittests::tst_FrameInterface_Init() { - Can::_MessageHandler->init(); - connect(Can::_MessageHandler, &Can::MessageHandler::didActionPerform, [=](const QCanBusFrame &vFrame) { + Can::_FrameInterface->init(); + connect(Can::_FrameInterface, &Can::FrameInterface::didActionPerform, [=](const QCanBusFrame &vFrame) { _emited = true; QString packet = vFrame.toString(); QCOMPARE(packet, _expected); }); - connect(Can::_MessageHandler, &Can::MessageHandler::didActionRequest, [=](const QCanBusFrame &vFrame) { + connect(Can::_FrameInterface, &Can::FrameInterface::didActionRequest, [=](const QCanBusFrame &vFrame) { _emited = true; QString packet = vFrame.toString(); QCOMPARE(packet, _expected); }); - connect(Can::_MessageHandler, &Can::MessageHandler::didActionCommand, [=](Gui::GuiActionType vAction) { + connect(Can::_FrameInterface, &Can::FrameInterface::didActionCommand, [=](Gui::GuiActionType vAction) { _emited = true; QCOMPARE(vAction, _action); }); } -void unittests::tst_MessageHandler_ActionPerform_PowerOff_Accepted() +void unittests::tst_FrameInterface_ActionPerform_PowerOff_Accepted() { _expected = " 100 [8] A5 01 00 01 01 00 00 00"; - Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionData::Accepted); + Can::_FrameInterface->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionData::Accepted); QVERIFY(_emited); } -void unittests::tst_MessageHandler_ActionPerform_PowerOff_Rejected() +void unittests::tst_FrameInterface_ActionPerform_PowerOff_Rejected() { _expected = " 100 [8] A5 01 00 01 00 00 00 00"; - Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionData::Rejected); + Can::_FrameInterface->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionData::Rejected); QVERIFY(_emited); } -void unittests::tst_MessageHandler_ActionPerform_Unknown() +void unittests::tst_FrameInterface_ActionPerform_Unknown() { _expected = " 000 [0]"; - Can::_MessageHandler->onActionPerform(Gui::GuiActionType::Unknown,Gui::GuiActionData::NoData); + Can::_FrameInterface->onActionPerform(Gui::GuiActionType::Unknown,Gui::GuiActionData::NoData); QVERIFY(_emited); } -void unittests::tst_MessageHandler_ActionRequest_PowerOff() +void unittests::tst_FrameInterface_ActionRequest_PowerOff() { _expected = " 100 [8] A5 01 00 00 00 00 00 00"; - Can::_MessageHandler->onActionRequest(Gui::GuiActionType::PowerOff); + Can::_FrameInterface->onActionRequest(Gui::GuiActionType::PowerOff); QVERIFY(_emited); } -void unittests::tst_MessageHandler_ActionRequest_Unknown() +void unittests::tst_FrameInterface_ActionRequest_Unknown() { _expected = " 000 [0]"; - Can::_MessageHandler->onActionRequest(Gui::GuiActionType::Unknown); + Can::_FrameInterface->onActionRequest(Gui::GuiActionType::Unknown); QVERIFY(_emited); } -void unittests::tst_MessageHandler_ActionCommand_PowerOff() +void unittests::tst_FrameInterface_ActionCommand_PowerOff() { _action = Gui::GuiActionType::PowerOff; QCanBusFrame mFrame; QString mPayload; - mFrame.setFrameId(Can::MessageHandler::eChlid_HD); + mFrame.setFrameId(Can::FrameInterface::eChlid_HD); mPayload = "A5 01 00 00 00 00 00 00"; mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char(' ')).toLatin1())); emit Can::_CanInterface->didRead(mFrame); @@ -123,9 +123,9 @@ void unittests::cleanup() { - disconnect(Can::_MessageHandler); + disconnect(Can::_FrameInterface); Can::_CanInterface ->initConnections(); - Can::_MessageHandler->initConnections(); + Can::_FrameInterface->initConnections(); } void unittests::cleanupTestCase() Index: unittests/unittests.h =================================================================== diff -u -rfee7fabf49befb065c89248c19e15efc9ca194e4 -rd3f98384e9400f8acb84c88dee75f1c480986998 --- unittests/unittests.h (.../unittests.h) (revision fee7fabf49befb065c89248c19e15efc9ca194e4) +++ unittests/unittests.h (.../unittests.h) (revision d3f98384e9400f8acb84c88dee75f1c480986998) @@ -36,14 +36,14 @@ void tst_CanInterface_Connect_Error_Type() {} void tst_CanInterface_Connect_NoError(); - void tst_MessageHandler_Init(); + void tst_FrameInterface_Init(); - void tst_MessageHandler_ActionPerform_PowerOff_Accepted(); - void tst_MessageHandler_ActionPerform_PowerOff_Rejected(); - void tst_MessageHandler_ActionPerform_Unknown(); - void tst_MessageHandler_ActionRequest_PowerOff(); - void tst_MessageHandler_ActionRequest_Unknown(); - void tst_MessageHandler_ActionCommand_PowerOff(); + void tst_FrameInterface_ActionPerform_PowerOff_Accepted(); + void tst_FrameInterface_ActionPerform_PowerOff_Rejected(); + void tst_FrameInterface_ActionPerform_Unknown(); + void tst_FrameInterface_ActionRequest_PowerOff(); + void tst_FrameInterface_ActionRequest_Unknown(); + void tst_FrameInterface_ActionCommand_PowerOff(); void cleanup(); void cleanupTestCase();