moving 'scan' functionality from ebusctl into ebusd continued.
This commit is contained in:
+23
-12
@@ -32,7 +32,7 @@ BaseLoop::BaseLoop()
|
||||
L.log(bas, trace, "ebus configuration dir: %s", A.getOptVal<const char*>("ebusconfdir"));
|
||||
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
|
||||
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
|
||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePolDB());
|
||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePollDB());
|
||||
|
||||
// create ebusloop
|
||||
m_ebusloop = new EBusLoop(m_commands);
|
||||
@@ -131,7 +131,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
// polling data
|
||||
if (strcasecmp(m_commands->getCmdType(index).c_str(), "P") == 0) {
|
||||
// get polldata
|
||||
polldata = m_commands->getPolData(index);
|
||||
polldata = m_commands->getPollData(index);
|
||||
if (polldata != "") {
|
||||
// decode data
|
||||
Command* command = new Command(index, (*m_commands)[index], polldata);
|
||||
@@ -151,7 +151,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, false);
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
||||
L.log(bas, trace, " msg: %s", ebusCommand.c_str());
|
||||
// send busCommand
|
||||
m_ebusloop->addBusCommand(busCommand);
|
||||
@@ -204,7 +204,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, false);
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
||||
L.log(bas, event, " msg: %s", ebusCommand.c_str());
|
||||
// send busCommand
|
||||
m_ebusloop->addBusCommand(busCommand);
|
||||
@@ -273,7 +273,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
ebusCommand += cmd[1];
|
||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, false);
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
||||
L.log(bas, trace, " msg: %s", ebusCommand.c_str());
|
||||
// send busCommand
|
||||
m_ebusloop->addBusCommand(busCommand);
|
||||
@@ -294,15 +294,25 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
case scan:
|
||||
if (cmd.size() < 1 || cmd.size() > 2) {
|
||||
result << "usage: 'scan'" << std::endl
|
||||
<< " 'scan full'";
|
||||
<< " 'scan full'" << std::endl
|
||||
<< " 'scan result'";
|
||||
break;
|
||||
}
|
||||
|
||||
//~ if (strcasecmp(cmd[1].c_str(), "FULL") == 0)
|
||||
//~ // scan(FULL);
|
||||
//~ else
|
||||
//~ // scan();
|
||||
if (strcasecmp(cmd[1].c_str(), "RESULT") == 0) {
|
||||
//~ m_ebusloop->scan(true);
|
||||
result << "TODO show result";
|
||||
break;
|
||||
}
|
||||
|
||||
if (strcasecmp(cmd[1].c_str(), "FULL") == 0) {
|
||||
m_ebusloop->scan(true);
|
||||
result << "done";
|
||||
break;
|
||||
}
|
||||
|
||||
m_ebusloop->scan();
|
||||
result << "done";
|
||||
break;
|
||||
|
||||
case log:
|
||||
@@ -362,7 +372,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
L.log(bas, trace, "ebus configuration dir: %s", A.getOptVal<const char*>("ebusconfdir"));
|
||||
L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB());
|
||||
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
|
||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePolDB());
|
||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePollDB());
|
||||
|
||||
delete m_commands;
|
||||
m_commands = commands;
|
||||
@@ -379,7 +389,8 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
<< " cyc - fetch cycle data 'cyc class cmd (sub)'" << std::endl
|
||||
<< " hex - send given hex value 'hex type value' (value: ZZPBSBNNDx)" << std::endl << std::endl
|
||||
<< " scan - scan ebus kown addresses 'scan'" << std::endl
|
||||
<< " - scan ebus all addresses 'scan full'" << std::endl << std::endl
|
||||
<< " - scan ebus all addresses 'scan full'" << std::endl
|
||||
<< " - scan show results 'scan result'" << std::endl << std::endl
|
||||
<< " log - change log areas 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
|
||||
<< " - change log level 'log level level' (level: error|event|trace|debug)" << std::endl << std::endl
|
||||
<< " raw - toggle log raw data 'raw'" << std::endl
|
||||
|
||||
+84
-7
@@ -25,7 +25,8 @@ extern LogInstance& L;
|
||||
extern Appl& A;
|
||||
|
||||
EBusLoop::EBusLoop(Commands* commands)
|
||||
: m_commands(commands), m_stop(false), m_lockCounter(0), m_priorRetry(false)
|
||||
: m_commands(commands), m_stop(false), m_lockCounter(0),
|
||||
m_priorRetry(false), m_scan(false), m_scanFull(false)
|
||||
{
|
||||
m_port = new Port(A.getOptVal<const char*>("device"), A.getOptVal<bool>("nodevicecheck"));
|
||||
m_port->open();
|
||||
@@ -72,15 +73,19 @@ void* EBusLoop::run()
|
||||
if (m_port->isOpen() == true) {
|
||||
ssize_t numBytes;
|
||||
|
||||
// add poll command
|
||||
if (m_commands->sizePolDB() > 0) {
|
||||
// add poll or scan command
|
||||
if (m_commands->sizePollDB() > 0 || m_scan == true) {
|
||||
// check polling delta
|
||||
time(&pollEnd);
|
||||
pollDelta = difftime(pollEnd, pollStart);
|
||||
|
||||
// add new polling command to send
|
||||
if (pollDelta >= m_pollInterval) {
|
||||
addPollCommand();
|
||||
if (m_scan == true)
|
||||
addScanCommand();
|
||||
else
|
||||
addPollCommand();
|
||||
|
||||
time(&pollStart);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +131,10 @@ void* EBusLoop::run()
|
||||
sendRetries = 0;
|
||||
|
||||
if (busCommand->isPoll() == true) {
|
||||
m_commands->storePolData(busCommand->getMessageStr().c_str()); // TODO use getResult()
|
||||
if (busCommand->isScan() == true)
|
||||
m_commands->storeScanData(busCommand->getMessageStr().c_str());
|
||||
else
|
||||
m_commands->storePollData(busCommand->getMessageStr().c_str()); // TODO use getResult()
|
||||
delete busCommand;
|
||||
}
|
||||
else
|
||||
@@ -255,11 +263,15 @@ void EBusLoop::analyseCycData()
|
||||
tmp += (*m_commands)[index][2];
|
||||
L.log(bus, event, " cycle [%4d] %s", index, tmp.c_str());
|
||||
}
|
||||
|
||||
// collect Slave address
|
||||
if (index != -3)
|
||||
collectSlave();
|
||||
}
|
||||
|
||||
void EBusLoop::addPollCommand()
|
||||
{
|
||||
int index = m_commands->nextPolCommand();
|
||||
int index = m_commands->nextPollCommand();
|
||||
if (index < 0) {
|
||||
L.log(bus, error, "polling index out of range");
|
||||
}
|
||||
@@ -275,7 +287,7 @@ void EBusLoop::addPollCommand()
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, true);
|
||||
BusCommand* busCommand = new BusCommand(ebusCommand, true, false);
|
||||
L.log(bus, trace, " msg: %s", ebusCommand.c_str());
|
||||
|
||||
addBusCommand(busCommand);
|
||||
@@ -549,3 +561,68 @@ int EBusLoop::recvSlaveData(SymbolString& result)
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
void EBusLoop::collectSlave()
|
||||
{
|
||||
std::vector<unsigned char>::iterator it;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
bool found = false;
|
||||
unsigned char mm = m_sstr[i];
|
||||
|
||||
if (i == 0) {
|
||||
if (mm == 0xff)
|
||||
mm = 0x04;
|
||||
else
|
||||
mm += 0x05;
|
||||
}
|
||||
|
||||
for (it = m_slave.begin(); it != m_slave.end(); it++)
|
||||
if ((*it) == mm)
|
||||
found = true;
|
||||
|
||||
if (found == false && isMaster(mm) == false && mm != BROADCAST) {
|
||||
m_slave.push_back(mm);
|
||||
L.log(bus, event, " new slave: %d %02x", m_slave.size(), m_slave.back());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EBusLoop::addScanCommand()
|
||||
{
|
||||
//~ static int index = 0;
|
||||
//~
|
||||
//~ if (m_scanFull == true) {
|
||||
//~
|
||||
//~ }
|
||||
//~ else {
|
||||
//~ m_slave[index]
|
||||
//~ }
|
||||
// TODO create next scan Command
|
||||
// loop over
|
||||
// scan -> from collected master and slave data
|
||||
// full -> loop 0x00 -> 0xff (without master and broadcast)
|
||||
// after loop reset state -> m_scan == false; m_scanFull == false;
|
||||
|
||||
|
||||
//~ int index = m_commands->nextPollCommand();
|
||||
//~ if (index < 0) {
|
||||
//~ L.log(bus, error, "polling index out of range");
|
||||
//~ }
|
||||
//~ else {
|
||||
//~ // TODO: implement as methode from class commands?
|
||||
//~ std::string tmp;
|
||||
//~ tmp += (*m_commands)[index][1];
|
||||
//~ tmp += " ";
|
||||
//~ tmp += (*m_commands)[index][2];
|
||||
//~ L.log(bus, event, " polling [%4d] %s", index, tmp.c_str());
|
||||
//~
|
||||
//~ std::string ebusCommand(A.getOptVal<const char*>("address"));
|
||||
//~ ebusCommand += m_commands->getEbusCommand(index);
|
||||
//~ std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
||||
//~
|
||||
//~ BusCommand* busCommand = new BusCommand(ebusCommand, true, true);
|
||||
//~ L.log(bus, trace, " msg: %s", ebusCommand.c_str());
|
||||
//~
|
||||
//~ addBusCommand(busCommand);
|
||||
//~ }
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ public:
|
||||
|
||||
void reload(Commands* commands) { m_commands = commands; }
|
||||
|
||||
void scan(const bool full=false) { m_scan = true; m_scanFull = full; }
|
||||
|
||||
private:
|
||||
Commands* m_commands;
|
||||
Port* m_port;
|
||||
@@ -73,6 +75,11 @@ private:
|
||||
int m_lockRetries;
|
||||
long m_acquireTime;
|
||||
|
||||
std::vector<unsigned char> m_slave;
|
||||
|
||||
bool m_scan;
|
||||
bool m_scanFull;
|
||||
|
||||
unsigned char fetchByte();
|
||||
void collectCycData(const int numRecv);
|
||||
void analyseCycData();
|
||||
@@ -82,6 +89,8 @@ private:
|
||||
int sendByte(const unsigned char sendByte);
|
||||
int recvSlaveAck(unsigned char& recvByte);
|
||||
int recvSlaveData(SymbolString& result);
|
||||
void collectSlave();
|
||||
void addScanCommand();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
namespace libebus
|
||||
{
|
||||
|
||||
BusCommand::BusCommand(const std::string commandStr, const bool isPoll)
|
||||
: m_isPoll(isPoll), m_command(commandStr), m_result(), m_resultCode(RESULT_OK)
|
||||
BusCommand::BusCommand(const std::string commandStr, const bool poll, const bool scan)
|
||||
: m_poll(poll), m_scan(scan), m_command(commandStr), m_result(), m_resultCode(RESULT_OK)
|
||||
{
|
||||
unsigned char dstAddress = m_command[1];
|
||||
|
||||
|
||||
@@ -34,11 +34,12 @@ class BusCommand
|
||||
{
|
||||
|
||||
public:
|
||||
BusCommand(const std::string command, const bool isPoll);
|
||||
BusCommand(const std::string command, const bool poll, const bool scan);
|
||||
~BusCommand();
|
||||
|
||||
CommandType getType() const { return m_type; }
|
||||
bool isPoll() const { return m_isPoll; }
|
||||
bool isPoll() const { return m_poll; }
|
||||
bool isScan() const { return m_scan; }
|
||||
|
||||
SymbolString getCommand() const { return m_command; }
|
||||
SymbolString getResult() const { return m_result; }
|
||||
@@ -55,7 +56,8 @@ public:
|
||||
|
||||
private:
|
||||
CommandType m_type;
|
||||
bool m_isPoll;
|
||||
bool m_poll;
|
||||
bool m_scan;
|
||||
SymbolString m_command;
|
||||
SymbolString m_result;
|
||||
int m_resultCode;
|
||||
|
||||
+31
-16
@@ -31,10 +31,10 @@ namespace libebus
|
||||
|
||||
Commands::~Commands()
|
||||
{
|
||||
for (mapCI_t iter = m_polDB.begin(); iter != m_polDB.end(); ++iter)
|
||||
for (mapCI_t iter = m_pollDB.begin(); iter != m_pollDB.end(); ++iter)
|
||||
delete iter->second;
|
||||
|
||||
m_polDB.clear();
|
||||
m_pollDB.clear();
|
||||
|
||||
for (mapCI_t iter = m_cycDB.begin(); iter != m_cycDB.end(); ++iter)
|
||||
delete iter->second;
|
||||
@@ -55,7 +55,7 @@ void Commands::addCommand(const cmd_t& command)
|
||||
|
||||
if (strcasecmp(command[0].c_str(),"P") == 0) {
|
||||
Command* cmd = new Command(m_cmdDB.size()-1, command);
|
||||
m_polDB.insert(pair_t(m_cmdDB.size()-1, cmd));
|
||||
m_pollDB.insert(pair_t(m_cmdDB.size()-1, cmd));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,33 +188,33 @@ std::string Commands::getCycData(int index) const
|
||||
return "";
|
||||
}
|
||||
|
||||
int Commands::nextPolCommand()
|
||||
int Commands::nextPollCommand()
|
||||
{
|
||||
size_t index = 0;
|
||||
|
||||
m_polIndex++;
|
||||
m_pollIndex++;
|
||||
|
||||
if (m_polIndex == m_polDB.size())
|
||||
m_polIndex = 0;
|
||||
if (m_pollIndex == m_pollDB.size())
|
||||
m_pollIndex = 0;
|
||||
|
||||
mapCI_t iter = m_polDB.begin();
|
||||
mapCI_t iter = m_pollDB.begin();
|
||||
|
||||
for (; iter != m_polDB.end(); iter++, index++)
|
||||
if (index == m_polIndex)
|
||||
for (; iter != m_pollDB.end(); iter++, index++)
|
||||
if (index == m_pollIndex)
|
||||
return iter->first;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Commands::storePolData(const std::string& data) const
|
||||
void Commands::storePollData(const std::string& data) const
|
||||
{
|
||||
// prepare string for searching command
|
||||
std::string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2));
|
||||
|
||||
mapCI_t iter = m_polDB.begin();
|
||||
mapCI_t iter = m_pollDB.begin();
|
||||
|
||||
// walk through commands
|
||||
for (; iter != m_polDB.end(); iter++) {
|
||||
for (; iter != m_pollDB.end(); iter++) {
|
||||
|
||||
std::string command = getEbusCommand(iter->first);
|
||||
|
||||
@@ -228,15 +228,30 @@ void Commands::storePolData(const std::string& data) const
|
||||
}
|
||||
}
|
||||
|
||||
std::string Commands::getPolData(int index) const
|
||||
std::string Commands::getPollData(const int index) const
|
||||
{
|
||||
mapCI_t iter = m_polDB.find(index);
|
||||
if (iter != m_polDB.end())
|
||||
mapCI_t iter = m_pollDB.find(index);
|
||||
if (iter != m_pollDB.end())
|
||||
return iter->second->getData();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
void Commands::storeScanData(const std::string& data)
|
||||
{
|
||||
std::vector<std::string>::const_iterator iter = m_scanDB.begin();
|
||||
bool found = false;
|
||||
|
||||
// walk through scan data
|
||||
for (; iter != m_scanDB.end(); iter++)
|
||||
if (data == (*iter))
|
||||
found = true;
|
||||
|
||||
if (found == false)
|
||||
m_scanDB.push_back(data);
|
||||
}
|
||||
|
||||
|
||||
void Commands::printCommand(const cmd_t& command) const
|
||||
{
|
||||
if (command.size() == 0)
|
||||
|
||||
+12
-7
@@ -40,7 +40,7 @@ class Commands
|
||||
{
|
||||
|
||||
public:
|
||||
Commands() : m_polIndex(-1) {}
|
||||
Commands() : m_pollIndex(-1) {}
|
||||
~Commands();
|
||||
|
||||
void addCommand(const cmd_t& command);
|
||||
@@ -48,7 +48,8 @@ public:
|
||||
|
||||
std::size_t sizeCmdDB() const { return m_cmdDB.size(); }
|
||||
std::size_t sizeCycDB() const { return m_cycDB.size(); }
|
||||
std::size_t sizePolDB() const { return m_polDB.size(); }
|
||||
std::size_t sizePollDB() const { return m_pollDB.size(); }
|
||||
std::size_t sizeScanDB() const { return m_scanDB.size(); }
|
||||
|
||||
cmd_t const& operator[](const std::size_t& index) const { return m_cmdDB[index]; }
|
||||
|
||||
@@ -60,15 +61,19 @@ public:
|
||||
int storeCycData(const std::string& data) const;
|
||||
std::string getCycData(int index) const;
|
||||
|
||||
int nextPolCommand();
|
||||
void storePolData(const std::string& data) const;
|
||||
std::string getPolData(int index) const;
|
||||
int nextPollCommand();
|
||||
void storePollData(const std::string& data) const;
|
||||
std::string getPollData(const int index) const;
|
||||
|
||||
void storeScanData(const std::string& data);
|
||||
std::string getScanData(const int index) const { return m_scanDB[index]; }
|
||||
|
||||
private:
|
||||
cmdDB_t m_cmdDB;
|
||||
map_t m_cycDB;
|
||||
map_t m_polDB;
|
||||
size_t m_polIndex;
|
||||
map_t m_pollDB;
|
||||
size_t m_pollIndex;
|
||||
std::vector<std::string> m_scanDB;
|
||||
|
||||
void printCommand(const cmd_t& command) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user