made SymbolString master/slave aware and contain only unescaped data, moved CRC tracking and escpaing/enscaping to BusHandler, moved parseInt/parseSignedInt from datatype.h to symbol.h, added new error code for retrival of unexpted symbol after a send to the bus

This commit is contained in:
john30
2017-02-26 16:31:32 +01:00
parent 5087ece9a4
commit 1a878694d2
17 changed files with 586 additions and 565 deletions
+42 -15
View File
@@ -50,26 +50,32 @@ int main(int argc, char** argv) {
SymbolString sstr(true);
if (argc > 1) {
result_t result = sstr.parseHex(argv[1], true);
result_t result;
if (argc > 2 && strcmp("escaped", argv[1]) == 0) {
result = sstr.parseHexEscaped(argv[2]);
} else {
result = sstr.parseHex(argv[1]);
}
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
} else {
unsigned char gotCrc = sstr.getCRC();
unsigned char gotCrc = sstr.calcCrc();
cout << "calculated CRC: 0x"
<< nouppercase << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(gotCrc) << endl;
}
return 0;
}
string gotStr, expectStr;
result_t result = sstr.parseHex("10feb5050427a915aa", false);
result_t result = sstr.parseHex("10feb5050427a915aa");
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
cout << "parse unescaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(false, false), expectStr = "10feb5050427a90015a90177";
verify(false, "parse escaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = sstr.getCRC(), expectCrc = 0x77;
gotStr = sstr.getDataStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = sstr.calcCrc(), expectCrc = 0x77;
ostringstream ostr;
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
expectStr = ostr.str();
@@ -77,19 +83,40 @@ int main(int argc, char** argv) {
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(gotCrc);
gotStr = ostr.str();
verify(false, "CRC", "10feb5050427a915aa", gotCrc == expectCrc, expectStr, gotStr);
gotStr = sstr.getDataStr(true, false), expectStr = "10feb5050427a915aa77";
verify(false, "unescape", "10feb5050427a915aa", true, expectStr, gotStr);
}
sstr = SymbolString(false);
result = sstr.parseHex("10feb5050427a90015a90177", true);
sstr.clear();
result = sstr.parseHexEscaped("10feb5050427a90015a901");
if (result != RESULT_OK) {
cout << "parse unescaped error: " << getResultCode(result) << endl;
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(true, false), expectStr = "10feb5050427a915aa77";
verify(false, "parse unescaped", "10feb5050427a90015a90177", true, expectStr, gotStr);
gotStr = sstr.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());
gotStr = ostr.str();
verify(false, "data size", "10feb5050427a90015a901", sstr.getDataSize() == 4, expectStr, gotStr);
}
sstr = SymbolString(); // slave
result = sstr.parseHexEscaped("0427a90015a901");
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(), expectStr = "0427a915aa";
verify(false, "parse escaped", "0427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);
expectStr = ostr.str();
ostr.str("");
ostr << dec << static_cast<unsigned>(sstr.getDataSize());
gotStr = ostr.str();
verify(false, "data size", "0427a90015a901", sstr.getDataSize() == 4, expectStr, gotStr);
}
return error ? 1 : 0;