From 696bbd6856a3297cb79cf79ecb15ceb76dfb84d0 Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Thu, 14 Sep 2023 18:07:45 +0200 Subject: [PATCH] Added setters for module parameters --- src/vscp/common/mdf.cpp | 116 +++++++++++++++---- src/vscp/common/mdf.h | 239 ++++++++++++++++++++++++++++++++-------- 2 files changed, 288 insertions(+), 67 deletions(-) diff --git a/src/vscp/common/mdf.cpp b/src/vscp/common/mdf.cpp index f255f4dfd..bb43c87e1 100644 --- a/src/vscp/common/mdf.cpp +++ b/src/vscp/common/mdf.cpp @@ -83,7 +83,49 @@ using namespace kainjow::mustache; // Constructor/Destructor // -CMDF_Value::CMDF_Value() +CMDF_Object::CMDF_Object(mdf_record_type type) +{ + m_type = type; +} + +CMDF_Object::~CMDF_Object() +{ + +} + +/////////////////////////////////////////////////////////////////////////////// +// getObjectTypeString +// + +std::string +CMDF_Object::getObjectTypeString() +{ + switch (m_type) { + case mdf_type_mdf: + return std::string("MDF top level"); + default: + return std::string("Unknown"); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// getMdfObjectType +// + +mdf_record_type +CMDF_Object::getMdfObjectType() +{ + return m_type; +}; + +// ---------------------------------------------------------------------------- + +/////////////////////////////////////////////////////////////////////////////// +// Constructor/Destructor +// + +CMDF_Value::CMDF_Value() : + CMDF_Object(mdf_type_value) { m_name.clear(); m_strValue.clear(); @@ -101,7 +143,8 @@ CMDF_Value::~CMDF_Value() // Constructor/Destructor // -CMDF_RemoteVariable::CMDF_RemoteVariable() +CMDF_RemoteVariable::CMDF_RemoteVariable() : + CMDF_Object(mdf_type_remotevar) { m_strDefault.clear(); m_type = remote_variable_type_unknown; @@ -279,7 +322,8 @@ CMDF_RemoteVariable::getTypeByteCount(void) // Constructor/Destructor // -CMDF_Bit::CMDF_Bit() +CMDF_Bit::CMDF_Bit() : + CMDF_Object(mdf_type_bit) { m_name.clear(); m_pos = 0; @@ -394,7 +438,8 @@ CMDF_Bit::setMax(uint8_t max) // Constructor/Destructor // -CMDF_Register::CMDF_Register() +CMDF_Register::CMDF_Register() : + CMDF_Object(mdf_type_register) { m_page = 0; m_offset = 0; @@ -563,7 +608,8 @@ CMDF_Register::operator=(const CMDF_Register &other) // Constructor/Destructor // -CMDF_ActionParameter::CMDF_ActionParameter() +CMDF_ActionParameter::CMDF_ActionParameter() : + CMDF_Object(mdf_type_action_param) { m_name.clear(); m_offset = 0; @@ -600,7 +646,7 @@ CMDF_ActionParameter::clearStorage(void) m_list_bit.clear(); - // Clearup value list + // Clear up value list std::deque::iterator iterValue; for (iterValue = m_list_value.begin(); iterValue != m_list_value.end(); ++iterValue) { CMDF_Value *pRecordValue = *iterValue; @@ -620,7 +666,8 @@ CMDF_ActionParameter::clearStorage(void) // Constructor/Destructor // -CMDF_Action::CMDF_Action() +CMDF_Action::CMDF_Action() : + CMDF_Object(mdf_type_action) { m_name.clear(); m_code = 0; @@ -663,7 +710,8 @@ CMDF_Action::clearStorage(void) // Constructor/Destructor // -CMDF_DecisionMatrix::CMDF_DecisionMatrix() +CMDF_DecisionMatrix::CMDF_DecisionMatrix() : + CMDF_Object(mdf_type_decision_matrix) { m_level = 1; m_startPage = 0; @@ -697,7 +745,8 @@ CMDF_DecisionMatrix::clearStorage() // Constructor/Destructor // -CMDF_EventData::CMDF_EventData() +CMDF_EventData::CMDF_EventData() : + CMDF_Object(mdf_type_event_data) { m_name.clear(); m_offset = 0; @@ -748,7 +797,8 @@ CMDF_EventData::clearStorage() // Constructor/Destructor // -CMDF_Event::CMDF_Event() +CMDF_Event::CMDF_Event() : + CMDF_Object(mdf_type_event) { m_name.clear(); m_class = 0; @@ -794,7 +844,8 @@ CMDF_Event::clearStorage() // Constructor/Destructor // -CMDF_Item::CMDF_Item() +CMDF_Item::CMDF_Item() : + CMDF_Object(mdf_type_value_item) { m_name.clear(); } @@ -808,7 +859,8 @@ CMDF_Item::~CMDF_Item() // Constructor/Destructor // -CMDF_BootLoaderInfo::CMDF_BootLoaderInfo() +CMDF_BootLoaderInfo::CMDF_BootLoaderInfo() : + CMDF_Object(mdf_type_bootloader) { m_nAlgorithm = 0; m_nBlockSize = 0; @@ -836,7 +888,8 @@ CMDF_BootLoaderInfo::clearStorage(void) // Constructor/Destructor // -CMDF_Address::CMDF_Address() +CMDF_Address::CMDF_Address() : + CMDF_Object(mdf_type_address) { clearStorage(); } @@ -866,7 +919,8 @@ CMDF_Address::clearStorage(void) // Constructor/Destructor // -CMDF_Manufacturer::CMDF_Manufacturer() +CMDF_Manufacturer::CMDF_Manufacturer() : + CMDF_Object(mdf_type_manufacturer) { clearStorage(); } @@ -944,7 +998,8 @@ CMDF_Manufacturer::clearStorage(void) // Constructor/Destructor // -CMDF_Picture::CMDF_Picture() +CMDF_Picture::CMDF_Picture() : + CMDF_Object(mdf_type_picture) { clearStorage(); m_strName = ""; // default name @@ -973,7 +1028,8 @@ CMDF_Picture::clearStorage(void) // Constructor/Destructor // -CMDF_Video::CMDF_Video() +CMDF_Video::CMDF_Video() : + CMDF_Object(mdf_type_video) { clearStorage(); } @@ -1001,7 +1057,8 @@ CMDF_Video::clearStorage(void) // Constructor/Destructor // -CMDF_Firmware::CMDF_Firmware() +CMDF_Firmware::CMDF_Firmware() : + CMDF_Object(mdf_type_firmware) { clearStorage(); } @@ -1039,7 +1096,8 @@ CMDF_Firmware::clearStorage(void) // Constructor/Destructor // -CMDF_Driver::CMDF_Driver() +CMDF_Driver::CMDF_Driver() : + CMDF_Object(mdf_type_driver) { clearStorage(); } @@ -1078,7 +1136,8 @@ CMDF_Driver::clearStorage(void) // Constructor/Destructor // -CMDF_Manual::CMDF_Manual() +CMDF_Manual::CMDF_Manual() : + CMDF_Object(mdf_type_manual) { clearStorage(); } @@ -1106,7 +1165,8 @@ CMDF_Manual::clearStorage(void) // Constructor/Destructor // -CMDF_Setup::CMDF_Setup() +CMDF_Setup::CMDF_Setup() : + CMDF_Object(mdf_type_setup) { clearStorage(); } @@ -1136,7 +1196,8 @@ CMDF_Setup::clearStorage(void) // Constructor/Destructor // -CMDF::CMDF() +CMDF::CMDF() : + CMDF_Object(mdf_type_mdf) { m_strLocale = "en"; m_vscpLevel = VSCP_LEVEL1; @@ -3284,6 +3345,10 @@ __handleMDFParserData(void *data, const XML_Char *content, int length) spdlog::trace("Parse-XML: handleMDFParserData: Module name: {0}", strContent); pmdf->m_strModule_Model = strContent; } + else if (gTokenList.at(0) == "copyright") { + spdlog::trace("Parse-XML: handleMDFParserData: Module copyright: {0}", strContent); + pmdf->m_copyright = strContent; + } else if (gTokenList.at(0) == "version") { spdlog::trace("Parse-XML: handleMDFParserData: Module name: {0}", strContent); pmdf->m_strModule_Version = strContent; @@ -5325,6 +5390,15 @@ CMDF::parseMDF_JSON(const std::string &path) spdlog::debug("Parse-JSON: There is no module model."); } + // Module version - not mandatory + if (j["module"].contains("copyright") && j["module"]["copyright"].is_string()) { + m_copyright = j["module"]["copyright"]; + spdlog::debug("Parse-JSON: Module copyright: {0}", m_copyright); + } + else { + spdlog::debug("Parse-JSON: There is no module copyright."); + } + // Module version - not mandatory if (j["module"].contains("version") && j["module"]["version"].is_string()) { m_strModule_Version = j["module"]["version"]; diff --git a/src/vscp/common/mdf.h b/src/vscp/common/mdf.h index 00db1f2f1..e47d6400e 100644 --- a/src/vscp/common/mdf.h +++ b/src/vscp/common/mdf.h @@ -99,19 +99,100 @@ typedef enum mdf_file_type { mdf_file_type_setup // Setup files } mdf_file_type; +// MDF record types +typedef enum mdf_record_type { + mdf_type_unknown, + mdf_type_mdf, + mdf_type_value, + mdf_type_value_item, + mdf_type_bit, + mdf_type_bit_item, + mdf_type_register, + mdf_type_register_item, + mdf_type_register_page, + mdf_type_remotevar, + mdf_type_remotevar_item, + mdf_type_decision_matrix, + mdf_type_action, + mdf_type_action_item, + mdf_type_action_param, + mdf_type_event, + mdf_type_event_item, + mdf_type_event_data, + mdf_type_event_data_item, + mdf_type_bootloader, + mdf_type_address, + mdf_type_manufacturer, + mdf_type_file, + mdf_type_picture, + mdf_type_picture_item, + mdf_type_video, + mdf_type_video_item, + mdf_type_firmware, + mdf_type_firmware_item, + mdf_type_driver, + mdf_type_driver_item, + mdf_type_setup, + mdf_type_setup_item, + mdf_type_manual, + mdf_type_manual_item, + mdf_type_redirection, + mdf_type_email, + mdf_type_phone, + mdf_type_fax, + mdf_type_web, + mdf_type_social, + mdf_type_alarm, + mdf_type_generic_string, // Used for direct item editing + mdf_type_generic_number, // Used for direct item editing + mdf_type_generic_url, // Used for direct item editing + mdf_type_generic_date, // Used for direct item editing + mdf_type_generic_access, // Used for direct item editing + mdf_type_generic_description, // Used for direct item editing + mdf_type_generic_description_item, // Used for direct item editing + mdf_type_generic_help_url, // Used for direct item editing + mdf_type_generic_help_url_item // Used for direct item editing +} mdf_record_type; + // * * * Settings * * * // Forward declarations class CMDF; class CMDF_Bit; +/*! + CMDF_Value + */ + +class CMDF_Object { + +public: + CMDF_Object(mdf_record_type type = mdf_type_unknown); + ~CMDF_Object(); + + /*! + Get the object type + @return Object type for record + */ + mdf_record_type getMdfObjectType(void); + + /*! + Get string representation for object type + @return Standard string with description of object type + */ + std::string getObjectTypeString(void); + +private: + mdf_record_type m_type; +}; + // ---------------------------------------------------------------------------- /*! CMDF_Value */ -class CMDF_Value { +class CMDF_Value : public CMDF_Object { public: CMDF_Value(); @@ -218,7 +299,7 @@ class CMDF_Value { */ -class CMDF_Bit { +class CMDF_Bit : public CMDF_Object { public: CMDF_Bit(); @@ -297,7 +378,7 @@ class CMDF_Bit { Set bit array start position (0-7) @param pos Bit array start position */ - void setPos(uint8_t pos); + void setPos(uint8_t pos); /*! Get bit array length (1-8) @@ -397,7 +478,7 @@ class CMDF_Bit { Holds information for one register */ -class CMDF_Register { +class CMDF_Register : public CMDF_Object { public: CMDF_Register(); @@ -696,7 +777,7 @@ class CMDF_Register { CMDF_RemoteVariable */ -class CMDF_RemoteVariable { +class CMDF_RemoteVariable : public CMDF_Object { public: CMDF_RemoteVariable(); @@ -919,7 +1000,7 @@ class CMDF_RemoteVariable { */ -class CMDF_ActionParameter { +class CMDF_ActionParameter : public CMDF_Object { public: CMDF_ActionParameter(); @@ -1057,7 +1138,7 @@ class CMDF_ActionParameter { */ -class CMDF_Action { +class CMDF_Action : public CMDF_Object { public: CMDF_Action(); @@ -1162,7 +1243,7 @@ class CMDF_Action { decision matrix. */ -class CMDF_DecisionMatrix { +class CMDF_DecisionMatrix : public CMDF_Object { public: CMDF_DecisionMatrix(); @@ -1278,7 +1359,7 @@ class CMDF_DecisionMatrix { */ -class CMDF_EventData { +class CMDF_EventData : public CMDF_Object { public: CMDF_EventData(); @@ -1385,7 +1466,7 @@ class CMDF_EventData { */ -class CMDF_Event { +class CMDF_Event : public CMDF_Object { public: CMDF_Event(); @@ -1530,7 +1611,7 @@ class CMDF_Event { */ -class CMDF_Item { +class CMDF_Item : public CMDF_Object { public: CMDF_Item(); @@ -1600,10 +1681,10 @@ class CMDF_Item { CMDF_BootLoaderInfo Holds information about the capabilities of a system - decission matrix. + decision matrix. */ -class CMDF_BootLoaderInfo { +class CMDF_BootLoaderInfo : public CMDF_Object { public: CMDF_BootLoaderInfo(); @@ -1655,7 +1736,7 @@ class CMDF_BootLoaderInfo { */ -class CMDF_Address { +class CMDF_Address : public CMDF_Object { public: CMDF_Address(); @@ -1735,7 +1816,7 @@ class CMDF_Address { */ -class CMDF_Manufacturer { +class CMDF_Manufacturer : public CMDF_Object { public: CMDF_Manufacturer(); @@ -1805,7 +1886,7 @@ class CMDF_Manufacturer { // ---------------------------------------------------------------------------- -class CMDF_Picture { +class CMDF_Picture : public CMDF_Object { public: CMDF_Picture(); @@ -1934,7 +2015,7 @@ class CMDF_Picture { // ---------------------------------------------------------------------------- -class CMDF_Video { +class CMDF_Video : public CMDF_Object { public: CMDF_Video(); @@ -2069,7 +2150,7 @@ class CMDF_Video { */ -class CMDF_Firmware { +class CMDF_Firmware : public CMDF_Object { public: CMDF_Firmware(); @@ -2275,7 +2356,7 @@ class CMDF_Firmware { */ -class CMDF_Driver { +class CMDF_Driver : public CMDF_Object { public: CMDF_Driver(); @@ -2472,7 +2553,7 @@ class CMDF_Driver { // ---------------------------------------------------------------------------- -class CMDF_Setup { +class CMDF_Setup : public CMDF_Object { public: CMDF_Setup(); @@ -2600,7 +2681,7 @@ class CMDF_Setup { // --------------------------------------------------------------------------- -class CMDF_Manual { +class CMDF_Manual : public CMDF_Object { public: CMDF_Manual(); @@ -2734,12 +2815,14 @@ class CMDF_Manual { */ -class CMDF { +class CMDF : public CMDF_Object { public: CMDF(); ~CMDF(); + const uint32_t type = 0; + // Friend declarations friend bool __getBitAttributes(std::deque *pbitlist, const char **attr); friend bool __getValueAttributes(std::deque *pvaluelist, const char **attr); @@ -2787,19 +2870,104 @@ class CMDF { std::string vscp_getDeviceHtmlStatusInfo(const uint8_t *registers, CMDF *pmdf); /*! - Get Module name in selected language. + Get Module name. @return Return string with module name */ std::string getModuleName(void) { return m_name; }; + /*! + Set Module name. + @parm Module name to set + */ + void setModuleName(std::string &str) { m_name = str; }; + + /*! + Get module version + @return Return string with module version. + */ + std::string getModuleModel(void) { return m_strModule_Model; }; + + /*! + Set module model + @Param Module model as string + */ + void setModuleModel(std::string &str) { m_name = str; }; + + /*! + Get module change date + @return Return string with module change date. + */ + std::string getModuleChangeDate(void) { return m_strModule_changeDate; }; + + /*! + Set module change date + @param str Module change date as ISO date formatted string + */ + void setModuleModel(std::string &str) { m_strModule_changeDate = str; }; + + + /*! + Get module version + @return Return string with module version. + */ + std::string getModuleVersion(void) { return m_strModule_Version; }; + + /*! + Set module version + @param str Module version on stringt form + */ + std::string setModuleVersion(std::string &str) { m_strModule_Model = str; }; + + /*! + Get module buffer size + @return Buffer size in bytes. + */ + uint16_t getModuleBufferSize(void) { return m_module_bufferSize; }; + + /*! + Set module buffer size + @param size Module buffer size to set + */ + void setModuleBufferSize(uint16_t size ) { m_module_bufferSize = size; }; + + /*! + Get Module copyright. + @return Return string with module copyright + */ + std::string getModuleCopyright(void) { return m_copyright; }; + + /*! + Set Module copyright. + @parm Module copyright to set + */ + void setModuleCopyright(std::string &str) { m_copyright = str; }; + /*! Return VSCP level for device. NOTE! that 0 == Level I, 1 == Level II @return Return VSCP level for module */ int getModuleLevel(void) { return m_vscpLevel; }; + + /*! + Set VSCP level for device + @param level VSCP level to set (0=Level I, 1=Level II). + */ + void setModuleLevel(int level = 0) { m_vscpLevel = level & 1; }; + + /*! + Return VSCP level for device. NOTE! that + 0 == Level I, 1 == Level II (Deprecated) + @return Return VSCP level for module + */ int getLevel(void) { return m_vscpLevel; }; + /*! + Set VSCP level for device (Deprecated) + @param level VSCP level to set (0=Level I, 1=Level II). + */ + void setLevel(int level = 0) { m_vscpLevel = level & 1; }; + /*! Get Module description in selected language. @param language Language to get description in. @@ -2838,29 +3006,7 @@ class CMDF { */ std::map *getModuleHelpUrlMap(void) { return &m_mapInfoURL; }; - /*! - Get module change date - @return Return string with module change date. - */ - std::string getModuleChangeDate(void) { return m_strModule_changeDate; }; - - /*! - Get module version - @return Return string with module version. - */ - std::string getModuleModel(void) { return m_strModule_Model; }; - - /*! - Get module version - @return Return string with module version. - */ - std::string getModuleVersion(void) { return m_strModule_Version; }; - - /*! - Get module buffer size - @return Buffer size in bytes. - */ - uint16_t getModuleBufferSize(void) { return m_module_bufferSize; }; + /*! Get manufacturer object @@ -3207,6 +3353,7 @@ class CMDF { uint8_t m_vscpLevel; // Module level. Default to level I std::string m_name; // Module name + std::string m_copyright; // Copyright std::map m_mapDescription; // Module description std::map m_mapInfoURL; // URL for full module information