From 79a9c50363a248b5a51b8346a83f1becedc31cac Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Tue, 5 Mar 2024 21:53:30 +0100 Subject: [PATCH] Full save of mdf in XML/JSON data in place --- src/vscp/common/mdf.cpp | 725 ++++++++++++++++++++++++++++++++++++---- src/vscp/common/mdf.h | 4 +- 2 files changed, 662 insertions(+), 67 deletions(-) diff --git a/src/vscp/common/mdf.cpp b/src/vscp/common/mdf.cpp index 7aa8e0fcd..a8fb19f8b 100644 --- a/src/vscp/common/mdf.cpp +++ b/src/vscp/common/mdf.cpp @@ -1842,12 +1842,6 @@ CMDF::writeMap_json(std::ofstream &fout, fout << std::endl << std::endl; } fout << "]"; - // if (bCommaAtEnd) { - // fout << "," << std::endl; - // } - // else { - // fout << std::endl; - // } } } @@ -2166,7 +2160,7 @@ CMDF::save_xml(const std::string &path) fout << "default=\"" << (int) pbit->getDefault() << "\" "; fout << "min=\"" << (int) pbit->getMin() << "\" "; fout << "max=\"" << (int) pbit->getMax() << "\" "; - fout << "access=\"" << preg->getAccessStr() << "\" >" << std::endl; + fout << "access=\"" << pbit->getAccessStr() << "\" >" << std::endl; writeMap_xml(fout, pbit->getMapDescription(), "description"); writeMap_xml(fout, pbit->getMapInfoUrl(), "infourl"); @@ -2214,6 +2208,278 @@ CMDF::save_xml(const std::string &path) fout << "" << std::endl; + // -------------------------------------------------------------------------- + + // -------------------------------------------------------------------------- + + fout << "" << std::endl; + std::deque *premotevars = getRemoteVariableList(); + + for (auto it = premotevars->cbegin(); it != premotevars->cend(); ++it) { + CMDF_RemoteVariable *prvar = *it; + + fout << "getName() << "\" "; + fout << "type=\"" << prvar->getType() << "\" "; + fout << "default=\"" << prvar->getDefault() << "\" "; + fout << "page=\"" << prvar->getPage() << "\" "; + fout << "offset=\"" << prvar->getOffset() << "\" "; + fout << "access=\"" << prvar->getAccessStr() << "\" "; + fout << "bitpos=\"" << prvar->getBitPos() << "\" "; + fout << std::hex << "fgcolor=\"" << prvar->getForegroundColor() << "\" " << std::dec; + fout << std::hex << "bgcolor=\"" << prvar->getBackgroundColor() << "\" " << std::dec; + fout << ">" << std::endl; + + // bits + std::deque *pbits = prvar->getListBits(); + if (pbits->size()) { + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "getName() << "\" "; + fout << "pos=\"" << (int) pbit->getPos() << "\" "; + fout << "width=\"" << (int) pbit->getWidth() << "\" "; + fout << "default=\"" << (int) pbit->getDefault() << "\" "; + fout << "min=\"" << (int) pbit->getMin() << "\" "; + fout << "max=\"" << (int) pbit->getMax() << "\" "; + fout << "access=\"" << pbit->getAccessStr() << "\" >" << std::endl; + + writeMap_xml(fout, pbit->getMapDescription(), "description"); + writeMap_xml(fout, pbit->getMapInfoUrl(), "infourl"); + + std::deque *pvalues = pbit->getListValues(); + if (pvalues->size()) { + fout << " "; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "getName() << "\" "; + fout << "value=\"" << pvalue->getValue() << "\" >" << std::endl; + writeMap_xml(fout, pvalue->getMapDescription(), "description"); + writeMap_xml(fout, pvalue->getMapInfoUrl(), "infourl"); + fout << " "; + } + fout << " " << std::endl; + } + + fout << "" << std::endl; // Bits + } // for bits + } // pbits size + + std::deque *pvalues = prvar->getListValues(); + if (pvalues->size()) { + fout << " "; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "getName() << "\" "; + fout << "value=\"" << pvalue->getValue() << "\" >" << std::endl; + writeMap_xml(fout, pvalue->getMapDescription(), "description"); + writeMap_xml(fout, pvalue->getMapInfoUrl(), "infourl"); + fout << " "; + } + fout << " " << std::endl; + } + + writeMap_xml(fout, prvar->getMapDescription(), "description"); + writeMap_xml(fout, prvar->getMapInfoUrl(), "infourl"); + + fout << "" << std::endl; + } + + fout << "" << std::endl; + + // -------------------------------------------------------------------------- + + fout << "" << std::endl; + + // bits + std::deque *pbits = getAlarmList(); + if (pbits->size()) { + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "getName() << "\" "; + fout << "pos=\"" << (int) pbit->getPos() << "\" "; + fout << "width=\"" << (int) pbit->getWidth() << "\" "; + fout << "default=\"" << (int) pbit->getDefault() << "\" "; + fout << "min=\"" << (int) pbit->getMin() << "\" "; + fout << "max=\"" << (int) pbit->getMax() << "\" "; + fout << "access=\"" << pbit->getAccessStr() << "\" >" << std::endl; + + writeMap_xml(fout, pbit->getMapDescription(), "description"); + writeMap_xml(fout, pbit->getMapInfoUrl(), "infourl"); + fout << "" << std::endl; // Bits + } // for bits + } // pbits size + + fout << "" << std::endl; + + // -------------------------------------------------------------------------- + + CMDF_DecisionMatrix *pdm = getDM(); // Get pointer to decision matrix + if (nullptr != pdm) { + + fout << "getLevel() << "\" "; + fout << "start-page=\"" << pdm->getStartPage() << "\" "; + fout << "start-offset=\"" << pdm->getStartOffset() << "\" "; + fout << "rowcnt=\"" << pdm->getRowCount() << "\" "; + fout << "rowsize=\"" << pdm->getRowSize() << "\" >" << std::endl; + + std::deque *pactionlst = pdm->getActionList(); + if (nullptr != pactionlst) { + for (auto it = pactionlst->cbegin(); it != pactionlst->cend(); ++it) { + CMDF_Action *paction = *it; + fout << "getName() << "\" "; + fout << "code=\"" << paction->getCode() << "\" >" << std::endl; + std::deque *pactionparamlst = paction->getListActionParameter(); + if (nullptr != pactionparamlst) { + for (auto it = pactionparamlst->cbegin(); it != pactionparamlst->cend(); ++it) { + CMDF_ActionParameter *pactionparam = *it; + fout << "getName() << "\" "; + fout << "offset=\"" << pactionparam->getOffset() << "\" "; + fout << "min=\"" << (int) pactionparam->getMin() << "\" "; + fout << "max=\"" << (int) pactionparam->getMax() << "\" >" << std::endl; + + // bits + std::deque *pbits = pactionparam->getListBits(); + if (pbits->size()) { + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "getName() << "\" "; + fout << "pos=\"" << (int) pbit->getPos() << "\" "; + fout << "width=\"" << (int) pbit->getWidth() << "\" "; + fout << "default=\"" << (int) pbit->getDefault() << "\" "; + fout << "min=\"" << (int) pbit->getMin() << "\" "; + fout << "max=\"" << (int) pbit->getMax() << "\" "; + fout << "access=\"" << pbit->getAccessStr() << "\" >" << std::endl; + + writeMap_xml(fout, pbit->getMapDescription(), "description"); + writeMap_xml(fout, pbit->getMapInfoUrl(), "infourl"); + + std::deque *pvalues = pactionparam->getListValues(); + if (pvalues->size()) { + fout << " "; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "getName() << "\" "; + fout << "value=\"" << pvalue->getValue() << "\" >" << std::endl; + writeMap_xml(fout, pvalue->getMapDescription(), "description"); + writeMap_xml(fout, pvalue->getMapInfoUrl(), "infourl"); + fout << " "; + } + fout << " " << std::endl; + } + + fout << "" << std::endl; // Bits + } // for bits + } // pbits size + + std::deque *pvalues = pactionparam->getListValues(); + if (pvalues->size()) { + fout << " "; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "getName() << "\" "; + fout << "value=\"" << pvalue->getValue() << "\" >" << std::endl; + writeMap_xml(fout, pvalue->getMapDescription(), "description"); + writeMap_xml(fout, pvalue->getMapInfoUrl(), "infourl"); + fout << " "; + } + fout << " " << std::endl; + } + + writeMap_xml(fout, pactionparam->getMapDescription(), "description"); + writeMap_xml(fout, pactionparam->getMapInfoUrl(), "infourl"); + + fout << "" << std::endl; + } + } + fout << "" << std::endl; + } // for pactionlst + + } // pactionlst + + fout << "" << std::endl; + } + + // -------------------------------------------------------------------------- + + std::deque *peventlst = getEventList(); // Get pointer to event list + if (nullptr != peventlst) { + + fout << "" << std::endl; + for (auto it = peventlst->cbegin(); it != peventlst->cend(); ++it) { + CMDF_Event *pevent = *it; + fout << "getName() << "\" "; + fout << "class=\"" << pevent->getClass() << "\" "; + fout << "type=\"" << pevent->getType() << "\" "; + fout << "priority=\"" << (int) pevent->getPriority() << "\" "; + fout << "dir=\"" << ((MDF_EVENT_DIR_IN == pevent->getDirection()) ? "in" : "out") << "\" >" << std::endl; + + std::deque *peventdatalst = pevent->getListEventData(); + if (peventdatalst->size()) { + for (auto it = peventdatalst->cbegin(); it != peventdatalst->cend(); ++it) { + CMDF_EventData *pdata = *it; + fout << "getName() << "\" "; + fout << "offset=\"" << pdata->getOffset() << "\" >" << std::endl; + + // bits + std::deque *pbits = pdata->getListBits(); + if (pbits->size()) { + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "getName() << "\" "; + fout << "pos=\"" << (int) pbit->getPos() << "\" "; + fout << "width=\"" << (int) pbit->getWidth() << "\" "; + fout << "default=\"" << (int) pbit->getDefault() << "\" "; + fout << "min=\"" << (int) pbit->getMin() << "\" "; + fout << "max=\"" << (int) pbit->getMax() << "\" "; + fout << "access=\"" << pbit->getAccessStr() << "\" >" << std::endl; + + writeMap_xml(fout, pbit->getMapDescription(), "description"); + writeMap_xml(fout, pbit->getMapInfoUrl(), "infourl"); + + std::deque *pvalues = pdata->getListValues(); + if (pvalues->size()) { + fout << " "; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "getName() << "\" "; + fout << "value=\"" << pvalue->getValue() << "\" >" << std::endl; + writeMap_xml(fout, pvalue->getMapDescription(), "description"); + writeMap_xml(fout, pvalue->getMapInfoUrl(), "infourl"); + fout << " "; + } + fout << " " << std::endl; + } + + fout << "" << std::endl; // Bits + } // for bits + } // pbits size + + writeMap_xml(fout, pdata->getMapDescription(), "description"); + writeMap_xml(fout, pdata->getMapInfoUrl(), "infourl"); + fout << "" << std::endl; + } + } + + fout << "" << std::endl; + } + // fout << "level=\"" << (int) pdm->getLevel() << "\" "; + fout << ""; + } + // Write out end data fout << "" << std::endl; fout << "" << std::endl; @@ -2249,7 +2515,7 @@ CMDF::save_json(const std::string &path) fout << "\"module\": {" << std::endl; fout << "\"name\": \"" << getModuleName() << "\"," << std::endl; fout << "\"copyright\": \"" << getModuleCopyright() << "\"," << std::endl; - fout << "\"level\": \"" << getModuleLevel() << "\"," << std::endl; + fout << "\"level\": " << (int)getModuleLevel() << "," << std::endl; fout << "\"model\": \"" << getModuleModel() << "\"," << std::endl; fout << "\"version\": \"" << getModuleVersion() << "\"," << std::endl; fout << "\"changed\": \"" << getModuleChangeDate() << "\"," << std::endl; @@ -2501,14 +2767,14 @@ CMDF::save_json(const std::string &path) fout << "{" << std::endl; fout << "\"name\": \"" << pFirmware->getName() << "\", " << std::endl; fout << "\"path\": \"" << pFirmware->getUrl() << "\", " << std::endl; - fout << "\"format\": \"" << pFirmware->getFormat() << "\", " << std::endl; + fout << "\"format\": \"" << pFirmware->getFormat() << "\", " << std::endl; fout << "\"date\": \"" << pFirmware->getDate() << "\", " << std::endl; fout << "\"target\": \"" << pFirmware->getTarget() << "\", " << std::endl; - fout << "\"targetcode\": \"" << pFirmware->getTargetCode() << "\", " << std::endl; - fout << "\"version_major\": \"" << pFirmware->getVersionMajor() << "\", " << std::endl; - fout << "\"version_minor\": \"" << pFirmware->getVersionMinor() << "\", " << std::endl; - fout << "\"version_subminor\": \"" << pFirmware->getVersionPatch() << "\", " << std::endl; - fout << "\"size\": \"" << pFirmware->getSize() << "\", " << std::endl; + fout << "\"targetcode\": " << pFirmware->getTargetCode() << ", " << std::endl; + fout << "\"version_major\": " << pFirmware->getVersionMajor() << ", " << std::endl; + fout << "\"version_minor\": " << pFirmware->getVersionMinor() << ", " << std::endl; + fout << "\"version_subminor\": " << pFirmware->getVersionPatch() << ", " << std::endl; + fout << "\"size\": " << pFirmware->getSize() << ", " << std::endl; fout << "\"md5\": \"" << pFirmware->getMd5() << "\"" << std::endl; writeMap_json(fout, pFirmware->getMapDescription(), "description", pFirmware->getMapInfoUrl()->size() > 0); writeMap_json(fout, pFirmware->getMapInfoUrl(), "infourl", false); @@ -2541,9 +2807,9 @@ CMDF::save_json(const std::string &path) fout << "\"date\": \"" << pDriver->getDate() << "\", " << std::endl; fout << "\"os\": \"" << pDriver->getOS() << "\", " << std::endl; fout << "\"osver\": \"" << pDriver->getOSVer() << "\", " << std::endl; - fout << "\"version_major\": \"" << pDriver->getVersionMajor() << "\", " << std::endl; - fout << "\"version_minor\": \"" << pDriver->getVersionMinor() << "\", " << std::endl; - fout << "\"version_subminor\": \"" << pDriver->getVersionPatch() << "\", " << std::endl; + fout << "\"version_major\": " << pDriver->getVersionMajor() << ", " << std::endl; + fout << "\"version_minor\": " << pDriver->getVersionMinor() << ", " << std::endl; + fout << "\"version_subminor\": " << pDriver->getVersionPatch() << ", " << std::endl; fout << "\"md5\": \"" << pDriver->getMd5() << "\"" << std::endl; writeMap_json(fout, pDriver->getMapDescription(), "description", pDriver->getMapInfoUrl()->size() > 0); writeMap_json(fout, pDriver->getMapInfoUrl(), "infourl", false); @@ -2594,22 +2860,25 @@ CMDF::save_json(const std::string &path) // -------------------------------------------------------------------------- if (getRegisterObjList()) { + std::set pages; + fout << "," << std::endl; fout << "\"registers\" : [" << std::endl; - // get pages - std::set pages; - std::deque *pregs = getRegisterObjList(); - uint32_t nPageCnt = getPages(pages); + size_t nPages = getPages(pages); + for (auto itr : pages) { - // Go throu pages create set/map with sorted registers - int pos = 0; + // get pages + std::set pages; + std::deque *pregs = getRegisterObjList(); + uint32_t nPageCnt = getPages(pages); - // Add registers for page - std::set regset; - std::map regmap; + // Go throu pages create set/map with sorted registers + int pos = 0; - for (auto itr : pages) { + // Add registers for page + std::set regset; + std::map regmap; // Create set with sorted register offsets and a map // to help find corresponding register pointer @@ -2619,27 +2888,164 @@ CMDF::save_json(const std::string &path) regmap[(*it)->getOffset()] = *it; } } - } - for (auto it = regset.cbegin(); it != regset.cend(); ++it) { - CMDF_Register *preg = regmap[*it]; + for (auto it = regset.cbegin(); it != regset.cend(); ++it) { + CMDF_Register *preg = regmap[*it]; + + fout << "{" << std::endl; + fout << "\"name\": \"" << preg->getName() << "\"," << std::endl; + fout << "\"page\": " << preg->getPage() << "," << std::endl; + fout << "\"offset\": " << preg->getOffset() << "," << std::endl; + fout << "\"span\": " << preg->getSpan() << "," << std::endl; + fout << "\"width\": " << preg->getWidth() << "," << std::endl; + fout << "\"access\": \"" << preg->getAccessStr() << "\"," << std::endl; + fout << "\"type\": \"" << preg->getTypeStr() << "\"," << std::endl; + fout << "\"default\": \"" << preg->getDefault() << "\"," << std::endl; + fout << "\"min\": " << (int) preg->getMin() << "," << std::endl; + fout << "\"max\": " << (int) preg->getMax() << "," << std::endl; + fout << std::hex << "\"fgcolor\": \"0x" << preg->getForegroundColor() << "\"," << std::dec << std::endl; + fout << std::hex << "\"bgcolor\": \"0x" << preg->getBackgroundColor() << "\"" << std::dec << std::endl; + + // bits + std::deque *pbits = preg->getListBits(); + if (pbits->size()) { + int pos = 0; + fout << "," << std::endl; + fout << "\"bit\": [" << std::endl; + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pbit->getName() << "\"," << std::endl; + fout << "\"pos\": " << (int) pbit->getPos() << "," << std::endl; + fout << "\"width\": " << (int) pbit->getWidth() << "," << std::endl; + fout << "\"default\": " << (int) pbit->getDefault() << "," << std::endl; + fout << "\"min\" :" << (int) pbit->getMin() << "," << std::endl; + fout << "\"max\" :" << (int) pbit->getMax() << "," << std::endl; + fout << "\"access\": \"" << pbit->getAccessStr() << "\"" << std::endl; + + // Bit info/docs + writeMap_json(fout, pbit->getMapDescription(), "description", pbit->getMapInfoUrl()->size() > 0); + writeMap_json(fout, pbit->getMapInfoUrl(), "infourl", pbit->getListValues()->size() > 0); + + std::deque *pvalues = pbit->getListValues(); + if (pvalues->size()) { + int pos = 0; + fout << "," << std::endl; + fout << "\"valuelist\": [" << std::endl; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pvalue->getName() << "\"," << std::endl; + fout << "\"value\": \"" << pvalue->getValue() << "\"" << std::endl; + writeMap_json(fout, pvalue->getMapDescription(), "description"); + writeMap_json(fout, pvalue->getMapInfoUrl(), "infourl"); + + fout << "}" << std::endl; + + // If items left add comma + pos++; + if (pos < pvalues->size()) { + fout << ","; + } + + fout << std::endl; + } + fout << "]" << std::endl; // End of values + } + + // If items left add comma + fout << "}" << std::endl; + pos++; + if (pos < pbits->size()) { + fout << ","; + } + + } // for bits + + fout << "]" << std::endl; // Ed of bits array + + } // pbits size + + std::deque *pvalues = preg->getListValues(); + if (pvalues->size()) { + int pos = 0; + fout << "," << std::endl; + fout << "\"valuelist\": [" << std::endl; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pvalue->getName() << "\"," << std::endl; + fout << "\"value\": \"" << pvalue->getValue() << "\"" << std::endl; + writeMap_json(fout, pvalue->getMapDescription(), "description", true); + writeMap_json(fout, pvalue->getMapInfoUrl(), "infourl", true); + fout << "}" << std::endl; + // End of valuelist - If items left add comma + pos++; + if (pos < pvalues->size()) { + fout << ","; + } + fout << std::endl; + } + + fout << "]" << std::endl; // End of values + + } // Values size + + // Register docs/info + writeMap_json(fout, preg->getMapDescription(), "description", preg->getMapInfoUrl()->size() > 0); + writeMap_json(fout, preg->getMapInfoUrl(), "infourl", true); + + // End of registers - If items left add comma + fout << "}"; + pos++; + if (pos < regset.size()) { + fout << ","; + } + fout << std::endl; + + } // registers for-loop + + nPages--; + if (nPages > 0) { + fout << ","; + } + + } // Pages + + // End of registers + fout << "]" << std::endl; + + } // Registers + + // ---------------------------------------------------------------------------- + + if (getRemoteVariableObjList()) { + + // Start of remote variables + fout << "," << std::endl; + fout << "\"remotevars\": [" << std::endl; + + std::deque *prvarList = getRemoteVariableObjList(); + + // Go throu pages create set/map with sorted registers + int pos = 0; + + for (auto it = prvarList->cbegin(); it != prvarList->cend(); ++it) { + CMDF_RemoteVariable *prvar = *it; fout << "{" << std::endl; - fout << "\"name\": \"" << preg->getName() << "\"," << std::endl; - fout << "\"page\": " << preg->getPage() << "," << std::endl; - fout << "\"offset\": " << preg->getOffset() << "," << std::endl; - fout << "\"span\": " << preg->getSpan() << "," << std::endl; - fout << "\"width\": " << preg->getWidth() << "," << std::endl; - fout << "\"access\": \"" << preg->getAccessStr() << "\"," << std::endl; - fout << "\"type\": \"" << preg->getTypeStr() << "\"," << std::endl; - fout << "\"default\": \"" << preg->getDefault() << "\"," << std::endl; - fout << "\"min\": " << (int) preg->getMin() << "," << std::endl; - fout << "\"max\": " << (int) preg->getMax() << "," << std::endl; - fout << std::hex << "\"fgcolor\": \"0x" << preg->getForegroundColor() << "\"," << std::dec << std::endl; - fout << std::hex << "\"bgcolor\": \"0x" << preg->getBackgroundColor() << "\"" << std::dec << std::endl; + fout << "\"name\": \"" << prvar->getName() << "\"," << std::endl; + fout << "\"type\": " << prvar->getType() << "," << std::endl; + fout << "\"default\": \"" << prvar->getDefault() << "\"," << std::endl; + fout << "\"page\": " << prvar->getPage() << "," << std::endl; + fout << "\"offset\": " << prvar->getOffset() << "," << std::endl; + fout << "\"access\": \"" << prvar->getAccessStr() << "\"," << std::endl; + fout << "\"bitpos\": " << prvar->getBitPos() << "," << std::endl; + fout << std::hex << "\"fgcolor\": \"0x" << prvar->getForegroundColor() << "\"," << std::dec << std::endl; + fout << std::hex << "\"bgcolor\": \"0x" << prvar->getBackgroundColor() << "\"" << std::dec << std::endl; // bits - std::deque *pbits = preg->getListBits(); + std::deque *pbits = prvar->getListBits(); if (pbits->size()) { int pos = 0; fout << "," << std::endl; @@ -2653,7 +3059,7 @@ CMDF::save_json(const std::string &path) fout << "\"default\": " << (int) pbit->getDefault() << "," << std::endl; fout << "\"min\" :" << (int) pbit->getMin() << "," << std::endl; fout << "\"max\" :" << (int) pbit->getMax() << "," << std::endl; - fout << "\"access\": \"" << preg->getAccessStr() << "\"" << std::endl; + fout << "\"access\": \"" << pbit->getAccessStr() << "\"" << std::endl; // Bit info/docs writeMap_json(fout, pbit->getMapDescription(), "description", pbit->getMapInfoUrl()->size() > 0); @@ -2698,7 +3104,7 @@ CMDF::save_json(const std::string &path) } // pbits size - std::deque *pvalues = preg->getListValues(); + std::deque *pvalues = prvar->getListValues(); if (pvalues->size()) { int pos = 0; fout << "," << std::endl; @@ -2708,53 +3114,240 @@ CMDF::save_json(const std::string &path) fout << "{" << std::endl; fout << "\"name\": \"" << pvalue->getName() << "\"," << std::endl; fout << "\"value\": \"" << pvalue->getValue() << "\"" << std::endl; - writeMap_json(fout, pvalue->getMapDescription(), "description", true); - writeMap_json(fout, pvalue->getMapInfoUrl(), "infourl", true); + writeMap_json(fout, pvalue->getMapDescription(), "description"); + writeMap_json(fout, pvalue->getMapInfoUrl(), "infourl"); fout << "}" << std::endl; // End of valuelist - If items left add comma pos++; - if (pos < pvalues->size()) { + if (pos < prvarList->size()) { fout << ","; } fout << std::endl; - } + } // value fout << "]" << std::endl; // End of values } // Values size - // Register docs/info - writeMap_json(fout, preg->getMapDescription(), "description", preg->getMapInfoUrl()->size() > 0); - writeMap_json(fout, preg->getMapInfoUrl(), "infourl", true); + // Remote variable docs/info + writeMap_json(fout, prvar->getMapDescription(), "description"); + writeMap_json(fout, prvar->getMapInfoUrl(), "infourl"); - // End of registers - If items left add comma + // End of remote variables - If items left add comma fout << "}"; pos++; - if (pos < regset.size()) { + if (pos < prvarList->size()) { fout << ","; } fout << std::endl; - } // registers for-loop + } // remote variable for-loop + + // End of remote variables + fout << "]" << std::endl; + } + + // ---------------------------------------------------------------------------- + + // Start of alarm bits + fout << "," << std::endl; + fout << "\"alarm\": [" << std::endl; + // bits + std::deque *pbits = getAlarmList(); + if (pbits->size()) { + int pos = 0; + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pbit->getName() << "\"," << std::endl; + fout << "\"pos\": " << (int) pbit->getPos() << "," << std::endl; + fout << "\"width\": " << (int) pbit->getWidth() << "," << std::endl; + fout << "\"default\": " << (int) pbit->getDefault() << "," << std::endl; + fout << "\"min\" :" << (int) pbit->getMin() << "," << std::endl; + fout << "\"max\" :" << (int) pbit->getMax() << "," << std::endl; + fout << "\"access\": \"" << pbit->getAccessStr() << "\"" << std::endl; + + // Bit info/docs + writeMap_json(fout, pbit->getMapDescription(), "description", pbit->getMapInfoUrl()->size() > 0); + writeMap_json(fout, pbit->getMapInfoUrl(), "infourl", pbit->getListValues()->size() > 0); + + // If items left add comma + fout << "}" << std::endl; + pos++; + if (pos < pbits->size()) { + fout << ","; + } + + } // for bits + + // fout << "]" << std::endl; // Ed of bits array + + } // pbits size + + // End of alarm fout << "]" << std::endl; - // End of registers - If items left add comma - /*pos++; - if (pos < pregs->size()) { - fout << ","; + // ---------------------------------------------------------------------------- + + std::deque *peventlst = getEventList(); // Get pointer to event list + if (nullptr != peventlst) { + + // Start of events + fout << "," << std::endl; + fout << "\"events\": [" << std::endl; + + int pos = 0; + + for (auto it = peventlst->cbegin(); it != peventlst->cend(); ++it) { + CMDF_Event *pevent = *it; + + fout << "{" << std::endl; + fout << "\"name\": \"" << pevent->getName() << "\"," << std::endl; + fout << "\"class\": " << pevent->getClass() << "," << std::endl; + fout << "\"type\": " << pevent->getType() << "," << std::endl; + fout << "\"priority\": " << (int) pevent->getPriority() << "," << std::endl; + fout << "\"dir\": \"" << ((MDF_EVENT_DIR_IN == pevent->getDirection()) ? "in" : "out") << "\"," << std::endl; + + std::deque *peventdtalst = pevent->getListEventData(); // Get pointer to event list + if (nullptr != peventdtalst) { + + int pos = 0; + fout << "\"data\": [" << std::endl; + + for (auto it = peventdtalst->cbegin(); it != peventdtalst->cend(); ++it) { + CMDF_EventData *peventdata = *it; + + fout << "{" << std::endl; + fout << "\"name\": \"" << peventdata->getName() << "\"," << std::endl; + fout << "\"offset\": " << peventdata->getOffset() << " " << std::endl; + + // bits + std::deque *pbits = peventdata->getListBits(); + if (pbits->size()) { + int pos = 0; + fout << "," << std::endl; + fout << "\"bit\": [" << std::endl; + for (auto it = pbits->cbegin(); it != pbits->cend(); ++it) { + CMDF_Bit *pbit = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pbit->getName() << "\"," << std::endl; + fout << "\"pos\": " << (int) pbit->getPos() << "," << std::endl; + fout << "\"width\": " << (int) pbit->getWidth() << "," << std::endl; + fout << "\"default\": " << (int) pbit->getDefault() << "," << std::endl; + fout << "\"min\" :" << (int) pbit->getMin() << "," << std::endl; + fout << "\"max\" :" << (int) pbit->getMax() << "," << std::endl; + fout << "\"access\": \"" << pbit->getAccessStr() << "\"" << std::endl; + + // Bit info/docs + writeMap_json(fout, pbit->getMapDescription(), "description", pbit->getMapInfoUrl()->size() > 0); + writeMap_json(fout, pbit->getMapInfoUrl(), "infourl", pbit->getListValues()->size() > 0); + + std::deque *pvalues = pbit->getListValues(); + if (pvalues->size()) { + int pos = 0; + fout << "," << std::endl; + fout << "\"valuelist\": [" << std::endl; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pvalue->getName() << "\"," << std::endl; + fout << "\"value\": \"" << pvalue->getValue() << "\"" << std::endl; + writeMap_json(fout, pvalue->getMapDescription(), "description"); + writeMap_json(fout, pvalue->getMapInfoUrl(), "infourl"); + + fout << "}" << std::endl; + + // If items left add comma + pos++; + if (pos < pvalues->size()) { + fout << ","; + } + + fout << std::endl; + } + fout << "]" << std::endl; // End of values + } + + // If items left add comma + fout << "}" << std::endl; + pos++; + if (pos < pbits->size()) { + fout << ","; + } + + } // for bits + + fout << "]" << std::endl; // Ed of bits array + + } // pbits size + + std::deque *pvalues = peventdata->getListValues(); + if (pvalues->size()) { + int pos = 0; + fout << "," << std::endl; + fout << "\"valuelist\": [" << std::endl; + for (auto it = pvalues->cbegin(); it != pvalues->cend(); ++it) { + CMDF_Value *pvalue = *it; + fout << "{" << std::endl; + fout << "\"name\": \"" << pvalue->getName() << "\"," << std::endl; + fout << "\"value\": \"" << pvalue->getValue() << "\"" << std::endl; + writeMap_json(fout, pvalue->getMapDescription(), "description"); + writeMap_json(fout, pvalue->getMapInfoUrl(), "infourl"); + fout << "}" << std::endl; + // End of valuelist - If items left add comma + pos++; + if (pos < pvalues->size()) { + fout << ","; + } + fout << std::endl; + } // value + + fout << "]" << std::endl; // End of values + + } // Values size + + // Remote variable docs/info + writeMap_json(fout, peventdata->getMapDescription(), "description"); + writeMap_json(fout, peventdata->getMapInfoUrl(), "infourl"); + + // End of event data - If items left add comma + fout << "}"; + pos++; + if (pos < peventdtalst->size()) { + fout << ","; + } + fout << std::endl; + } // for event data + + fout << "]" << std::endl; // End of event data + + } // Event data is available + + // End of remote variables - If items left add comma + fout << "}"; + pos++; + if (pos < peventlst->size()) { + fout << ","; + } + fout << std::endl; + + } // event for-loop + + // End of events + fout << "]" << std::endl; } - fout << std::endl;*/ - // End of registers - fout << "}" << std::endl; + // ---------------------------------------------------------------------------- + //----------------------------------------------------------------------------- -} // Registers + // End of module + fout << "}" << std::endl; -// JSON file end -fout << "}" << std::endl; + // JSON file end + fout << "}" << std::endl; -return VSCP_ERROR_SUCCESS; + return VSCP_ERROR_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/vscp/common/mdf.h b/src/vscp/common/mdf.h index febc005f9..e91baf2fa 100644 --- a/src/vscp/common/mdf.h +++ b/src/vscp/common/mdf.h @@ -939,6 +939,7 @@ class CMDF_RemoteVariable : public CMDF_Object { @return Real text description of type. */ std::string getTypeString(void); + std::string getTypeStr(void) { return getTypeString(); }; /*! Get number of bytes for a remote variable type @@ -3984,7 +3985,8 @@ class CMDF : public CMDF_Object { Return remote variable list from its name @return Pointer to CMDF_RemoteVariable class list */ - std::deque *getRemoteVariableList(void) { return &m_list_remotevar; }; + std::deque *getRemoteVariableList(void) { return &m_list_remotevar; }; // Deprecated + std::deque *getRemoteVariableObjList(void) { return &m_list_remotevar; }; /*! Delete a defined remote variable