clearly separate master/slave symbolstrings

This commit is contained in:
john30
2017-02-26 17:34:22 +01:00
parent 1a878694d2
commit cc59b32f0d
13 changed files with 297 additions and 218 deletions
+26 -23
View File
@@ -71,9 +71,9 @@ result_t PollRequest::prepare(unsigned char ownMasterAddress) {
return result; return result;
} }
bool PollRequest::notify(result_t result, SymbolString& slave) { bool PollRequest::notify(result_t result, SlaveSymbolString& slave) {
if (result == RESULT_OK) { if (result == RESULT_OK) {
result = m_message->storeLastData(pt_slaveData, slave, m_index); result = m_message->storeLastData(slave, m_index);
if (result >= RESULT_OK && m_index+1 < m_message->getCount()) { if (result >= RESULT_OK && m_index+1 < m_message->getCount()) {
m_index++; m_index++;
result = prepare(m_master[0]); result = prepare(m_master[0]);
@@ -114,21 +114,21 @@ result_t ScanRequest::prepare(unsigned char ownMasterAddress) {
return result; return result;
} }
bool ScanRequest::notify(result_t result, SymbolString& slave) { bool ScanRequest::notify(result_t result, SlaveSymbolString& slave) {
unsigned char dstAddress = m_master[1]; unsigned char dstAddress = m_master[1];
if (result == RESULT_OK) { if (result == RESULT_OK) {
if (m_message == m_messageMap->getScanMessage()) { if (m_message == m_messageMap->getScanMessage()) {
Message* message = m_messageMap->getScanMessage(dstAddress); Message* message = m_messageMap->getScanMessage(dstAddress);
if (message != NULL) { if (message != NULL) {
m_message = message; m_message = message;
m_message->storeLastData(pt_masterData, m_master, m_index); // expected to work since this is a clone m_message->storeLastData(m_master, m_index); // expected to work since this is a clone
} }
} else if (m_message->getDstAddress() == SYN) { } else if (m_message->getDstAddress() == SYN) {
m_message = m_message->derive(dstAddress, true); m_message = m_message->derive(dstAddress, true);
m_messageMap->add(m_message); m_messageMap->add(m_message);
m_message->storeLastData(pt_masterData, m_master, m_index); // expected to work since this is a clone m_message->storeLastData(m_master, m_index); // expected to work since this is a clone
} }
result = m_message->storeLastData(pt_slaveData, slave, m_index); result = m_message->storeLastData(slave, m_index);
if (result >= RESULT_OK && m_index+1 < m_message->getCount()) { if (result >= RESULT_OK && m_index+1 < m_message->getCount()) {
m_index++; m_index++;
result = prepare(m_master[0]); result = prepare(m_master[0]);
@@ -180,7 +180,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave) {
} }
bool ActiveBusRequest::notify(result_t result, SymbolString& slave) { bool ActiveBusRequest::notify(result_t result, SlaveSymbolString& slave) {
if (result == RESULT_OK) { if (result == RESULT_OK) {
logDebug(lf_bus, "read res: %s", slave.getDataStr().c_str()); logDebug(lf_bus, "read res: %s", slave.getDataStr().c_str());
} }
@@ -189,10 +189,8 @@ bool ActiveBusRequest::notify(result_t result, SymbolString& slave) {
return false; return false;
} }
void GrabbedMessage::setLastData(SymbolString& master, SymbolString& slave) { void GrabbedMessage::setLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
m_lastMaster.clear();
m_lastMaster = master; m_lastMaster = master;
m_lastSlave.clear();
m_lastSlave = slave; m_lastSlave = slave;
m_count++; m_count++;
} }
@@ -277,7 +275,12 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
return true; return true;
} }
bool master = isMaster(dstAddress) || dstAddress == BROADCAST || m_lastSlave.size() <= 1 || m_lastSlave[0] == 0; bool master = isMaster(dstAddress) || dstAddress == BROADCAST || m_lastSlave.size() <= 1 || m_lastSlave[0] == 0;
SymbolString *input = master ? &m_lastMaster : &m_lastSlave; SymbolString *input;
if (master) {
input = &m_lastMaster;
} else {
input = &m_lastSlave;
}
unsigned char baseOffset = master ? 5 : 1; unsigned char baseOffset = master ? 5 : 1;
unsigned char remain = input->size(); unsigned char remain = input->size();
if (remain <= baseOffset) { if (remain <= baseOffset) {
@@ -324,7 +327,7 @@ void BusHandler::clear() {
m_scanResults.clear(); m_scanResults.clear();
} }
result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave) { result_t BusHandler::sendAndWait(MasterSymbolString& master, SlaveSymbolString& slave) {
result_t result = RESULT_ERR_NO_SIGNAL; result_t result = RESULT_ERR_NO_SIGNAL;
slave.clear(); slave.clear();
ActiveBusRequest request(master, slave); ActiveBusRequest request(master, slave);
@@ -355,8 +358,8 @@ result_t BusHandler::readFromBus(Message* message, string inputStr, const unsign
const unsigned char srcAddress) { const unsigned char srcAddress) {
unsigned char masterAddress = srcAddress == SYN ? m_ownMasterAddress : srcAddress; unsigned char masterAddress = srcAddress == SYN ? m_ownMasterAddress : srcAddress;
result_t ret = RESULT_EMPTY; result_t ret = RESULT_EMPTY;
SymbolString master(true); MasterSymbolString master;
SymbolString slave; SlaveSymbolString slave;
for (unsigned char index = 0; index < message->getCount(); index++) { for (unsigned char index = 0; index < message->getCount(); index++) {
istringstream input(inputStr); istringstream input(inputStr);
ret = message->prepareMaster(masterAddress, master, input, UI_FIELD_SEPARATOR, dstAddress, index); ret = message->prepareMaster(masterAddress, master, input, UI_FIELD_SEPARATOR, dstAddress, index);
@@ -370,7 +373,7 @@ result_t BusHandler::readFromBus(Message* message, string inputStr, const unsign
logError(lf_bus, "send message part %d: %s", index, getResultCode(ret)); logError(lf_bus, "send message part %d: %s", index, getResultCode(ret));
break; break;
} }
ret = message->storeLastData(pt_slaveData, slave, index); ret = message->storeLastData(slave, index);
if (ret < RESULT_OK) { if (ret < RESULT_OK) {
logError(lf_bus, "store message part %d: %s", index, getResultCode(ret)); logError(lf_bus, "store message part %d: %s", index, getResultCode(ret));
break; break;
@@ -1038,16 +1041,16 @@ void BusHandler::receiveCompleted() {
if (message && (message->getLastUpdateTime() == 0 || message->getLastSlaveData().size() < 10)) { if (message && (message->getLastUpdateTime() == 0 || message->getLastSlaveData().size() < 10)) {
// e.g. 10fe07040a b5564149303001248901 // e.g. 10fe07040a b5564149303001248901
m_seenAddresses[slaveAddress] |= SCAN_INIT; m_seenAddresses[slaveAddress] |= SCAN_INIT;
SymbolString idData; MasterSymbolString dummyMaster;
istringstream input; istringstream input;
result_t result = message->prepareMaster(m_ownMasterAddress, idData, input); result_t result = message->prepareMaster(m_ownMasterAddress, dummyMaster, input);
if (result == RESULT_OK) { if (result == RESULT_OK) {
idData.clear(); SlaveSymbolString idData;
idData.push_back(9); idData.push_back(9);
for (size_t i = 5; i <= 5+9; i++) { for (size_t i = 5; i <= 5+9; i++) {
idData.push_back(m_command[i]); idData.push_back(m_command[i]);
} }
result = message->storeLastData(pt_slaveData, idData, 0); result = message->storeLastData(idData, 0);
} }
if (result == RESULT_OK) { if (result == RESULT_OK) {
m_seenAddresses[slaveAddress] |= SCAN_DONE; m_seenAddresses[slaveAddress] |= SCAN_DONE;
@@ -1253,7 +1256,7 @@ void BusHandler::formatSeenInfo(ostringstream& output) {
} }
} }
result_t BusHandler::scanAndWait(unsigned char dstAddress, SymbolString& slave) { result_t BusHandler::scanAndWait(unsigned char dstAddress, SlaveSymbolString& slave) {
if (!isValidAddress(dstAddress) || isMaster(dstAddress)) { if (!isValidAddress(dstAddress) || isMaster(dstAddress)) {
return RESULT_ERR_INVALID_ADDR; return RESULT_ERR_INVALID_ADDR;
} }
@@ -1263,7 +1266,7 @@ result_t BusHandler::scanAndWait(unsigned char dstAddress, SymbolString& slave)
return RESULT_ERR_NOTFOUND; return RESULT_ERR_NOTFOUND;
} }
istringstream input; istringstream input;
SymbolString master(true); MasterSymbolString master;
result_t result = scanMessage->prepareMaster(m_ownMasterAddress, master, input, UI_FIELD_SEPARATOR, dstAddress); result_t result = scanMessage->prepareMaster(m_ownMasterAddress, master, input, UI_FIELD_SEPARATOR, dstAddress);
if (result == RESULT_OK) { if (result == RESULT_OK) {
result = sendAndWait(master, slave); result = sendAndWait(master, slave);
@@ -1272,7 +1275,7 @@ result_t BusHandler::scanAndWait(unsigned char dstAddress, SymbolString& slave)
if (message != NULL && message != scanMessage) { if (message != NULL && message != scanMessage) {
scanMessage = message; scanMessage = message;
// update the cache, expected to work since this is a clone // update the cache, expected to work since this is a clone
scanMessage->storeLastData(pt_masterData, master, 0); scanMessage->storeLastData(master, 0);
} }
} }
if (result != RESULT_ERR_NO_SIGNAL) { if (result != RESULT_ERR_NO_SIGNAL) {
@@ -1282,7 +1285,7 @@ result_t BusHandler::scanAndWait(unsigned char dstAddress, SymbolString& slave)
if (result != RESULT_OK || slave.size() == 0) { // avoid "invalid position" during decode if (result != RESULT_OK || slave.size() == 0) { // avoid "invalid position" during decode
return result; return result;
} }
return scanMessage->storeLastData(pt_slaveData, slave, 0); // update the cache return scanMessage->storeLastData(slave, 0); // update the cache
} }
bool BusHandler::enableGrab(bool enable) { bool BusHandler::enableGrab(bool enable) {
+34 -34
View File
@@ -106,10 +106,10 @@ class BusRequest {
public: public:
/** /**
* Constructor. * Constructor.
* @param master the master data @a SymbolString to send. * @param master the master data @a MasterSymbolString to send.
* @param deleteOnFinish whether to automatically delete this @a BusRequest when finished. * @param deleteOnFinish whether to automatically delete this @a BusRequest when finished.
*/ */
BusRequest(SymbolString& master, const bool deleteOnFinish) BusRequest(MasterSymbolString& master, const bool deleteOnFinish)
: m_master(master), m_busLostRetries(0), : m_master(master), m_busLostRetries(0),
m_deleteOnFinish(deleteOnFinish) {} m_deleteOnFinish(deleteOnFinish) {}
@@ -121,15 +121,15 @@ class BusRequest {
/** /**
* Notify the request of the specified result. * Notify the request of the specified result.
* @param result the result of the request. * @param result the result of the request.
* @param slave the slave data @a SymbolString received. * @param slave the @a SlaveSymbolString received.
* @return true if the request needs to be restarted. * @return true if the request needs to be restarted.
*/ */
virtual bool notify(result_t result, SymbolString& slave) = 0; virtual bool notify(result_t result, SlaveSymbolString& slave) = 0;
protected: protected:
/** the master data @a SymbolString to send. */ /** the master data @a MasterSymbolString to send. */
SymbolString& m_master; MasterSymbolString& m_master;
/** the number of times a send is repeated due to lost arbitration. */ /** the number of times a send is repeated due to lost arbitration. */
unsigned int m_busLostRetries; unsigned int m_busLostRetries;
@@ -166,12 +166,12 @@ class PollRequest : public BusRequest {
result_t prepare(unsigned char masterAddress); result_t prepare(unsigned char masterAddress);
// @copydoc // @copydoc
virtual bool notify(result_t result, SymbolString& slave); virtual bool notify(result_t result, SlaveSymbolString& slave);
private: private:
/** the master data @a SymbolString. */ /** the master data @a MasterSymbolString. */
SymbolString m_master{true}; MasterSymbolString m_master;
/** the associated @a Message. */ /** the associated @a Message. */
Message* m_message; Message* m_message;
@@ -215,15 +215,15 @@ class ScanRequest : public BusRequest {
result_t prepare(unsigned char masterAddress); result_t prepare(unsigned char masterAddress);
// @copydoc // @copydoc
virtual bool notify(result_t result, SymbolString& slave); virtual bool notify(result_t result, SlaveSymbolString& slave);
private: private:
/** the @a MessageMap instance. */ /** the @a MessageMap instance. */
MessageMap* m_messageMap; MessageMap* m_messageMap;
/** the master data @a SymbolString. */ /** the master data @a MasterSymbolString. */
SymbolString m_master{true}; MasterSymbolString m_master;
/** the currently queried @a Message. */ /** the currently queried @a Message. */
Message* m_message; Message* m_message;
@@ -257,10 +257,10 @@ class ActiveBusRequest : public BusRequest {
public: public:
/** /**
* Constructor. * Constructor.
* @param master the master data @a SymbolString to send. * @param master the master data @a MasterSymbolString to send.
* @param slave reference to @a SymbolString for filling in the received slave data. * @param slave reference to @a SlaveSymbolString for filling in the received slave data.
*/ */
ActiveBusRequest(SymbolString& master, SymbolString& slave) ActiveBusRequest(MasterSymbolString& master, SlaveSymbolString& slave)
: BusRequest(master, false), m_result(RESULT_ERR_NO_SIGNAL), m_slave(slave) {} : BusRequest(master, false), m_result(RESULT_ERR_NO_SIGNAL), m_slave(slave) {}
/** /**
@@ -269,15 +269,15 @@ class ActiveBusRequest : public BusRequest {
virtual ~ActiveBusRequest() {} virtual ~ActiveBusRequest() {}
// @copydoc // @copydoc
virtual bool notify(result_t result, SymbolString& slave); virtual bool notify(result_t result, SlaveSymbolString& slave);
private: private:
/** the result of handling the request. */ /** the result of handling the request. */
result_t m_result; result_t m_result;
/** reference to @a SymbolString for filling in the received slave data. */ /** reference to @a SlaveSymbolString for filling in the received slave data. */
SymbolString& m_slave; SlaveSymbolString& m_slave;
}; };
@@ -302,10 +302,10 @@ class GrabbedMessage {
/** /**
* Set the last received data. * Set the last received data.
* @param master the last master @a SymbolString. * @param master the last @a MasterSymbolString.
* @param slave the last slave @a SymbolString. * @param slave the last @a SymbolString.
*/ */
void setLastData(SymbolString& master, SymbolString& slave); void setLastData(MasterSymbolString& master, SlaveSymbolString& slave);
/** /**
* Dump the last received data and message count to the output. * Dump the last received data and message count to the output.
@@ -320,11 +320,11 @@ class GrabbedMessage {
private: private:
/** the last master @a SymbolString. */ /** the last @a MasterSymbolString. */
SymbolString m_lastMaster; MasterSymbolString m_lastMaster;
/** the last slave @a SymbolString. */ /** the last @a SlaveSymbolString. */
SymbolString m_lastSlave; SlaveSymbolString m_lastSlave;
/** the number of times this message was seen. */ /** the number of times this message was seen. */
unsigned int m_count; unsigned int m_count;
@@ -401,11 +401,11 @@ class BusHandler : public WaitThread {
/** /**
* Send a message on the bus and wait for the answer. * 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 @a MasterSymbolString with the master data to send.
* @param slave the @a SymbolString that will be filled with retrieved slave data. * @param slave the @a SlaveSymbolString that will be filled with retrieved slave data.
* @return the result code. * @return the result code.
*/ */
result_t sendAndWait(SymbolString& master, SymbolString& slave); result_t sendAndWait(MasterSymbolString& master, SlaveSymbolString& slave);
/** /**
* Prepare the master part for the @a Message, send it to the bus and wait for the answer. * Prepare the master part for the @a Message, send it to the bus and wait for the answer.
@@ -458,10 +458,10 @@ class BusHandler : public WaitThread {
/** /**
* Send a scan message on the bus and wait for the answer. * Send a scan message on the bus and wait for the answer.
* @param dstAddress the destination slave address to send to. * @param dstAddress the destination slave address to send to.
* @param slave the @a SymbolString that will be filled with retrieved slave data. * @param slave the @a SlaveSymbolString that will be filled with retrieved slave data.
* @return the result code. * @return the result code.
*/ */
result_t scanAndWait(unsigned char dstAddress, SymbolString& slave); result_t scanAndWait(unsigned char dstAddress, SlaveSymbolString& slave);
/** /**
* Start or stop grabbing unknown messages. * Start or stop grabbing unknown messages.
@@ -647,11 +647,11 @@ class BusHandler : public WaitThread {
/** whether the current message part is being repeated. */ /** whether the current message part is being repeated. */
bool m_repeat; bool m_repeat;
/** the received command. */ /** the received command @a MasterSymbolString. */
SymbolString m_command{true}; MasterSymbolString m_command;
/** the received response or response to send. */ /** the received response @a SlaveSymbolString or response to send. */
SymbolString m_response; SlaveSymbolString m_response;
/** the participating bus addresses seen so far (0 if not seen yet, or combination of @a SEEN bits). */ /** the participating bus addresses seen so far (0 if not seen yet, or combination of @a SEEN bits). */
unsigned char m_seenAddresses[256]; unsigned char m_seenAddresses[256];
+6 -2
View File
@@ -875,7 +875,7 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
return RESULT_OK; return RESULT_OK;
} }
result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolString& data, string& relativeFile, result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSymbolString& data, string& relativeFile,
bool verbose) { bool verbose) {
PartType partType; PartType partType;
if (isMaster(address)) { if (isMaster(address)) {
@@ -1053,6 +1053,9 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolS
* @return the exit code. * @return the exit code.
*/ */
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
/* if (argc >= 2 && strcmp(argv[1], "config") == 0) {
return config_main(argc, argv);
}*/
struct argp aargp = { argpoptions, parse_opt, NULL, argpdoc, datahandler_getargs(), NULL, NULL }; struct argp aargp = { argpoptions, parse_opt, NULL, argpdoc, datahandler_getargs(), NULL, NULL };
int arg_index = -1; int arg_index = -1;
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0); setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
@@ -1081,7 +1084,8 @@ int main(int argc, char* argv[]) {
logError(lf_main, "invalid scan message %s: missing \"/\"", arg.c_str()); logError(lf_main, "invalid scan message %s: missing \"/\"", arg.c_str());
continue; continue;
} }
SymbolString master(false), slave(false); MasterSymbolString master;
SlaveSymbolString slave;
result_t res = master.parseHex(arg.substr(0, pos)); result_t res = master.parseHex(arg.substr(0, pos));
if (res == RESULT_OK) { if (res == RESULT_OK) {
res = slave.parseHex(arg.substr(pos+1)); res = slave.parseHex(arg.substr(pos+1));
+2 -2
View File
@@ -103,12 +103,12 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose = false, bool denyRe
* @param messages the @a MessageMap to load the messages into. * @param messages the @a MessageMap to load the messages into.
* @param address the address of the scan participant * @param address the address of the scan participant
* (either master for broadcast master data or slave for read slave data). * (either master for broadcast master data or slave for read slave data).
* @param data the scan @a SymbolString for which to load the configuration file. * @param data the scan @a SlaveSymbolString for which to load the configuration file.
* @param relativeFile the string in which the name of the configuration file is stored on success. * @param relativeFile the string in which the name of the configuration file is stored on success.
* @param verbose whether to verbosely log problems. * @param verbose whether to verbosely log problems.
* @return the result code. * @return the result code.
*/ */
result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolString& data, string& relativeFile, result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSymbolString& data, string& relativeFile,
bool verbose = false); bool verbose = false);
} // namespace ebusd } // namespace ebusd
+13 -13
View File
@@ -233,7 +233,7 @@ void MainLoop::run() {
result = m_busHandler->startScan(true, "*"); result = m_busHandler->startScan(true, "*");
} else { } else {
logNotice(lf_main, "starting initial scan for %2.2x", m_initialScan); logNotice(lf_main, "starting initial scan for %2.2x", m_initialScan);
SymbolString slave; SlaveSymbolString slave;
result = m_busHandler->scanAndWait(m_initialScan, slave); result = m_busHandler->scanAndWait(m_initialScan, slave);
Message* message = m_messages->getScanMessage(m_initialScan); Message* message = m_messages->getScanMessage(m_initialScan);
if (result == RESULT_OK && message != NULL) { if (result == RESULT_OK && message != NULL) {
@@ -257,7 +257,7 @@ void MainLoop::run() {
taskDelay = 5; taskDelay = 5;
lastScanAddress = 0; lastScanAddress = 0;
} else { } else {
SymbolString slave; SlaveSymbolString slave;
if (scanned) { if (scanned) {
Message* message = m_messages->getScanMessage(lastScanAddress); Message* message = m_messages->getScanMessage(lastScanAddress);
slave = message->getLastSlaveData(); slave = message->getLastSlaveData();
@@ -472,7 +472,7 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn
return "ERR: command not found"; return "ERR: command not found";
} }
result_t MainLoop::parseHexMaster(vector<string> &args, size_t argPos, SymbolString& master, result_t MainLoop::parseHexMaster(vector<string> &args, size_t argPos, MasterSymbolString& master,
unsigned char srcAddress) { unsigned char srcAddress) {
ostringstream msg; ostringstream msg;
while (argPos < args.size()) { while (argPos < args.size()) {
@@ -614,7 +614,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
time(&now); time(&now);
if (hex && argPos > 0) { if (hex && argPos > 0) {
SymbolString master(true); MasterSymbolString master;
result_t ret = parseHexMaster(args, argPos, master, srcAddress); result_t ret = parseHexMaster(args, argPos, master, srcAddress);
if (ret != RESULT_OK) { if (ret != RESULT_OK) {
return getResultCode(ret); return getResultCode(ret);
@@ -642,13 +642,13 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
if (srcAddress == SYN if (srcAddress == SYN
&& (message->getLastUpdateTime() + maxAge > now && (message->getLastUpdateTime() + maxAge > now
|| (message->isPassive() && message->getLastUpdateTime() != 0))) { || (message->isPassive() && message->getLastUpdateTime() != 0))) {
SymbolString& slave = message->getLastSlaveData(); SlaveSymbolString& slave = message->getLastSlaveData();
logNotice(lf_main, "hex read %s %s from cache", message->getCircuit().c_str(), message->getName().c_str()); logNotice(lf_main, "hex read %s %s from cache", message->getCircuit().c_str(), message->getName().c_str());
return slave.getDataStr(); return slave.getDataStr();
} }
// send message // send message
SymbolString slave; SlaveSymbolString slave;
ret = m_busHandler->sendAndWait(master, slave); ret = m_busHandler->sendAndWait(master, slave);
if (ret == RESULT_OK) { if (ret == RESULT_OK) {
@@ -761,7 +761,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
if (verbosity & OF_NAMES) { if (verbosity & OF_NAMES) {
result << message->getCircuit() << " " << message->getName() << " "; result << message->getCircuit() << " " << message->getName() << " ";
} }
ret = message->decodeLastData(pt_slaveData, result, verbosity|(numeric?OF_NUMERIC:0), false, ret = message->decodeLastSlaveData(result, verbosity|(numeric?OF_NUMERIC:0), false,
fieldIndex == -2 ? NULL : fieldName.c_str(), fieldIndex); fieldIndex == -2 ? NULL : fieldName.c_str(), fieldIndex);
if (ret < RESULT_OK) { if (ret < RESULT_OK) {
logError(lf_main, "read %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(), logError(lf_main, "read %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(),
@@ -821,7 +821,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
} }
if (hex && argPos > 0) { if (hex && argPos > 0) {
SymbolString master(true); MasterSymbolString master;
result_t ret = parseHexMaster(args, argPos, master, srcAddress); result_t ret = parseHexMaster(args, argPos, master, srcAddress);
if (ret != RESULT_OK) { if (ret != RESULT_OK) {
return getResultCode(ret); return getResultCode(ret);
@@ -844,7 +844,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
return getResultCode(RESULT_ERR_INVALID_ARG); // non-matching circuit return getResultCode(RESULT_ERR_INVALID_ARG); // non-matching circuit
} }
// send message // send message
SymbolString slave; SlaveSymbolString slave;
ret = m_busHandler->sendAndWait(master, slave); ret = m_busHandler->sendAndWait(master, slave);
if (ret == RESULT_OK) { if (ret == RESULT_OK) {
@@ -916,7 +916,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
return getResultCode(RESULT_OK); return getResultCode(RESULT_OK);
} }
ret = message->decodeLastData(pt_slaveData, result); // decode data ret = message->decodeLastSlaveData(result); // decode data
if (ret >= RESULT_OK && result.str().empty()) { if (ret >= RESULT_OK && result.str().empty()) {
logNotice(lf_main, "write %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(), logNotice(lf_main, "write %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(),
getResultCode(ret)); getResultCode(ret));
@@ -956,7 +956,7 @@ string MainLoop::executeHex(vector<string> &args) {
} }
if (argPos > 0) { if (argPos > 0) {
SymbolString master(true); MasterSymbolString master;
result_t ret = parseHexMaster(args, argPos, master, srcAddress); result_t ret = parseHexMaster(args, argPos, master, srcAddress);
if (ret != RESULT_OK) { if (ret != RESULT_OK) {
return getResultCode(ret); return getResultCode(ret);
@@ -964,7 +964,7 @@ string MainLoop::executeHex(vector<string> &args) {
logNotice(lf_main, "hex cmd: %s", master.getDataStr().c_str()); logNotice(lf_main, "hex cmd: %s", master.getDataStr().c_str());
// send message // send message
SymbolString slave; SlaveSymbolString slave;
ret = m_busHandler->sendAndWait(master, slave); ret = m_busHandler->sendAndWait(master, slave);
if (ret == RESULT_OK) { if (ret == RESULT_OK) {
@@ -1305,7 +1305,7 @@ string MainLoop::executeScan(vector<string> &args, string levels) {
if (result != RESULT_OK) { if (result != RESULT_OK) {
return getResultCode(result); return getResultCode(result);
} }
SymbolString slave; SlaveSymbolString slave;
result = m_busHandler->scanAndWait(dstAddress, slave); result = m_busHandler->scanAndWait(dstAddress, slave);
if (result != RESULT_OK) { if (result != RESULT_OK) {
return getResultCode(result); return getResultCode(result);
+3 -2
View File
@@ -145,11 +145,12 @@ class MainLoop : public Thread, DeviceListener {
* Parse the hex master message from the remaining arguments. * Parse the hex master message from the remaining arguments.
* @param args the arguments passed to the command. * @param args the arguments passed to the command.
* @param argPos the index of the first argument to parse. * @param argPos the index of the first argument to parse.
* @param master the master @a SymbolString to write the data to. * @param master the @a MasterSymbolString to write the data to.
* @param srcAddress the source address to set, or @a SYN for the own master address. * @param srcAddress the source address to set, or @a SYN for the own master address.
* @return the result from parsing the arguments. * @return the result from parsing the arguments.
*/ */
result_t parseHexMaster(vector<string> &args, size_t argPos, SymbolString& master, unsigned char srcAddress = SYN); result_t parseHexMaster(vector<string> &args, size_t argPos, MasterSymbolString& master,
unsigned char srcAddress = SYN);
/** /**
* Get the access levels associated with the specified user name. * Get the access levels associated with the specified user name.
+4 -4
View File
@@ -77,14 +77,14 @@ int main() {
string check[5] = checks[i]; string check[5] = checks[i];
istringstream isstr(check[0]); istringstream isstr(check[0]);
string expectStr = check[1]; string expectStr = check[1];
SymbolString mstr(true); MasterSymbolString mstr;
result_t result = mstr.parseHex(check[2]); result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true; error = true;
continue; continue;
} }
SymbolString sstr; SlaveSymbolString sstr;
result = sstr.parseHex(check[3]); result = sstr.parseHex(check[3]);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
@@ -130,14 +130,14 @@ int main() {
cout << "\": create OK" << endl; cout << "\": create OK" << endl;
ostringstream output; ostringstream output;
SymbolString writeMstr(true); MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10)); result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result) cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl; << endl;
error = true; error = true;
} }
SymbolString writeSstr; SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2)); result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result) cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
+65 -46
View File
@@ -155,7 +155,7 @@ uint64_t Message::createKey(const vector<unsigned char> id,
return key; return key;
} }
uint64_t Message::createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination) { uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLength, bool anyDestination) {
if (master.size() < 5) { if (master.size() < 5) {
return INVALID_KEY; return INVALID_KEY;
} }
@@ -532,7 +532,7 @@ bool Message::checkIdPrefix(vector<unsigned char>& id) {
return true; return true;
} }
bool Message::checkId(SymbolString& master, unsigned char* index) { bool Message::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength(); unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
return false; return false;
@@ -590,7 +590,7 @@ bool Message::hasField(const char* fieldName, bool numeric) {
return m_data->hasField(fieldName, numeric); return m_data->hasField(fieldName, numeric);
} }
result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& master, result_t Message::prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
istringstream& input, char separator, istringstream& input, char separator,
const unsigned char dstAddress, unsigned char index) { const unsigned char dstAddress, unsigned char index) {
if (m_isPassive) { if (m_isPassive) {
@@ -612,14 +612,15 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
if (result != RESULT_OK) { if (result != RESULT_OK) {
return result; return result;
} }
result = storeLastData(pt_masterData, master, index); result = storeLastData(master, index);
if (result < RESULT_OK) { if (result < RESULT_OK) {
return result; return result;
} }
return RESULT_OK; return RESULT_OK;
} }
result_t Message::prepareMasterPart(SymbolString& master, istringstream& input, char separator, unsigned char index) { result_t Message::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
if (index != 0) { if (index != 0) {
return RESULT_ERR_NOTFOUND; return RESULT_ERR_NOTFOUND;
} }
@@ -636,7 +637,7 @@ result_t Message::prepareMasterPart(SymbolString& master, istringstream& input,
return result; return result;
} }
result_t Message::prepareSlave(istringstream& input, SymbolString& slave) { result_t Message::prepareSlave(istringstream& input, SlaveSymbolString& slave) {
if (m_isWrite) { if (m_isWrite) {
return RESULT_ERR_INVALID_ARG; // prepare not possible return RESULT_ERR_INVALID_ARG; // prepare not possible
} }
@@ -655,21 +656,19 @@ result_t Message::prepareSlave(istringstream& input, SymbolString& slave) {
return result; return result;
} }
result_t Message::storeLastData(SymbolString& master, SymbolString& slave) { result_t Message::storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
result_t result = storeLastData(pt_masterData, master, 0); result_t result = storeLastData(master, 0);
if (result >= RESULT_OK) { if (result >= RESULT_OK) {
result = storeLastData(pt_slaveData, slave, 0); result = storeLastData(slave, 0);
} }
return result; return result;
} }
result_t Message::storeLastData(const PartType partType, SymbolString& data, unsigned char index) { result_t Message::storeLastData(MasterSymbolString& data, unsigned char index) {
if (data.size() > 0 if (data.size() > 0
&& (m_isWrite || this->m_dstAddress == BROADCAST || partType == pt_slaveData && (m_isWrite || this->m_dstAddress == BROADCAST || isMaster(this->m_dstAddress))) {
|| (partType == pt_masterData && isMaster(this->m_dstAddress)))) {
time(&m_lastUpdateTime); time(&m_lastUpdateTime);
} }
if (partType == pt_masterData) {
switch (data.compareTo(m_lastMasterData)) { switch (data.compareTo(m_lastMasterData)) {
case 1: // completely different case 1: // completely different
m_lastChangeTime = m_lastUpdateTime; m_lastChangeTime = m_lastUpdateTime;
@@ -679,25 +678,37 @@ result_t Message::storeLastData(const PartType partType, SymbolString& data, uns
m_lastMasterData = data; m_lastMasterData = data;
break; break;
} }
} else if (partType == pt_slaveData) { return RESULT_OK;
}
result_t Message::storeLastData(SlaveSymbolString& data, unsigned char index) {
if (data.size() > 0) {
time(&m_lastUpdateTime);
}
if (data != m_lastSlaveData) { if (data != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime; m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = data; m_lastSlaveData = data;
} }
}
return RESULT_OK; return RESULT_OK;
} }
result_t Message::decodeLastData(const PartType partType, result_t Message::decodeLastMasterData(ostringstream& output, OutputFormat outputFormat,
ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) { bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
unsigned char offset; unsigned char offset = (unsigned char)(m_id.size() - 2);
if (partType == pt_masterData) { result_t result = m_data->read(pt_masterData, m_lastMasterData, offset,
offset = (unsigned char)(m_id.size() - 2); output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
} else { if (result < RESULT_OK) {
offset = 0; return result;
} }
result_t result = m_data->read(partType, partType == pt_masterData ? m_lastMasterData : m_lastSlaveData, offset, if (result == RESULT_EMPTY && fieldName != NULL) {
return RESULT_ERR_NOTFOUND;
}
return result;
}
result_t Message::decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
result_t result = m_data->read(pt_slaveData, m_lastSlaveData, 0,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex); output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) { if (result < RESULT_OK) {
return result; return result;
@@ -873,13 +884,13 @@ ChainedMessage::ChainedMessage(const string circuit, const string level, const s
m_ids(ids), m_lengths(lengths), m_ids(ids), m_lengths(lengths),
m_maxTimeDiff(m_ids.size()*15) { // 15 seconds per message m_maxTimeDiff(m_ids.size()*15) { // 15 seconds per message
size_t cnt = ids.size(); size_t cnt = ids.size();
m_lastMasterDatas = reinterpret_cast<SymbolString**>(calloc(cnt, sizeof(SymbolString*))); m_lastMasterDatas = reinterpret_cast<MasterSymbolString**>(calloc(cnt, sizeof(MasterSymbolString*)));
m_lastSlaveDatas = reinterpret_cast<SymbolString**>(calloc(cnt, sizeof(SymbolString*))); m_lastSlaveDatas = reinterpret_cast<SlaveSymbolString**>(calloc(cnt, sizeof(SlaveSymbolString*)));
m_lastMasterUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t))); m_lastMasterUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t)));
m_lastSlaveUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t))); m_lastSlaveUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t)));
for (size_t index = 0; index < cnt; index++) { for (size_t index = 0; index < cnt; index++) {
m_lastMasterDatas[index] = new SymbolString(true); m_lastMasterDatas[index] = new MasterSymbolString;
m_lastSlaveDatas[index] = new SymbolString(); m_lastSlaveDatas[index] = new SlaveSymbolString();
} }
} }
@@ -908,7 +919,7 @@ Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned c
return result; return result;
} }
bool ChainedMessage::checkId(SymbolString& master, unsigned char* index) { bool ChainedMessage::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength(); unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
return false; return false;
@@ -969,13 +980,13 @@ bool ChainedMessage::checkId(Message& other) {
return false; return false;
} }
result_t ChainedMessage::prepareMasterPart(SymbolString& master, istringstream& input, char separator, result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) { unsigned char index) {
size_t cnt = getCount(); size_t cnt = getCount();
if (index >= cnt) { if (index >= cnt) {
return RESULT_ERR_NOTFOUND; return RESULT_ERR_NOTFOUND;
} }
SymbolString allData(true); MasterSymbolString allData;
result_t result = m_data->write(input, pt_masterData, allData, 0, separator); result_t result = m_data->write(input, pt_masterData, allData, 0, separator);
if (result != RESULT_OK) { if (result != RESULT_OK) {
return result; return result;
@@ -1007,24 +1018,23 @@ result_t ChainedMessage::prepareMasterPart(SymbolString& master, istringstream&
return result; return result;
} }
result_t ChainedMessage::storeLastData(SymbolString& master, SymbolString& slave) { result_t ChainedMessage::storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
// determine index from master ID // determine index from master ID
unsigned char index = 0; unsigned char index = 0;
if (checkId(master, &index)) { if (checkId(master, &index)) {
result_t result = storeLastData(pt_masterData, master, index); result_t result = storeLastData(master, index);
if (result >= RESULT_OK) { if (result >= RESULT_OK) {
result = storeLastData(pt_slaveData, slave, index); result = storeLastData(slave, index);
} }
return result; return result;
} }
return RESULT_ERR_INVALID_ARG; return RESULT_ERR_INVALID_ARG;
} }
result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& data, unsigned char index) { result_t ChainedMessage::storeLastData(MasterSymbolString& data, unsigned char index) {
if (index >= m_ids.size()) { if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG; return RESULT_ERR_INVALID_ARG;
} }
if (partType == pt_masterData) {
switch (data.compareTo(*m_lastMasterDatas[index])) { switch (data.compareTo(*m_lastMasterDatas[index])) {
case 1: // completely different case 1: // completely different
*m_lastMasterDatas[index] = data; *m_lastMasterDatas[index] = data;
@@ -1034,15 +1044,24 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
break; break;
} }
time(&m_lastMasterUpdateTimes[index]); time(&m_lastMasterUpdateTimes[index]);
} else if (partType == pt_slaveData) { return combineLastParts();
}
result_t ChainedMessage::storeLastData(SlaveSymbolString& data, unsigned char index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
if (data != *m_lastSlaveDatas[index]) { if (data != *m_lastSlaveDatas[index]) {
*m_lastSlaveDatas[index] = data; *m_lastSlaveDatas[index] = data;
} }
time(&m_lastSlaveUpdateTimes[index]); time(&m_lastSlaveUpdateTimes[index]);
} return combineLastParts();
}
result_t ChainedMessage::combineLastParts() {
// check arrival time of all parts // check arrival time of all parts
time_t minTime = 0, maxTime = 0; time_t minTime = 0, maxTime = 0;
for (index = 0; index < m_ids.size(); index++) { for (unsigned char index = 0; index < m_ids.size(); index++) {
if (index == 0) { if (index == 0) {
minTime = maxTime = m_lastMasterUpdateTimes[index]; minTime = maxTime = m_lastMasterUpdateTimes[index];
} else { } else {
@@ -1064,10 +1083,10 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
} }
} }
// everything was completely retrieved in short time // everything was completely retrieved in short time
SymbolString master(true); MasterSymbolString master;
SymbolString slave; SlaveSymbolString slave;
size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN
for (index = 0; index < m_ids.size(); index++) { for (unsigned char index = 0; index < m_ids.size(); index++) {
SymbolString* add = m_lastMasterDatas[index]; SymbolString* add = m_lastMasterDatas[index];
size_t end = 5+(*add)[4]; size_t end = 5+(*add)[4];
for (size_t pos = index == 0 ? 0 : offset; pos < end; pos++) { for (size_t pos = index == 0 ? 0 : offset; pos < end; pos++) {
@@ -1085,9 +1104,9 @@ result_t ChainedMessage::storeLastData(const PartType partType, SymbolString& da
} }
master[4] = (unsigned char)(master.size()-5); master[4] = (unsigned char)(master.size()-5);
slave[0] = (unsigned char)(slave.size()-1); slave[0] = (unsigned char)(slave.size()-1);
result_t result = Message::storeLastData(pt_masterData, master, 0); result_t result = Message::storeLastData(master, 0);
if (result == RESULT_OK) { if (result == RESULT_OK) {
result = Message::storeLastData(pt_slaveData, slave, 0); result = Message::storeLastData(slave, 0);
} }
return result; return result;
} }
@@ -1116,9 +1135,9 @@ void ChainedMessage::dumpColumn(ostream& output, column_t column, bool withCondi
/** /**
* Get the first available @a Message from the list. * Get the first available @a Message from the list.
* @param messages the list of @a Message instances to check. * @param messages the list of @a Message instances to check.
* @param sameIdExtAs the optional @a Message to check for having the same ID. * @param sameIdExtAs the optional @a MasterSymbolString to check for having the same ID.
*/ */
Message* getFirstAvailable(vector<Message*> &messages, SymbolString* sameIdExtAs) { Message* getFirstAvailable(vector<Message*> &messages, MasterSymbolString* sameIdExtAs) {
for (vector<Message*>::iterator msgIt = messages.begin(); msgIt != messages.end(); msgIt++) { for (vector<Message*>::iterator msgIt = messages.begin(); msgIt != messages.end(); msgIt++) {
Message* message = *msgIt; Message* message = *msgIt;
if (sameIdExtAs && !message->checkId(*sameIdExtAs)) { if (sameIdExtAs && !message->checkId(*sameIdExtAs)) {
@@ -2034,7 +2053,7 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
return ret; return ret;
} }
Message* MessageMap::find(SymbolString& master, bool anyDestination, Message* MessageMap::find(MasterSymbolString& master, bool anyDestination,
const bool withRead, const bool withWrite, const bool withPassive) { const bool withRead, const bool withWrite, const bool withPassive) {
if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) { if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) {
return m_scanMessage; return m_scanMessage;
+67 -40
View File
@@ -173,13 +173,13 @@ class Message {
const unsigned char srcAddress, const unsigned char dstAddress); const unsigned char srcAddress, const unsigned char dstAddress);
/** /**
* Calculate the key for the master @a SymbolString. * Calculate the key for the @a MasterSymbolString.
* @param master the master @a SymbolString. * @param master the @a MasterSymbolString.
* @param maxIdLength the maximum ID length to use * @param maxIdLength the maximum ID length to use
* @param anyDestination @p true to use the special @a SYN as destination address in the key. * @param anyDestination @p true to use the special @a SYN as destination address in the key.
* @return the key for the ID, or -1LL if the data is invalid. * @return the key for the ID, or -1LL if the data is invalid.
*/ */
static uint64_t createKey(SymbolString& master, static uint64_t createKey(MasterSymbolString& master,
unsigned char maxIdLength, bool anyDestination = false); unsigned char maxIdLength, bool anyDestination = false);
/** /**
@@ -349,11 +349,11 @@ class Message {
/** /**
* Check the ID against the master @a SymbolString data. * Check the ID against the master @a SymbolString data.
* @param master the master @a SymbolString to check against. * @param master the @a MasterSymbolString to check against.
* @param index the variable in which to store the message part index, or NULL to ignore. * @param index the variable in which to store the message part index, or NULL to ignore.
* @return true if the ID matches, false otherwise. * @return true if the ID matches, false otherwise.
*/ */
virtual bool checkId(SymbolString& master, unsigned char* index = NULL); virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
/** /**
* Check the ID against the other @a Message. * Check the ID against the other @a Message.
@@ -421,14 +421,14 @@ class Message {
/** /**
* Prepare the master @a SymbolString for sending a query or command to the bus. * Prepare the master @a SymbolString for sending a query or command to the bus.
* @param srcAddress the source address to set. * @param srcAddress the source address to set.
* @param master the master data @a SymbolString for writing symbols to. * @param master the @a MasterSymbolString for writing symbols to.
* @param input the @a istringstream to parse the formatted value(s) from. * @param input the @a istringstream to parse the formatted value(s) from.
* @param separator the separator character between multiple fields. * @param separator the separator character between multiple fields.
* @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction. * @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction.
* @param index the index of the part to prepare. * @param index the index of the part to prepare.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
result_t prepareMaster(const unsigned char srcAddress, SymbolString& master, result_t prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
istringstream& input, char separator = UI_FIELD_SEPARATOR, istringstream& input, char separator = UI_FIELD_SEPARATOR,
const unsigned char dstAddress = SYN, unsigned char index = 0); const unsigned char dstAddress = SYN, unsigned char index = 0);
@@ -436,44 +436,51 @@ class Message {
protected: protected:
/** /**
* Prepare a part of the master data @a SymbolString for sending (everything including NN). * Prepare a part of the master data @a SymbolString for sending (everything including NN).
* @param master the master data @a SymbolString for writing symbols to. * @param master the @a MasterSymbolString for writing symbols to.
* @param input the @a istringstream to parse the formatted value(s) from. * @param input the @a istringstream to parse the formatted value(s) from.
* @param separator the separator character between multiple fields. * @param separator the separator character between multiple fields.
* @param index the index of the part to prepare. * @param index the index of the part to prepare.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
virtual result_t prepareMasterPart(SymbolString& master, istringstream& input, char separator, unsigned char index); virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
public: public:
/** /**
* Prepare the slave @a SymbolString for sending an answer to the bus. * Prepare the slave @a SymbolString for sending an answer to the bus.
* @param input the @a istringstream to parse the formatted value(s) from. * @param input the @a istringstream to parse the formatted value(s) from.
* @param slave the slave data @a SymbolString for writing symbols to. * @param slave the @a SlaveSymbolString for writing symbols to.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
virtual result_t prepareSlave(istringstream& input, SymbolString& slave); virtual result_t prepareSlave(istringstream& input, SlaveSymbolString& slave);
/** /**
* Store the last seen master and slave data. * Store the last seen master and slave data.
* @param master the last seen master data. * @param master the last seen @a MasterSymbolString.
* @param slave the last seen slave data. * @param slave the last seen @a SlaveSymbolString.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
virtual result_t storeLastData(SymbolString& master, SymbolString& slave); virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
/** /**
* Store last seen master or slave data. * Store last seen master data.
* @param partType the @a PartType of the data. * @param data the last @a MasterSymbolString.
* @param data the last seen data.
* @param index the index of the part to store. * @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
virtual result_t storeLastData(const PartType partType, SymbolString& data, unsigned char index); virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
/** /**
* Decode the value from the last stored data. * Store last seen slave data.
* @param partType the @a PartType of the data. * @param data the last seen @a SlaveSymbolString.
* @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
/**
* Decode the value from the last stored master 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 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.
@@ -481,8 +488,19 @@ class Message {
* @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.
*/ */
virtual result_t decodeLastData(const PartType partType, virtual result_t decodeLastMasterData(ostringstream& output, OutputFormat outputFormat = 0,
ostringstream& output, OutputFormat outputFormat = 0, bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
/**
* Decode the value from the last stored slave 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 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.
*/
virtual result_t decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1); bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
/** /**
@@ -508,15 +526,15 @@ class Message {
/** /**
* Get the last seen master data. * Get the last seen master data.
* @return the last seen master @a SymbolString. * @return the last seen @a MasterSymbolString.
*/ */
SymbolString& getLastMasterData() { return m_lastMasterData; } MasterSymbolString& getLastMasterData() { return m_lastMasterData; }
/** /**
* Get the last seen slave data. * Get the last seen slave data.
* @return the last seen slave @a SymbolString. * @return the last seen @a SlaveSymbolString.
*/ */
SymbolString& getLastSlaveData() { return m_lastSlaveData; } SlaveSymbolString& getLastSlaveData() { return m_lastSlaveData; }
/** /**
* Get the time when this message was last seen with reasonable data. * Get the time when this message was last seen with reasonable data.
@@ -630,11 +648,11 @@ class Message {
/** the @a Condition for this message, or NULL. */ /** the @a Condition for this message, or NULL. */
Condition* m_condition; Condition* m_condition;
/** the last seen master data. */ /** the last seen @a MasterSymbolString. */
SymbolString m_lastMasterData{true}; MasterSymbolString m_lastMasterData;
/** the last seen slave data. */ /** the last seen @a SlaveSymbolString. */
SymbolString m_lastSlaveData; SlaveSymbolString m_lastSlaveData;
/** the system time when the message was last updated, 0 for never. */ /** the system time when the message was last updated, 0 for never. */
time_t m_lastUpdateTime; time_t m_lastUpdateTime;
@@ -691,7 +709,7 @@ class ChainedMessage : public Message {
virtual unsigned char getIdLength() const { return (unsigned char)(m_ids[0].size() - 2); } virtual unsigned char getIdLength() const { return (unsigned char)(m_ids[0].size() - 2); }
// @copydoc // @copydoc
virtual bool checkId(SymbolString& master, unsigned char* index = NULL); virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
// @copydoc // @copydoc
virtual bool checkId(Message& other); virtual bool checkId(Message& other);
@@ -702,16 +720,25 @@ class ChainedMessage : public Message {
protected: protected:
// @copydoc // @copydoc
virtual result_t prepareMasterPart(SymbolString& master, istringstream& input, char separator, unsigned char index); virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
public: public:
// @copydoc // @copydoc
virtual result_t storeLastData(SymbolString& master, SymbolString& slave); virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
// @copydoc // @copydoc
virtual result_t storeLastData(const PartType partType, SymbolString& data, unsigned char index); virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
// @copydoc
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
/**
* Combine all last stored data.
* @return the result code.
*/
virtual result_t combineLastParts();
protected: protected:
// @copydoc // @copydoc
@@ -728,11 +755,11 @@ class ChainedMessage : public Message {
/** the maximum allowed time difference of any data pair. */ /** the maximum allowed time difference of any data pair. */
const time_t m_maxTimeDiff; const time_t m_maxTimeDiff;
/** array of the last seen master datas. */ /** array of the last seen @a MasterSymbolString instances. */
SymbolString** m_lastMasterDatas; MasterSymbolString** m_lastMasterDatas;
/** array of the last seen slave datas. */ /** array of the last seen @a SlaveSymbolString instances. */
SymbolString** m_lastSlaveDatas; SlaveSymbolString** m_lastSlaveDatas;
/** array of the system times when the corresponding master data was last updated, 0 for never. */ /** array of the system times when the corresponding master data was last updated, 0 for never. */
time_t* m_lastMasterUpdateTimes; time_t* m_lastMasterUpdateTimes;
@@ -1337,7 +1364,7 @@ class MessageMap : public FileReader {
/** /**
* Find the @a Message instance for the specified master data. * Find the @a Message instance for the specified master data.
* @param master the master @a SymbolString for identifying the @a Message. * @param master the @a MasterSymbolString for identifying the @a Message.
* @param anyDestination true to only return messages without a particular destination. * @param anyDestination true to only return messages without a particular destination.
* @param withRead true to include read messages (default true). * @param withRead true to include read messages (default true).
* @param withWrite true to include write messages (default true). * @param withWrite true to include write messages (default true).
@@ -1345,7 +1372,7 @@ class MessageMap : public FileReader {
* @return the @a Message instance, or NULL. * @return the @a Message instance, or NULL.
* Note: the caller may not free the returned instance. * Note: the caller may not free the returned instance.
*/ */
Message* find(SymbolString& master, bool anyDestination = false, Message* find(MasterSymbolString& master, bool anyDestination = false,
const bool withRead = true, const bool withWrite = true, const bool withPassive = true); const bool withRead = true, const bool withWrite = true, const bool withPassive = true);
/** /**
+26 -1
View File
@@ -113,13 +113,14 @@ int parseSignedInt(const char* str, int base, const int minValue, const int maxV
* A string of unescaped bus symbols. * A string of unescaped bus symbols.
*/ */
class SymbolString { class SymbolString {
public: protected:
/** /**
* Creates a new empty instance. * Creates a new empty instance.
* @param isMaster whether this instance if for the master part. * @param isMaster whether this instance if for the master part.
*/ */
explicit SymbolString(const bool isMaster = false) { m_isMaster = isMaster; } explicit SymbolString(const bool isMaster = false) { m_isMaster = isMaster; }
public:
/** /**
* Update the CRC by adding a value. * Update the CRC by adding a value.
* @param crc the current CRC to update. * @param crc the current CRC to update.
@@ -268,6 +269,30 @@ class SymbolString {
}; };
/**
* A string of unescaped master bus symbols.
*/
class MasterSymbolString : public SymbolString {
public:
/**
* Creates a new empty instance.
*/
MasterSymbolString() : SymbolString(true) {}
};
/**
* A string of unescaped slave bus symbols.
*/
class SlaveSymbolString : public SymbolString {
public:
/**
* Creates a new empty instance.
*/
SlaveSymbolString() : SymbolString(false) {}
};
/** /**
* Return whether the address is one of the 25 master addresses. * Return whether the address is one of the 25 master addresses.
* @param addr the address to check. * @param addr the address to check.
+4 -4
View File
@@ -473,14 +473,14 @@ int main() {
string check[5] = checks[i]; string check[5] = checks[i];
istringstream isstr(check[0]); istringstream isstr(check[0]);
string expectStr = check[1]; string expectStr = check[1];
SymbolString mstr(true); MasterSymbolString mstr;
result_t result = mstr.parseHex(check[2]); result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true; error = true;
continue; continue;
} }
SymbolString sstr; SlaveSymbolString sstr;
result = sstr.parseHex(check[3]); result = sstr.parseHex(check[3]);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
@@ -563,14 +563,14 @@ int main() {
} }
ostringstream output; ostringstream output;
SymbolString writeMstr(true); MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10)); result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result) cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl; << endl;
error = true; error = true;
} }
SymbolString writeSstr; SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2)); result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result) cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
+9 -9
View File
@@ -170,8 +170,8 @@ int main() {
map<string, Condition*> &conditions = messages->getConditions(); map<string, Condition*> &conditions = messages->getConditions();
Message* message = NULL; Message* message = NULL;
vector<Message*> deleteMessages; vector<Message*> deleteMessages;
vector<SymbolString*> mstrs; vector<MasterSymbolString*> mstrs;
vector<SymbolString*> sstrs; vector<SlaveSymbolString*> sstrs;
mstrs.resize(1); mstrs.resize(1);
sstrs.resize(1); sstrs.resize(1);
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) { for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
@@ -260,7 +260,7 @@ int main() {
} else if (mstrs[pos] != NULL) { } else if (mstrs[pos] != NULL) {
delete mstrs[pos]; delete mstrs[pos];
} }
mstrs[pos] = new SymbolString(true); mstrs[pos] = new MasterSymbolString;
result = mstrs[pos]->parseHex(token); result = mstrs[pos]->parseHex(token);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl;
@@ -277,7 +277,7 @@ int main() {
} else if (sstrs[pos] != NULL) { } else if (sstrs[pos] != NULL) {
delete sstrs[pos]; delete sstrs[pos];
} }
sstrs[pos] = new SymbolString(); sstrs[pos] = new SlaveSymbolString();
result = sstrs[pos]->parseHex(token); result = sstrs[pos]->parseHex(token);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl;
@@ -292,7 +292,7 @@ int main() {
if (mstrs[0] != NULL) { if (mstrs[0] != NULL) {
delete mstrs[0]; delete mstrs[0];
} }
mstrs[0] = new SymbolString(true); mstrs[0] = new MasterSymbolString;
result = mstrs[0]->parseHex(check[2]); result = mstrs[0]->parseHex(check[2]);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
@@ -301,7 +301,7 @@ int main() {
if (sstrs[0] != NULL) { if (sstrs[0] != NULL) {
delete sstrs[0]; delete sstrs[0];
} }
sstrs[0] = new SymbolString(); sstrs[0] = new SlaveSymbolString();
result = sstrs[0]->parseHex(check[3]); result = sstrs[0]->parseHex(check[3]);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl; cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
@@ -419,7 +419,7 @@ int main() {
} }
if (!message->isPassive() && (withInput || !decode)) { if (!message->isPassive() && (withInput || !decode)) {
istringstream input(inputStr); istringstream input(inputStr);
SymbolString writeMstr(true); MasterSymbolString writeMstr;
result = message->prepareMaster(0xff, writeMstr, input); result = message->prepareMaster(0xff, writeMstr, input);
if (failedPrepare) { if (failedPrepare) {
if (result == RESULT_OK) { if (result == RESULT_OK) {
@@ -453,10 +453,10 @@ int main() {
delete templates; delete templates;
delete messages; delete messages;
for (vector<SymbolString*>::iterator it = mstrs.begin(); it != mstrs.end(); it++) { for (vector<MasterSymbolString*>::iterator it = mstrs.begin(); it != mstrs.end(); it++) {
delete *it; delete *it;
} }
for (vector<SymbolString*>::iterator it = sstrs.begin(); it != sstrs.end(); it++) { for (vector<SlaveSymbolString*>::iterator it = sstrs.begin(); it != sstrs.end(); it++) {
delete *it; delete *it;
} }
return 0; return 0;
+13 -13
View File
@@ -47,19 +47,19 @@ void verify(bool expectFailMatch, string type, string input,
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
SymbolString sstr(true); MasterSymbolString mstr;
if (argc > 1) { if (argc > 1) {
result_t result; result_t result;
if (argc > 2 && strcmp("escaped", argv[1]) == 0) { if (argc > 2 && strcmp("escaped", argv[1]) == 0) {
result = sstr.parseHexEscaped(argv[2]); result = mstr.parseHexEscaped(argv[2]);
} else { } else {
result = sstr.parseHex(argv[1]); result = mstr.parseHex(argv[1]);
} }
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl; cout << "parse escaped error: " << getResultCode(result) << endl;
} else { } else {
unsigned char gotCrc = sstr.calcCrc(); unsigned char gotCrc = mstr.calcCrc();
cout << "calculated CRC: 0x" cout << "calculated CRC: 0x"
<< nouppercase << setw(2) << hex << setfill('0') << nouppercase << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(gotCrc) << endl; << static_cast<unsigned>(gotCrc) << endl;
@@ -68,14 +68,14 @@ int main(int argc, char** argv) {
} }
string gotStr, expectStr; string gotStr, expectStr;
result_t result = sstr.parseHex("10feb5050427a915aa"); result_t result = mstr.parseHex("10feb5050427a915aa");
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "parse unescaped error: " << getResultCode(result) << endl; cout << "parse unescaped error: " << getResultCode(result) << endl;
error = true; error = true;
} else { } else {
gotStr = sstr.getDataStr(), expectStr = "10feb5050427a915aa"; gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr); verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = sstr.calcCrc(), expectCrc = 0x77; unsigned char gotCrc = mstr.calcCrc(), expectCrc = 0x77;
ostringstream ostr; ostringstream ostr;
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc); ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
expectStr = ostr.str(); expectStr = ostr.str();
@@ -85,24 +85,24 @@ int main(int argc, char** argv) {
verify(false, "CRC", "10feb5050427a915aa", gotCrc == expectCrc, expectStr, gotStr); verify(false, "CRC", "10feb5050427a915aa", gotCrc == expectCrc, expectStr, gotStr);
} }
sstr.clear(); mstr.clear();
result = sstr.parseHexEscaped("10feb5050427a90015a901"); result = mstr.parseHexEscaped("10feb5050427a90015a901");
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl; cout << "parse escaped error: " << getResultCode(result) << endl;
error = true; error = true;
} else { } else {
gotStr = sstr.getDataStr(), expectStr = "10feb5050427a915aa"; gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse escaped", "10feb5050427a90015a901", true, expectStr, gotStr); verify(false, "parse escaped", "10feb5050427a90015a901", true, expectStr, gotStr);
ostringstream ostr; ostringstream ostr;
ostr << dec << static_cast<unsigned>(4); ostr << dec << static_cast<unsigned>(4);
expectStr = ostr.str(); expectStr = ostr.str();
ostr.str(""); ostr.str("");
ostr << dec << static_cast<unsigned>(sstr.getDataSize()); ostr << dec << static_cast<unsigned>(mstr.getDataSize());
gotStr = ostr.str(); gotStr = ostr.str();
verify(false, "data size", "10feb5050427a90015a901", sstr.getDataSize() == 4, expectStr, gotStr); verify(false, "data size", "10feb5050427a90015a901", mstr.getDataSize() == 4, expectStr, gotStr);
} }
sstr = SymbolString(); // slave SlaveSymbolString sstr;
result = sstr.parseHexEscaped("0427a90015a901"); result = sstr.parseHexEscaped("0427a90015a901");
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl; cout << "parse escaped error: " << getResultCode(result) << endl;