Index: sources/applicationcontroller.cpp =================================================================== diff -u -rde2f87e15fa05b1c45581cfedd8f1af0c47c2b48 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision de2f87e15fa05b1c45581cfedd8f1af0c47c2b48) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -54,15 +54,15 @@ connect(_GuiController , SIGNAL(didActionRequest(GuiActionType)), this , SLOT( onActionRequest(GuiActionType))); // From GUI - connect(_GuiController , SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), - this , SLOT( onActionPerform(GuiActionType, GuiActionInfo))); + connect(_GuiController , SIGNAL(didActionPerform(GuiActionType,GuiActionData)), + this , SLOT( onActionPerform(GuiActionType, GuiActionData))); // From HD/DG connect(_MessageHandler, SIGNAL(didActionCommand(GuiActionType)), this , SLOT( onActionCommand(GuiActionType))); // From HD/DG - connect(_MessageHandler, SIGNAL(didActionConfirm(GuiActionType,GuiActionInfo)), - this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); + connect(_MessageHandler, SIGNAL(didActionConfirm(GuiActionType,GuiActionData)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionData))); } @@ -84,14 +84,14 @@ * \details An action which has been commanded by HD has been performed by GUI.\n * GUI notifies that the action has been performed * \param vAction - * \param vInfo + * \param vData */ -void ApplicationController::onActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +void ApplicationController::onActionPerform(GuiActionType vAction, GuiActionData vData) { - // qDebug() << "ApplicationController.actionPerformed : " << vAction << vInfo; + // qDebug() << "ApplicationController.actionPerformed : " << vAction << vData; // Process the performed action by GUI // Process ... - emit didActionPerform(vAction, vInfo); + emit didActionPerform(vAction, vData); } /*! @@ -113,12 +113,12 @@ * \details GUI requested an action. * In response HD confirmed the action. * \param vAction - * \param vInfo + * \param vData */ -void ApplicationController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) +void ApplicationController::onActionConfirm(GuiActionType vAction, GuiActionData vData) { // qDebug() << "ApplicationController.actionConfirmed : " << vAction; // Process the command and notify GUI Controller // Process ... - emit didActionConfirm(vAction, vInfo); + emit didActionConfirm(vAction, vData); } Index: sources/applicationcontroller.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/applicationcontroller.h (.../applicationcontroller.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/applicationcontroller.h (.../applicationcontroller.h) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -49,17 +49,17 @@ private slots: // Should be private for thread safety and is connected internally. void onActionRequest (GuiActionType vAction); // UI => HD/DG - void onActionConfirm (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void onActionConfirm (GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void onActionCommand (GuiActionType vAction); // UI <= HD/DG - void onActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void onActionPerform (GuiActionType vAction, GuiActionData vData); // UI => HD/DG signals: void didActionRequest(GuiActionType vAction ); // UI => HD/DG - void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void didActionConfirm(GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void didActionCommand(GuiActionType vAction ); // UI <= HD/DG - void didActionPerform(GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void didActionPerform(GuiActionType vAction, GuiActionData vData); // UI => HD/DG void quit(int retcode=0); Index: sources/canbus/caninterface.cpp =================================================================== diff -u -rde2f87e15fa05b1c45581cfedd8f1af0c47c2b48 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision de2f87e15fa05b1c45581cfedd8f1af0c47c2b48) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -31,6 +31,11 @@ */ CanInterface::CanInterface(QObject *parent) : QObject(parent) {} +/*! + * \brief CanInterface Initialization + * \details Initializes the CANBUS and check if can be connected + * \return true if connected false otherwise + */ bool CanInterface::init() { QString mError; @@ -54,14 +59,23 @@ return true; } +/*! + * \brief CanInterface status + * \details CanInterface status description + * \return + */ QString CanInterface::status() const { return _canStatus; } +/*! + * \brief CanInterface connection + * \details Initializes the required signal/slot connection between this class and other objects\n + * to be able to communicate. + */ void CanInterface::connection() { - if (_canDevice) { connect(_canDevice, SIGNAL(framesReceived()), this , SLOT ( onRead())); @@ -74,6 +88,12 @@ this , SLOT( onActionRequest(QCanBusFrame))); } +/*! + * \brief CanInterface status + * \details Sets the Can interface status description + * \param vDescription Description about the Can Interface error + * \param vError Qt Can Interface Error + */ void CanInterface::status(const QString &vDescription, QString vError) { QString mError=""; @@ -89,16 +109,24 @@ .arg(_canInterface) .arg(mError) ; - // qDebug() << _canStatus; } +/*! + * \brief CanInterface send + * \details send a frame over the CAN Bus + * \param vFrame CAN message frame + */ void CanInterface::send(const QCanBusFrame &vFrame) { if( !_canDevice ) return; _canDevice->writeFrame(vFrame); } +/*! + * \brief CanInterface quit + * \details Quit the Can Interface by disconnecting the bus and device. + */ void CanInterface::quit() { if (!_canDevice) @@ -111,6 +139,12 @@ status(tr("Disconnected")); } +/*! + * \brief frameFlags + * \details Can message frame type as flags + * \param frame Can message frame + * \return Frame flag + */ static QString frameFlags(const QCanBusFrame &frame) { QString result = QLatin1String(" --- "); @@ -125,6 +159,11 @@ return result; } +/*! + * \brief CanInterface onError + * \details Can Bus error handler which sets the can status description + * \param vError CanBus error + */ void CanInterface::onError(QCanBusDevice::CanBusError vError) { switch (vError) { @@ -141,6 +180,10 @@ emit didError(_canStatus); } +/*! + * \brief CanInterface onRead + * \details CanBus read handler + */ void CanInterface::onRead() { if (!_canDevice) @@ -170,12 +213,24 @@ } } +/*! + * \brief CanInterface onActionPerform + * \details sends a Can message frame of the can message of the performed action + * This is a response from application UI to HD device + * \param vFrame Can message frame + */ void CanInterface::onActionPerform(const QCanBusFrame &vFrame) { // TODO : Process Frame send(vFrame); } +/*! + * \brief CanInterface onActionRequest + * \details sends a Can message frame of the can message of the requested action + * This is a request for action from application UI to HD device + * \param vFrame Can message frame + */ void CanInterface::onActionRequest(const QCanBusFrame &vFrame) { // TODO : Process Frame Index: sources/canbus/messagehandler.cpp =================================================================== diff -u -rde2f87e15fa05b1c45581cfedd8f1af0c47c2b48 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/canbus/messagehandler.cpp (.../messagehandler.cpp) (revision de2f87e15fa05b1c45581cfedd8f1af0c47c2b48) +++ sources/canbus/messagehandler.cpp (.../messagehandler.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -19,6 +19,7 @@ // Qt #include +#include // Project #include "applicationcontroller.h" @@ -43,26 +44,114 @@ void MessageHandler::init() { connection(); + checked_in(); + //startTimer(1000); } /*! * \brief Message Handler connections definition + * \details Initializes the required signal/slot connection between this class and other objects\n + * to be able to communicate. */ void MessageHandler::connection() { // From GUI connect(_ApplicationController, SIGNAL(didActionRequest(GuiActionType)), this , SLOT( onActionRequest(GuiActionType))); // From GUI - connect(_ApplicationController, SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), - this , SLOT( onActionPerform(GuiActionType, GuiActionInfo))); + connect(_ApplicationController, SIGNAL(didActionPerform(GuiActionType,GuiActionData)), + this , SLOT( onActionPerform(GuiActionType, GuiActionData))); // From HD/DG connect(_CanInterface , SIGNAL(didRead(QCanBusFrame)), this , SLOT( onRead(QCanBusFrame))); } +void MessageHandler::checked_in() +{ + QCanBusFrame mFrame; + mFrame.setFrameId(eChlid_UI); + mFrame.setPayload(buildMessage(GuiActions::Check_In)); + emit didActionPerform(mFrame); +} +QByteArray MessageHandler::buildMessage(GuiActionType vAction, GuiActionData vData) +{ + QByteArray mPayload ; + addSyncByte (mPayload); + addActionId (mPayload, vAction ); // Message ID + addLegth (mPayload, vAction ); // Payload Length + addPayload (mPayload); // Adding required Data + addChecksum (mPayload); // Checksum + addPadding (mPayload); // Padded to 8 byte frame + return mPayload ; +} + +void MessageHandler::addSyncByte(QByteArray &vPayload) +{ + vPayload.append(ePayload_Sync); // Sync byte +} + +void MessageHandler::addActionId(QByteArray &vPayload, GuiActionType vAction) +{ + if (vAction != GuiActions::Unknown) { + vPayload += (vAction >> 8) & 0xFF;//high byte + vPayload += vAction & 0xFF;// low byte + } +} + +void MessageHandler::addLegth(QByteArray &vPayload, GuiActionType vAction) +{ + vPayload.append( payloadLen[vAction]); +} + +void MessageHandler::addPayload(QByteArray &vPayload, GuiActionData vData) +{ + // if the payload is more than a remaining frame empty bytes + // then it requires to be chopped. + vPayload.append(vData); // Adding required Data +} + +void MessageHandler::addPadding(QByteArray &vPayload) +{ + vPayload.rightJustified(eCanFrameLen,'\0'); +} + +quint8 MessageHandler::checksum(QByteArray &vBytes) +{ + // TODO : has not been used yet + return '\0'; +} + +bool MessageHandler::hasSyncByte(QByteArray &vPayload) +{ + if (vPayload.left(eLenSync) == ePayload_Sync) { + vPayload = vPayload.right(eLenSync); + return true; + } + return false; +} + +GuiActionType MessageHandler::getActionId(QByteArray &vPayload) +{ + GuiActionType mActionId = vPayload.left(eLenActionId); + vPayload = vPayload.right(eLenActionId); + return mActionId; +} + +quint8 MessageHandler::getLength(QByteArray &vPayload) +{ + quint8 mPayloadLength = vPayload.left(eLenPayload); + vPayload = vPayload.right(eLenPayload); + return mPayloadLength; +} + +void MessageHandler::addChecksum(QByteArray &vPayload) +{ + vPayload += checksum(vPayload); +} + + /*! * \brief Process the requested action * \details Processes the requested action @@ -72,16 +161,8 @@ { // TODO : Test Code QCanBusFrame mFrame; - QString mPayload; - switch (vAction) { - case GuiActionType::PowerOff: - mFrame.setFrameId(eChlid_UI); - mPayload = "A5 01 00 00 00 00 00 00"; - mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char(' ')).toLatin1())); - break; - default: - break; - } + mFrame.setFrameId(eChlid_UI); + mFrame.setPayload(buildMessage(vAction)); emit didActionRequest(mFrame); } @@ -90,27 +171,14 @@ * \details An action which has been commanded by HD has been performed by GUI.\n * GUI notifies that the action has been performed * \param vAction - * \param vInfo + * \param vData */ -void MessageHandler::onActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +void MessageHandler::onActionPerform(GuiActionType vAction, GuiActionData vData) { // TODO : Test Code QCanBusFrame mFrame; - QString mPayload; - switch (vAction) { - case GuiActionType::PowerOff: - mFrame.setFrameId(eChlid_UI); - if (vInfo == GuiActionInfo::Accepted) { - mPayload = "A5 01 00 01 01 00 00 00"; - } - else { - mPayload = "A5 01 00 01 00 00 00 00"; - } - mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char(' ')).toLatin1())); - break; - default: - break; - } + mFrame.setFrameId(eChlid_UI); + mFrame.setPayload(buildMessage(vAction, vData)); emit didActionPerform(mFrame); } @@ -121,28 +189,69 @@ void MessageHandler::onRead(const QCanBusFrame &vFrame) { // TODO : Test Code - bool isCommand = true; - bool isUnknown = false; + bool isCommand = true ; + bool isUnknown = false; + bool isIgnored = false; - // TODO : For test - if (vFrame.toString() != " 020 [8] A5 01 00 00 00 00 00 00") { - isUnknown = true; - } + //// TODO : For test + //QString cmd = " 020 [8] A5 01"; + //if (vFrame.toString().left(cmd.length()) != cmd) { + // isUnknown = true; + //} - switch (vFrame.frameId()) { + Can_Id mCanId = vFrame.frameId(); + switch (mCanId) { + case eChlid_HD_DG: + case eChlid_DG_HD: + isIgnored = true; + break; case eChlid_HD: - // qDebug() << "<=HD"; break; default: break; } - if (isUnknown) return; + QByteArray mPayload = vFrame.payload(); + Message message; + if (messages[mCanId].isEmpty()) { + // there is no message in the message list for this channel + // so we expect to have a new message which starts with Sync + // and we are striping out the payload and add to the list + if (hasSyncByte(mPayload)) { + message.actionId = getActionId(mPayload); + message.length = getLength(mPayload); + + if (message.length <= eMaxHeaderData) { // payload can be fitted in one frame so we have all the payload + message.data = getPayload(mPayload); + } else { + + } + + if (checksum(message.data) != getChecksum(mPayload)) { + // ERROR : Checksum error + } + messages[mCanId].append(message); + } else { + // ERROR : incomplete message or corrupted without sync byte (without header) + } + } else { + if (!messages[mCanId].last().isFull()) { + + } + } + + + if (isUnknown || isIgnored) return; + if (isCommand) { - //qDebug() << vFrame.toString(); emit didActionCommand(GuiActions::PowerOff); } else { emit didActionConfirm(GuiActions::PowerOff,GuiActions::Accepted); } } + +void MessageHandler::timerEvent(QTimerEvent *event) +{ + QObject::timerEvent(event); +} Index: sources/canbus/messagehandler.h =================================================================== diff -u -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/canbus/messagehandler.h (.../messagehandler.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) +++ sources/canbus/messagehandler.h (.../messagehandler.h) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -20,6 +20,7 @@ // Qt #include #include +#include // Project #include "main.h" @@ -35,8 +36,27 @@ using namespace Gui; namespace Can { +#define CAN_FRAME_LENGTH 8 +#define MAX_PAYLOAD_IN_HEADER_FRAME 3 + /*! - * \brief The MessageHandler class + * + * \brief The MessageHandler class + * \details This class is handling the can message by building and striping it. + * // -- CAN MESSAGE STRUCTURE -- + * #1 #2 #3 #4 #5 #6 #7 #8 + * +---+---+---+---+---+---+---+---+...........+ + * | A5| MsgId |Len| Payload |CRC|..padding..| + * +---+---+---+---+---+---+---+---+...........+ + * Header Frame: + * 1 - CRC is last after payload + * Ex1 - If Len=0 then CRC is #5 + * Ex2 - If Len=1 then CRC is #6 and payload is #5 + * 2 - If CRC is not the last by in the frame + * then there is padding 0x00 to make the frame 8 byte fix + * Tail Frame: + * 3 - Partial frames only have Payload and CRC ( and padded) + * */ class MessageHandler : public QObject { @@ -45,33 +65,116 @@ // friends friend class ::unittests; + struct Message { + quInt8 length; + GuiActionType actionId; + QByteArray data; + bool isFull() { + return length == data.length(); + } + }; + + typedef QList MessageList; + QHash messages; + + const QMap payloadLen { + {GuiActions::PowerOff, 0x01}, + {GuiActions::Check_In, 0x00} + }; + // constants - enum payload_info { - ePayload_Sync = 0xA5, + enum Payload_Data : quint8 { + ePayload_None = 0x00, + ePayload_Sync = 0xA5, }; - enum can_id { - eChlid_HD = 0x020, - eChlid_UI = 0x100, + enum Frame_Data : quint8 { + eCanFrameLen = 8, + eMaxHeaderData = 3, + + eLenSync = 1, + eLenActionId = 2, + eLenPayload = 1, + eLenChecksum = 1, + }; + enum Can_Id : quint16 { + // Broadcasts + //// Alarm + eChlid_HD_Alarm = 0x001, ///< HD alarm broadcast + eChlid_DG_Alarm = 0x002, ///< DG alarm broadcast + eChlid_UI_Alarm = 0x004, ///< UI alarm broadcast [Out] + //// Sync + eChlid_HD_Sync = 0x040, ///< HD sync broadcast + eChlid_DG_Sync = 0x080, ///< DG sync broadcast + eChlid_UI_Sync = 0x200, ///< UI sync broadcast [Out] + + // UI not listening + eChlid_HD_DG = 0x008, ///< HD => DG + eChlid_DG_HD = 0x010, ///< DG => HD + + // UI is listening + eChlid_HD = 0x020, ///< HD => UI + eChlid_UI = 0x100, ///< UI => HD [Out] + + // UI lessens occasionally + eChlid_DG_UI = eChlid_DG_Alarm, ///< No direct channel has been defined between DG&UI, May be required for logging + eChlid_UI_DG = eChlid_UI_Sync , ///< No direct channel has been defined between DG&UI, May be required for logging + + + + }; + // Singleton SINGLETON_DECL(MessageHandler) public: void init(); private: void connection(); + void checked_in(); // TODO : needs to be renamed and called from the main timer to tell HD, UI is alive + // build message to be sent + QByteArray buildMessage (GuiActionType vAction , GuiActionData vData = GuiActionData::NoData); + void addSyncByte ( QByteArray &vPayload ); + void addActionId ( QByteArray &vPayload , GuiActionType vAction); + void addLegth ( QByteArray &vPayload , GuiActionType vAction); + void addPayload ( QByteArray &vPayload , GuiActionData vData = GuiActionData::NoData); + void addChecksum ( QByteArray &vPayload ); + void addPadding ( QByteArray &vPayload ); + + quint8 checksum ( QByteArray &vBytes ); + + // strip message to its parts + QByteArray stripMessage ( const QCanBusFrame &vFrame ); + bool hasSyncByte ( QByteArray &vPayload ); + GuiActionType getActionId ( QByteArray &vPayload ); + quint8 getLength ( QByteArray &vPayload ); + QByteArray getPayload ( QByteArray &vPayload ); + bool getChecksum ( QByteArray &vPayload ); + + // 0 - command definition + // 0.0- Can ID + // 0.1- command id + // 0.2- command payload length + + // 1 - create, frame, schedule, send + + + // 2 - read, categorize, buffer, act + private slots: // Should be private for thread safety and is connected internally. void onActionRequest (GuiActionType vAction); // UI => HD/DG - void onActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void onActionPerform (GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void onRead (const QCanBusFrame &vFrame); +protected: + virtual void timerEvent(QTimerEvent *event) override; signals: - void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void didActionConfirm(GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void didActionCommand(GuiActionType vAction ); // UI <= HD/DG void didActionRequest(const QCanBusFrame &vFrame ); // UI => HD/DG Index: sources/gui/guiactions.cpp =================================================================== diff -u -r09e6b966b0e44bad7540f1571e7562b28e3d9fe7 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guiactions.cpp (.../guiactions.cpp) (revision 09e6b966b0e44bad7540f1571e7562b28e3d9fe7) +++ sources/gui/guiactions.cpp (.../guiactions.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -1,7 +1,24 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * \copyright \n + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n + * IN PART OR IN WHOLE, \n + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n + * + * \file guicontroller.h + * \date 2019/09/30 + * \author Behrouz NematiPour + * + */ + #include "guiactions.h" using namespace Gui; +/*! + * \brief GuiActions Constructor + */ GuiActions::GuiActions() { } Index: sources/gui/guiactions.h =================================================================== diff -u -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guiactions.h (.../guiactions.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) +++ sources/gui/guiactions.h (.../guiactions.h) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -6,7 +6,7 @@ * IN PART OR IN WHOLE, \n * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n * - * \file guiactions.h + * \file guiactions.cpp * \date 2019/09/30 * \author Behrouz NematiPour * @@ -22,22 +22,23 @@ Q_GADGET explicit GuiActions(); public: - enum GuiActionsType_Enum { - Unknown, - PowerOff, + enum GuiActionsType_Enum /*: quint16 QML doesn't support*/ { + Unknown = 0x0000, + PowerOff = 0x0100, + Check_In = 0x0700, }; - enum GuiActionsInfo_Enum { - NoInfo, - Accepted, - Rejected, + enum GuiActionsData_Enum /*: quint8 QML doesn't support*/ { + NoData = 0x00, + Accepted = 0x01, + Rejected = 0x00, }; Q_ENUM(GuiActionsType_Enum) - Q_ENUM(GuiActionsInfo_Enum) + Q_ENUM(GuiActionsData_Enum) }; // to be able to use the enum as signal/slot parameter typedef GuiActions::GuiActionsType_Enum GuiActionType; -typedef GuiActions::GuiActionsInfo_Enum GuiActionInfo; +typedef GuiActions::GuiActionsData_Enum GuiActionData; } Index: sources/gui/guicontroller.cpp =================================================================== diff -u -rde2f87e15fa05b1c45581cfedd8f1af0c47c2b48 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision de2f87e15fa05b1c45581cfedd8f1af0c47c2b48) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -40,8 +40,8 @@ connect(_ApplicationController, SIGNAL(didActionCommand(GuiActionType)), this , SLOT( onActionCommand(GuiActionType))); // From HD/DG - connect(_ApplicationController, SIGNAL(didActionConfirm(GuiActionType, GuiActionInfo)), - this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); + connect(_ApplicationController, SIGNAL(didActionConfirm(GuiActionType, GuiActionData)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionData))); } @@ -55,8 +55,8 @@ } /*! - * \brief GuiController::onActionRequest - * This method Confirmed that if the action is accepted or not,\n + * \brief An Action has been requested + * \details This method Confirmed that if the action is accepted or not,\n * Regarding the current state and the action.\n * These actions are only user actions and there is only one user interaction,\n * So no need to capture from which screen this action comes since we have the current state.\n @@ -66,14 +66,13 @@ void GuiController::doActionRequest(GuiActionType vAction) { // Process the GuiView Request. - // If can be processed in GuiController take action and notify GuiView - //qDebug() << "GuiController.actionRequested : " << vAction; - GuiActionInfo mInfo = GuiActionInfo::Accepted; - Q_UNUSED(mInfo) + // It can be processed in GuiController take action and notify GuiView + GuiActionData mData = GuiActionData::Accepted; switch (vAction) { - // TODO : Test Code case GuiActionType::PowerOff: - emit didActionConfirm(vAction, mInfo); + //GUI Controller decides (loop back) + //case Another_Command_Which_Doesn't_Require_HD_Approval: + emit didActionConfirm(vAction, mData); break; default: // If it requires to be Confirmed by HD/DG send the request to ApplicationController @@ -87,14 +86,13 @@ * \details An action which has been commanded by HD has been performed by Gui.\n * Gui notifies that the action has been performed * \param vAction - * \param vInfo + * \param vData */ -void GuiController::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +void GuiController::doActionPerform(GuiActionType vAction, GuiActionData vData) { - // qDebug() << "GuiController.actionPerformed : " << vAction << vInfo; // Process the performed action by Gui // Process ... - emit didActionPerform(vAction, vInfo); + emit didActionPerform(vAction, vData); } /*! @@ -105,7 +103,6 @@ */ void GuiController::onActionCommand(GuiActionType vAction) { - // qDebug() << "GuiController.actionCommanded : " << vAction; // Process the command and notify GuiView // Process ... emit didActionCommand(vAction); @@ -116,12 +113,11 @@ * \details Gui requested an action. * In response HD confirmed the action. * \param vAction - * \param vInfo + * \param vData */ -void GuiController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) +void GuiController::onActionConfirm(GuiActionType vAction, GuiActionData vData) { - // qDebug() << "GuiController.actionConfirmed : " << vAction; // Process the command and notify GuiView // Process ... - emit didActionConfirm(vAction, vInfo); + emit didActionConfirm(vAction, vData); } Index: sources/gui/guicontroller.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guicontroller.h (.../guicontroller.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guicontroller.h (.../guicontroller.h) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -39,18 +39,18 @@ public slots: void doActionRequest (GuiActionType vAction); // UI => HD/DG - void doActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void doActionPerform (GuiActionType vAction, GuiActionData vData); // UI => HD/DG private slots: // Should be private for thread safety and is connected internally. - void onActionConfirm (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void onActionConfirm (GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void onActionCommand (GuiActionType vAction); // UI <= HD/DG signals: void didActionRequest(GuiActionType vAction ); // UI => HD/DG - void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void didActionConfirm(GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void didActionCommand(GuiActionType vAction ); // UI <= HD/DG - void didActionPerform(GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void didActionPerform(GuiActionType vAction, GuiActionData vData); // UI => HD/DG }; } Index: sources/gui/guiglobals.cpp =================================================================== diff -u -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guiglobals.cpp (.../guiglobals.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) +++ sources/gui/guiglobals.cpp (.../guiglobals.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -23,18 +23,30 @@ namespace Gui { QQuickView *_viewer = nullptr; + /*! + * \brief registerTypes + * \details registering meta types + */ void registerTypes() { qRegisterMetaType ("GuiActionType"); - qRegisterMetaType ("GuiActionInfo"); + qRegisterMetaType ("GuiActionData"); } + /*! + * \brief registerQmlTypes + * \details registering QML types + */ void registerQmlTypes() { qmlRegisterType ("Gui.View", 0, 1, "GuiView"); qmlRegisterUncreatableType ("Gui.Actions", 0, 1, "GuiActions",QStringLiteral("Used only for enumerations no need to have an object")); } + /*! + * \brief startGui + * \details the GUI initializer/starter function + */ void startGui() { _viewer = new QQuickView; registerTypes(); Index: sources/gui/guiview.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guiview.cpp (.../guiview.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guiview.cpp (.../guiview.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -31,8 +31,8 @@ void GuiView::connection() { - connect(_GuiController, SIGNAL(didActionConfirm(GuiActionType, GuiActionInfo)), - this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); + connect(_GuiController, SIGNAL(didActionConfirm(GuiActionType, GuiActionData)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionData))); connect(_GuiController, SIGNAL(didActionCommand(GuiActionType )), this , SLOT( onActionCommand(GuiActionType ))); @@ -43,15 +43,15 @@ connect(this , SIGNAL(didActionRequest(GuiActionType)), _GuiController, SLOT( doActionRequest(GuiActionType))); - connect(this , SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), - _GuiController, SLOT( doActionPerform(GuiActionType,GuiActionInfo))); + connect(this , SIGNAL(didActionPerform(GuiActionType,GuiActionData)), + _GuiController, SLOT( doActionPerform(GuiActionType,GuiActionData))); } -void GuiView::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) +void GuiView::onActionConfirm(GuiActionType vAction, GuiActionData vData) { // process the evaluation and notify GUI // process ... - emit didActionConfirm(vAction, vInfo); + emit didActionConfirm(vAction, vData); } void GuiView::onActionCommand(GuiActionType vAction) @@ -67,7 +67,7 @@ emit didActionRequest(vAction); } -void GuiView::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +void GuiView::doActionPerform(GuiActionType vAction, GuiActionData vData) { - emit didActionPerform(vAction, vInfo); + emit didActionPerform(vAction, vData); } Index: sources/gui/guiview.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/guiview.h (.../guiview.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guiview.h (.../guiview.h) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -36,19 +36,19 @@ void connection(); private slots: - void onActionConfirm (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void onActionConfirm (GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void onActionCommand (GuiActionType vAction ); // UI <= HD/DG public slots: // is public since will be used in the UI and is in the same thread. void doActionRequest (GuiActionType vAction ); // UI => HD/DG - void doActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void doActionPerform (GuiActionType vAction, GuiActionData vData); // UI => HD/DG signals: - void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void didActionConfirm(GuiActionType vAction, GuiActionData vData); // UI <= HD/DG void didActionCommand(GuiActionType vAction ); // UI <= HD/DG void didActionRequest(GuiActionType vAction ); // UI => HD/DG - void didActionPerform(GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void didActionPerform(GuiActionType vAction, GuiActionData vData); // UI => HD/DG }; } Index: sources/gui/qml/main.qml =================================================================== diff -u -r174d5078531f9dfbe9cdc45274b852984bb72647 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- sources/gui/qml/main.qml (.../main.qml) (revision 174d5078531f9dfbe9cdc45274b852984bb72647) +++ sources/gui/qml/main.qml (.../main.qml) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -39,7 +39,7 @@ onDidActionConfirm: { switch(vAction) { case GuiActions.PowerOff: - if (vInfo === GuiActions.Accepted) + if (vData === GuiActions.Accepted) _powerOffDialog.open() break; } Index: unittests/unittests.cpp =================================================================== diff -u -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 -rd6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f --- unittests/unittests.cpp (.../unittests.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) +++ unittests/unittests.cpp (.../unittests.cpp) (revision d6c7d6c382fe56e19d132f6ba0bcbbc1e6b2060f) @@ -77,21 +77,21 @@ void unittests::tst_MessageHandler_ActionPerform_PowerOff_Accepted() { _expected = " 100 [8] A5 01 00 01 01 00 00 00"; - Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionInfo::Accepted); + Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionData::Accepted); QVERIFY(_emited); } void unittests::tst_MessageHandler_ActionPerform_PowerOff_Rejected() { _expected = " 100 [8] A5 01 00 01 00 00 00 00"; - Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionInfo::Rejected); + Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionData::Rejected); QVERIFY(_emited); } void unittests::tst_MessageHandler_ActionPerform_Unknown() { _expected = " 000 [0]"; - Can::_MessageHandler->onActionPerform(Gui::GuiActionType::Unknown,Gui::GuiActionInfo::NoInfo); + Can::_MessageHandler->onActionPerform(Gui::GuiActionType::Unknown,Gui::GuiActionData::NoData); QVERIFY(_emited); }