added option "-n" to read command for retrieving name/value pairs in numeric form, added numeric and verbose options to json, use null for unset values or replacement in json, allow passing raw value when writing name/value pairs, fix for numeric parsing of empty string

This commit is contained in:
john30
2015-06-04 13:04:38 +02:00
parent 1a87c46fde
commit 294c953c99
6 changed files with 125 additions and 113 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
if (result == RESULT_OK) { if (result == RESULT_OK) {
if (!append) if (!append)
scanResult << hex << setw(2) << setfill('0') << static_cast<unsigned>(dstAddress) << UI_FIELD_SEPARATOR; scanResult << hex << setw(2) << setfill('0') << static_cast<unsigned>(dstAddress) << UI_FIELD_SEPARATOR;
result = m_message->decode(pt_slaveData, slave, scanResult, append); // decode data result = m_message->decode(pt_slaveData, slave, scanResult, 0, append); // decode data
} }
if (result < RESULT_OK) { if (result < RESULT_OK) {
logError(lf_bus, "scan %2.2x failed: %s", dstAddress, getResultCode(result)); logError(lf_bus, "scan %2.2x failed: %s", dstAddress, getResultCode(result));
+20 -16
View File
@@ -253,7 +253,7 @@ result_t MainLoop::readFromBus(Message* message, SymbolString& master, string in
string MainLoop::executeRead(vector<string> &args) string MainLoop::executeRead(vector<string> &args)
{ {
size_t argPos = 1; size_t argPos = 1;
bool hex = false, verbose = false; bool hex = false, verbose = false, numeric = false;
time_t maxAge = 5*60; time_t maxAge = 5*60;
string circuit; string circuit;
unsigned char dstAddress = SYN, pollPriority = 0; unsigned char dstAddress = SYN, pollPriority = 0;
@@ -262,11 +262,11 @@ string MainLoop::executeRead(vector<string> &args)
hex = true; hex = true;
} else if (args[argPos] == "-f") { } else if (args[argPos] == "-f") {
maxAge = 0; maxAge = 0;
} } else if (args[argPos] == "-v") {
else if (args[argPos] == "-v") {
verbose = true; verbose = true;
} } else if (args[argPos] == "-n") {
else if (args[argPos] == "-m") { numeric = true;
} else if (args[argPos] == "-m") {
argPos++; argPos++;
if (args.size() > argPos) { if (args.size() > argPos) {
result_t result; result_t result;
@@ -280,16 +280,14 @@ string MainLoop::executeRead(vector<string> &args)
argPos = 0; // print usage argPos = 0; // print usage
break; break;
} }
} } else if (args[argPos] == "-c") {
else if (args[argPos] == "-c") {
argPos++; argPos++;
if (argPos >= args.size()) { if (argPos >= args.size()) {
argPos = 0; // print usage argPos = 0; // print usage
break; break;
} }
circuit = args[argPos]; circuit = args[argPos];
} } else if (args[argPos] == "-d") {
else if (args[argPos] == "-d") {
argPos++; argPos++;
if (argPos >= args.size()) { if (argPos >= args.size()) {
argPos = 0; // print usage argPos = 0; // print usage
@@ -315,7 +313,7 @@ string MainLoop::executeRead(vector<string> &args)
} }
argPos++; argPos++;
} }
if (hex && (dstAddress != SYN || verbose || pollPriority > 0 || args.size() < argPos + 1)) { if (hex && (dstAddress != SYN || verbose || numeric || pollPriority > 0 || args.size() < argPos + 1)) {
argPos = 0; // print usage argPos = 0; // print usage
} }
@@ -366,7 +364,7 @@ string MainLoop::executeRead(vector<string> &args)
return getResultCode(ret); return getResultCode(ret);
} }
if (argPos == 0 || args.size() < argPos + 1 || args.size() > argPos + 2) if (argPos == 0 || args.size() < argPos + 1 || args.size() > argPos + 2)
return "usage: read [-f] [-m SECONDS] [-c CIRCUIT] [-d ZZ] [-p PRIO] [-v] NAME [FIELD[.N]]\n" return "usage: read [-f] [-m SECONDS] [-c CIRCUIT] [-d ZZ] [-p PRIO] [-v] [-n] NAME [FIELD[.N]]\n"
" or: read [-f] [-m SECONDS] [-c CIRCUIT] -h ZZPBSBNNDx\n" " or: read [-f] [-m SECONDS] [-c CIRCUIT] -h ZZPBSBNNDx\n"
" Read value(s) or hex message.\n" " Read value(s) or hex message.\n"
" -f force reading from the bus (same as '-m 0')\n" " -f force reading from the bus (same as '-m 0')\n"
@@ -375,6 +373,7 @@ string MainLoop::executeRead(vector<string> &args)
" -d ZZ override destination address ZZ\n" " -d ZZ override destination address ZZ\n"
" -p PRIO set the message poll priority (1-9)\n" " -p PRIO set the message poll priority (1-9)\n"
" -v be verbose (include field names, units, and comments)\n" " -v be verbose (include field names, units, and comments)\n"
" -n use numeric value of value=name pairs\n"
" NAME the NAME of the message to send\n" " NAME the NAME of the message to send\n"
" FIELD only retrieve the field named FIELD\n" " FIELD only retrieve the field named FIELD\n"
" N only retrieve the N'th field named FIELD (0-based)\n" " N only retrieve the N'th field named FIELD (0-based)\n"
@@ -413,7 +412,7 @@ string MainLoop::executeRead(vector<string> &args)
cacheMessage = message; // message is newer/better cacheMessage = message; // message is newer/better
if (cacheMessage != NULL && (cacheMessage->getLastUpdateTime() + maxAge > now || (cacheMessage->isPassive() && cacheMessage->getLastUpdateTime() != 0))) { if (cacheMessage != NULL && (cacheMessage->getLastUpdateTime() + maxAge > now || (cacheMessage->isPassive() && cacheMessage->getLastUpdateTime() != 0))) {
result_t ret = cacheMessage->decodeLastData(result, false, verbose?df_verbose:df_standard, fieldIndex==-2 ? NULL : fieldName.c_str(), fieldIndex); result_t ret = cacheMessage->decodeLastData(result, (verbose?OF_VERBOSE:0)|(numeric?OF_NUMERIC:0), false, fieldIndex==-2 ? NULL : fieldName.c_str(), fieldIndex);
if (ret != RESULT_OK) { if (ret != RESULT_OK) {
if (ret < RESULT_OK) if (ret < RESULT_OK)
logError(lf_main, "read cached: %s", getResultCode(ret)); logError(lf_main, "read cached: %s", getResultCode(ret));
@@ -440,7 +439,7 @@ string MainLoop::executeRead(vector<string> &args)
if (ret != RESULT_OK) if (ret != RESULT_OK)
return getResultCode(ret); return getResultCode(ret);
ret = message->decode(pt_slaveData, slave, result, false, verbose?df_verbose:df_standard, fieldIndex==-2 ? NULL : fieldName.c_str(), fieldIndex); ret = message->decode(pt_slaveData, slave, result, (verbose?OF_VERBOSE:0)|(numeric?OF_NUMERIC:0), false, fieldIndex==-2 ? NULL : fieldName.c_str(), fieldIndex);
if (ret < RESULT_OK) { if (ret < RESULT_OK) {
logError(lf_main, "read: %s", getResultCode(ret)); logError(lf_main, "read: %s", getResultCode(ret));
return getResultCode(ret); return getResultCode(ret);
@@ -641,7 +640,7 @@ string MainLoop::executeFind(vector<string> &args)
if (lastup == 0) if (lastup == 0)
result << "no data stored"; result << "no data stored";
else else
message->decodeLastData(result, verbose?df_verbose:df_standard); message->decodeLastData(result, verbose?OF_VERBOSE:0);
if (verbose) { if (verbose) {
if (lastup == 0) if (lastup == 0)
sprintf(str, "%02x", dstAddress); sprintf(str, "%02x", dstAddress);
@@ -840,7 +839,7 @@ string MainLoop::executeQuit(vector<string> &args, bool& connected)
string MainLoop::executeHelp() string MainLoop::executeHelp()
{ {
return "usage:\n" return "usage:\n"
" read|r Read value(s): read [-f] [-m SECONDS] [-c CIRCUIT] [-d ZZ] [-p PRIO] [-v] NAME [FIELD[.N]]\n" " read|r Read value(s): read [-f] [-m SECONDS] [-c CIRCUIT] [-d ZZ] [-p PRIO] [-v] [-n] NAME [FIELD[.N]]\n"
" Read hex message: read [-f] [-m SECONDS] [-c CIRCUIT] -h ZZPBSBNNDx\n" " Read hex message: read [-f] [-m SECONDS] [-c CIRCUIT] -h ZZPBSBNNDx\n"
" write|w Write value(s): write [-c] CIRCUIT NAME [VALUE[;VALUE]*]\n" " write|w Write value(s): write [-c] CIRCUIT NAME [VALUE[;VALUE]*]\n"
" Write hex message: write -h ZZPBSBNNDx\n" " Write hex message: write -h ZZPBSBNNDx\n"
@@ -866,6 +865,7 @@ string MainLoop::executeHelp()
string MainLoop::executeGet(vector<string> &args, bool& connected) string MainLoop::executeGet(vector<string> &args, bool& connected)
{ {
result_t ret = RESULT_OK; result_t ret = RESULT_OK;
bool verbose = false, numeric = false;
size_t argPos = 1; size_t argPos = 1;
string uri = args[argPos++]; string uri = args[argPos++];
ostringstream result; ostringstream result;
@@ -897,6 +897,10 @@ string MainLoop::executeGet(vector<string> &args, bool& connected)
pollPriority = (unsigned char)parseInt(value.c_str(), 10, 1, 9, ret); pollPriority = (unsigned char)parseInt(value.c_str(), 10, 1, 9, ret);
} else if (strcmp(qname.c_str(), "exact") == 0) { } else if (strcmp(qname.c_str(), "exact") == 0) {
exact = value.length()==0 || strcmp(value.c_str(), "1") == 0; exact = value.length()==0 || strcmp(value.c_str(), "1") == 0;
} else if (strcmp(qname.c_str(), "verbose") == 0) {
verbose = value.length()==0 || strcmp(value.c_str(), "1") == 0;
} else if (strcmp(qname.c_str(), "numeric") == 0) {
numeric = value.length()==0 || strcmp(value.c_str(), "1") == 0;
} }
if (ret != RESULT_OK) if (ret != RESULT_OK)
break; break;
@@ -937,7 +941,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected)
if (lastup != 0) { if (lastup != 0) {
result << ",\n \"zz\": \"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(dstAddress) << "\""; result << ",\n \"zz\": \"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(dstAddress) << "\"";
result << ",\n \"fields\": ["; result << ",\n \"fields\": [";
ret = message->decodeLastData(result, false, df_json); ret = message->decodeLastData(result, (verbose?OF_VERBOSE:0)|(numeric?OF_NUMERIC:0)|OF_JSON);
result << "\n ]"; result << "\n ]";
} }
result << ",\n \"passive\": " << (message->isPassive() ? "true" : "false"); result << ",\n \"passive\": " << (message->isPassive() ? "true" : "false");
+59 -54
View File
@@ -96,7 +96,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
unsigned long int ret = strtoul(str, &strEnd, base); unsigned long int ret = strtoul(str, &strEnd, base);
if (strEnd == NULL || *strEnd != 0) { if (strEnd == NULL || strEnd == str|| *strEnd != 0) {
result = RESULT_ERR_INVALID_NUM; // invalid value result = RESULT_ERR_INVALID_NUM; // invalid value
return 0; return 0;
} }
@@ -429,8 +429,8 @@ void SingleDataField::dump(ostream& output)
result_t SingleDataField::read(const PartType partType, result_t SingleDataField::read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat, const char* fieldName, signed char fieldIndex) bool leadingSeparator, const char* fieldName, signed char fieldIndex)
{ {
if (partType != m_partType) if (partType != m_partType)
return RESULT_OK; return RESULT_OK;
@@ -454,36 +454,36 @@ result_t SingleDataField::read(const PartType partType,
} }
if (leadingSeparator) { if (leadingSeparator) {
if (dataFormat==df_json) if (outputFormat & OF_JSON)
output << ","; output << ",";
else else
output << UI_FIELD_SEPARATOR; output << UI_FIELD_SEPARATOR;
} }
if (dataFormat==df_verbose) if (outputFormat & OF_JSON)
output << "\n {\"name\": \"" << m_name << "\"" << ", \"value\": ";
else if (outputFormat & OF_VERBOSE)
output << m_name << "="; output << m_name << "=";
else if (dataFormat==df_json)
output << "\n {\"name\": \"" << m_name << "\"";
if (dataFormat==df_json) result_t result = readSymbols(data, offset, output, outputFormat);
output << ", \"value\": ";
result_t result = readSymbols(data, offset, output, dataFormat);
if (result != RESULT_OK) if (result != RESULT_OK)
return result; return result;
if (m_unit.length() > 0) { if (outputFormat & OF_VERBOSE) {
if (dataFormat==df_verbose) if (m_unit.length() > 0) {
output << " " << m_unit; if (outputFormat & OF_JSON)
else if (dataFormat==df_json) output << ", \"unit\": \"" << m_unit << '"';
output << ", \"unit\": \"" << m_unit << '"'; else
output << " " << m_unit;
}
if (m_comment.length() > 0) {
if (outputFormat & OF_JSON)
output << ", \"comment\": \"" << m_comment << '"';
else
output << " [" << m_comment << "]";
}
} }
if (m_comment.length() > 0) { if (outputFormat & OF_JSON)
if (dataFormat==df_verbose)
output << " [" << m_comment << "]";
else if (dataFormat==df_json)
output << ", \"comment\": \"" << m_comment << '"';
}
if (dataFormat==df_json)
output << "}"; output << "}";
return RESULT_OK; return RESULT_OK;
} }
@@ -542,8 +542,7 @@ void StringDataField::dump(ostream& output)
} }
result_t StringDataField::readSymbols(SymbolString& input, const unsigned char baseOffset, result_t StringDataField::readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat)
DataFormat dataFormat)
{ {
size_t start = 0, count = m_length; size_t start = 0, count = m_length;
int incr = 1; int incr = 1;
@@ -558,7 +557,7 @@ result_t StringDataField::readSymbols(SymbolString& input, const unsigned char b
incr = -1; incr = -1;
} }
if (dataFormat==df_json) if (outputFormat & OF_JSON)
output << '"'; output << '"';
for (size_t offset = start, i = 0; i < count; offset += incr, i++) { for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
if (m_length == 4 && i == 2 && m_dataType.type == bt_dat) if (m_length == 4 && i == 2 && m_dataType.type == bt_dat)
@@ -633,7 +632,7 @@ result_t StringDataField::readSymbols(SymbolString& input, const unsigned char b
} }
last = ch; last = ch;
} }
if (dataFormat==df_json) if (outputFormat & OF_JSON)
output << '"'; output << '"';
return RESULT_OK; return RESULT_OK;
@@ -962,8 +961,7 @@ void NumberDataField::dump(ostream& output)
} }
result_t NumberDataField::readSymbols(SymbolString& input, const unsigned char baseOffset, result_t NumberDataField::readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat)
DataFormat dataFormat)
{ {
unsigned int value = 0; unsigned int value = 0;
int signedValue; int signedValue;
@@ -975,11 +973,10 @@ result_t NumberDataField::readSymbols(SymbolString& input, const unsigned char b
output << setw(0) << dec; // initialize output output << setw(0) << dec; // initialize output
if ((m_dataType.flags & REQ) == 0 && value == m_dataType.replacement) { if ((m_dataType.flags & REQ) == 0 && value == m_dataType.replacement) {
if (dataFormat==df_json) if (outputFormat & OF_JSON)
output << '"'; output << "null";
output << NULL_VALUE; else
if (dataFormat==df_json) output << NULL_VALUE;
output << '"';
return RESULT_OK; return RESULT_OK;
} }
@@ -1006,7 +1003,7 @@ result_t NumberDataField::readSymbols(SymbolString& input, const unsigned char b
output << static_cast<float>((float)signedValue * (float)(-m_divisor)); output << static_cast<float>((float)signedValue * (float)(-m_divisor));
else if (m_divisor <= 1) { else if (m_divisor <= 1) {
if ((m_dataType.flags & (FIX|BCD)) == (FIX|BCD)) { if ((m_dataType.flags & (FIX|BCD)) == (FIX|BCD)) {
if (dataFormat==df_json) { if (outputFormat & OF_JSON) {
output << '"'; output << '"';
output << setw(m_length * 2) << setfill('0'); output << setw(m_length * 2) << setfill('0');
output << '"'; output << '"';
@@ -1045,12 +1042,12 @@ result_t NumberDataField::writeSymbols(istringstream& input,
} }
else else
value = (unsigned int)strtoul(str, &strEnd, 10); value = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || *strEnd != 0) if (strEnd == NULL || strEnd == str || *strEnd != 0)
return RESULT_ERR_INVALID_NUM; // invalid value return RESULT_ERR_INVALID_NUM; // invalid value
} else { } else {
char* strEnd = NULL; char* strEnd = NULL;
double dvalue = strtod(str, &strEnd); double dvalue = strtod(str, &strEnd);
if (strEnd == NULL || *strEnd != 0) if (strEnd == NULL || strEnd == str || *strEnd != 0)
return RESULT_ERR_INVALID_NUM; // invalid value return RESULT_ERR_INVALID_NUM; // invalid value
if (m_divisor < 0) if (m_divisor < 0)
dvalue = round(dvalue / -m_divisor); dvalue = round(dvalue / -m_divisor);
@@ -1132,8 +1129,7 @@ void ValueListDataField::dump(ostream& output)
} }
result_t ValueListDataField::readSymbols(SymbolString& input, const unsigned char baseOffset, result_t ValueListDataField::readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat)
DataFormat dataFormat)
{ {
unsigned int value = 0; unsigned int value = 0;
@@ -1145,16 +1141,17 @@ result_t ValueListDataField::readSymbols(SymbolString& input, const unsigned cha
if (it == m_values.end() && value != m_dataType.replacement) { if (it == m_values.end() && value != m_dataType.replacement) {
return RESULT_ERR_NOTFOUND; // value assignment not found return RESULT_ERR_NOTFOUND; // value assignment not found
} }
output << setw(0) << dec; // initialize output if (it == m_values.end()) {
if (dataFormat==df_json) if (outputFormat & OF_JSON)
output << '"'; output << "null";
if (it != m_values.end()) { else if (value == m_dataType.replacement)
output << NULL_VALUE;
} else if (outputFormat & OF_NUMERIC)
output << setw(0) << dec << static_cast<int>(value);
else if (outputFormat & OF_JSON)
output << '"' << it->second << '"';
else
output << it->second; output << it->second;
} else if (value == m_dataType.replacement) {
output << NULL_VALUE;
}
if (dataFormat==df_json)
output << '"';
return RESULT_OK; return RESULT_OK;
} }
@@ -1173,6 +1170,14 @@ result_t ValueListDataField::writeSymbols(istringstream& input,
if (strcasecmp(str, NULL_VALUE) == 0) if (strcasecmp(str, NULL_VALUE) == 0)
return writeRawValue(m_dataType.replacement, baseOffset, output); // replacement value return writeRawValue(m_dataType.replacement, baseOffset, output); // replacement value
char* strEnd = NULL; // fall back to raw value in input
unsigned int value;
value = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0)
return RESULT_ERR_INVALID_NUM; // invalid value
if (m_values.find(value) != m_values.end())
return writeRawValue(value, baseOffset, output);
return RESULT_ERR_NOTFOUND; // value assignment not found return RESULT_ERR_NOTFOUND; // value assignment not found
} }
@@ -1272,8 +1277,8 @@ void DataFieldSet::dump(ostream& output)
result_t DataFieldSet::read(const PartType partType, result_t DataFieldSet::read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat, const char* fieldName, signed char fieldIndex) bool leadingSeparator, const char* fieldName, signed char fieldIndex)
{ {
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0; bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) { for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
@@ -1284,7 +1289,7 @@ result_t DataFieldSet::read(const PartType partType,
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) if (!previousFullByteOffset && !field->hasFullByteOffset(false))
offset--; offset--;
result_t result = field->read(partType, data, offset, output, leadingSeparator, dataFormat, fieldName, fieldIndex); result_t result = field->read(partType, data, offset, output, outputFormat, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) if (result < RESULT_OK)
return result; return result;
@@ -1308,11 +1313,11 @@ result_t DataFieldSet::read(const PartType partType,
if (!found) { if (!found) {
return RESULT_EMPTY; return RESULT_EMPTY;
} }
if (m_comment.length() > 0) { if (m_comment.length() > 0 && (outputFormat & OF_VERBOSE)) {
if (dataFormat==df_verbose) if (outputFormat & OF_JSON)
output << " [" << m_comment << "]";
else if (dataFormat==df_json)
output << ",\"comment\": \"" << m_comment << '"'; output << ",\"comment\": \"" << m_comment << '"';
else
output << " [" << m_comment << "]";
} }
return RESULT_OK; return RESULT_OK;
+25 -22
View File
@@ -46,12 +46,19 @@ using namespace std;
/** the separator character used between fields (in UI only). */ /** the separator character used between fields (in UI only). */
#define UI_FIELD_SEPARATOR ';' #define UI_FIELD_SEPARATOR ';'
/** the data output format. */ /** the type for data output format options. */
enum DataFormat { /*class OutputFormat {
df_standard, //!< standard format (values only) public:
df_verbose, //!< verbose format (names, values, units, and comments) bool operator&(int x){return false;}
df_json, //!< JSON format (names, values, units, and comments) OutputFormat(int x) {}
}; };*/
//typedef xOutputFormat* OutputFormat;
typedef int OutputFormat;
/* the bit flags for @a OutputFormat. */
static const unsigned int OF_VERBOSE = 0x01; //!< verbose format (names, values, units, and comments).
static const unsigned int OF_NUMERIC = 0x02; //!< numeric format (keep numeric value of value=name pairs).
static const unsigned int OF_JSON = 0x04; //!< JSON format.
/** the message part in which a data field is stored. */ /** the message part in which a data field is stored. */
enum PartType { enum PartType {
@@ -226,8 +233,8 @@ public:
* @param data the unescaped data @a SymbolString for reading binary data. * @param data the unescaped data @a SymbolString for reading binary data.
* @param offset the additional offset to add for reading binary data. * @param offset the additional offset to add for reading binary data.
* @param output the @a ostringstream to append the formatted value to. * @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 leadingSeparator whether to prepend a separator before the formatted value.
* @param dataFormat the @a DataFormat to use.
* @param fieldName the optional name of a field to limit the output to. * @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. * @param fieldIndex the optional index of the named field to limit the output to, or -1.
* @return @a RESULT_OK on success (or if the partType does not match), * @return @a RESULT_OK on success (or if the partType does not match),
@@ -236,8 +243,8 @@ public:
*/ */
virtual result_t read(const PartType partType, virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1) = 0; bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1) = 0;
/** /**
* Writes the value to the master or slave @a SymbolString. * Writes the value to the master or slave @a SymbolString.
@@ -346,8 +353,8 @@ public:
// @copydoc // @copydoc
virtual result_t read(const PartType partType, virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1); bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
// @copydoc // @copydoc
virtual result_t write(istringstream& input, virtual result_t write(istringstream& input,
@@ -361,12 +368,11 @@ protected:
* @param input the unescaped @a SymbolString to read the binary value from. * @param input the unescaped @a SymbolString to read the binary value from.
* @param baseOffset the base offset in the @a SymbolString. * @param baseOffset the base offset in the @a SymbolString.
* @param output the ostringstream to append the formatted value to. * @param output the ostringstream to append the formatted value to.
* @param dataFormat the @a DataFormat to use. * @param outputFormat the @a OutputFormat options to use.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset, virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat) = 0;
DataFormat dataFormat) = 0;
/** /**
* Internal method for writing the field to a @a SymbolString. * Internal method for writing the field to a @a SymbolString.
@@ -433,8 +439,7 @@ protected:
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset, virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat);
DataFormat dataFormat);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output); virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -547,8 +552,7 @@ protected:
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset, virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat);
DataFormat dataFormat);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output); virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -608,8 +612,7 @@ protected:
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset, virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
ostringstream& output, ostringstream& output, OutputFormat outputFormat);
DataFormat dataFormat);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output); virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -686,8 +689,8 @@ public:
// @copydoc // @copydoc
virtual result_t read(const PartType partType, virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1); bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
// @copydoc // @copydoc
virtual result_t write(istringstream& input, virtual result_t write(istringstream& input,
+11 -11
View File
@@ -364,15 +364,15 @@ result_t Message::prepareSlave(SymbolString& slaveData)
} }
result_t Message::decode(const PartType partType, SymbolString& data, result_t Message::decode(const PartType partType, SymbolString& data,
ostringstream& output, bool leadingSeparator, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat, const char* fieldName, signed char fieldIndex) bool leadingSeparator, const char* fieldName, signed char fieldIndex)
{ {
unsigned char offset; unsigned char offset;
if (partType == pt_masterData) if (partType == pt_masterData)
offset = (unsigned char)(m_id.size() - 2); offset = (unsigned char)(m_id.size() - 2);
else else
offset = 0; offset = 0;
result_t result = m_data->read(partType, data, offset, output, leadingSeparator, dataFormat, fieldName, fieldIndex); result_t result = m_data->read(partType, data, offset, output, outputFormat, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) if (result < RESULT_OK)
return result; return result;
if (result == RESULT_EMPTY && fieldName != NULL) if (result == RESULT_EMPTY && fieldName != NULL)
@@ -399,18 +399,18 @@ result_t Message::decode(const PartType partType, SymbolString& data,
} }
result_t Message::decode(SymbolString& masterData, SymbolString& slaveData, result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
ostringstream& output, bool leadingSeparator, ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat) bool leadingSeparator)
{ {
unsigned char offset = (unsigned char)(m_id.size() - 2); unsigned char offset = (unsigned char)(m_id.size() - 2);
size_t startPos = output.str().length(); size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, masterData, offset, output, leadingSeparator, dataFormat, NULL, -1); result_t result = m_data->read(pt_masterData, masterData, offset, output, outputFormat, leadingSeparator, NULL, -1);
if (result < RESULT_OK) if (result < RESULT_OK)
return result; return result;
bool empty = result == RESULT_EMPTY; bool empty = result == RESULT_EMPTY;
offset = 0; offset = 0;
leadingSeparator = output.str().length() > startPos; leadingSeparator = output.str().length() > startPos;
result = m_data->read(pt_slaveData, slaveData, offset, output, leadingSeparator, dataFormat, NULL, -1); result = m_data->read(pt_slaveData, slaveData, offset, output, outputFormat, leadingSeparator, NULL, -1);
if (result < RESULT_OK) if (result < RESULT_OK)
return result; return result;
if (result == RESULT_EMPTY && !empty) if (result == RESULT_EMPTY && !empty)
@@ -432,18 +432,18 @@ result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
return result; return result;
} }
result_t Message::decodeLastData(ostringstream& output, bool leadingSeparator, result_t Message::decodeLastData(ostringstream& output, OutputFormat outputFormat,
DataFormat dataFormat, const char* fieldName, signed char fieldIndex) bool leadingSeparator, const char* fieldName, signed char fieldIndex)
{ {
unsigned char offset = (unsigned char)(m_id.size() - 2); unsigned char offset = (unsigned char)(m_id.size() - 2);
size_t startPos = output.str().length(); size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, m_lastMasterData, offset, output, leadingSeparator, dataFormat, fieldName, fieldIndex); result_t result = m_data->read(pt_masterData, m_lastMasterData, offset, output, outputFormat, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) if (result < RESULT_OK)
return result; return result;
bool empty = result == RESULT_EMPTY; bool empty = result == RESULT_EMPTY;
offset = 0; offset = 0;
leadingSeparator = output.str().length() > startPos; leadingSeparator = output.str().length() > startPos;
result = m_data->read(pt_slaveData, m_lastSlaveData, offset, output, leadingSeparator, dataFormat, fieldName, fieldIndex); result = m_data->read(pt_slaveData, m_lastSlaveData, offset, output, outputFormat, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) if (result < RESULT_OK)
return result; return result;
if (result == RESULT_EMPTY && !empty) if (result == RESULT_EMPTY && !empty)
+9 -9
View File
@@ -188,40 +188,40 @@ public:
* @param partType the @a PartType of the data. * @param partType the @a PartType of the data.
* @param data the unescaped data @a SymbolString for reading binary data. * @param data the unescaped data @a SymbolString for reading binary data.
* @param output the @a ostringstream to append the formatted value to. * @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 leadingSeparator whether to prepend a separator before the formatted value.
* @param dataFormat the @a DataFormat to use.
* @param fieldName the optional name of a field to limit the output to. * @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. * @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. * @return @a RESULT_OK on success, or an error code.
*/ */
result_t decode(const PartType partType, SymbolString& data, result_t decode(const PartType partType, SymbolString& data,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, OutputFormat outputFormat=0,
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1); bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
/** /**
* Decode all parts of a received message. * Decode all parts of a received message.
* @param masterData the unescaped master data @a SymbolString to decode. * @param masterData the unescaped master data @a SymbolString to decode.
* @param slaveData the unescaped slave data @a SymbolString to decode. * @param slaveData the unescaped slave data @a SymbolString to decode.
* @param output the @a ostringstream to append the formatted value to. * @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 leadingSeparator whether to prepend a separator before the formatted value.
* @param dataFormat the @a DataFormat to use.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
result_t decode(SymbolString& masterData, SymbolString& slaveData, result_t decode(SymbolString& masterData, SymbolString& slaveData,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, OutputFormat outputFormat=0,
DataFormat dataFormat=df_standard); bool leadingSeparator=false);
/** /**
* Decode the value from the last stored data. * Decode the value from the last stored data.
* @param output the @a ostringstream to append the formatted value to. * @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 leadingSeparator whether to prepend a separator before the formatted value.
* @param dataFormat the @a DataFormat to use.
* @param fieldName the optional name of a field to limit the output to. * @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. * @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. * @return @a RESULT_OK on success, or an error code.
*/ */
result_t decodeLastData(ostringstream& output, bool leadingSeparator=false, result_t decodeLastData(ostringstream& output, OutputFormat outputFormat=0,
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1); bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
/** /**
* Get the last seen slave data. * Get the last seen slave data.