From bcf0997d35aec671af77f070fd4ca9fc1c777dff Mon Sep 17 00:00:00 2001 From: John Date: Sat, 5 Feb 2022 12:52:00 +0100 Subject: [PATCH] comments, optimized --- src/lib/ebus/message.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 504e2078..5a952c67 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -2164,11 +2164,15 @@ result_t MessageMap::readConditions(const string& filename, string* types, strin bool MessageMap::extractDefaultsFromFilename(const string& filename, map* defaults, symbol_t* destAddress, unsigned int* software, unsigned int* hardware) const { + // check filename to match (glob style with optionals in brackets): ZZ.[ID.][*.][CIRCUIT.[?.]][*.][HW????.][*.][SW????.][*.]csv + // ZZ is the address, ID is the 5 char identifier (reduced by trailing 0 one by one for finding a match), CIRCUIT is + // the optional circuit name, ? behind the circuit name is the circuit number suffix (when having more than one of these), + // ???? behind HW is the hardware version, ???? behind SW is the software version string ident, circuit, suffix; unsigned int sw = UINT_MAX, hw = UINT_MAX; string remain = filename; if (remain.length() > 4 && remain.substr(remain.length()-4) == ".csv") { - remain = remain.substr(0, remain.length()-3); // including trailing "." + remain = remain.substr(0, remain.length()-3); // keep trailing "." } size_t pos = remain.find('.'); if (pos != 2) { @@ -2185,8 +2189,8 @@ bool MessageMap::extractDefaultsFromFilename(const string& filename, map 1) { - pos = remain.rfind(".SW"); // check for ".SWxxxx." - if (pos != string::npos && remain.find(".", pos+1) == pos+7) { + pos = remain.rfind(".SW"); // check for ".SWxxxx." from the end + if (pos != string::npos && remain.find('.', pos+1) == pos+7) { sw = parseInt(remain.substr(pos+3, 4).c_str(), 10, 0, 9999, &result); if (result != RESULT_OK) { return false; // invalid "SWxxxx" @@ -2198,8 +2202,8 @@ bool MessageMap::extractDefaultsFromFilename(const string& filename, map 1) { - pos = remain.rfind(".HW"); // check for ".HWxxxx." - if (pos != string::npos && remain.find(".", pos+1) == pos+7) { + pos = remain.rfind(".HW"); // check for ".HWxxxx." from the end + if (pos != string::npos && remain.find('.', pos+1) == pos+7) { hw = parseInt(remain.substr(pos+3, 4).c_str(), 10, 0, 9999, &result); if (result != RESULT_OK) { return false; // invalid "HWxxxx"