solved todo: cache symbols instead of decoded values, use cache for verbose and field-selective read as well, include names and comments in verbose find

This commit is contained in:
john30
2015-03-07 14:07:58 +01:00
parent e81ac863ad
commit 6740a6376b
5 changed files with 116 additions and 59 deletions
+4 -3
View File
@@ -1288,14 +1288,15 @@ result_t DataFieldSet::read(const PartType partType,
}
}
if (findFieldIndex && !found)
return RESULT_ERR_NOTFOUND;
if (!found) {
return RESULT_EMPTY;
}
if (verbose) {
if (m_comment.length() > 0)
output << " [" << m_comment << "]";
}
return found ? RESULT_OK : RESULT_EMPTY;
return RESULT_OK;
}
result_t DataFieldSet::write(istringstream& input,
+56 -14
View File
@@ -289,6 +289,10 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
result = m_data->write(input, pt_masterData, master, (unsigned char)(m_id.size() - 2), separator);
if (result != RESULT_OK)
return result;
if (master != m_lastMasterData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastMasterData = master;
}
masterData.addAll(master);
return result;
}
@@ -307,6 +311,11 @@ result_t Message::prepareSlave(SymbolString& slaveData)
result = m_data->write(input, pt_slaveData, slave, 0);
if (result != RESULT_OK)
return result;
time(&m_lastUpdateTime);
if (slave != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = slave;
}
slaveData.addAll(slave);
return result;
}
@@ -321,16 +330,24 @@ result_t Message::decode(const PartType partType, SymbolString& data,
offset = (unsigned char)(m_id.size() - 2);
else
offset = 0;
size_t startPos = output.str().length();
result_t result = m_data->read(partType, data, offset, output, leadingSeparator, verbose, fieldName, fieldIndex, separator);
if (result < RESULT_OK) {
if (result < RESULT_OK)
return result;
}
if (result == RESULT_EMPTY)
return RESULT_ERR_NOTFOUND;
time(&m_lastUpdateTime);
string value = output.str().substr(startPos);
if (value != m_lastValue)
m_lastChangeTime = m_lastUpdateTime;
m_lastValue = value;
if (partType == pt_masterData) {
if (data != m_lastMasterData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastMasterData = data;
}
} else if (partType == pt_slaveData) {
if (data != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = data;
}
}
return RESULT_OK;
}
@@ -341,23 +358,48 @@ result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
unsigned char offset = (unsigned char)(m_id.size() - 2);
size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, masterData, offset, output, leadingSeparator, verbose, NULL, -1, separator);
if (result < RESULT_OK) {
if (result < RESULT_OK)
return result;
}
bool empty = result==RESULT_EMPTY;
offset = 0;
leadingSeparator = output.str().length() > startPos;
result = m_data->read(pt_slaveData, slaveData, offset, output, leadingSeparator, verbose, NULL, -1, separator);
if (result < RESULT_OK) {
if (result < RESULT_OK)
return result;
}
if (empty && result == RESULT_EMPTY)
return RESULT_ERR_NOTFOUND;
time(&m_lastUpdateTime);
string value = output.str().substr(startPos);
if (value != m_lastValue)
if (masterData != m_lastMasterData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastValue = value;
m_lastMasterData = masterData;
}
if (slaveData != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = slaveData;
}
return RESULT_OK;
}
result_t Message::decodeLastData(ostringstream& output,
bool verbose, const char* fieldName, signed char fieldIndex,
char separator)
{
bool leadingSeparator = false;
unsigned char offset = (unsigned char)(m_id.size() - 2);
size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, m_lastMasterData, offset, output, leadingSeparator, verbose, fieldName, fieldIndex, separator);
if (result < RESULT_OK)
return result;
bool empty = result==RESULT_EMPTY;
offset = 0;
leadingSeparator = output.str().length() > startPos;
result = m_data->read(pt_slaveData, m_lastSlaveData, offset, output, leadingSeparator, verbose, fieldName, fieldIndex, separator);
if (empty && result == RESULT_EMPTY)
return RESULT_ERR_NOTFOUND;
return result;
}
bool Message::isLessPollWeight(const Message* other)
{
unsigned int tw = m_pollPriority * m_pollCount;
+16 -5
View File
@@ -209,10 +209,18 @@ public:
bool verbose=false, char separator=UI_FIELD_SEPARATOR);
/**
* Get the last decoded value.
* @return the last decoded value, or the empty string if it was not successful.
* Decode the value from the last stored data.
* @param output the @a ostringstream to append the formatted value to.
* @param verbose whether to prepend the name, append the unit (if present), and append
* the comment in square brackets (if present).
* @param fieldName the optional name of a field to limit the output to.
* @param fieldIndex the optional index of the named field to limit the output to, or -1.
* @param separator the separator character between multiple fields.
* @return @a RESULT_OK on success, or an error code.
*/
string getLastValue() { return m_lastValue; }
result_t decodeLastData(ostringstream& output,
bool verbose=false, const char* fieldName=NULL, signed char fieldIndex=-1,
char separator=UI_FIELD_SEPARATOR);
/**
* Get the time when @a m_lastValue was last stored.
@@ -281,8 +289,11 @@ private:
/** the priority for polling, or 0 for no polling at all. */
const unsigned char m_pollPriority;
/** the last decoded value. */
string m_lastValue;
/** the last seen master data. */
SymbolString m_lastMasterData;
/** the last seen slave data. */
SymbolString m_lastSlaveData;
/** the system time when @a m_lastValue was last stored, 0 for never. */
time_t m_lastUpdateTime;
+2 -1
View File
@@ -46,7 +46,7 @@ int main()
// message= [type];class;name;[comment];[QQ];ZZ;PBSB;fields...
// field= name;[pos];type[;[divisor|values][;[unit][;[comment]]]]
string checks[][5] = {
// "message", "flags"
// "message", "decoded", "master", "slave", "flags"
{"date,HDA:3,,,Datum", "", "", "", "t"},
{"time,VTI,,,", "", "", "", "t"},
{"dcfstate,UCH,0=nosignal;1=ok;2=sync;3=valid,,", "", "", "", "t"},
@@ -56,6 +56,7 @@ int main()
{"sensor,UCH,0=ok;85=circuit;170=cutoff,,Fühlerstatus", "", "", "", "t"},
{"tempsensor,temp;sensor", "", "", "", "t"},
{"u,,first,,,fe,0700,,x,,bda", "26.10.2014", "fffe07000426100614", "00", "p"},
{"u,broadcast,hwStatus,,,fe,b505,27,,,UCH,,,,,,UCH,,,,,,UCH,,,", "0;19;0", "10feb505042700130097", "00", ""},
{"w,,first,,,15,b509,0400,date,,bda", "26.10.2014", "ff15b50906040026100614", "00", "m"},
{"r,ehp,time,,,08,b509,0d2800,,,time", "15:00:17", "ff08b509030d2800", "0311000f", "md"},
{"r,ehp,date,,,08,b509,0d2900,,,date", "23.11.2014", "ff08b509030d2900", "03170b0e", "md"},