introduced symbol_t, added SymbolString::dataAt() and ::isMaster(), renamed SymbolString::getDataStr() to getStr(), use size_t/ssize_t where appropriate, simplified by use of new SymbolString methods, corrected broadcast scan conversion, use override declaration

This commit is contained in:
john30
2017-03-04 14:01:20 +01:00
parent dfa0e6e08f
commit 18fc12499b
25 changed files with 806 additions and 862 deletions
+59 -71
View File
@@ -62,11 +62,11 @@ const char* getStateCode(BusState state) {
}
}
result_t PollRequest::prepare(unsigned char ownMasterAddress) {
result_t PollRequest::prepare(symbol_t ownMasterAddress) {
istringstream input;
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, UI_FIELD_SEPARATOR, SYN, m_index);
if (result == RESULT_OK) {
logInfo(lf_bus, "poll cmd: %s", m_master.getDataStr().c_str());
logInfo(lf_bus, "poll cmd: %s", m_master.getStr().c_str());
}
return result;
}
@@ -97,11 +97,11 @@ bool PollRequest::notify(result_t result, SlaveSymbolString& slave) {
}
result_t ScanRequest::prepare(unsigned char ownMasterAddress) {
result_t ScanRequest::prepare(symbol_t ownMasterAddress) {
if (m_slaves.empty()) {
return RESULT_ERR_EOF;
}
unsigned char dstAddress = m_slaves.front();
symbol_t dstAddress = m_slaves.front();
if (m_index == 0 && m_messages.size() == m_allMessages.size()) { // first message for this address
m_busHandler->setScanResult(dstAddress, "");
}
@@ -109,13 +109,13 @@ result_t ScanRequest::prepare(unsigned char ownMasterAddress) {
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, UI_FIELD_SEPARATOR, dstAddress,
m_index);
if (result >= RESULT_OK) {
logInfo(lf_bus, "scan %2.2x cmd: %s", dstAddress, m_master.getDataStr().c_str());
logInfo(lf_bus, "scan %2.2x cmd: %s", dstAddress, m_master.getStr().c_str());
}
return result;
}
bool ScanRequest::notify(result_t result, SlaveSymbolString& slave) {
unsigned char dstAddress = m_master[1];
symbol_t dstAddress = m_master[1];
if (result == RESULT_OK) {
if (m_message == m_messageMap->getScanMessage()) {
Message* message = m_messageMap->getScanMessage(dstAddress);
@@ -182,7 +182,7 @@ bool ScanRequest::notify(result_t result, SlaveSymbolString& slave) {
bool ActiveBusRequest::notify(result_t result, SlaveSymbolString& slave) {
if (result == RESULT_OK) {
logDebug(lf_bus, "read res: %s", slave.getDataStr().c_str());
logDebug(lf_bus, "read res: %s", slave.getStr().c_str());
}
m_result = result;
m_slave = slave;
@@ -199,28 +199,25 @@ void GrabbedMessage::setLastData(MasterSymbolString& master, SlaveSymbolString&
* Decode the input @a SymbolString with the specified @a DataType and length.
* @param type the @a DataType.
* @param input the @a SymbolString to read the binary value from.
* @param isMaster whether the @a SymbolString is the master part.
* @param baseOffset the base offset in the @a SymbolString.
* @param length the number of symbols to read.
* @param offsets the last offset to the baseOffset to read.
* @param output the ostringstream to append the formatted value to.
* @param firstOnly whether to read only the first non-erroneous offset.
* @return @a RESULT_OK on success, or an error code.
*/
bool decodeType(DataType* type, SymbolString *input, bool isMaster, unsigned char baseOffset, unsigned char length,
unsigned char offsets, ostringstream& output, bool firstOnly = false) {
bool decodeType(DataType* type, SymbolString *input, size_t length,
size_t offsets, ostringstream& output, bool firstOnly = false) {
bool first = true;
string in = input->getDataStr(baseOffset);
for (unsigned char offset = 0; offset <= offsets; offset++) {
string in = input->getStr(input->getDataOffset());
for (size_t offset = 0; offset <= offsets; offset++) {
ostringstream out;
result_t result = type->readSymbols(*input, isMaster, (unsigned char)(baseOffset+offset), (unsigned char)length,
out, 0);
result_t result = type->readSymbols(*input, offset, length, out, 0);
if (result != RESULT_OK) {
continue;
}
if (type->isNumeric() && type->hasFlag(DAY)) {
unsigned int value = 0;
if (type->readRawValue(*input, (unsigned char)(baseOffset+offset), (unsigned char)length, value) == RESULT_OK) {
if (type->readRawValue(*input, offset, length, value) == RESULT_OK) {
out.str("");
out << DataField::getDayName(reinterpret_cast<NumberDataType*>(type)->getMinValue()+value);
}
@@ -260,10 +257,10 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
if (!first) {
output << endl;
}
unsigned char dstAddress = m_lastMaster[1];
output << m_lastMaster.getDataStr();
symbol_t dstAddress = m_lastMaster[1];
output << m_lastMaster.getStr();
if (dstAddress != BROADCAST && !isMaster(dstAddress)) {
output << " / " << m_lastSlave.getDataStr();
output << " / " << m_lastSlave.getStr();
}
output << " = " << static_cast<unsigned>(m_count);
if (message) {
@@ -281,15 +278,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
} else {
input = &m_lastSlave;
}
unsigned char baseOffset = master ? 5 : 1;
unsigned char remain = input->size();
if (remain <= baseOffset) {
return true;
}
remain = (unsigned char)(remain-baseOffset);
if ((*input)[baseOffset-1] < remain) {
remain = (*input)[baseOffset-1];
}
size_t remain = input->getDataSize();
if (remain == 0) {
return true;
}
@@ -298,22 +287,22 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored()) { // skip bit and ignored types
continue;
}
unsigned char maxLength = baseType->getBitCount()/8;
size_t maxLength = baseType->getBitCount()/8;
bool firstOnly = maxLength >= 8;
if (maxLength > remain) {
maxLength = remain;
}
if (baseType->isAdjustableLength()) {
for (unsigned char length = maxLength; length >= 1; length--) {
for (size_t length = maxLength; length >= 1; length--) {
DataType* type = types->get(baseType->getId(), length);
if (decodeType(type, input, master, baseOffset, length, (unsigned char)(remain-length), output, firstOnly)) {
if (decodeType(type, input, length, remain-length, output, firstOnly)) {
if (firstOnly) {
break; // only a single offset with maximum length when adjustable maximum size is at least 8 bytes
}
}
}
} else if (maxLength > 0) {
decodeType(baseType, input, master, baseOffset, maxLength, (unsigned char)(remain-maxLength), output);
decodeType(baseType, input, maxLength, remain-maxLength, output);
}
}
}
@@ -331,7 +320,7 @@ result_t BusHandler::sendAndWait(MasterSymbolString& master, SlaveSymbolString&
result_t result = RESULT_ERR_NO_SIGNAL;
slave.clear();
ActiveBusRequest request(master, slave);
logInfo(lf_bus, "send message: %s", master.getDataStr().c_str());
logInfo(lf_bus, "send message: %s", master.getStr().c_str());
for (int sendRetries = m_failedSendRetries + 1; sendRetries >= 0; sendRetries--) {
m_nextRequests.push(&request);
@@ -354,13 +343,13 @@ result_t BusHandler::sendAndWait(MasterSymbolString& master, SlaveSymbolString&
return result;
}
result_t BusHandler::readFromBus(Message* message, string inputStr, const unsigned char dstAddress,
const unsigned char srcAddress) {
unsigned char masterAddress = srcAddress == SYN ? m_ownMasterAddress : srcAddress;
result_t BusHandler::readFromBus(Message* message, string inputStr, const symbol_t dstAddress,
const symbol_t srcAddress) {
symbol_t masterAddress = srcAddress == SYN ? m_ownMasterAddress : srcAddress;
result_t ret = RESULT_EMPTY;
MasterSymbolString master;
SlaveSymbolString slave;
for (unsigned char index = 0; index < message->getCount(); index++) {
for (size_t index = 0; index < message->getCount(); index++) {
istringstream input(inputStr);
ret = message->prepareMaster(masterAddress, master, input, UI_FIELD_SEPARATOR, dstAddress, index);
if (ret != RESULT_OK) {
@@ -424,7 +413,7 @@ void BusHandler::run() {
result_t BusHandler::handleSymbol() {
unsigned int timeout = SYN_TIMEOUT;
unsigned char sendSymbol = ESC;
symbol_t sendSymbol = ESC;
bool sending = false;
BusRequest* startRequest = NULL;
@@ -565,7 +554,7 @@ result_t BusHandler::handleSymbol() {
}
// receive next symbol (optionally check reception of sent symbol)
unsigned char recvSymbol;
symbol_t recvSymbol;
result = m_device->recv(timeout+m_transferLatency, recvSymbol);
if (!sending && result == RESULT_ERR_TIMEOUT && m_generateSynInterval > 0
@@ -701,7 +690,7 @@ result_t BusHandler::handleSymbol() {
return setState(bs_skip, RESULT_ERR_CRC);
}
if (m_answer) {
unsigned char dstAddress = m_command[1];
symbol_t dstAddress = m_command[1];
if (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress) {
if (m_crcValid) {
addSeenAddress(m_command[0]);
@@ -925,7 +914,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
m_currentRequest = NULL;
} else if (state == bs_sendSyn || (result != RESULT_OK && !firstRepetition)) {
logDebug(lf_bus, "notify request: %s", getResultCode(result));
unsigned char dstAddress = m_currentRequest->m_master[1];
symbol_t dstAddress = m_currentRequest->m_master[1];
if (result == RESULT_OK) {
addSeenAddress(dstAddress);
}
@@ -988,7 +977,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
return result;
}
void BusHandler::addSeenAddress(unsigned char address) {
void BusHandler::addSeenAddress(symbol_t address) {
if (!isValidAddress(address, false)) {
return;
}
@@ -1023,7 +1012,7 @@ void BusHandler::addSeenAddress(unsigned char address) {
}
void BusHandler::receiveCompleted() {
unsigned char srcAddress = m_command[0], dstAddress = m_command[1];
symbol_t srcAddress = m_command[0], dstAddress = m_command[1];
if (srcAddress == dstAddress) {
logError(lf_bus, "invalid self-addressed message from %2.2x", srcAddress);
return;
@@ -1033,12 +1022,12 @@ void BusHandler::receiveCompleted() {
bool master = isMaster(dstAddress);
if (dstAddress == BROADCAST) {
logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str());
if (m_command.size() >= 5+9 && m_command[2] == 0x07 && m_command[3] == 0x04) {
unsigned char slaveAddress = (unsigned char)((srcAddress+5)&0xff);
logInfo(lf_update, "update BC cmd: %s", m_command.getStr().c_str());
if (m_command.getDataSize() >= 10 && m_command[2] == 0x07 && m_command[3] == 0x04) {
symbol_t slaveAddress = getSlaveAddress(srcAddress);
addSeenAddress(slaveAddress);
Message* message = m_messages->getScanMessage(slaveAddress);
if (message && (message->getLastUpdateTime() == 0 || message->getLastSlaveData().size() < 10)) {
if (message && (message->getLastUpdateTime() == 0 || message->getLastSlaveData().getDataSize() < 10)) {
// e.g. 10fe07040a b5564149303001248901
m_seenAddresses[slaveAddress] |= SCAN_INIT;
MasterSymbolString dummyMaster;
@@ -1046,9 +1035,9 @@ void BusHandler::receiveCompleted() {
result_t result = message->prepareMaster(m_ownMasterAddress, dummyMaster, input);
if (result == RESULT_OK) {
SlaveSymbolString idData;
idData.push_back(9);
for (size_t i = 5; i <= 5+9; i++) {
idData.push_back(m_command[i]);
idData.push_back(10);
for (size_t i = 0; i < 10; i++) {
idData.push_back(m_command.dataAt(i));
}
result = message->storeLastData(idData, 0);
}
@@ -1059,9 +1048,9 @@ void BusHandler::receiveCompleted() {
}
}
} else if (master) {
logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str());
logInfo(lf_update, "update MM cmd: %s", m_command.getStr().c_str());
} else {
logInfo(lf_update, "update MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
logInfo(lf_update, "update MS cmd: %s / %s", m_command.getStr().c_str(), m_response.getStr().c_str());
}
Message* message = m_messages->find(m_command);
if (m_grabMessages) {
@@ -1075,12 +1064,11 @@ void BusHandler::receiveCompleted() {
}
if (message == NULL) {
if (dstAddress == BROADCAST) {
logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
logNotice(lf_update, "unknown BC cmd: %s", m_command.getStr().c_str());
} else if (master) {
logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str());
logNotice(lf_update, "unknown MM cmd: %s", m_command.getStr().c_str());
} else {
logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(),
m_response.getDataStr().c_str());
logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getStr().c_str(), m_response.getStr().c_str());
}
} else {
m_messages->invalidateCache(message);
@@ -1093,7 +1081,7 @@ void BusHandler::receiveCompleted() {
}
if (result < RESULT_OK) {
logError(lf_update, "unable to parse %s %s from %s / %s: %s", circuit.c_str(), name.c_str(),
m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
m_command.getStr().c_str(), m_response.getStr().c_str(), getResultCode(result));
} else {
string data = output.str();
if (m_answer && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) {
@@ -1133,13 +1121,13 @@ result_t BusHandler::startScan(bool full, string levels) {
}
m_scanResults.clear();
deque<unsigned char> slaves;
for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master
deque<symbol_t> slaves;
for (symbol_t slave = 1; slave != 0; slave++) { // 0 is known to be a master
if (!isValidAddress(slave, false) || isMaster(slave)) {
continue;
}
if (!full && (m_seenAddresses[slave]&SEEN) == 0) {
unsigned char master = getMasterAddress(slave); // check if we saw the corresponding master already
symbol_t master = getMasterAddress(slave); // check if we saw the corresponding master already
if (master == SYN || (m_seenAddresses[master]&SEEN) == 0) {
continue;
}
@@ -1158,7 +1146,7 @@ result_t BusHandler::startScan(bool full, string levels) {
return RESULT_OK;
}
void BusHandler::setScanResult(unsigned char dstAddress, string str) {
void BusHandler::setScanResult(symbol_t dstAddress, string str) {
m_seenAddresses[dstAddress] |= SCAN_INIT;
if (str.length() > 0) {
m_seenAddresses[dstAddress] |= SCAN_DONE;
@@ -1178,8 +1166,8 @@ void BusHandler::formatScanResult(ostringstream& output) {
output << m_runningScans << " scan(s) still running" << endl;
}
bool first = true;
for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master
map<unsigned char, string>::iterator it = m_scanResults.find(slave);
for (symbol_t slave = 1; slave != 0; slave++) { // 0 is known to be a master
map<symbol_t, string>::iterator it = m_scanResults.find(slave);
if (it != m_scanResults.end()) {
if (first) {
first = false;
@@ -1191,7 +1179,7 @@ void BusHandler::formatScanResult(ostringstream& output) {
}
if (first) {
// fallback to autoscan results
for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master
for (symbol_t slave = 1; slave != 0; slave++) { // 0 is known to be a master
if (isValidAddress(slave, false) && !isMaster(slave) && (m_seenAddresses[slave]&SCAN_DONE) != 0) {
Message* message = m_messages->getScanMessage(slave);
if (message != NULL && message->getLastUpdateTime() > 0) {
@@ -1209,12 +1197,12 @@ void BusHandler::formatScanResult(ostringstream& output) {
}
void BusHandler::formatSeenInfo(ostringstream& output) {
unsigned char address = 0;
symbol_t address = 0;
for (int index = 0; index < 256; index++, address++) {
if (isValidAddress(address, false) && ((m_seenAddresses[address]&SEEN) != 0
|| (!m_device->isReadOnly() && (address == m_ownMasterAddress || address == m_ownSlaveAddress)))) {
output << endl << "address " << setfill('0') << setw(2) << hex << static_cast<unsigned>(address);
unsigned char master;
symbol_t master;
if (isMaster(address)) {
output << ": master";
master = address;
@@ -1256,7 +1244,7 @@ void BusHandler::formatSeenInfo(ostringstream& output) {
}
}
result_t BusHandler::scanAndWait(unsigned char dstAddress, SlaveSymbolString& slave) {
result_t BusHandler::scanAndWait(symbol_t dstAddress, SlaveSymbolString& slave) {
if (!isValidAddress(dstAddress) || isMaster(dstAddress)) {
return RESULT_ERR_INVALID_ADDR;
}
@@ -1282,7 +1270,7 @@ result_t BusHandler::scanAndWait(unsigned char dstAddress, SlaveSymbolString& sl
m_seenAddresses[dstAddress] |= SCAN_DONE;
}
}
if (result != RESULT_OK || slave.size() == 0) { // avoid "invalid position" during decode
if (result != RESULT_OK || slave.getDataSize() == 0) { // avoid "invalid position" during decode
return result;
}
return scanMessage->storeLastData(slave, 0); // update the cache
@@ -1313,7 +1301,7 @@ void BusHandler::formatGrabResult(const bool unknown, ostringstream& output, con
}
}
unsigned char BusHandler::getNextScanAddress(unsigned char lastAddress, bool& scanned) {
symbol_t BusHandler::getNextScanAddress(symbol_t lastAddress, bool& scanned) {
if (lastAddress == SYN) {
return SYN;
}
@@ -1325,7 +1313,7 @@ unsigned char BusHandler::getNextScanAddress(unsigned char lastAddress, bool& sc
scanned = (m_seenAddresses[lastAddress]&SCAN_INIT) != 0;
return lastAddress;
}
unsigned char master = getMasterAddress(lastAddress);
symbol_t master = getMasterAddress(lastAddress);
if (master != SYN && (m_seenAddresses[master]&SEEN) != 0 && (m_seenAddresses[lastAddress]&LOAD_INIT) == 0) {
scanned = (m_seenAddresses[lastAddress]&SCAN_INIT) != 0;
return lastAddress;
@@ -1334,7 +1322,7 @@ unsigned char BusHandler::getNextScanAddress(unsigned char lastAddress, bool& sc
return SYN;
}
void BusHandler::setScanConfigLoaded(unsigned char address, string file) {
void BusHandler::setScanConfigLoaded(symbol_t address, string file) {
m_seenAddresses[address] |= LOAD_INIT;
if (!file.empty()) {
m_seenAddresses[address] |= LOAD_DONE;
+25 -25
View File
@@ -163,10 +163,10 @@ class PollRequest : public BusRequest {
* @param masterAddress the master bus address to use.
* @return the result code.
*/
result_t prepare(unsigned char masterAddress);
result_t prepare(symbol_t masterAddress);
// @copydoc
virtual bool notify(result_t result, SlaveSymbolString& slave);
virtual bool notify(result_t result, SlaveSymbolString& slave) override;
private:
@@ -177,7 +177,7 @@ class PollRequest : public BusRequest {
Message* m_message;
/** the current part index in @a m_message. */
unsigned char m_index;
size_t m_index;
};
@@ -195,7 +195,7 @@ class ScanRequest : public BusRequest {
* @param slaves the slave addresses to scan.
* @param busHandler the @a BusHandler instance to notify of final scan result.
*/
ScanRequest(MessageMap* messageMap, deque<Message*> messages, deque<unsigned char> slaves, BusHandler* busHandler)
ScanRequest(MessageMap* messageMap, deque<Message*> messages, deque<symbol_t> slaves, BusHandler* busHandler)
: BusRequest(m_master, true), m_messageMap(messageMap), m_index(0), m_allMessages(messages), m_messages(messages),
m_slaves(slaves), m_busHandler(busHandler) {
m_message = m_messages.front();
@@ -212,10 +212,10 @@ class ScanRequest : public BusRequest {
* @param masterAddress the master bus address to use.
* @return the result code.
*/
result_t prepare(unsigned char masterAddress);
result_t prepare(symbol_t masterAddress);
// @copydoc
virtual bool notify(result_t result, SlaveSymbolString& slave);
virtual bool notify(result_t result, SlaveSymbolString& slave) override;
private:
@@ -229,7 +229,7 @@ class ScanRequest : public BusRequest {
Message* m_message;
/** the current part index in @a m_message. */
unsigned char m_index;
size_t m_index;
/** all secondary @a Message instances. */
const deque<Message*> m_allMessages;
@@ -238,7 +238,7 @@ class ScanRequest : public BusRequest {
deque<Message*> m_messages;
/** the slave addresses to scan. */
deque<unsigned char> m_slaves;
deque<symbol_t> m_slaves;
/** the @a ostringstream for building the scan result of a single slave. */
ostringstream m_scanResult;
@@ -269,7 +269,7 @@ class ActiveBusRequest : public BusRequest {
virtual ~ActiveBusRequest() {}
// @copydoc
virtual bool notify(result_t result, SlaveSymbolString& slave);
virtual bool notify(result_t result, SlaveSymbolString& slave) override;
private:
@@ -352,13 +352,13 @@ class BusHandler : public WaitThread {
* @param pollInterval the interval in seconds in which poll messages are cycled, or 0 if disabled.
*/
BusHandler(Device* device, MessageMap* messages,
const unsigned char ownAddress, const bool answer,
const symbol_t ownAddress, const bool answer,
const unsigned int busLostRetries, const unsigned int failedSendRetries,
const unsigned int transferLatency, const unsigned int busAcquireTimeout, const unsigned int slaveRecvTimeout,
const unsigned int lockCount, const bool generateSyn,
const unsigned int pollInterval)
: WaitThread(), m_device(device), m_reconnect(false), m_messages(messages),
m_ownMasterAddress(ownAddress), m_ownSlaveAddress((unsigned char)(ownAddress+5)),
m_ownMasterAddress(ownAddress), m_ownSlaveAddress(getSlaveAddress(ownAddress)),
m_answer(answer), m_addressConflict(false),
m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries),
m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout),
@@ -415,8 +415,8 @@ class BusHandler : public WaitThread {
* @param srcAddress the source address to set, or @a SYN for the own master address.
* @return the result code.
*/
result_t readFromBus(Message* message, string inputStr, const unsigned char dstAddress = SYN,
const unsigned char srcAddress = SYN);
result_t readFromBus(Message* message, string inputStr, const symbol_t dstAddress = SYN,
const symbol_t srcAddress = SYN);
/**
* Main thread entry.
@@ -436,7 +436,7 @@ class BusHandler : public WaitThread {
* @param dstAddress the scanned slave address.
* @param str the scan result @a string to set, or empty if not a single part of the scan was successful.
*/
void setScanResult(unsigned char dstAddress, string str);
void setScanResult(symbol_t dstAddress, string str);
/**
* Called from @a ScanRequest upon completion.
@@ -461,7 +461,7 @@ class BusHandler : public WaitThread {
* @param slave the @a SlaveSymbolString that will be filled with retrieved slave data.
* @return the result code.
*/
result_t scanAndWait(unsigned char dstAddress, SlaveSymbolString& slave);
result_t scanAndWait(symbol_t dstAddress, SlaveSymbolString& slave);
/**
* Start or stop grabbing unknown messages.
@@ -513,14 +513,14 @@ class BusHandler : public WaitThread {
* @param scanned set to true when the slave is already scanned but not yet loaded, set to false when it still needs to be scanned and loaded.
* @return the next slave address that still needs to be scanned or loaded, or @a SYN.
*/
unsigned char getNextScanAddress(unsigned char lastAddress, bool& scanned);
symbol_t getNextScanAddress(symbol_t lastAddress, bool& scanned);
/**
* Set the state of the participant to configuration @a LOADED.
* @param address the slave address.
* @param file the file from which the configuration was loaded, or empty if loading was not possible.
*/
void setScanConfigLoaded(unsigned char address, string file);
void setScanConfigLoaded(symbol_t address, string file);
private:
@@ -543,7 +543,7 @@ class BusHandler : public WaitThread {
* Add a seen bus address.
* @param address the seen bus address.
*/
void addSeenAddress(unsigned char address);
void addSeenAddress(symbol_t address);
/**
* Called when a passive reception was successfully completed.
@@ -560,10 +560,10 @@ class BusHandler : public WaitThread {
MessageMap* m_messages;
/** the own master address. */
const unsigned char m_ownMasterAddress;
const symbol_t m_ownMasterAddress;
/** the own slave address. */
const unsigned char m_ownSlaveAddress;
const symbol_t m_ownSlaveAddress;
/** whether to answer queries for the own master/slave address. */
const bool m_answer;
@@ -624,7 +624,7 @@ class BusHandler : public WaitThread {
/** the offset of the next symbol that needs to be sent from the command or response,
* (only relevant if m_request is set and state is @a bs_command or @a bs_response). */
unsigned char m_nextSendPos;
size_t m_nextSendPos;
/** the number of received symbols in the last second. */
unsigned int m_symPerSec;
@@ -636,10 +636,10 @@ class BusHandler : public WaitThread {
BusState m_state;
/** 0 when not escaping/unescaping, or @a ESC when receiving, or the original value when sending. */
unsigned char m_escape;
symbol_t m_escape;
/** the calculated CRC. */
unsigned char m_crc;
symbol_t m_crc;
/** whether the CRC matched. */
bool m_crcValid;
@@ -654,10 +654,10 @@ class BusHandler : public WaitThread {
SlaveSymbolString m_response;
/** the participating bus addresses seen so far (0 if not seen yet, or combination of @a SEEN bits). */
unsigned char m_seenAddresses[256];
symbol_t m_seenAddresses[256];
/** the scan results by slave address. */
map<unsigned char, string> m_scanResults;
map<symbol_t, string> m_scanResults;
/** whether to grab messages. */
bool m_grabMessages;
+23 -36
View File
@@ -296,13 +296,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
} else if (strcmp("full", arg) == 0) {
opt->initialScan = SYN;
} else {
opt->initialScan = (unsigned char)parseInt(arg, 16, 0x00, 0xff, result);
opt->initialScan = (symbol_t)parseInt(arg, 16, 0x00, 0xff, result);
if (!isValidAddress(opt->initialScan)) {
argp_error(state, "invalid initial scan address");
return EINVAL;
}
if (isMaster(opt->initialScan)) {
opt->initialScan = (unsigned char)(opt->initialScan+5);
opt->initialScan = getSlaveAddress(opt->initialScan);
}
}
}
@@ -328,7 +328,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
// eBUS options:
case 'a': // --address=31
opt->address = (unsigned char)parseInt(arg, 16, 0, 0xff, result);
opt->address = (symbol_t)parseInt(arg, 16, 0, 0xff, result);
if (result != RESULT_OK || !isMaster(opt->address)) {
argp_error(state, "invalid address");
return EINVAL;
@@ -875,32 +875,24 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
return RESULT_OK;
}
result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSymbolString& data, string& relativeFile,
result_t loadScanConfigFile(MessageMap* messages, symbol_t address, SlaveSymbolString& data, string& relativeFile,
bool verbose) {
PartType partType;
if (isMaster(address)) {
address = (unsigned char)(data[0]+5); // slave address of sending master
partType = pt_masterData;
if (data.size() < 5+1+5+2+2) { // skip QQ ZZ PB SB NN
logError(lf_main, "unable to load scan config %2.2x: master part too short", address);
return RESULT_EMPTY;
}
} else {
partType = pt_slaveData;
if (data.size() < 1+1+5+2+2) { // skip NN
logError(lf_main, "unable to load scan config %2.2x: slave part too short", address);
return RESULT_EMPTY;
}
address = getSlaveAddress(data[0]); // slave address of sending master
}
if (data.getDataSize() < 1+5+2+2) {
logError(lf_main, "unable to load scan config %2.2x: slave part too short", address);
return RESULT_EMPTY;
}
DataFieldSet* identFields = DataFieldSet::getIdentFields();
string path, prefix, ident; // path: cfgpath/MANUFACTURER, prefix: ZZ., ident: C[C[C[C[C]]]], SW: xxxx, HW: xxxx
unsigned int sw = 0, hw = 0;
ostringstream out;
unsigned char offset = 0;
unsigned char field = 0;
result_t result = (*identFields)[field]->read(partType, data, offset, out, 0); // manufacturer name
size_t offset = 0;
size_t field = 0;
result_t result = (*identFields)[field]->read(data, offset, out, 0); // manufacturer name
if (result == RESULT_ERR_NOTFOUND) {
result = (*identFields)[field]->read(partType, data, offset, out, OF_NUMERIC); // manufacturer name
result = (*identFields)[field]->read(data, offset, out, OF_NUMERIC); // manufacturer name
}
if (result == RESULT_OK) {
path = out.str();
@@ -911,26 +903,24 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSy
prefix = out.str();
out.str("");
out.clear();
offset = (unsigned char)(offset+(*identFields)[field++]->getLength(partType));
result = (*identFields)[field]->read(partType, data, offset, out, 0); // identification string
offset += (*identFields)[field++]->getLength(pt_slaveData);
result = (*identFields)[field]->read(data, offset, out, 0); // identification string
}
if (result == RESULT_OK) {
ident = out.str();
out.str("");
offset = (unsigned char)(offset+(*identFields)[field++]->getLength(partType));
result = (*identFields)[field]->read(partType, data, offset, sw, 0); // software version number
offset += (*identFields)[field++]->getLength(pt_slaveData);
result = (*identFields)[field]->read(data, offset, sw, 0); // software version number
if (result == RESULT_ERR_OUT_OF_RANGE) {
sw = (data[(partType == pt_masterData ? 5 : 1)+offset] << 16)
| data[(partType == pt_masterData ? 5 : 1)+offset+1];
sw = (data.dataAt(offset) << 16) | data.dataAt(offset+1); // use hex value instead
result = RESULT_OK;
}
}
if (result == RESULT_OK) {
offset = (unsigned char)(offset+(*identFields)[field++]->getLength(partType));
result = (*identFields)[field]->read(partType, data, offset, hw, 0); // hardware version number
offset += (*identFields)[field++]->getLength(pt_slaveData);
result = (*identFields)[field]->read(data, offset, hw, 0); // hardware version number
if (result == RESULT_ERR_OUT_OF_RANGE) {
hw = (data[(partType == pt_masterData ? 5 : 1)+offset] << 16)
| data[(partType == pt_masterData ? 5 : 1)+offset+1];
hw = (data.dataAt(offset) << 16) | data.dataAt(offset+1); // use hex value instead
result = RESULT_OK;
}
}
@@ -967,7 +957,7 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSy
string best;
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
string name = *it;
unsigned char checkDest;
symbol_t checkDest;
string checkIdent, useCircuit, useSuffix;
unsigned int checkSw, checkHw;
if (!FileReader::extractDefaultsFromFilename(name.substr(path.length()+1), checkDest, checkIdent, useCircuit,
@@ -1053,9 +1043,6 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSy
* @return the exit code.
*/
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 };
int arg_index = -1;
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
@@ -1098,7 +1085,7 @@ int main(int argc, char* argv[]) {
logError(lf_main, "invalid scan message %s: master part too short", arg.c_str());
continue;
}
unsigned char address = master[1];
symbol_t address = master[1];
Message* message = s_messageMap->getScanMessage(address);
if (!message) {
logError(lf_main, "invalid scan address %2.2x", address);
+3 -3
View File
@@ -44,12 +44,12 @@ struct options {
bool scanConfig; //!< pick configuration files matching initial scan
/** the initial address to scan for scanconfig
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
unsigned char initialScan;
symbol_t initialScan;
bool checkConfig; //!< check CSV config files, then stop
bool dumpConfig; //!< dump CSV config files, then stop
unsigned int pollInterval; //!< poll interval in seconds, 0 to disable [5]
unsigned char address; //!< own bus address [31]
symbol_t address; //!< own bus address [31]
bool answer; //!< answer to requests from other masters
unsigned int acquireTimeout; //!< bus acquisition timeout in us [9400]
unsigned int acquireRetries; //!< number of retries for bus acquisition [3]
@@ -108,7 +108,7 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose = false, bool denyRe
* @param verbose whether to verbosely log problems.
* @return the result code.
*/
result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SlaveSymbolString& data, string& relativeFile,
result_t loadScanConfigFile(MessageMap* messages, symbol_t address, SlaveSymbolString& data, string& relativeFile,
bool verbose = false);
} // namespace ebusd
+33 -33
View File
@@ -193,7 +193,7 @@ void MainLoop::run() {
bool reload = true;
time_t lastTaskRun, now, lastSignal = 0, since, sinkSince = 1;
int taskDelay = 5;
unsigned char lastScanAddress = 0; // 0 is known to be a master
symbol_t lastScanAddress = 0; // 0 is known to be a master
time(&now);
lastTaskRun = now;
ostringstream updates;
@@ -341,17 +341,17 @@ void MainLoop::run() {
}
}
void MainLoop::notifyDeviceData(const unsigned char byte, bool received) {
void MainLoop::notifyDeviceData(const symbol_t symbol, bool received) {
if (received && m_dumpFile) {
m_dumpFile->write((unsigned char*)&byte, 1);
m_dumpFile->write((unsigned char*)&symbol, 1);
}
if (m_logRawFile) {
m_logRawFile->write((unsigned char*)&byte, 1, received);
m_logRawFile->write((unsigned char*)&symbol, 1, received);
} else if (m_logRawEnabled) {
if (received) {
logNotice(lf_bus, "<%02x", byte);
logNotice(lf_bus, "<%02x", symbol);
} else {
logNotice(lf_bus, ">%02x", byte);
logNotice(lf_bus, ">%02x", symbol);
}
}
}
@@ -473,7 +473,7 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn
}
result_t MainLoop::parseHexMaster(vector<string> &args, size_t argPos, MasterSymbolString& master,
unsigned char srcAddress) {
symbol_t srcAddress) {
ostringstream msg;
while (argPos < args.size()) {
if ((args[argPos].length() % 2) != 0) {
@@ -520,7 +520,8 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
OutputFormat verbosity = 0;
time_t maxAge = 5*60;
string circuit, params;
unsigned char srcAddress = SYN, dstAddress = SYN, pollPriority = 0;
symbol_t srcAddress = SYN, dstAddress = SYN;
size_t pollPriority = 0;
while (args.size() > argPos && args[argPos][0] == '-') {
if (args[argPos] == "-h") {
hex = true;
@@ -572,7 +573,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
}
bool dest = args[argPos] == "-d";
result_t ret;
unsigned char address = (unsigned char)parseInt(args[argPos].c_str(), 16, 0, 0xff, ret);
symbol_t address = (symbol_t)parseInt(args[argPos].c_str(), 16, 0, 0xff, ret);
if (ret != RESULT_OK || !isValidAddress(address, dest) || dest == isMaster(address)) {
return getResultCode(RESULT_ERR_INVALID_ADDR);
}
@@ -588,7 +589,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
break;
}
result_t ret;
pollPriority = (unsigned char)parseInt(args[argPos].c_str(), 10, 1, 9, ret);
pollPriority = (size_t)parseInt(args[argPos].c_str(), 10, 1, 9, ret);
if (ret != RESULT_OK) {
return getResultCode(RESULT_ERR_INVALID_NUM);
}
@@ -622,7 +623,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
if (master[1] == BROADCAST || isMaster(master[1])) {
return getResultCode(RESULT_ERR_INVALID_ARG);
}
logNotice(lf_main, "read hex cmd: %s", master.getDataStr().c_str());
logNotice(lf_main, "read hex cmd: %s", master.getStr().c_str());
// find message
Message* message = m_messages->find(master, false, true, false, false);
@@ -644,7 +645,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
|| (message->isPassive() && message->getLastUpdateTime() != 0))) {
SlaveSymbolString& slave = message->getLastSlaveData();
logNotice(lf_main, "hex read %s %s from cache", message->getCircuit().c_str(), message->getName().c_str());
return slave.getDataStr();
return slave.getStr();
}
// send message
@@ -664,7 +665,7 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
logError(lf_main, "read hex %s %s cache update: %s", message->getCircuit().c_str(), message->getName().c_str(),
getResultCode(ret));
}
return slave.getDataStr();
return slave.getStr();
}
logError(lf_main, "read hex %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(),
getResultCode(ret));
@@ -695,14 +696,14 @@ string MainLoop::executeRead(vector<string> &args, const string levels) {
" Dx data byte(s) to send";
}
string fieldName;
signed char fieldIndex = -2;
ssize_t fieldIndex = -2;
if (args.size() == argPos + 2) {
fieldName = args[argPos + 1];
fieldIndex = -1;
size_t pos = fieldName.find_last_of('.');
if (pos != string::npos) {
result_t result = RESULT_OK;
fieldIndex = static_cast<char>(parseInt(fieldName.substr(pos+1).c_str(), 10, 0, MAX_POS, result));
fieldIndex = static_cast<ssize_t>(parseInt(fieldName.substr(pos+1).c_str(), 10, 0, MAX_POS, result));
if (result == RESULT_OK) {
fieldName = fieldName.substr(0, pos);
}
@@ -781,7 +782,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
size_t argPos = 1;
bool hex = false;
string circuit;
unsigned char srcAddress = SYN, dstAddress = SYN;
symbol_t srcAddress = SYN, dstAddress = SYN;
while (args.size() > argPos && args[argPos][0] == '-') {
if (args[argPos] == "-h") {
hex = true;
@@ -793,7 +794,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
}
bool dest = args[argPos] == "-d";
result_t ret;
unsigned char address = (unsigned char)parseInt(args[argPos].c_str(), 16, 0, 0xff, ret);
symbol_t address = (symbol_t)parseInt(args[argPos].c_str(), 16, 0, 0xff, ret);
if (ret != RESULT_OK || !isValidAddress(address, dest) || dest == isMaster(address)) {
return getResultCode(RESULT_ERR_INVALID_ADDR);
}
@@ -826,7 +827,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
if (ret != RESULT_OK) {
return getResultCode(ret);
}
logNotice(lf_main, "write hex cmd: %s", master.getDataStr().c_str());
logNotice(lf_main, "write hex cmd: %s", master.getStr().c_str());
// find message
Message* message = m_messages->find(master, false, false, true, false);
@@ -867,7 +868,7 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
if (isMaster(master[1])) {
return getResultCode(RESULT_OK);
}
return slave.getDataStr();
return slave.getStr();
}
logError(lf_main, "write hex %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(),
getResultCode(ret));
@@ -936,14 +937,14 @@ string MainLoop::executeWrite(vector<string> &args, const string levels) {
string MainLoop::executeHex(vector<string> &args) {
size_t argPos = 1;
unsigned char srcAddress = SYN;
symbol_t srcAddress = SYN;
if (args.size() > argPos && args[argPos] == "-s") {
argPos++;
if (argPos >= args.size()) {
argPos = 0; // print usage
} else {
result_t ret;
unsigned char address = (unsigned char)parseInt(args[argPos].c_str(), 16, 0, 0xff, ret);
symbol_t address = (symbol_t)parseInt(args[argPos].c_str(), 16, 0, 0xff, ret);
if (ret != RESULT_OK || !isValidAddress(address, false) || !isMaster(address)) {
return getResultCode(RESULT_ERR_INVALID_ADDR);
}
@@ -961,7 +962,7 @@ string MainLoop::executeHex(vector<string> &args) {
if (ret != RESULT_OK) {
return getResultCode(ret);
}
logNotice(lf_main, "hex cmd: %s", master.getDataStr().c_str());
logNotice(lf_main, "hex cmd: %s", master.getStr().c_str());
// send message
SlaveSymbolString slave;
@@ -974,7 +975,7 @@ string MainLoop::executeHex(vector<string> &args) {
if (isMaster(master[1])) {
return getResultCode(RESULT_OK);
}
return slave.getDataStr();
return slave.getStr();
}
logError(lf_main, "hex: %s", getResultCode(ret));
return getResultCode(ret);
@@ -996,7 +997,7 @@ string MainLoop::executeFind(vector<string> &args, string levels) {
OutputFormat verbosity = 0;
vector<column_t> columns;
string circuit;
vector<unsigned char> id;
vector<symbol_t> id;
while (args.size() > argPos && args[argPos][0] == '-') {
if (args[argPos] == "-v") {
switch (verbosity) {
@@ -1165,18 +1166,17 @@ string MainLoop::executeFind(vector<string> &args, string levels) {
if (lastup == 0) {
result << "no data stored";
} else if (hexFormat) {
result << message->getLastMasterData().getDataStr()
<< " / " << message->getLastSlaveData().getDataStr();
result << message->getLastMasterData().getStr() << " / " << message->getLastSlaveData().getStr();
} else {
result_t ret = message->decodeLastData(result, verbosity);
if (ret != RESULT_OK) {
result << " (" << getResultCode(ret)
<< " for " << message->getLastMasterData().getDataStr()
<< " / " << message->getLastSlaveData().getDataStr() << ")";
<< " for " << message->getLastMasterData().getStr()
<< " / " << message->getLastSlaveData().getStr() << ")";
}
}
if (verbosity == (OF_NAMES|OF_UNITS|OF_COMMENTS)) {
unsigned char dstAddress = message->getDstAddress();
symbol_t dstAddress = message->getDstAddress();
if (dstAddress != SYN) {
snprintf(str, sizeof(str), "%02x", dstAddress);
} else if (lastup != 0 && message->getLastMasterData().size() > 1) {
@@ -1298,7 +1298,7 @@ string MainLoop::executeScan(vector<string> &args, string levels) {
}
result_t result;
unsigned char dstAddress = (unsigned char)parseInt(args[1].c_str(), 16, 0, 0xff, result);
symbol_t dstAddress = (symbol_t)parseInt(args[1].c_str(), 16, 0, 0xff, result);
if (result == RESULT_OK && !isValidAddress(dstAddress, false)) {
result = RESULT_ERR_INVALID_ADDR;
}
@@ -1475,7 +1475,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected) {
name = uri.substr(pos + 1);
}
time_t since = 0;
unsigned char pollPriority = 0;
size_t pollPriority = 0;
bool exact = false;
string user = "";
if (args.size() > argPos) {
@@ -1495,7 +1495,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected) {
if (qname == "since") {
since = parseInt(value.c_str(), 10, 0, 0xffffffff, ret);
} else if (qname == "poll") {
pollPriority = (unsigned char)parseInt(value.c_str(), 10, 1, 9, ret);
pollPriority = (size_t)parseInt(value.c_str(), 10, 1, 9, ret);
} else if (qname == "exact") {
exact = value.length() == 0 || value == "1";
} else if (qname == "verbose") {
@@ -1533,7 +1533,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected) {
bool first = true;
for (deque<Message*>::iterator it = messages.begin(); it != messages.end();) {
Message* message = *it++;
unsigned char dstAddress = message->getDstAddress();
symbol_t dstAddress = message->getDstAddress();
if (dstAddress == SYN) {
continue;
}
+9 -9
View File
@@ -64,20 +64,20 @@ class UserList : public UserInfo, public FileReader {
// @copydoc
virtual result_t addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end,
vector< vector<string> >* defaults, const string& defaultDest, const string& defaultCircuit,
const string& defaultSuffix, const string& filename, unsigned int lineNo);
const string& defaultSuffix, const string& filename, unsigned int lineNo) override;
// @copydoc
virtual bool hasUser(const string user) {
virtual bool hasUser(const string user) override {
return m_userLevels.find(user) != m_userLevels.end();
}
// @copydoc
virtual bool checkSecret(const string user, const string secret) {
virtual bool checkSecret(const string user, const string secret) override {
return m_userSecrets.find(user) != m_userSecrets.end() && m_userSecrets[user] == secret;
}
// @copydoc
virtual string getLevels(const string user) { return m_userLevels[user]; }
virtual string getLevels(const string user) override { return m_userLevels[user]; }
private:
/** the secret string by user name. */
@@ -119,12 +119,12 @@ class MainLoop : public Thread, DeviceListener {
void addMessage(NetMessage* message) { m_netQueue.push(message); }
// @copydoc
virtual void notifyDeviceData(const unsigned char byte, bool received);
virtual void notifyDeviceData(const symbol_t symbol, bool received) override;
protected:
// @copydoc
virtual void run();
virtual void run() override;
private:
@@ -150,7 +150,7 @@ class MainLoop : public Thread, DeviceListener {
* @return the result from parsing the arguments.
*/
result_t parseHexMaster(vector<string> &args, size_t argPos, MasterSymbolString& master,
unsigned char srcAddress = SYN);
symbol_t srcAddress = SYN);
/**
* Get the access levels associated with the specified user name.
@@ -317,14 +317,14 @@ class MainLoop : public Thread, DeviceListener {
MessageMap* m_messages;
/** the own master address for sending on the bus. */
const unsigned char m_address;
const symbol_t m_address;
/** whether to pick configuration files matching initial scan. */
const bool m_scanConfig;
/** the initial address to scan for @a m_scanConfig
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
const unsigned char m_initialScan;
const symbol_t m_initialScan;
/** whether to enable the hex command. */
const bool m_enableHex;
+7 -7
View File
@@ -39,7 +39,7 @@ void contrib_tem_register() {
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
}
result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) {
result_t TemParamDataType::derive(int divisor, size_t bitCount, NumberDataType* &derived) {
if (divisor == 0) {
divisor = 1;
}
@@ -53,8 +53,8 @@ result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDat
return RESULT_ERR_INVALID_ARG;
}
result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
result_t TemParamDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
@@ -72,7 +72,7 @@ result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
return RESULT_OK;
}
int grp = 0, num = 0;
if (isMaster) {
if (input.isMaster()) {
grp = (value & 0x1f); // grp in bits 0...5
num = ((value >> 8) & 0x7f); // num in bits 8...13
} else {
@@ -91,8 +91,8 @@ result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
}
result_t TemParamDataType::writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
unsigned int value;
int grp, num;
string token;
@@ -128,7 +128,7 @@ result_t TemParamDataType::writeSymbols(istringstream& input,
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
if (isMaster) {
if (output.isMaster()) {
value = grp | (num << 8); // grp in bits 0...5, num in bits 8...13
} else {
value = (grp << 7) | num; // grp in bits 7...11, num in bits 0...6
+6 -6
View File
@@ -50,17 +50,17 @@ class TemParamDataType : public NumberDataType {
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {}
// @copydoc
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
virtual result_t derive(int divisor, size_t bitCount, NumberDataType* &derived) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
};
/**
+10 -12
View File
@@ -131,22 +131,20 @@ int main() {
ostringstream output;
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
result = writeMstr.parseHex(mstr.getStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
result = writeSstr.parseHex(sstr.getStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, 0, -1, false);
result = fields->read(mstr, 0, output, 0, -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, 0, -1, !output.str().empty());
result = fields->read(sstr, 0, output, 0, -1, !output.str().empty());
}
if (failedRead) {
if (result >= RESULT_OK) {
@@ -167,9 +165,9 @@ int main() {
}
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
result = fields->write(input, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
result = fields->write(input, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
@@ -186,8 +184,8 @@ int main() {
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr() + " "
+ sstr.getDataStr(), writeMstr.getDataStr() + " " + writeSstr.getDataStr());
verify(failedWriteMatch, "write", expectStr, match, mstr.getStr() + " " + sstr.getStr(),
writeMstr.getStr() + " " + writeSstr.getStr());
}
delete fields;
fields = NULL;
+79 -104
View File
@@ -44,7 +44,7 @@ result_t DataField::create(vector<string>::iterator& it,
DataFieldTemplates* templates, DataField*& returnField,
const bool isWriteMessage,
const bool isTemplate, const bool isBroadcastOrMasterDestination,
const unsigned char maxFieldLength) {
const size_t maxFieldLength) {
vector<SingleDataField*> fields;
string firstName, firstComment;
result_t result = RESULT_OK;
@@ -188,7 +188,7 @@ result_t DataField::create(vector<string>::iterator& it,
templ = templates->get(token.substr(0, pos));
}
if (templ == NULL) { // basetype[:len]
unsigned char length;
size_t length;
string typeName;
if (pos == string::npos) {
length = 0; // no length specified
@@ -197,7 +197,7 @@ result_t DataField::create(vector<string>::iterator& it,
if (pos+2 == token.length() && token[pos+1] == '*') {
length = REMAIN_LEN;
} else {
length = (unsigned char)parseInt(token.substr(pos+1).c_str(), 10, 1, maxFieldLength, result);
length = (size_t)parseInt(token.substr(pos+1).c_str(), 10, 1, (unsigned int)maxFieldLength, result);
if (result != RESULT_OK) {
break;
}
@@ -271,16 +271,16 @@ string DataField::getDayName(int day) {
return dayNames[day];
}
result_t SingleDataField::create(const string id, const unsigned char length,
result_t SingleDataField::create(const string id, const size_t length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField) {
DataType* dataType = DataTypeList::getInstance()->get(id, length == REMAIN_LEN ? (unsigned char)0 : length);
DataType* dataType = DataTypeList::getInstance()->get(id, length == REMAIN_LEN ? 0 : length);
if (!dataType) {
return RESULT_ERR_NOTFOUND;
}
unsigned char bitCount = dataType->getBitCount();
unsigned char byteCount = (unsigned char)((bitCount + 7) / 8);
size_t bitCount = dataType->getBitCount();
size_t byteCount = (bitCount + 7) / 8;
if (dataType->isAdjustableLength()) {
// check length
if ((bitCount % 8) != 0) {
@@ -291,7 +291,7 @@ result_t SingleDataField::create(const string id, const unsigned char length,
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
byteCount = (unsigned char)((bitCount + 7) / 8);
byteCount = (bitCount + 7) / 8;
} else if (length == 0) {
byteCount = 1; // default byte count: 1 byte
} else if (length <= byteCount || length == REMAIN_LEN) {
@@ -348,24 +348,16 @@ void SingleDataField::dump(ostream& output) {
}
result_t SingleDataField::read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName, signed char fieldIndex) {
if (partType != m_partType) {
return RESULT_EMPTY;
}
switch (m_partType) {
case pt_masterData:
offset = (unsigned char)(offset + 5); // skip QQ ZZ PB SB NN
break;
case pt_slaveData:
offset++; // skip NN
break;
default:
result_t SingleDataField::read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName, ssize_t fieldIndex) {
if (m_partType == pt_any) {
return RESULT_ERR_INVALID_PART;
}
if ((data.isMaster() ? pt_masterData : pt_slaveData) != m_partType) {
return RESULT_EMPTY;
}
bool remainder = m_length == REMAIN_LEN && m_dataType->isAdjustableLength();
if (offset + (remainder?1:m_length) > data.size()) {
if (offset + (remainder?1:m_length) > data.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
@@ -374,25 +366,17 @@ result_t SingleDataField::read(const PartType partType,
return m_dataType->readRawValue(data, offset, m_length, output);
}
result_t SingleDataField::read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
if (partType != m_partType) {
return RESULT_OK;
}
switch (m_partType) {
case pt_masterData:
offset = (unsigned char)(offset + 5); // skip QQ ZZ PB SB NN
break;
case pt_slaveData:
offset++; // skip NN
break;
default:
result_t SingleDataField::read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
if (m_partType == pt_any) {
return RESULT_ERR_INVALID_PART;
}
if ((data.isMaster() ? pt_masterData : pt_slaveData) != m_partType) {
return RESULT_OK;
}
bool remainder = m_length == REMAIN_LEN && m_dataType->isAdjustableLength();
if (offset + (remainder?1:m_length) > data.size()) {
if (offset + (remainder?1:m_length) > data.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
@@ -418,7 +402,7 @@ result_t SingleDataField::read(const PartType partType,
}
}
result_t result = readSymbols(data, m_partType == pt_masterData, offset, output, outputFormat);
result_t result = readSymbols(data, offset, output, outputFormat);
if (result != RESULT_OK) {
return result;
}
@@ -442,35 +426,27 @@ result_t SingleDataField::read(const PartType partType,
return RESULT_OK;
}
result_t SingleDataField::write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator, unsigned char* length) {
if (partType != m_partType) {
return RESULT_OK;
}
switch (m_partType) {
case pt_masterData:
offset = (unsigned char)(offset + 5); // skip QQ ZZ PB SB NN
break;
case pt_slaveData:
offset++; // skip NN
break;
default:
result_t SingleDataField::write(istringstream& input, SymbolString& data,
size_t offset, char separator, size_t* length) {
if (m_partType == pt_any) {
return RESULT_ERR_INVALID_PART;
}
return writeSymbols(input, (const unsigned char)offset, data, m_partType == pt_masterData, length);
if ((data.isMaster() ? pt_masterData : pt_slaveData) != m_partType) {
return RESULT_OK;
}
return writeSymbols(input, (const size_t)offset, data, length);
}
result_t SingleDataField::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
result_t SingleDataField::readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat) {
return m_dataType->readSymbols(input, isMaster, offset, m_length, output, outputFormat);
return m_dataType->readSymbols(input, offset, m_length, output, outputFormat);
}
result_t SingleDataField::writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
return m_dataType->writeSymbols(input, offset, m_length, output, isMaster, usedLength);
const size_t offset,
SymbolString& output, size_t* usedLength) {
return m_dataType->writeSymbols(input, offset, m_length, output, usedLength);
}
SingleDataField* SingleDataField::clone() {
@@ -522,9 +498,9 @@ bool SingleDataField::hasField(const char* fieldName, bool numeric) {
return numeric == numericType && (fieldName == NULL || fieldName == m_name);
}
unsigned char SingleDataField::getLength(PartType partType, unsigned char maxLength) {
size_t SingleDataField::getLength(PartType partType, size_t maxLength) {
if (partType != m_partType) {
return (unsigned char)0;
return 0;
}
bool remainder = m_length == REMAIN_LEN && m_dataType->isAdjustableLength();
return remainder ? maxLength : m_length;
@@ -601,8 +577,8 @@ void ValueListDataField::dump(ostream& output) {
dumpString(output, m_comment);
}
result_t ValueListDataField::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
result_t ValueListDataField::readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
@@ -633,8 +609,8 @@ result_t ValueListDataField::readSymbols(SymbolString& input, const bool isMaste
}
result_t ValueListDataField::writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset,
SymbolString& output, size_t* usedLength) {
NumberDataType* numType = reinterpret_cast<NumberDataType*>(m_dataType);
if (isIgnored()) {
// replacement value
@@ -711,11 +687,11 @@ void ConstantDataField::dump(ostream& output) {
dumpString(output, m_comment);
}
result_t ConstantDataField::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
result_t ConstantDataField::readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat) {
ostringstream coutput;
result_t result = SingleDataField::readSymbols(input, isMaster, offset, coutput, 0);
result_t result = SingleDataField::readSymbols(input, offset, coutput, 0);
if (result != RESULT_OK) {
return result;
}
@@ -730,10 +706,10 @@ result_t ConstantDataField::readSymbols(SymbolString& input, const bool isMaster
}
result_t ConstantDataField::writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset,
SymbolString& output, size_t* usedLength) {
istringstream cinput(m_value);
return SingleDataField::writeSymbols(cinput, offset, output, isMaster, usedLength);
return SingleDataField::writeSymbols(cinput, offset, output, usedLength);
}
@@ -795,8 +771,8 @@ DataFieldSet* DataFieldSet::clone() {
return new DataFieldSet(m_name, m_comment, fields);
}
unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength) {
unsigned char length = 0;
size_t DataFieldSet::getLength(PartType partType, size_t maxLength) {
size_t length = 0;
bool previousFullByteOffset[] = { true, true, true, true };
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
@@ -805,13 +781,13 @@ unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength
if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) {
length--;
}
unsigned char fieldLength = field->getLength(partType, maxLength);
size_t fieldLength = field->getLength(partType, maxLength);
if (fieldLength >= maxLength) {
maxLength = 0;
} else {
maxLength = (unsigned char)(maxLength-fieldLength);
maxLength = maxLength - fieldLength;
}
length = (unsigned char)(length + fieldLength);
length = length + fieldLength;
previousFullByteOffset[partType] = field->hasFullByteOffset(true);
}
@@ -820,11 +796,11 @@ unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength
return length;
}
string DataFieldSet::getName(signed char fieldIndex) {
string DataFieldSet::getName(ssize_t fieldIndex) {
if (fieldIndex < 0) {
return m_name;
}
if ((unsigned char)fieldIndex >= m_fields.size()) {
if ((size_t)fieldIndex >= m_fields.size()) {
return "";
}
if (m_uniqueNames) {
@@ -876,23 +852,23 @@ void DataFieldSet::dump(ostream& output) {
}
}
result_t DataFieldSet::read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName, signed char fieldIndex) {
result_t DataFieldSet::read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName, ssize_t fieldIndex) {
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it;
if (partType != pt_any && field->getPartType() != partType) {
if (field->getPartType() != partType) {
continue;
}
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) {
offset--;
}
result_t result = field->read(partType, data, offset, output, fieldName, fieldIndex);
result_t result = field->read(data, offset, output, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
offset = (unsigned char)(offset + field->getLength(partType, (unsigned char)(data.size()-offset)));
offset += field->getLength(partType, data.getDataSize()-offset);
previousFullByteOffset = field->hasFullByteOffset(true);
if (result != RESULT_EMPTY) {
found = true;
@@ -915,17 +891,17 @@ result_t DataFieldSet::read(const PartType partType,
return RESULT_OK;
}
result_t DataFieldSet::read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
result_t DataFieldSet::read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
if (!m_uniqueNames && outputIndex < 0) {
outputIndex = 0;
}
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it;
if (partType != pt_any && field->getPartType() != partType) {
if (field->getPartType() != partType) {
if (outputIndex >= 0 && !field->isIgnored()) {
outputIndex++;
}
@@ -934,12 +910,12 @@ result_t DataFieldSet::read(const PartType partType,
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) {
offset--;
}
result_t result = field->read(partType, data, offset, output, outputFormat, outputIndex, leadingSeparator,
result_t result = field->read(data, offset, output, outputFormat, outputIndex, leadingSeparator,
fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
offset = (unsigned char)(offset + field->getLength(partType, (unsigned char)(data.size()-offset)));
offset += field->getLength(partType, data.getDataSize()-offset);
previousFullByteOffset = field->hasFullByteOffset(true);
if (result != RESULT_EMPTY) {
found = true;
@@ -973,23 +949,22 @@ result_t DataFieldSet::read(const PartType partType,
return RESULT_OK;
}
result_t DataFieldSet::write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator, unsigned char* length) {
result_t DataFieldSet::write(istringstream& input, SymbolString& data,
size_t offset, char separator, size_t* length) {
string token;
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
bool previousFullByteOffset = true;
unsigned char baseOffset = offset;
size_t baseOffset = offset;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it;
if (partType != pt_any && field->getPartType() != partType) {
if (field->getPartType() != partType) {
continue;
}
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) {
offset--;
}
result_t result;
unsigned char fieldLength;
size_t fieldLength;
if (m_fields.size() > 1) {
if (field->isIgnored()) {
token.clear();
@@ -997,19 +972,19 @@ result_t DataFieldSet::write(istringstream& input,
token.clear();
}
istringstream single(token);
result = (*it)->write(single, partType, data, offset, separator, &fieldLength);
result = (*it)->write(single, data, offset, separator, &fieldLength);
} else {
result = (*it)->write(input, partType, data, offset, separator, &fieldLength);
result = (*it)->write(input, data, offset, separator, &fieldLength);
}
if (result != RESULT_OK) {
return result;
}
offset = (unsigned char)(offset+fieldLength);
offset += fieldLength;
previousFullByteOffset = field->hasFullByteOffset(true);
}
if (length != NULL) {
*length = (unsigned char)(offset-baseOffset);
*length = offset-baseOffset;
}
return RESULT_OK;
}
+59 -77
View File
@@ -92,7 +92,7 @@ class DataField {
DataFieldTemplates* templates, DataField*& returnField,
const bool isWriteMessage,
const bool isTemplate, const bool isBroadcastOrMasterDestination,
const unsigned char maxFieldLength = MAX_POS);
const size_t maxFieldLength = MAX_POS);
/**
* Dump the @a string optionally embedded in @a TEXT_SEPARATOR to the output.
@@ -115,7 +115,7 @@ class DataField {
* @param maxLength the maximum length for calculating remainder of input.
* @return the length of this field (or contained fields) in bytes.
*/
virtual unsigned char getLength(PartType partType, unsigned char maxLength = MAX_LEN) = 0;
virtual size_t getLength(PartType partType, size_t maxLength = MAX_LEN) = 0;
/**
* Derive a new @a DataField from this field.
@@ -138,7 +138,7 @@ class DataField {
* @param fieldIndex the index of the field, or -1 for this.
* @return the field name, or the index as string if not unique or not available.
*/
virtual string getName(signed char fieldIndex = -1) { return m_name; }
virtual string getName(ssize_t fieldIndex = -1) { return m_name; }
/**
* Get the field comment.
@@ -162,7 +162,6 @@ class DataField {
/**
* Reads the numeric value from the @a SymbolString.
* @param partType the @a PartType of the data.
* @param data the data @a SymbolString for reading binary data.
* @param offset the additional offset to add for reading binary data.
* @param output the variable in which to store the numeric value.
@@ -173,13 +172,11 @@ class DataField {
* not match or ignored, or due to @a fieldName or @a fieldIndex),
* or an error code.
*/
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName = NULL, signed char fieldIndex = -1) = 0;
virtual result_t read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName = NULL, ssize_t fieldIndex = -1) = 0;
/**
* Reads the value from the @a SymbolString.
* @param partType the @a PartType of the data.
* @param data the 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.
@@ -192,24 +189,21 @@ class DataField {
* or @a RESULT_EMPTY if the field was skipped (either ignored or due to @a fieldName or @a fieldIndex),
* or an error code.
*/
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1) = 0;
virtual result_t read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) = 0;
/**
* Writes the value to the master or slave @a SymbolString.
* @param input the @a istringstream to parse the formatted value from.
* @param partType the @a PartType of the data.
* @param data the unescaped data @a SymbolString for writing binary data.
* @param offset the additional offset to add for writing binary data.
* @param separator the separator character between multiple fields.
* @param length the variable in which to store the used length in bytes, or NULL.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator = UI_FIELD_SEPARATOR, unsigned char* length = NULL) = 0;
virtual result_t write(istringstream& input, SymbolString& data,
size_t offset, char separator = UI_FIELD_SEPARATOR, size_t* length = NULL) = 0;
protected:
@@ -237,7 +231,7 @@ class SingleDataField : public DataField {
*/
SingleDataField(const string name, const string comment,
const string unit, DataType* dataType, const PartType partType,
const unsigned char length)
const size_t length)
: DataField(name, comment),
m_unit(unit), m_dataType(dataType), m_partType(partType),
m_length(length) {}
@@ -248,7 +242,7 @@ class SingleDataField : public DataField {
virtual ~SingleDataField() {}
// @copydoc
virtual SingleDataField* clone();
virtual SingleDataField* clone() override;
/**
* Factory method for creating a new @a SingleDataField instance derived from a base type.
@@ -266,7 +260,7 @@ class SingleDataField : public DataField {
* @return @a RESULT_OK on success, or an error code.
* Note: the caller needs to free the created instance.
*/
static result_t create(const string id, const unsigned char length,
static result_t create(const string id, const size_t length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField);
@@ -290,13 +284,13 @@ class SingleDataField : public DataField {
PartType getPartType() const { return m_partType; }
// @copydoc
virtual unsigned char getLength(PartType partType, unsigned char maxLength = MAX_LEN);
virtual size_t getLength(PartType partType, size_t maxLength = MAX_LEN) override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
/**
* Get whether this field uses a full byte offset.
@@ -307,40 +301,36 @@ class SingleDataField : public DataField {
bool hasFullByteOffset(bool after);
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
// @copydoc
virtual bool hasField(const char* fieldName, bool numeric);
virtual bool hasField(const char* fieldName, bool numeric) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator = UI_FIELD_SEPARATOR, unsigned char* length = NULL);
virtual result_t write(istringstream& input, SymbolString& data,
size_t offset, char separator = UI_FIELD_SEPARATOR, size_t* length = NULL) override;
protected:
/**
* Internal method for reading the field from a @a SymbolString.
* @param input the @a SymbolString to read the binary value from.
* @param isMaster whether the @a SymbolString is the master part.
* @param offset the offset in the @a SymbolString.
* @param output the ostringstream to append the formatted value to.
* @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 bool isMaster,
const unsigned char offset,
virtual result_t readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat);
/**
@@ -348,13 +338,12 @@ class SingleDataField : public DataField {
* @param input the @a istringstream to parse the formatted value from.
* @param offset the offset in the @a SymbolString.
* @param output the @a SymbolString to write the binary value to.
* @param isMaster whether the @a SymbolString is the master part.
* @param usedLength the variable in which to store the used length in bytes, or NULL.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset,
SymbolString& output, size_t* usedLength);
/** the value unit. */
const string m_unit;
@@ -366,7 +355,7 @@ class SingleDataField : public DataField {
const PartType m_partType;
/** the number of symbols in the message part in which the field is stored. */
const unsigned char m_length;
const size_t m_length;
};
@@ -387,7 +376,7 @@ class ValueListDataField : public SingleDataField {
*/
ValueListDataField(const string name, const string comment,
const string unit, NumberDataType* dataType, const PartType partType,
const unsigned char length, const map<unsigned int, string> values)
const size_t length, const map<unsigned int, string> values)
: SingleDataField(name, comment, unit, dataType, partType, length),
m_values(values) {}
@@ -397,28 +386,26 @@ class ValueListDataField : public SingleDataField {
virtual ~ValueListDataField() {}
// @copydoc
virtual ValueListDataField* clone();
virtual ValueListDataField* clone() override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType, int divisor,
map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input, const size_t offset,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
virtual result_t writeSymbols(istringstream& input, const size_t offset,
SymbolString& output, size_t* usedLength) override;
private:
@@ -445,7 +432,7 @@ class ConstantDataField : public SingleDataField {
*/
ConstantDataField(const string name, const string comment,
const string unit, DataType* dataType, const PartType partType,
const unsigned char length, const string value, const bool verify)
const size_t length, const string value, const bool verify)
: SingleDataField(name, comment, unit, dataType, partType, length),
m_value(value), m_verify(verify) {}
@@ -455,28 +442,26 @@ class ConstantDataField : public SingleDataField {
virtual ~ConstantDataField() {}
// @copydoc
virtual ConstantDataField* clone();
virtual ConstantDataField* clone() override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType, int divisor,
map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input, const size_t offset,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
virtual result_t writeSymbols(istringstream& input, const size_t offset,
SymbolString& output, size_t* usedLength) override;
private:
@@ -538,19 +523,19 @@ class DataFieldSet : public DataField {
virtual ~DataFieldSet();
// @copydoc
virtual DataFieldSet* clone();
virtual DataFieldSet* clone() override;
// @copydoc
virtual unsigned char getLength(PartType partType, unsigned char maxLength = MAX_LEN);
virtual size_t getLength(PartType partType, size_t maxLength = MAX_LEN) override;
// @copydoc
virtual string getName(signed char fieldIndex = -1);
virtual string getName(ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
/**
* Returns the @a SingleDataField at the specified index.
@@ -583,26 +568,23 @@ class DataFieldSet : public DataField {
size_t size() const { return m_fields.size(); }
// @copydoc
virtual bool hasField(const char* fieldName, bool numeric);
virtual bool hasField(const char* fieldName, bool numeric) override;
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator = UI_FIELD_SEPARATOR, unsigned char* length = NULL);
virtual result_t write(istringstream& input, SymbolString& data,
size_t offset, char separator = UI_FIELD_SEPARATOR, size_t* length = NULL) override;
private:
@@ -658,7 +640,7 @@ class DataFieldTemplates : public FileReader {
// @copydoc
virtual result_t addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end,
vector< vector<string> >* defaults, const string& defaultDest, const string& defaultCircuit,
const string& defaultSuffix, const string& filename, unsigned int lineNo);
const string& defaultSuffix, const string& filename, unsigned int lineNo) override;
/**
* Gets the template @a DataField instance with the specified name.
+118 -118
View File
@@ -91,7 +91,7 @@ void printErrorPos(ostream& out, vector<string>::iterator begin, const vector<st
}
bool DataType::dump(ostream& output, const unsigned char length, const bool appendSeparatorDivisor) const {
bool DataType::dump(ostream& output, const size_t length, const bool appendSeparatorDivisor) const {
output << m_id;
if (isAdjustableLength()) {
if (length == REMAIN_LEN) {
@@ -107,21 +107,21 @@ bool DataType::dump(ostream& output, const unsigned char length, const bool appe
}
result_t StringDataType::readRawValue(SymbolString& input, const unsigned char offset,
const unsigned char length, unsigned int& value) {
result_t StringDataType::readRawValue(SymbolString& input, const size_t offset,
const size_t length, unsigned int& value) {
return RESULT_EMPTY;
}
result_t StringDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char baseOffset, const unsigned char length,
result_t StringDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch;
symbol_t symbol;
bool terminated = false;
if (count == REMAIN_LEN && input.size() > baseOffset) {
count = input.size()-baseOffset;
} else if (baseOffset + count > input.size()) {
if (count == REMAIN_LEN && input.getDataSize() > offset) {
count = input.getDataSize() - offset;
} else if (offset + count > input.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (hasFlag(REV)) { // reverted binary representation (most significant byte first)
@@ -133,27 +133,27 @@ result_t StringDataType::readSymbols(SymbolString& input, const bool isMaster,
output << '"';
}
output << setfill('0') << (m_isHex ? hex : dec);
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
ch = input[baseOffset + offset];
for (size_t index = start, i = 0; i < count; index += incr, i++) {
symbol = input.dataAt(offset + index);
if (m_isHex) {
if (i > 0) {
output << ' ';
}
output << setw(2) << static_cast<unsigned>(ch);
output << setw(2) << static_cast<unsigned>(symbol);
} else {
if (ch == 0x00) {
if (symbol == 0x00) {
terminated = true;
} else if (!terminated) {
if (ch < 0x20) {
ch = (unsigned char)m_replacement;
} else if (!isprint(ch)) {
ch = '?';
if (symbol < 0x20) {
symbol = (symbol_t)m_replacement;
} else if (!isprint(symbol)) {
symbol = '?';
} else if (outputFormat & OF_JSON) {
if (ch == '"' || ch == '\\') {
if (symbol == '"' || symbol == '\\') {
output << '\\'; // escape
}
}
output << static_cast<char>(ch);
output << static_cast<char>(symbol);
}
}
}
@@ -164,8 +164,8 @@ result_t StringDataType::readSymbols(SymbolString& input, const bool isMaster,
}
result_t StringDataType::writeSymbols(istringstream& input,
unsigned char baseOffset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
size_t start = 0, count = length;
bool remainder = count == REMAIN_LEN && hasFlag(ADJ);
int incr = 1;
@@ -180,17 +180,17 @@ result_t StringDataType::writeSymbols(istringstream& input,
if (remainder) {
count = 1;
}
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
output[baseOffset + offset] = (unsigned char)m_replacement; // fill up with replacement
for (size_t index = start, i = 0; i < count; index += incr, i++) {
output.dataAt(offset + index) = (symbol_t)m_replacement; // fill up with replacement
}
if (usedLength != NULL) {
*usedLength = (unsigned char)count;
*usedLength = count;
}
return RESULT_OK;
}
result_t result;
size_t i = 0, offset;
for (offset = start; i < count; offset += incr, i++) {
size_t i = 0, index;
for (index = start; i < count; index += incr, i++) {
if (m_isHex) {
while (!input.eof() && input.peek() == ' ') {
input.get();
@@ -199,11 +199,11 @@ result_t StringDataType::writeSymbols(istringstream& input,
value = m_replacement; // fill up with replacement
} else {
token.clear();
token.push_back((unsigned char)input.get());
token.push_back((symbol_t)input.get());
if (input.eof()) {
return RESULT_ERR_INVALID_NUM; // too short hex value
}
token.push_back((unsigned char)input.get());
token.push_back((symbol_t)input.get());
if (input.eof()) {
return RESULT_ERR_INVALID_NUM; // too short hex value
}
@@ -224,41 +224,41 @@ result_t StringDataType::writeSymbols(istringstream& input,
}
if (remainder && input.eof() && i > 0) {
if (value == 0x00 && !m_isHex) {
output[baseOffset + offset] = 0;
offset += incr;
output.dataAt(offset + index) = 0;
index += incr;
}
break;
}
if (value > 0xff) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
output[baseOffset + offset] = (unsigned char)value;
output.dataAt(offset + index) = (symbol_t)value;
}
if (!remainder && i < count) {
return RESULT_ERR_EOF; // input too short
}
if (usedLength != NULL) {
*usedLength = (unsigned char)((offset-start)*incr);
*usedLength = (index-start)*incr;
}
return RESULT_OK;
}
result_t DateTimeDataType::readRawValue(SymbolString& input, const unsigned char offset,
const unsigned char length, unsigned int& value) {
result_t DateTimeDataType::readRawValue(SymbolString& input, const size_t offset,
const size_t length, unsigned int& value) {
return RESULT_EMPTY;
}
result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char baseOffset, const unsigned char length,
result_t DateTimeDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch, last = 0, hour = 0;
if (count == REMAIN_LEN && input.size() > baseOffset) {
count = input.size()-baseOffset;
} else if (baseOffset + count > input.size()) {
symbol_t symbol, last = 0, hour = 0;
if (count == REMAIN_LEN && input.getDataSize() > offset) {
count = input.getDataSize() - offset;
} else if (offset + count > input.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (hasFlag(REV)) { // reverted binary representation (most significant byte first)
@@ -270,20 +270,20 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
output << '"';
}
int type = (m_hasDate?2:0) | (m_hasTime?1:0);
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
for (size_t index = start, i = 0; i < count; index += incr, i++) {
if (length == 4 && i == 2 && m_hasDate) {
continue; // skip weekday in between
}
ch = input[baseOffset + offset];
if (hasFlag(BCD) && (hasFlag(REQ) || ch != m_replacement)) {
if ((ch & 0xf0) > 0x90 || (ch & 0x0f) > 0x09) {
symbol = input.dataAt(offset + index);
if (hasFlag(BCD) && (hasFlag(REQ) || symbol != m_replacement)) {
if ((symbol & 0xf0) > 0x90 || (symbol & 0x0f) > 0x09) {
return RESULT_ERR_OUT_OF_RANGE; // invalid BCD
}
ch = (unsigned char)((ch >> 4) * 10 + (ch & 0x0f));
symbol = (symbol_t)((symbol >> 4) * 10 + (symbol & 0x0f));
}
switch (type) {
case 2: // date only
if (!hasFlag(REQ) && ch == m_replacement) {
if (!hasFlag(REQ) && symbol == m_replacement) {
if (i + 1 != length) {
output << NULL_VALUE << ".";
break;
@@ -299,7 +299,7 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
if (i == 0) {
break;
}
int mjd = last + ch*256 + 15020; // 01.01.1900
int mjd = last + symbol*256 + 15020; // 01.01.1900
int y = static_cast<int>((mjd-15078.2)/365.25);
int m = static_cast<int>((mjd-14956.1-static_cast<int>(y*365.25))/30.6001);
int d = mjd-14956-static_cast<int>(y*365.25)-static_cast<int>(m*30.6001);
@@ -313,16 +313,16 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
break;
}
if (i + 1 == length) {
output << (2000 + ch);
} else if (ch < 1 || (i == 0 && ch > 31) || (i == 1 && ch > 12)) {
output << (2000 + symbol);
} else if (symbol < 1 || (i == 0 && symbol > 31) || (i == 1 && symbol > 12)) {
return RESULT_ERR_OUT_OF_RANGE; // invalid date
} else {
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(ch) << ".";
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(symbol) << ".";
}
break;
case 1: // time only
if (!hasFlag(REQ) && ch == m_replacement) {
if (!hasFlag(REQ) && symbol == m_replacement) {
if (length == 1) { // truncated time
output << NULL_VALUE << ":" << NULL_VALUE;
break;
@@ -335,10 +335,10 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
}
if (hasFlag(SPE)) { // minutes since midnight
if (i == 0) {
last = ch;
last = symbol;
continue;
}
int minutes = ch*256 + last;
int minutes = symbol*256 + last;
if (minutes > 24*60) {
return RESULT_ERR_OUT_OF_RANGE; // invalid value
}
@@ -347,31 +347,31 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
return RESULT_ERR_OUT_OF_RANGE; // invalid hour
}
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(hour);
ch = (unsigned char)(minutes % 60);
symbol = (symbol_t)(minutes % 60);
} else if (length == 1) { // truncated time
if (i == 0) {
ch = (unsigned char)(ch/(60/m_resolution)); // convert to hours
offset -= incr; // repeat for minutes
symbol = (symbol_t)(symbol/(60/m_resolution)); // convert to hours
index -= incr; // repeat for minutes
count++;
} else {
ch = (unsigned char)((ch % (60/m_resolution)) * m_resolution); // convert to minutes
symbol = (symbol_t)((symbol % (60/m_resolution)) * m_resolution); // convert to minutes
}
}
if (i == 0) {
if (ch > 24) {
if (symbol > 24) {
return RESULT_ERR_OUT_OF_RANGE; // invalid hour
}
hour = ch;
} else if (ch > 59 || (hour == 24 && ch > 0)) {
hour = symbol;
} else if (symbol > 59 || (hour == 24 && symbol > 0)) {
return RESULT_ERR_OUT_OF_RANGE; // invalid time
}
if (i > 0) {
output << ":";
}
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(ch);
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(symbol);
break;
}
last = ch;
last = symbol;
}
if (outputFormat & OF_JSON) {
output << '"';
@@ -380,8 +380,8 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
}
result_t DateTimeDataType::writeSymbols(istringstream& input,
unsigned char baseOffset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
size_t start = 0, count = length;
bool remainder = count == REMAIN_LEN && hasFlag(ADJ);
int incr = 1;
@@ -396,19 +396,19 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
if (remainder) {
count = 1;
}
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
output[baseOffset + offset] = (unsigned char)m_replacement; // fill up with replacement
for (size_t index = start, i = 0; i < count; index += incr, i++) {
output.dataAt(offset + index) = (symbol_t)m_replacement; // fill up with replacement
}
if (usedLength != NULL) {
*usedLength = (unsigned char)count;
*usedLength = count;
}
return RESULT_OK;
}
result_t result;
size_t i = 0, offset;
size_t i = 0, index;
int type = (m_hasDate?2:0) | (m_hasTime?1:0);
bool skip = false;
for (offset = start; i < count; offset += skip ? 0 : incr, i++) {
for (index = start; i < count; index += skip ? 0 : incr, i++) {
skip = false;
switch (type) {
case 2: // date only
@@ -435,9 +435,9 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
int l = last <= 2 ? 1 : 0;
int mjd = 14956 + lastLast + static_cast<int>((y-l)*365.25) + static_cast<int>((last+1+l*12)*30.6001);
value = mjd - 15020; // 01.01.1900
output[baseOffset + offset] = (unsigned char)(value&0xff);
output.dataAt(offset + index) = (symbol_t)(value&0xff);
value >>= 8;
offset += incr;
index += incr;
skip = false;
break;
}
@@ -450,10 +450,10 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
int mjd = 14956 + lastLast + static_cast<int>((y-l)*365.25) + static_cast<int>((last+1+l*12)*30.6001);
int daysSinceSunday = (mjd+3) % 7; // Sun=0
if (hasFlag(BCD)) {
output[baseOffset + offset - incr] = (unsigned char)((6+daysSinceSunday) % 7); // Sun=0x06
output.dataAt(offset + index - incr) = (symbol_t)((6+daysSinceSunday) % 7); // Sun=0x06
} else {
// Sun=0x07
output[baseOffset + offset - incr] = (unsigned char)(daysSinceSunday == 0 ? 7 : daysSinceSunday);
output.dataAt(offset + index - incr) = (symbol_t)(daysSinceSunday == 0 ? 7 : daysSinceSunday);
}
}
if (value >= 2000) {
@@ -498,9 +498,9 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
break;
}
value += last*60;
output[baseOffset + offset] = (unsigned char)(value&0xff);
output.dataAt(offset + index) = (symbol_t)(value&0xff);
value >>= 8;
offset += incr;
index += incr;
} else if (length == 1) { // truncated time
if (i == 0) {
skip = true; // repeat for minutes
@@ -526,7 +526,7 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
if (value > 0xff) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
output[baseOffset + offset] = (unsigned char)value;
output.dataAt(offset + index) = (symbol_t)value;
}
}
@@ -534,14 +534,14 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
return RESULT_ERR_EOF; // input too short
}
if (usedLength != NULL) {
*usedLength = (unsigned char)((offset-start)*incr);
*usedLength = (index-start)*incr;
}
return RESULT_OK;
}
unsigned char NumberDataType::calcPrecision(const int divisor) {
unsigned char precision = 0;
size_t NumberDataType::calcPrecision(const int divisor) {
size_t precision = 0;
if (divisor > 1) {
for (unsigned int exp = 1; exp < MAX_DIVISOR; exp *= 10, precision++) {
if (exp >= (unsigned int)divisor) {
@@ -552,7 +552,7 @@ unsigned char NumberDataType::calcPrecision(const int divisor) {
return precision;
}
bool NumberDataType::dump(ostream& output, unsigned char length, const bool appendSeparatorDivisor) const {
bool NumberDataType::dump(ostream& output, size_t length, const bool appendSeparatorDivisor) const {
if (m_bitCount < 8) {
DataType::dump(output, m_bitCount, appendSeparatorDivisor);
} else {
@@ -573,7 +573,7 @@ bool NumberDataType::dump(ostream& output, unsigned char length, const bool appe
return false;
}
result_t NumberDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) {
result_t NumberDataType::derive(int divisor, size_t bitCount, NumberDataType* &derived) {
if (divisor == 0) {
divisor = 1;
}
@@ -627,13 +627,13 @@ result_t NumberDataType::derive(int divisor, unsigned char bitCount, NumberDataT
}
result_t NumberDataType::readRawValue(SymbolString& input,
unsigned char baseOffset, const unsigned char length,
size_t offset, const size_t length,
unsigned int& value) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch;
symbol_t symbol;
if (baseOffset + length > input.size()) {
if (offset + length > input.getDataSize()) {
return RESULT_ERR_INVALID_POS; // not enough data available
}
if (hasFlag(REV)) { // reverted binary representation (most significant byte first)
@@ -643,25 +643,25 @@ result_t NumberDataType::readRawValue(SymbolString& input,
value = 0;
unsigned int exp = 1;
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
ch = input[baseOffset + offset];
for (size_t index = start, i = 0; i < count; index += incr, i++) {
symbol = input.dataAt(offset + index);
if (hasFlag(BCD)) {
if (!hasFlag(REQ) && ch == (m_replacement & 0xff)) {
if (!hasFlag(REQ) && symbol == (m_replacement & 0xff)) {
value = m_replacement;
return RESULT_OK;
}
if (!hasFlag(HCD)) {
if ((ch & 0xf0) > 0x90 || (ch & 0x0f) > 0x09) {
if ((symbol & 0xf0) > 0x90 || (symbol & 0x0f) > 0x09) {
return RESULT_ERR_OUT_OF_RANGE; // invalid BCD
}
ch = (unsigned char)((ch >> 4) * 10 + (ch & 0x0f));
} else if (ch > 0x63) {
symbol = (symbol_t)((symbol >> 4) * 10 + (symbol & 0x0f));
} else if (symbol > 0x63) {
return RESULT_ERR_OUT_OF_RANGE; // invalid HCD
}
value += ch * exp;
value += symbol * exp;
exp *= 100;
} else {
value |= ch * exp;
value |= symbol * exp;
exp <<= 8;
}
}
@@ -675,13 +675,13 @@ result_t NumberDataType::readRawValue(SymbolString& input,
return RESULT_OK;
}
result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char baseOffset, const unsigned char length,
result_t NumberDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
int signedValue;
result_t result = readRawValue(input, baseOffset, length, value);
result_t result = readRawValue(input, offset, length, value);
if (result != RESULT_OK) {
return result;
}
@@ -718,7 +718,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
# if HAVE_DIRECT_FLOAT_FORMAT == 2
value = __builtin_bswap32(value);
# endif
unsigned char* pval = (unsigned char*)&value;
symbol_t* pval = reinterpret_cast<symbol_t*>(&value);
val = *reinterpret_cast<float*>(pval);
#else
int exp = (value >> 23) & 0xff; // 8 bits, signed
@@ -741,7 +741,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
}
}
if (m_precision != 0) {
output << fixed << setprecision(m_precision+6);
output << fixed << setprecision(static_cast<int>(m_precision+6));
} else if (val == 0) {
output << fixed << setprecision(1);
}
@@ -754,7 +754,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
} else if (m_divisor <= 1) {
output << static_cast<unsigned>(value);
} else {
output << setprecision(m_precision)
output << setprecision(static_cast<int>(m_precision))
<< fixed << (static_cast<float>(value) / static_cast<float>(m_divisor));
}
return RESULT_OK;
@@ -772,27 +772,27 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
if (hasFlag(FIX) && hasFlag(BCD)) {
if (outputFormat & OF_JSON) {
output << '"';
output << setw(length * 2) << setfill('0');
output << setw(static_cast<int>(length * 2)) << setfill('0');
output << static_cast<signed>(signedValue) << setw(0);
output << '"';
return RESULT_OK;
}
output << setw(length * 2) << setfill('0');
output << setw(static_cast<int>(length * 2)) << setfill('0');
}
output << static_cast<signed>(signedValue) << setw(0);
} else {
output << setprecision(m_precision)
output << setprecision(static_cast<int>(m_precision))
<< fixed << (static_cast<float>(signedValue) / static_cast<float>(m_divisor));
}
return RESULT_OK;
}
result_t NumberDataType::writeRawValue(unsigned int value,
const unsigned char baseOffset, const unsigned char length,
SymbolString& output, unsigned char* usedLength) {
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch;
symbol_t symbol;
if (m_bitCount < 8 && (value & ~((1 << m_bitCount) - 1)) != 0) {
return RESULT_ERR_OUT_OF_RANGE;
@@ -806,25 +806,25 @@ result_t NumberDataType::writeRawValue(unsigned int value,
incr = -1;
}
for (size_t offset = start, i = 0, exp = 1; i < count; offset += incr, i++) {
for (size_t index = start, i = 0, exp = 1; i < count; index += incr, i++) {
if (hasFlag(BCD)) {
if (!hasFlag(REQ) && value == m_replacement) {
ch = m_replacement & 0xff;
symbol = m_replacement & 0xff;
} else {
ch = (unsigned char)((value / exp) % 100);
symbol = (symbol_t)((value / exp) % 100);
if (!hasFlag(HCD)) {
ch = (unsigned char)(((ch / 10) << 4) | (ch % 10));
symbol = (symbol_t)(((symbol / 10) << 4) | (symbol % 10));
}
}
exp *= 100;
} else {
ch = (value / exp) & 0xff;
symbol = (value / exp) & 0xff;
exp <<= 8;
}
if (offset == start && (m_bitCount % 8) != 0 && baseOffset + offset < output.size()) {
output[baseOffset + offset] |= ch;
if (index == start && (m_bitCount % 8) != 0 && offset + index < output.getDataSize()) {
output.dataAt(offset + index) |= symbol;
} else {
output[baseOffset + offset] = ch;
output.dataAt(offset + index) = symbol;
}
}
if (usedLength != NULL) {
@@ -834,8 +834,8 @@ result_t NumberDataType::writeRawValue(unsigned int value,
}
result_t NumberDataType::writeSymbols(istringstream& input,
const unsigned char baseOffset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
unsigned int value;
const char* str = input.str().c_str();
@@ -856,7 +856,7 @@ result_t NumberDataType::writeSymbols(istringstream& input,
}
#ifdef HAVE_DIRECT_FLOAT_FORMAT
float val = static_cast<float>(dvalue);
unsigned char* pval = (unsigned char*)&val;
symbol_t* pval = reinterpret_cast<symbol_t*>(&val);
value = *reinterpret_cast<int32_t*>(pval);
# if HAVE_DIRECT_FLOAT_FORMAT == 2
value = __builtin_bswap32(value);
@@ -938,7 +938,7 @@ result_t NumberDataType::writeSymbols(istringstream& input,
}
}
return writeRawValue(value, baseOffset, length, output, usedLength);
return writeRawValue(value, offset, length, output, usedLength);
}
@@ -1067,7 +1067,7 @@ void DataTypeList::clear() {
result_t DataTypeList::add(DataType* dataType) {
if (!dataType->isAdjustableLength()) {
ostringstream str;
unsigned char bitCount = dataType->getBitCount();
size_t bitCount = dataType->getBitCount();
str << dataType->getId() << LENGTH_SEPARATOR << static_cast<unsigned>(bitCount >= 8?bitCount/8:bitCount);
map<string, DataType*>::iterator it = m_typesByIdLength.find(str.str());
if (it != m_typesByIdLength.end()) {
@@ -1086,7 +1086,7 @@ result_t DataTypeList::add(DataType* dataType) {
return RESULT_OK;
}
DataType* DataTypeList::get(const string id, const unsigned char length) {
DataType* DataTypeList::get(const string id, const size_t length) {
DataType* dataType = NULL;
if (length > 0) {
ostringstream str;
+43 -45
View File
@@ -170,7 +170,7 @@ class DataType {
* @param replacement the replacement value (fill-up value for @a StringDataType, no replacement if equal to
* @a NumberDataType#minValue).
*/
DataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement)
DataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement)
: m_id(id), m_bitCount(bitCount), m_flags(flags), m_replacement(replacement) {}
/**
@@ -186,7 +186,7 @@ class DataType {
/**
* @return the number of bits (maximum length if #ADJ flag is set).
*/
unsigned char getBitCount() const { return m_bitCount; }
size_t getBitCount() const { return m_bitCount; }
/**
* Check whether a flag is set.
@@ -224,7 +224,7 @@ class DataType {
* @param appendSeparatorDivisor whether to append a @a FIELD_SEPARATOR followed by the divisor (if available).
* @return true when a non-default divisor was written to the output.
*/
virtual bool dump(ostream& output, const unsigned char length, const bool appendSeparatorDivisor = true) const;
virtual bool dump(ostream& output, const size_t length, const bool appendSeparatorDivisor = true) const;
/**
* Internal method for reading the numeric raw value from a @a SymbolString.
@@ -235,21 +235,20 @@ class DataType {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
const size_t offset, const size_t length,
unsigned int& value) = 0;
/**
* Internal method for reading the field from a @a SymbolString.
* @param input the @a SymbolString to read the binary value from.
* @param isMaster whether the @a SymbolString is the master part.
* @param offset the offset in the @a SymbolString.
* @param offset the offset in the data of the @a SymbolString.
* @param length the number of symbols to read.
* @param output the ostringstream to append the formatted value to.
* @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 bool isMaster,
const unsigned char offset, const unsigned char length,
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) = 0;
/**
@@ -258,13 +257,12 @@ class DataType {
* @param offset the offset in the @a SymbolString.
* @param length the number of symbols to write, or @a REMAIN_LEN.
* @param output the @a SymbolString to write the binary value to.
* @param isMaster whether the @a SymbolString is the master part.
* @param usedLength the variable in which to store the used length in bytes, or NULL.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) = 0;
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) = 0;
protected:
@@ -272,7 +270,7 @@ class DataType {
const string m_id;
/** the number of bits (maximum length if #ADJ flag is set, must be multiple of 8 with flag #BCD). */
const unsigned char m_bitCount;
const size_t m_bitCount;
/** the combination of flags (like #BCD). */
const uint16_t m_flags;
@@ -296,7 +294,7 @@ class StringDataType : public DataType {
* @param replacement the replacement value (fill-up value).
* @param isHex true for hex digits instead of characters.
*/
StringDataType(const string id, const unsigned char bitCount, const uint16_t flags,
StringDataType(const string id, const size_t bitCount, const uint16_t flags,
const unsigned int replacement, bool isHex = false)
: DataType(id, bitCount, flags, replacement), m_isHex(isHex) {}
@@ -307,18 +305,18 @@ class StringDataType : public DataType {
// @copydoc
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
unsigned int& value);
const size_t offset, const size_t length,
unsigned int& value) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
private:
@@ -342,7 +340,7 @@ class DateTimeDataType : public DataType {
* @param hasTime true if time part is present.
* @param resolution the the resolution in minutes for time types, or 1.
*/
DateTimeDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
DateTimeDataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement,
const bool hasDate, const bool hasTime, const int16_t resolution)
: DataType(id, bitCount, flags, replacement), m_hasDate(hasDate), m_hasTime(hasTime),
m_resolution(resolution == 0 ? 1 : resolution) {}
@@ -369,18 +367,18 @@ class DateTimeDataType : public DataType {
// @copydoc
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
unsigned int& value);
const size_t offset, const size_t length,
unsigned int& value) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
private:
@@ -410,7 +408,7 @@ class NumberDataType : public DataType {
* @param maxValue the maximum raw value.
* @param divisor the divisor (negative for reciprocal).
*/
NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
NumberDataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement,
const unsigned int minValue, const unsigned int maxValue, const int divisor)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue), m_divisor(divisor),
m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(NULL) {}
@@ -424,7 +422,7 @@ class NumberDataType : public DataType {
* @param firstBit the offset to the first bit.
* @param divisor the divisor (negative for reciprocal).
*/
NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
NumberDataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement,
const int16_t firstBit, const int divisor)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1 << bitCount)-1), m_divisor(divisor),
m_precision(0), m_firstBit(firstBit), m_baseType(NULL) {}
@@ -440,10 +438,10 @@ class NumberDataType : public DataType {
* @param divisor the divisor (negative for reciprocal).
* @return the precision for formatting the value.
*/
static unsigned char calcPrecision(const int divisor);
static size_t calcPrecision(const int divisor);
// @copydoc
virtual bool dump(ostream& output, const unsigned char length, const bool appendSeparatorDivisor = true) const;
virtual bool dump(ostream& output, const size_t length, const bool appendSeparatorDivisor = true) const override;
/**
* Derive a new @a NumberDataType from this.
@@ -455,7 +453,7 @@ class NumberDataType : public DataType {
* not necessary.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
virtual result_t derive(int divisor, size_t bitCount, NumberDataType* &derived);
/**
* @return the minimum raw value.
@@ -475,7 +473,7 @@ class NumberDataType : public DataType {
/**
* @return the precision for formatting the value.
*/
unsigned char getPrecision() const { return m_precision; }
size_t getPrecision() const { return m_precision; }
/**
* @return the offset to the first bit.
@@ -484,13 +482,13 @@ class NumberDataType : public DataType {
// @copydoc
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
unsigned int& value);
const size_t offset, const size_t length,
unsigned int& value) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
/**
* Internal method for writing the numeric raw value to a @a SymbolString.
@@ -503,13 +501,13 @@ class NumberDataType : public DataType {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t writeRawValue(unsigned int value,
const unsigned char offset, const unsigned char length,
SymbolString& output, unsigned char* usedLength = NULL);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength = NULL);
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
private:
@@ -523,7 +521,7 @@ class NumberDataType : public DataType {
const int m_divisor;
/** the precision for formatting the value. */
const unsigned char m_precision;
const size_t m_precision;
/** the offset to the first bit. */
const int16_t m_firstBit;
@@ -582,7 +580,7 @@ class DataTypeList {
* @return the @a DataType instance, or NULL if not available.
* Note: the caller may not free the instance.
*/
DataType* get(const string id, const unsigned char length = 0);
DataType* get(const string id, const size_t length = 0);
/**
* Returns an iterator pointing to the first ID/@a DataType pair.
+9 -9
View File
@@ -98,7 +98,7 @@ bool Device::isValid() {
return m_fd != -1;
}
result_t Device::send(const unsigned char value) {
result_t Device::send(const symbol_t value) {
if (!isValid()) {
return RESULT_ERR_DEVICE;
}
@@ -111,7 +111,7 @@ result_t Device::send(const unsigned char value) {
return RESULT_OK;
}
result_t Device::recv(const unsigned int timeout, unsigned char& value) {
result_t Device::recv(const unsigned int timeout, symbol_t& value) {
if (!isValid()) {
return RESULT_ERR_DEVICE;
}
@@ -268,13 +268,13 @@ result_t NetworkDevice::open() {
int cnt;
if (ioctl(m_fd, FIONREAD, &cnt) >= 0 && cnt > 1) {
// skip buffered input
unsigned char buf[256];
symbol_t buf[256];
while (::read(m_fd, &buf, 256) > 0) {
}
}
if (m_bufSize == 0) {
m_bufSize = MAX_LEN+1;
m_buffer = (unsigned char*)malloc(m_bufSize);
m_buffer = reinterpret_cast<symbol_t*>(malloc(m_bufSize));
if (!m_buffer) {
m_bufSize = 0;
}
@@ -287,7 +287,7 @@ result_t NetworkDevice::open() {
}
void NetworkDevice::checkDevice() {
unsigned char value;
symbol_t value;
ssize_t c = ::recv(m_fd, &value, 1, MSG_PEEK | MSG_DONTWAIT);
if (c == 0 || (c < 0 && errno != EAGAIN)) {
m_bufLen = 0; // flush read buffer
@@ -299,15 +299,15 @@ bool NetworkDevice::available() {
return m_buffer && m_bufLen > 0;
}
ssize_t NetworkDevice::write(const unsigned char value) {
ssize_t NetworkDevice::write(const symbol_t value) {
m_bufLen = 0; // flush read buffer
return Device::write(value);
}
ssize_t NetworkDevice::read(unsigned char& value) {
ssize_t NetworkDevice::read(symbol_t& value) {
if (available()) {
value = m_buffer[m_bufPos];
m_bufPos = (unsigned char)((m_bufPos+1)%m_bufSize);
m_bufPos = (m_bufPos+1)%m_bufSize;
m_bufLen--;
return 1;
}
@@ -318,7 +318,7 @@ ssize_t NetworkDevice::read(unsigned char& value) {
}
value = m_buffer[0];
m_bufPos = 1;
m_bufLen = (unsigned char)(size-1);
m_bufLen = size-1;
return size;
}
return Device::read(value);
+21 -20
View File
@@ -26,6 +26,7 @@
#include <iostream>
#include <fstream>
#include "lib/ebus/result.h"
#include "lib/ebus/symbol.h"
namespace ebusd {
@@ -49,11 +50,11 @@ class DeviceListener {
virtual ~DeviceListener() {}
/**
* Listener method that is called when a data byte was received/sent.
* @param byte the data byte received/sent.
* Listener method that is called when a symbol was received/sent.
* @param symbol the received/sent symbol.
* @param received @a true on reception, @a false on sending.
*/
virtual void notifyDeviceData(const unsigned char byte, bool received) = 0; // abstract
virtual void notifyDeviceData(const symbol_t symbol, bool received) = 0; // abstract
};
@@ -112,7 +113,7 @@ class Device {
* @param value the byte value to write.
* @return the @a result_t code.
*/
result_t send(const unsigned char value);
result_t send(const symbol_t value);
/**
* Read a single byte from the device.
@@ -120,7 +121,7 @@ class Device {
* @param value the reference in which the received byte value is stored.
* @return the result_t code.
*/
result_t recv(const unsigned int timeout, unsigned char& value);
result_t recv(const unsigned int timeout, symbol_t& value);
/**
* Return the device name.
@@ -164,14 +165,14 @@ class Device {
* @param value the byte value to write.
* @return the number of bytes written, or -1 on error.
*/
virtual ssize_t write(const unsigned char value) { return ::write(m_fd, &value, 1); }
virtual ssize_t write(const symbol_t value) { return ::write(m_fd, &value, 1); }
/**
* Read a single byte.
* @param value the reference in which the read byte value is stored.
* @return the number of bytes read, or -1 on error.
*/
virtual ssize_t read(unsigned char& value) { return ::read(m_fd, &value, 1); }
virtual ssize_t read(symbol_t& value) { return ::read(m_fd, &value, 1); }
/** the device name (e.g. "/dev/ttyUSB0" for serial, "127.0.0.1:1234" for network). */
const char* m_name;
@@ -210,15 +211,15 @@ class SerialDevice : public Device {
: Device(name, checkDevice, readOnly, initialSend) {}
// @copydoc
virtual result_t open();
virtual result_t open() override;
// @copydoc
virtual void close();
virtual void close() override;
protected:
// @copydoc
virtual void checkDevice();
virtual void checkDevice() override;
private:
@@ -245,24 +246,24 @@ class NetworkDevice : public Device {
m_buffer(NULL), m_bufSize(0), m_bufLen(0), m_bufPos(0) {}
// @copydoc
virtual unsigned int getLatency() const { return 10000; }
virtual unsigned int getLatency() const override { return 10000; }
// @copydoc
virtual result_t open();
virtual result_t open() override;
protected:
// @copydoc
virtual void checkDevice();
virtual void checkDevice() override;
// @copydoc
virtual bool available();
virtual bool available() override;
// @copydoc
virtual ssize_t write(const unsigned char value);
virtual ssize_t write(const symbol_t value) override;
// @copydoc
virtual ssize_t read(unsigned char& value);
virtual ssize_t read(symbol_t& value) override;
private:
@@ -273,16 +274,16 @@ class NetworkDevice : public Device {
const bool m_udp;
/** the buffer memory, or NULL. */
unsigned char* m_buffer;
symbol_t* m_buffer;
/** the buffer size. */
unsigned char m_bufSize;
size_t m_bufSize;
/** the buffer fill length. */
unsigned char m_bufLen;
size_t m_bufLen;
/** the buffer read position. */
unsigned char m_bufPos;
size_t m_bufPos;
};
} // namespace ebusd
+4 -4
View File
@@ -66,7 +66,7 @@ extern void printErrorPos(ostream& out, vector<string>::iterator begin, const ve
vector<string>::iterator pos, string filename, size_t lineNo, result_t result);
extern unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue,
result_t& result, unsigned int* length);
result_t& result, size_t* length);
/**
* An abstract class that support reading definitions from a file.
@@ -105,7 +105,7 @@ class FileReader {
if (lastSep != string::npos) { // potential destination address, matches "^ZZ."
// extract defaultDest, defaultCircuit, defaultSuffix from filename:
// ZZ.IDENT[.CIRCUIT][.SUFFIX].*csv
unsigned char checkDest;
symbol_t checkDest;
string checkIdent, useCircuit, useSuffix;
unsigned int checkSw, checkHw;
if (extractDefaultsFromFilename(filename.substr(lastSep+1), checkDest, checkIdent, useCircuit, useSuffix,
@@ -320,7 +320,7 @@ class FileReader {
* @param hardware the hardware version part HWXXXX (BCD digits, set to @a UINT_MAX if not present).
* @return true if at least the address and the identification part were extracted, false otherwise.
*/
static bool extractDefaultsFromFilename(string name, unsigned char& dest, string& ident, string& circuit,
static bool extractDefaultsFromFilename(string name, symbol_t& dest, string& ident, string& circuit,
string& suffix, unsigned int& software, unsigned int& hardware) {
ident = circuit = suffix = "";
software = hardware = UINT_MAX;
@@ -332,7 +332,7 @@ class FileReader {
return false; // missing "ZZ."
}
result_t result = RESULT_OK;
dest = (unsigned char)parseInt(name.substr(0, pos).c_str(), 16, 0, 0xff, result, NULL);
dest = (symbol_t)parseInt(name.substr(0, pos).c_str(), 16, 0, 0xff, result, NULL);
if (result != RESULT_OK || !isValidAddress(dest)) {
return false; // invalid "ZZ"
}
+132 -128
View File
@@ -60,10 +60,10 @@ extern DataFieldTemplates* getTemplates(const string filename);
Message::Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
DataField* data, const bool deleteData,
const unsigned char pollPriority,
const size_t pollPriority,
Condition* condition)
: m_circuit(circuit), m_level(level), m_name(name), m_isWrite(isWrite),
m_isPassive(isPassive), m_comment(comment),
@@ -81,7 +81,7 @@ Message::Message(const string circuit, const string level, const string name,
Message::Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive,
const unsigned char pb, const unsigned char sb,
const symbol_t pb, const symbol_t sb,
DataField* data, const bool deleteData)
: m_circuit(circuit), m_level(level), m_name(name), m_isWrite(isWrite),
m_isPassive(isPassive), m_comment(),
@@ -135,9 +135,9 @@ string getDefault(const string value, vector<string>* defaults, size_t pos, bool
return defaultStr.substr(0, insertPos)+value+defaultStr.substr(insertPos+1);
}
uint64_t Message::createKey(const vector<unsigned char> id,
uint64_t Message::createKey(const vector<symbol_t> id,
const bool isWrite, const bool isPassive,
const unsigned char srcAddress, const unsigned char dstAddress) {
const symbol_t srcAddress, const symbol_t dstAddress) {
uint64_t key = (uint64_t)(id.size()-2) << (8 * 7 + 5);
if (isPassive) {
key |= (uint64_t)getMasterNumber(srcAddress) << (8 * 7); // 0..25
@@ -146,7 +146,7 @@ uint64_t Message::createKey(const vector<unsigned char> id,
}
key |= (uint64_t)dstAddress << (8 * 6);
int exp = 5;
for (vector<unsigned char>::const_iterator it = id.begin(); it < id.end(); it++) {
for (vector<symbol_t>::const_iterator it = id.begin(); it < id.end(); it++) {
key ^= (uint64_t)*it << (8 * exp--);
if (exp == 0) {
exp = 3;
@@ -155,15 +155,15 @@ uint64_t Message::createKey(const vector<unsigned char> id,
return key;
}
uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLength, bool anyDestination) {
uint64_t Message::createKey(MasterSymbolString& master, size_t maxIdLength, bool anyDestination) {
if (master.size() < 5) {
return INVALID_KEY;
}
unsigned char idLength = master[4];
size_t idLength = master.getDataSize();
if (maxIdLength < idLength) {
idLength = maxIdLength;
}
if (master.size() < 5+idLength) {
if (master.getDataSize() < idLength) {
return INVALID_KEY;
}
uint64_t key = (uint64_t)idLength << (8 * 7 + 5);
@@ -172,8 +172,8 @@ uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLengt
key |= (uint64_t)master[2] << (8 * 5); // PB
key |= (uint64_t)master[3] << (8 * 4); // SB
int exp = 3;
for (unsigned char i = 0; i < idLength; i++) {
key ^= (uint64_t)master[5 + i] << (8 * exp--);
for (size_t i = 0; i < idLength; i++) {
key ^= (uint64_t)master.dataAt(i) << (8 * exp--);
if (exp == 0) {
exp = 3;
}
@@ -181,7 +181,7 @@ uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLengt
return key;
}
result_t Message::parseId(string input, vector<unsigned char>& id) {
result_t Message::parseId(string input, vector<symbol_t>& id) {
istringstream in(input);
while (!in.eof()) {
while (in.peek() == ' ') {
@@ -198,7 +198,7 @@ result_t Message::parseId(string input, vector<unsigned char>& id) {
input.push_back(static_cast<char>(in.get()));
result_t result;
unsigned char value = (unsigned char)parseInt(input.c_str(), 16, 0, 0xff, result);
symbol_t value = (symbol_t)parseInt(input.c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result; // invalid hex value
}
@@ -214,7 +214,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
result_t result;
bool isWrite = false, isPassive = false;
string defaultName;
unsigned char pollPriority = 0;
size_t pollPriority = 0;
size_t defaultPos = 1;
if (it == end) {
return RESULT_ERR_EOF;
@@ -233,7 +233,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
if (type == 'r' || type == 'R') { // active read
char poll = str[1];
if (poll >= '0' && poll <= '9') { // poll priority (=active read)
pollPriority = (unsigned char)(poll - '0');
pollPriority = poll - '0';
defaultName.erase(1, 1); // cut off priority digit
}
} else if (type == 'w' || type == 'W') { // active write
@@ -281,11 +281,11 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
if (it == end) {
return RESULT_ERR_EOF;
}
unsigned char srcAddress;
symbol_t srcAddress;
if (*str == 0) {
srcAddress = SYN; // no specific source
} else {
srcAddress = (unsigned char)parseInt(str, 16, 0, 0xff, result);
srcAddress = (symbol_t)parseInt(str, 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -298,7 +298,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
if (it == end) {
return RESULT_ERR_EOF;
}
vector<unsigned char> dstAddresses;
vector<symbol_t> dstAddresses;
bool isBroadcastOrMasterDestination = false;
if (*str == 0) {
dstAddresses.push_back(SYN); // no specific destination
@@ -308,7 +308,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
bool first = true;
while (getline(stream, token, VALUE_SEPARATOR)) {
FileReader::trim(token);
unsigned char dstAddress = (unsigned char)parseInt(token.c_str(), 16, 0, 0xff, result);
symbol_t dstAddress = (symbol_t)parseInt(token.c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -326,7 +326,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
}
}
vector<unsigned char> id;
vector<symbol_t> id;
string token = *it++; // [PBSB]
bool useDefaults = token.empty();
if (useDefaults) {
@@ -350,8 +350,8 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
defaultIdPrefix = getDefault("", defaults, defaultPos);
}
defaultPos++;
vector< vector<unsigned char> > chainIds;
vector<unsigned char> chainLengths;
vector< vector<symbol_t> > chainIds;
vector<size_t> chainLengths;
istringstream stream(token);
size_t maxLength = MAX_POS;
size_t chainLength = 16;
@@ -369,7 +369,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
}
token.resize(lengthPos);
}
vector<unsigned char> chainId = id;
vector<symbol_t> chainId = id;
result = parseId(token, chainId);
if (result != RESULT_OK) {
return result;
@@ -378,12 +378,12 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
return RESULT_ERR_INVALID_LIST;
}
chainIds.push_back(chainId);
chainLengths.push_back((unsigned char)chainLength);
chainLengths.push_back((symbol_t)chainLength);
if (first) {
chainPrefixLength = chainId.size();
maxLength = 0;
} else if (chainPrefixLength > 2) {
vector<unsigned char>& front = chainIds.front();
vector<symbol_t>& front = chainIds.front();
for (size_t pos = 2; pos < chainPrefixLength; pos++) {
if (chainId[pos] != front[pos]) {
chainPrefixLength = pos;
@@ -439,13 +439,13 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
data = new DataFieldSet("", "", fields);
} else {
result = DataField::create(it, realEnd, templates, data, isWrite, false, isBroadcastOrMasterDestination,
(unsigned char)maxLength);
maxLength);
if (result != RESULT_OK) {
return result;
}
}
if (id.size() + data->getLength(pt_masterData, (unsigned char)maxLength) > 2 + maxLength
|| data->getLength(pt_slaveData, (unsigned char)maxLength) > maxLength) {
if (id.size() + data->getLength(pt_masterData, maxLength) > 2 + maxLength
|| data->getLength(pt_slaveData, maxLength) > maxLength) {
// max NN exceeded
delete data;
return RESULT_ERR_INVALID_POS;
@@ -453,8 +453,8 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
unsigned int index = 0;
bool multiple = dstAddresses.size() > 1;
char num[10];
for (vector<unsigned char>::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) {
unsigned char dstAddress = *it;
for (vector<symbol_t>::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) {
symbol_t dstAddress = *it;
string useCircuit = circuit;
if (multiple) {
snprintf(num, sizeof(num), ".%d", index);
@@ -477,7 +477,7 @@ Message* Message::createScanMessage() {
return new Message("scan", "", "", false, false, 0x07, 0x04, DataFieldSet::getIdentFields(), true);
}
Message* Message::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) {
Message* Message::derive(const symbol_t dstAddress, const symbol_t srcAddress, const string circuit) {
Message* result = new Message(circuit.length() == 0 ? m_circuit : circuit, m_level, m_name,
m_isWrite, m_isPassive, m_comment,
srcAddress == SYN ? m_srcAddress : srcAddress, dstAddress,
@@ -489,7 +489,7 @@ Message* Message::derive(const unsigned char dstAddress, const unsigned char src
return result;
}
Message* Message::derive(const unsigned char dstAddress, const bool extendCircuit) {
Message* Message::derive(const symbol_t dstAddress, const bool extendCircuit) {
if (extendCircuit) {
ostringstream out;
out << m_circuit << '.' << hex << setw(2) << setfill('0') << static_cast<unsigned>(dstAddress);
@@ -520,7 +520,7 @@ bool Message::checkLevel(const string level, const string checkLevels) {
}
return false;
}
bool Message::checkIdPrefix(vector<unsigned char>& id) {
bool Message::checkIdPrefix(vector<symbol_t>& id) {
if (id.size() > m_id.size()) {
return false;
}
@@ -532,13 +532,13 @@ bool Message::checkIdPrefix(vector<unsigned char>& id) {
return true;
}
bool Message::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
bool Message::checkId(MasterSymbolString& master, size_t* index) {
size_t idLen = getIdLength();
if (master.getDataSize() < idLen) {
return false;
}
for (unsigned char pos = 0; pos < idLen; pos++) {
if (m_id[2+pos] != master[5+pos]) {
for (size_t pos = 0; pos < idLen; pos++) {
if (m_id[2+pos] != master.dataAt(pos)) {
return false;
}
}
@@ -549,18 +549,18 @@ bool Message::checkId(MasterSymbolString& master, unsigned char* index) {
}
bool Message::checkId(Message& other) {
unsigned char idLen = getIdLength();
size_t idLen = getIdLength();
if (idLen != other.getIdLength() || getCount() > 1) { // only equal for non-chained messages
return false;
}
return other.checkIdPrefix(m_id);
}
uint64_t Message::getDerivedKey(const unsigned char dstAddress) {
uint64_t Message::getDerivedKey(const symbol_t dstAddress) {
return (m_key & ~(0xffLL << (8*6))) | (uint64_t)dstAddress << (8*6);
}
bool Message::setPollPriority(unsigned char priority) {
bool Message::setPollPriority(size_t priority) {
if (priority == m_pollPriority || m_isPassive || isScanMessage() || m_dstAddress == SYN) {
return false;
}
@@ -590,9 +590,9 @@ bool Message::hasField(const char* fieldName, bool numeric) {
return m_data->hasField(fieldName, numeric);
}
result_t Message::prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
result_t Message::prepareMaster(const symbol_t srcAddress, MasterSymbolString& master,
istringstream& input, char separator,
const unsigned char dstAddress, unsigned char index) {
const symbol_t dstAddress, size_t index) {
if (m_isPassive) {
return RESULT_ERR_INVALID_ARG; // prepare not possible
}
@@ -620,20 +620,20 @@ result_t Message::prepareMaster(const unsigned char srcAddress, MasterSymbolStri
}
result_t Message::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
size_t index) {
if (index != 0) {
return RESULT_ERR_NOTFOUND;
}
unsigned char pos = master.size();
size_t pos = master.size();
master.push_back(0); // length, will be set later
for (size_t i = 2; i < m_id.size(); i++) {
master.push_back(m_id[i]);
}
result_t result = m_data->write(input, pt_masterData, master, getIdLength(), separator);
result_t result = m_data->write(input, master, getIdLength(), separator);
if (result != RESULT_OK) {
return result;
}
master[pos] = (unsigned char)(master.size()-pos-1);
master[pos] = (symbol_t)(master.size()-pos-1);
return result;
}
@@ -643,11 +643,11 @@ result_t Message::prepareSlave(istringstream& input, SlaveSymbolString& slave) {
}
slave.clear();
slave.push_back(0); // length, will be set later
result_t result = m_data->write(input, pt_slaveData, slave, 0);
result_t result = m_data->write(input, slave, 0);
if (result != RESULT_OK) {
return result;
}
slave[0] = (unsigned char)(slave.size()-1);
slave[0] = (symbol_t)(slave.size()-1);
time(&m_lastUpdateTime);
if (slave != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
@@ -664,7 +664,7 @@ result_t Message::storeLastData(MasterSymbolString& master, SlaveSymbolString& s
return result;
}
result_t Message::storeLastData(MasterSymbolString& data, unsigned char index) {
result_t Message::storeLastData(MasterSymbolString& data, size_t index) {
if (data.size() > 0
&& (m_isWrite || this->m_dstAddress == BROADCAST || isMaster(this->m_dstAddress))) {
time(&m_lastUpdateTime);
@@ -681,7 +681,7 @@ result_t Message::storeLastData(MasterSymbolString& data, unsigned char index) {
return RESULT_OK;
}
result_t Message::storeLastData(SlaveSymbolString& data, unsigned char index) {
result_t Message::storeLastData(SlaveSymbolString& data, size_t index) {
if (data.size() > 0) {
time(&m_lastUpdateTime);
}
@@ -693,9 +693,9 @@ result_t Message::storeLastData(SlaveSymbolString& data, unsigned char index) {
}
result_t Message::decodeLastMasterData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
unsigned char offset = (unsigned char)(m_id.size() - 2);
result_t result = m_data->read(pt_masterData, m_lastMasterData, offset,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
size_t offset = m_id.size() - 2;
result_t result = m_data->read(m_lastMasterData, offset,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
@@ -707,8 +707,8 @@ result_t Message::decodeLastMasterData(ostringstream& output, OutputFormat outpu
}
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,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
result_t result = m_data->read(m_lastSlaveData, 0,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
@@ -720,17 +720,16 @@ result_t Message::decodeLastSlaveData(ostringstream& output, OutputFormat output
}
result_t Message::decodeLastData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, m_lastMasterData, getIdLength(), output, outputFormat, -1,
result_t result = m_data->read(m_lastMasterData, getIdLength(), output, outputFormat, -1,
leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
bool empty = result == RESULT_EMPTY;
leadingSeparator |= output.str().length() > startPos;
result = m_data->read(pt_slaveData, m_lastSlaveData, 0, output, outputFormat, -1, leadingSeparator, fieldName,
fieldIndex);
result = m_data->read(m_lastSlaveData, 0, output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
@@ -742,13 +741,13 @@ result_t Message::decodeLastData(ostringstream& output, OutputFormat outputForma
return result;
}
result_t Message::decodeLastDataNumField(unsigned int& output, const char* fieldName, signed char fieldIndex) {
result_t result = m_data->read(pt_masterData, m_lastMasterData, getIdLength(), output, fieldName, fieldIndex);
result_t Message::decodeLastDataNumField(unsigned int& output, const char* fieldName, ssize_t fieldIndex) {
result_t result = m_data->read(m_lastMasterData, getIdLength(), output, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
if (result == RESULT_EMPTY) {
result = m_data->read(pt_slaveData, m_lastSlaveData, 0, output, fieldName, fieldIndex);
result = m_data->read(m_lastSlaveData, 0, output, fieldName, fieldIndex);
}
if (result < RESULT_OK) {
return result;
@@ -760,10 +759,10 @@ result_t Message::decodeLastDataNumField(unsigned int& output, const char* field
}
bool Message::isLessPollWeight(const Message* other) {
unsigned char tprio = m_pollPriority;
unsigned char oprio = other->m_pollPriority;
unsigned int tw = tprio * m_pollCount;
unsigned int ow = oprio * other->m_pollCount;
size_t tprio = m_pollPriority;
size_t oprio = other->m_pollPriority;
size_t tw = tprio * m_pollCount;
size_t ow = oprio * other->m_pollCount;
if (tw > ow) {
return true;
}
@@ -851,12 +850,12 @@ void Message::dumpColumn(ostream& output, column_t column, bool withConditions)
}
break;
case COLUMN_PBSB:
for (vector<unsigned char>::const_iterator it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) {
for (vector<symbol_t>::const_iterator it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) {
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
}
break;
case COLUMN_ID:
for (vector<unsigned char>::const_iterator it = m_id.begin()+2; it < m_id.end(); it++) {
for (vector<symbol_t>::const_iterator it = m_id.begin()+2; it < m_id.end(); it++) {
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
}
break;
@@ -872,11 +871,11 @@ void Message::dumpColumn(ostream& output, column_t column, bool withConditions)
ChainedMessage::ChainedMessage(const string circuit, const string level, const string name,
const bool isWrite, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
vector< vector<unsigned char> > ids, vector<unsigned char> lengths,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
vector< vector<symbol_t> > ids, vector<size_t> lengths,
DataField* data, const bool deleteData,
const unsigned char pollPriority,
const size_t pollPriority,
Condition* condition)
: Message(circuit, level, name, isWrite, false, comment,
srcAddress, dstAddress, id,
@@ -895,7 +894,7 @@ ChainedMessage::ChainedMessage(const string circuit, const string level, const s
}
ChainedMessage::~ChainedMessage() {
for (unsigned char index = 0; index < m_ids.size(); index++) {
for (size_t index = 0; index < m_ids.size(); index++) {
delete m_lastMasterDatas[index];
m_lastMasterDatas[index] = NULL;
delete m_lastSlaveDatas[index];
@@ -907,7 +906,7 @@ ChainedMessage::~ChainedMessage() {
free(m_lastSlaveUpdateTimes);
}
Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) {
Message* ChainedMessage::derive(const symbol_t dstAddress, const symbol_t srcAddress, const string circuit) {
ChainedMessage* result = new ChainedMessage(circuit.length() == 0 ? m_circuit : circuit, m_level, m_name,
m_isWrite, m_comment,
srcAddress == SYN ? m_srcAddress : srcAddress, dstAddress,
@@ -919,22 +918,22 @@ Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned c
return result;
}
bool ChainedMessage::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
bool ChainedMessage::checkId(MasterSymbolString& master, size_t* index) {
size_t idLen = getIdLength();
if (master.getDataSize() < idLen) {
return false;
}
unsigned char chainPrefixLength = Message::getIdLength();
for (unsigned char pos = 0; pos < chainPrefixLength; pos++) {
if (m_id[2+pos] != master[5+pos]) {
size_t chainPrefixLength = Message::getIdLength();
for (size_t pos = 0; pos < chainPrefixLength; pos++) {
if (m_id[2+pos] != master.dataAt(pos)) {
return false; // chain prefix mismatch
}
}
for (unsigned char checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<unsigned char> id = m_ids[checkIndex];
for (size_t checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<symbol_t> id = m_ids[checkIndex];
bool found = false;
for (unsigned char pos = chainPrefixLength; pos < idLen; pos++) {
if (id[2+pos] != master[5+pos]) {
for (size_t pos = chainPrefixLength; pos < idLen; pos++) {
if (id[2+pos] != master.dataAt(pos)) {
found = false;
break;
}
@@ -951,21 +950,21 @@ bool ChainedMessage::checkId(MasterSymbolString& master, unsigned char* index) {
}
bool ChainedMessage::checkId(Message& other) {
unsigned char idLen = getIdLength();
size_t idLen = getIdLength();
if (idLen != other.getIdLength() || other.getCount() == 1) { // only equal for chained messages
return false;
}
if (!other.checkIdPrefix(m_id)) {
return false; // chain prefix mismatch
}
vector< vector<unsigned char> > otherIds = ((ChainedMessage&)other).m_ids;
unsigned char chainPrefixLength = Message::getIdLength();
for (unsigned char checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<unsigned char> id = m_ids[checkIndex];
for (unsigned char otherIndex = 0; otherIndex < otherIds.size(); otherIndex++) {
vector<unsigned char> otherId = otherIds[otherIndex];
vector< vector<symbol_t> > otherIds = ((ChainedMessage&)other).m_ids;
size_t chainPrefixLength = Message::getIdLength();
for (size_t checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<symbol_t> id = m_ids[checkIndex];
for (size_t otherIndex = 0; otherIndex < otherIds.size(); otherIndex++) {
vector<symbol_t> otherId = otherIds[otherIndex];
bool found = false;
for (unsigned char pos = chainPrefixLength; pos < idLen; pos++) {
for (size_t pos = chainPrefixLength; pos < idLen; pos++) {
if (id[2+pos] != otherId[2+pos]) {
found = false;
break;
@@ -981,13 +980,13 @@ bool ChainedMessage::checkId(Message& other) {
}
result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
size_t index) {
size_t cnt = getCount();
if (index >= cnt) {
return RESULT_ERR_NOTFOUND;
}
MasterSymbolString allData;
result_t result = m_data->write(input, pt_masterData, allData, 0, separator);
result_t result = m_data->write(input, allData, 0, separator);
if (result != RESULT_OK) {
return result;
}
@@ -999,16 +998,16 @@ result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringst
addData = m_lengths[i+1];
}
}
if (pos+addData > allData.size()) {
if (pos+addData > allData.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
vector<unsigned char> id = m_ids[index];
master.push_back((unsigned char)(id.size()-2+addData)); // NN
vector<symbol_t> id = m_ids[index];
master.push_back((symbol_t)(id.size()-2+addData)); // NN
for (size_t i = 2; i < id.size(); i++) {
master.push_back(id[i]);
}
for (size_t i = 0; i < addData; i++) {
master.push_back(allData[pos+i]);
master.push_back(allData.dataAt(pos+i));
}
if (index == 0) {
for (size_t i = 0; i < cnt; i++) {
@@ -1020,7 +1019,7 @@ result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringst
result_t ChainedMessage::storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
// determine index from master ID
unsigned char index = 0;
size_t index = 0;
if (checkId(master, &index)) {
result_t result = storeLastData(master, index);
if (result >= RESULT_OK) {
@@ -1031,7 +1030,7 @@ result_t ChainedMessage::storeLastData(MasterSymbolString& master, SlaveSymbolSt
return RESULT_ERR_INVALID_ARG;
}
result_t ChainedMessage::storeLastData(MasterSymbolString& data, unsigned char index) {
result_t ChainedMessage::storeLastData(MasterSymbolString& data, size_t index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
@@ -1047,7 +1046,7 @@ result_t ChainedMessage::storeLastData(MasterSymbolString& data, unsigned char i
return combineLastParts();
}
result_t ChainedMessage::storeLastData(SlaveSymbolString& data, unsigned char index) {
result_t ChainedMessage::storeLastData(SlaveSymbolString& data, size_t index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
@@ -1061,7 +1060,7 @@ result_t ChainedMessage::storeLastData(SlaveSymbolString& data, unsigned char in
result_t ChainedMessage::combineLastParts() {
// check arrival time of all parts
time_t minTime = 0, maxTime = 0;
for (unsigned char index = 0; index < m_ids.size(); index++) {
for (size_t index = 0; index < m_ids.size(); index++) {
if (index == 0) {
minTime = maxTime = m_lastMasterUpdateTimes[index];
} else {
@@ -1085,25 +1084,30 @@ result_t ChainedMessage::combineLastParts() {
// everything was completely retrieved in short time
MasterSymbolString master;
SlaveSymbolString slave;
size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN
for (unsigned char index = 0; index < m_ids.size(); index++) {
SymbolString* add = m_lastMasterDatas[index];
size_t end = 5+(*add)[4];
for (size_t pos = index == 0 ? 0 : offset; pos < end; pos++) {
master.push_back((*add)[pos]);
size_t offset = m_ids[0].size()-2;
SymbolString* add = m_lastMasterDatas[0];
for (size_t pos = 0; pos < 5+offset; pos++) {
master.push_back((*add)[pos]); // copy header
}
slave.push_back(0); // NN, set later
for (size_t index = 0; index < m_ids.size(); index++) {
add = m_lastMasterDatas[index];
size_t end = add->getDataSize();
for (size_t pos = offset; pos < end; pos++) {
master.push_back(add->dataAt(pos));
}
add = m_lastSlaveDatas[index];
end = 1+(*add)[0];
for (size_t pos = index == 0 ? 0 : 1; pos < end; pos++) {
slave.push_back((*add)[pos]);
end = add->getDataSize();
for (size_t pos = 0; pos < end; pos++) {
slave.push_back(add->dataAt(pos));
}
}
// adjust NN
if (master.size()-5 > 255 || slave.size()-1 > 255) {
return RESULT_ERR_INVALID_POS;
}
master[4] = (unsigned char)(master.size()-5);
slave[0] = (unsigned char)(slave.size()-1);
master[4] = (symbol_t)(master.size()-5);
slave[0] = (symbol_t)(slave.size()-1);
result_t result = Message::storeLastData(master, 0);
if (result == RESULT_OK) {
result = Message::storeLastData(slave, 0);
@@ -1118,8 +1122,8 @@ void ChainedMessage::dumpColumn(ostream& output, column_t column, bool withCondi
}
bool first = true;
for (size_t index = 0; index < m_ids.size(); index++) {
vector<unsigned char> id = m_ids[index];
for (vector<unsigned char>::const_iterator it = id.begin()+2; it < id.end(); it++) {
vector<symbol_t> id = m_ids[index];
for (vector<symbol_t>::const_iterator it = id.begin()+2; it < id.end(); it++) {
if (first) {
first = false;
} else {
@@ -1258,13 +1262,13 @@ result_t Condition::create(const string condName, vector<string>::iterator& it,
}
string field = it == end ? "" : *(it++); // fieldname
string zz = it == end ? "" : *(it++); // ZZ
unsigned char dstAddress = SYN;
symbol_t dstAddress = SYN;
result_t result = RESULT_OK;
if (zz.length() == 0) {
zz = defaultDest;
}
if (zz.length() > 0) {
dstAddress = (unsigned char)parseInt(zz.c_str(), 16, 0, 0xff, result);
dstAddress = (symbol_t)parseInt(zz.c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -1556,7 +1560,7 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond
log << (isSingleton() ? "loaded \"" : "included \"") << m_filename << "\" for \"" << getDestination() << "\"";
if (isSingleton() && !m_defaultDest.empty()) {
result_t temp;
unsigned char address = (unsigned char)parseInt(m_defaultDest.c_str(), 16, 0, 0xff, temp);
symbol_t address = (symbol_t)parseInt(m_defaultDest.c_str(), 16, 0, 0xff, temp);
if (temp == RESULT_OK) {
size_t pos = m_filename.find_last_of('/');
string filename;
@@ -1640,7 +1644,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
}
addPollMessage(message);
}
unsigned char idLength = message->getIdLength();
size_t idLength = message->getIdLength();
if (idLength > m_maxIdLength) {
m_maxIdLength = idLength;
}
@@ -1825,7 +1829,7 @@ result_t MessageMap::addFromFile(vector<string>::iterator& begin, const vector<s
return result;
}
Message* MessageMap::getScanMessage(const unsigned char dstAddress) {
Message* MessageMap::getScanMessage(const symbol_t dstAddress) {
if (dstAddress == SYN) {
return m_scanMessage;
}
@@ -1931,7 +1935,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
return overallResult;
}
void MessageMap::addLoadedFile(unsigned char address, string file, string comment) {
void MessageMap::addLoadedFile(symbol_t address, string file, string comment) {
if (!file.empty()) {
string fileComment = "\""+file+"\"";
if (!comment.empty()) {
@@ -1945,7 +1949,7 @@ void MessageMap::addLoadedFile(unsigned char address, string file, string commen
}
}
string MessageMap::getLoadedFiles(unsigned char address) {
string MessageMap::getLoadedFiles(symbol_t address) {
if (m_loadedFiles.find(address) == m_loadedFiles.end()) {
return "";
}
@@ -2062,16 +2066,16 @@ Message* MessageMap::find(MasterSymbolString& master, bool anyDestination,
if (baseKey == INVALID_KEY) {
return NULL;
}
unsigned char maxIdLength = Message::getKeyLength(baseKey);
for (unsigned char idLength = maxIdLength; true; idLength--) {
size_t maxIdLength = Message::getKeyLength(baseKey);
for (size_t idLength = maxIdLength; true; idLength--) {
uint64_t key = baseKey;
if (idLength == maxIdLength) {
baseKey &= ~ID_LENGTH_AND_IDS_MASK;
} else {
key |= (uint64_t)idLength << (8 * 7 + 5);
int exp = 3;
for (unsigned char i = 0; i < idLength; i++) {
key ^= (uint64_t)master[5 + i] << (8 * exp--);
for (size_t i = 0; i < idLength; i++) {
key ^= (uint64_t)master.dataAt(i) << (8 * exp--);
if (exp == 0) {
exp = 3;
}
+77 -77
View File
@@ -125,10 +125,10 @@ class Message {
*/
Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
DataField* data, const bool deleteData,
const unsigned char pollPriority = 0,
const size_t pollPriority = 0,
Condition* condition = NULL);
@@ -148,7 +148,7 @@ class Message {
*/
Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive,
const unsigned char pb, const unsigned char sb,
const symbol_t pb, const symbol_t sb,
DataField* data, const bool deleteData);
@@ -168,9 +168,9 @@ class Message {
* @param dstAddress the destination address, or @a SYN for any (set later).
* @return the key for the ID.
*/
static uint64_t createKey(const vector<unsigned char> id,
static uint64_t createKey(const vector<symbol_t> id,
const bool isWrite, const bool isPassive,
const unsigned char srcAddress, const unsigned char dstAddress);
const symbol_t srcAddress, const symbol_t dstAddress);
/**
* Calculate the key for the @a MasterSymbolString.
@@ -180,14 +180,14 @@ class Message {
* @return the key for the ID, or -1LL if the data is invalid.
*/
static uint64_t createKey(MasterSymbolString& master,
unsigned char maxIdLength, bool anyDestination = false);
size_t maxIdLength, bool anyDestination = false);
/**
* Get the length field from the key.
* @param key the key.
* @return the length field from the key.
*/
static unsigned char getKeyLength(uint64_t key) { return (unsigned char)(key >> (8 * 7 + 5)); }
static size_t getKeyLength(uint64_t key) { return key >> (8 * 7 + 5); }
/**
* Parse an ID part from the input @a string.
@@ -195,7 +195,7 @@ class Message {
* @param id the vector to which to add the parsed values.
* @return @a RESULT_OK on success, or an error code.
*/
static result_t parseId(string input, vector<unsigned char>& id);
static result_t parseId(string input, vector<symbol_t>& id);
/**
* Factory method for creating new instances.
@@ -236,7 +236,7 @@ class Message {
* @param circuit the new circuit name, or empty to use the current circuit name.
* @return the derived @a Message instance.
*/
virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress = SYN,
virtual Message* derive(const symbol_t dstAddress, const symbol_t srcAddress = SYN,
const string circuit = "");
/**
@@ -245,7 +245,7 @@ class Message {
* @param extendCircuit whether to extend the current circuit name with a dot and the new destination address in hex.
* @return the derived @a ScanMessage instance.
*/
Message* derive(const unsigned char dstAddress, const bool extendCircuit);
Message* derive(const symbol_t dstAddress, const bool extendCircuit);
/**
* Get the optional circuit name.
@@ -289,7 +289,7 @@ class Message {
* @param fieldIndex the index of the field.
* @return the field name, or the index as string if not unique or not available.
*/
virtual string getFieldName(signed char fieldIndex) const { return m_data->getName(fieldIndex); }
virtual string getFieldName(ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
/**
* Get whether this is a write message.
@@ -314,38 +314,38 @@ class Message {
* Get the source address.
* @return the source address, or @a SYN for any.
*/
unsigned char getSrcAddress() const { return m_srcAddress; }
symbol_t getSrcAddress() const { return m_srcAddress; }
/**
* Get the destination address.
* @return the destination address, or @a SYN for any.
*/
unsigned char getDstAddress() const { return m_dstAddress; }
symbol_t getDstAddress() const { return m_dstAddress; }
/**
* Get the primary command byte.
* @return the primary command byte.
*/
unsigned char getPrimaryCommand() const { return m_id[0]; }
symbol_t getPrimaryCommand() const { return m_id[0]; }
/**
* Get the secondary command byte.
* @return the secondary command byte.
*/
unsigned char getSecondaryCommand() const { return m_id[1]; }
symbol_t getSecondaryCommand() const { return m_id[1]; }
/**
* Get the length of the ID bytes (without primary and secondary command bytes).
* @return the length of the ID bytes (without primary and secondary command bytes).
*/
virtual unsigned char getIdLength() const { return (unsigned char)(m_id.size() - 2); }
virtual size_t getIdLength() const { return m_id.size() - 2; }
/**
* Check if the full command ID starts with the given value.
* @param id the ID bytes to check against.
* @return true if the full command ID starts with the given value.
*/
bool checkIdPrefix(vector<unsigned char>& id);
bool checkIdPrefix(vector<symbol_t>& id);
/**
* Check the ID against the master @a SymbolString data.
@@ -353,7 +353,7 @@ class Message {
* @param index the variable in which to store the message part index, or NULL to ignore.
* @return true if the ID matches, false otherwise.
*/
virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
virtual bool checkId(MasterSymbolString& master, size_t* index = NULL);
/**
* Check the ID against the other @a Message.
@@ -373,20 +373,20 @@ class Message {
* @param dstAddress the destination address for the derivation.
* @return the derived key for storing in @a MessageMap.
*/
uint64_t getDerivedKey(const unsigned char dstAddress);
uint64_t getDerivedKey(const symbol_t dstAddress);
/**
* Get the polling priority, or 0 for no polling at all.
* @return the polling priority, or 0 for no polling at all.
*/
unsigned char getPollPriority() const { return m_pollPriority; }
size_t getPollPriority() const { return m_pollPriority; }
/**
* Set the polling priority.
* @param priority the polling priority, or 0 for no polling at all.
* @return true when the priority was changed and polling was not enabled before, false otherwise.
*/
bool setPollPriority(unsigned char priority);
bool setPollPriority(size_t priority);
/**
* Set the poll priority suitable for resolving a @a Condition.
@@ -416,7 +416,7 @@ class Message {
/**
* @return the number of parts this message is composed of.
*/
virtual unsigned char getCount() { return 1; }
virtual size_t getCount() { return 1; }
/**
* Prepare the master @a SymbolString for sending a query or command to the bus.
@@ -428,9 +428,9 @@ class Message {
* @param index the index of the part to prepare.
* @return @a RESULT_OK on success, or an error code.
*/
result_t prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
result_t prepareMaster(const symbol_t srcAddress, MasterSymbolString& master,
istringstream& input, char separator = UI_FIELD_SEPARATOR,
const unsigned char dstAddress = SYN, unsigned char index = 0);
const symbol_t dstAddress = SYN, size_t index = 0);
protected:
@@ -443,7 +443,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
size_t index);
public:
@@ -469,7 +469,7 @@ class Message {
* @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
virtual result_t storeLastData(MasterSymbolString& data, size_t index);
/**
* Store last seen slave data.
@@ -477,7 +477,7 @@ class Message {
* @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);
virtual result_t storeLastData(SlaveSymbolString& data, size_t index);
/**
* Decode the value from the last stored master data.
@@ -489,7 +489,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastMasterData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1);
/**
* Decode the value from the last stored slave data.
@@ -501,7 +501,7 @@ class Message {
* @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, ssize_t fieldIndex = -1);
/**
* Decode the value from the last stored data.
@@ -513,7 +513,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1);
/**
* Decode a particular numeric field value from the last stored data.
@@ -522,7 +522,7 @@ class Message {
* @param fieldIndex the optional index of the named field, or -1.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastDataNumField(unsigned int& output, const char* fieldName, signed char fieldIndex = -1);
virtual result_t decodeLastDataNumField(unsigned int& output, const char* fieldName, ssize_t fieldIndex = -1);
/**
* Get the last seen master data.
@@ -599,13 +599,13 @@ class Message {
const string m_comment;
/** the source address, or @a SYN for any (only relevant if passive). */
const unsigned char m_srcAddress;
const symbol_t m_srcAddress;
/** the destination address, or @a SYN for any (only for temporary scan messages). */
const unsigned char m_dstAddress;
const symbol_t m_dstAddress;
/** the primary, secondary, and optionally further command ID bytes. */
vector<unsigned char> m_id;
vector<symbol_t> m_id;
/**
* the key for storing in @a MessageMap.
@@ -637,7 +637,7 @@ class Message {
const bool m_deleteData;
/** the priority for polling, or 0 for no polling at all. */
unsigned char m_pollPriority;
size_t m_pollPriority;
/** whether this message is used by a @a Condition. */
bool m_usedByCondition;
@@ -692,47 +692,47 @@ class ChainedMessage : public Message {
*/
ChainedMessage(const string circuit, const string level, const string name,
const bool isWrite, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
vector< vector<unsigned char> > ids, vector<unsigned char> lengths,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
vector< vector<symbol_t> > ids, vector<size_t> lengths,
DataField* data, const bool deleteData,
const unsigned char pollPriority,
const size_t pollPriority,
Condition* condition = NULL);
virtual ~ChainedMessage();
// @copydoc
virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress = SYN,
const string circuit = "");
virtual Message* derive(const symbol_t dstAddress, const symbol_t srcAddress = SYN,
const string circuit = "") override;
// @copydoc
virtual unsigned char getIdLength() const { return (unsigned char)(m_ids[0].size() - 2); }
virtual size_t getIdLength() const override { return m_ids[0].size() - 2; }
// @copydoc
virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
virtual bool checkId(MasterSymbolString& master, size_t* index = NULL) override;
// @copydoc
virtual bool checkId(Message& other);
virtual bool checkId(Message& other) override;
// @copydoc
virtual unsigned char getCount() { return (unsigned char)m_ids.size(); }
virtual size_t getCount() override { return m_ids.size(); }
protected:
// @copydoc
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
size_t index) override;
public:
// @copydoc
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) override;
// @copydoc
virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
virtual result_t storeLastData(MasterSymbolString& data, size_t index) override;
// @copydoc
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
virtual result_t storeLastData(SlaveSymbolString& data, size_t index) override;
/**
* Combine all last stored data.
@@ -742,15 +742,15 @@ class ChainedMessage : public Message {
protected:
// @copydoc
virtual void dumpColumn(ostream& output, column_t column, bool withConditions = false);
virtual void dumpColumn(ostream& output, column_t column, bool withConditions = false) override;
private:
/** the primary, secondary, and optional further ID bytes for each part of the chain. */
const vector< vector<unsigned char> > m_ids;
const vector< vector<symbol_t> > m_ids;
/** the data length for each part of the chain. */
const vector<unsigned char> m_lengths;
const vector<size_t> m_lengths;
/** the maximum allowed time difference of any data pair. */
const time_t m_maxTimeDiff;
@@ -899,7 +899,7 @@ class SimpleCondition : public Condition {
* @param hasValues whether a value has to be checked against.
*/
SimpleCondition(const string condName, const string refName, const string circuit, const string level,
const string name, const unsigned char dstAddress, const string field, const bool hasValues = false)
const string name, const symbol_t dstAddress, const string field, const bool hasValues = false)
: Condition(),
m_condName(condName), m_refName(refName), m_circuit(circuit), m_level(level), m_name(name),
m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(NULL) { }
@@ -910,20 +910,20 @@ class SimpleCondition : public Condition {
virtual ~SimpleCondition() {}
// @copydoc
virtual SimpleCondition* derive(string valueList);
virtual SimpleCondition* derive(string valueList) override;
// @copydoc
virtual void dump(ostream& output, bool matched = false);
virtual void dump(ostream& output, bool matched = false) override;
// @copydoc
virtual CombinedCondition* combineAnd(Condition* other);
virtual CombinedCondition* combineAnd(Condition* other) override;
// @copydoc
virtual result_t resolve(MessageMap* messages, ostringstream& errorMessage,
void (*readMessageFunc)(Message* message) = NULL);
void (*readMessageFunc)(Message* message) = NULL) override;
// @copydoc
virtual bool isTrue();
virtual bool isTrue() override;
/**
* Return whether the condition is based on a numeric value.
@@ -963,7 +963,7 @@ class SimpleCondition : public Condition {
/** the override destination address, or @a SYN (only for @a Message without specific destination as well as scan
* message). */
const unsigned char m_dstAddress;
const symbol_t m_dstAddress;
/** the field name, or empty for first field. */
const string m_field;
@@ -993,7 +993,7 @@ class SimpleNumericCondition : public SimpleCondition {
* @param valueRanges the valid value ranges (pairs of from/to inclusive), empty for @a m_message seen check.
*/
SimpleNumericCondition(const string condName, const string refName, const string circuit, const string level,
const string name, const unsigned char dstAddress, const string field, const vector<unsigned int> valueRanges)
const string name, const symbol_t dstAddress, const string field, const vector<unsigned int> valueRanges)
: SimpleCondition(condName, refName, circuit, level, name, dstAddress, field, true),
m_valueRanges(valueRanges) { }
@@ -1005,7 +1005,7 @@ class SimpleNumericCondition : public SimpleCondition {
protected:
// @copydoc
virtual bool checkValue(Message* message, const string field);
virtual bool checkValue(Message* message, const string field) override;
private:
@@ -1031,7 +1031,7 @@ class SimpleStringCondition : public SimpleCondition {
* @param values the valid values.
*/
SimpleStringCondition(const string condName, const string refName, const string circuit, const string level,
const string name, const unsigned char dstAddress, const string field, const vector<string> values)
const string name, const symbol_t dstAddress, const string field, const vector<string> values)
: SimpleCondition(condName, refName, circuit, level, name, dstAddress, field, true),
m_values(values) { }
@@ -1041,12 +1041,12 @@ class SimpleStringCondition : public SimpleCondition {
virtual ~SimpleStringCondition() {}
// @copydoc
virtual bool isNumeric() { return false; }
virtual bool isNumeric() override { return false; }
protected:
// @copydoc
virtual bool checkValue(Message* message, const string field);
virtual bool checkValue(Message* message, const string field) override;
private:
@@ -1072,17 +1072,17 @@ class CombinedCondition : public Condition {
virtual ~CombinedCondition() {}
// @copydoc
virtual void dump(ostream& output, bool matched = false);
virtual void dump(ostream& output, bool matched = false) override;
// @copydoc
virtual CombinedCondition* combineAnd(Condition* other) { m_conditions.push_back(other); return this; }
virtual CombinedCondition* combineAnd(Condition* other) override { m_conditions.push_back(other); return this; }
// @copydoc
virtual result_t resolve(MessageMap* messages, ostringstream& errorMessage,
void (*readMessageFunc)(Message* message) = NULL);
void (*readMessageFunc)(Message* message) = NULL) override;
// @copydoc
virtual bool isTrue();
virtual bool isTrue() override;
private:
@@ -1209,7 +1209,7 @@ class LoadInstruction : public Instruction {
virtual ~LoadInstruction() { }
// @copydoc
virtual result_t execute(MessageMap* messages, ostringstream& log, Condition* condition);
virtual result_t execute(MessageMap* messages, ostringstream& log, Condition* condition) override;
private:
@@ -1252,7 +1252,7 @@ class MessageMap : public FileReader {
// @copydoc
virtual result_t addDefaultFromFile(vector< vector<string> >& defaults, vector<string>& row,
vector<string>::iterator& begin, string defaultDest, string defaultCircuit, string defaultSuffix,
const string& filename, unsigned int lineNo);
const string& filename, unsigned int lineNo) override;
/**
* Read the @a Condition instance(s) from the types field.
@@ -1266,14 +1266,14 @@ class MessageMap : public FileReader {
// @copydoc
virtual result_t addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end,
vector< vector<string> >* defaults, const string& defaultDest, const string& defaultCircuit,
const string& defaultSuffix, const string& filename, unsigned int lineNo);
const string& defaultSuffix, const string& filename, unsigned int lineNo) override;
/**
* Get the scan @a Message instance for the specified address.
* @param dstAddress the destination address, or @a SYN for the base scan @a Message.
* @return the scan @a Message instance, or NULL if the dstAddress is no slave.
*/
Message* getScanMessage(const unsigned char dstAddress = SYN);
Message* getScanMessage(const symbol_t dstAddress = SYN);
/**
* Resolve all @a Condition instances.
@@ -1305,7 +1305,7 @@ class MessageMap : public FileReader {
* @param file the name of the file from which a configuration part was loaded for the participant.
* @param comment an optional comment.
*/
void addLoadedFile(unsigned char address, string file, string comment);
void addLoadedFile(symbol_t address, string file, string comment);
/**
* Get the loaded files for a participant.
@@ -1313,7 +1313,7 @@ class MessageMap : public FileReader {
* @return the name of the file(s) loaded for the participant (separated by comma and enclosed in double quotes),
* or empty.
*/
string getLoadedFiles(unsigned char address);
string getLoadedFiles(symbol_t address);
/**
* Get the stored @a Message instances for the key.
@@ -1452,10 +1452,10 @@ class MessageMap : public FileReader {
Message* m_scanMessage;
/** the loaded configuration files by slave address. */
map<unsigned char, string> m_loadedFiles;
map<symbol_t, string> m_loadedFiles;
/** the maximum ID length used by any of the known @a Message instances. */
unsigned char m_maxIdLength;
size_t m_maxIdLength;
/** the number of distinct @a Message instances stored in @a m_messagesByName. */
size_t m_messageCount;
+24 -25
View File
@@ -34,7 +34,7 @@ using std::setfill;
/**
* CRC8 lookup table for the polynom 0x9b = x^8 + x^7 + x^4 + x^3 + x^1 + 1.
*/
static const unsigned char CRC_LOOKUP_TABLE[] = {
static const symbol_t CRC_LOOKUP_TABLE[] = {
0x00, 0x9b, 0xad, 0x36, 0xc1, 0x5a, 0x6c, 0xf7, 0x19, 0x82, 0xb4, 0x2f, 0xd8, 0x43, 0x75, 0xee,
0x32, 0xa9, 0x9f, 0x04, 0xf3, 0x68, 0x5e, 0xc5, 0x2b, 0xb0, 0x86, 0x1d, 0xea, 0x71, 0x47, 0xdc,
0x64, 0xff, 0xc9, 0x52, 0xa5, 0x3e, 0x08, 0x93, 0x7d, 0xe6, 0xd0, 0x4b, 0xbc, 0x27, 0x11, 0x8a,
@@ -55,7 +55,7 @@ static const unsigned char CRC_LOOKUP_TABLE[] = {
unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue,
result_t& result, unsigned int* length) {
result_t& result, size_t* length) {
char* strEnd = NULL;
unsigned long ret = strtoul(str, &strEnd, base);
@@ -77,7 +77,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
}
int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result,
unsigned int* length) {
size_t* length) {
char* strEnd = NULL;
long ret = strtol(str, &strEnd, base);
@@ -99,14 +99,14 @@ int parseSignedInt(const char* str, int base, const int minValue, const int maxV
}
void SymbolString::updateCrc(unsigned char& crc, const unsigned char value) {
void SymbolString::updateCrc(symbol_t& crc, const symbol_t value) {
crc = CRC_LOOKUP_TABLE[crc]^value;
}
result_t SymbolString::parseHex(const string& str) {
result_t result;
for (size_t i = 0; i < str.size(); i += 2) {
unsigned char value = (unsigned char)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
symbol_t value = (symbol_t)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -119,7 +119,7 @@ result_t SymbolString::parseHexEscaped(const string& str) {
result_t result;
bool inEscape = false;
for (size_t i = 0; i < str.size(); i += 2) {
unsigned char value = (unsigned char)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
symbol_t value = (symbol_t)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -144,24 +144,23 @@ result_t SymbolString::parseHexEscaped(const string& str) {
return inEscape ? RESULT_ERR_ESC : RESULT_OK;
}
const string SymbolString::getDataStr(unsigned char skipFirstSymbols) {
const string SymbolString::getStr(size_t skipFirstSymbols) {
ostringstream sstr;
for (size_t i = 0; i < m_data.size(); i++) {
if (skipFirstSymbols > 0) {
skipFirstSymbols--;
} else {
unsigned char value = m_data[i];
sstr << nouppercase << setw(2) << hex
<< setfill('0') << static_cast<unsigned>(value);
<< setfill('0') << static_cast<unsigned>(m_data[i]);
}
}
return sstr.str();
}
unsigned char SymbolString::calcCrc() const {
unsigned char crc = 0;
symbol_t SymbolString::calcCrc() const {
symbol_t crc = 0;
for (size_t i = 0; i < m_data.size(); i++) {
unsigned char value = m_data[i];
symbol_t value = m_data[i];
if (value == ESC) {
updateCrc(crc, ESC);
updateCrc(crc, 0x00);
@@ -181,7 +180,7 @@ unsigned char SymbolString::calcCrc() const {
* @param bits the upper or lower 4 bits of the address.
* @return the 1-based index of the upper or lower 4 bits of a master address (1 to 5), or 0.
*/
unsigned char getMasterPartIndex(unsigned char bits) {
unsigned int getMasterPartIndex(symbol_t bits) {
switch (bits) {
case 0x0:
return 1;
@@ -198,18 +197,18 @@ unsigned char getMasterPartIndex(unsigned char bits) {
}
}
bool isMaster(unsigned char addr) {
bool isMaster(symbol_t addr) {
return getMasterPartIndex(addr & 0x0F) > 0
&& getMasterPartIndex((addr & 0xF0)>>4) > 0;
}
bool isSlaveMaster(unsigned char addr) {
return isMaster((unsigned char)(addr+256-5));
bool isSlaveMaster(symbol_t addr) {
return isMaster((symbol_t)(addr+256-5));
}
unsigned char getSlaveAddress(unsigned char addr) {
symbol_t getSlaveAddress(symbol_t addr) {
if (isMaster(addr)) {
return (unsigned char)(addr+5);
return (symbol_t)(addr+5);
}
if (isValidAddress(addr, false)) {
return addr;
@@ -217,30 +216,30 @@ unsigned char getSlaveAddress(unsigned char addr) {
return SYN;
}
unsigned char getMasterAddress(unsigned char addr) {
symbol_t getMasterAddress(symbol_t addr) {
if (isMaster(addr)) {
return addr;
}
addr = (unsigned char)(addr+256-5);
addr = (symbol_t)(addr+256-5);
if (isMaster(addr)) {
return addr;
}
return SYN;
}
unsigned char getMasterNumber(unsigned char addr) {
unsigned char priority = getMasterPartIndex(addr & 0x0F);
unsigned int getMasterNumber(symbol_t addr) {
unsigned int priority = getMasterPartIndex(addr & 0x0F);
if (priority == 0) {
return 0;
}
unsigned char index = getMasterPartIndex((addr & 0xF0) >> 4);
unsigned int index = getMasterPartIndex((addr & 0xF0) >> 4);
if (index == 0) {
return 0;
}
return (unsigned char)(5*(priority-1) + index);
return 5*(priority-1) + index;
}
bool isValidAddress(unsigned char addr, bool allowBroadcast) {
bool isValidAddress(symbol_t addr, bool allowBroadcast) {
return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST);
}
+46 -30
View File
@@ -68,6 +68,9 @@ namespace ebusd {
using std::string;
using std::vector;
/** the base type for symbols sent to/from the eBUS. */
typedef unsigned char symbol_t;
/** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA. */
#define ESC 0xA9
@@ -94,7 +97,7 @@ using std::vector;
* @return the parsed value.
*/
unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue,
result_t& result, unsigned int* length = NULL);
result_t& result, size_t* length = NULL);
/**
* Parse a signed int value.
@@ -107,7 +110,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
* @return the parsed value.
*/
int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result,
unsigned int* length = NULL);
size_t* length = NULL);
/**
* A string of unescaped bus symbols.
@@ -126,7 +129,13 @@ class SymbolString {
* @param crc the current CRC to update.
* @param value the escaped value to add to the current CRC.
*/
static void updateCrc(unsigned char& crc, const unsigned char value);
static void updateCrc(symbol_t& crc, const symbol_t value);
/**
* Return whether this instance if for the master part.
* @return whether this instance if for the master part.
*/
bool isMaster() const { return m_isMaster; }
/**
* Parse the hex @a string and add all symbols.
@@ -147,14 +156,14 @@ class SymbolString {
* @param skipFirstSymbols the number of first symbols to skip.
* @return the symbols as hex string.
*/
const string getDataStr(unsigned char skipFirstSymbols = 0);
const string getStr(size_t skipFirstSymbols = 0);
/**
* Return a reference to the symbol at the specified index.
* @param index the index of the symbol to return.
* @return the reference to the symbol at the specified index.
*/
unsigned char& operator[](const size_t index) {
symbol_t& operator[](const size_t index) {
if (index >= m_data.size()) {
m_data.resize(index+1, 0);
}
@@ -209,37 +218,44 @@ class SymbolString {
* Append a symbol to the end of the symbol string.
* @param value the symbol to append.
*/
void push_back(const unsigned char value) { m_data.push_back(value); }
void push_back(const symbol_t value) { m_data.push_back(value); }
/**
* Return the number of symbols in this symbol string.
* @return the number of available symbols.
*/
unsigned char size() const { return (unsigned char)m_data.size(); }
size_t size() const { return m_data.size(); }
/**
* Return the offset to the first data byte DD.
* @return the offset to the first data byte DD.
*/
unsigned char getDataOffset() const { return m_isMaster ? 5 : 1; }
size_t getDataOffset() const { return m_isMaster ? 5 : 1; }
/**
* Return the number of data bytes DD.
* @return the number of data bytes DD.
* Return the number of effectively available data bytes DD.
* @return the number of effectively available data bytes DD.
*/
unsigned char getDataSize() const { return m_data.size() > (m_isMaster ? 4 : 0) ? m_data[m_isMaster ? 4 : 0] : 0; }
/**
* Return the data byte at the specified index (within DD).
* @param index the index of the data byte to return (0 up to NN excluding).
* @return the data byte at the specified index, or @a SYN if not available.
*/
unsigned char getDataAt(const size_t index) {
size_t offset = m_isMaster ? 5 : 1;
if (offset+index >= m_data.size()) {
return SYN;
size_t getDataSize() const {
size_t lengthOffset = (m_isMaster ? 4 : 0);
if (m_data.size() <= lengthOffset) {
return 0;
}
return m_data[offset+index];
size_t ret = m_data[lengthOffset];
return m_data.size() < lengthOffset + 1 + ret ? m_data.size() - lengthOffset - 1 : ret;
}
/**
* Return a reference to the data byte at the specified index (within DD).
* @param index the index of the data byte (within DD) to return.
* @return the reference to the data byte at the specified index.
*/
symbol_t& dataAt(const size_t index) {
size_t offset = (m_isMaster ? 5 : 1) + index;
if (offset >= m_data.size()) {
m_data.resize(offset+1, 0);
}
return m_data[offset];
}
/**
@@ -258,7 +274,7 @@ class SymbolString {
* Calculate the CRC.
* @return the calculated CRC.
*/
unsigned char calcCrc() const;
symbol_t calcCrc() const;
/**
* Clear the symbols.
@@ -275,7 +291,7 @@ class SymbolString {
: m_data(str.m_data), m_isMaster(str.m_isMaster) {}
/** the string of unescaped symbols. */
vector<unsigned char> m_data;
vector<symbol_t> m_data;
/** whether this instance if for the master part. */
bool m_isMaster;
@@ -311,14 +327,14 @@ class SlaveSymbolString : public SymbolString {
* @param addr the address to check.
* @return <code>true</code> if the specified address is a master address.
*/
bool isMaster(unsigned char addr);
bool isMaster(symbol_t addr);
/**
* Return whether the address is a slave address of one of the 25 masters.
* @param addr the address to check.
* @return <code>true</code> if the specified address is a slave address of a master.
*/
bool isSlaveMaster(unsigned char addr);
bool isSlaveMaster(symbol_t addr);
/**
* Return the slave address associated with the specified address (master or slave).
@@ -326,7 +342,7 @@ bool isSlaveMaster(unsigned char addr);
* @return the slave address, or SYN if the specified address is neither a master address nor a slave address of a
* master.
*/
unsigned char getSlaveAddress(unsigned char addr);
symbol_t getSlaveAddress(symbol_t addr);
/**
* Return the master address associated with the specified address (master or slave).
@@ -334,14 +350,14 @@ unsigned char getSlaveAddress(unsigned char addr);
* @return the master address, or SYN if the specified address is neither a master address nor a slave address of a
* master.
*/
unsigned char getMasterAddress(unsigned char addr);
symbol_t getMasterAddress(symbol_t addr);
/**
* Return the number of the master if the address is a valid bus address.
* @param addr the bus address.
* @return the number of the master if the address is a valid bus address (1 to 25), or 0.
*/
unsigned char getMasterNumber(unsigned char addr);
unsigned int getMasterNumber(symbol_t addr);
/**
* Return whether the address is a valid bus address.
@@ -349,7 +365,7 @@ unsigned char getMasterNumber(unsigned char addr);
* @param allowBroadcast whether to also allow @a addr to be the broadcast address (default true).
* @return <code>true</code> if the specified address is a valid bus address.
*/
bool isValidAddress(unsigned char addr, bool allowBroadcast = true);
bool isValidAddress(symbol_t addr, bool allowBroadcast = true);
} // namespace ebusd
+10 -13
View File
@@ -564,22 +564,20 @@ int main() {
ostringstream output;
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
result = writeMstr.parseHex(mstr.getStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
result = writeSstr.parseHex(sstr.getStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
result = fields->read(mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
result = fields->read(sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
!output.str().empty());
}
if (failedRead) {
@@ -602,9 +600,9 @@ int main() {
if (verbosity == 0) {
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
result = fields->write(input, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
result = fields->write(input, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
@@ -621,9 +619,8 @@ int main() {
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr() + " "
+ sstr.getDataStr(), writeMstr.getDataStr() + " "
+ writeSstr.getDataStr());
verify(failedWriteMatch, "write", expectStr, match, mstr.getStr() + " " + sstr.getStr(),
writeMstr.getStr() + " " + writeSstr.getStr());
}
}
delete fields;
+1 -1
View File
@@ -39,7 +39,7 @@ int main() {
int count = 0;
while (1) {
unsigned char byte = 0;
symbol_t byte = 0;
result = device->recv(0, byte);
if (result == RESULT_OK) {
+2 -3
View File
@@ -399,7 +399,7 @@ int main() {
if (message->isPassive() || decode) {
ostringstream output;
for (unsigned char index = 0; index < message->getCount(); index++) {
for (size_t index = 0; index < message->getCount(); index++) {
message->storeLastData(*mstrs[index], *sstrs[index]);
}
if (withMessageDump && !decodeJson) {
@@ -438,8 +438,7 @@ int main() {
cout << " \"" << inputStr << "\": prepare OK" << endl;
bool match = writeMstr == *mstrs[0];
verify(failedPrepareMatch, "prepare", inputStr, match, mstrs[0]->getDataStr(),
writeMstr.getDataStr());
verify(failedPrepareMatch, "prepare", inputStr, match, mstrs[0]->getStr(), writeMstr.getStr());
}
}
+5 -5
View File
@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
} else {
unsigned char gotCrc = mstr.calcCrc();
symbol_t gotCrc = mstr.calcCrc();
cout << "calculated CRC: 0x"
<< nouppercase << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(gotCrc) << endl;
@@ -73,9 +73,9 @@ int main(int argc, char** argv) {
cout << "parse unescaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = mstr.calcCrc(), expectCrc = 0x77;
symbol_t gotCrc = mstr.calcCrc(), expectCrc = 0x77;
ostringstream ostr;
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
expectStr = ostr.str();
@@ -91,7 +91,7 @@ int main(int argc, char** argv) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse escaped", "10feb5050427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);
@@ -108,7 +108,7 @@ int main(int argc, char** argv) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(), expectStr = "0427a915aa";
gotStr = sstr.getStr(), expectStr = "0427a915aa";
verify(false, "parse escaped", "0427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);
+1 -1
View File
@@ -160,7 +160,7 @@ int main(int argc, char* argv[]) {
fstream file(opt.dumpFile, ios::in | ios::binary);
if (file.is_open()) {
while (true) {
unsigned char byte = (unsigned char)file.get();
symbol_t byte = (symbol_t)file.get();
if (file.eof()) {
break;
}