introduced symbol_t, added SymbolString::dataAt() and ::isMaster(), renamed SymbolString::getDataStr() to getStr(), use size_t/ssize_t where appropriate, simplified by use of new SymbolString methods, corrected broadcast scan conversion, use override declaration

This commit is contained in:
john30
2017-03-04 14:01:20 +01:00
parent dfa0e6e08f
commit 18fc12499b
25 changed files with 806 additions and 862 deletions
+10 -13
View File
@@ -564,22 +564,20 @@ int main() {
ostringstream output;
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
result = writeMstr.parseHex(mstr.getStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
result = writeSstr.parseHex(sstr.getStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
result = fields->read(mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
result = fields->read(sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
!output.str().empty());
}
if (failedRead) {
@@ -602,9 +600,9 @@ int main() {
if (verbosity == 0) {
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
result = fields->write(input, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
result = fields->write(input, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
@@ -621,9 +619,8 @@ int main() {
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr() + " "
+ sstr.getDataStr(), writeMstr.getDataStr() + " "
+ writeSstr.getDataStr());
verify(failedWriteMatch, "write", expectStr, match, mstr.getStr() + " " + sstr.getStr(),
writeMstr.getStr() + " " + writeSstr.getStr());
}
}
delete fields;
+1 -1
View File
@@ -39,7 +39,7 @@ int main() {
int count = 0;
while (1) {
unsigned char byte = 0;
symbol_t byte = 0;
result = device->recv(0, byte);
if (result == RESULT_OK) {
+2 -3
View File
@@ -399,7 +399,7 @@ int main() {
if (message->isPassive() || decode) {
ostringstream output;
for (unsigned char index = 0; index < message->getCount(); index++) {
for (size_t index = 0; index < message->getCount(); index++) {
message->storeLastData(*mstrs[index], *sstrs[index]);
}
if (withMessageDump && !decodeJson) {
@@ -438,8 +438,7 @@ int main() {
cout << " \"" << inputStr << "\": prepare OK" << endl;
bool match = writeMstr == *mstrs[0];
verify(failedPrepareMatch, "prepare", inputStr, match, mstrs[0]->getDataStr(),
writeMstr.getDataStr());
verify(failedPrepareMatch, "prepare", inputStr, match, mstrs[0]->getStr(), writeMstr.getStr());
}
}
+5 -5
View File
@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
} else {
unsigned char gotCrc = mstr.calcCrc();
symbol_t gotCrc = mstr.calcCrc();
cout << "calculated CRC: 0x"
<< nouppercase << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(gotCrc) << endl;
@@ -73,9 +73,9 @@ int main(int argc, char** argv) {
cout << "parse unescaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = mstr.calcCrc(), expectCrc = 0x77;
symbol_t gotCrc = mstr.calcCrc(), expectCrc = 0x77;
ostringstream ostr;
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
expectStr = ostr.str();
@@ -91,7 +91,7 @@ int main(int argc, char** argv) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse escaped", "10feb5050427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);
@@ -108,7 +108,7 @@ int main(int argc, char** argv) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(), expectStr = "0427a915aa";
gotStr = sstr.getStr(), expectStr = "0427a915aa";
verify(false, "parse escaped", "0427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);