diff --git a/src/address.cc b/src/address.cc index e6384c0..4115dbc 100644 --- a/src/address.cc +++ b/src/address.cc @@ -23,6 +23,11 @@ using namespace std; vector splitSequenceOfAddressExpressionsAtCommas(const string& mes); +bool isValidMatchExpression(const std::string& s, bool *has_wildcard); +bool doesIdMatchExpression(const std::string& id, std::string match_rule); +bool doesAddressMatchExpressions(Address &address, + std::vector& address_expressions, + bool *used_wildcard); bool isValidMatchExpression(const string& s, bool *has_wildcard) { @@ -180,180 +185,6 @@ bool hasWildCard(const string& mes) return mes.find('*') != string::npos; } -bool doesIdsMatchExpressionss(vector &ids, vector& mes, bool *used_wildcard) -{ - bool match = false; - for (string &id : ids) - { - if (doesIdMatchExpressionss(id, mes, used_wildcard)) - { - match = true; - } - // Go through all ids even though there is an early match. - // This way we can see if theres an exact match later. - } - return match; -} - -bool doesIdMatchExpressionss(const string& id, vector& mes, bool *used_wildcard) -{ - bool found_match = false; - bool found_negative_match = false; - bool exact_match = false; - *used_wildcard = false; - - // Goes through all possible match expressions. - // If no expression matches, neither positive nor negative, - // then the result is false. (ie no match) - - // If more than one positive match is found, and no negative, - // then the result is true. - - // If more than one negative match is found, irrespective - // if there is any positive matches or not, then the result is false. - - // If a positive match is found, using a wildcard not any exact match, - // then *used_wildcard is set to true. - - for (string me : mes) - { - bool has_wildcard = hasWildCard(me); - bool is_negative_rule = (me.length() > 0 && me.front() == '!'); - if (is_negative_rule) - { - me.erase(0, 1); - } - - bool m = doesIdMatchExpression(id, me); - - if (is_negative_rule) - { - if (m) found_negative_match = true; - } - else - { - if (m) - { - found_match = true; - if (!has_wildcard) - { - exact_match = true; - } - } - } - } - - if (found_negative_match) - { - return false; - } - if (found_match) - { - if (exact_match) - { - *used_wildcard = false; - } - else - { - *used_wildcard = true; - } - return true; - } - return false; -} - -bool doesIdMatchAddressExpressions(const string& id, vector& aes, bool *used_wildcard) -{ -/* bool found_match = false; - bool found_negative_match = false; - bool exact_match = false;*/ - *used_wildcard = false; - - // Goes through all possible match expressions. - // If no expression matches, neither positive nor negative, - // then the result is false. (ie no match) - - // If more than one positive match is found, and no negative, - // then the result is true. - - // If more than one negative match is found, irrespective - // if there is any positive matches or not, then the result is false. - - // If a positive match is found, using a wildcard not any exact match, - // then *used_wildcard is set to true. -/* - for (AddressExpression &ae : aes) - { - bool has_wildcard = ae.has_wildcard; - bool is_negative_rule = (me.length() > 0 && me.front() == '!'); - if (is_negative_rule) - { - me.erase(0, 1); - } - - bool m = doesIdMatchExpression(id, me); - - if (is_negative_rule) - { - if (m) found_negative_match = true; - } - else - { - if (m) - { - found_match = true; - if (!has_wildcard) - { - exact_match = true; - } - } - } - } - - if (found_negative_match) - { - return false; - } - if (found_match) - { - if (exact_match) - { - *used_wildcard = false; - } - else - { - *used_wildcard = true; - } - return true; - } -*/ - return false; -} - -string toIdsCommaSeparated(vector &ids) -{ - string cs; - for (string& s: ids) - { - cs += s; - cs += ","; - } - if (cs.length() > 0) cs.pop_back(); - return cs; -} - -string toIdsCommaSeparated(vector &ids) -{ - string cs; - for (AddressExpression& ae: ids) - { - cs += ae.str(); - cs += ","; - } - if (cs.length() > 0) cs.pop_back(); - return cs; -} - bool AddressExpression::match(const std::string &i, uint16_t m, uchar v, uchar t) { if (!(mfct == 0xffff || mfct == m)) return false; diff --git a/src/address.h b/src/address.h index 6aed8f7..a2de586 100644 --- a/src/address.h +++ b/src/address.h @@ -77,33 +77,11 @@ struct AddressExpression !*.V=33 */ bool isValidSequenceOfAddressExpressions(const std::string& s); - -bool isValidMatchExpression(const std::string& s, bool *has_wildcard); - - -bool doesIdMatchExpression(const std::string& id, - std::string match_rule); -bool doesIdMatchExpressionss(const std::string& id, - std::vector& match_rules, - bool *used_wildcard); -bool doesIdsMatchExpressionss(std::vector &ids, - std::vector& match_rules, - bool *used_wildcard); -std::string toIdsCommaSeparated(std::vector &ids); -std::string toIdsCommaSeparated(std::vector &ids); - std::vector splitAddressExpressions(const std::string &aes); - bool flagToManufacturer(const char *s, uint16_t *out_mfct); - std::string manufacturerFlag(int m_field); - bool doesTelegramMatchExpressions(std::vector
&addresses, std::vector& address_expressions, bool *used_wildcard); -bool doesAddressMatchExpressions(Address &address, - std::vector& address_expressions, - bool *used_wildcard); - #endif diff --git a/wmbusmeters.1 b/wmbusmeters.1 index 0a2fab0..bb3c176 100644 --- a/wmbusmeters.1 +++ b/wmbusmeters.1 @@ -176,7 +176,7 @@ and the other set to beta. Alfa has an antenna tuned for 433M, beta has an anten .TP \fBmeter_type\fR for example multical21:t1 (suffix means that we expect this meter to transmit t1 telegrams) the driver auto can be used, but is not recommended for production. .TP -\fBmeter_id\fR one or more 8 digit numbers separated with commas, a single '*' wildcard, or a prefix '76543*' with wildcard. +\fBmeter_id\fR one or more addresses separated with commas, a single '*' wildcard, or a prefix '76543*' with wildcard. You can as a suffix fully or partially specify manufacturer, version and type: 12345678.M=KAM.V=1b.T=16 You can use p0 to p250 to specify an mbus primary address. .TP \fBmeter_key\fR a unique key for the meter, if meter telegrams are not encrypted, you must supply an empty key: ""