Skip to content

Commit

Permalink
Added method to get remote variable from page/offset
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Dec 14, 2023
1 parent cfb750f commit 39a2e78
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
22 changes: 20 additions & 2 deletions src/vscp/common/mdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ bool
CMDF::load(const std::string &file, bool bLocalFile)
{
std::string remoteFile = file;
std::string localFile = file;
std::string localFile = file;

if (remoteFile.npos == remoteFile.find("http://")) {
std::string str;
Expand Down Expand Up @@ -7700,7 +7700,7 @@ CMDF::getDefaultRegisterValue(uint32_t reg, uint16_t page)
//

CMDF_RemoteVariable *
CMDF::getRemoteVariable(const std::string& name)
CMDF::getRemoteVariable(const std::string &name)
{
std::string remotevar = name;
vscp_trim(remotevar);
Expand All @@ -7720,6 +7720,24 @@ CMDF::getRemoteVariable(const std::string& name)
return nullptr;
}

///////////////////////////////////////////////////////////////////////////////
// getRemoteVariable
//

CMDF_RemoteVariable *
CMDF::getRemoteVariable(uint32_t offset, uint16_t page)
{
std::deque<CMDF_RemoteVariable *>::iterator iter;
for (iter = m_list_remotevar.begin(); iter != m_list_remotevar.end(); ++iter) {
CMDF_RemoteVariable *pvar = *iter;
if ((nullptr == pvar) && (page == pvar->getPage()) && (offset == pvar->getOffset()) ) {
return pvar;
}
}

return nullptr;
}

///////////////////////////////////////////////////////////////////////////////
// getRegisterList
//
Expand Down
39 changes: 31 additions & 8 deletions src/vscp/common/mdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ typedef enum mdf_record_type {
mdf_type_register_page,
mdf_type_remotevar,
mdf_type_remotevar_item,
mdf_type_remotevar_sub_item,
mdf_type_decision_matrix,
mdf_type_action,
mdf_type_action_item,
Expand Down Expand Up @@ -253,7 +254,7 @@ class CMDF_Value : public CMDF_Object {
Set value
@param value Value on string form.
*/
void setValue(const std::string& value) { m_strValue = value; };
void setValue(const std::string &value) { m_strValue = value; };

/*!
Set value
Expand All @@ -278,7 +279,7 @@ class CMDF_Value : public CMDF_Object {
@param lang Language
@param desc Register description to set
*/
void setDescription(const std::string& lang, std::string &desc) { m_mapDescription[lang] = desc; };
void setDescription(const std::string &lang, std::string &desc) { m_mapDescription[lang] = desc; };

/*!
Get the value info URL
Expand Down Expand Up @@ -714,6 +715,20 @@ class CMDF_Register : public CMDF_Object {
*/
std::deque<CMDF_Bit *> *getListBits(void) { return &m_list_bit; };

/*!
Get the bit mask for all defined bits
@return A combined bitmask for all bits
*/
uint8_t getAllBitMask(void)
{
uint8_t mask = 0;
std::deque<CMDF_Bit *> *pbits = getListBits();
for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) {
mask |= (*it)->getMask();
}
return mask;
};

/*!
Fetch the value definition list
@return Value definition list
Expand Down Expand Up @@ -839,7 +854,7 @@ class CMDF_RemoteVariable : public CMDF_Object {
Get the register description
@return Register description
*/
std::string getDescription(const std::string& lang = "en") { return m_mapDescription[lang]; };
std::string getDescription(const std::string &lang = "en") { return m_mapDescription[lang]; };

/*!
Set register description
Expand Down Expand Up @@ -908,7 +923,7 @@ class CMDF_RemoteVariable : public CMDF_Object {
Set default value for remote variable
@param strDefault Default value.
*/
void setDefault(const std::string& strDefault) { m_strDefault = strDefault; };
void setDefault(const std::string &strDefault) { m_strDefault = strDefault; };

/*!
Get Page for remote variable
Expand Down Expand Up @@ -1199,7 +1214,7 @@ class CMDF_Action : public CMDF_Object {
Get the register description
@return Register description
*/
std::string getDescription(const std::string& lang = "en") { return m_mapDescription[lang]; };
std::string getDescription(const std::string &lang = "en") { return m_mapDescription[lang]; };

/*!
Set register description
Expand Down Expand Up @@ -3806,10 +3821,18 @@ class CMDF : public CMDF_Object {

/*!
Return remote variable from its name
@param name Name iof remote variable to search for.
@return Pointer to CMDF_RemoteVariable class if found else NULL.
@param name Name of remote variable to search for.
@return Pointer to CMDF_RemoteVariable class if found, else NULL.
*/
CMDF_RemoteVariable *getRemoteVariable(const std::string &name);

/*!
Return remote variable from its offset/page
@param offset Offset for start register for remote variable
@param page Page where remote variable is located
@return Pointer to CMDF_RemoteVariable class if found, else NULL.
*/
CMDF_RemoteVariable *getRemoteVariable(const std::string& name);
CMDF_RemoteVariable *getRemoteVariable(uint32_t offset, uint16_t page = 0);

/*!
Return remote variable list from its name
Expand Down

0 comments on commit 39a2e78

Please sign in to comment.