added result/error constants, use constants where possible, determine type from destination address and switched to enum, added isErrorResult and remove error description from result
This commit is contained in:
+24
-22
@@ -147,17 +147,17 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string type = m_commands->getEbusType(index);
|
|
||||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||||
ebusCommand += m_commands->getEbusCommand(index);
|
ebusCommand += m_commands->getEbusCommand(index);
|
||||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||||
|
|
||||||
L.log(bas, trace, " type: %s msg: %s", type.c_str(), ebusCommand.c_str());
|
BusCommand* busCommand = new BusCommand(ebusCommand);
|
||||||
|
L.log(bas, trace, " type: %s msg: %s", busCommand->getTypeCStr(), ebusCommand.c_str());
|
||||||
// send busCommand
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(new BusCommand(type, ebusCommand));
|
m_ebusloop->addBusCommand(busCommand);
|
||||||
BusCommand* busCommand = m_ebusloop->getBusCommand();
|
busCommand = m_ebusloop->getBusCommand();
|
||||||
|
|
||||||
if (busCommand->getResult().c_str()[0] != '-') {
|
if (!busCommand->isErrorResult()) {
|
||||||
// decode data
|
// decode data
|
||||||
Command* command = new Command(index, (*m_commands)[index], busCommand->getResult());
|
Command* command = new Command(index, (*m_commands)[index], busCommand->getResult());
|
||||||
|
|
||||||
@@ -166,8 +166,8 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
delete command;
|
delete command;
|
||||||
} else {
|
} else {
|
||||||
L.log(bas, error, " %s", busCommand->getResult().c_str());
|
L.log(bas, error, " %s", busCommand->getResultCodeCStr());
|
||||||
result << busCommand->getResult();
|
result << busCommand->getResultCodeCStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete busCommand;
|
delete busCommand;
|
||||||
@@ -188,7 +188,6 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
|
|
||||||
std::string type = m_commands->getEbusType(index);
|
|
||||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||||
ebusCommand += m_commands->getEbusCommand(index);
|
ebusCommand += m_commands->getEbusCommand(index);
|
||||||
|
|
||||||
@@ -205,14 +204,15 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||||
|
|
||||||
L.log(bas, event, " type: %s msg: %s", type.c_str(), ebusCommand.c_str());
|
BusCommand* busCommand = new BusCommand(ebusCommand);
|
||||||
|
L.log(bas, event, " type: %s msg: %s", busCommand->getTypeCStr(), ebusCommand.c_str());
|
||||||
// send busCommand
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(new BusCommand(type, ebusCommand));
|
m_ebusloop->addBusCommand(busCommand);
|
||||||
BusCommand* busCommand = m_ebusloop->getBusCommand();
|
busCommand = m_ebusloop->getBusCommand();
|
||||||
|
|
||||||
if (busCommand->getResult().c_str()[0] != '-') {
|
if (!busCommand->isErrorResult()) {
|
||||||
// decode result
|
// decode result
|
||||||
if (strcasecmp(type.c_str(), "BC") == 0)
|
if (busCommand->getType()==broadcast)
|
||||||
result << "done";
|
result << "done";
|
||||||
else if (busCommand->getResult().substr(busCommand->getResult().length()-8) == "00000000")
|
else if (busCommand->getResult().substr(busCommand->getResult().length()-8) == "00000000")
|
||||||
result << "done";
|
result << "done";
|
||||||
@@ -220,8 +220,8 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
result << "error";
|
result << "error";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
L.log(bas, error, " %s", busCommand->getResult().c_str());
|
L.log(bas, error, " %s", busCommand->getResultCodeCStr());
|
||||||
result << busCommand->getResult();
|
result << busCommand->getResultCodeCStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete busCommand;
|
delete busCommand;
|
||||||
@@ -271,21 +271,23 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|| (strcasecmp(cmd[1].c_str(), "MM") == 0)
|
|| (strcasecmp(cmd[1].c_str(), "MM") == 0)
|
||||||
|| (strcasecmp(cmd[1].c_str(), "BC") == 0)) {
|
|| (strcasecmp(cmd[1].c_str(), "BC") == 0)) {
|
||||||
|
|
||||||
std::string type = cmd[1];
|
|
||||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||||
cmd[2].erase(std::remove_if(cmd[2].begin(), cmd[2].end(), isspace), cmd[2].end());
|
cmd[2].erase(std::remove_if(cmd[2].begin(), cmd[2].end(), isspace), cmd[2].end());
|
||||||
ebusCommand += cmd[2];
|
ebusCommand += cmd[2];
|
||||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||||
|
|
||||||
L.log(bas, trace, " type: %s msg: %s", type.c_str(), ebusCommand.c_str());
|
BusCommand* busCommand = new BusCommand(ebusCommand);
|
||||||
|
L.log(bas, trace, " type: %s msg: %s", busCommand->getTypeCStr(), ebusCommand.c_str());
|
||||||
// send busCommand
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(new BusCommand(type, ebusCommand));
|
m_ebusloop->addBusCommand(busCommand);
|
||||||
BusCommand* busCommand = m_ebusloop->getBusCommand();
|
busCommand = m_ebusloop->getBusCommand();
|
||||||
|
|
||||||
if (busCommand->getResult().c_str()[0] == '-')
|
|
||||||
L.log(bas, error, " %s", busCommand->getResult().c_str());
|
|
||||||
|
|
||||||
|
if (busCommand->isErrorResult()) {
|
||||||
|
L.log(bas, error, " %s", busCommand->getResultCodeCStr());
|
||||||
|
result << busCommand->getResultCodeCStr();
|
||||||
|
} else {
|
||||||
result << busCommand->getResult();
|
result << busCommand->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
delete busCommand;
|
delete busCommand;
|
||||||
|
|
||||||
|
|||||||
+12
-13
@@ -75,7 +75,7 @@ void* EBusLoop::run()
|
|||||||
busResult = m_bus->proceed();
|
busResult = m_bus->proceed();
|
||||||
|
|
||||||
// new cyc message arrived
|
// new cyc message arrived
|
||||||
if (busResult == 2) {
|
if (busResult == RESULT_SYN) {
|
||||||
std::string data = m_bus->getCycData();
|
std::string data = m_bus->getCycData();
|
||||||
L.log(bus, trace, "%s", data.c_str());
|
L.log(bus, trace, "%s", data.c_str());
|
||||||
|
|
||||||
@@ -101,10 +101,10 @@ void* EBusLoop::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add new bus command to send
|
// add new bus command to send
|
||||||
if (busResult == 4 && busCommandActive == false && m_sendBuffer.size() != 0) {
|
if (busResult == RESULT_AUTO_SYN && busCommandActive == false && m_sendBuffer.size() != 0) {
|
||||||
BusCommand* busCommand = m_sendBuffer.remove();
|
BusCommand* busCommand = m_sendBuffer.remove();
|
||||||
L.log(bus, debug, " type: %s msg: %s",
|
L.log(bus, debug, " type: %s msg: %s",
|
||||||
busCommand->getType().c_str(), busCommand->getCommand().c_str());
|
busCommand->getTypeCStr(), busCommand->getCommand().c_str());
|
||||||
m_bus->addCommand(busCommand);
|
m_bus->addCommand(busCommand);
|
||||||
L.log(bus, debug, " addCommand success");
|
L.log(bus, debug, " addCommand success");
|
||||||
busCommandActive = true;
|
busCommandActive = true;
|
||||||
@@ -117,7 +117,7 @@ void* EBusLoop::run()
|
|||||||
pollDelta = difftime(end, start);
|
pollDelta = difftime(end, start);
|
||||||
|
|
||||||
// add new polling command to send
|
// add new polling command to send
|
||||||
if (busResult == 4 && busCommandActive == false && pollDelta >= m_pollInterval) {
|
if (busResult == RESULT_AUTO_SYN && busCommandActive == false && pollDelta >= m_pollInterval) {
|
||||||
L.log(bus, trace, "polling Intervall reached");
|
L.log(bus, trace, "polling Intervall reached");
|
||||||
|
|
||||||
int index = m_commands->nextPolCommand();
|
int index = m_commands->nextPolCommand();
|
||||||
@@ -133,14 +133,13 @@ void* EBusLoop::run()
|
|||||||
tmp += (*m_commands)[index][2];
|
tmp += (*m_commands)[index][2];
|
||||||
L.log(bus, event, " polling [%d] %s", index, tmp.c_str());
|
L.log(bus, event, " polling [%d] %s", index, tmp.c_str());
|
||||||
|
|
||||||
std::string type = m_commands->getEbusType(index);
|
|
||||||
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
std::string ebusCommand(A.getParam<const char*>("p_address"));
|
||||||
ebusCommand += m_commands->getEbusCommand(index);
|
ebusCommand += m_commands->getEbusCommand(index);
|
||||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||||
|
|
||||||
L.log(bus, trace, " type: %s msg: %s", type.c_str(), ebusCommand.c_str());
|
BusCommand* busCommand = new BusCommand(ebusCommand);
|
||||||
|
L.log(bus, trace, " type: %s msg: %s", busCommand->getTypeCStr(), ebusCommand.c_str());
|
||||||
|
|
||||||
BusCommand* busCommand = new BusCommand(type, ebusCommand);
|
|
||||||
m_bus->addCommand(busCommand);
|
m_bus->addCommand(busCommand);
|
||||||
L.log(bus, debug, " addCommand success");
|
L.log(bus, debug, " addCommand success");
|
||||||
busCommandActive = true;
|
busCommandActive = true;
|
||||||
@@ -152,23 +151,23 @@ void* EBusLoop::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send bus command
|
// send bus command
|
||||||
if (busResult == 1 && busCommandActive == true) {
|
if (busResult == RESULT_BUS_ACQUIRED && busCommandActive == true) {
|
||||||
L.log(bus, trace, " getBus success");
|
L.log(bus, trace, " getBus success");
|
||||||
lookbusretries = 0;
|
lookbusretries = 0;
|
||||||
m_bus->sendCommand();
|
m_bus->sendCommand();
|
||||||
BusCommand* busCommand = m_bus->recvCommand();
|
BusCommand* busCommand = m_bus->recvCommand();
|
||||||
L.log(bus, trace, " %s", busCommand->getResult().c_str());
|
L.log(bus, trace, " %s", busCommand->getResult().c_str());
|
||||||
|
|
||||||
if (busCommand->getResult().c_str()[0] == '-' && retries < m_retries) {
|
if (busCommand->isErrorResult() && retries < m_retries) {
|
||||||
retries++;
|
retries++;
|
||||||
L.log(bus, trace, " retry number: %d", retries);
|
L.log(bus, trace, " retry number: %d", retries);
|
||||||
busCommand->setResult(std::string());
|
busCommand->setResult(std::string(), RESULT_OK);
|
||||||
m_bus->addCommand(busCommand);
|
m_bus->addCommand(busCommand);
|
||||||
} else {
|
} else {
|
||||||
retries = 0;
|
retries = 0;
|
||||||
if (pollCommandActive == true) {
|
if (pollCommandActive == true) {
|
||||||
// only save correct results
|
// only save correct results
|
||||||
if (busCommand->getResult().c_str()[0] != '-')
|
if (!busCommand->isErrorResult())
|
||||||
m_commands->storePolData(busCommand->getResult().c_str());
|
m_commands->storePolData(busCommand->getResult().c_str());
|
||||||
|
|
||||||
delete busCommand;
|
delete busCommand;
|
||||||
@@ -181,7 +180,7 @@ void* EBusLoop::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (busResult == 0) {
|
if (busResult == RESULT_ERR_BUS_LOST) {
|
||||||
L.log(bus, trace, " getBus failure");
|
L.log(bus, trace, " getBus failure");
|
||||||
if (lookbusretries >= m_lookbusretries) {
|
if (lookbusretries >= m_lookbusretries) {
|
||||||
L.log(bus, event, " getBus failed - command deleted");
|
L.log(bus, event, " getBus failed - command deleted");
|
||||||
@@ -192,7 +191,7 @@ void* EBusLoop::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (busResult == -1)
|
if (busResult == RESULT_ERR_SEND)
|
||||||
L.log(bus, event, " getBus error");
|
L.log(bus, event, " getBus error");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user