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:
@@ -100,7 +100,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
|
||||
if (result == RESULT_OK) {
|
||||
if (!append)
|
||||
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) {
|
||||
logError(lf_bus, "scan %2.2x failed: %s", dstAddress, getResultCode(result));
|
||||
|
||||
+20
-16
@@ -253,7 +253,7 @@ result_t MainLoop::readFromBus(Message* message, SymbolString& master, string in
|
||||
string MainLoop::executeRead(vector<string> &args)
|
||||
{
|
||||
size_t argPos = 1;
|
||||
bool hex = false, verbose = false;
|
||||
bool hex = false, verbose = false, numeric = false;
|
||||
time_t maxAge = 5*60;
|
||||
string circuit;
|
||||
unsigned char dstAddress = SYN, pollPriority = 0;
|
||||
@@ -262,11 +262,11 @@ string MainLoop::executeRead(vector<string> &args)
|
||||
hex = true;
|
||||
} else if (args[argPos] == "-f") {
|
||||
maxAge = 0;
|
||||
}
|
||||
else if (args[argPos] == "-v") {
|
||||
} else if (args[argPos] == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
else if (args[argPos] == "-m") {
|
||||
} else if (args[argPos] == "-n") {
|
||||
numeric = true;
|
||||
} else if (args[argPos] == "-m") {
|
||||
argPos++;
|
||||
if (args.size() > argPos) {
|
||||
result_t result;
|
||||
@@ -280,16 +280,14 @@ string MainLoop::executeRead(vector<string> &args)
|
||||
argPos = 0; // print usage
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (args[argPos] == "-c") {
|
||||
} else if (args[argPos] == "-c") {
|
||||
argPos++;
|
||||
if (argPos >= args.size()) {
|
||||
argPos = 0; // print usage
|
||||
break;
|
||||
}
|
||||
circuit = args[argPos];
|
||||
}
|
||||
else if (args[argPos] == "-d") {
|
||||
} else if (args[argPos] == "-d") {
|
||||
argPos++;
|
||||
if (argPos >= args.size()) {
|
||||
argPos = 0; // print usage
|
||||
@@ -315,7 +313,7 @@ string MainLoop::executeRead(vector<string> &args)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -366,7 +364,7 @@ string MainLoop::executeRead(vector<string> &args)
|
||||
return getResultCode(ret);
|
||||
}
|
||||
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"
|
||||
" Read value(s) or hex message.\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"
|
||||
" -p PRIO set the message poll priority (1-9)\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"
|
||||
" FIELD only retrieve the field named FIELD\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
|
||||
|
||||
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)
|
||||
logError(lf_main, "read cached: %s", getResultCode(ret));
|
||||
@@ -440,7 +439,7 @@ string MainLoop::executeRead(vector<string> &args)
|
||||
if (ret != RESULT_OK)
|
||||
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) {
|
||||
logError(lf_main, "read: %s", getResultCode(ret));
|
||||
return getResultCode(ret);
|
||||
@@ -641,7 +640,7 @@ string MainLoop::executeFind(vector<string> &args)
|
||||
if (lastup == 0)
|
||||
result << "no data stored";
|
||||
else
|
||||
message->decodeLastData(result, verbose?df_verbose:df_standard);
|
||||
message->decodeLastData(result, verbose?OF_VERBOSE:0);
|
||||
if (verbose) {
|
||||
if (lastup == 0)
|
||||
sprintf(str, "%02x", dstAddress);
|
||||
@@ -840,7 +839,7 @@ string MainLoop::executeQuit(vector<string> &args, bool& connected)
|
||||
string MainLoop::executeHelp()
|
||||
{
|
||||
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"
|
||||
" write|w Write value(s): write [-c] CIRCUIT NAME [VALUE[;VALUE]*]\n"
|
||||
" Write hex message: write -h ZZPBSBNNDx\n"
|
||||
@@ -866,6 +865,7 @@ string MainLoop::executeHelp()
|
||||
string MainLoop::executeGet(vector<string> &args, bool& connected)
|
||||
{
|
||||
result_t ret = RESULT_OK;
|
||||
bool verbose = false, numeric = false;
|
||||
size_t argPos = 1;
|
||||
string uri = args[argPos++];
|
||||
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);
|
||||
} else if (strcmp(qname.c_str(), "exact") == 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)
|
||||
break;
|
||||
@@ -937,7 +941,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected)
|
||||
if (lastup != 0) {
|
||||
result << ",\n \"zz\": \"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(dstAddress) << "\"";
|
||||
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 \"passive\": " << (message->isPassive() ? "true" : "false");
|
||||
|
||||
+59
-54
@@ -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);
|
||||
|
||||
if (strEnd == NULL || *strEnd != 0) {
|
||||
if (strEnd == NULL || strEnd == str|| *strEnd != 0) {
|
||||
result = RESULT_ERR_INVALID_NUM; // invalid value
|
||||
return 0;
|
||||
}
|
||||
@@ -429,8 +429,8 @@ void SingleDataField::dump(ostream& output)
|
||||
|
||||
result_t SingleDataField::read(const PartType partType,
|
||||
SymbolString& data, unsigned char offset,
|
||||
ostringstream& output, bool leadingSeparator,
|
||||
DataFormat dataFormat, const char* fieldName, signed char fieldIndex)
|
||||
ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator, const char* fieldName, signed char fieldIndex)
|
||||
{
|
||||
if (partType != m_partType)
|
||||
return RESULT_OK;
|
||||
@@ -454,36 +454,36 @@ result_t SingleDataField::read(const PartType partType,
|
||||
}
|
||||
|
||||
if (leadingSeparator) {
|
||||
if (dataFormat==df_json)
|
||||
if (outputFormat & OF_JSON)
|
||||
output << ",";
|
||||
else
|
||||
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 << "=";
|
||||
else if (dataFormat==df_json)
|
||||
output << "\n {\"name\": \"" << m_name << "\"";
|
||||
|
||||
if (dataFormat==df_json)
|
||||
output << ", \"value\": ";
|
||||
result_t result = readSymbols(data, offset, output, dataFormat);
|
||||
result_t result = readSymbols(data, offset, output, outputFormat);
|
||||
if (result != RESULT_OK)
|
||||
return result;
|
||||
|
||||
if (m_unit.length() > 0) {
|
||||
if (dataFormat==df_verbose)
|
||||
output << " " << m_unit;
|
||||
else if (dataFormat==df_json)
|
||||
output << ", \"unit\": \"" << m_unit << '"';
|
||||
if (outputFormat & OF_VERBOSE) {
|
||||
if (m_unit.length() > 0) {
|
||||
if (outputFormat & OF_JSON)
|
||||
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 (dataFormat==df_verbose)
|
||||
output << " [" << m_comment << "]";
|
||||
else if (dataFormat==df_json)
|
||||
output << ", \"comment\": \"" << m_comment << '"';
|
||||
}
|
||||
if (dataFormat==df_json)
|
||||
if (outputFormat & OF_JSON)
|
||||
output << "}";
|
||||
return RESULT_OK;
|
||||
}
|
||||
@@ -542,8 +542,7 @@ void StringDataField::dump(ostream& output)
|
||||
}
|
||||
|
||||
result_t StringDataField::readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat)
|
||||
ostringstream& output, OutputFormat outputFormat)
|
||||
{
|
||||
size_t start = 0, count = m_length;
|
||||
int incr = 1;
|
||||
@@ -558,7 +557,7 @@ result_t StringDataField::readSymbols(SymbolString& input, const unsigned char b
|
||||
incr = -1;
|
||||
}
|
||||
|
||||
if (dataFormat==df_json)
|
||||
if (outputFormat & OF_JSON)
|
||||
output << '"';
|
||||
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
|
||||
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;
|
||||
}
|
||||
if (dataFormat==df_json)
|
||||
if (outputFormat & OF_JSON)
|
||||
output << '"';
|
||||
|
||||
return RESULT_OK;
|
||||
@@ -962,8 +961,7 @@ void NumberDataField::dump(ostream& output)
|
||||
}
|
||||
|
||||
result_t NumberDataField::readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat)
|
||||
ostringstream& output, OutputFormat outputFormat)
|
||||
{
|
||||
unsigned int value = 0;
|
||||
int signedValue;
|
||||
@@ -975,11 +973,10 @@ result_t NumberDataField::readSymbols(SymbolString& input, const unsigned char b
|
||||
output << setw(0) << dec; // initialize output
|
||||
|
||||
if ((m_dataType.flags & REQ) == 0 && value == m_dataType.replacement) {
|
||||
if (dataFormat==df_json)
|
||||
output << '"';
|
||||
output << NULL_VALUE;
|
||||
if (dataFormat==df_json)
|
||||
output << '"';
|
||||
if (outputFormat & OF_JSON)
|
||||
output << "null";
|
||||
else
|
||||
output << NULL_VALUE;
|
||||
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));
|
||||
else if (m_divisor <= 1) {
|
||||
if ((m_dataType.flags & (FIX|BCD)) == (FIX|BCD)) {
|
||||
if (dataFormat==df_json) {
|
||||
if (outputFormat & OF_JSON) {
|
||||
output << '"';
|
||||
output << setw(m_length * 2) << setfill('0');
|
||||
output << '"';
|
||||
@@ -1045,12 +1042,12 @@ result_t NumberDataField::writeSymbols(istringstream& input,
|
||||
}
|
||||
else
|
||||
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
|
||||
} else {
|
||||
char* strEnd = NULL;
|
||||
double dvalue = strtod(str, &strEnd);
|
||||
if (strEnd == NULL || *strEnd != 0)
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0)
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
if (m_divisor < 0)
|
||||
dvalue = round(dvalue / -m_divisor);
|
||||
@@ -1132,8 +1129,7 @@ void ValueListDataField::dump(ostream& output)
|
||||
}
|
||||
|
||||
result_t ValueListDataField::readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat)
|
||||
ostringstream& output, OutputFormat outputFormat)
|
||||
{
|
||||
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) {
|
||||
return RESULT_ERR_NOTFOUND; // value assignment not found
|
||||
}
|
||||
output << setw(0) << dec; // initialize output
|
||||
if (dataFormat==df_json)
|
||||
output << '"';
|
||||
if (it != m_values.end()) {
|
||||
if (it == m_values.end()) {
|
||||
if (outputFormat & OF_JSON)
|
||||
output << "null";
|
||||
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;
|
||||
} else if (value == m_dataType.replacement) {
|
||||
output << NULL_VALUE;
|
||||
}
|
||||
if (dataFormat==df_json)
|
||||
output << '"';
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
@@ -1173,6 +1170,14 @@ result_t ValueListDataField::writeSymbols(istringstream& input,
|
||||
if (strcasecmp(str, NULL_VALUE) == 0)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1272,8 +1277,8 @@ void DataFieldSet::dump(ostream& output)
|
||||
|
||||
result_t DataFieldSet::read(const PartType partType,
|
||||
SymbolString& data, unsigned char offset,
|
||||
ostringstream& output, bool leadingSeparator,
|
||||
DataFormat dataFormat, const char* fieldName, signed char fieldIndex)
|
||||
ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator, const char* fieldName, signed char fieldIndex)
|
||||
{
|
||||
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
|
||||
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))
|
||||
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)
|
||||
return result;
|
||||
@@ -1308,11 +1313,11 @@ result_t DataFieldSet::read(const PartType partType,
|
||||
if (!found) {
|
||||
return RESULT_EMPTY;
|
||||
}
|
||||
if (m_comment.length() > 0) {
|
||||
if (dataFormat==df_verbose)
|
||||
output << " [" << m_comment << "]";
|
||||
else if (dataFormat==df_json)
|
||||
if (m_comment.length() > 0 && (outputFormat & OF_VERBOSE)) {
|
||||
if (outputFormat & OF_JSON)
|
||||
output << ",\"comment\": \"" << m_comment << '"';
|
||||
else
|
||||
output << " [" << m_comment << "]";
|
||||
}
|
||||
|
||||
return RESULT_OK;
|
||||
|
||||
+25
-22
@@ -46,12 +46,19 @@ using namespace std;
|
||||
/** the separator character used between fields (in UI only). */
|
||||
#define UI_FIELD_SEPARATOR ';'
|
||||
|
||||
/** the data output format. */
|
||||
enum DataFormat {
|
||||
df_standard, //!< standard format (values only)
|
||||
df_verbose, //!< verbose format (names, values, units, and comments)
|
||||
df_json, //!< JSON format (names, values, units, and comments)
|
||||
};
|
||||
/** the type for data output format options. */
|
||||
/*class OutputFormat {
|
||||
public:
|
||||
bool operator&(int x){return false;}
|
||||
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. */
|
||||
enum PartType {
|
||||
@@ -226,8 +233,8 @@ public:
|
||||
* @param data the unescaped data @a SymbolString 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 outputFormat the @a OutputFormat options to use.
|
||||
* @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 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),
|
||||
@@ -236,8 +243,8 @@ public:
|
||||
*/
|
||||
virtual result_t read(const PartType partType,
|
||||
SymbolString& data, unsigned char offset,
|
||||
ostringstream& output, bool leadingSeparator=false,
|
||||
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1) = 0;
|
||||
ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1) = 0;
|
||||
|
||||
/**
|
||||
* Writes the value to the master or slave @a SymbolString.
|
||||
@@ -346,8 +353,8 @@ public:
|
||||
// @copydoc
|
||||
virtual result_t read(const PartType partType,
|
||||
SymbolString& data, unsigned char offset,
|
||||
ostringstream& output, bool leadingSeparator=false,
|
||||
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
|
||||
// @copydoc
|
||||
virtual result_t write(istringstream& input,
|
||||
@@ -361,12 +368,11 @@ protected:
|
||||
* @param input the unescaped @a SymbolString to read the binary value from.
|
||||
* @param baseOffset the base offset in the @a SymbolString.
|
||||
* @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.
|
||||
*/
|
||||
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat) = 0;
|
||||
ostringstream& output, OutputFormat outputFormat) = 0;
|
||||
|
||||
/**
|
||||
* Internal method for writing the field to a @a SymbolString.
|
||||
@@ -433,8 +439,7 @@ protected:
|
||||
|
||||
// @copydoc
|
||||
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat);
|
||||
ostringstream& output, OutputFormat outputFormat);
|
||||
|
||||
// @copydoc
|
||||
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
|
||||
@@ -547,8 +552,7 @@ protected:
|
||||
|
||||
// @copydoc
|
||||
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat);
|
||||
ostringstream& output, OutputFormat outputFormat);
|
||||
|
||||
// @copydoc
|
||||
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
|
||||
@@ -608,8 +612,7 @@ protected:
|
||||
|
||||
// @copydoc
|
||||
virtual result_t readSymbols(SymbolString& input, const unsigned char baseOffset,
|
||||
ostringstream& output,
|
||||
DataFormat dataFormat);
|
||||
ostringstream& output, OutputFormat outputFormat);
|
||||
|
||||
// @copydoc
|
||||
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
|
||||
@@ -686,8 +689,8 @@ public:
|
||||
// @copydoc
|
||||
virtual result_t read(const PartType partType,
|
||||
SymbolString& data, unsigned char offset,
|
||||
ostringstream& output, bool leadingSeparator=false,
|
||||
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
|
||||
// @copydoc
|
||||
virtual result_t write(istringstream& input,
|
||||
|
||||
+11
-11
@@ -364,15 +364,15 @@ result_t Message::prepareSlave(SymbolString& slaveData)
|
||||
}
|
||||
|
||||
result_t Message::decode(const PartType partType, SymbolString& data,
|
||||
ostringstream& output, bool leadingSeparator,
|
||||
DataFormat dataFormat, const char* fieldName, signed char fieldIndex)
|
||||
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 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)
|
||||
return result;
|
||||
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,
|
||||
ostringstream& output, bool leadingSeparator,
|
||||
DataFormat dataFormat)
|
||||
ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator)
|
||||
{
|
||||
unsigned char offset = (unsigned char)(m_id.size() - 2);
|
||||
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)
|
||||
return result;
|
||||
bool empty = result == RESULT_EMPTY;
|
||||
offset = 0;
|
||||
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)
|
||||
return result;
|
||||
if (result == RESULT_EMPTY && !empty)
|
||||
@@ -432,18 +432,18 @@ result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
|
||||
return result;
|
||||
}
|
||||
|
||||
result_t Message::decodeLastData(ostringstream& output, bool leadingSeparator,
|
||||
DataFormat dataFormat, const char* fieldName, signed char fieldIndex)
|
||||
result_t Message::decodeLastData(ostringstream& output, OutputFormat outputFormat,
|
||||
bool leadingSeparator, const char* fieldName, signed char fieldIndex)
|
||||
{
|
||||
unsigned char offset = (unsigned char)(m_id.size() - 2);
|
||||
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)
|
||||
return result;
|
||||
bool empty = result == RESULT_EMPTY;
|
||||
offset = 0;
|
||||
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)
|
||||
return result;
|
||||
if (result == RESULT_EMPTY && !empty)
|
||||
|
||||
@@ -188,40 +188,40 @@ public:
|
||||
* @param partType the @a PartType of the data.
|
||||
* @param data the unescaped data @a SymbolString for reading binary 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 dataFormat the @a DataFormat to use.
|
||||
* @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.
|
||||
*/
|
||||
result_t decode(const PartType partType, SymbolString& data,
|
||||
ostringstream& output, bool leadingSeparator=false,
|
||||
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
ostringstream& output, OutputFormat outputFormat=0,
|
||||
bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
|
||||
/**
|
||||
* Decode all parts of a received message.
|
||||
* @param masterData the unescaped master 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 outputFormat the @a OutputFormat options to use.
|
||||
* @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.
|
||||
*/
|
||||
result_t decode(SymbolString& masterData, SymbolString& slaveData,
|
||||
ostringstream& output, bool leadingSeparator=false,
|
||||
DataFormat dataFormat=df_standard);
|
||||
ostringstream& output, OutputFormat outputFormat=0,
|
||||
bool leadingSeparator=false);
|
||||
|
||||
/**
|
||||
* Decode the value from the last stored 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 dataFormat the @a DataFormat to use.
|
||||
* @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.
|
||||
*/
|
||||
result_t decodeLastData(ostringstream& output, bool leadingSeparator=false,
|
||||
DataFormat dataFormat=df_standard, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
result_t decodeLastData(ostringstream& output, OutputFormat outputFormat=0,
|
||||
bool leadingSeparator=false, const char* fieldName=NULL, signed char fieldIndex=-1);
|
||||
|
||||
/**
|
||||
* Get the last seen slave data.
|
||||
|
||||
Reference in New Issue
Block a user