moving 'scan' functionality from ebusctl into ebusd continued.

This commit is contained in:
Roland Jax
2014-11-16 21:50:35 +01:00
parent e5452282ad
commit b6cae7884a
7 changed files with 166 additions and 47 deletions
+2 -2
View File
@@ -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];
+5 -3
View File
@@ -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
View File
@@ -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
View File
@@ -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;