Index: sources/applicationcontroller.cpp =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -r846a9ebc350e33be4affab3cc4c136248900015d --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 846a9ebc350e33be4affab3cc4c136248900015d) @@ -1,29 +1,34 @@ /*! * * 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 + * \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 applicationcontroller.cpp - * \date 2019/09/30 - * \author Behrouz NematiPour + * \file applicationcontroller.cpp + * \author (last) Behrouz NematiPour + * \date (last) 25-Aug-2020 + * \author (original) Behrouz NematiPour + * \date (original) 24-Sep-2019 * */ #include "applicationcontroller.h" // Qt +#include +#include // Project -#include "guiglobals.h" #include "maintimer.h" -#include "guicontroller.h" #include "messagedispatcher.h" #include "logger.h" -#include "usbwatcher.h" +#include "DriveWatcher.h" #include "filehandler.h" +#include "guicontroller.h" + +using namespace Storage; + /*! * \brief ApplicationController::ApplicationController * \details Constructor @@ -44,10 +49,11 @@ _init = true; initConnections(); + // coco begin validated: The class ApplicationPost has not been implemented Yet. if (!_applicationPost->init()) return false; + // coco end + LOG_EVENT("UI," + tr("%1 Initialized").arg(metaObject()->className())); - LOG_EVENT(QObject::tr("%1 Initialized").arg(metaObject()->className())); - return true; } @@ -75,7 +81,7 @@ { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. - quitThread(); + quitThread(); // validated } // coco end @@ -97,18 +103,31 @@ connect(&_MessageDispatcher, SIGNAL(didActionReceive(GuiActionType, const QVariantList &)), this , SLOT( onActionReceive(GuiActionType, const QVariantList &))); + connect(&_MessageDispatcher, SIGNAL(didFailedTransmit(Sequence)), + this , SLOT( onFailedTransmit(Sequence))); + + // USB drive connect(&_GuiController , SIGNAL(didUSBDriveUmount()), this , SLOT( onUSBDriveUmount())); - connect(&_USBWatcher , SIGNAL(didUSBDriveMount ()), + connect(&_DriveWatcher , SIGNAL(didUSBDriveMount ()), this , SLOT( onUSBDriveMount ())); - connect(&_USBWatcher , SIGNAL(didUSBDriveRemove()), + connect(&_DriveWatcher , SIGNAL(didUSBDriveRemove()), this , SLOT( onUSBDriveRemove())); + // SD Card + connect(&_DriveWatcher , SIGNAL(didSDCardStateChange(bool, bool)), + this , SLOT( onSDCardStateChange(bool, bool))); + + connect(&_GuiController , SIGNAL(didExportLog()), this , SLOT( onExportLog())); - connect(&_Logger , SIGNAL(didExport()), + connect(&_Logger , SIGNAL(didExportLogs()), this , SLOT( onExport())); + + // ---- Signal/Slots + ADJUST_TRANSMT_MODEL_BRIDGE_CONNECTIONS(_GuiController ) + ACTION_RECEIVE_MODEL_BRIDGE_CONNECTIONS(_MessageDispatcher) } /*! @@ -142,11 +161,21 @@ if ( ! _thread ) return; // runs in thread - moveToThread(qApp->thread()); + moveToThread(qApp->thread()); // validated } // coco end /*! + * \brief ApplicationController::onFailedTransmit + * Called when we failed to get a response back from the HD + * \param seq - The sequence that failed to send to the HD. + */ +void ApplicationController::onFailedTransmit(Sequence seq) +{ + emit didFailedTransmit(seq); +} + +/*! * \brief Process the requested action * \details Processes the requested action * \param vAction - User requested Action @@ -181,51 +210,81 @@ /*! * \brief ApplicationController::onUSBDriveMount - * \details This is the slot which connects to the _USBWatcher didUSBDriveMount signal + * \details This is the slot which connects to the _DriveWatcher didUSBDriveMount signal * and notifies the other classes (GuiController) by emitting its signal didUSBDriveMount */ void ApplicationController::onUSBDriveMount () { + // coco begin validated: This needs user interaction to plug-in USB device + // has been tested manually emit didUSBDriveMount(); } +// coco end /*! * \brief ApplicationController::onUSBDriveRemove * \details This is the slot which connects to the _GuiController didUSBDriveUmount signal - * and notifies the other classes (USBWatcher) by emitting its signal didUSBDriveUmount + * and notifies the other classes (DriveWatcher) by emitting its signal didUSBDriveUmount */ void ApplicationController::onUSBDriveUmount() { + // coco begin validated: This needs user interaction to plug-in USB device + // has been tested manually emit didUSBDriveUmount(); } +// coco end /*! * \brief ApplicationController::onUSBDriveRemove - * \details This is the slot which connects to the _USBWatcher didUSBDriveRemove signal + * \details This is the slot which connects to the _DriveWatcher didUSBDriveRemove signal * and notifies the other classes (GuiController) by emitting its signal didUSBDriveRemove */ void ApplicationController::onUSBDriveRemove() { + // coco begin validated: This needs user interaction to plug-in USB device + // has been tested manually emit didUSBDriveRemove(); } +// coco end /*! + * \brief ApplicationController::onSDCardStateChange + * \details This is the slot which connects to the _DriveWatcher didSDCardStateChange signal + * and notifies the other classes (GuiController) by emitting its signal didSDCardStateChange + * \param vIsReady - SdCard is Ready + * \param vIsReadOnly - SdCard is ReadOnly + */ +void ApplicationController::onSDCardStateChange(bool vIsReady, bool vIsReadOnly) +{ + // coco begin validated: This needs user interaction to plug-in SD Card + // has been tested manually + emit didSDCardStateChange(vIsReady, vIsReadOnly); +} +// coco end + +/*! * \brief ApplicationController::onExportLog * \details the slot which will be called by UI to so the log export. */ void ApplicationController::onExportLog() { + // coco begin validated: This needs user interaction to plug-in USB device + // has been tested manually LOG_EXPORT; } +// coco end /*! * \brief ApplicationController::onExport * \details the slot which will be called by logger is done exporting. */ void ApplicationController::onExport() { + // coco begin validated: This needs user interaction to plug-in USB device + // has been tested manually emit didExport(); } +// coco end /*! * \brief ApplicationController::keepAlive @@ -236,7 +295,137 @@ { #ifndef DISABLE_KEEP_ALIVE QVariantList mData; - mData += static_cast(GuiActionData::NoData); - onActionTransmit(GuiActionType::KeepAlive, mData); + int mFakeDataLen = gFakeData.length(); + // coco begin validated: This is a fake data generator for CANBus missing/swapped frames Testing + // will never be executed on the product + // has been tested manually + if (mFakeDataLen) { + if (gFakeSeqAtBegin) { + createFakeSeqAtBeginLongMessage(mData, mFakeDataLen); + } else { + createFakeSequencedLongMessage (mData, mFakeDataLen); + } + } + // coco end + else { + mData += static_cast(GuiActionData::NoData); + } + onActionTransmit(GuiActionType::ID_KeepAlive, mData); #endif } + +/*! + * \brief ApplicationController::createFakeSequencedLongMessage + * \details This method is creating the fake message with frame sequence + * which we use for Denali Message test + * \param vFakeDataLen + */ +void ApplicationController::createFakeSequencedLongMessage(QVariantList &vData, const int vFakeDataLen) +{ + // coco begin validated: This is a fake data generator for CANBus missing/swapped frames Testing + // will never be executed on the product + // has been tested manually + QByteArray data; + if (vFakeDataLen == 1 && gFakeData == QByteArray::fromHex(gFakeData_default)) { + static quint16 txCount = 0; + Types::U16 seq; + quint8 dataBytesLeft = 0; + const quint8 crcBytesLen = 2; + for (int i = 0; i < 13; i++) { + switch (i) { + case 0: // First frame : HEAD + seq.value = txCount; + data += seq.bytes[0]; + data += seq.bytes[1]; + break; + + case 12: // Last frame with CRC + dataBytesLeft = 8 - sizeof(seq) - crcBytesLen; + for (int j = 0; j < dataBytesLeft; j++) { + data += (char)(0); + } + seq.value = txCount; + data += seq.bytes[0]; + data += seq.bytes[1]; + break; + + default: // Middle Frames + dataBytesLeft = 8 - sizeof(seq); + for (int j = 0; j < dataBytesLeft; j++) { + data += (char)(0); + } + seq.value = txCount; + data += seq.bytes[0]; + data += seq.bytes[1]; + break; + + } + Types::safeIncrement(txCount); + } + vData += QByteArray::fromHex(data.toHex()); + } else { + vData += gFakeData; + } +} +// coco end + +/*! + * \brief ApplicationController::createFakeSequencedAtBeginLongMessage + * \details This method is creating the fake message with frame sequence + * which we use for Denali Message test + * \param vFakeDataLen + */ +void ApplicationController::createFakeSeqAtBeginLongMessage(QVariantList &vData, const int vFakeDataLen) +{ + // coco begin validated: This is a fake data generator for CANBus missing/swapped frames Testing + // will never be executed on the product + // has been tested manually + QByteArray data; + if (vFakeDataLen == 1 && gFakeData == QByteArray::fromHex(gFakeData_default)) { + static quint32 txCount = 0; + Types::U32 seq; + quint8 dataBytesLeft = 0; + const quint8 crcBytesLen = 2; + for (int i = 0; i < 13; i++) { + switch (i) { + case 0: // First frame : HEAD + seq.value = txCount; + data += seq.bytes[0]; + data += seq.bytes[1]; + //data += seq.bytes[3]; // Chopped off + //data += seq.bytes[4]; // Chopped off + break; + + case 12: // Last frame with CRC + seq.value = txCount; + data += seq.bytes[0]; + data += seq.bytes[1]; + data += seq.bytes[2]; + data += seq.bytes[3]; + dataBytesLeft = 8 - sizeof(seq) - crcBytesLen; + for (int j = 0; j < dataBytesLeft; j++) { + data += (char)(0); + } + break; + + default: // Middle Frames + dataBytesLeft = 8 - sizeof(seq); + seq.value = txCount; + data += seq.bytes[0]; + data += seq.bytes[1]; + data += seq.bytes[2]; + data += seq.bytes[3]; + for (int j = 0; j < dataBytesLeft; j++) { + data += (char)(0); + } + break; + + } + Types::safeIncrement(txCount); + } + vData += QByteArray::fromHex(data.toHex()); + } else { + vData += gFakeData; + } +} +// coco end