solved some TODOs, check hex input and message length, simplified SymbolString ctors, fixed extra newline in scan result, no longer include write messages in default find command types, append command type to find result in verbose mode, add source and/or destination to update log when not set in the message definition, documentation

This commit is contained in:
john30
2015-02-15 12:20:06 +01:00
parent 2de793784e
commit 71d8727d2d
9 changed files with 177 additions and 136 deletions
+34 -20
View File
@@ -85,6 +85,7 @@ bool PollRequest::notify(result_t result, SymbolString& slave)
result_t ScanRequest::prepare(unsigned char ownMasterAddress, unsigned char dstAddress)
{
istringstream input;
m_master.clear();
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, UI_FIELD_SEPARATOR, dstAddress);
if (result == RESULT_OK)
logInfo(lf_bus, "scan cmd: %s", m_master.getDataStr().c_str());
@@ -136,7 +137,7 @@ bool ActiveBusRequest::notify(result_t result, SymbolString& slave)
logNotice(lf_bus, "read res: %s", slave.getDataStr().c_str());
m_result = result;
m_slave = SymbolString(slave, false, false);
m_slave.addAll(slave);
return false;
}
@@ -145,12 +146,12 @@ bool ActiveBusRequest::notify(result_t result, SymbolString& slave)
result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
{
result_t result = RESULT_SYN;
ActiveBusRequest* request = new ActiveBusRequest(master, slave);
ActiveBusRequest request(master, slave);
for (int sendRetries=m_failedSendRetries+1; sendRetries>=0; sendRetries--) {
m_nextRequests.add(request);
bool success = m_finishedRequests.waitRemove(request);
result = success == true ? request->m_result : RESULT_ERR_TIMEOUT;
m_nextRequests.add(&request);
bool success = m_finishedRequests.waitRemove(&request);
result = success == true ? request.m_result : RESULT_ERR_TIMEOUT;
if (result == RESULT_OK)
break;
@@ -161,11 +162,9 @@ result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
}
logError(lf_bus, "%s, %s", getResultCode(result), sendRetries>0 ? "retry send" : "");
request->m_busLostRetries = 0;
request.m_busLostRetries = 0;
}
delete request;
return result;
}
@@ -255,7 +254,7 @@ result_t BusHandler::handleSymbol()
case bs_sendCmd:
if (m_currentRequest != NULL) {
sendSymbol = m_currentRequest->m_master[m_nextSendPos];
sendSymbol = m_currentRequest->m_master[m_nextSendPos]; // escaped command
sending = true;
}
break;
@@ -276,7 +275,7 @@ result_t BusHandler::handleSymbol()
case bs_sendRes:
if (m_currentRequest != NULL) {
sendSymbol = m_response[m_nextSendPos];
sendSymbol = m_response[m_nextSendPos]; // escaped response
sending = true;
}
break;
@@ -366,14 +365,14 @@ result_t BusHandler::handleSymbol()
case bs_recvCmd:
headerLen = 4;
crcPos = m_command.size() > headerLen ? headerLen + 1 + m_command[headerLen] : 0xff;
crcPos = m_command.size() > headerLen ? headerLen + 1 + m_command[headerLen] : 0xff; // header symbols are never escaped
result = m_command.push_back(recvSymbol, true, m_command.size() < crcPos);
if (result < RESULT_OK)
return setState(bs_skip, result);
if (result == RESULT_OK && crcPos != 0xff && m_command.size() == crcPos + 1) { // CRC received
unsigned char dstAddress = m_command[1];
m_commandCrcValid = m_command[headerLen + 1 + m_command[headerLen]] == m_command.getCRC();
m_commandCrcValid = m_command[headerLen + 1 + m_command[headerLen]] == m_command.getCRC(); // header symbols are never escaped
if (m_commandCrcValid) {
if (dstAddress == BROADCAST) {
receiveCompleted();
@@ -408,7 +407,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_sendSyn, RESULT_OK);
}
}
else if (isMaster(m_command[1]) == true) {
else if (isMaster(m_command[1]) == true) { // header symbols are never escaped
receiveCompleted();
return setState(bs_skip, RESULT_OK);
}
@@ -543,6 +542,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_skip, RESULT_ERR_INVALID_ARG); // don't know this request or definition has wrong direction, deny
// build response and store in m_response for sending back to requesting master
m_response.clear(true); // escape while sending response
result = message->prepareSlave(m_response);
if (result != RESULT_OK)
return setState(bs_skip, result);
@@ -608,7 +608,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
}
if (state == bs_noSignal) { // notify all requests
m_response.clear();
m_response.clear(false); // notify with empty response
while ((m_currentRequest = m_nextRequests.remove(false)) != NULL) {
bool restart = m_currentRequest->notify(RESULT_ERR_NO_SIGNAL, m_response);
if (restart == true) { // should not occur with no signal
@@ -640,7 +640,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
if (state == bs_ready || state == bs_skip) {
m_command.clear();
m_commandCrcValid = false;
m_response.clear();
m_response.clear(false); // unescape while receiving response
m_responseCrcValid = false;
m_nextSendPos = 0;
}
@@ -650,9 +650,9 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
void BusHandler::receiveCompleted()
{
unsigned char dstAddress = m_command[1];
unsigned char srcAddress = m_command[0], dstAddress = m_command[1];
bool master = isMaster(dstAddress);
m_seenAddresses[m_command[0]] = true;
m_seenAddresses[srcAddress] = true;
if (dstAddress == BROADCAST)
logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true) {
@@ -674,7 +674,15 @@ void BusHandler::receiveCompleted()
logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
else {
string data = output.str();
logNotice(lf_update, "update %s %s: %s", clazz.c_str(), name.c_str(), data.c_str());
if (message->getDstAddress() == SYN) { // any destination
if (message->getSrcAddress() == SYN) // any destination and any source
logNotice(lf_update, "update %s %s QQ=%2.2x ZZ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, dstAddress, data.c_str());
else
logNotice(lf_update, "update %s %s ZZ=%2.2x: %s", clazz.c_str(), name.c_str(), dstAddress, data.c_str());
} else if (message->getSrcAddress() == SYN) // any source
logNotice(lf_update, "update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str());
else
logNotice(lf_update, "update %s %s: %s", clazz.c_str(), name.c_str(), data.c_str());
}
}
else {
@@ -730,9 +738,15 @@ result_t BusHandler::startScan(bool full)
void BusHandler::formatScanResult(ostringstream& output)
{
bool first = true;
for (unsigned int slave=0; slave<=255; slave++) {
map<unsigned char, string>::iterator it = m_scanResults.find(slave);
if (it != m_scanResults.end())
output << it->second << endl;
if (it != m_scanResults.end()) {
if (first)
first = false;
else
output << endl;
output << it->second;
}
}
}
+10 -10
View File
@@ -79,7 +79,7 @@ public:
/**
* Constructor.
* @param master the master data @a SymbolString to send.
* @param master the escaped master data @a SymbolString to send.
* @param deleteOnFinish whether to automatically delete this @a BusRequest when finished.
*/
BusRequest(SymbolString& master, const bool deleteOnFinish)
@@ -101,7 +101,7 @@ public:
protected:
/** the master data @a SymbolString to send. */
/** the escaped master data @a SymbolString to send. */
SymbolString& m_master;
/** the number of times a send is repeated due to lost arbitration. */
@@ -145,7 +145,7 @@ public:
private:
/** the master data @a SymbolString. */
/** the escaped master data @a SymbolString. */
SymbolString m_master;
/** the associated @a Message. */
@@ -191,7 +191,7 @@ public:
private:
/** the master data @a SymbolString. */
/** the escaped master data @a SymbolString. */
SymbolString m_master;
/** the currently queried @a Message. */
@@ -216,7 +216,7 @@ public:
/**
* Constructor.
* @param master reference to the master data @a SymbolString to send.
* @param master the escaped master data @a SymbolString to send.
* @param slave reference to @a SymbolString for filling in the received slave data.
*/
ActiveBusRequest(SymbolString& master, SymbolString& slave)
@@ -274,7 +274,7 @@ public:
m_pollInterval(pollInterval), m_lastReceive(0), m_lastPoll(0),
m_currentRequest(NULL), m_nextSendPos(0),
m_state(bs_noSignal), m_repeat(false),
m_commandCrcValid(false), m_responseCrcValid(false),
m_command(false), m_commandCrcValid(false), m_response(false), m_responseCrcValid(false),
m_scanMessage(NULL) {
memset(m_seenAddresses, 0, sizeof(m_seenAddresses));
}
@@ -290,7 +290,7 @@ public:
/**
* Send a message on the bus and wait for the answer.
* @param master the @a SymbolString with the master data to send.
* @param master the escaped @a SymbolString with the master data to send.
* @param slave the @a SymbolString that will be filled with retrieved slave data.
* @return the result code.
*/
@@ -401,7 +401,7 @@ private:
WQueue<BusRequest*> m_finishedRequests;
/** the offset of the next symbol that needs to be sent from the command or response,
* (only relevant if m_request is set and state is bs_command or bs_response). */
* (only relevant if m_request is set and state is @a bs_command or @a bs_response). */
unsigned char m_nextSendPos;
/** the current @a BusState. */
@@ -410,13 +410,13 @@ private:
/** whether the current message part is being repeated. */
bool m_repeat;
/** the received/sent command. */
/** the unescaped received command. */
SymbolString m_command;
/** whether the command CRC is valid. */
bool m_commandCrcValid;
/** the received/sent response. */
/** the unescaped received response or escaped response to send. */
SymbolString m_response;
/** whether the response CRC is valid. */
+37 -18
View File
@@ -267,7 +267,7 @@ string MainLoop::executeRead(vector<string> &args)
return message->getLastValue();
} // else: read directly from bus
SymbolString master;
SymbolString master(true);
istringstream input;
result_t ret = message->prepareMaster(m_address, master, input);
if (ret != RESULT_OK) {
@@ -277,7 +277,7 @@ string MainLoop::executeRead(vector<string> &args)
logInfo(lf_main, "read cmd: %s", master.getDataStr().c_str());
// send message
SymbolString slave;
SymbolString slave(false);
ret = m_busHandler->sendAndWait(master, slave);
ostringstream result;
@@ -305,23 +305,33 @@ string MainLoop::executeWrite(vector<string> &args)
break;
}
ostringstream msg;
msg << hex << setw(2) << setfill('0') << static_cast<unsigned>(m_address) << setw(0);
while (argPos < args.size()) {
if ((args[argPos].length() % 2) != 0) {
return getResultCode(RESULT_ERR_INVALID_NUM);
}
msg << args[argPos++];
}
if (msg.str().size() < 4*2) // at least ZZ, PB, SB, NN
return getResultCode(RESULT_ERR_INVALID_ARG);
result_t ret;
unsigned int length = parseInt(msg.str().substr(3*2, 2).c_str(), 16, 0, 16, ret);
if (ret == RESULT_OK && (4+length)*2 != msg.str().size())
return getResultCode(RESULT_ERR_INVALID_ARG);
SymbolString master(msg.str());
if (isValidAddress(master[1]) == false)
return getResultCode(RESULT_ERR_INVALID_ADDR);
SymbolString master(true);
ret = master.push_back(m_address, false);
if (ret == RESULT_OK)
ret = master.parseHex(msg.str());
if (ret == RESULT_OK && isValidAddress(master[1]) == false)
ret = RESULT_ERR_INVALID_ADDR;
if (ret != RESULT_OK)
return getResultCode(ret);
logNotice(lf_main, "write hex cmd: %s", master.getDataStr().c_str());
// send message
SymbolString slave;
result_t ret = m_busHandler->sendAndWait(master, slave);
SymbolString slave(false);
ret = m_busHandler->sendAndWait(master, slave);
if (ret == RESULT_OK) {
if (master[1] == BROADCAST || isMaster(master[1]))
@@ -350,7 +360,7 @@ string MainLoop::executeWrite(vector<string> &args)
if (message == NULL)
return getResultCode(RESULT_ERR_NOTFOUND);
SymbolString master;
SymbolString master(true);
istringstream input(args[argPos + 2]);
result_t ret = message->prepareMaster(m_address, master, input);
if (ret != RESULT_OK) {
@@ -360,7 +370,7 @@ string MainLoop::executeWrite(vector<string> &args)
logInfo(lf_main, "write cmd: %s", master.getDataStr().c_str());
// send message
SymbolString slave;
SymbolString slave(false);
ret = m_busHandler->sendAndWait(master, slave);
ostringstream result;
@@ -382,7 +392,7 @@ string MainLoop::executeWrite(vector<string> &args)
string MainLoop::executeFind(vector<string> &args)
{
size_t argPos = 1;
bool verbose = false, withRead = true, withWrite = true, withPassive = true, first = true, onlyWithData = false;
bool verbose = false, withRead = true, withWrite = false, withPassive = true, first = true, onlyWithData = false;
string clazz;
while (args.size() > argPos && args[argPos][0] == '-') {
if (args[argPos] == "-v")
@@ -429,9 +439,9 @@ string MainLoop::executeFind(vector<string> &args)
return "usage: 'find [-v] [-r] [-w] [-p] [-d] [-c CLASS] [NAME]'\n"
" Find value(s).\n"
" -v be verbose (append destination address and update time)\n"
" -r limit to active read messages (default all types)\n"
" -w limit to active write messages (default all types)\n"
" -p limit to passive messages (default all types)\n"
" -r limit to active read messages (default read + passive)\n"
" -w limit to active write messages (default read + passive)\n"
" -p limit to passive messages (default read + passive)\n"
" -d only retrieve messages with actual data"
" -c CLASS limit to messages of CLASS\n"
" NAME the NAME of the message to find or a part thereof";
@@ -444,7 +454,7 @@ string MainLoop::executeFind(vector<string> &args)
bool found = false;
ostringstream result;
char str[34];
char str[31];
for (deque<Message*>::iterator it = messages.begin(); it < messages.end();) {
Message* message = *it++;
unsigned char dstAddress = message->getDstAddress();
@@ -462,14 +472,23 @@ string MainLoop::executeFind(vector<string> &args)
result << message->getLastValue();
if (verbose == true) {
if (lastup == 0)
sprintf(str, "ZZ=%02x", dstAddress);
sprintf(str, "%02x", dstAddress);
else {
struct tm* td = localtime(&lastup);
sprintf(str, "ZZ=%02x, lastup=%04d-%02d-%02d %02d:%02d:%02d",
sprintf(str, "%02x, lastup=%04d-%02d-%02d %02d:%02d:%02d",
dstAddress, td->tm_year+1900, td->tm_mon+1, td->tm_mday,
td->tm_hour, td->tm_min, td->tm_sec);
}
result << " [" << str << "]";
result << " [ZZ=" << str;
if (message->isPassive())
result << ", passive";
else
result << ", active";
if (message->isWrite())
result << " write]";
else
result << " read]";
}
found = true;
}
+4 -4
View File
@@ -252,7 +252,7 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
if (m_isPassive == true)
return RESULT_ERR_INVALID_ARG; // prepare not possible
SymbolString master;
SymbolString master(false);
result_t result = master.push_back(srcAddress, false, false);
if (result != RESULT_OK)
return result;
@@ -283,7 +283,7 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
result = m_data->write(input, pt_masterData, master, m_id.size() - 2, separator);
if (result != RESULT_OK)
return result;
masterData = SymbolString(master, true);
masterData.addAll(master);
return result;
}
@@ -292,7 +292,7 @@ result_t Message::prepareSlave(SymbolString& slaveData)
if (m_isPassive == false || m_isWrite == true)
return RESULT_ERR_INVALID_ARG; // prepare not possible
SymbolString slave;
SymbolString slave(false);
unsigned char addData = m_data->getLength(pt_slaveData);
result_t result = slave.push_back(addData, false, false);
if (result != RESULT_OK)
@@ -301,7 +301,7 @@ result_t Message::prepareSlave(SymbolString& slaveData)
result = m_data->write(input, pt_slaveData, slave, 0);
if (result != RESULT_OK)
return result;
slaveData = SymbolString(slave, true);
slaveData.addAll(slave);
return result;
}
+22 -24
View File
@@ -48,37 +48,35 @@ static const unsigned char CRC_LOOKUP_TABLE[] =
};
SymbolString::SymbolString(const string& str) //TODO use a factory method instead
: m_unescapeState(0), m_crc(0)
void SymbolString::addAll(const SymbolString& str)
{
// parse + escape
for (size_t i = 0; i+1 < str.size(); i += 2) {
unsigned long value = strtoul(str.substr(i, 2).c_str(), NULL, 16); // TODO check
push_back((unsigned char)value, false, true);
bool addCrc = m_unescapeState == 0;
bool isEscaped = str.m_unescapeState == 0;
vector<unsigned char> data = str.m_data;
for (size_t i = 0; i < data.size(); i++) {
push_back(data[i], isEscaped, addCrc);
}
// add CRC + escape
push_back(m_crc, false, false);
if (addCrc)
push_back(m_crc, false, false); // add CRC
}
SymbolString::SymbolString(const SymbolString& str, const bool escape, const bool addCrc)
: m_unescapeState(escape == true ? 0 : 1), m_crc(0)
result_t SymbolString::parseHex(const string& str, const bool isEscaped)
{
for (size_t i = 0; i < str.size(); i++) {
push_back(str[i], str.m_unescapeState == 0, true);
}
if (addCrc == true)
// add CRC
push_back(m_crc, false, false);
}
bool addCrc = m_unescapeState == 0;
for (size_t i = 0; i < str.size(); i += 2) {
char* strEnd = NULL;
const char* strBegin = str.substr(i, 2).c_str();
unsigned int value = strtoul(strBegin, &strEnd, 16);
SymbolString::SymbolString(const string& str, bool isEscaped)
: m_unescapeState(1), m_crc(0)
{
// parse + optionally unescape
for (size_t i = 0; i+1 < str.size(); i += 2) {
unsigned long value = strtoul(str.substr(i, 2).c_str(), NULL, 16); // TODO check
push_back((unsigned char)value, isEscaped, false);
if (strEnd == NULL || *strEnd != 0 || strEnd != strBegin+2 || value > 0xff)
return RESULT_ERR_INVALID_NUM; // invalid value
push_back((unsigned char)value, isEscaped, addCrc);
}
if (addCrc)
push_back(m_crc, false, false); // add CRC
return RESULT_OK;
}
const string SymbolString::getDataStr(const bool unescape)
+22 -46
View File
@@ -45,30 +45,24 @@ class SymbolString
public:
/**
* Creates a new unescaped empty instance.
* Creates a new empty escaped or unescaped instance.
* @param escaped whether to create an escaped instance.
*/
SymbolString() : m_unescapeState(1), m_crc(0) {}
SymbolString(const bool escaped=true) : m_unescapeState(escaped == true ? 0 : 1), m_crc(0) {}
/**
* Creates a new escaped instance from an unescaped hex string and adds the calculated CRC.
* @param str the unescaped hex string.
* Add all symbols from the other @a SymbolString and the calculated CRC if escaped.
* @param str the @a SymbolString to copy from.
*/
SymbolString(const string& str);
void addAll(const SymbolString& str);
/**
* Creates a new escaped or unescaped instance from another @a SymbolString and adds the calculated CRC.
* @param str the @a SymbolString top copy from.
* @param escape true for an escaped instance, false for an unescaped instance.
* @param addCrc whether to add the calculated CRC as last symbol.
* Parse the escaped or unescaped hex @a string, add all symbols, and add the calculated CRC if escaped.
* @param str the hex @a string.
* @param isEscaped whether the hex string is escaped.
* @return @a RESULT_OK on success, or an error code.
*/
SymbolString(const SymbolString& str, const bool escape, const bool addCrc=true);
/**
* Creates a new unescaped instance from a hex string.
* @param isEscaped whether the hex string is escaped and shall be unescaped.
* @param str the hex string.
*/
SymbolString(const string& str, const bool isEscaped);
result_t parseHex(const string& str, const bool isEscaped=false);
/**
* Returns the symbols as hex string.
@@ -84,32 +78,12 @@ public:
*/
unsigned char& operator[](const size_t index) { if (index >= m_data.size()) m_data.resize(index+1, 0); return m_data[index]; }
/**
* Returns the symbol at the specified index.
* @param index the index of the symbol to return.
* @return the symbol at the specified index.
*/
const unsigned char& operator[](const size_t index) const { return m_data[index]; }
/**
* Returns whether this instance is equal to the other instance.
* @param other the other instance.
* @return true if this instance is equal to the other instance (i.e. both escaped or both unescaped and same symbols).
*/
bool operator==(SymbolString& other) {
return m_unescapeState==other.m_unescapeState && m_data==other.m_data;
/*bool ret = m_unescapeState==other.m_unescapeState && m_data==other.m_data;
for (int i=0; i<m_data.size(); i++) {
cout<<setw(2)<<setfill('0')<<hex<<static_cast<unsigned>(m_data[i])<<" ";
}
cout<<"["<<static_cast<unsigned>(m_unescapeState)<<"]";
cout<<(ret?" == ":" != ");
for (int i=0; i<other.m_data.size(); i++) {
cout<<setw(2)<<setfill('0')<<hex<<static_cast<unsigned>(other.m_data[i])<<" ";
}
cout<<"["<<static_cast<unsigned>(other.m_unescapeState)<<"]"<<endl;
return ret;*/
}
bool operator==(SymbolString& other) { return m_unescapeState==other.m_unescapeState && m_data==other.m_data; }
/**
* Appends a the symbol to the end of the symbol string and escapes/unescapes it if necessary.
@@ -135,10 +109,16 @@ public:
unsigned char getCRC() const { return m_crc; }
/**
* Clears the symbols.
* Clear the symbols.
*/
void clear() { m_data.clear(); m_unescapeState = m_unescapeState==0 ? 0 : 1; m_crc = 0; }
/**
* Clear the symbols and adjust the escape mode.
* @param escape true to set to an escaped instance, false to set to an unescaped instance.
*/
void clear(const bool escape) { m_data.clear(); m_unescapeState = escape ? 0 : 1; m_crc = 0; }
private:
/**
@@ -149,14 +129,12 @@ private:
: m_data(str.m_data), m_unescapeState(str.m_unescapeState), m_crc(str.m_crc) {}
/**
* Updates the calculated CRC in @a m_crc by adding a value.
* Update the calculated CRC in @a m_crc by adding a value.
* @param value the (escaped) value to add to the calculated CRC in @a m_crc.
*/
void addCRC(const unsigned char value);
/**
* the string of bus symbols.
*/
/** the string of bus symbols. */
vector<unsigned char> m_data;
/**
@@ -166,9 +144,7 @@ private:
*/
int m_unescapeState;
/**
* the calculated CRC.
*/
/** the calculated CRC. */
unsigned char m_crc;
};
+23 -5
View File
@@ -215,8 +215,18 @@ int main()
string check[5] = checks[i];
istringstream isstr(check[0]);
string expectStr = check[1];
SymbolString mstr(check[2], false);
SymbolString sstr(check[3], false);
SymbolString mstr(false);
result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
continue;
}
SymbolString sstr(false);
result = sstr.parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
continue;
}
string flags = check[4];
bool isSet = flags.find('s') != string::npos;
bool failedCreate = flags.find('c') != string::npos;
@@ -237,7 +247,7 @@ int main()
fields = NULL;
}
vector<string>::iterator it = entries.begin();
result_t result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]);
result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]);
if (failedCreate == true) {
if (result == RESULT_OK)
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
@@ -272,8 +282,16 @@ int main()
}
ostringstream output;
SymbolString writeMstr(mstr.getDataStr().substr(0, 10), false);
SymbolString writeSstr(sstr.getDataStr().substr(0, 2), false);
SymbolString writeMstr(false);
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl;
}
SymbolString writeSstr(false);
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
}
result = fields->read(pt_masterData, mstr, 0, output, false, verbose);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, output.str().empty() == false, verbose);
+12 -3
View File
@@ -74,8 +74,18 @@ int main()
string check[5] = checks[i];
istringstream isstr(check[0]);
string inputStr = check[1];
SymbolString mstr(check[2]);
SymbolString sstr(check[3]);
SymbolString mstr(true);
result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
continue;
}
SymbolString sstr(true);
result = sstr.parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
continue;
}
string flags = check[4];
bool isTemplate = flags == "t";
bool dontMap = flags.find('m') != string::npos;
@@ -94,7 +104,6 @@ int main()
delete deleteMessage;
deleteMessage = NULL;
}
result_t result;
if (isTemplate == true) {
// store new template
DataField* fields = NULL;
+13 -6
View File
@@ -25,14 +25,18 @@ using namespace std;
int main ()
{
SymbolString sstr("10feb5050427a915aa");
SymbolString sstr(true);
result_t result = sstr.parseHex("10feb5050427a915aa", false);
if (result != RESULT_OK)
std::cout << "parse escaped error: " << getResultCode(result) << std::endl;
std::string gotStr = sstr.getDataStr(false), expectStr = "10feb5050427a90015a90177";
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
std::cout << "ctor escaped OK" << std::endl;
std::cout << "parse escaped OK" << std::endl;
else
std::cout << "ctor escaped error: got " << gotStr << ", expected "
std::cout << "parse escaped error: got " << gotStr << ", expected "
<< expectStr << std::endl;
unsigned char gotCrc = sstr.getCRC(), expectCrc = 0x77;
@@ -55,14 +59,17 @@ int main ()
std::cout << "unescape error: got " << gotStr << ", expected "
<< expectStr << std::endl;
sstr = SymbolString("10feb5050427a90015a90177", true);
sstr = SymbolString(false);
result = sstr.parseHex("10feb5050427a90015a90177", true);
if (result != RESULT_OK)
std::cout << "parse unescaped error: " << getResultCode(result) << std::endl;
gotStr = sstr.getDataStr();
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
std::cout << "ctor unescaped OK" << std::endl;
std::cout << "parse unescaped OK" << std::endl;
else
std::cout << "ctor unescaped error: got " << gotStr << ", expected "
std::cout << "parse unescaped error: got " << gotStr << ", expected "
<< expectStr << std::endl;
return 0;