changed code style

This commit is contained in:
john30
2015-02-21 13:18:36 +01:00
parent 0bfc63c13a
commit 41cd38ab75
20 changed files with 218 additions and 217 deletions
+46 -46
View File
@@ -98,7 +98,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
bool append = m_scanResults != NULL && m_scanResults->find(dstAddress) != m_scanResults->end(); bool append = m_scanResults != NULL && m_scanResults->find(dstAddress) != m_scanResults->end();
ostringstream scanResult; ostringstream scanResult;
if (result == RESULT_OK) { if (result == RESULT_OK) {
if (append == false) if (!append)
scanResult << hex << setw(2) << setfill('0') << static_cast<unsigned>(dstAddress) << UI_FIELD_SEPARATOR; scanResult << hex << setw(2) << setfill('0') << static_cast<unsigned>(dstAddress) << UI_FIELD_SEPARATOR;
result = m_message->decode(pt_slaveData, slave, scanResult, append); // decode data result = m_message->decode(pt_slaveData, slave, scanResult, append); // decode data
} }
@@ -110,14 +110,14 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
string str = scanResult.str(); string str = scanResult.str();
logNotice(lf_bus, "scan: %s", str.c_str()); logNotice(lf_bus, "scan: %s", str.c_str());
if (m_scanResults != NULL) { if (m_scanResults != NULL) {
if (append == true) if (append)
(*m_scanResults)[dstAddress] += str; (*m_scanResults)[dstAddress] += str;
else else
(*m_scanResults)[dstAddress] = str; (*m_scanResults)[dstAddress] = str;
} }
// check for remaining secondary messages // check for remaining secondary messages
if (m_messages.empty() == true) if (m_messages.empty())
return false; return false;
m_message = m_messages.front(); m_message = m_messages.front();
@@ -151,12 +151,12 @@ result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
for (int sendRetries=m_failedSendRetries+1; sendRetries>=0; sendRetries--) { for (int sendRetries=m_failedSendRetries+1; sendRetries>=0; sendRetries--) {
m_nextRequests.add(&request); m_nextRequests.add(&request);
bool success = m_finishedRequests.waitRemove(&request); bool success = m_finishedRequests.waitRemove(&request);
result = success == true ? request.m_result : RESULT_ERR_TIMEOUT; result = success ? request.m_result : RESULT_ERR_TIMEOUT;
if (result == RESULT_OK) if (result == RESULT_OK)
break; break;
if (success == false || result == RESULT_ERR_NO_SIGNAL) { if (!success || result == RESULT_ERR_NO_SIGNAL) {
logError(lf_bus, "%s, give up", getResultCode(result)); logError(lf_bus, "%s, give up", getResultCode(result));
break; break;
} }
@@ -174,7 +174,7 @@ void BusHandler::run()
time_t lastTime; time_t lastTime;
time(&lastTime); time(&lastTime);
do { do {
if (m_device->isValid() == true) { if (m_device->isValid()) {
result_t result = handleSymbol(); result_t result = handleSymbol();
if (result != RESULT_ERR_TIMEOUT) if (result != RESULT_ERR_TIMEOUT)
symCount++; symCount++;
@@ -191,7 +191,7 @@ void BusHandler::run()
symCount = 0; symCount = 0;
} }
} else { } else {
if (Wait(10) == false) if (!Wait(10))
break; break;
result_t result = m_device->open(); result_t result = m_device->open();
@@ -201,7 +201,7 @@ void BusHandler::run()
logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result)); logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result));
symCount = 0; symCount = 0;
} }
} while (isRunning() == true); } while (isRunning());
} }
result_t BusHandler::handleSymbol() result_t BusHandler::handleSymbol()
@@ -306,7 +306,7 @@ result_t BusHandler::handleSymbol()
// send symbol if necessary // send symbol if necessary
result_t result; result_t result;
if (sending == true) { if (sending) {
result = m_device->send(sendSymbol); result = m_device->send(sendSymbol);
if (result == RESULT_OK) if (result == RESULT_OK)
if (m_state == bs_ready) if (m_state == bs_ready)
@@ -336,9 +336,9 @@ result_t BusHandler::handleSymbol()
m_lastReceive = now; m_lastReceive = now;
if (recvSymbol == SYN) { if (recvSymbol == SYN) {
if (sending == false && m_remainLockCount > 0 && m_command.size() != 1) if (!sending && m_remainLockCount > 0 && m_command.size() != 1)
m_remainLockCount--; m_remainLockCount--;
else if (sending == false && m_remainLockCount == 0 && m_command.size() == 1) else if (!sending && m_remainLockCount == 0 && m_command.size() == 1)
m_remainLockCount = 1; // wait for next AUTO-SYN after SYN / address / SYN (bus locked for own priority) m_remainLockCount = 1; // wait for next AUTO-SYN after SYN / address / SYN (bus locked for own priority)
return setState(bs_ready, RESULT_ERR_SYN); return setState(bs_ready, RESULT_ERR_SYN);
@@ -355,8 +355,8 @@ result_t BusHandler::handleSymbol()
return RESULT_OK; return RESULT_OK;
case bs_ready: case bs_ready:
if (startRequest != NULL && sending == true) { if (startRequest != NULL && sending) {
if (m_nextRequests.remove(startRequest) == false) { if (!m_nextRequests.remove(startRequest)) {
// request already removed (e.g. due to timeout) // request already removed (e.g. due to timeout)
return setState(bs_skip, RESULT_ERR_TIMEOUT); return setState(bs_skip, RESULT_ERR_TIMEOUT);
} }
@@ -397,7 +397,7 @@ result_t BusHandler::handleSymbol()
receiveCompleted(); receiveCompleted();
return setState(bs_skip, RESULT_OK); return setState(bs_skip, RESULT_OK);
} }
if (m_answer == true if (m_answer
&& (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress)) && (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress))
return setState(bs_sendCmdAck, RESULT_OK); return setState(bs_sendCmdAck, RESULT_OK);
@@ -406,11 +406,11 @@ result_t BusHandler::handleSymbol()
if (dstAddress == BROADCAST) if (dstAddress == BROADCAST)
return setState(bs_skip, RESULT_ERR_CRC); return setState(bs_skip, RESULT_ERR_CRC);
if (m_answer == true if (m_answer
&& (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress)) { && (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress)) {
return setState(bs_sendCmdAck, RESULT_ERR_CRC); return setState(bs_sendCmdAck, RESULT_ERR_CRC);
} }
if (m_repeat == true) if (m_repeat)
return setState(bs_skip, RESULT_ERR_CRC); return setState(bs_skip, RESULT_ERR_CRC);
return setState(bs_recvCmdAck, RESULT_ERR_CRC); return setState(bs_recvCmdAck, RESULT_ERR_CRC);
} }
@@ -418,15 +418,15 @@ result_t BusHandler::handleSymbol()
case bs_recvCmdAck: case bs_recvCmdAck:
if (recvSymbol == ACK) { if (recvSymbol == ACK) {
if (m_commandCrcValid == false) if (!m_commandCrcValid)
return setState(bs_skip, RESULT_ERR_ACK); return setState(bs_skip, RESULT_ERR_ACK);
if (m_currentRequest != NULL) { if (m_currentRequest != NULL) {
if (isMaster(m_currentRequest->m_master[1]) == true) { if (isMaster(m_currentRequest->m_master[1])) {
return setState(bs_sendSyn, RESULT_OK); return setState(bs_sendSyn, RESULT_OK);
} }
} }
else if (isMaster(m_command[1]) == true) { // header symbols are never escaped else if (isMaster(m_command[1])) { // header symbols are never escaped
receiveCompleted(); receiveCompleted();
return setState(bs_skip, RESULT_OK); return setState(bs_skip, RESULT_OK);
} }
@@ -435,7 +435,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_recvRes, RESULT_OK); return setState(bs_recvRes, RESULT_OK);
} }
if (recvSymbol == NAK) { if (recvSymbol == NAK) {
if (m_repeat == false) { if (!m_repeat) {
m_repeat = true; m_repeat = true;
m_nextSendPos = 0; m_nextSendPos = 0;
m_command.clear(); m_command.clear();
@@ -465,7 +465,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_recvResAck, RESULT_OK); return setState(bs_recvResAck, RESULT_OK);
} }
if (m_repeat == true) { if (m_repeat) {
if (m_currentRequest != NULL) if (m_currentRequest != NULL)
return setState(bs_sendSyn, RESULT_ERR_CRC); return setState(bs_sendSyn, RESULT_ERR_CRC);
@@ -480,14 +480,14 @@ result_t BusHandler::handleSymbol()
case bs_recvResAck: case bs_recvResAck:
if (recvSymbol == ACK) { if (recvSymbol == ACK) {
if (m_responseCrcValid == false) if (!m_responseCrcValid)
return setState(bs_skip, RESULT_ERR_ACK); return setState(bs_skip, RESULT_ERR_ACK);
receiveCompleted(); receiveCompleted();
return setState(bs_skip, RESULT_OK); return setState(bs_skip, RESULT_OK);
} }
if (recvSymbol == NAK) { if (recvSymbol == NAK) {
if (m_repeat == false) { if (!m_repeat) {
m_repeat = true; m_repeat = true;
m_response.clear(); m_response.clear();
return setState(bs_recvRes, RESULT_ERR_NAK, true); return setState(bs_recvRes, RESULT_ERR_NAK, true);
@@ -497,7 +497,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_skip, RESULT_ERR_ACK); return setState(bs_skip, RESULT_ERR_ACK);
case bs_sendCmd: case bs_sendCmd:
if (m_currentRequest != NULL && sending == true) { if (m_currentRequest != NULL && sending) {
if (recvSymbol == sendSymbol) { if (recvSymbol == sendSymbol) {
// successfully sent // successfully sent
m_nextSendPos++; m_nextSendPos++;
@@ -515,11 +515,11 @@ result_t BusHandler::handleSymbol()
return setState(bs_skip, RESULT_ERR_INVALID_ARG); return setState(bs_skip, RESULT_ERR_INVALID_ARG);
case bs_sendResAck: case bs_sendResAck:
if (m_currentRequest != NULL && sending == true) { if (m_currentRequest != NULL && sending) {
if (recvSymbol == sendSymbol) { if (recvSymbol == sendSymbol) {
// successfully sent // successfully sent
if (m_responseCrcValid == false) { if (!m_responseCrcValid) {
if (m_repeat == false) { if (!m_repeat) {
m_repeat = true; m_repeat = true;
m_response.clear(); m_response.clear();
return setState(bs_recvRes, RESULT_ERR_NAK, true); return setState(bs_recvRes, RESULT_ERR_NAK, true);
@@ -532,25 +532,25 @@ result_t BusHandler::handleSymbol()
return setState(bs_skip, RESULT_ERR_INVALID_ARG); return setState(bs_skip, RESULT_ERR_INVALID_ARG);
case bs_sendCmdAck: case bs_sendCmdAck:
if (sending == true && m_answer == true) { if (sending && m_answer) {
if (recvSymbol == sendSymbol) { if (recvSymbol == sendSymbol) {
// successfully sent // successfully sent
if (m_commandCrcValid == false) { if (!m_commandCrcValid) {
if (m_repeat == false) { if (!m_repeat) {
m_repeat = true; m_repeat = true;
m_command.clear(); m_command.clear();
return setState(bs_recvCmd, RESULT_ERR_NAK, true); return setState(bs_recvCmd, RESULT_ERR_NAK, true);
} }
return setState(bs_skip, RESULT_ERR_ACK); return setState(bs_skip, RESULT_ERR_ACK);
} }
if (isMaster(m_command[1]) == true) if (isMaster(m_command[1]))
receiveCompleted(); // decode command and store value receiveCompleted(); // decode command and store value
return setState(bs_skip, RESULT_OK); return setState(bs_skip, RESULT_OK);
m_nextSendPos = 0; m_nextSendPos = 0;
m_repeat = false; m_repeat = false;
Message* message = m_messages->find(m_command); Message* message = m_messages->find(m_command);
if (message == NULL || message->isPassive() == false || message->isWrite() == true) if (message == NULL || !message->isPassive() || message->isWrite())
return setState(bs_skip, RESULT_ERR_INVALID_ARG); // don't know this request or definition has wrong direction, deny return setState(bs_skip, RESULT_ERR_INVALID_ARG); // don't know this request or definition has wrong direction, deny
// build response and store in m_response for sending back to requesting master // build response and store in m_response for sending back to requesting master
@@ -564,7 +564,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_skip, RESULT_ERR_INVALID_ARG); return setState(bs_skip, RESULT_ERR_INVALID_ARG);
case bs_sendRes: case bs_sendRes:
if (sending == true && m_answer == true) { if (sending && m_answer) {
if (recvSymbol == sendSymbol) { if (recvSymbol == sendSymbol) {
// successfully sent // successfully sent
m_nextSendPos++; m_nextSendPos++;
@@ -578,7 +578,7 @@ result_t BusHandler::handleSymbol()
return setState(bs_skip, RESULT_ERR_INVALID_ARG); return setState(bs_skip, RESULT_ERR_INVALID_ARG);
case bs_sendSyn: case bs_sendSyn:
if (sending == true) { if (sending) {
if (recvSymbol == sendSymbol) { if (recvSymbol == sendSymbol) {
// successfully sent // successfully sent
return setState(bs_skip, RESULT_OK); return setState(bs_skip, RESULT_OK);
@@ -600,17 +600,17 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
m_nextRequests.add(m_currentRequest); // repeat m_nextRequests.add(m_currentRequest); // repeat
m_currentRequest = NULL; m_currentRequest = NULL;
} }
else if (state == bs_sendSyn || (result != RESULT_OK && firstRepetition == false)) { else if (state == bs_sendSyn || (result != RESULT_OK && !firstRepetition)) {
logDebug(lf_bus, "notify request: %s", getResultCode(result)); logDebug(lf_bus, "notify request: %s", getResultCode(result));
unsigned char dstAddress = m_currentRequest->m_master[1]; unsigned char dstAddress = m_currentRequest->m_master[1];
if (result == RESULT_OK && isValidAddress(dstAddress, false) == true) if (result == RESULT_OK && isValidAddress(dstAddress, false))
m_seenAddresses[dstAddress] = true; m_seenAddresses[dstAddress] = true;
bool restart = m_currentRequest->notify(result, m_response); bool restart = m_currentRequest->notify(result, m_response);
if (restart == true) { if (restart) {
m_currentRequest->m_busLostRetries = 0; m_currentRequest->m_busLostRetries = 0;
m_nextRequests.add(m_currentRequest); m_nextRequests.add(m_currentRequest);
} }
else if (m_currentRequest->m_deleteOnFinish == true) else if (m_currentRequest->m_deleteOnFinish)
delete m_currentRequest; delete m_currentRequest;
else else
m_finishedRequests.add(m_currentRequest); m_finishedRequests.add(m_currentRequest);
@@ -623,11 +623,11 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
m_response.clear(false); // notify with empty response m_response.clear(false); // notify with empty response
while ((m_currentRequest = m_nextRequests.remove(false)) != NULL) { while ((m_currentRequest = m_nextRequests.remove(false)) != NULL) {
bool restart = m_currentRequest->notify(RESULT_ERR_NO_SIGNAL, m_response); bool restart = m_currentRequest->notify(RESULT_ERR_NO_SIGNAL, m_response);
if (restart == true) { // should not occur with no signal if (restart) { // should not occur with no signal
m_currentRequest->m_busLostRetries = 0; m_currentRequest->m_busLostRetries = 0;
m_nextRequests.add(m_currentRequest); m_nextRequests.add(m_currentRequest);
} }
else if (m_currentRequest->m_deleteOnFinish == true) else if (m_currentRequest->m_deleteOnFinish)
delete m_currentRequest; delete m_currentRequest;
else else
m_finishedRequests.add(m_currentRequest); m_finishedRequests.add(m_currentRequest);
@@ -667,7 +667,7 @@ void BusHandler::receiveCompleted()
m_seenAddresses[srcAddress] = true; m_seenAddresses[srcAddress] = true;
if (dstAddress == BROADCAST) if (dstAddress == BROADCAST)
logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str()); logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true) { else if (master) {
logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str()); logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str());
m_seenAddresses[dstAddress] = true; m_seenAddresses[dstAddress] = true;
} }
@@ -680,7 +680,7 @@ void BusHandler::receiveCompleted()
if (message == NULL) { if (message == NULL) {
if (dstAddress == BROADCAST) if (dstAddress == BROADCAST)
logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str()); logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true) else if (master)
logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str()); logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str());
else 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.getDataStr().c_str(), m_response.getDataStr().c_str());
@@ -694,7 +694,7 @@ void BusHandler::receiveCompleted()
logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result)); logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
else { else {
string data = output.str(); string data = output.str();
if (m_answer == true && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) { if (m_answer && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) {
logNotice(lf_update, "self-update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str()); // TODO store in database of internal variables logNotice(lf_update, "self-update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str()); // TODO store in database of internal variables
} }
else if (message->getDstAddress() == SYN) { // any destination else if (message->getDstAddress() == SYN) { // any destination
@@ -733,11 +733,11 @@ result_t BusHandler::startScan(bool full)
m_scanResults.clear(); m_scanResults.clear();
for (unsigned int slave=0; slave<=255; slave++) { for (unsigned int slave=0; slave<=255; slave++) {
if (isValidAddress(slave, false) == false || isMaster(slave) == true) if (!isValidAddress(slave, false) || isMaster(slave))
continue; continue;
if (full == false && m_seenAddresses[slave] == false) { if (!full && !m_seenAddresses[slave]) {
unsigned int master = slave+(256-5); // check if we saw the corresponding master already unsigned int master = slave+(256-5); // check if we saw the corresponding master already
if (isMaster(master) == false || m_seenAddresses[slave] == false) if (!isMaster(master) || !m_seenAddresses[slave])
continue; continue;
} }
+4 -4
View File
@@ -501,7 +501,7 @@ result_t loadConfigFiles(DataFieldTemplates* templates, MessageMap* messages, bo
*/ */
static void logRawData(const unsigned char byte, bool received) static void logRawData(const unsigned char byte, bool received)
{ {
if (received == true) if (received)
logNotice(lf_bus, "<%02x", byte); logNotice(lf_bus, "<%02x", byte);
else else
logNotice(lf_bus, ">%02x", byte); logNotice(lf_bus, ">%02x", byte);
@@ -522,7 +522,7 @@ int main(int argc, char* argv[])
DataFieldTemplates templates; DataFieldTemplates templates;
MessageMap messages; MessageMap messages;
if (opt.checkConfig == true) { if (opt.checkConfig) {
logNotice(lf_main, "Performing configuration check..."); logNotice(lf_main, "Performing configuration check...");
loadConfigFiles(&templates, &messages, true); loadConfigFiles(&templates, &messages, true);
@@ -534,13 +534,13 @@ int main(int argc, char* argv[])
} }
// open the device // open the device
Device *device = Device::create(opt.device, opt.noDeviceCheck==false, &logRawData); Device *device = Device::create(opt.device, !opt.noDeviceCheck, &logRawData);
if (device == NULL) { if (device == NULL) {
logError(lf_main, "unable to create device %s", opt.device); logError(lf_main, "unable to create device %s", opt.device);
return EINVAL; return EINVAL;
} }
if (opt.foreground == false) { if (!opt.foreground) {
setLogFile(opt.logFile); setLogFile(opt.logFile);
daemonize(); // make me daemon daemonize(); // make me daemon
} }
+19 -19
View File
@@ -39,7 +39,7 @@ MainLoop::MainLoop(const struct options opt, Device *device, DataFieldTemplates*
result_t result = m_device->open(); result_t result = m_device->open();
if (result != RESULT_OK) if (result != RESULT_OK)
logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result)); logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result));
else if (m_device->isValid() == false) else if (!m_device->isValid())
logError(lf_bus, "device %s not available", m_device->getName()); logError(lf_bus, "device %s not available", m_device->getName());
// create BusHandler // create BusHandler
@@ -78,7 +78,7 @@ void MainLoop::run()
{ {
bool running = true; bool running = true;
while (running == true) { while (running) {
string result; string result;
// pick the next message to handle // pick the next message to handle
@@ -88,7 +88,7 @@ void MainLoop::run()
time_t since, until; time_t since, until;
time(&until); time(&until);
bool listening = message->isListening(since); bool listening = message->isListening(since);
if (listening == false) if (!listening)
since = until; since = until;
bool connected = true; bool connected = true;
@@ -102,12 +102,12 @@ void MainLoop::run()
logNotice(lf_main, "<<< %s", result.c_str()); logNotice(lf_main, "<<< %s", result.c_str());
result += "\n\n"; result += "\n\n";
} }
if (listening == true) { if (listening) {
result += getUpdates(since, until); result += getUpdates(since, until);
} }
// send result to client // send result to client
message->setResult(result, listening, until, connected == false); message->setResult(result, listening, until, !connected);
} }
} }
@@ -122,7 +122,7 @@ string MainLoop::decodeMessage(const string& data, bool& connected, bool& listen
bool escaped = false; bool escaped = false;
while (getline(stream, token, ' ') != 0) { while (getline(stream, token, ' ') != 0) {
if (escaped == true) { if (escaped) {
args.pop_back(); args.pop_back();
if (token.length() > 0 && token[token.length()-1] == '"') { if (token.length() > 0 && token[token.length()-1] == '"') {
token = token.substr(0, token.length() - 1); token = token.substr(0, token.length() - 1);
@@ -245,7 +245,7 @@ string MainLoop::executeRead(vector<string> &args)
time(&now); time(&now);
Message* updateMessage = NULL; Message* updateMessage = NULL;
if (maxAge > 0 && verbose == false) { if (maxAge > 0 && !verbose) {
updateMessage = m_messages->find(clazz, args[argPos], false, true); updateMessage = m_messages->find(clazz, args[argPos], false, true);
if (updateMessage != NULL && updateMessage->getLastUpdateTime() + maxAge > now) if (updateMessage != NULL && updateMessage->getLastUpdateTime() + maxAge > now)
@@ -322,7 +322,7 @@ string MainLoop::executeWrite(vector<string> &args)
ret = master.push_back(m_address, false); ret = master.push_back(m_address, false);
if (ret == RESULT_OK) if (ret == RESULT_OK)
ret = master.parseHex(msg.str()); ret = master.parseHex(msg.str());
if (ret == RESULT_OK && isValidAddress(master[1]) == false) if (ret == RESULT_OK && !isValidAddress(master[1]))
ret = RESULT_ERR_INVALID_ADDR; ret = RESULT_ERR_INVALID_ADDR;
if (ret != RESULT_OK) if (ret != RESULT_OK)
return getResultCode(ret); return getResultCode(ret);
@@ -382,7 +382,7 @@ string MainLoop::executeWrite(vector<string> &args)
return getResultCode(RESULT_OK); return getResultCode(RESULT_OK);
ret = message->decode(pt_slaveData, slave, result); // decode data ret = message->decode(pt_slaveData, slave, result); // decode data
if (ret == RESULT_OK && result.str().empty() == true) if (ret == RESULT_OK && result.str().empty())
return getResultCode(RESULT_OK); return getResultCode(RESULT_OK);
} }
if (ret != RESULT_OK) { if (ret != RESULT_OK) {
@@ -401,21 +401,21 @@ string MainLoop::executeFind(vector<string> &args)
if (args[argPos] == "-v") if (args[argPos] == "-v")
verbose = true; verbose = true;
else if (args[argPos] == "-r") { else if (args[argPos] == "-r") {
if (first == true) { if (first) {
first = false; first = false;
withWrite = withPassive = false; withWrite = withPassive = false;
} }
withRead = true; withRead = true;
} }
else if (args[argPos] == "-w") { else if (args[argPos] == "-w") {
if (first == true) { if (first) {
first = false; first = false;
withRead = withPassive = false; withRead = withPassive = false;
} }
withWrite = true; withWrite = true;
} }
else if (args[argPos] == "-p") { else if (args[argPos] == "-p") {
if (first == true) { if (first) {
first = false; first = false;
withRead = withWrite = false; withRead = withWrite = false;
} }
@@ -464,16 +464,16 @@ string MainLoop::executeFind(vector<string> &args)
if (dstAddress == SYN) if (dstAddress == SYN)
continue; continue;
time_t lastup = message->getLastUpdateTime(); time_t lastup = message->getLastUpdateTime();
if (onlyWithData == true && lastup == 0) if (onlyWithData && lastup == 0)
continue; continue;
if (found == true) if (found)
result << endl; result << endl;
result << message->getClass() << " " << message->getName() << " = "; result << message->getClass() << " " << message->getName() << " = ";
if (lastup == 0) if (lastup == 0)
result << "no data stored"; result << "no data stored";
else else
result << message->getLastValue(); result << message->getLastValue();
if (verbose == true) { if (verbose) {
if (lastup == 0) if (lastup == 0)
sprintf(str, "%02x", dstAddress); sprintf(str, "%02x", dstAddress);
else { else {
@@ -495,7 +495,7 @@ string MainLoop::executeFind(vector<string> &args)
} }
found = true; found = true;
} }
if (found == false) if (!found)
return getResultCode(RESULT_ERR_NOTFOUND); return getResultCode(RESULT_ERR_NOTFOUND);
return result.str(); return result.str();
@@ -504,7 +504,7 @@ string MainLoop::executeFind(vector<string> &args)
string MainLoop::executeListen(vector<string> &args, bool& listening) string MainLoop::executeListen(vector<string> &args, bool& listening)
{ {
if (args.size() == 1) { if (args.size() == 1) {
if (listening == true) if (listening)
return "listen continued"; return "listen continued";
listening = true; listening = true;
@@ -525,7 +525,7 @@ string MainLoop::executeState(vector<string> &args)
return "usage: 'state'\n" return "usage: 'state'\n"
" Report bus state."; " Report bus state.";
if (m_busHandler->hasSignal() == true) { if (m_busHandler->hasSignal()) {
ostringstream result; ostringstream result;
result << "signal acquired, " result << "signal acquired, "
<< static_cast<unsigned>(m_busHandler->getSymbolRate()) << " symbols/sec, max. " << static_cast<unsigned>(m_busHandler->getSymbolRate()) << " symbols/sec, max. "
@@ -579,7 +579,7 @@ string MainLoop::executeLog(vector<string> &args)
" AREA the log area to include (main|network|bus|update|all)\n" " AREA the log area to include (main|network|bus|update|all)\n"
" LEVEL the log level to set (error|notice|info|debug)"; " LEVEL the log level to set (error|notice|info|debug)";
if (result == true) if (result)
return getResultCode(RESULT_OK); return getResultCode(RESULT_OK);
return getResultCode(RESULT_ERR_INVALID_ARG); return getResultCode(RESULT_ERR_INVALID_ARG);
+9 -9
View File
@@ -74,7 +74,7 @@ void Connection::run()
time_t listenSince = 0; time_t listenSince = 0;
bool closed = false; bool closed = false;
while (closed == false) { while (!closed) {
#ifdef HAVE_PPOLL #ifdef HAVE_PPOLL
// wait for new fd event // wait for new fd event
ret = ppoll(fds, nfds, &tdiff, NULL); ret = ppoll(fds, nfds, &tdiff, NULL);
@@ -109,12 +109,12 @@ void Connection::run()
#endif #endif
} }
if (newData == true || m_listening == true) { if (newData || m_listening) {
char data[256]; char data[256];
size_t datalen = 0; size_t datalen = 0;
if (newData == true) { if (newData) {
if (m_socket->isValid() == false) if (!m_socket->isValid())
break; break;
datalen = m_socket->recv(data, sizeof(data)-1); datalen = m_socket->recv(data, sizeof(data)-1);
@@ -133,7 +133,7 @@ void Connection::run()
logDebug(lf_network, "[%05d] wait for result", getID()); logDebug(lf_network, "[%05d] wait for result", getID());
string result = message.getResult(); string result = message.getResult();
if (m_socket->isValid() == false) if (!m_socket->isValid())
break; break;
m_socket->send(result.c_str(), result.size()); m_socket->send(result.c_str(), result.size());
@@ -154,7 +154,7 @@ void Connection::run()
Network::Network(const bool local, const int port, WQueue<NetMessage*>* netQueue) Network::Network(const bool local, const int port, WQueue<NetMessage*>* netQueue)
: m_netQueue(netQueue), m_listening(false) : m_netQueue(netQueue), m_listening(false)
{ {
if (local == true) if (local)
m_tcpServer = new TCPServer(port, "127.0.0.1"); m_tcpServer = new TCPServer(port, "127.0.0.1");
else else
m_tcpServer = new TCPServer(port, "0.0.0.0"); m_tcpServer = new TCPServer(port, "0.0.0.0");
@@ -168,7 +168,7 @@ Network::~Network()
{ {
stop(); stop();
while (m_connections.empty() == false) { while (!m_connections.empty()) {
Connection* connection = m_connections.back(); Connection* connection = m_connections.back();
m_connections.pop_back(); m_connections.pop_back();
connection->stop(); connection->stop();
@@ -183,7 +183,7 @@ Network::~Network()
void Network::run() void Network::run()
{ {
if (m_listening == false) if (!m_listening)
return; return;
int ret; int ret;
@@ -277,7 +277,7 @@ void Network::cleanConnections()
{ {
list<Connection*>::iterator c_it; list<Connection*>::iterator c_it;
for (c_it = m_connections.begin(); c_it != m_connections.end(); c_it++) { for (c_it = m_connections.begin(); c_it != m_connections.end(); c_it++) {
if ((*c_it)->isRunning() == false) { if (!(*c_it)->isRunning()) {
Connection* connection = *c_it; Connection* connection = *c_it;
c_it = m_connections.erase(c_it); c_it = m_connections.erase(c_it);
delete connection; delete connection;
+1 -1
View File
@@ -86,7 +86,7 @@ public:
{ {
pthread_mutex_lock(&m_mutex); pthread_mutex_lock(&m_mutex);
while (m_resultSet == false) while (!m_resultSet)
pthread_cond_wait(&m_cond, &m_mutex); pthread_cond_wait(&m_cond, &m_mutex);
pthread_mutex_unlock(&m_mutex); pthread_mutex_unlock(&m_mutex);
+54 -54
View File
@@ -119,7 +119,7 @@ void printErrorPos(vector<string>::iterator begin, const vector<string>::iterato
bool first = true; bool first = true;
int cnt = 0; int cnt = 0;
while (begin != end) { while (begin != end) {
if (first == true) if (first)
first = false; first = false;
else { else {
cout << FIELD_SEPARATOR; cout << FIELD_SEPARATOR;
@@ -166,22 +166,22 @@ result_t DataField::create(vector<string>::iterator& it,
if (it == end) if (it == end)
break; break;
if (isTemplate == true) if (isTemplate)
partType = pt_any; partType = pt_any;
else { else {
const char* partStr = (*it++).c_str(); const char* partStr = (*it++).c_str();
hasPartStr = partStr[0] != 0; hasPartStr = partStr[0] != 0;
if (it == end) { if (it == end) {
if (name.empty() == false || hasPartStr == true) if (!name.empty() || hasPartStr)
result = RESULT_ERR_MISSING_TYPE; result = RESULT_ERR_MISSING_TYPE;
break; break;
} }
if (dstAddress == BROADCAST || isMaster(dstAddress) == true if (dstAddress == BROADCAST || isMaster(dstAddress)
|| (isWriteMessage == true && hasPartStr == false) || (isWriteMessage && !hasPartStr)
|| strcasecmp(partStr, "M") == 0) { // master data || strcasecmp(partStr, "M") == 0) { // master data
partType = pt_masterData; partType = pt_masterData;
} }
else if ((isWriteMessage == false && hasPartStr == false) else if ((!isWriteMessage && !hasPartStr)
|| strcasecmp(partStr, "S") == 0) { // slave data || strcasecmp(partStr, "S") == 0) { // slave data
partType = pt_slaveData; partType = pt_slaveData;
} }
@@ -191,14 +191,14 @@ result_t DataField::create(vector<string>::iterator& it,
} }
} }
if (fields.empty() == true) { if (fields.empty()) {
firstName = name; firstName = name;
firstComment = comment; firstComment = comment;
} }
const string typeStr = *it++; const string typeStr = *it++;
if (typeStr.empty() == true) { if (typeStr.empty()) {
if (name.empty() == false || hasPartStr == true) if (!name.empty() || hasPartStr)
result = RESULT_ERR_MISSING_TYPE; result = RESULT_ERR_MISSING_TYPE;
break; break;
} }
@@ -206,7 +206,7 @@ result_t DataField::create(vector<string>::iterator& it,
map<unsigned int, string> values; map<unsigned int, string> values;
if (it != end) { if (it != end) {
const string divisorStr = *it++; const string divisorStr = *it++;
if (divisorStr.empty() == false) { if (!divisorStr.empty()) {
if (divisorStr.find('=') == string::npos) if (divisorStr.find('=') == string::npos)
divisor = parseInt(divisorStr.c_str(), 10, 1, 10000, result); divisor = parseInt(divisorStr.c_str(), 10, 1, 10000, result);
else { else {
@@ -265,7 +265,7 @@ result_t DataField::create(vector<string>::iterator& it,
while (result == RESULT_OK && getline(stream, token, VALUE_SEPARATOR) != 0) { while (result == RESULT_OK && getline(stream, token, VALUE_SEPARATOR) != 0) {
DataField* templ = templates->get(token); DataField* templ = templates->get(token);
if (templ == NULL) { if (templ == NULL) {
if (found == false) if (!found)
break; // fallback to direct definition break; // fallback to direct definition
result = RESULT_ERR_NOTFOUND; // cannot mix reference and direct definition result = RESULT_ERR_NOTFOUND; // cannot mix reference and direct definition
} }
@@ -276,7 +276,7 @@ result_t DataField::create(vector<string>::iterator& it,
} }
if (result != RESULT_OK) if (result != RESULT_OK)
break; break;
if (found == true) if (found)
continue; // go to next definition continue; // go to next definition
} }
typeName = typeStr; typeName = typeStr;
@@ -329,11 +329,11 @@ result_t DataField::create(vector<string>::iterator& it,
add = new StringDataField(name, comment, unit, *dataType, partType, byteCount); add = new StringDataField(name, comment, unit, *dataType, partType, byteCount);
break; break;
case bt_num: case bt_num:
if (values.empty() == true && (dataType->flags & DAY) != 0) { if (values.empty() && (dataType->flags & DAY) != 0) {
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++) for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
values[dataType->minValueOrLength + i] = dayNames[i]; values[dataType->minValueOrLength + i] = dayNames[i];
} }
if (values.empty() == true || (dataType->flags & LST) == 0) { if (values.empty() || (dataType->flags & LST) == 0) {
if (divisor == 0) if (divisor == 0)
divisor = 1; divisor = 1;
if ((dataType->bitCount % 8) == 0) if ((dataType->bitCount % 8) == 0)
@@ -361,7 +361,7 @@ result_t DataField::create(vector<string>::iterator& it,
} while (it != end && result == RESULT_OK); } while (it != end && result == RESULT_OK);
if (result != RESULT_OK) { if (result != RESULT_OK) {
while (fields.empty() == false) { // cleanup already created fields while (!fields.empty()) { // cleanup already created fields
delete fields.back(); delete fields.back();
fields.pop_back(); fields.pop_back();
} }
@@ -407,17 +407,17 @@ result_t SingleDataField::read(const PartType partType,
default: default:
return RESULT_ERR_INVALID_PART; return RESULT_ERR_INVALID_PART;
} }
if (isIgnored() == true || (filterName != NULL && m_name != filterName)) { if (isIgnored() || (filterName != NULL && m_name != filterName)) {
if (offset + m_length > data.size()) { if (offset + m_length > data.size()) {
return RESULT_ERR_INVALID_POS; return RESULT_ERR_INVALID_POS;
} }
return RESULT_EMPTY; return RESULT_EMPTY;
} }
if (leadingSeparator == true) if (leadingSeparator)
output << separator; output << separator;
if (verbose == true) if (verbose)
output << m_name << "="; output << m_name << "=";
result_t result = readSymbols(data, offset, output); result_t result = readSymbols(data, offset, output);
@@ -461,13 +461,13 @@ result_t StringDataField::derive(string name, string comment,
{ {
if (m_partType != pt_any && partType == pt_any) if (m_partType != pt_any && partType == pt_any)
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
if (divisor != 0 || values.empty() == false) if (divisor != 0 || !values.empty())
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
if (name.empty() == true) if (name.empty())
name = m_name; name = m_name;
if (comment.empty() == true) if (comment.empty())
comment = m_comment; comment = m_comment;
if (unit.empty() == true) if (unit.empty())
unit = m_unit; unit = m_unit;
fields.push_back(new StringDataField(name, comment, unit, m_dataType, partType, m_length)); fields.push_back(new StringDataField(name, comment, unit, m_dataType, partType, m_length));
@@ -590,7 +590,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
incr = -1; incr = -1;
} }
if (isIgnored() == true && (m_dataType.flags & REQ) == 0) { if (isIgnored() && (m_dataType.flags & REQ) == 0) {
for (size_t offset = start, i = 0; i < count; offset += incr, i++) { for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
output[baseOffset + offset] = m_dataType.replacement; // fill up with replacement output[baseOffset + offset] = m_dataType.replacement; // fill up with replacement
} }
@@ -602,17 +602,17 @@ result_t StringDataField::writeSymbols(istringstream& input,
switch (m_dataType.type) switch (m_dataType.type)
{ {
case bt_hexstr: case bt_hexstr:
while (input.eof() == false && input.peek() == ' ') while (!input.eof() && input.peek() == ' ')
input.get(); input.get();
if (input.eof() == true) // no more digits if (input.eof()) // no more digits
value = m_dataType.replacement; // fill up with replacement value = m_dataType.replacement; // fill up with replacement
else { else {
token.clear(); token.clear();
token.push_back(input.get()); token.push_back(input.get());
if (input.eof() == true) if (input.eof())
return RESULT_ERR_INVALID_NUM; // too short hex value return RESULT_ERR_INVALID_NUM; // too short hex value
token.push_back(input.get()); token.push_back(input.get());
if (input.eof() == true) if (input.eof())
return RESULT_ERR_INVALID_NUM; // too short hex value return RESULT_ERR_INVALID_NUM; // too short hex value
value = parseInt(token.c_str(), 16, 0, 0xff, result); value = parseInt(token.c_str(), 16, 0, 0xff, result);
@@ -623,7 +623,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
case bt_dat: case bt_dat:
if (m_length == 4 && i == 2) if (m_length == 4 && i == 2)
continue; // skip weekday in between continue; // skip weekday in between
if (input.eof() == true || getline(input, token, '.') == 0) if (input.eof() || getline(input, token, '.') == 0)
return RESULT_ERR_EOF; // incomplete return RESULT_ERR_EOF; // incomplete
if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) { if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) {
value = m_dataType.replacement; value = m_dataType.replacement;
@@ -659,7 +659,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
return RESULT_ERR_OUT_OF_RANGE; // invalid date part return RESULT_ERR_OUT_OF_RANGE; // invalid date part
break; break;
case bt_tim: case bt_tim:
if (input.eof() == true || getline(input, token, LENGTH_SEPARATOR) == 0) if (input.eof() || getline(input, token, LENGTH_SEPARATOR) == 0)
return RESULT_ERR_EOF; // incomplete return RESULT_ERR_EOF; // incomplete
if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) { if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) {
value = m_dataType.replacement; value = m_dataType.replacement;
@@ -695,11 +695,11 @@ result_t StringDataField::writeSymbols(istringstream& input,
} }
break; break;
default: default:
if (input.eof() == true) if (input.eof())
value = m_dataType.replacement; value = m_dataType.replacement;
else { else {
value = input.get(); value = input.get();
if (input.eof() == true || value < 0x20) if (input.eof() || value < 0x20)
value = m_dataType.replacement; value = m_dataType.replacement;
} }
break; break;
@@ -726,7 +726,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
bool NumericDataField::hasFullByteOffset(bool after) bool NumericDataField::hasFullByteOffset(bool after)
{ {
return m_length > 1 || (m_bitCount % 8) == 0 return m_length > 1 || (m_bitCount % 8) == 0
|| (after == true && m_bitOffset + (m_bitCount % 8) >= 8); || (after && m_bitOffset + (m_bitCount % 8) >= 8);
} }
void NumericDataField::dump(ostream& output) void NumericDataField::dump(ostream& output)
@@ -848,17 +848,17 @@ result_t NumberDataField::derive(string name, string comment,
{ {
if (m_partType != pt_any && partType == pt_any) if (m_partType != pt_any && partType == pt_any)
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
if (name.empty() == true) if (name.empty())
name = m_name; name = m_name;
if (comment.empty() == true) if (comment.empty())
comment = m_comment; comment = m_comment;
if (unit.empty() == true) if (unit.empty())
unit = m_unit; unit = m_unit;
if (divisor == 0) if (divisor == 0)
divisor = m_divisor; divisor = m_divisor;
else if ((m_dataType.bitCount % 8) == 0) else if ((m_dataType.bitCount % 8) == 0)
divisor *= m_dataType.divisorOrFirstBit; divisor *= m_dataType.divisorOrFirstBit;
if (values.empty() == false) { if (!values.empty()) {
if (divisor != 1) if (divisor != 1)
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
@@ -896,7 +896,7 @@ result_t NumberDataField::readSymbols(SymbolString& input,
bool negative = (m_dataType.flags & SIG) != 0 && (value & (1 << (m_bitCount - 1))) != 0; bool negative = (m_dataType.flags & SIG) != 0 && (value & (1 << (m_bitCount - 1))) != 0;
if (m_bitCount == 32) { if (m_bitCount == 32) {
if (negative == false) { if (!negative) {
if (m_divisor <= 1) if (m_divisor <= 1)
output << static_cast<unsigned>(value); output << static_cast<unsigned>(value);
else else
@@ -906,7 +906,7 @@ result_t NumberDataField::readSymbols(SymbolString& input,
} }
signedValue = (int) value; // negative signed value signedValue = (int) value; // negative signed value
} }
else if (negative == true) // negative signed value else if (negative) // negative signed value
signedValue = (int) value - (1 << m_bitCount); signedValue = (int) value - (1 << m_bitCount);
else else
signedValue = (int) value; signedValue = (int) value;
@@ -929,7 +929,7 @@ result_t NumberDataField::writeSymbols(istringstream& input,
unsigned int value; unsigned int value;
const char* str = input.str().c_str(); const char* str = input.str().c_str();
if ((m_dataType.flags & REQ) == 0 && (isIgnored() == true || strcasecmp(str, NULL_VALUE) == 0)) if ((m_dataType.flags & REQ) == 0 && (isIgnored() || strcasecmp(str, NULL_VALUE) == 0))
value = m_dataType.replacement; // replacement value value = m_dataType.replacement; // replacement value
else if (str == NULL || *str == 0) else if (str == NULL || *str == 0)
return RESULT_ERR_EOF; // input too short return RESULT_ERR_EOF; // input too short
@@ -992,16 +992,16 @@ result_t ValueListDataField::derive(string name, string comment,
{ {
if (m_partType != pt_any && partType == pt_any) if (m_partType != pt_any && partType == pt_any)
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
if (name.empty() == true) if (name.empty())
name = m_name; name = m_name;
if (comment.empty() == true) if (comment.empty())
comment = m_comment; comment = m_comment;
if (unit.empty() == true) if (unit.empty())
unit = m_unit; unit = m_unit;
if (divisor != 0 && divisor != 1) if (divisor != 0 && divisor != 1)
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
if (values.empty() == false) { if (!values.empty()) {
if (values.begin()->first < m_dataType.minValueOrLength if (values.begin()->first < m_dataType.minValueOrLength
|| values.rbegin()->first > m_dataType.maxValueOrLength) || values.rbegin()->first > m_dataType.maxValueOrLength)
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
@@ -1019,7 +1019,7 @@ void ValueListDataField::dump(ostream& output)
NumericDataField::dump(output); NumericDataField::dump(output);
bool first = true; bool first = true;
for (map<unsigned int, string>::iterator it = m_values.begin(); it != m_values.end(); it++) { for (map<unsigned int, string>::iterator it = m_values.begin(); it != m_values.end(); it++) {
if (first == true) if (first)
first = false; first = false;
else else
output << VALUE_SEPARATOR; output << VALUE_SEPARATOR;
@@ -1057,7 +1057,7 @@ result_t ValueListDataField::readSymbols(SymbolString& input,
result_t ValueListDataField::writeSymbols(istringstream& input, result_t ValueListDataField::writeSymbols(istringstream& input,
unsigned char baseOffset, SymbolString& output) unsigned char baseOffset, SymbolString& output)
{ {
if (isIgnored() == true) if (isIgnored())
return writeRawValue(m_dataType.replacement, baseOffset, output); // replacement value return writeRawValue(m_dataType.replacement, baseOffset, output); // replacement value
const char* str = input.str().c_str(); const char* str = input.str().c_str();
@@ -1110,7 +1110,7 @@ DataFieldSet* DataFieldSet::createIdentFields()
DataFieldSet::~DataFieldSet() DataFieldSet::~DataFieldSet()
{ {
while (m_fields.empty() == false) { while (!m_fields.empty()) {
delete m_fields.back(); delete m_fields.back();
m_fields.pop_back(); m_fields.pop_back();
} }
@@ -1125,7 +1125,7 @@ unsigned char DataFieldSet::getLength(PartType partType)
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) { for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it; SingleDataField* field = *it;
if (field->getPartType() == partType) { if (field->getPartType() == partType) {
if (previousFullByteOffset[partType] == false && field->hasFullByteOffset(false) == false) if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false))
length--; length--;
length += field->getLength(partType); length += field->getLength(partType);
@@ -1142,7 +1142,7 @@ result_t DataFieldSet::derive(string name, string comment,
unsigned int divisor, map<unsigned int, string> values, unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields) vector<SingleDataField*>& fields)
{ {
if (values.empty() == false) if (!values.empty())
return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) { for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
@@ -1172,7 +1172,7 @@ result_t DataFieldSet::read(const PartType partType,
if (partType != pt_any && field->getPartType() != partType) if (partType != pt_any && field->getPartType() != partType)
continue; continue;
if (previousFullByteOffset == false && field->hasFullByteOffset(false) == false) if (!previousFullByteOffset && !field->hasFullByteOffset(false))
offset--; offset--;
result_t result = field->read(partType, data, offset, output, leadingSeparator, verbose, filterName, separator); result_t result = field->read(partType, data, offset, output, leadingSeparator, verbose, filterName, separator);
@@ -1188,12 +1188,12 @@ result_t DataFieldSet::read(const PartType partType,
} }
} }
if (verbose == true) { if (verbose) {
if (m_comment.length() > 0) if (m_comment.length() > 0)
output << " [" << m_comment << "]"; output << " [" << m_comment << "]";
} }
return found == true ? RESULT_OK : RESULT_EMPTY; return found ? RESULT_OK : RESULT_EMPTY;
} }
result_t DataFieldSet::write(istringstream& input, result_t DataFieldSet::write(istringstream& input,
@@ -1208,12 +1208,12 @@ result_t DataFieldSet::write(istringstream& input,
if (partType != pt_any && field->getPartType() != partType) if (partType != pt_any && field->getPartType() != partType)
continue; continue;
if (previousFullByteOffset == false && field->hasFullByteOffset(false) == false) if (!previousFullByteOffset && !field->hasFullByteOffset(false))
offset--; offset--;
result_t result; result_t result;
if (m_fields.size() > 1) { if (m_fields.size() > 1) {
if (field->isIgnored() == true) if (field->isIgnored())
token.clear(); token.clear();
else if (getline(input, token, separator) == 0) else if (getline(input, token, separator) == 0)
token.clear(); token.clear();
@@ -1249,7 +1249,7 @@ result_t DataFieldTemplates::add(DataField* field, bool replace)
string name = field->getName(); string name = field->getName();
map<string, DataField*>::iterator it = m_fieldsByName.find(name); map<string, DataField*>::iterator it = m_fieldsByName.find(name);
if (it != m_fieldsByName.end()) { if (it != m_fieldsByName.end()) {
if (replace == false) if (!replace)
return RESULT_ERR_DUPLICATE; // duplicate key return RESULT_ERR_DUPLICATE; // duplicate key
delete it->second; delete it->second;
+8 -8
View File
@@ -87,7 +87,7 @@ bool Device::isValid()
if (m_fd == -1) if (m_fd == -1)
return false; return false;
if (m_checkDevice == true) if (m_checkDevice)
checkDevice(); checkDevice();
return m_fd != -1; return m_fd != -1;
@@ -95,13 +95,13 @@ bool Device::isValid()
result_t Device::send(const unsigned char value) result_t Device::send(const unsigned char value)
{ {
if (isValid() == false) if (!isValid())
return RESULT_ERR_DEVICE; return RESULT_ERR_DEVICE;
if (write(m_fd, &value, 1) != 1) if (write(m_fd, &value, 1) != 1)
return RESULT_ERR_SEND; return RESULT_ERR_SEND;
if (m_logRaw == true && m_logRawFunc != NULL) if (m_logRaw && m_logRawFunc != NULL)
(*m_logRawFunc)(value, false); (*m_logRawFunc)(value, false);
return RESULT_OK; return RESULT_OK;
@@ -109,7 +109,7 @@ result_t Device::send(const unsigned char value)
result_t Device::recv(const long timeout, unsigned char& value) result_t Device::recv(const long timeout, unsigned char& value)
{ {
if (isValid() == false) if (!isValid())
return RESULT_ERR_DEVICE; return RESULT_ERR_DEVICE;
if (timeout > 0) { if (timeout > 0) {
@@ -153,10 +153,10 @@ result_t Device::recv(const long timeout, unsigned char& value)
if (nbytes < 0) if (nbytes < 0)
return RESULT_ERR_DEVICE; return RESULT_ERR_DEVICE;
if (m_logRaw == true && m_logRawFunc != NULL) if (m_logRaw && m_logRawFunc != NULL)
(*m_logRawFunc)(value, true); (*m_logRawFunc)(value, true);
if (m_dumpRaw == true && m_dumpRawStream.is_open() == true) { if (m_dumpRaw && m_dumpRawStream.is_open()) {
m_dumpRawStream.write((char*)&value, 1); m_dumpRawStream.write((char*)&value, 1);
m_dumpRawFileSize++; m_dumpRawFileSize++;
if ((m_dumpRawFileSize%1024) == 0) if ((m_dumpRawFileSize%1024) == 0)
@@ -182,7 +182,7 @@ void Device::setDumpRaw(bool dumpRaw)
m_dumpRaw = dumpRaw; m_dumpRaw = dumpRaw;
if (dumpRaw == false || m_dumpRawFile == NULL) if (!dumpRaw || m_dumpRawFile == NULL)
m_dumpRawStream.close(); m_dumpRawStream.close();
else { else {
m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app); m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app);
@@ -197,7 +197,7 @@ void Device::setDumpRawFile(const char* dumpFile) {
m_dumpRawStream.close(); m_dumpRawStream.close();
m_dumpRawFile = dumpFile; m_dumpRawFile = dumpFile;
if (m_dumpRaw == true && m_dumpRawFile != NULL) { if (m_dumpRaw && m_dumpRawFile != NULL) {
m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app); m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app);
m_dumpRawFileSize = 0; m_dumpRawFileSize = 0;
} }
+5 -5
View File
@@ -72,7 +72,7 @@ public:
{ {
ifstream ifs; ifstream ifs;
ifs.open(filename.c_str(), ifstream::in); ifs.open(filename.c_str(), ifstream::in);
if (ifs.is_open() == false) if (!ifs.is_open())
return RESULT_ERR_NOTFOUND; return RESULT_ERR_NOTFOUND;
string line; string line;
@@ -96,7 +96,7 @@ public:
switch (ch) switch (ch)
{ {
case FIELD_SEPARATOR: case FIELD_SEPARATOR:
if (quotedText == true) if (quotedText)
field << ch; field << ch;
else { else {
row.push_back(field.str()); row.push_back(field.str());
@@ -104,7 +104,7 @@ public:
} }
break; break;
case TEXT_SEPARATOR: case TEXT_SEPARATOR:
if (quotedText == true) { if (quotedText) {
quotedText = false; quotedText = false;
} }
else if (prev == TEXT_SEPARATOR) { // double dquote else if (prev == TEXT_SEPARATOR) { // double dquote
@@ -130,7 +130,7 @@ public:
result_t result; result_t result;
vector<string>::iterator it = row.begin(); vector<string>::iterator it = row.begin();
const vector<string>::iterator end = row.end(); const vector<string>::iterator end = row.end();
if (m_supportsDefaults == true) { if (m_supportsDefaults) {
if (line[0] == '*') { if (line[0] == '*') {
row[0] = row[0].substr(1); row[0] = row[0].substr(1);
defaults.push_back(row); defaults.push_back(row);
@@ -142,7 +142,7 @@ public:
result = addFromFile(it, end, arg, NULL, filename, lineNo); result = addFromFile(it, end, arg, NULL, filename, lineNo);
if (result != RESULT_OK) { if (result != RESULT_OK) {
if (verbose == false) { if (!verbose) {
ifs.close(); ifs.close();
return result; return result;
} }
+19 -19
View File
@@ -45,7 +45,7 @@ Message::Message(const string clazz, const string name, const bool isWrite,
{ {
int exp = 7; int exp = 7;
unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5); unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5);
if (isPassive == true) if (isPassive)
key |= (unsigned long long)getMasterNumber(srcAddress) << (8 * exp--); // 0..25 key |= (unsigned long long)getMasterNumber(srcAddress) << (8 * exp--); // 0..25
else else
key |= 0x1fLL << (8 * exp--); // special value for active key |= 0x1fLL << (8 * exp--); // special value for active
@@ -159,7 +159,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
srcAddress = parseInt(str, 16, 0, 0xff, result); srcAddress = parseInt(str, 16, 0, 0xff, result);
if (result != RESULT_OK) if (result != RESULT_OK)
return result; return result;
if (isMaster(srcAddress) == false) if (!isMaster(srcAddress))
return RESULT_ERR_INVALID_ADDR; return RESULT_ERR_INVALID_ADDR;
} }
@@ -173,7 +173,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
dstAddress = parseInt(str, 16, 0, 0xff, result); dstAddress = parseInt(str, 16, 0, 0xff, result);
if (result != RESULT_OK) if (result != RESULT_OK)
return result; return result;
if (isValidAddress(dstAddress) == false) if (!isValidAddress(dstAddress))
return RESULT_ERR_INVALID_ADDR; return RESULT_ERR_INVALID_ADDR;
} }
@@ -190,14 +190,14 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
istringstream input(token); istringstream input(token);
if (it == end) if (it == end)
return RESULT_ERR_EOF; return RESULT_ERR_EOF;
while (input.eof() == false) { while (!input.eof()) {
while (input.peek() == ' ') while (input.peek() == ' ')
input.get(); input.get();
if (input.eof() == true) // no more digits if (input.eof()) // no more digits
break; break;
token.clear(); token.clear();
token.push_back(input.get()); token.push_back(input.get());
if (input.eof() == true) { if (input.eof()) {
return RESULT_ERR_INVALID_ARG; // too short hex return RESULT_ERR_INVALID_ARG; // too short hex
} }
token.push_back(input.get()); token.push_back(input.get());
@@ -249,7 +249,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& masterData, istringstream& input, char separator, const unsigned char dstAddress) result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& masterData, istringstream& input, char separator, const unsigned char dstAddress)
{ {
if (m_isPassive == true) if (m_isPassive)
return RESULT_ERR_INVALID_ARG; // prepare not possible return RESULT_ERR_INVALID_ARG; // prepare not possible
SymbolString master(false); SymbolString master(false);
@@ -289,7 +289,7 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
result_t Message::prepareSlave(SymbolString& slaveData) result_t Message::prepareSlave(SymbolString& slaveData)
{ {
if (m_isPassive == false || m_isWrite == true) if (!m_isPassive || m_isWrite)
return RESULT_ERR_INVALID_ARG; // prepare not possible return RESULT_ERR_INVALID_ARG; // prepare not possible
SymbolString slave(false); SymbolString slave(false);
@@ -398,7 +398,7 @@ result_t MessageMap::add(Message* message)
m_messagesByName[nameKey] = message; m_messagesByName[nameKey] = message;
m_messageCount++; m_messageCount++;
if (isPassive == true) if (isPassive)
m_passiveMessageCount++; m_passiveMessageCount++;
nameKey = string(isPassive ? "-P" : (isWrite ? "-W" : "-R")) + name; // also store without class nameKey = string(isPassive ? "-P" : (isWrite ? "-W" : "-R")) + name; // also store without class
@@ -483,28 +483,28 @@ deque<Message*> MessageMap::findAll(const string& clazz, const string& name, con
if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-" if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-"
continue; continue;
Message* message = it->second; Message* message = it->second;
if (checkClass == true) { if (checkClass) {
string check = strtolower(message->getClass()); string check = strtolower(message->getClass());
if (completeMatch ? (check != lclass) : (check.find(lclass) == check.npos)) if (completeMatch ? (check != lclass) : (check.find(lclass) == check.npos))
continue; continue;
} }
if (checkName == true) { if (checkName) {
string check = strtolower(message->getName()); string check = strtolower(message->getName());
if (completeMatch ? (check != lname) : (check.find(lname) == check.npos)) if (completeMatch ? (check != lname) : (check.find(lname) == check.npos))
continue; continue;
} }
if (checkPb == true && message->getId()[0] != pb) if (checkPb && message->getId()[0] != pb)
continue; continue;
if (message->isPassive() == true) { if (message->isPassive()) {
if (withPassive == false) if (!withPassive)
continue; continue;
} }
else if (message->isWrite() == true) { else if (message->isWrite()) {
if (withWrite == false) if (!withWrite)
continue; continue;
} }
else { else {
if (withRead == false) if (!withRead)
continue; continue;
} }
ret.push_back(message); ret.push_back(message);
@@ -556,7 +556,7 @@ Message* MessageMap::find(SymbolString& master)
void MessageMap::clear() void MessageMap::clear()
{ {
// clear poll messages // clear poll messages
while (m_pollMessages.empty() == false) { while (!m_pollMessages.empty()) {
m_pollMessages.top(); m_pollMessages.top();
m_pollMessages.pop(); m_pollMessages.pop();
} }
@@ -578,7 +578,7 @@ void MessageMap::clear()
Message* MessageMap::getNextPoll() Message* MessageMap::getNextPoll()
{ {
if (m_pollMessages.empty() == true) if (m_pollMessages.empty())
return NULL; return NULL;
Message* ret = m_pollMessages.top(); Message* ret = m_pollMessages.top();
m_pollMessages.pop(); m_pollMessages.pop();
+13 -13
View File
@@ -86,7 +86,7 @@ const string SymbolString::getDataStr(const bool unescape)
for (size_t i = 0; i < m_data.size(); i++) { for (size_t i = 0; i < m_data.size(); i++) {
unsigned char value = m_data[i]; unsigned char value = m_data[i];
if (m_unescapeState == 0 && unescape == true && previousEscape == true) { if (m_unescapeState == 0 && unescape && previousEscape) {
if (value == 0x00) if (value == 0x00)
sstr << "a9"; // ESC sstr << "a9"; // ESC
else if (value == 0x01) else if (value == 0x01)
@@ -96,7 +96,7 @@ const string SymbolString::getDataStr(const bool unescape)
previousEscape = false; previousEscape = false;
} }
else if (m_unescapeState == 0 && unescape == true && value == ESC) { else if (m_unescapeState == 0 && unescape && value == ESC) {
previousEscape = true; // escape sequence not yet finished previousEscape = true; // escape sequence not yet finished
} }
else { else {
@@ -111,35 +111,35 @@ const string SymbolString::getDataStr(const bool unescape)
result_t SymbolString::push_back(const unsigned char value, const bool isEscaped, const bool updateCRC) result_t SymbolString::push_back(const unsigned char value, const bool isEscaped, const bool updateCRC)
{ {
if (m_unescapeState == 0) { // store escaped data if (m_unescapeState == 0) { // store escaped data
if (isEscaped == false && value == ESC) { if (!isEscaped && value == ESC) {
m_data.push_back(ESC); m_data.push_back(ESC);
m_data.push_back(0x00); m_data.push_back(0x00);
if (updateCRC == true) { if (updateCRC) {
addCRC(ESC); addCRC(ESC);
addCRC(0x00); addCRC(0x00);
} }
} }
else if (isEscaped == false && value == SYN) { else if (!isEscaped && value == SYN) {
m_data.push_back(ESC); m_data.push_back(ESC);
m_data.push_back(0x01); m_data.push_back(0x01);
if (updateCRC == true) { if (updateCRC) {
addCRC(ESC); addCRC(ESC);
addCRC(0x01); addCRC(0x01);
} }
} }
else { else {
m_data.push_back(value); m_data.push_back(value);
if (updateCRC == true) if (updateCRC)
addCRC(value); addCRC(value);
} }
return RESULT_OK; return RESULT_OK;
} }
else if (isEscaped == false) { else if (!isEscaped) {
if (m_unescapeState != 1) if (m_unescapeState != 1)
return RESULT_ERR_ESC; // invalid unescape state return RESULT_ERR_ESC; // invalid unescape state
m_data.push_back(value); m_data.push_back(value);
if (updateCRC == true) { if (updateCRC) {
if (value == ESC) { if (value == ESC) {
addCRC(ESC); addCRC(ESC);
addCRC(0x00); addCRC(0x00);
@@ -155,7 +155,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
return RESULT_OK; return RESULT_OK;
} }
else if (m_unescapeState != 1) { else if (m_unescapeState != 1) {
if (updateCRC == true) if (updateCRC)
addCRC(value); addCRC(value);
if (value == 0x00) { if (value == 0x00) {
@@ -171,13 +171,13 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
return RESULT_ERR_ESC; // invalid escape sequence return RESULT_ERR_ESC; // invalid escape sequence
} }
else if (value == ESC) { else if (value == ESC) {
if (updateCRC == true) if (updateCRC)
addCRC(value); addCRC(value);
m_unescapeState = 2; m_unescapeState = 2;
return RESULT_IN_ESC; return RESULT_IN_ESC;
} }
if (updateCRC == true) if (updateCRC)
addCRC(value); addCRC(value);
m_data.push_back(value); m_data.push_back(value);
@@ -242,6 +242,6 @@ unsigned char getMasterNumber(unsigned char addr) {
} }
bool isValidAddress(unsigned char addr, bool allowBroadcast) { bool isValidAddress(unsigned char addr, bool allowBroadcast) {
return addr != SYN && addr != ESC && (allowBroadcast == true || addr != BROADCAST); return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST);
} }
+1 -1
View File
@@ -48,7 +48,7 @@ public:
* Creates a new empty escaped or unescaped instance. * Creates a new empty escaped or unescaped instance.
* @param escaped whether to create an escaped instance. * @param escaped whether to create an escaped instance.
*/ */
SymbolString(const bool escaped=true) : m_unescapeState(escaped == true ? 0 : 1), m_crc(0) {} SymbolString(const bool escaped=true) : m_unescapeState(escaped ? 0 : 1), m_crc(0) {}
/** /**
* Add all symbols from the other @a SymbolString and the calculated CRC if escaped. * Add all symbols from the other @a SymbolString and the calculated CRC if escaped.
+8 -8
View File
@@ -26,14 +26,14 @@ using namespace std;
void verify(bool expectFailMatch, string type, string input, void verify(bool expectFailMatch, string type, string input,
bool match, string expectStr, string gotStr) bool match, string expectStr, string gotStr)
{ {
if (expectFailMatch == true) { if (expectFailMatch) {
if (match == true) if (match)
cout << " failed " << type << " match >" << input cout << " failed " << type << " match >" << input
<< "< error: unexpectedly succeeded" << endl; << "< error: unexpectedly succeeded" << endl;
else else
cout << " failed " << type << " match >" << input << "< OK" << endl; cout << " failed " << type << " match >" << input << "< OK" << endl;
} }
else if (match == true) else if (match)
cout << " " << type << " match >" << input << "< OK" << endl; cout << " " << type << " match >" << input << "< OK" << endl;
else else
cout << " " << type << " match >" << input << "< error: got >" cout << " " << type << " match >" << input << "< error: got >"
@@ -248,7 +248,7 @@ int main()
} }
vector<string>::iterator it = entries.begin(); vector<string>::iterator it = entries.begin();
result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]); result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]);
if (failedCreate == true) { if (failedCreate) {
if (result == RESULT_OK) if (result == RESULT_OK)
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl; cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
else else
@@ -294,9 +294,9 @@ int main()
} }
result = fields->read(pt_masterData, mstr, 0, output, false, verbose); result = fields->read(pt_masterData, mstr, 0, output, false, verbose);
if (result >= RESULT_OK) { if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, output.str().empty() == false, verbose); result = fields->read(pt_slaveData, sstr, 0, output, !output.str().empty(), verbose);
} }
if (failedRead == true) if (failedRead)
if (result >= RESULT_OK) if (result >= RESULT_OK)
cout << " failed read " << fields->getName() << " >" cout << " failed read " << fields->getName() << " >"
<< check[2] << "< error: unexpectedly succeeded" << endl; << check[2] << "< error: unexpectedly succeeded" << endl;
@@ -312,12 +312,12 @@ int main()
verify(failedReadMatch, "read", check[2], match, expectStr, output.str()); verify(failedReadMatch, "read", check[2], match, expectStr, output.str());
} }
if (verbose == false) { if (!verbose) {
istringstream input(expectStr); istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0); result = fields->write(input, pt_masterData, writeMstr, 0);
if (result >= RESULT_OK) if (result >= RESULT_OK)
result = fields->write(input, pt_slaveData, writeSstr, 0); result = fields->write(input, pt_slaveData, writeSstr, 0);
if (failedWrite == true) { if (failedWrite) {
if (result >= RESULT_OK) if (result >= RESULT_OK)
cout << " failed write " << fields->getName() << " >" cout << " failed write " << fields->getName() << " >"
<< expectStr << "< error: unexpectedly succeeded" << endl; << expectStr << "< error: unexpectedly succeeded" << endl;
+2 -2
View File
@@ -34,7 +34,7 @@ int main ()
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "open failed: " << getResultCode(result) << endl; cout << "open failed: " << getResultCode(result) << endl;
} else { } else {
if (device->isValid() == false) if (!device->isValid())
cout << "device not available." << endl; cout << "device not available." << endl;
int count = 0; int count = 0;
@@ -52,7 +52,7 @@ int main ()
device->close(); device->close();
if(device->isValid() == false) if (!device->isValid())
cout << "close successful." << endl; cout << "close successful." << endl;
} }
+9 -9
View File
@@ -27,14 +27,14 @@ using namespace std;
void verify(bool expectFailMatch, string type, string input, void verify(bool expectFailMatch, string type, string input,
bool match, string expectStr, string gotStr) bool match, string expectStr, string gotStr)
{ {
if (expectFailMatch == true) { if (expectFailMatch) {
if (match == true) if (match)
cout << " failed " << type << " match >" << input cout << " failed " << type << " match >" << input
<< "< error: unexpectedly succeeded" << endl; << "< error: unexpectedly succeeded" << endl;
else else
cout << " failed " << type << " match >" << input << "< OK" << endl; cout << " failed " << type << " match >" << input << "< OK" << endl;
} }
else if (match == true) else if (match)
cout << " " << type << " match >" << input << "< OK" << endl; cout << " " << type << " match >" << input << "< OK" << endl;
else else
cout << " " << type << " match >" << input << "< error: got >" cout << " " << type << " match >" << input << "< error: got >"
@@ -104,7 +104,7 @@ int main()
delete deleteMessage; delete deleteMessage;
deleteMessage = NULL; deleteMessage = NULL;
} }
if (isTemplate == true) { if (isTemplate) {
// store new template // store new template
DataField* fields = NULL; DataField* fields = NULL;
vector<string>::iterator it = entries.begin(); vector<string>::iterator it = entries.begin();
@@ -136,7 +136,7 @@ int main()
else { else {
vector<string>::iterator it = entries.begin(); vector<string>::iterator it = entries.begin();
result = Message::create(it, entries.end(), NULL, templates, deleteMessage); result = Message::create(it, entries.end(), NULL, templates, deleteMessage);
if (failedCreate == true) { if (failedCreate) {
if (result == RESULT_OK) if (result == RESULT_OK)
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl; cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
else else
@@ -158,7 +158,7 @@ int main()
continue; continue;
} }
cout << "\"" << check[0] << "\": create OK" << endl; cout << "\"" << check[0] << "\": create OK" << endl;
if (dontMap == false) { if (!dontMap) {
result_t result = messages->add(deleteMessage); result_t result = messages->add(deleteMessage);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": add error: " cout << "\"" << check[0] << "\": add error: "
@@ -168,7 +168,7 @@ int main()
cout << " map OK" << endl; cout << " map OK" << endl;
message = deleteMessage; message = deleteMessage;
deleteMessage = NULL; deleteMessage = NULL;
if (onlyMap == true) if (onlyMap)
continue; continue;
Message* foundMessage = messages->find(mstr); Message* foundMessage = messages->find(mstr);
if (foundMessage == message) if (foundMessage == message)
@@ -182,7 +182,7 @@ int main()
message = deleteMessage; message = deleteMessage;
} }
if (message->isPassive() == true || decode == true) { if (message->isPassive() || decode) {
ostringstream output; ostringstream output;
result = message->decode(mstr, sstr, output); result = message->decode(mstr, sstr, output);
if (result != RESULT_OK) { if (result != RESULT_OK) {
@@ -199,7 +199,7 @@ int main()
istringstream input(inputStr); istringstream input(inputStr);
SymbolString writeMstr; SymbolString writeMstr;
result = message->prepareMaster(0xff, writeMstr, input); result = message->prepareMaster(0xff, writeMstr, input);
if (failedPrepare == true) { if (failedPrepare) {
if (result == RESULT_OK) if (result == RESULT_OK)
cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl; cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl;
else else
+2 -2
View File
@@ -82,7 +82,7 @@ TCPSocket* TCPClient::connect(const string& server, const int& port)
int TCPServer::start() int TCPServer::start()
{ {
if (m_listening == true) if (m_listening)
return 0; return 0;
m_lfd = socket(AF_INET, SOCK_STREAM, 0); m_lfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -115,7 +115,7 @@ int TCPServer::start()
TCPSocket* TCPServer::newSocket() TCPSocket* TCPServer::newSocket()
{ {
if (m_listening == false) if (!m_listening)
return NULL; return NULL;
struct sockaddr_in address; struct sockaddr_in address;
+5 -4
View File
@@ -32,11 +32,12 @@ void* Thread::runThread(void* arg)
Thread::~Thread() Thread::~Thread()
{ {
if (m_started == true) if (m_started) {
pthread_detach(m_threadid); pthread_detach(m_threadid);
}
if (m_started == true) if (m_started) {
pthread_cancel(m_threadid); pthread_cancel(m_threadid);
}
} }
bool Thread::start(const char* name) bool Thread::start(const char* name)
@@ -62,7 +63,7 @@ bool Thread::join()
{ {
int result = -1; int result = -1;
if (m_started == true) { if (m_started) {
m_stopped = true; m_stopped = true;
result = pthread_join(m_threadid, NULL); result = pthread_join(m_threadid, NULL);
+1 -1
View File
@@ -53,7 +53,7 @@ public:
* Return whether this @a Thread is still running and not yet stopped. * Return whether this @a Thread is still running and not yet stopped.
* @return true if this @a Thread is till running and not yet stopped. * @return true if this @a Thread is till running and not yet stopped.
*/ */
virtual bool isRunning() { return m_running == true && m_stopped == false; } virtual bool isRunning() { return m_running && !m_stopped; }
/** /**
* Create the native thread and set its name. * Create the native thread and set its name.
+2 -2
View File
@@ -87,7 +87,7 @@ public:
pthread_mutex_lock(&m_mutex); pthread_mutex_lock(&m_mutex);
T item; T item;
if (wait == true) { if (wait) {
while (m_queue.size() == 0) while (m_queue.size() == 0)
pthread_cond_wait(&m_cond, &m_mutex); pthread_cond_wait(&m_cond, &m_mutex);
item = m_queue.front(); item = m_queue.front();
@@ -157,7 +157,7 @@ public:
pthread_mutex_lock(&m_mutex); pthread_mutex_lock(&m_mutex);
T item; T item;
if (wait == true) { if (wait) {
while (m_queue.size() == 0) while (m_queue.size() == 0)
pthread_cond_wait(&m_cond, &m_mutex); pthread_cond_wait(&m_cond, &m_mutex);
item = m_queue.front(); item = m_queue.front();
+7 -7
View File
@@ -189,8 +189,8 @@ string fetchData(TCPSocket* socket, bool& listening)
#endif #endif
} }
if (newData == true) { if (newData) {
if (socket->isValid() == true) { if (socket->isValid()) {
datalen = socket->recv(data, sizeof(data)); datalen = socket->recv(data, sizeof(data));
if (datalen < 0) { if (datalen < 0) {
@@ -204,14 +204,14 @@ string fetchData(TCPSocket* socket, bool& listening)
if ((ss.str().length() >= 2 if ((ss.str().length() >= 2
&& ss.str()[ss.str().length()-2] == '\n' && ss.str()[ss.str().length()-2] == '\n'
&& ss.str()[ss.str().length()-1] == '\n') && ss.str()[ss.str().length()-1] == '\n')
|| listening == true) || listening)
break; break;
} }
else else
break; break;
} }
else if (newInput == true) { else if (newInput) {
getline(cin, message); getline(cin, message);
message += '\n'; message += '\n';
@@ -242,7 +242,7 @@ void connect(const char* host, int port, char* const *args, int argCount)
string message; string message;
bool listening = false; bool listening = false;
if (once == false) { if (!once) {
cout << host << ": "; cout << host << ": ";
getline(cin, message); getline(cin, message);
} }
@@ -270,7 +270,7 @@ void connect(const char* host, int port, char* const *args, int argCount)
if (strcasecmp(message.c_str(), "L") == 0 if (strcasecmp(message.c_str(), "L") == 0
|| strcasecmp(message.c_str(), "LISTEN") == 0) { || strcasecmp(message.c_str(), "LISTEN") == 0) {
listening = true; listening = true;
while (listening && cin.eof() == false) { while (listening && !cin.eof()) {
string result(fetchData(socket, listening)); string result(fetchData(socket, listening));
cout << result; cout << result;
if (strcasecmp(result.c_str(), "LISTEN STOPPED") == 0) if (strcasecmp(result.c_str(), "LISTEN STOPPED") == 0)
@@ -281,7 +281,7 @@ void connect(const char* host, int port, char* const *args, int argCount)
cout << fetchData(socket, listening); cout << fetchData(socket, listening);
} }
} while (once == false && cin.eof() == false); } while (!once && !cin.eof());
delete socket; delete socket;
+3 -3
View File
@@ -140,18 +140,18 @@ int main(int argc, char* argv[])
if (result != RESULT_OK) if (result != RESULT_OK)
cout << "unable to open " << opt.device << ": " << getResultCode(result) << endl; cout << "unable to open " << opt.device << ": " << getResultCode(result) << endl;
if (device->isValid() == false) if (!device->isValid())
cout << "device " << opt.device << " not available" << endl; cout << "device " << opt.device << " not available" << endl;
else { else {
cout << "device opened" << endl; cout << "device opened" << endl;
fstream file(opt.dumpFile, ios::in | ios::binary); fstream file(opt.dumpFile, ios::in | ios::binary);
if (file.is_open() == true) { if (file.is_open()) {
while (true) { while (true) {
unsigned char byte = file.get(); unsigned char byte = file.get();
if (file.eof() == true) if (file.eof())
break; break;
cout << hex << setw(2) << setfill('0') cout << hex << setw(2) << setfill('0')
<< static_cast<unsigned>(byte) << endl; << static_cast<unsigned>(byte) << endl;