/*! * * Copyright (c) 2019-2020 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) 01-Jun-2021 * \author (original) Behrouz NematiPour * \date (original) 01-Jun-2021 * */ #pragma once // Qt #include // Project #include "MAbstract.h" #include "types.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 */ } }; // ------------------------------------------------------------------ // TODO : I believe the two model can be merged. They have so much in common. // On the CANBus it was separated since the type of data in send and receive was totally different. // But here it's the same. class MDeviceBrightnessRequest : public MDeviceRequestBase { public: 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; QString toString() { return MDeviceRequestBase::toString("DeviceBrightness", { _data.mBrightnessPercent }); } }; class MDeviceBrightnessResponse : public MDeviceResponseBase { 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; }; } typedef Model::MDeviceResponseBase ::Data DeviceResponseBaseData ; typedef Model::MDeviceBrightnessRequest ::Data DeviceBrightnessRequestData ; typedef Model::MDeviceBrightnessResponse::Data DeviceBrightnessResponseData ;