solved some TODOs

This commit is contained in:
john30
2016-01-06 13:37:35 +01:00
parent 93b83c5fa5
commit 4fec638b78
3 changed files with 16 additions and 14 deletions
+7 -8
View File
@@ -367,7 +367,7 @@ result_t SingleDataField::create(const char* typeNameStr, const unsigned char le
const PartType partType, int divisor, map<unsigned int, string> values, const PartType partType, int divisor, map<unsigned int, string> values,
SingleDataField* &returnField) SingleDataField* &returnField)
{ {
for (size_t i = 0; i < sizeof(dataTypes) / sizeof(dataType_t); i++) { // TODO use a map for (size_t i = 0; i < sizeof(dataTypes) / sizeof(dataType_t); i++) {
const dataType_t* dataType = &dataTypes[i]; const dataType_t* dataType = &dataTypes[i];
if (strcasecmp(typeNameStr, dataType->name) != 0) if (strcasecmp(typeNameStr, dataType->name) != 0)
continue; continue;
@@ -748,8 +748,8 @@ result_t StringDataField::writeSymbols(istringstream& input,
return RESULT_OK; return RESULT_OK;
} }
result_t result; result_t result;
size_t i = 0; size_t i = 0, offset;
for (size_t offset = start; i < count; offset += incr, i++) { for (offset = start; i < count; offset += incr, i++) {
switch (m_dataType.type) switch (m_dataType.type)
{ {
case bt_hexstr: case bt_hexstr:
@@ -856,10 +856,9 @@ result_t StringDataField::writeSymbols(istringstream& input,
} }
break; break;
} }
if (remainder && input.eof() && i > 0) { if (remainder && input.eof() && i > 0)
count = (offset-start)*incr;
break; break;
}
lastLast = last; lastLast = last;
last = value; last = value;
if ((m_dataType.flags & BCD) != 0 && ((m_dataType.flags & REQ) != 0 || value != m_dataType.replacement)) { if ((m_dataType.flags & BCD) != 0 && ((m_dataType.flags & REQ) != 0 || value != m_dataType.replacement)) {
@@ -872,10 +871,10 @@ result_t StringDataField::writeSymbols(istringstream& input,
output[baseOffset + offset] = (unsigned char)value; output[baseOffset + offset] = (unsigned char)value;
} }
if (!remainder && i < m_length) // TODO check with bt_tim and m_length == 1 if (!remainder && i < count)
return RESULT_ERR_EOF; // input too short return RESULT_ERR_EOF; // input too short
if (length!=NULL) if (length!=NULL)
*length = (unsigned char)count; *length = (unsigned char)((offset-start)*incr);
return RESULT_OK; return RESULT_OK;
} }
+4 -4
View File
@@ -733,7 +733,8 @@ ChainedMessage::ChainedMessage(const string circuit, const string name,
: Message(circuit, name, isWrite, false, comment, : Message(circuit, name, isWrite, false, comment,
srcAddress, dstAddress, id, srcAddress, dstAddress, id,
data, deleteData, pollPriority, condition), data, deleteData, pollPriority, condition),
m_ids(ids), m_lengths(lengths) m_ids(ids), m_lengths(lengths),
m_maxTimeDiff(m_ids.size()*15) // 15 seconds per message
{ {
size_t cnt = ids.size(); size_t cnt = ids.size();
m_lastMasterDatas = (SymbolString**)calloc(cnt, sizeof(SymbolString*)); m_lastMasterDatas = (SymbolString**)calloc(cnt, sizeof(SymbolString*));
@@ -807,7 +808,7 @@ result_t ChainedMessage::prepareMasterPart(SymbolString& master, istringstream&
return RESULT_ERR_NOTFOUND; return RESULT_ERR_NOTFOUND;
SymbolString allData(false); SymbolString allData(false);
result_t result = m_data->write(input, pt_masterData, allData, 0, separator); // TODO cache this? result_t result = m_data->write(input, pt_masterData, allData, 0, separator);
if (result != RESULT_OK) if (result != RESULT_OK)
return result; return result;
size_t pos = 0, addData = 0; size_t pos = 0, addData = 0;
@@ -896,7 +897,7 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
if (m_lastSlaveUpdateTimes[index]>maxTime) { if (m_lastSlaveUpdateTimes[index]>maxTime) {
maxTime = m_lastSlaveUpdateTimes[index]; maxTime = m_lastSlaveUpdateTimes[index];
} }
if (minTime==0 || maxTime==0 || maxTime-minTime>30) {// TODO constant multiplied by number of messages if (minTime==0 || maxTime==0 || maxTime-minTime>m_maxTimeDiff) {
return RESULT_CONTINUE; return RESULT_CONTINUE;
} }
} }
@@ -904,7 +905,6 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
SymbolString master(false); SymbolString master(false);
SymbolString slave(false); SymbolString slave(false);
size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN
//getIdLength(); // TODO usually shorter than real ID, only use for external interface
for (index=0; index<m_ids.size(); index++) { for (index=0; index<m_ids.size(); index++) {
SymbolString* add = m_lastMasterDatas[index]; SymbolString* add = m_lastMasterDatas[index];
size_t end = 5+(*add)[4]; size_t end = 5+(*add)[4];
+5 -2
View File
@@ -589,10 +589,13 @@ protected:
private: private:
/** the primary, secondary, and optional further ID bytes for each part of the chain. */ /** the primary, secondary, and optional further ID bytes for each part of the chain. */
vector< vector<unsigned char> > m_ids; const vector< vector<unsigned char> > m_ids;
/** the data length for each part of the chain. */ /** the data length for each part of the chain. */
vector<unsigned char> m_lengths; const vector<unsigned char> m_lengths;
/** the maximum allowed time difference of any data pair. */
const time_t m_maxTimeDiff;
/** array of the last seen master datas. */ /** array of the last seen master datas. */
SymbolString** m_lastMasterDatas; SymbolString** m_lastMasterDatas;