/*! * * Copyright (c) 2021-2022 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 DeviceModels.h * \author (last) Behrouz NematiPour * \date (last) 12-Nov-2021 * \author (original) Behrouz NematiPour * \date (original) 03-Jun-2021 * */ #pragma once // Qt #include // Project #include "MAbstract.h" #include "types.h" #include "DeviceError.h" // forward declarations class tst_models; namespace Model { /*! * \brief The MDeviceRequestBase class * \details The base class of the all devices requests models */ class MDeviceRequestBase { protected: /*! * \brief toString * \details the global toString function for all the request message models * which is mainly used for logging and debugging. * \param vStringPrefix - a prefix string to be inserted after senderID (UI) and parameter values list. * This is comma separated. * \param vParameters - list of parameter values of the model as a comma separated string. * \return QString */ static QString toString (const QString &vStringPrefix, const QVariantList &vParameters) { QString senderID = MAbstract::unitText(MAbstract::Unit_Enum::eUI) + ","; QString mString = QString(senderID + vStringPrefix); for (const auto ¶m : vParameters) mString += QString(",%1").arg(param.toString()); return mString; } }; /*! * \brief The MDeviceResponseBase class * \details The base class of the all devices responses models */ class MDeviceResponseBase : public MAbstract { // friends friend class ::tst_models; public: Type_Enum typeText () const override { return Type_Enum::eEvent ; } Unit_Enum unitText () const override { return Unit_Enum::eDV ; } QString infoText () const override { return QString("DeviceBase") ; } struct Data { // by default it has to be accepted with no rejection reason bool mAccepted = true; /*!< Accepted value of type quint32 extracted out */ quint32 mReason = 0 ; /*!< Reason value of type quint32 extracted out */ QString mMessage = "" ; /*!< Message value of type QString of the reason */ }; MDeviceResponseBase () { } bool fromByteArray (const QByteArray &, int * = nullptr) override { return false; /* no conversion needed */ } }; /*! * \brief The MDeviceBrightnessRequest class * \details The model for the device brightness value modification request. */ class MDeviceBrightnessRequest : public MDeviceRequestBase { // ------------------------------------------------------------------ // TODO : Merge the two models as they have much in common in this case. // On the CANBus it was separated since the type of data in send and receive was totally different. // But here it's the same. // TODO: improve later - this has to be match with HW2UI in response QMap UI2HW = { // the mapping is not linear so has to be mapped to keep the order { 20, 1}, { 40, 3}, { 60, 5}, { 80, 6}, {100, 10}, }; public: // TODO : these needs to be available in Views static const quint8 mBrightness_min = 2; static const quint8 mBrightness_max = 10; static const quint8 mBrightness_res = 2; struct Data { quint8 mBrightness_old = mBrightness_min ; quint8 mBrightness_val = 0; quint8 mBrightnessPercent = 100; bool mRead = false; } _data; Device::DeviceError::Scripts_Error_Enum setBrightnessSysVal(); QString toString() { return MDeviceRequestBase::toString("DeviceBrightness", { _data.mBrightnessPercent }); } }; /*! * \brief The MDeviceBrightnessResponse class * \details The model for the device brightness value request. */ class MDeviceBrightnessResponse : public MDeviceResponseBase { // TODO: improve later - this has to be match with UI2HW in request QMap HW2UI = { // the mapping is not linear so has to be mapped to keep the order { 1, 20}, { 3, 40}, { 5, 60}, { 6, 80}, { 10, 100}, }; public: struct Data : MDeviceResponseBase::Data { quint8 mBrightnessPercent = 0; } _data; QVariantList parameters () const override { return { _data.mBrightnessPercent }; } QString infoText () const override { return QString("DeviceBrightness") ; } Data data () const { return _data; } Device::DeviceError::Scripts_Error_Enum setBrightnessPercent(quint8 vSysVal); }; // ---------- MDeviceBluetoothPaired 'Reset' ---------- // /*! * \brief The MDeviceBluetoothPairedResetRequest class * \details The model for the bluetooth pared removal script call. */ class MDeviceBluetoothPairedResetRequest : public MDeviceRequestBase { public: struct Data { } _data; QString toString() { return MDeviceRequestBase::toString("DeviceBluetoothPairedReset", { }); } }; /*! * \brief The MDeviceBluetoothPairedResetResponse class * \details The model for the bluetooth pared removal script call returned value / response. */ class MDeviceBluetoothPairedResetResponse : public MDeviceResponseBase { public: struct Data : MDeviceResponseBase::Data { } _data; QVariantList parameters ( ) const override { return { }; } QString infoText ( ) const override { return QString("DeviceBluetoothPairedReset") ; } Data data ( ) const { return _data; } bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; }; // ---------- MDeviceBluetoothPaired 'Query' ---------- // /*! * \brief The MDeviceBluetoothPairedQueryRequest class * \details The model for the bluetooth pared removal script call. */ class MDeviceBluetoothPairedQueryRequest : public MDeviceRequestBase { public: struct Data { } _data; QString toString() { return MDeviceRequestBase::toString("DeviceBluetoothPairedQuery", { }); } }; /*! * \brief The MDeviceBluetoothPairedQueryResponse class * \details The model for the bluetooth pared removal script call returned value / response. */ class MDeviceBluetoothPairedQueryResponse : public MDeviceResponseBase { public: const quint8 LEN_COUNT = 2; const char SEPARATOR = ' '; const char *ZERO = "00:00:00:00:00:00"; enum { eAddr, eName, }; struct Data : MDeviceResponseBase::Data { QString mAddr = ""; // Paired device address QString mName = ""; // Paired device name QStringList mInfo = {}; // combination of the {mAddr, mName} to be used in QML/GUI side. } _data; QVariantList parameters ( ) const override { return { }; } QString infoText ( ) const override { return QString("DeviceBluetoothPairedQuery"); } Data data ( ) const { return _data; } bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; }; } typedef Model::MDeviceResponseBase ::Data DeviceResponseBaseData ; typedef Model::MDeviceBrightnessRequest ::Data DeviceBrightnessRequestData ; typedef Model::MDeviceBrightnessResponse::Data DeviceBrightnessResponseData ; typedef Model::MDeviceBluetoothPairedResetRequest ::Data DeviceBluetoothPairedResetRequestData ; typedef Model::MDeviceBluetoothPairedResetResponse::Data DeviceBluetoothPairedResetResponseData; typedef Model::MDeviceBluetoothPairedQueryRequest ::Data DeviceBluetoothPairedQueryRequestData ; typedef Model::MDeviceBluetoothPairedQueryResponse::Data DeviceBluetoothPairedQueryResponseData;