fixed parsing of inline conditions (numeric ranges and single numeric values)
This commit is contained in:
+48
-26
@@ -1007,27 +1007,33 @@ result_t splitValues(string valueList, vector<unsigned int>& valueRanges)
|
|||||||
result_t result;
|
result_t result;
|
||||||
while (getline(stream, str, VALUE_SEPARATOR)) {
|
while (getline(stream, str, VALUE_SEPARATOR)) {
|
||||||
FileReader::trim(str);
|
FileReader::trim(str);
|
||||||
if (str.length()==0)
|
if (str.length()==0) {
|
||||||
return RESULT_ERR_INVALID_ARG;
|
return RESULT_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
bool upto = str[0]=='<';
|
bool upto = str[0]=='<';
|
||||||
if (upto || str[0]=='>') {
|
if (upto || str[0]=='>') {
|
||||||
if (str.length()==1)
|
if (str.length()==1) {
|
||||||
return RESULT_ERR_INVALID_ARG;
|
return RESULT_ERR_INVALID_ARG;
|
||||||
if (upto)
|
}
|
||||||
|
if (upto) {
|
||||||
valueRanges.push_back(0);
|
valueRanges.push_back(0);
|
||||||
|
}
|
||||||
bool inclusive = str[1]=='=';
|
bool inclusive = str[1]=='=';
|
||||||
unsigned int val = parseInt(str.substr(inclusive?2:1).c_str(), 10, inclusive?0:1, inclusive?UINT_MAX:(UINT_MAX-1), result);
|
unsigned int val = parseInt(str.substr(inclusive?2:1).c_str(), 10, inclusive?0:1, inclusive?UINT_MAX:(UINT_MAX-1), result);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
valueRanges.push_back(inclusive ? val : (val+(upto?-1:1)));
|
valueRanges.push_back(inclusive ? val : (val+(upto?-1:1)));
|
||||||
if (!upto)
|
if (!upto) {
|
||||||
valueRanges.push_back(UINT_MAX);
|
valueRanges.push_back(UINT_MAX);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
size_t pos = str.find('-');
|
size_t pos = str.find('-');
|
||||||
if (pos>0) { // range
|
if (pos!=string::npos && pos>0) { // range
|
||||||
unsigned int val = parseInt(str.substr(0, pos).c_str(), 10, 0, UINT_MAX, result);
|
unsigned int val = parseInt(str.substr(0, pos).c_str(), 10, 0, UINT_MAX, result);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
valueRanges.push_back(val);
|
valueRanges.push_back(val);
|
||||||
pos++;
|
pos++;
|
||||||
} else { // single value
|
} else { // single value
|
||||||
@@ -1037,8 +1043,9 @@ result_t splitValues(string valueList, vector<unsigned int>& valueRanges)
|
|||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK)
|
||||||
return result;
|
return result;
|
||||||
valueRanges.push_back(val);
|
valueRanges.push_back(val);
|
||||||
if (pos==0)
|
if (pos==0) {
|
||||||
valueRanges.push_back(val); // single value
|
valueRanges.push_back(val); // single value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
@@ -1049,24 +1056,29 @@ result_t Condition::create(const string condName, vector<string>::iterator& it,
|
|||||||
// name,circuit,messagename,[comment],[fieldname],[ZZ],values (name already skipped by caller)
|
// name,circuit,messagename,[comment],[fieldname],[ZZ],values (name already skipped by caller)
|
||||||
string circuit = it==end ? "" : *(it++); // circuit
|
string circuit = it==end ? "" : *(it++); // circuit
|
||||||
string name = it==end ? "" : *(it++); // messagename
|
string name = it==end ? "" : *(it++); // messagename
|
||||||
if (it<end)
|
if (it<end) {
|
||||||
it++; // comment
|
it++; // comment
|
||||||
|
}
|
||||||
string field = it==end ? "" : *(it++); // fieldname
|
string field = it==end ? "" : *(it++); // fieldname
|
||||||
string zz = it==end ? "" : *(it++); // ZZ
|
string zz = it==end ? "" : *(it++); // ZZ
|
||||||
unsigned char dstAddress = SYN;
|
unsigned char dstAddress = SYN;
|
||||||
result_t result = RESULT_OK;
|
result_t result = RESULT_OK;
|
||||||
if (zz.length()==0)
|
if (zz.length()==0) {
|
||||||
zz = defaultDest;
|
zz = defaultDest;
|
||||||
|
}
|
||||||
if (zz.length()>0) {
|
if (zz.length()>0) {
|
||||||
dstAddress = (unsigned char)parseInt(zz.c_str(), 16, 0, 0xff, result);
|
dstAddress = (unsigned char)parseInt(zz.c_str(), 16, 0, 0xff, result);
|
||||||
if (result != RESULT_OK)
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
if (dstAddress!=SYN && !isValidAddress(dstAddress, false))
|
}
|
||||||
|
if (dstAddress!=SYN && !isValidAddress(dstAddress, false)) {
|
||||||
return RESULT_ERR_INVALID_ADDR;
|
return RESULT_ERR_INVALID_ADDR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (name.length()==0) {
|
if (name.length()==0) {
|
||||||
if (!isValidAddress(dstAddress, false) || isMaster(dstAddress))
|
if (!isValidAddress(dstAddress, false) || isMaster(dstAddress)) {
|
||||||
return RESULT_ERR_INVALID_ADDR;
|
return RESULT_ERR_INVALID_ADDR;
|
||||||
|
}
|
||||||
} else if (circuit.length()==0) {
|
} else if (circuit.length()==0) {
|
||||||
circuit = defaultCircuit;
|
circuit = defaultCircuit;
|
||||||
}
|
}
|
||||||
@@ -1079,44 +1091,50 @@ result_t Condition::create(const string condName, vector<string>::iterator& it,
|
|||||||
// strings
|
// strings
|
||||||
vector<string> values;
|
vector<string> values;
|
||||||
result = splitValues(valueList, values);
|
result = splitValues(valueList, values);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
returnValue = new SimpleStringCondition(condName, circuit, name, dstAddress, field, values);
|
returnValue = new SimpleStringCondition(condName, circuit, name, dstAddress, field, values);
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
// numbers
|
// numbers
|
||||||
vector<unsigned int> valueRanges;
|
vector<unsigned int> valueRanges;
|
||||||
result = splitValues(valueList, valueRanges);
|
result = splitValues(valueList, valueRanges);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
returnValue = new SimpleNumericCondition(condName, circuit, name, dstAddress, field, valueRanges);
|
returnValue = new SimpleNumericCondition(condName, circuit, name, dstAddress, field, valueRanges);
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleCondition* SimpleCondition::derive(string valueList)
|
SimpleCondition* SimpleCondition::derive(string valueList)
|
||||||
{
|
{
|
||||||
if (valueList.empty())
|
if (valueList.empty()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
string name = m_condName+valueList;
|
string name = m_condName+valueList;
|
||||||
if (valueList[0]=='=')
|
if (valueList[0]=='=') {
|
||||||
valueList.erase(0);
|
valueList.erase(0, 1);
|
||||||
|
}
|
||||||
result_t result;
|
result_t result;
|
||||||
if (valueList[0]=='\'') {
|
if (valueList[0]=='\'') {
|
||||||
// strings
|
// strings
|
||||||
vector<string> values;
|
vector<string> values;
|
||||||
result = splitValues(valueList, values);
|
result = splitValues(valueList, values);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return new SimpleStringCondition(name, m_circuit, m_name, m_dstAddress, m_field, values);
|
return new SimpleStringCondition(name, m_circuit, m_name, m_dstAddress, m_field, values);
|
||||||
}
|
}
|
||||||
// numbers
|
// numbers
|
||||||
if (!isNumeric())
|
if (!isNumeric()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
vector<unsigned int> valueRanges;
|
vector<unsigned int> valueRanges;
|
||||||
result = splitValues(valueList, valueRanges);
|
result = splitValues(valueList, valueRanges);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return new SimpleNumericCondition(name, m_circuit, m_name, m_dstAddress, m_field, valueRanges);
|
return new SimpleNumericCondition(name, m_circuit, m_name, m_dstAddress, m_field, valueRanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1134,16 +1152,18 @@ CombinedCondition* SimpleCondition::combineAnd(Condition* other)
|
|||||||
|
|
||||||
result_t SimpleCondition::resolve(MessageMap* messages, ostringstream& errorMessage)
|
result_t SimpleCondition::resolve(MessageMap* messages, ostringstream& errorMessage)
|
||||||
{
|
{
|
||||||
if (m_message!=NULL)
|
if (m_message!=NULL) {
|
||||||
return RESULT_OK; // already resolved
|
return RESULT_OK; // already resolved
|
||||||
|
}
|
||||||
Message* message;
|
Message* message;
|
||||||
if (m_name.length()==0) {
|
if (m_name.length()==0) {
|
||||||
message = messages->getScanMessage(m_dstAddress);
|
message = messages->getScanMessage(m_dstAddress);
|
||||||
errorMessage << "scan condition " << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(m_dstAddress);
|
errorMessage << "scan condition " << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(m_dstAddress);
|
||||||
} else {
|
} else {
|
||||||
message = messages->find(m_circuit, m_name, false);
|
message = messages->find(m_circuit, m_name, false);
|
||||||
if (!message)
|
if (!message) {
|
||||||
message = messages->find(m_circuit, m_name, false, true);
|
message = messages->find(m_circuit, m_name, false, true);
|
||||||
|
}
|
||||||
errorMessage << "condition " << m_circuit << " " << m_name;
|
errorMessage << "condition " << m_circuit << " " << m_name;
|
||||||
}
|
}
|
||||||
if (!message) {
|
if (!message) {
|
||||||
@@ -1182,15 +1202,17 @@ result_t SimpleCondition::resolve(MessageMap* messages, ostringstream& errorMess
|
|||||||
}
|
}
|
||||||
m_message = message;
|
m_message = message;
|
||||||
message->setUsedByCondition();
|
message->setUsedByCondition();
|
||||||
if (m_name.length()>0)
|
if (m_name.length()>0) {
|
||||||
messages->addPollMessage(message, true);
|
messages->addPollMessage(message, true);
|
||||||
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleCondition::isTrue()
|
bool SimpleCondition::isTrue()
|
||||||
{
|
{
|
||||||
if (!m_message)
|
if (!m_message) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (m_message->getLastChangeTime()>m_lastCheckTime) {
|
if (m_message->getLastChangeTime()>m_lastCheckTime) {
|
||||||
bool isTrue = !m_hasValues; // for message seen check
|
bool isTrue = !m_hasValues; // for message seen check
|
||||||
if (!isTrue) {
|
if (!isTrue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user