From 857c5fa2cd5a462b13f3a71aafa2825e490fd256 Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Sun, 5 May 2024 21:39:33 +0200 Subject: [PATCH] Bootloader test code in place --- src/vscp/common/mdf.cpp | 132 ++++++------- src/vscp/common/register.cpp | 2 +- src/vscp/common/vscp_bootdevice.cpp | 16 +- src/vscp/common/vscp_bootdevice.h | 8 +- src/vscp/common/vscp_bootdevice_pic1.cpp | 14 +- src/vscp/common/vscp_bootdevice_vscp.cpp | 240 +++++++++++++++++------ src/vscp/common/vscp_bootdevice_vscp.h | 98 ++++----- src/vscp/common/vscp_client_canal.cpp | 21 +- src/vscp/common/vscp_client_mqtt.cpp | 35 ++-- src/vscp/common/vscpcanaldeviceif.cpp | 2 +- src/vscp/common/vscphelper.cpp | 72 +------ src/vscp/common/vscphelper.h | 24 +-- src/vscp/common/vscpremotetcpif.cpp | 7 +- 13 files changed, 348 insertions(+), 323 deletions(-) diff --git a/src/vscp/common/mdf.cpp b/src/vscp/common/mdf.cpp index f65296fc2..2f16229d5 100644 --- a/src/vscp/common/mdf.cpp +++ b/src/vscp/common/mdf.cpp @@ -1918,7 +1918,7 @@ CMDF::save_xml(const std::string &path) fout << "" << std::endl; } - if (cnt = pManufacturer->getPhoneObjCount()) { + if ((cnt = pManufacturer->getPhoneObjCount())) { for (int i = 0; i < cnt; i++) { CMDF_Item *pitem = pManufacturer->getPhoneObj(i); if (nullptr != pitem) { @@ -1931,7 +1931,7 @@ CMDF::save_xml(const std::string &path) } } - if (cnt = pManufacturer->getFaxObjCount()) { + if ((cnt = pManufacturer->getFaxObjCount())) { for (int i = 0; i < cnt; i++) { CMDF_Item *pitem = pManufacturer->getFaxObj(i); if (nullptr != pitem) { @@ -1944,7 +1944,7 @@ CMDF::save_xml(const std::string &path) } } - if (cnt = pManufacturer->getEmailObjCount()) { + if ((cnt = pManufacturer->getEmailObjCount())) { for (int i = 0; i < cnt; i++) { CMDF_Item *pitem = pManufacturer->getEmailObj(i); if (nullptr != pitem) { @@ -1957,7 +1957,7 @@ CMDF::save_xml(const std::string &path) } } - if (cnt = pManufacturer->getWebObjCount()) { + if ((cnt = pManufacturer->getWebObjCount())) { for (int i = 0; i < cnt; i++) { CMDF_Item *pitem = pManufacturer->getWebObj(i); if (nullptr != pitem) { @@ -1970,7 +1970,7 @@ CMDF::save_xml(const std::string &path) } } - if (cnt = pManufacturer->getSocialObjCount()) { + if ((cnt = pManufacturer->getSocialObjCount())) { for (int i = 0; i < cnt; i++) { CMDF_Item *pitem = pManufacturer->getSocialObj(i); if (nullptr != pitem) { @@ -2545,7 +2545,7 @@ CMDF::save_json(const std::string &path) fout << "}" << std::endl; } - if (cnt = pManufacturer->getPhoneObjCount()) { + if ((cnt = pManufacturer->getPhoneObjCount())) { fout << "," << std::endl; fout << "\"telephone\": [" << std::endl; int i = 0; @@ -2568,7 +2568,7 @@ CMDF::save_json(const std::string &path) fout << "]"; } - if (cnt = pManufacturer->getFaxObjCount()) { + if ((cnt = pManufacturer->getFaxObjCount())) { fout << "," << std::endl; fout << "\"fax\": [" << std::endl; int i = 0; @@ -2591,7 +2591,7 @@ CMDF::save_json(const std::string &path) fout << "]"; } - if (cnt = pManufacturer->getEmailObjCount()) { + if ((cnt = pManufacturer->getEmailObjCount())) { fout << "," << std::endl; fout << "\"email\": [" << std::endl; int i = 0; @@ -2614,7 +2614,7 @@ CMDF::save_json(const std::string &path) fout << "]"; } - if (cnt = pManufacturer->getWebObjCount()) { + if ((cnt = pManufacturer->getWebObjCount())) { fout << "," << std::endl; fout << "\"web\": [" << std::endl; int i = 0; @@ -2637,7 +2637,7 @@ CMDF::save_json(const std::string &path) fout << "]"; } - if (cnt = pManufacturer->getSocialObjCount()) { + if ((cnt = pManufacturer->getSocialObjCount())) { fout << "," << std::endl; fout << "\"social\": [" << std::endl; int i = 0; @@ -7029,12 +7029,12 @@ CMDF::getDescriptionList(json &j, std::map &map) if (j["description"].is_string()) { map["en"] = j["description"]; - spdlog::debug("Parse-JSON: Description: {0} language: 'en' ", j["description"]); + spdlog::debug("Parse-JSON: Description: {0} language: 'en' ", map["en"]); } else if (j["description"].is_object()) { for (auto &item : j["description"].items()) { map[item.key()] = item.value(); - spdlog::debug("Parse-JSON: Description: {0} language: '{1}'", item.value(), item.key()); + spdlog::debug("Parse-JSON: Description: {0} language: '{1}'", (std::string)item.value(), (std::string)item.key()); } } else { @@ -7060,12 +7060,12 @@ CMDF::getInfoUrlList(json &j, std::map &map) if (j["infourl"].is_string()) { map["en"] = j["infourl"]; - spdlog::debug("Parse-JSON: InfoURL: {0} language: 'en' ", j["infourl"]); + spdlog::debug("Parse-JSON: InfoURL: {0} language: 'en' ", map["en"]); } else if (j["infourl"].is_object()) { for (auto &item : j["infourl"].items()) { map[item.key()] = item.value(); - spdlog::debug("Parse-JSON: InfoURL: {0} language: '{1}'", item.value(), item.key()); + spdlog::debug("Parse-JSON: InfoURL: {0} language: '{1}'", (std::string)item.value(), (std::string)item.key()); } } else { @@ -7759,7 +7759,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jreg.contains("size") && jreg["size"].is_number()) { preg->m_span = jreg["size"]; spdlog::trace("Parse-JSON: Module register span: {0}", preg->m_span); - if ((preg->m_span == 0)) { + if (preg->m_span == 0) { spdlog::warn("Parse-JSON: Register span is zero. This is not supported. " "Default set (1)"); } @@ -7767,7 +7767,7 @@ CMDF::parseMDF_JSON(const std::string &path) else if (jreg.contains("size") && jreg["size"].is_string()) { preg->m_span = vscp_readStringValue(jreg["size"]); spdlog::trace("Parse-JSON: Module register span: {0}", preg->m_span); - if ((preg->m_span == 0)) { + if (preg->m_span == 0) { spdlog::warn("Parse-JSON: Register span is zero. This is not supported. " "Default set (1)"); } @@ -8095,7 +8095,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (j["module"].contains("remotevar") && j["module"]["remotevar"].is_array()) { for (auto &rvar : j["module"]["remotevar"].items()) { // std::cout << "key: " << rvar.key() << ", value:" << rvar.value() << '\n'; - spdlog::trace("Parse-JSON: Remote variable key = {0} type = {1}.", rvar.key(), rvar.value()); + spdlog::trace("Parse-JSON: Remote variable key = {0} type = {1}.", (std::string)rvar.key(), (std::string)rvar.value()); if (rvar.value().is_object()) { CMDF_RemoteVariable *prvar = new CMDF_RemoteVariable(); @@ -8889,7 +8889,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jpic.contains("name") && jpic["name"].is_string()) { ppicture->m_strName = jpic["name"]; - spdlog::trace("Parse-JSON: Picture name: {0} ", jpic["name"]); + spdlog::trace("Parse-JSON: Picture name: {0} ", ppicture->m_strName); } else { spdlog::warn("Parse-JSON: No picture name."); @@ -8897,7 +8897,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jpic.contains("url") && jpic["url"].is_string()) { ppicture->m_strURL = jpic["url"]; - spdlog::trace("Parse-JSON: Picture URL: {0} ", jpic["url"]); + spdlog::trace("Parse-JSON: Picture URL: {0} ", ppicture->m_strURL); } else { spdlog::warn("Parse-JSON: No picture url."); @@ -8905,7 +8905,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jpic.contains("format") && jpic["format"].is_string()) { ppicture->m_strFormat = jpic["format"]; - spdlog::trace("Parse-JSON: Picture Format: {0} ", jpic["url"]); + spdlog::trace("Parse-JSON: Picture Format: {0} ", ppicture->m_strFormat); } else { spdlog::warn("Parse-JSON: No picture format."); @@ -8913,7 +8913,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jpic.contains("date") && jpic["date"].is_string()) { ppicture->m_strDate = jpic["date"]; - spdlog::trace("Parse-JSON: Picture date: {0} ", jpic["date"]); + spdlog::trace("Parse-JSON: Picture date: {0} ", ppicture->m_strDate); } else { spdlog::warn("Parse-JSON: No picture date"); @@ -8945,7 +8945,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jvideo.contains("name") && jvideo["name"].is_string()) { pvideo->m_strName = jvideo["name"]; - spdlog::trace("Parse-JSON: Video name: {0} ", jvideo["name"]); + spdlog::trace("Parse-JSON: Video name: {0} ", pvideo->m_strName); } else { spdlog::warn("Parse-JSON: No video name."); @@ -8953,7 +8953,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jvideo.contains("url") && jvideo["url"].is_string()) { pvideo->m_strURL = jvideo["url"]; - spdlog::trace("Parse-JSON: Video URL: {0} ", jvideo["url"]); + spdlog::trace("Parse-JSON: Video URL: {0} ", pvideo->m_strURL); } else { spdlog::warn("Parse-JSON: No video url."); @@ -8961,7 +8961,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jvideo.contains("format") && jvideo["format"].is_string()) { pvideo->m_strFormat = jvideo["format"]; - spdlog::trace("Parse-JSON: Video Format: {0} ", jvideo["url"]); + spdlog::trace("Parse-JSON: Video Format: {0} ", pvideo->m_strFormat); } else { spdlog::warn("Parse-JSON: No video format."); @@ -8969,7 +8969,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jvideo.contains("date") && jvideo["date"].is_string()) { pvideo->m_strDate = jvideo["date"]; - spdlog::trace("Parse-JSON: Video date: {0} ", jvideo["date"]); + spdlog::trace("Parse-JSON: Video date: {0} ", pvideo->m_strDate); } else { spdlog::warn("Parse-JSON: No video date"); @@ -9001,7 +9001,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("name") && jfirmware["name"].is_string()) { pfirmware->m_strName = jfirmware["name"]; - spdlog::trace("Parse-JSON: Fiirmware name: {0} ", jfirmware["name"]); + spdlog::trace("Parse-JSON: Fiirmware name: {0} ", pfirmware->m_strName); } else { spdlog::warn("Parse-JSON: No firmware name."); @@ -9009,7 +9009,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("url") && jfirmware["url"].is_string()) { pfirmware->m_strURL = jfirmware["url"]; - spdlog::trace("Parse-JSON: Firmware URL: {0} ", jfirmware["url"]); + spdlog::trace("Parse-JSON: Firmware URL: {0} ", pfirmware->m_strURL); } else { spdlog::warn("Parse-JSON: No firmware url."); @@ -9017,7 +9017,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("target") && jfirmware["target"].is_string()) { pfirmware->m_strTarget = jfirmware["target"]; - spdlog::trace("Parse-JSON: Firmware target: {0} ", jfirmware["target"]); + spdlog::trace("Parse-JSON: Firmware target: {0} ", pfirmware->m_strTarget); } else { spdlog::warn("Parse-JSON: No firmware target."); @@ -9025,7 +9025,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("targetcode") && jfirmware["targetcode"].is_number()) { pfirmware->m_targetCode = jfirmware["targetcode"]; - spdlog::trace("Parse-JSON: Firmware target: {0} ", jfirmware["targetcode"]); + spdlog::trace("Parse-JSON: Firmware target: {0} ", pfirmware->m_targetCode); } else { spdlog::warn("Parse-JSON: No firmware target code."); @@ -9034,7 +9034,7 @@ CMDF::parseMDF_JSON(const std::string &path) // Target code string value if (jfirmware.contains("targetcode") && jfirmware["targetcode"].is_string()) { pfirmware->m_targetCode = vscp_readStringValue(jfirmware["targetcode"]); - spdlog::trace("Parse-JSON: Firmware target: {0} ", jfirmware["targetcode"]); + spdlog::trace("Parse-JSON: Firmware target: {0} ", pfirmware->m_targetCode); } else { spdlog::warn("Parse-JSON: No firmware target code."); @@ -9042,7 +9042,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("targetcode") && jfirmware["targetcode"].is_number()) { pfirmware->m_targetCode = jfirmware["targetcode"]; - spdlog::trace("Parse-JSON: Firmware target: {0} ", jfirmware["targetcode"]); + spdlog::trace("Parse-JSON: Firmware target: {0} ", pfirmware->m_targetCode); } else { spdlog::warn("Parse-JSON: No firmware target code."); @@ -9050,7 +9050,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("format") && jfirmware["format"].is_string()) { pfirmware->m_strFormat = jfirmware["format"]; - spdlog::trace("Parse-JSON: Firmware format: {0} ", jfirmware["format"]); + spdlog::trace("Parse-JSON: Firmware format: {0} ", pfirmware->m_strFormat); } else { spdlog::warn("Parse-JSON: No firmware format."); @@ -9058,7 +9058,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("date") && jfirmware["date"].is_string()) { pfirmware->m_strDate = jfirmware["date"]; - spdlog::trace("Parse-JSON: Firmware date: {0} ", jfirmware["date"]); + spdlog::trace("Parse-JSON: Firmware date: {0} ", pfirmware->m_strDate); } else { spdlog::warn("Parse-JSON: No firmware date"); @@ -9066,7 +9066,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("version_major") && jfirmware["version_major"].is_number()) { pfirmware->m_version_major = jfirmware["version_major"]; - spdlog::trace("Parse-JSON: Firmware version major: {0} ", jfirmware["version_major"]); + spdlog::trace("Parse-JSON: Firmware version major: {0} ", pfirmware->m_version_major); } else { spdlog::warn("Parse-JSON: No firmware version_major"); @@ -9074,7 +9074,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("version_major") && jfirmware["version_major"].is_string()) { pfirmware->m_version_major = vscp_readStringValue(jfirmware["version_major"]); - spdlog::trace("Parse-JSON: Firmware version major: {0} ", jfirmware["version_major"]); + spdlog::trace("Parse-JSON: Firmware version major: {0} ", pfirmware->m_version_major); } else { spdlog::warn("Parse-JSON: No firmware version_major"); @@ -9082,7 +9082,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("version_minor") && jfirmware["version_minor"].is_number()) { pfirmware->m_version_minor = jfirmware["version_minor"]; - spdlog::trace("Parse-JSON: Firmware version minor: {0} ", jfirmware["version_minor"]); + spdlog::trace("Parse-JSON: Firmware version minor: {0} ", pfirmware->m_version_minor); } else { spdlog::warn("Parse-JSON: No firmware version_minor"); @@ -9090,7 +9090,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("version_minor") && jfirmware["version_minor"].is_string()) { pfirmware->m_version_minor = vscp_readStringValue(jfirmware["version_minor"]); - spdlog::trace("Parse-JSON: Firmware version minor: {0} ", jfirmware["version_minor"]); + spdlog::trace("Parse-JSON: Firmware version minor: {0} ", pfirmware->m_version_minor); } else { spdlog::warn("Parse-JSON: No firmware version_minor"); @@ -9098,7 +9098,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("version_patch") && jfirmware["version_patch"].is_number()) { pfirmware->m_version_patch = jfirmware["version_patch"]; - spdlog::trace("Parse-JSON: Firmware version patch: {0} ", jfirmware["version_patch"]); + spdlog::trace("Parse-JSON: Firmware version patch: {0} ", pfirmware->m_version_patch); } else { spdlog::warn("Parse-JSON: No firmware version patch"); @@ -9106,7 +9106,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("version_patch") && jfirmware["version_patch"].is_string()) { pfirmware->m_version_patch = vscp_readStringValue(jfirmware["version_patch"]); - spdlog::trace("Parse-JSON: Firmware version patch: {0} ", jfirmware["version_patch"]); + spdlog::trace("Parse-JSON: Firmware version patch: {0} ", pfirmware->m_version_patch ); } else { spdlog::warn("Parse-JSON: No firmware version patch"); @@ -9114,7 +9114,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("size") && jfirmware["size"].is_number()) { pfirmware->m_size = jfirmware["size"]; - spdlog::trace("Parse-JSON: Firmware version size: {0} ", jfirmware["size"]); + spdlog::trace("Parse-JSON: Firmware version size: {0} ", pfirmware->m_size); } else { spdlog::warn("Parse-JSON: No firmware version size"); @@ -9122,7 +9122,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("size") && jfirmware["size"].is_string()) { pfirmware->m_size = vscp_readStringValue(jfirmware["size"]); - spdlog::trace("Parse-JSON: Firmware version size: {0} ", jfirmware["size"]); + spdlog::trace("Parse-JSON: Firmware version size: {0} ", pfirmware->m_size); } else { spdlog::warn("Parse-JSON: No firmware version size"); @@ -9130,7 +9130,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jfirmware.contains("md5sum") && jfirmware["md5sum"].is_string()) { pfirmware->m_strMd5 = jfirmware["md5sum"]; - spdlog::trace("Parse-JSON: Firmware version md5: {0} ", jfirmware["md5sum"]); + spdlog::trace("Parse-JSON: Firmware version md5: {0} ", pfirmware->m_strMd5); } else { spdlog::warn("Parse-JSON: No firmware version md5sum"); @@ -9162,7 +9162,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("name") && jdriver["name"].is_string()) { pdriver->m_strName = jdriver["name"]; - spdlog::trace("Parse-JSON: Driver name: {0} ", jdriver["name"]); + spdlog::trace("Parse-JSON: Driver name: {0} ", pdriver->m_strName); } else { spdlog::warn("Parse-JSON: No driver name."); @@ -9170,7 +9170,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("url") && jdriver["url"].is_string()) { pdriver->m_strURL = jdriver["url"]; - spdlog::trace("Parse-JSON: Driver URL: {0} ", jdriver["url"]); + spdlog::trace("Parse-JSON: Driver URL: {0} ", pdriver->m_strURL); } else { spdlog::warn("Parse-JSON: No driver url."); @@ -9178,7 +9178,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("name") && jdriver["name"].is_string()) { pdriver->m_strName = jdriver["name"]; - spdlog::trace("Parse-JSON: Driver name: {0} ", jdriver["name"]); + spdlog::trace("Parse-JSON: Driver name: {0} ", pdriver->m_strName); } else { spdlog::warn("Parse-JSON: No driver name."); @@ -9187,7 +9187,7 @@ CMDF::parseMDF_JSON(const std::string &path) // Type if (jdriver.contains("type") && jdriver["type"].is_string()) { pdriver->m_strType = jdriver["type"]; - spdlog::trace("Parse-JSON: driver type: {0} ", jdriver["type"]); + spdlog::trace("Parse-JSON: driver type: {0} ", pdriver->m_strType); } else { spdlog::warn("Parse-JSON: No driver type."); @@ -9196,7 +9196,7 @@ CMDF::parseMDF_JSON(const std::string &path) // OS if (jdriver.contains("os") && jdriver["os"].is_string()) { pdriver->m_strOS = jdriver["os"]; - spdlog::trace("Parse-JSON: driver OS: {0} ", jdriver["os"]); + spdlog::trace("Parse-JSON: driver OS: {0} ", pdriver->m_strOS); } else { spdlog::warn("Parse-JSON: No driver OS."); @@ -9205,7 +9205,7 @@ CMDF::parseMDF_JSON(const std::string &path) // OS version if (jdriver.contains("osver") && jdriver["osver"].is_string()) { pdriver->m_strOSVer = jdriver["osver"]; - spdlog::trace("Parse-JSON: driver OS version: {0} ", jdriver["osver"]); + spdlog::trace("Parse-JSON: driver OS version: {0} ", pdriver->m_strOSVer); } else { spdlog::warn("Parse-JSON: No driver OS version."); @@ -9214,7 +9214,7 @@ CMDF::parseMDF_JSON(const std::string &path) // Architecture if (jdriver.contains("architecture") && jdriver["architecture"].is_string()) { pdriver->m_strArchitecture = jdriver["architecture"]; - spdlog::trace("Parse-JSON: driver OS architecture: {0} ", jdriver["architecture"]); + spdlog::trace("Parse-JSON: driver OS architecture: {0} ", pdriver->m_strArchitecture); } else { spdlog::warn("Parse-JSON: No driver architecture."); @@ -9222,7 +9222,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("date") && jdriver["date"].is_string()) { pdriver->m_strDate = jdriver["date"]; - spdlog::trace("Parse-JSON: Driver date: {0} ", jdriver["date"]); + spdlog::trace("Parse-JSON: Driver date: {0} ", pdriver->m_strDate); } else { spdlog::warn("Parse-JSON: No driver date"); @@ -9230,7 +9230,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("version_major") && jdriver["version_major"].is_number()) { pdriver->m_version_major = jdriver["version_major"]; - spdlog::trace("Parse-JSON: Driver version major: {0} ", jdriver["version_major"]); + spdlog::trace("Parse-JSON: Driver version major: {0} ", pdriver->m_version_major); } else { spdlog::warn("Parse-JSON: No driver version_major"); @@ -9238,7 +9238,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("version_major") && jdriver["version_major"].is_string()) { pdriver->m_version_major = vscp_readStringValue(jdriver["version_major"]); - spdlog::trace("Parse-JSON: Driver version major: {0} ", jdriver["version_major"]); + spdlog::trace("Parse-JSON: Driver version major: {0} ", pdriver->m_version_major); } else { spdlog::warn("Parse-JSON: No driver version_major"); @@ -9246,7 +9246,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("version_minor") && jdriver["version_minor"].is_number()) { pdriver->m_version_minor = jdriver["version_minor"]; - spdlog::trace("Parse-JSON: Driver version minor: {0} ", jdriver["version_minor"]); + spdlog::trace("Parse-JSON: Driver version minor: {0} ", pdriver->m_version_minor); } else { spdlog::warn("Parse-JSON: No driver version_minor"); @@ -9254,7 +9254,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("version_minor") && jdriver["version_minor"].is_string()) { pdriver->m_version_minor = vscp_readStringValue(jdriver["version_minor"]); - spdlog::trace("Parse-JSON: Driver version minor: {0} ", jdriver["version_minor"]); + spdlog::trace("Parse-JSON: Driver version minor: {0} ", pdriver->m_version_minor); } else { spdlog::warn("Parse-JSON: No driver version_minor"); @@ -9262,7 +9262,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("version_patch") && jdriver["version_patch"].is_number()) { pdriver->m_version_patch = jdriver["version_patch"]; - spdlog::trace("Parse-JSON: Driver version patch: {0} ", jdriver["version_patch"]); + spdlog::trace("Parse-JSON: Driver version patch: {0} ", pdriver->m_version_patch); } else { spdlog::warn("Parse-JSON: No driver version patch"); @@ -9270,7 +9270,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("version_patch") && jdriver["version_patch"].is_string()) { pdriver->m_version_patch = vscp_readStringValue(jdriver["version_patch"]); - spdlog::trace("Parse-JSON: Driver version patch: {0} ", jdriver["version_patch"]); + spdlog::trace("Parse-JSON: Driver version patch: {0} ", pdriver->m_version_patch); } else { spdlog::warn("Parse-JSON: No driver version patch"); @@ -9278,7 +9278,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jdriver.contains("md5sum") && jdriver["md5sum"].is_string()) { pdriver->m_strMd5 = jdriver["md5sum"]; - spdlog::trace("Parse-JSON: Driver version md5: {0} ", jdriver["md5sum"]); + spdlog::trace("Parse-JSON: Driver version md5: {0} ", pdriver->m_strMd5); } else { spdlog::warn("Parse-JSON: No driver version md5sum"); @@ -9310,7 +9310,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jmanual.contains("name") && jmanual["name"].is_string()) { pmanual->m_strName = jmanual["name"]; - spdlog::trace("Parse-JSON: Manual name: {0} ", jmanual["name"]); + spdlog::trace("Parse-JSON: Manual name: {0} ", pmanual->m_strName); } else { spdlog::warn("Parse-JSON: No manual name."); @@ -9318,7 +9318,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jmanual.contains("url") && jmanual["url"].is_string()) { pmanual->m_strURL = jmanual["url"]; - spdlog::trace("Parse-JSON: Manual URL: {0} ", jmanual["url"]); + spdlog::trace("Parse-JSON: Manual URL: {0} ", pmanual->m_strURL); } else { spdlog::warn("Parse-JSON: No manual url."); @@ -9326,7 +9326,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jmanual.contains("format") && jmanual["format"].is_string()) { pmanual->m_strFormat = jmanual["format"]; - spdlog::trace("Parse-JSON: Manual Format: {0} ", jmanual["format"]); + spdlog::trace("Parse-JSON: Manual Format: {0} ", pmanual->m_strFormat); } else { spdlog::warn("Parse-JSON: No manual format."); @@ -9334,7 +9334,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jmanual.contains("lang") && jmanual["lang"].is_string()) { pmanual->m_strLanguage = jmanual["lang"]; - spdlog::trace("Parse-JSON: Manual language: {0} ", jmanual["lang"]); + spdlog::trace("Parse-JSON: Manual language: {0} ", pmanual->m_strLanguage); } else { spdlog::warn("Parse-JSON: No manual language."); @@ -9342,7 +9342,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jmanual.contains("date") && jmanual["date"].is_string()) { pmanual->m_strDate = jmanual["date"]; - spdlog::trace("Parse-JSON: Manual date: {0} ", jmanual["date"]); + spdlog::trace("Parse-JSON: Manual date: {0} ", pmanual->m_strDate); } else { spdlog::warn("Parse-JSON: No manual date"); @@ -9374,7 +9374,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jsetup.contains("name") && jsetup["name"].is_string()) { psetup->m_strName = jsetup["name"]; - spdlog::trace("Parse-JSON: Setup name: {0} ", jsetup["name"]); + spdlog::trace("Parse-JSON: Setup name: {0} ", psetup->m_strName); } else { spdlog::warn("Parse-JSON: No setup name."); @@ -9382,7 +9382,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jsetup.contains("url") && jsetup["url"].is_string()) { psetup->m_strURL = jsetup["url"]; - spdlog::trace("Parse-JSON: Setup URL: {0} ", jsetup["url"]); + spdlog::trace("Parse-JSON: Setup URL: {0} ", psetup->m_strURL); } else { spdlog::warn("Parse-JSON: No setup url."); @@ -9390,7 +9390,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jsetup.contains("format") && jsetup["format"].is_string()) { psetup->m_strFormat = jsetup["format"]; - spdlog::trace("Parse-JSON: Setup Format: {0} ", jsetup["url"]); + spdlog::trace("Parse-JSON: Setup Format: {0} ", psetup->m_strFormat); } else { spdlog::warn("Parse-JSON: No setup format."); @@ -9398,7 +9398,7 @@ CMDF::parseMDF_JSON(const std::string &path) if (jsetup.contains("date") && jsetup["date"].is_string()) { psetup->m_strDate = jsetup["date"]; - spdlog::trace("Parse-JSON: Setup date: {0} ", jsetup["date"]); + spdlog::trace("Parse-JSON: Setup date: {0} ", psetup->m_strDate); } else { spdlog::warn("Parse-JSON: No setup date"); diff --git a/src/vscp/common/register.cpp b/src/vscp/common/register.cpp index 194c621b6..498dced90 100644 --- a/src/vscp/common/register.cpp +++ b/src/vscp/common/register.cpp @@ -1668,7 +1668,7 @@ CUserRegisters::remoteVarFromRegToString(CMDF_RemoteVariable &remoteVar, std::st pstr = new uint8_t[remoteVar.getTypeByteCount() + 1]; if (nullptr == pstr) return false; - memset(pstr, 0, sizeof(pstr)); + memset(pstr, 0, remoteVar.getTypeByteCount() + 1); for (unsigned int i = remoteVar.getOffset(); i < (remoteVar.getOffset() + remoteVar.getTypeByteCount()); i++) { pstr[i] = ppage->getReg(i); } diff --git a/src/vscp/common/vscp_bootdevice.cpp b/src/vscp/common/vscp_bootdevice.cpp index 63fa3f845..494fe6bb2 100644 --- a/src/vscp/common/vscp_bootdevice.cpp +++ b/src/vscp/common/vscp_bootdevice.cpp @@ -322,23 +322,29 @@ CBootDevice::getMinMaxForRange(uint32_t start, uint32_t end, uint32_t *pmin, uin } /////////////////////////////////////////////////////////////////////////////// -// fillBlock +// fillMemoryBuffer // int -CBootDevice::fillBlock(uint8_t *pblock, uint32_t size, uint32_t start, uint8_t fill) +CBootDevice::fillMemoryBuffer(uint8_t *pmem, uint32_t size, uint32_t start, uint8_t fill) { - if (nullptr == pblock) { + // Check pointers + if (nullptr == pmem) { return VSCP_ERROR_INVALID_POINTER; } + // Check size + if (!size) { + return VSCP_ERROR_SIZE; + } + // Fill block with void value (0xff for flash) - memset(pblock, fill, size); + memset(pmem, fill, size); for (auto const &pblk : m_memblkList) { if ((pblk->getStartAddress() >= start) && (pblk->getStartAddress() < (start + size))) { for (uint8_t pos = 0; pos < pblk->getSize(); pos++) { - pblock[(pblk->getStartAddress() - start) + pos] = *(pblk->getBlock() + pos); + pmem[(pblk->getStartAddress() - start) + pos] = *(pblk->getBlock() + pos); } } } diff --git a/src/vscp/common/vscp_bootdevice.h b/src/vscp/common/vscp_bootdevice.h index 6d162d302..3b1954e3a 100644 --- a/src/vscp/common/vscp_bootdevice.h +++ b/src/vscp/common/vscp_bootdevice.h @@ -210,14 +210,16 @@ class CBootDevice { virtual int getMinMaxForRange(uint32_t start, uint32_t end, uint32_t *pmin, uint32_t *pmax); /*! - Fill block with firmware data - @param pblock Pointer to the beginning of an allocated block + Fill memory buffer with firmware data + The memory buffer is an area that hold an image of the memory on a remote + device. Typically for one type of memory. + @param pmem Pointer to the beginning of an allocated memory buffer @param size Total size of block @param start Logical start address @param fill Value to initialize block with- 0xff is default @return VSCP_ERROR_SUCCESS or errorcode otherwise. */ - int fillBlock(uint8_t *pblock, uint32_t size, uint32_t start, uint8_t fill = 0xff); + int fillMemoryBuffer(uint8_t *pmem, uint32_t size, uint32_t start, uint8_t fill = 0xff); /*! Get info for hex file in html format diff --git a/src/vscp/common/vscp_bootdevice_pic1.cpp b/src/vscp/common/vscp_bootdevice_pic1.cpp index 19e8a6dc7..db30357e8 100644 --- a/src/vscp/common/vscp_bootdevice_pic1.cpp +++ b/src/vscp/common/vscp_bootdevice_pic1.cpp @@ -35,9 +35,9 @@ #include "vscp_bootdevice_pic1.h" #include "spdlog/fmt/bin_to_hex.h" -#include -#include -#include +// #include +// #include +// #include #include /////////////////////////////////////////////////////////////////////////////// @@ -824,7 +824,7 @@ CBootDevice_PIC1::writeFirmwareBlock(uint32_t start, uint32_t end) } // Init the block - if (VSCP_ERROR_SUCCESS != (rv = fillBlock(pbuf, size, start))) { + if (VSCP_ERROR_SUCCESS != (rv = fillMemoryBuffer(pbuf, size, start))) { spdlog::error("writeFirmwareBlock: Failed to fill code block with data."); if (nullptr != m_statusCallback) { m_statusCallback(-1, @@ -880,13 +880,13 @@ CBootDevice_PIC1::deviceLoad(std::function statusCallba m_checksum = 0; uint32_t progress = 0; - uint32_t addr; + uint32_t addr = 0; std::string strStatus; uint8_t pbuf[BUFFER_SIZE_CODE]; uint32_t nPackets; - uint32_t minAddr; - uint32_t maxAddr; + // uint32_t minAddr; + // uint32_t maxAddr; if (nullptr != m_statusCallback) { m_statusCallback(0, "Starting firmware download"); diff --git a/src/vscp/common/vscp_bootdevice_vscp.cpp b/src/vscp/common/vscp_bootdevice_vscp.cpp index 3a3990a03..35a24331c 100644 --- a/src/vscp/common/vscp_bootdevice_vscp.cpp +++ b/src/vscp/common/vscp_bootdevice_vscp.cpp @@ -308,11 +308,104 @@ CBootDevice_VSCP::deviceInit(cguid &ourguid, uint8_t devicecode, bool bAbortOnFi // ---------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////// -// writeFirmwareBlockDataChunk +// writeBlockStart // int -CBootDevice_VSCP::writeFirmwareBlockDataChunk(const uint8_t *paddr, uint16_t size) +CBootDevice_VSCP::writeBlockStart(uint32_t block, uint8_t type) +{ + int rv; + vscpEventEx ex; + + ex.vscp_class = VSCP_CLASS1_PROTOCOL; + ex.vscp_type = VSCP_TYPE_PROTOCOL_START_BLOCK; + ex.timestamp = vscp_makeTimeStamp(); + vscp_setEventExDateTimeBlockToNow(&ex); + + cguid node_guid; + m_stdRegs.getGUID(node_guid); + + ex.sizeData = 8; + ex.data[0] = (block >> 24) & 0xff; + ex.data[1] = (block >> 16) & 0xff; + ex.data[2] = (block >> 8) & 0xff; + ex.data[3] = block & 0xff; + ex.data[4] = type; + + if (VSCP_ERROR_SUCCESS != (rv = m_pclient->send(ex))) { + spdlog::error("VSCP bootloader: Failed to send start block transfer event {0}", rv); + if (nullptr != m_statusCallback) { + m_statusCallback(-1, "VSCP bootloader: Failed to send start block transfer event"); + } + return rv; + } + + // Wait for response on start block transfer event + if (VSCP_ERROR_SUCCESS != + (rv = checkResponse(ex, node_guid, VSCP_TYPE_PROTOCOL_START_BLOCK_ACK, VSCP_TYPE_PROTOCOL_START_BLOCK_NACK))) { + spdlog::error("VSCP bootloader: Negative response from block start request {0}", rv); + if (nullptr != m_statusCallback) { + m_statusCallback(-1, "VSCP bootloader: Negative response from block start request"); + } + return rv; + } + + return VSCP_ERROR_SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////// +// programBlock +// + +int +CBootDevice_VSCP::programBlock(uint32_t block) +{ + int rv; + vscpEventEx ex; + + ex.vscp_class = VSCP_CLASS1_PROTOCOL; + ex.vscp_type = VSCP_TYPE_PROTOCOL_PROGRAM_BLOCK_DATA; + ex.timestamp = vscp_makeTimeStamp(); + vscp_setEventExDateTimeBlockToNow(&ex); + + cguid node_guid; + m_stdRegs.getGUID(node_guid); + + ex.sizeData = 8; + ex.data[0] = (block >> 24) & 0xff; + ex.data[1] = (block >> 16) & 0xff; + ex.data[2] = (block >> 8) & 0xff; + ex.data[3] = block & 0xff; + + if (VSCP_ERROR_SUCCESS != (rv = m_pclient->send(ex))) { + spdlog::error("VSCP bootloader: Failed to send start block transfer event {0}", rv); + if (nullptr != m_statusCallback) { + m_statusCallback(-1, "VSCP bootloader: Failed to send start block transfer event"); + } + return rv; + } + + // Wait for response on start block transfer event + if (VSCP_ERROR_SUCCESS != (rv = checkResponse(ex, + node_guid, + VSCP_TYPE_PROTOCOL_PROGRAM_BLOCK_DATA_ACK, + VSCP_TYPE_PROTOCOL_PROGRAM_BLOCK_DATA_NACK))) { + spdlog::error("VSCP bootloader: Negative response from block start request {0}", rv); + if (nullptr != m_statusCallback) { + m_statusCallback(-1, "VSCP bootloader: Negative response from block start request"); + } + return rv; + } + + return VSCP_ERROR_SUCCESS; +} + +/////////////////////////////////////////////////////////////////////////////// +// writeChunk +// + +int +CBootDevice_VSCP::writeChunk(const uint8_t *paddr, uint16_t size) { int rv; vscpEventEx ex; @@ -356,11 +449,11 @@ CBootDevice_VSCP::writeFirmwareBlockDataChunk(const uint8_t *paddr, uint16_t siz } /////////////////////////////////////////////////////////////////////////////// -// writeFirmwareBlock +// writeBlock // int -CBootDevice_VSCP::writeFirmwareBlock(const uint8_t *paddr) +CBootDevice_VSCP::writeBlock(const uint8_t *paddr) { int rv; vscpEventEx ex; @@ -381,17 +474,22 @@ CBootDevice_VSCP::writeFirmwareBlock(const uint8_t *paddr) } for (uint32_t chunk = 0; chunk < nChunks; chunk++) { - //uint32_t addr = memory_range[8].beginning; - spdlog::debug("Loading flash on remote device... block={0} {1:X}", chunk, chunk * m_chunkSize); - if (VSCP_ERROR_SUCCESS != writeFirmwareBlockDataChunk(paddr + (m_chunkSize*nChunks), m_chunkSize)) { - spdlog::error("Failed to write flash data to node(s)."); + + spdlog::debug("Loading memory chunk on remote device. chunk={0} {1:X} ", chunk, chunk * m_chunkSize); + if (nullptr != m_statusCallback) { + m_statusCallback((100 * chunk) / nChunks, vscp_str_format("Loading memory chunk on remote device. chunk = %d.", chunk).c_str()); + } + + if (VSCP_ERROR_SUCCESS != writeChunk(paddr + (m_chunkSize * nChunks), m_chunkSize)) { + spdlog::error("Failed to write chunk to remote device. rv={}", rv); + if (nullptr != m_statusCallback) { + m_statusCallback((100 * chunk) / nChunks, vscp_str_format("Failed to write chunk to remote device rv=%d.", rv).c_str()); + } break; } paddr += m_chunkSize; - if (nullptr != m_statusCallback) { - m_statusCallback((100 * chunk) / nChunks, "" /*vscp_str_format("blk %d.", blk).c_str()*/); - } + } // for @@ -412,11 +510,6 @@ CBootDevice_VSCP::deviceLoad(std::function statusCallba uint32_t addr; std::string strStatus; - uint32_t minAddr; - uint32_t maxAddr; - - uint32_t nBlocks; - m_checksum = 0; if (nullptr != m_statusCallback) { @@ -427,14 +520,28 @@ CBootDevice_VSCP::deviceLoad(std::function statusCallba m_checksum = 0; // Iterate over memory types - int pos = 0; - do { + for (int pos = 0; pos < NUMBER_OF_MEMORY_TYPES; pos++) { + + spdlog::error("writeFirmwareBlock: Handling memory range {0}", memory_range[pos].type); + if (nullptr != m_statusCallback) { + m_statusCallback(-1, + vscp_str_format("writeFirmwareBlock: Handling memory range %d", memory_range[pos].type).c_str()); + } + uint32_t minAddr; + uint32_t maxAddr; + + // Fetch min and max address for selected memory range if (VSCP_ERROR_SUCCESS != - (rv = getMinMaxForRange(memory_range[pos++].beginning, memory_range[pos++].end, &minAddr, &maxAddr))) { - spdlog::error("writeFirmwareBlock: Failed to get min max range for block {0:X}-{1:X}", minAddr, maxAddr); + (rv = getMinMaxForRange(memory_range[pos].beginning, memory_range[pos].end, &minAddr, &maxAddr))) { + spdlog::error("writeFirmwareBlock: Failed to get min max range for block {0:X}-{1:X} rv=%d", + minAddr, + maxAddr, + rv); if (nullptr != m_statusCallback) { - m_statusCallback(-1, vscp_str_format("writeFirmwareBlock: Failed to get min max range for block", rv).c_str()); + m_statusCallback( + -1, + vscp_str_format("writeFirmwareBlock: Failed to get min max range for block. rv=%d", rv).c_str()); } return rv; } @@ -442,16 +549,32 @@ CBootDevice_VSCP::deviceLoad(std::function statusCallba // If there is a memory range to work with if (maxAddr > minAddr) { - nBlocks = (maxAddr - minAddr) / m_blockSize; + /*! + The number of blocks to transfer count from the first byte to the + last byte. The lowest address may need to be adjusted to a block + boundary. There is no ned to do this for the upper address + */ + minAddr -= (minAddr % m_blockSize); // Adjust to block boundary + + uint32_t nBlocks = (maxAddr - minAddr) / m_blockSize; // A not completely full packet also count if (0 != ((maxAddr - minAddr) % m_blockSize)) { nBlocks++; } - uint8_t *pbuf = new uint8_t[m_blockSize]; + uint32_t startBlock = (minAddr - memory_range[pos].beginning) / m_blockSize; + + /* + Some notes to remember (and handle): + - Blocksize can be less than data size (ChunkSize) for a frame (8/512) + - A block size that is less than + */ + uint8_t *pbuf = new uint8_t[memory_range[pos].end - memory_range[pos].beginning + 1]; - // Init the block - if (VSCP_ERROR_SUCCESS != (rv = fillBlock(pbuf, m_blockSize, minAddr))) { + // Init the memory image. Fill unused positions with 0xff + // After fill we have a block with data that is that is + // offset memory_range[pos].beginning + if (VSCP_ERROR_SUCCESS != (rv = fillMemoryBuffer(pbuf, m_blockSize, memory_range[pos].beginning))) { spdlog::error("writeFirmwareBlock: Failed to fill code block with data."); if (nullptr != m_statusCallback) { m_statusCallback( @@ -462,49 +585,48 @@ CBootDevice_VSCP::deviceLoad(std::function statusCallba return rv; } - // * * * start block * * * + // Write blocks to remote device - ex.vscp_class = VSCP_CLASS1_PROTOCOL; - ex.vscp_type = VSCP_TYPE_PROTOCOL_START_BLOCK; - ex.timestamp = vscp_makeTimeStamp(); - vscp_setEventExDateTimeBlockToNow(&ex); + uint32_t block = 0; + while (block < nBlocks) { - cguid node_guid; - m_stdRegs.getGUID(node_guid); + /*! + * * * start block * * * - ex.sizeData = 8; - // ex.data[0] = (nblock >> 24) & 0xff; - // ex.data[1] = (nblock >> 16) & 0xff; - // ex.data[2] = (nblock >> 8) & 0xff; - // ex.data[3] = nblock & 0xff; - ex.data[4] = memory_range[pos].type; - - if (VSCP_ERROR_SUCCESS != (rv = m_pclient->send(ex))) { - spdlog::error("VSCP bootloader: Failed to send start block transfer event {0}", rv); - if (nullptr != m_statusCallback) { - m_statusCallback(-1, "VSCP bootloader: Failed to send start block transfer event"); + Startblock is the first block in an area. The block number + is given and also memory type. Blocknumbers can skip + blocks that should not be written. + */ + if (VSCP_ERROR_SUCCESS != (rv = writeBlockStart(block, memory_range[pos].type))) { + delete[] pbuf; + return rv; } - return rv; - } - // Wait for response on start block transfer event - if (VSCP_ERROR_SUCCESS != - (rv = - checkResponse(ex, node_guid, VSCP_TYPE_PROTOCOL_START_BLOCK_ACK, VSCP_TYPE_PROTOCOL_START_BLOCK_NACK))) { - spdlog::error("VSCP bootloader: Negative response from block start request {0}", rv); - if (nullptr != m_statusCallback) { - m_statusCallback(-1, "VSCP bootloader: Negative response from block start request"); + // Write the block + if (VSCP_ERROR_SUCCESS != (rv = writeBlock(pbuf + (block * m_blockSize)))) { + spdlog::error("VSCP bootloader: Failed to write block {0}", rv); + if (nullptr != m_statusCallback) { + m_statusCallback(-1, "VSCP bootloader: Failed to write block"); + } + delete[] pbuf; + return rv; } - return rv; - } - while (true) { - if (VSCP_ERROR_SUCCESS != (rv = writeFirmwareBlock(pbuf))) { + // Program the block + if (VSCP_ERROR_SUCCESS != (rv = programBlock(block))) { + delete[] pbuf; return rv; } - } - } - } while (0xff == memory_range[pos++].type); + + // Next block + block++; + + } // Writing blocks + + delete[] pbuf; + + } // There is bytes to write + } // for memory types return VSCP_ERROR_TIMEOUT; } diff --git a/src/vscp/common/vscp_bootdevice_vscp.h b/src/vscp/common/vscp_bootdevice_vscp.h index a499a1feb..3cc5cf985 100644 --- a/src/vscp/common/vscp_bootdevice_vscp.h +++ b/src/vscp/common/vscp_bootdevice_vscp.h @@ -141,6 +141,19 @@ class CBootDevice_VSCP : public CBootDevice { // Default timeout for response static const uint8_t BOOT_COMMAND_RESPONSE_TIMEOUT = 5; + static const uint8_t NUMBER_OF_MEMORY_TYPES = 8; + + struct memory_range { + uint8_t type; + uint32_t beginning; + uint32_t end; + } memory_range[NUMBER_OF_MEMORY_TYPES] = { + { 0x00, MEM_CODE_START, MEM_CODE_START }, { 0x01, MEM_EEPROM_START, MEM_EEPROM_END }, + { 0x02, MEM_CONFIG_START, MEM_CONFIG_END }, { 0x03, MEM_RAM_START, MEM_RAM_END }, + { 0x04, MEM_USERID_START, MEM_USERID_END }, { 0xfd, MEM_USER0_START, MEM_USER0_END }, + { 0xfe, MEM_USER1_START, MEM_USER1_END }, { 0xff, MEM_USER2_START, MEM_USER2_END } + }; + // Initialize data void init(void); @@ -158,17 +171,18 @@ class CBootDevice_VSCP : public CBootDevice { MDF is not the same as the one read from the remote device. @return VSCP_ERROR_SUCCESS on success. */ - int deviceInit(cguid& ourguid, uint8_t devicecode, bool bAbortOnFirmwareCodeFail = false); + int deviceInit(cguid &ourguid, uint8_t devicecode, bool bAbortOnFirmwareCodeFail = false); /*! Perform the actual firmware load process + All memory areas are loaded to the device @param statusCallback Callback that receive status info as presentage (int) and status message (const char *) @param bAbortOnFirmwareCodeFail If firmware device code stored in standard registers is different then the one we try to load, abort if true. @return VSCP_ERROR_SUCCESS on success. */ - int deviceLoad(std::function statusCallback = nullptr,bool bAbortOnFirmwareCodeFail = true); + int deviceLoad(std::function statusCallback = nullptr, bool bAbortOnFirmwareCodeFail = true); /*! Restart remote device @@ -182,7 +196,24 @@ class CBootDevice_VSCP : public CBootDevice { */ int deviceReboot(void); + + /*! + Write block start to remote device + @param block Block number to write + @param type Memoty type code for memory to write + @return VSCP_ERROR_SUCCESS on success. + */ + int writeBlockStart(uint32_t block, uint8_t type); + + /*! + Program block on remote device + @param block Block number to write + @return VSCP_ERROR_SUCCESS on success. + */ + int programBlock(uint32_t block); + + /*! Write a sector @param paddr Pointer to firts byte of 8-byte block to write to remote device @@ -190,31 +221,14 @@ class CBootDevice_VSCP : public CBootDevice { max event data (8/512) @return VSCP_ERROR_SUCCESS on success. */ - int writeFirmwareBlockDataChunk(const uint8_t *paddr, uint16_t size); + int writeChunk(const uint8_t *paddr, uint16_t size); /*! Write a firmware flock to the device @param paddr Address to beginning of data to write @return VSCP_ERROR_SUCCESS on success. */ - int writeFirmwareBlock(const uint8_t *paddr); - - /*! - Write to device control registry - - @param addr Address to set as start address - @param flags Control Flags - @param cmd Boot command - @param cmdData0 Boot command data byte 0 - @param cmdData1 Boot command data byte 1 - @return VSCP_ERROR_SUCCESS on success. - - */ - // int writeDeviceControlRegs(uint32_t addr, - // uint8_t flags = (MODE_WRT_UNLCK | MODE_AUTO_ERASE | MODE_AUTO_INC | MODE_ACK), - // uint8_t cmd = CMD_NOP, - // uint8_t cmdData0 = 0, - // uint8_t cmdData1 = 0); + int writeBlock(const uint8_t *paddr); /*! Check response event @@ -231,36 +245,7 @@ class CBootDevice_VSCP : public CBootDevice { uint16_t response_event_nack, uint32_t timeout = BOOT_COMMAND_DEFAULT_RESPONSE_TIMEOUT); - /*! - Check for response from nodes (Level I). - - This routine is used as a check for response from nodes under boot. - - The supplied id is valid from bit 8 and upwards. The lower eight bits - are the id. - Only extended messages are accepted as a valid response. - - @param id Response code to look for. - @return VSCP_ERROR_SUCCESS on success. - */ - int checkResponseLevel1(uint32_t id); - - /*! - Check for response from nodes over server (Level II). - - This routine is used as a check for response from nodes under boot. - - The supplied id is valid from bit 8 and upwards. The lower eight bits - are the id. - Only extended messages are accepted as a valid response. - - @param id Response code to look for. - @return VSCP_ERROR_SUCCESS on success. - */ - int checkResponseLevel2(uint32_t id); - private: - /// Current set page in register space on remote device uint32_t m_page; @@ -271,7 +256,7 @@ class CBootDevice_VSCP : public CBootDevice { Current block number This is the current block we are writing */ - //uint32_t m_blockNumber; + // uint32_t m_blockNumber; /*! Internal address pointer @@ -293,7 +278,7 @@ class CBootDevice_VSCP : public CBootDevice { cases. block size can be less then chunk size. This is escpecially true - for level II + for level II */ uint16_t m_chunkSize; @@ -319,13 +304,4 @@ class CBootDevice_VSCP : public CBootDevice { CRC for full programming data. */ uint16_t m_crc16; - - struct memory_range { - uint8_t type; - uint32_t beginning; - uint32_t end; - } memory_range[8] = { { 0x00, MEM_CODE_START, MEM_CODE_START }, { 0x01, MEM_EEPROM_START, MEM_EEPROM_END }, - { 0x02, MEM_CONFIG_START, MEM_CONFIG_END }, { 0x03, MEM_RAM_START, MEM_RAM_END }, - { 0x04, MEM_USERID_START, MEM_USERID_END }, { 0xfd, MEM_USER0_START, MEM_USER0_END }, - { 0xfe, MEM_USER1_START, MEM_USER1_END }, { 0xff, MEM_USER2_START, MEM_USER2_END } }; }; diff --git a/src/vscp/common/vscp_client_canal.cpp b/src/vscp/common/vscp_client_canal.cpp index 3972b62df..34834253b 100644 --- a/src/vscp/common/vscp_client_canal.cpp +++ b/src/vscp/common/vscp_client_canal.cpp @@ -38,7 +38,16 @@ #include "vscp_client_canal.h" #include "vscphelper.h" -#include + + +//#include +#include // Needs C++11 -std=c++11 + +// for convenience +using json = nlohmann::json; +//using namespace kainjow::mustache; + +//#include #include // Forward declaration @@ -124,13 +133,13 @@ vscpClientCanal::initFromJson(const std::string &config) spdlog::error("CANAL CLIENT: JSON init: Name must be set."); return false; // Must be set } - spdlog::debug("CANAL CLIENT: JSON init: name={}.", j["name"]); + spdlog::debug("CANAL CLIENT: JSON init: name={}.", (std::string)j["name"]); if (!j["path"].is_string()) { spdlog::error("CANAL CLIENT: JSON init: Path must be set."); return false; // Must be set } - spdlog::debug("CANAL CLIENT: JSON init: path={}.", j["path"]); + spdlog::debug("CANAL CLIENT: JSON init: path={}.", (std::string)j["path"]); if (j.contains("config")) { if (!j["config"].is_string()) { @@ -141,7 +150,7 @@ vscpClientCanal::initFromJson(const std::string &config) else { j["config"] = ""; // Set default } - spdlog::debug("CANAL CLIENT: JSON init: config=\"{}\".", j["config"]); + spdlog::debug("CANAL CLIENT: JSON init: config=\"{}\".", (std::string)j["config"]); if (j.contains("flags")) { if (j["flags"].is_string()) { @@ -151,7 +160,7 @@ vscpClientCanal::initFromJson(const std::string &config) else { j["flags"] = 0; // Set default } - spdlog::debug("CANAL CLIENT: JSON init: flags={}.", j["flags"]); + spdlog::debug("CANAL CLIENT: JSON init: flags={}.", (uint32_t)j["flags"]); if (j.contains("datarate")) { if (j["datarate"].is_string()) { @@ -161,7 +170,7 @@ vscpClientCanal::initFromJson(const std::string &config) else { j["datarate"] = 0; // Set default } - spdlog::debug("CANAL CLIENT: JSON init: datarate={}.", j["datarate"]); + spdlog::debug("CANAL CLIENT: JSON init: datarate={}.", (int)j["datarate"]); setName(j["name"]); return (init(j["path"], j["config"], j["flags"], j["datarate"])); diff --git a/src/vscp/common/vscp_client_mqtt.cpp b/src/vscp/common/vscp_client_mqtt.cpp index db8304344..81f9698fa 100644 --- a/src/vscp/common/vscp_client_mqtt.cpp +++ b/src/vscp/common/vscp_client_mqtt.cpp @@ -52,11 +52,14 @@ #include #include +#include + #include -using namespace kainjow::mustache; +#include -#include -#include +// for convenience +using json = nlohmann::json; +using namespace kainjow::mustache; // Forward declaration static void * @@ -1291,7 +1294,9 @@ vscpClientMqtt::initFromJson(const std::string &config) if (j.contains("user-escapes") && j["user-escapes"].is_object()) { for (auto it = j["user-escapes"].begin(); it != j["user-escapes"].end(); ++it) { m_mapUserEscapes[it.key()] = it.value(); - spdlog::debug("MQTT CLIENT: json mqtt init: 'user-escapes' Set to {0}={1}.", it.key(), it.value()); + spdlog::debug("MQTT CLIENT: json mqtt init: 'user-escapes' Set to {0}={1}.", + (std::string) it.key(), + (std::string) it.value()); } } @@ -1376,7 +1381,9 @@ vscpClientMqtt::initFromJson(const std::string &config) if (jj.contains("user-properties") && jj["user-properties"].is_object()) { for (auto it = jj.begin(); it != jj.end(); ++it) { m_mapMqttProperties[it.key()] = it.value(); - spdlog::debug("MQTT CLIENT: json mqtt init: v5 'user-properties' Set to {0}={1}.", it.key(), it.value()); + spdlog::debug("MQTT CLIENT: json mqtt init: v5 'user-properties' Set to {0}={1}.", + (std::string) it.key(), + (std::string) it.value()); } } } @@ -1419,21 +1426,21 @@ vscpClientMqtt::handleMessage(const struct mosquitto_message *pmsg) // Get subscribe format for subscribe topic for (std::list::const_iterator it = m_mqtt_subscribeTopicList.begin(); - it != m_mqtt_subscribeTopicList.end(); - ++it) { + it != m_mqtt_subscribeTopicList.end(); + ++it) { - subscribeTopic *psubscribe = (*it); - // if topics match - if (!strstr(psubscribe->getTopic().c_str(), pmsg->topic)) { - format = psubscribe->getFormat(); - break; - } + subscribeTopic *psubscribe = (*it); + // if topics match + if (!strstr(psubscribe->getTopic().c_str(), pmsg->topic)) { + format = psubscribe->getFormat(); + break; } + } // If autofmt the payload must be checked to find the correct format // top convert MQTT msg to VSCP event if (autofmt == format) { - + // Topic is nill we need to find format // If First char of payload... diff --git a/src/vscp/common/vscpcanaldeviceif.cpp b/src/vscp/common/vscpcanaldeviceif.cpp index e8cbf02fb..0d34b2345 100644 --- a/src/vscp/common/vscpcanaldeviceif.cpp +++ b/src/vscp/common/vscpcanaldeviceif.cpp @@ -493,7 +493,7 @@ VscpCanalDeviceIf::init(std::string strpath, m_strPath = strpath; m_strParameter = strparam; m_deviceFlags = flags; - m_bAsync = m_bAsync; + m_bAsync = bAsync; return init(); } diff --git a/src/vscp/common/vscphelper.cpp b/src/vscp/common/vscphelper.cpp index 1758670bb..06e793610 100644 --- a/src/vscp/common/vscphelper.cpp +++ b/src/vscp/common/vscphelper.cpp @@ -58,12 +58,11 @@ #endif #include -#include // Needs C++11 -std=c++11 +#include #include #include #include -//#include #include #include #include @@ -7376,76 +7375,7 @@ vscp_getHashPasswordComponents(uint8_t *pSalt, uint8_t *pHash, const std::string return true; } -//////////////////////////////////////////////////////////////////////////////// -// vscp_makePasswordHash -// -/* -bool -vscp_makePasswordHash(std::string &result, const std::string &password, uint8_t *pSalt) -{ - int i; - uint8_t salt[16]; - uint8_t buf[32]; - - result.clear(); - - // Get random IV - if (nullptr == pSalt) { - if (16 != getRandomIV(salt, 16)) { - return false; - } - } - else { - memcpy(salt, pSalt, 16); - } - - uint8_t *p = new uint8_t[strlen((const char *) password.c_str())]; - if (nullptr == p) { - return false; - } - - memcpy(p, (const char *) password.c_str(), strlen((const char *) password.c_str())); - fastpbkdf2_hmac_sha256(p, strlen((const char *) password.c_str()), salt, 16, 70000, buf, 32); - delete[] p; - - for (i = 0; i < 16; i++) { - result += vscp_str_format("%02X", salt[i]); - } - result += (";"); - for (i = 0; i < 32; i++) { - result += vscp_str_format("%02X", buf[i]); - } - - return true; -} -*/ - -//////////////////////////////////////////////////////////////////////////////// -// vscp_isPasswordValid -// - -// bool -// vscp_isPasswordValid(const std::string &stored_pw, const std::string &password) -// { -// std::string calcHash; // Calculated hash -// uint8_t salt[16]; // Stored salt -// uint8_t hash[32]; // Stored hash - -// if (!vscp_getHashPasswordComponents(salt, hash, stored_pw)) { -// return false; -// } - -// if (!vscp_makePasswordHash(calcHash, password, salt)) { -// return false; -// } - -// if (stored_pw != calcHash) { -// return false; -// } - -// return true; -// } /////////////////////////////////////////////////////////////////////////////// // vscp_getSalt diff --git a/src/vscp/common/vscphelper.h b/src/vscp/common/vscphelper.h index 0e71149a1..71f2b6321 100644 --- a/src/vscp/common/vscphelper.h +++ b/src/vscp/common/vscphelper.h @@ -1823,7 +1823,7 @@ vscp_convertEventToCanal(canalMsg *pcanalMsg, const vscpEvent *pvscpEvent, uint8 /*! Covert VSCP event to CANAL message - /*! + Convert VSCP event to a CANAL message @param pcanalMsg Pointer to CANAL message that get result @param pvscpEventEx Pointer to VSCP event ex that should be converted @@ -2221,28 +2221,6 @@ vscp_hexStr2ByteArray(uint8_t *array, size_t size, const char *hexstr); bool vscp_getHashPasswordComponents(uint8_t *pSalt, uint8_t *pHash, const std::string &stored_pw); -/*! - * Make password hash with prepended salt from clear text password. - * - * @param result Will get hex hash string with random salt prepended - * separated with ";". - * @param password Clear text password to be hashed. - * @return true on success, false otherwise. - */ -//bool -//vscp_makePasswordHash(std::string &result, const std::string &password, uint8_t *pSalt = NULL); - -/*! - * Validate password - * - * @param stored_pw Stored password on the form "salt;hash" - * @param password Password to test (clear text). - * @return true on success, false otherwise. - */ - -//bool -//vscp_isPasswordValid(const std::string &stored_pw, const std::string &password); - /*! * Get salt * diff --git a/src/vscp/common/vscpremotetcpif.cpp b/src/vscp/common/vscpremotetcpif.cpp index a5666ae1d..394928277 100644 --- a/src/vscp/common/vscpremotetcpif.cpp +++ b/src/vscp/common/vscpremotetcpif.cpp @@ -657,11 +657,6 @@ VscpRemoteTcpIf::doCmdSendLevel1(const canalMsg *pCanalMsg) event.GUID[0] = pCanalMsg->id & 0xff; - // Protect event.data for out ouf bounce access - if (sizeof(event.data) < pCanalMsg->sizeData) { - return VSCP_ERROR_PARAMETER; - } - event.sizeData = pCanalMsg->sizeData; memcpy(event.data, pCanalMsg->data, pCanalMsg->sizeData); @@ -2120,7 +2115,7 @@ VscpRemoteTcpIf::readLevel2Registers(uint32_t reg, while (CANAL_ERROR_SUCCESS == doCmdReceiveEx(&e)) { // Valid event // Quit if done? - if ((allRcvValue == (receive_flags & 0xffffffff))) break; + if (allRcvValue == (receive_flags & 0xffffffff)) break; // Check for correct reply event #ifdef DEBUG_LIB_VSCP_HELPER