clearly separate master/slave symbolstrings

This commit is contained in:
john30
2017-02-26 17:34:22 +01:00
parent 1a878694d2
commit cc59b32f0d
13 changed files with 297 additions and 218 deletions
+4 -4
View File
@@ -77,14 +77,14 @@ int main() {
string check[5] = checks[i];
istringstream isstr(check[0]);
string expectStr = check[1];
SymbolString mstr(true);
MasterSymbolString mstr;
result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
SymbolString sstr;
SlaveSymbolString sstr;
result = sstr.parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
@@ -130,14 +130,14 @@ int main() {
cout << "\": create OK" << endl;
ostringstream output;
SymbolString writeMstr(true);
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
error = true;
}
SymbolString writeSstr;
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
+90 -71
View File
@@ -155,7 +155,7 @@ uint64_t Message::createKey(const vector<unsigned char> id,
return key;
}
uint64_t Message::createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination) {
uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLength, bool anyDestination) {
if (master.size() < 5) {
return INVALID_KEY;
}
@@ -532,7 +532,7 @@ bool Message::checkIdPrefix(vector<unsigned char>& id) {
return true;
}
bool Message::checkId(SymbolString& master, unsigned char* index) {
bool Message::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
return false;
@@ -590,7 +590,7 @@ bool Message::hasField(const char* fieldName, bool numeric) {
return m_data->hasField(fieldName, numeric);
}
result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& master,
result_t Message::prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
istringstream& input, char separator,
const unsigned char dstAddress, unsigned char index) {
if (m_isPassive) {
@@ -612,14 +612,15 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
if (result != RESULT_OK) {
return result;
}
result = storeLastData(pt_masterData, master, index);
result = storeLastData(master, index);
if (result < RESULT_OK) {
return result;
}
return RESULT_OK;
}
result_t Message::prepareMasterPart(SymbolString& master, istringstream& input, char separator, unsigned char index) {
result_t Message::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
if (index != 0) {
return RESULT_ERR_NOTFOUND;
}
@@ -636,7 +637,7 @@ result_t Message::prepareMasterPart(SymbolString& master, istringstream& input,
return result;
}
result_t Message::prepareSlave(istringstream& input, SymbolString& slave) {
result_t Message::prepareSlave(istringstream& input, SlaveSymbolString& slave) {
if (m_isWrite) {
return RESULT_ERR_INVALID_ARG; // prepare not possible
}
@@ -655,49 +656,59 @@ result_t Message::prepareSlave(istringstream& input, SymbolString& slave) {
return result;
}
result_t Message::storeLastData(SymbolString& master, SymbolString& slave) {
result_t result = storeLastData(pt_masterData, master, 0);
result_t Message::storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
result_t result = storeLastData(master, 0);
if (result >= RESULT_OK) {
result = storeLastData(pt_slaveData, slave, 0);
result = storeLastData(slave, 0);
}
return result;
}
result_t Message::storeLastData(const PartType partType, SymbolString& data, unsigned char index) {
result_t Message::storeLastData(MasterSymbolString& data, unsigned char index) {
if (data.size() > 0
&& (m_isWrite || this->m_dstAddress == BROADCAST || partType == pt_slaveData
|| (partType == pt_masterData && isMaster(this->m_dstAddress)))) {
&& (m_isWrite || this->m_dstAddress == BROADCAST || isMaster(this->m_dstAddress))) {
time(&m_lastUpdateTime);
}
if (partType == pt_masterData) {
switch (data.compareTo(m_lastMasterData)) {
case 1: // completely different
m_lastChangeTime = m_lastUpdateTime;
m_lastMasterData = data;
break;
case 2: // only master address is different
m_lastMasterData = data;
break;
}
} else if (partType == pt_slaveData) {
if (data != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = data;
}
switch (data.compareTo(m_lastMasterData)) {
case 1: // completely different
m_lastChangeTime = m_lastUpdateTime;
m_lastMasterData = data;
break;
case 2: // only master address is different
m_lastMasterData = data;
break;
}
return RESULT_OK;
}
result_t Message::decodeLastData(const PartType partType,
ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
unsigned char offset;
if (partType == pt_masterData) {
offset = (unsigned char)(m_id.size() - 2);
} else {
offset = 0;
result_t Message::storeLastData(SlaveSymbolString& data, unsigned char index) {
if (data.size() > 0) {
time(&m_lastUpdateTime);
}
result_t result = m_data->read(partType, partType == pt_masterData ? m_lastMasterData : m_lastSlaveData, offset,
if (data != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = data;
}
return RESULT_OK;
}
result_t Message::decodeLastMasterData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
unsigned char offset = (unsigned char)(m_id.size() - 2);
result_t result = m_data->read(pt_masterData, m_lastMasterData, offset,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
if (result == RESULT_EMPTY && fieldName != NULL) {
return RESULT_ERR_NOTFOUND;
}
return result;
}
result_t Message::decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
result_t result = m_data->read(pt_slaveData, m_lastSlaveData, 0,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
@@ -873,13 +884,13 @@ ChainedMessage::ChainedMessage(const string circuit, const string level, const s
m_ids(ids), m_lengths(lengths),
m_maxTimeDiff(m_ids.size()*15) { // 15 seconds per message
size_t cnt = ids.size();
m_lastMasterDatas = reinterpret_cast<SymbolString**>(calloc(cnt, sizeof(SymbolString*)));
m_lastSlaveDatas = reinterpret_cast<SymbolString**>(calloc(cnt, sizeof(SymbolString*)));
m_lastMasterDatas = reinterpret_cast<MasterSymbolString**>(calloc(cnt, sizeof(MasterSymbolString*)));
m_lastSlaveDatas = reinterpret_cast<SlaveSymbolString**>(calloc(cnt, sizeof(SlaveSymbolString*)));
m_lastMasterUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t)));
m_lastSlaveUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t)));
for (size_t index = 0; index < cnt; index++) {
m_lastMasterDatas[index] = new SymbolString(true);
m_lastSlaveDatas[index] = new SymbolString();
m_lastMasterDatas[index] = new MasterSymbolString;
m_lastSlaveDatas[index] = new SlaveSymbolString();
}
}
@@ -908,7 +919,7 @@ Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned c
return result;
}
bool ChainedMessage::checkId(SymbolString& master, unsigned char* index) {
bool ChainedMessage::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
return false;
@@ -969,13 +980,13 @@ bool ChainedMessage::checkId(Message& other) {
return false;
}
result_t ChainedMessage::prepareMasterPart(SymbolString& master, istringstream& input, char separator,
result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
size_t cnt = getCount();
if (index >= cnt) {
return RESULT_ERR_NOTFOUND;
}
SymbolString allData(true);
MasterSymbolString allData;
result_t result = m_data->write(input, pt_masterData, allData, 0, separator);
if (result != RESULT_OK) {
return result;
@@ -1007,42 +1018,50 @@ result_t ChainedMessage::prepareMasterPart(SymbolString& master, istringstream&
return result;
}
result_t ChainedMessage::storeLastData(SymbolString& master, SymbolString& slave) {
result_t ChainedMessage::storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
// determine index from master ID
unsigned char index = 0;
if (checkId(master, &index)) {
result_t result = storeLastData(pt_masterData, master, index);
result_t result = storeLastData(master, index);
if (result >= RESULT_OK) {
result = storeLastData(pt_slaveData, slave, index);
result = storeLastData(slave, index);
}
return result;
}
return RESULT_ERR_INVALID_ARG;
}
result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& data, unsigned char index) {
result_t ChainedMessage::storeLastData(MasterSymbolString& data, unsigned char index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
if (partType == pt_masterData) {
switch (data.compareTo(*m_lastMasterDatas[index])) {
case 1: // completely different
*m_lastMasterDatas[index] = data;
break;
case 2: // only master address is different
*m_lastMasterDatas[index] = data;
break;
}
time(&m_lastMasterUpdateTimes[index]);
} else if (partType == pt_slaveData) {
if (data != *m_lastSlaveDatas[index]) {
*m_lastSlaveDatas[index] = data;
}
time(&m_lastSlaveUpdateTimes[index]);
switch (data.compareTo(*m_lastMasterDatas[index])) {
case 1: // completely different
*m_lastMasterDatas[index] = data;
break;
case 2: // only master address is different
*m_lastMasterDatas[index] = data;
break;
}
time(&m_lastMasterUpdateTimes[index]);
return combineLastParts();
}
result_t ChainedMessage::storeLastData(SlaveSymbolString& data, unsigned char index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
if (data != *m_lastSlaveDatas[index]) {
*m_lastSlaveDatas[index] = data;
}
time(&m_lastSlaveUpdateTimes[index]);
return combineLastParts();
}
result_t ChainedMessage::combineLastParts() {
// check arrival time of all parts
time_t minTime = 0, maxTime = 0;
for (index = 0; index < m_ids.size(); index++) {
for (unsigned char index = 0; index < m_ids.size(); index++) {
if (index == 0) {
minTime = maxTime = m_lastMasterUpdateTimes[index];
} else {
@@ -1064,10 +1083,10 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
}
}
// everything was completely retrieved in short time
SymbolString master(true);
SymbolString slave;
MasterSymbolString master;
SlaveSymbolString slave;
size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN
for (index = 0; index < m_ids.size(); index++) {
for (unsigned char index = 0; index < m_ids.size(); index++) {
SymbolString* add = m_lastMasterDatas[index];
size_t end = 5+(*add)[4];
for (size_t pos = index == 0 ? 0 : offset; pos < end; pos++) {
@@ -1085,9 +1104,9 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
}
master[4] = (unsigned char)(master.size()-5);
slave[0] = (unsigned char)(slave.size()-1);
result_t result = Message::storeLastData(pt_masterData, master, 0);
result_t result = Message::storeLastData(master, 0);
if (result == RESULT_OK) {
result = Message::storeLastData(pt_slaveData, slave, 0);
result = Message::storeLastData(slave, 0);
}
return result;
}
@@ -1116,9 +1135,9 @@ void ChainedMessage::dumpColumn(ostream& output, column_t column, bool withCondi
/**
* Get the first available @a Message from the list.
* @param messages the list of @a Message instances to check.
* @param sameIdExtAs the optional @a Message to check for having the same ID.
* @param sameIdExtAs the optional @a MasterSymbolString to check for having the same ID.
*/
Message* getFirstAvailable(vector<Message*> &messages, SymbolString* sameIdExtAs) {
Message* getFirstAvailable(vector<Message*> &messages, MasterSymbolString* sameIdExtAs) {
for (vector<Message*>::iterator msgIt = messages.begin(); msgIt != messages.end(); msgIt++) {
Message* message = *msgIt;
if (sameIdExtAs && !message->checkId(*sameIdExtAs)) {
@@ -2034,7 +2053,7 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
return ret;
}
Message* MessageMap::find(SymbolString& master, bool anyDestination,
Message* MessageMap::find(MasterSymbolString& master, bool anyDestination,
const bool withRead, const bool withWrite, const bool withPassive) {
if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) {
return m_scanMessage;
+67 -40
View File
@@ -173,13 +173,13 @@ class Message {
const unsigned char srcAddress, const unsigned char dstAddress);
/**
* Calculate the key for the master @a SymbolString.
* @param master the master @a SymbolString.
* Calculate the key for the @a MasterSymbolString.
* @param master the @a MasterSymbolString.
* @param maxIdLength the maximum ID length to use
* @param anyDestination @p true to use the special @a SYN as destination address in the key.
* @return the key for the ID, or -1LL if the data is invalid.
*/
static uint64_t createKey(SymbolString& master,
static uint64_t createKey(MasterSymbolString& master,
unsigned char maxIdLength, bool anyDestination = false);
/**
@@ -349,11 +349,11 @@ class Message {
/**
* Check the ID against the master @a SymbolString data.
* @param master the master @a SymbolString to check against.
* @param master the @a MasterSymbolString to check against.
* @param index the variable in which to store the message part index, or NULL to ignore.
* @return true if the ID matches, false otherwise.
*/
virtual bool checkId(SymbolString& master, unsigned char* index = NULL);
virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
/**
* Check the ID against the other @a Message.
@@ -421,14 +421,14 @@ class Message {
/**
* Prepare the master @a SymbolString for sending a query or command to the bus.
* @param srcAddress the source address to set.
* @param master the master data @a SymbolString for writing symbols to.
* @param master the @a MasterSymbolString for writing symbols to.
* @param input the @a istringstream to parse the formatted value(s) from.
* @param separator the separator character between multiple fields.
* @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction.
* @param index the index of the part to prepare.
* @return @a RESULT_OK on success, or an error code.
*/
result_t prepareMaster(const unsigned char srcAddress, SymbolString& master,
result_t prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
istringstream& input, char separator = UI_FIELD_SEPARATOR,
const unsigned char dstAddress = SYN, unsigned char index = 0);
@@ -436,44 +436,51 @@ class Message {
protected:
/**
* Prepare a part of the master data @a SymbolString for sending (everything including NN).
* @param master the master data @a SymbolString for writing symbols to.
* @param master the @a MasterSymbolString for writing symbols to.
* @param input the @a istringstream to parse the formatted value(s) from.
* @param separator the separator character between multiple fields.
* @param index the index of the part to prepare.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t prepareMasterPart(SymbolString& master, istringstream& input, char separator, unsigned char index);
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
public:
/**
* Prepare the slave @a SymbolString for sending an answer to the bus.
* @param input the @a istringstream to parse the formatted value(s) from.
* @param slave the slave data @a SymbolString for writing symbols to.
* @param slave the @a SlaveSymbolString for writing symbols to.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t prepareSlave(istringstream& input, SymbolString& slave);
virtual result_t prepareSlave(istringstream& input, SlaveSymbolString& slave);
/**
* Store the last seen master and slave data.
* @param master the last seen master data.
* @param slave the last seen slave data.
* @param master the last seen @a MasterSymbolString.
* @param slave the last seen @a SlaveSymbolString.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(SymbolString& master, SymbolString& slave);
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
/**
* Store last seen master or slave data.
* @param partType the @a PartType of the data.
* @param data the last seen data.
* Store last seen master data.
* @param data the last @a MasterSymbolString.
* @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(const PartType partType, SymbolString& data, unsigned char index);
virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
/**
* Decode the value from the last stored data.
* @param partType the @a PartType of the data.
* Store last seen slave data.
* @param data the last seen @a SlaveSymbolString.
* @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
/**
* Decode the value from the last stored master data.
* @param output the @a ostringstream to append the formatted value to.
* @param outputFormat the @a OutputFormat options to use.
* @param leadingSeparator whether to prepend a separator before the formatted value.
@@ -481,8 +488,19 @@ class Message {
* @param fieldIndex the optional index of the named field to limit the output to, or -1.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastData(const PartType partType,
ostringstream& output, OutputFormat outputFormat = 0,
virtual result_t decodeLastMasterData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
/**
* Decode the value from the last stored slave data.
* @param output the @a ostringstream to append the formatted value to.
* @param outputFormat the @a OutputFormat options to use.
* @param leadingSeparator whether to prepend a separator before the formatted value.
* @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.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
/**
@@ -508,15 +526,15 @@ class Message {
/**
* Get the last seen master data.
* @return the last seen master @a SymbolString.
* @return the last seen @a MasterSymbolString.
*/
SymbolString& getLastMasterData() { return m_lastMasterData; }
MasterSymbolString& getLastMasterData() { return m_lastMasterData; }
/**
* Get the last seen slave data.
* @return the last seen slave @a SymbolString.
* @return the last seen @a SlaveSymbolString.
*/
SymbolString& getLastSlaveData() { return m_lastSlaveData; }
SlaveSymbolString& getLastSlaveData() { return m_lastSlaveData; }
/**
* Get the time when this message was last seen with reasonable data.
@@ -630,11 +648,11 @@ class Message {
/** the @a Condition for this message, or NULL. */
Condition* m_condition;
/** the last seen master data. */
SymbolString m_lastMasterData{true};
/** the last seen @a MasterSymbolString. */
MasterSymbolString m_lastMasterData;
/** the last seen slave data. */
SymbolString m_lastSlaveData;
/** the last seen @a SlaveSymbolString. */
SlaveSymbolString m_lastSlaveData;
/** the system time when the message was last updated, 0 for never. */
time_t m_lastUpdateTime;
@@ -691,7 +709,7 @@ class ChainedMessage : public Message {
virtual unsigned char getIdLength() const { return (unsigned char)(m_ids[0].size() - 2); }
// @copydoc
virtual bool checkId(SymbolString& master, unsigned char* index = NULL);
virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
// @copydoc
virtual bool checkId(Message& other);
@@ -702,16 +720,25 @@ class ChainedMessage : public Message {
protected:
// @copydoc
virtual result_t prepareMasterPart(SymbolString& master, istringstream& input, char separator, unsigned char index);
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
public:
// @copydoc
virtual result_t storeLastData(SymbolString& master, SymbolString& slave);
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
// @copydoc
virtual result_t storeLastData(const PartType partType, SymbolString& data, unsigned char index);
virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
// @copydoc
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
/**
* Combine all last stored data.
* @return the result code.
*/
virtual result_t combineLastParts();
protected:
// @copydoc
@@ -728,11 +755,11 @@ class ChainedMessage : public Message {
/** the maximum allowed time difference of any data pair. */
const time_t m_maxTimeDiff;
/** array of the last seen master datas. */
SymbolString** m_lastMasterDatas;
/** array of the last seen @a MasterSymbolString instances. */
MasterSymbolString** m_lastMasterDatas;
/** array of the last seen slave datas. */
SymbolString** m_lastSlaveDatas;
/** array of the last seen @a SlaveSymbolString instances. */
SlaveSymbolString** m_lastSlaveDatas;
/** array of the system times when the corresponding master data was last updated, 0 for never. */
time_t* m_lastMasterUpdateTimes;
@@ -1337,7 +1364,7 @@ class MessageMap : public FileReader {
/**
* Find the @a Message instance for the specified master data.
* @param master the master @a SymbolString for identifying the @a Message.
* @param master the @a MasterSymbolString for identifying the @a Message.
* @param anyDestination true to only return messages without a particular destination.
* @param withRead true to include read messages (default true).
* @param withWrite true to include write messages (default true).
@@ -1345,7 +1372,7 @@ class MessageMap : public FileReader {
* @return the @a Message instance, or NULL.
* Note: the caller may not free the returned instance.
*/
Message* find(SymbolString& master, bool anyDestination = false,
Message* find(MasterSymbolString& master, bool anyDestination = false,
const bool withRead = true, const bool withWrite = true, const bool withPassive = true);
/**
+26 -1
View File
@@ -113,13 +113,14 @@ int parseSignedInt(const char* str, int base, const int minValue, const int maxV
* A string of unescaped bus symbols.
*/
class SymbolString {
public:
protected:
/**
* Creates a new empty instance.
* @param isMaster whether this instance if for the master part.
*/
explicit SymbolString(const bool isMaster = false) { m_isMaster = isMaster; }
public:
/**
* Update the CRC by adding a value.
* @param crc the current CRC to update.
@@ -268,6 +269,30 @@ class SymbolString {
};
/**
* A string of unescaped master bus symbols.
*/
class MasterSymbolString : public SymbolString {
public:
/**
* Creates a new empty instance.
*/
MasterSymbolString() : SymbolString(true) {}
};
/**
* A string of unescaped slave bus symbols.
*/
class SlaveSymbolString : public SymbolString {
public:
/**
* Creates a new empty instance.
*/
SlaveSymbolString() : SymbolString(false) {}
};
/**
* Return whether the address is one of the 25 master addresses.
* @param addr the address to check.
+4 -4
View File
@@ -473,14 +473,14 @@ int main() {
string check[5] = checks[i];
istringstream isstr(check[0]);
string expectStr = check[1];
SymbolString mstr(true);
MasterSymbolString mstr;
result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
SymbolString sstr;
SlaveSymbolString sstr;
result = sstr.parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
@@ -563,14 +563,14 @@ int main() {
}
ostringstream output;
SymbolString writeMstr(true);
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
error = true;
}
SymbolString writeSstr;
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
+9 -9
View File
@@ -170,8 +170,8 @@ int main() {
map<string, Condition*> &conditions = messages->getConditions();
Message* message = NULL;
vector<Message*> deleteMessages;
vector<SymbolString*> mstrs;
vector<SymbolString*> sstrs;
vector<MasterSymbolString*> mstrs;
vector<SlaveSymbolString*> sstrs;
mstrs.resize(1);
sstrs.resize(1);
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
@@ -260,7 +260,7 @@ int main() {
} else if (mstrs[pos] != NULL) {
delete mstrs[pos];
}
mstrs[pos] = new SymbolString(true);
mstrs[pos] = new MasterSymbolString;
result = mstrs[pos]->parseHex(token);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl;
@@ -277,7 +277,7 @@ int main() {
} else if (sstrs[pos] != NULL) {
delete sstrs[pos];
}
sstrs[pos] = new SymbolString();
sstrs[pos] = new SlaveSymbolString();
result = sstrs[pos]->parseHex(token);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl;
@@ -292,7 +292,7 @@ int main() {
if (mstrs[0] != NULL) {
delete mstrs[0];
}
mstrs[0] = new SymbolString(true);
mstrs[0] = new MasterSymbolString;
result = mstrs[0]->parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
@@ -301,7 +301,7 @@ int main() {
if (sstrs[0] != NULL) {
delete sstrs[0];
}
sstrs[0] = new SymbolString();
sstrs[0] = new SlaveSymbolString();
result = sstrs[0]->parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
@@ -419,7 +419,7 @@ int main() {
}
if (!message->isPassive() && (withInput || !decode)) {
istringstream input(inputStr);
SymbolString writeMstr(true);
MasterSymbolString writeMstr;
result = message->prepareMaster(0xff, writeMstr, input);
if (failedPrepare) {
if (result == RESULT_OK) {
@@ -453,10 +453,10 @@ int main() {
delete templates;
delete messages;
for (vector<SymbolString*>::iterator it = mstrs.begin(); it != mstrs.end(); it++) {
for (vector<MasterSymbolString*>::iterator it = mstrs.begin(); it != mstrs.end(); it++) {
delete *it;
}
for (vector<SymbolString*>::iterator it = sstrs.begin(); it != sstrs.end(); it++) {
for (vector<SlaveSymbolString*>::iterator it = sstrs.begin(); it != sstrs.end(); it++) {
delete *it;
}
return 0;
+13 -13
View File
@@ -47,19 +47,19 @@ void verify(bool expectFailMatch, string type, string input,
}
int main(int argc, char** argv) {
SymbolString sstr(true);
MasterSymbolString mstr;
if (argc > 1) {
result_t result;
if (argc > 2 && strcmp("escaped", argv[1]) == 0) {
result = sstr.parseHexEscaped(argv[2]);
result = mstr.parseHexEscaped(argv[2]);
} else {
result = sstr.parseHex(argv[1]);
result = mstr.parseHex(argv[1]);
}
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
} else {
unsigned char gotCrc = sstr.calcCrc();
unsigned char gotCrc = mstr.calcCrc();
cout << "calculated CRC: 0x"
<< nouppercase << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(gotCrc) << endl;
@@ -68,14 +68,14 @@ int main(int argc, char** argv) {
}
string gotStr, expectStr;
result_t result = sstr.parseHex("10feb5050427a915aa");
result_t result = mstr.parseHex("10feb5050427a915aa");
if (result != RESULT_OK) {
cout << "parse unescaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = sstr.calcCrc(), expectCrc = 0x77;
unsigned char gotCrc = mstr.calcCrc(), expectCrc = 0x77;
ostringstream ostr;
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
expectStr = ostr.str();
@@ -85,24 +85,24 @@ int main(int argc, char** argv) {
verify(false, "CRC", "10feb5050427a915aa", gotCrc == expectCrc, expectStr, gotStr);
}
sstr.clear();
result = sstr.parseHexEscaped("10feb5050427a90015a901");
mstr.clear();
result = mstr.parseHexEscaped("10feb5050427a90015a901");
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse escaped", "10feb5050427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);
expectStr = ostr.str();
ostr.str("");
ostr << dec << static_cast<unsigned>(sstr.getDataSize());
ostr << dec << static_cast<unsigned>(mstr.getDataSize());
gotStr = ostr.str();
verify(false, "data size", "10feb5050427a90015a901", sstr.getDataSize() == 4, expectStr, gotStr);
verify(false, "data size", "10feb5050427a90015a901", mstr.getDataSize() == 4, expectStr, gotStr);
}
sstr = SymbolString(); // slave
SlaveSymbolString sstr;
result = sstr.parseHexEscaped("0427a90015a901");
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;