diff --git a/src/lib/ebus/command.cpp b/src/lib/ebus/command.cpp deleted file mode 100644 index 37fefaf4..00000000 --- a/src/lib/ebus/command.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#include "command.h" -#include "decode.h" -#include "encode.h" -#include -#include -#include -#include -#include -#include - -string Command::calcData() -{ - // encode - only first entry will be encoded - // ToDo: if more parts are needed, they will be implemented - encode(m_data, m_command[13], m_command[14]); - - if (m_error.length() > 0) - m_result = m_error; - - return m_result; -} - -string Command::calcResult(const cmd_t& cmd) -{ - int elements = strtol(m_command[9].c_str(), NULL, 10); - - if (cmd.size() > 3) { - bool found = false; - - for (size_t i = 3; i < cmd.size(); i++) { - int j; - - for (j = 0; j < elements; j++) { - if (m_command[10 + j*8] == cmd[i]) { - found = true; - break; - } - } - - if (found == true) { - found = false; - - // decode - calcSub(m_command[11 + j*8], m_command[12 + j*8], - m_command[13 + j*8], m_command[14 + j*8]); - } - - } - - } else { - for (int j = 0; j < elements; j++) { - - // decode - calcSub(m_command[11 + j*8], m_command[12 + j*8], - m_command[13 + j*8], m_command[14 + j*8]); - } - } - - if (m_error.length() > 0) - m_result = m_error; - - return m_result; -} - -void Command::calcSub(const string& part, const string& position, - const string& type, const string& factor) -{ - string data; - - // Master Data - if (strcasecmp(part.c_str(), "MD") == 0) { - // QQ ZZ PB SB NN - int md_pos = 10; - int md_len = strtol(m_command[7].c_str(), NULL, 10)*2; - data = m_data.substr(md_pos, md_len); - } - - // Slave Acknowledge - else if (strcasecmp(part.c_str(), "SA") == 0) { - // QQ ZZ PB SB NN + Dx + CRC - int sa_pos = 10 + (strtol(m_command[7].c_str(), NULL, 10)*2) + 2; - int sa_len = 2; - data = m_data.substr(sa_pos, sa_len); - } - - // Slave Data - else if (strcasecmp(part.c_str(), "SD") == 0) { - // QQ ZZ PB SB NN + Dx + CRC ACK NN - int sd_pos = 10 + (strtol(m_command[7].c_str(), NULL, 10)*2) + 6; - int sd_len = m_data.length() - (10 + (strtol(m_command[7].c_str(), NULL, 10)*2) + 6) - 4; - data = m_data.substr(sd_pos, sd_len); - } - - // Master Acknowledge - else if (strcasecmp(part.c_str(), "MA") == 0) { - // QQ ZZ PB SB NN + Dx + CRC ACK NN + Dx - int ma_pos = m_data.length() - 2; - int ma_len = 2; - data = m_data.substr(ma_pos, ma_len); - } - - decode(data, position, type, factor); -} - -void Command::decode(const string& data, const string& position, - const string& type, const string& factor) -{ - ostringstream result, value; - Decode* help = NULL; - - // prepare position - string token; - istringstream stream(position); - vector pos; - - while (getline(stream, token, ',') != 0) - pos.push_back(strtol(token.c_str(), NULL, 10)); - - if (strcasecmp(type.c_str(), "HEX") == 0) { - if (pos.size() <= 1 || pos[1] < pos[0]) - pos[1] = pos[0]; - - value << data.substr((pos[0]-1)*2, (pos[1]-pos[0]+1)*2); - help = new DecodeHEX(value.str()); - } - else if (strcasecmp(type.c_str(), "UCH") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeUCH(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "SCH") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeSCH(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "UIN") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2); - help = new DecodeUIN(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "SIN") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2); - help = new DecodeSIN(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "ULG") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2) - << data.substr((pos[2]-1)*2, 2) << data.substr((pos[3]-1)*2, 2); - help = new DecodeULG(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "SLG") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2) - << data.substr((pos[2]-1)*2, 2) << data.substr((pos[3]-1)*2, 2); - help = new DecodeSLG(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "FLT") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2); - help = new DecodeFLT(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "STR") == 0) { - if (pos.size() <= 1 || pos[1] < pos[0]) - pos[1] = pos[0]; - - value << data.substr((pos[0]-1)*2, (pos[1]-pos[0]+1)*2); - help = new DecodeSTR(value.str()); - } - else if (strcasecmp(type.c_str(), "BCD") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeBCD(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "D1B") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeD1B(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "D1C") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeD1C(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "D2B") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2); - help = new DecodeD2B(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "D2C") == 0) { - value << data.substr((pos[0]-1)*2, 2) << data.substr((pos[1]-1)*2, 2); - help = new DecodeD2C(value.str(), factor); - } - else if (strcasecmp(type.c_str(), "BDA") == 0) { - value << data.substr((pos[0]-1)*2, 2) - << data.substr((pos[1]-1)*2, 2) - << data.substr((pos[2]-1)*2, 2); - help = new DecodeBDA(value.str()); - } - else if (strcasecmp(type.c_str(), "HDA") == 0) { - value << data.substr((pos[0]-1)*2, 2) - << data.substr((pos[1]-1)*2, 2) - << data.substr((pos[2]-1)*2, 2); - help = new DecodeHDA(value.str()); - } - else if (strcasecmp(type.c_str(), "BTI") == 0) { - value << data.substr((pos[0]-1)*2, 2) - << data.substr((pos[1]-1)*2, 2) - << data.substr((pos[2]-1)*2, 2); - help = new DecodeBTI(value.str()); - } - else if (strcasecmp(type.c_str(), "HTI") == 0) { - value << data.substr((pos[0]-1)*2, 2) - << data.substr((pos[1]-1)*2, 2) - << data.substr((pos[2]-1)*2, 2); - help = new DecodeHTI(value.str()); - } - else if (strcasecmp(type.c_str(), "BDY") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeBDY(value.str()); - } - else if (strcasecmp(type.c_str(), "HDY") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeHDY(value.str()); - } - else if (strcasecmp(type.c_str(), "TTM") == 0) { - value << data.substr((pos[0]-1)*2, 2); - help = new DecodeTTM(value.str()); - } - - if (help == NULL) { - result << "type '" << type.c_str() << "' not implemented!"; - m_error = result.str(); - } else { - result << help->decode(); - - if (m_result.length() > 0) - m_result += " "; - - m_result += result.str(); - } - - delete help; -} - -void Command::encode(const string& data, const string& type, - const string& factor) -{ - ostringstream result; - Encode* help = NULL; - - if (strcasecmp(type.c_str(), "HEX") == 0) { - help = new EncodeHEX(data); - } - else if (strcasecmp(type.c_str(), "UCH") == 0) { - help = new EncodeUCH(data, factor); - } - else if (strcasecmp(type.c_str(), "SCH") == 0) { - help = new EncodeSCH(data, factor); - } - else if (strcasecmp(type.c_str(), "UIN") == 0) { - help = new EncodeUIN(data, factor); - } - else if (strcasecmp(type.c_str(), "SIN") == 0) { - help = new EncodeSIN(data, factor); - } - else if (strcasecmp(type.c_str(), "ULG") == 0) { - help = new EncodeULG(data, factor); - } - else if (strcasecmp(type.c_str(), "SLG") == 0) { - help = new EncodeSLG(data, factor); - } - else if (strcasecmp(type.c_str(), "FLT") == 0) { - help = new EncodeSLG(data, factor); - } - else if (strcasecmp(type.c_str(), "STR") == 0) { - help = new EncodeSTR(data); - } - else if (strcasecmp(type.c_str(), "BCD") == 0) { - help = new EncodeBCD(data, factor); - } - else if (strcasecmp(type.c_str(), "D1B") == 0) { - help = new EncodeD1B(data, factor); - } - else if (strcasecmp(type.c_str(), "D1C") == 0) { - help = new EncodeD1C(data, factor); - } - else if (strcasecmp(type.c_str(), "D2B") == 0) { - help = new EncodeD2B(data, factor); - } - else if (strcasecmp(type.c_str(), "D2C") == 0) { - help = new EncodeD2C(data, factor); - } - else if (strcasecmp(type.c_str(), "BDA") == 0) { - help = new EncodeBDA(data); - } - else if (strcasecmp(type.c_str(), "HDA") == 0) { - help = new EncodeHDA(data); - } - else if (strcasecmp(type.c_str(), "BTI") == 0) { - help = new EncodeBTI(data); - } - else if (strcasecmp(type.c_str(), "HTI") == 0) { - help = new EncodeHTI(data); - } - else if (strcasecmp(type.c_str(), "BDY") == 0) { - help = new EncodeBDY(data); - } - else if (strcasecmp(type.c_str(), "HDY") == 0) { - help = new EncodeHDY(data); - } - else if (strcasecmp(type.c_str(), "TTM") == 0) { - help = new EncodeTTM(data); - } - - if (help == NULL) { - result << "type '" << type.c_str() << "' not implemented!"; - m_error = result.str(); - } else { - result << help->encode(); - - if (m_result.length() > 0) - m_result += " "; - - m_result += result.str(); - } - - delete help; -} - diff --git a/src/lib/ebus/command.h b/src/lib/ebus/command.h deleted file mode 100644 index b90a374a..00000000 --- a/src/lib/ebus/command.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef LIBEBUS_COMMAND_H_ -#define LIBEBUS_COMMAND_H_ - -#include -#include - -using namespace std; - -typedef vector cmd_t; -typedef cmd_t::const_iterator cmdCI_t; - -class Command -{ - -public: - Command(int index, cmd_t command) : m_index(index), m_command(command) {} - Command(int index, cmd_t command, string data) - : m_index(index), m_command(command), m_data(data) {} - - cmd_t getCommand() const { return m_command; } - void setData(const string& data) { m_data = data; } - string getData() const { return m_data; } - string calcData(); - - string calcResult(const cmd_t& cmd); - -private: - int m_index; - cmd_t m_command; - string m_data; - string m_result; - string m_error; - - void calcSub(const string& part, const string& position, - const string& type, const string& factor); - - void decode(const string& data, const string& position, - const string& type, const string& factor); - - void encode(const string& data, const string& type, - const string& factor); - -}; - -#endif // LIBEBUS_COMMAND_H_ diff --git a/src/lib/ebus/commands.cpp b/src/lib/ebus/commands.cpp deleted file mode 100644 index 3f781799..00000000 --- a/src/lib/ebus/commands.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#include "commands.h" -#include -#include -#include -#include -#include -#include - -using namespace std; - -Commands::~Commands() -{ - for (mapCI_t iter = m_pollDB.begin(); iter != m_pollDB.end(); ++iter) - delete iter->second; - - m_pollDB.clear(); - - for (mapCI_t iter = m_cycDB.begin(); iter != m_cycDB.end(); ++iter) - delete iter->second; - - m_cycDB.clear(); - - m_cmdDB.clear(); -} - -void Commands::addCommand(const cmd_t& command) -{ - m_cmdDB.push_back(command); - - if (strcasecmp(command[0].c_str(),"C") == 0) { - Command* cmd = new Command(m_cmdDB.size()-1, command); - m_cycDB.insert(pair_t(m_cmdDB.size()-1, cmd)); - } - - if (strcasecmp(command[0].c_str(),"P") == 0) { - Command* cmd = new Command(m_cmdDB.size()-1, command); - m_pollDB.insert(pair_t(m_cmdDB.size()-1, cmd)); - } -} - -void Commands::printCommands() const -{ - if (m_cmdDB.size() == 0) - return; - - for (cmdDBCI_t i = m_cmdDB.begin(); i != m_cmdDB.end(); i++) { - printCommand(*i); - cout << endl; - } -} - -int Commands::findCommand(const string& data) const -{ - // no commands definend - if (m_cmdDB.size() == 0) - return -2; - - // preapre string for searching command - string token; - istringstream isstr(data); - vector cmd; - - // split stream - while (getline(isstr, token, ' ') != 0) - cmd.push_back(token); - - size_t index; - cmdDBCI_t i = m_cmdDB.begin(); - - // walk through commands - GET - if (strcasecmp(cmd[0].c_str(), "GET") == 0) { - for (index = 0; i != m_cmdDB.end(); i++, index++) { - - // empty line - if ((*i).size() == 0) - continue; - - if (((strcasecmp((*i)[0].c_str(), "R") == 0) - || (strcasecmp((*i)[0].c_str(), "P") == 0)) - && (strcasecmp((*i)[1].c_str(), cmd[1].c_str()) == 0) - && (strcasecmp((*i)[2].c_str(), cmd[2].c_str()) == 0)) - return index; - } - // walk through commands - SET, CYC - } else { - // correct type - if (strcasecmp(cmd[0].c_str(), "SET") == 0) - cmd[0] = "W"; - else if (strcasecmp(cmd[0].c_str(), "CYC") == 0) - cmd[0] = "C"; - - for (index = 0; i != m_cmdDB.end(); i++, index++) { - - // empty line - if ((*i).size() == 0) - continue; - - if (strcasecmp((*i)[0].c_str(), cmd[0].c_str()) == 0 && - strcasecmp((*i)[1].c_str(), cmd[1].c_str()) == 0 && - strcasecmp((*i)[2].c_str(), cmd[2].c_str()) == 0) - return index; - } - } - - // command not found - return -1; -} - -string Commands::getBusCommand(const int index) const -{ - cmd_t command = m_cmdDB.at(index); - string cmd; - stringstream sstr; - - if (strcasecmp(command[0].c_str(), "C") == 0) - cmd += command[4]; // QQ - - cmd += command[5]; // ZZ - cmd += command[6]; // PBSB - sstr << setw(2) << hex << setfill('0') << command[7]; - cmd += sstr.str(); // NN - cmd += command[8]; // Dx - - return cmd; -} - -int Commands::storeCycData(const string& data) const -{ - // no commands defined - if (m_cycDB.size() == 0) - return -2; - - // search skipped - string too short - if (data.length() < 10) - return -3; - - // prepare string for searching command - string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2)); - - mapCI_t iter = m_cycDB.begin(); - - // walk through commands - for (; iter != m_cycDB.end(); iter++) { - - string command = getBusCommand(iter->first); - - // skip wrong search string length - if (command.length() > search.length()) - continue; - - if (strcasecmp(command.c_str(), search.substr(0,command.length()).c_str()) == 0) { - iter->second->setData(data); - return iter->first; - } - } - - // command not found - return -1; -} - -string Commands::getCycData(int index) const -{ - mapCI_t iter = m_cycDB.find(index); - if (iter != m_cycDB.end()) - return iter->second->getData(); - else - return ""; -} - -int Commands::nextPollCommand() -{ - size_t index = 0; - - m_pollIndex++; - - if (m_pollIndex == m_pollDB.size()) - m_pollIndex = 0; - - mapCI_t iter = m_pollDB.begin(); - - for (; iter != m_pollDB.end(); iter++, index++) - if (index == m_pollIndex) - return iter->first; - - return -1; -} - -void Commands::storePollData(const string& data) const -{ - // prepare string for searching command - string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2)); - - mapCI_t iter = m_pollDB.begin(); - - // walk through commands - for (; iter != m_pollDB.end(); iter++) { - - string command = getBusCommand(iter->first); - - // skip wrong search string length - if (command.length() > search.length()) - continue; - - if (strcasecmp(command.c_str(), search.substr(0,command.length()).c_str()) == 0) - iter->second->setData(data); - - } -} - -string Commands::getPollData(const int index) const -{ - mapCI_t iter = m_pollDB.find(index); - if (iter != m_pollDB.end()) - return iter->second->getData(); - else - return ""; -} - -void Commands::storeScanData(const string& data) -{ - vector::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) - return; - - for (cmdCI_t i = command.begin(); i != command.end(); i++) - cout << *i << ';'; -} - diff --git a/src/lib/ebus/commands.h b/src/lib/ebus/commands.h deleted file mode 100644 index a696a955..00000000 --- a/src/lib/ebus/commands.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef LIBEBUS_COMMANDS_H_ -#define LIBEBUS_COMMANDS_H_ - -#include "command.h" -#include -#include -#include - -using namespace std; - -typedef vector cmdDB_t; -typedef cmdDB_t::const_iterator cmdDBCI_t; - -typedef map map_t; -typedef map_t::const_iterator mapCI_t; -typedef pair pair_t; - -class Commands -{ - -public: - Commands() : m_pollIndex(-1) {} - ~Commands(); - - void addCommand(const cmd_t& command); - void printCommands() const; - - size_t sizeCmdDB() const { return m_cmdDB.size(); } - size_t sizeCycDB() const { return m_cycDB.size(); } - size_t sizePollDB() const { return m_pollDB.size(); } - size_t sizeScanDB() const { return m_scanDB.size(); } - - cmd_t const& operator[](const size_t& index) const { return m_cmdDB[index]; } - - int findCommand(const string& data) const; - - string getCmdType(const int index) const { return string(m_cmdDB.at(index)[0]); } - string getBusCommand(const int index) const; - - int storeCycData(const string& data) const; - string getCycData(int index) const; - - int nextPollCommand(); - void storePollData(const string& data) const; - string getPollData(const int index) const; - - void storeScanData(const string& data); - string getScanData(const int index) const { return m_scanDB[index]; } - -private: - cmdDB_t m_cmdDB; - map_t m_cycDB; - map_t m_pollDB; - size_t m_pollIndex; - vector m_scanDB; - - void printCommand(const cmd_t& command) const; - -}; - -#endif // LIBEBUS_COMMANDS_H_ - diff --git a/src/lib/ebus/configfile.cpp b/src/lib/ebus/configfile.cpp deleted file mode 100644 index 11019af0..00000000 --- a/src/lib/ebus/configfile.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#include "configfile.h" -#include -#include -#include - -using namespace std; - -void ConfigFileCSV::parse(istream& is, Commands& commands) -{ - string line; - - // read lines - while (getline(is, line) != 0) { - cmd_t row; - string column; - - istringstream isstr(line); - - // walk through columns - while (getline(isstr, column, ';') != 0) - row.push_back(column); - - // skip empty and commented rows - if (row.empty() == true || row[0][0] == '#') - continue; - - commands.addCommand(row); - } -}; - - -ConfigCommands::ConfigCommands(const string path, const FileType type) -{ - m_path = path; - m_configfile = NULL; - setType(type); - addFiles(m_path, m_extension); -} - -void ConfigCommands::setType(const FileType type) -{ - if (m_configfile != NULL) - delete m_configfile; - - switch (type) { - case ft_csv: - m_configfile = new ConfigFileCSV(); - m_extension = "csv"; - break; - }; -}; - -Commands* ConfigCommands::getCommands() -{ - Commands* commands = new Commands(); - vector::const_iterator i = m_files.begin(); - - for(; i != m_files.end(); i++) { - fstream file((*i).c_str(), ios::in); - - if(file.is_open() == true) { - m_configfile->parse(file, *commands); - file.close(); - } - } - return commands; -}; - -void ConfigCommands::addFiles(const string path, const string extension) -{ - DIR* dir = opendir(path.c_str()); - - if (dir == NULL) - return; - - dirent* d = readdir(dir); - - while (d != NULL) { - - if (d->d_type == DT_DIR) { - string fn = d->d_name; - - if (fn != "." && fn != "..") { - const string p = path + "/" + d->d_name; - addFiles(p, extension); - } - - } else if (d->d_type == DT_REG) { - string fn = d->d_name; - - if (fn.find(extension, (fn.length() - extension.length())) != string::npos) { - const string p = path + "/" + d->d_name; - m_files.push_back(p); - } - } - - d = readdir(dir); - } - - closedir(dir); -}; - diff --git a/src/lib/ebus/configfile.h b/src/lib/ebus/configfile.h deleted file mode 100644 index f6f37563..00000000 --- a/src/lib/ebus/configfile.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef LIBEBUS_CONFIGFILE_H_ -#define LIBEBUS_CONFIGFILE_H_ - -#include "commands.h" -#include -#include - -using namespace std; - -/** \file configfile.h */ - -/** available file endings / types. */ -enum FileType { - ft_csv /*!< CSV */ -}; - -/** - * @brief base class for config files. - */ -class ConfigFile -{ - -public: - /** - * @brief destructor. - */ - virtual ~ConfigFile() {} - - /** - * @brief read input stream and stored data into commands - * @param is open input stream for reading. - * @param commands object as datastore. - */ - virtual void parse(istream& is, Commands& commands) = 0; - -}; - -/** - * @brief derived class for CSV config files. - */ -class ConfigFileCSV : public ConfigFile -{ - -public: - /** - * @brief destructor. - */ - ~ConfigFileCSV() {} - - /** - * @brief read input stream and stored data into commands - * @param is open input stream for reading. - * @param commands object as datastore. - */ - void parse(istream& is, Commands& commands); - -}; - -/** - * @brief class to parse configuration files and store into commands instance. - */ -class ConfigCommands -{ - -public: - /** - * @brief set file type and add recursive files from given path. - * @param path to configuration files. - * @param type to parse. - */ - ConfigCommands(const string path, const FileType type); - - /** - * @brief destructor. - */ - ~ConfigCommands() { delete m_configfile; } - - /** - * @brief setter for file type. - * @param type of files. - */ - void setType(const FileType type); - - /** - * @brief parse files for commands and store them into commands instance. - * @return a commands instance - */ - Commands* getCommands(); - -private: - /** the configfile instance */ - ConfigFile* m_configfile; - - /** main path for configuration files */ - string m_path; - - /** valid file extension */ - string m_extension; - - /** vector of configuration files */ - vector m_files; - - /** - * @brief parse path for given file extension. - * @param path to configuration files. - * @param extension with file type. - */ - void addFiles(const string path, const string extension); - -}; - -#endif // LIBEBUS_CONFIGFILE_H_ - diff --git a/src/lib/ebus/decode.cpp b/src/lib/ebus/decode.cpp deleted file mode 100644 index b86bed97..00000000 --- a/src/lib/ebus/decode.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#include "decode.h" -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -Decode::Decode(const string& data, const string& factor) - : m_data(data) -{ - if ((factor.find_first_not_of("0123456789.") == string::npos) == true) - m_factor = static_cast(strtod(factor.c_str(), NULL)); - else - m_factor = 1.0; -} - - -string DecodeHEX::decode() -{ - ostringstream result; - - for (size_t i = 0; i < m_data.length()/2; i++) - result << m_data.substr(i*2, 2) << " "; - - return result.str().substr(0, result.str().length()-1); -} - -string DecodeUCH::decode() -{ - stringstream ss; - ss << hex << m_data; - - unsigned short x; - ss >> x; - - ostringstream result; - result << setprecision(3) << fixed << static_cast(x * m_factor); - - return result.str(); -} - -string DecodeSCH::decode() -{ - stringstream ss; - ss << hex << m_data; - - unsigned short x; - ss >> x; - - ostringstream result; - if ((x & 0x80) == 0x80) - result << setprecision(3) << fixed - << static_cast(static_cast(- ( ((unsigned char) (~ x)) + 1) ) * m_factor); - else - result << setprecision(3) << fixed - << static_cast(static_cast(x) * m_factor); - - return result.str(); -} - -string DecodeUIN::decode() -{ - stringstream ss; - ss << hex << m_data; - - unsigned short x; - ss >> x; - - ostringstream result; - result << setprecision(3) << fixed << static_cast(x * m_factor); - - return result.str(); -} - -string DecodeSIN::decode() -{ - stringstream ss; - ss << hex << m_data; - - unsigned short x; - ss >> x; - - ostringstream result; - result << setprecision(3) << fixed << static_cast(static_cast(x) * m_factor); - - return result.str(); -} - -string DecodeULG::decode() -{ - stringstream ss; - ss << hex << m_data; - - unsigned int x; - ss >> x; - - ostringstream result; - result << setprecision(3) << fixed << static_cast(x * m_factor); - - return result.str(); -} - -string DecodeSLG::decode() -{ - stringstream ss; - ss << hex << m_data; - - unsigned int x; - ss >> x; - - ostringstream result; - result << setprecision(3) << fixed <(static_cast(x) * m_factor); - - return result.str(); -} - -string DecodeFLT::decode() -{ - stringstream ss; - ss << hex << m_data; - - short x; - ss >> x; - - ostringstream result; - result << setprecision(3) << fixed << static_cast(x / 1000.0 * m_factor); - - return result.str(); -} - -string DecodeSTR::decode() -{ - ostringstream result; - - for (size_t i = 0; i <= m_data.length()/2; i++) { - char tmp = static_cast(strtol(m_data.substr(i*2, 2).c_str(), NULL, 16)); - if (tmp == 0x00) tmp = 0x20; - result << tmp; - } - - return result.str().substr(0, result.str().length()-1); -} - -string DecodeBCD::decode() -{ - ostringstream result; - unsigned char src = strtol(m_data.c_str(), NULL, 16); - - if ((src & 0x0F) > 0x09 || ((src >> 4) & 0x0F) > 0x09) - result << static_cast(0xFF); - else - result << static_cast(( ( ((src & 0xF0) >> 4) * 10) + (src & 0x0F) ) * m_factor); - - return result.str(); -} - -string DecodeD1B::decode() -{ - ostringstream result; - unsigned char src = strtol(m_data.c_str(), NULL, 16); - - if ((src & 0x80) == 0x80) - result << static_cast((- ( ((unsigned char) (~ src)) + 1) ) * m_factor); - else - result << static_cast(src * m_factor); - - return result.str(); -} - -string DecodeD1C::decode() -{ - ostringstream result; - unsigned char src = strtol(m_data.c_str(), NULL, 16); - - if (src > 0xC8) - result << static_cast(0xFF); - else - result << static_cast((src / 2.0) * m_factor); - - return result.str(); -} - -string DecodeD2B::decode() -{ - ostringstream result; - unsigned char src_lsb = static_cast(strtol(m_data.substr(0, 2).c_str(), NULL, 16)); - unsigned char src_msb = static_cast(strtol(m_data.substr(2, 2).c_str(), NULL, 16)); - - if ((src_msb & 0x80) == 0x80) - result << static_cast - ((- ( ((unsigned char) (~ src_msb)) + - ( ( ((unsigned char) (~ src_lsb)) + 1) / 256.0) ) ) * m_factor); - - else - result << static_cast((src_msb + (src_lsb / 256.0)) * m_factor); - - return result.str(); -} - -string DecodeD2C::decode() -{ - ostringstream result; - unsigned char src_lsb = static_cast(strtol(m_data.substr(0, 2).c_str(), NULL, 16)); - unsigned char src_msb = static_cast(strtol(m_data.substr(2, 2).c_str(), NULL, 16)); - - if ((src_msb & 0x80) == 0x80) - result << static_cast - ((- ( ( ( ((unsigned char) (~ src_msb)) * 16.0) ) + - ( ( ((unsigned char) (~ src_lsb)) & 0xF0) >> 4) + - ( ( ( ((unsigned char) (~ src_lsb)) & 0x0F) +1 ) / 16.0) ) ) * m_factor); - - else - result << static_cast(( (src_msb * 16.0) + ((src_lsb & 0xF0) >> 4) + - ((src_lsb & 0x0F) / 16.0) ) * m_factor); - - return result.str(); -} - -string DecodeBDA::decode() -{ - ostringstream result; - Decode* decode; - short array[3]; - for (int i = 0; i < 3; i++) { - decode = new DecodeBCD(m_data.substr(i*2, 2), "1.0"); - array[i] = static_cast(strtol(decode->decode().c_str(), NULL, 10)); - delete decode; - } - - result << setw(2) << setfill('0') << array[0] << "." - << setw(2) << setfill('0') << array[1] << "." - << array[2] + 2000; - - return result.str(); -} - -string DecodeHDA::decode() -{ - ostringstream result; - short dd = static_cast(strtol(m_data.substr(0, 2).c_str(), NULL, 16)); - short mm = static_cast(strtol(m_data.substr(2, 2).c_str(), NULL, 16)); - short yy = static_cast(strtol(m_data.substr(4, 2).c_str(), NULL, 16)); - - result << setw(2) << setfill('0') << dd << "." - << setw(2) << setfill('0') << mm << "." - << yy + 2000; - - return result.str(); -} - -string DecodeBTI::decode() -{ - ostringstream result; - Decode* decode; - short array[3]; - for (int i = 0; i < 3; i++) { - decode = new DecodeBCD(m_data.substr(i*2, 2), "1.0"); - array[i] = static_cast(strtol(decode->decode().c_str(), NULL, 10)); - delete decode; - } - - result << setw(2) << setfill('0') << array[0] << ":" - << setw(2) << setfill('0') << array[1] << ":" - << setw(2) << setfill('0') << array[2]; - - return result.str(); -} - -string DecodeHTI::decode() -{ - ostringstream result; - short hh = static_cast(strtol(m_data.substr(0, 2).c_str(), NULL, 16)); - short mm = static_cast(strtol(m_data.substr(2, 2).c_str(), NULL, 16)); - short ss = static_cast(strtol(m_data.substr(4, 2).c_str(), NULL, 16)); - - result << setw(2) << setfill('0') << hh << ":" - << setw(2) << setfill('0') << mm << ":" - << setw(2) << setfill('0') << ss; - - return result.str(); -} - -string DecodeBDY::decode() -{ - const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; - - ostringstream result; - short day = static_cast(strtol(m_data.c_str(), NULL, 16)); - - if (day < 0 || day > 6) - day = 7; - - result << days[day]; - - return result.str(); -} - -string DecodeHDY::decode() -{ - const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; - - ostringstream result; - short day = static_cast(strtol(m_data.c_str(), NULL, 16)) - 1; - - if (day < 0 || day > 6) - day = 7; - - result << days[day]; - - return result.str(); -} - -string DecodeTTM::decode() -{ - ostringstream result; - short hh = static_cast(strtol(m_data.c_str(), NULL, 16)) / 6; - short mm = static_cast(strtol(m_data.c_str(), NULL, 16)) % 6 * 10; - - result << setw(2) << setfill('0') << hh << ":" - << setw(2) << setfill('0') << mm; - - return result.str(); -} - diff --git a/src/lib/ebus/decode.h b/src/lib/ebus/decode.h deleted file mode 100644 index 73c8d2a4..00000000 --- a/src/lib/ebus/decode.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef LIBEBUS_DECODE_H_ -#define LIBEBUS_DECODE_H_ - -#include - -using namespace std; - -class Decode -{ - -public: - Decode(const string& data, const string& factor = ""); - virtual ~Decode() {} - - virtual string decode() = 0; - -protected: - string m_data; - float m_factor; - -}; - - -class DecodeHEX : public Decode -{ - -public: - DecodeHEX(const string& data) : Decode(data) {} - ~DecodeHEX() {} - - string decode(); - -}; - -class DecodeUCH : public Decode -{ - -public: - DecodeUCH(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeUCH() {} - - string decode(); - -}; - -class DecodeSCH : public Decode -{ - -public: - DecodeSCH(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeSCH() {} - - string decode(); - -}; - -class DecodeUIN : public Decode -{ - -public: - DecodeUIN(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeUIN() {} - - string decode(); - -}; - -class DecodeSIN : public Decode -{ - -public: - DecodeSIN(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeSIN() {} - - string decode(); - -}; - -class DecodeULG : public Decode -{ - -public: - DecodeULG(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeULG() {} - - string decode(); - -}; - -class DecodeSLG : public Decode -{ - -public: - DecodeSLG(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeSLG() {} - - string decode(); - -}; - -class DecodeFLT : public Decode -{ - -public: - DecodeFLT(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeFLT() {} - - string decode(); - -}; - -class DecodeSTR : public Decode -{ - -public: - DecodeSTR(string data) : Decode(data) {} - ~DecodeSTR() {} - - string decode(); - -}; - -class DecodeBCD : public Decode -{ - -public: - DecodeBCD(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeBCD() {} - - string decode(); - -}; - -class DecodeD1B : public Decode -{ - -public: - DecodeD1B(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeD1B() {} - - string decode(); - -}; - -class DecodeD1C : public Decode -{ - -public: - DecodeD1C(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeD1C() {} - - string decode(); - -}; - -class DecodeD2B : public Decode -{ - -public: - DecodeD2B(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeD2B() {} - - string decode(); - -}; - -class DecodeD2C : public Decode -{ - -public: - DecodeD2C(const string& data, const string& factor) - : Decode(data, factor) {} - ~DecodeD2C() {} - - string decode(); - -}; - -class DecodeBDA : public Decode -{ - -public: - DecodeBDA(const string& data) : Decode(data) {} - ~DecodeBDA() {} - - string decode(); - -}; - -class DecodeHDA : public Decode -{ - -public: - DecodeHDA(const string& data) : Decode(data) {} - ~DecodeHDA() {} - - string decode(); - -}; - -class DecodeBTI : public Decode -{ - -public: - DecodeBTI(const string& data) : Decode(data) {} - ~DecodeBTI() {} - - string decode(); - -}; - -class DecodeHTI : public Decode -{ - -public: - DecodeHTI(const string& data) : Decode(data) {} - ~DecodeHTI() {} - - string decode(); - -}; - -class DecodeBDY : public Decode -{ - -public: - DecodeBDY(const string& data) : Decode(data) {} - ~DecodeBDY() {} - - string decode(); - -}; - -class DecodeHDY : public Decode -{ - -public: - DecodeHDY(const string& data) : Decode(data) {} - ~DecodeHDY() {} - - string decode(); - -}; - -class DecodeTTM : public Decode -{ - -public: - DecodeTTM(const string& data) : Decode(data) {} - ~DecodeTTM() {} - - string decode(); - -}; - -#endif // LIBEBUS_DECODE_H_ diff --git a/src/lib/ebus/encode.cpp b/src/lib/ebus/encode.cpp deleted file mode 100644 index 42b58dc2..00000000 --- a/src/lib/ebus/encode.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#include "encode.h" -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -Encode::Encode(const string& data, const string& factor) - : m_data(data) -{ - if ((factor.find_first_not_of("0123456789.") == string::npos) == true) - m_factor = static_cast(strtod(factor.c_str(), NULL)); - else - m_factor = 1.0; -} - - -string EncodeHEX::encode() -{ - m_data.erase(remove_if(m_data.begin(), m_data.end(), ::isspace), m_data.end()); - - return m_data; -} - -string EncodeUCH::encode() -{ - ostringstream result; - unsigned short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << setw(2) << hex << setfill('0') << src; - - return result.str().substr(result.str().length()-2,2); -} - -string EncodeSCH::encode() -{ - ostringstream result; - short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - - if (src < -127 || src > 127) - result << setw(2) << hex << setfill('0') - << static_cast(0x80); - else - result << setw(2) << hex << setfill('0') - << static_cast(src); - - return result.str().substr(result.str().length()-2,2); -} - -string EncodeUIN::encode() -{ - ostringstream result; - unsigned short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << setw(4) << hex << setfill('0') << src; - - return result.str().substr(2,2) + result.str().substr(0,2); -} - -string EncodeSIN::encode() -{ - ostringstream result; - short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << setw(4) << hex << setfill('0') << src; - - return result.str().substr(2,2) + result.str().substr(0,2); -} - -string EncodeULG::encode() -{ - ostringstream result; - unsigned long src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << setw(8) << hex << setfill('0') << src; - - return result.str().substr(6,2) + result.str().substr(4,2) + - result.str().substr(2,2) + result.str().substr(0,2); -} - -string EncodeSLG::encode() -{ - ostringstream result; - int src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << setw(8) << hex << setfill('0') << src; - - return result.str().substr(6,2) + result.str().substr(4,2) + - result.str().substr(2,2) + result.str().substr(0,2); -} - -string EncodeFLT::encode() -{ - ostringstream result; - short src = static_cast(strtod(m_data.c_str(), NULL) * 1000.0 / m_factor); - result << setw(4) << hex << setfill('0') << src; - - return result.str().substr(2,2) + result.str().substr(0,2); -} - -string EncodeSTR::encode() -{ - ostringstream result; - - for (size_t i = 0; i < m_data.length(); i++) - result << setw(2) << hex << setfill('0') << static_cast(m_data[i]); - - return result.str(); -} - -string EncodeBCD::encode() -{ - ostringstream result; - short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - - if (src > 99) - result << setw(2) << hex << setfill('0') - << static_cast(0xFF); - else - result << setw(2) << hex << setfill('0') - << static_cast( ((src / 10) << 4) | (src % 10) ); - - return result.str().substr(result.str().length()-2,2); -} - -string EncodeD1B::encode() -{ - ostringstream result; - short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - - if (src < -127 || src > 127) - result << setw(2) << hex << setfill('0') - << static_cast(0x80); - else - result << setw(2) << hex << setfill('0') - << static_cast(src); - - return result.str().substr(result.str().length()-2,2); -} - -string EncodeD1C::encode() -{ - ostringstream result; - float src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - - if (src < 0.0 || src > 100.0) - result << setw(2) << hex << setfill('0') - << static_cast(0xFF); - else - result << setw(2) << hex << setfill('0') - << static_cast(src * 2.0); - - return result.str(); -} - -string EncodeD2B::encode() -{ - ostringstream result; - float src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - - if (src < -127.999 || src > 127.999) { - result << setw(2) << hex << setfill('0') - << static_cast(0x80) - << setw(2) << hex << setfill('0') - << static_cast(0x00); - } else { - unsigned char tgt_lsb = static_cast((src - ((short) src)) * 256.0); - unsigned char tgt_msb; - - if (src < 0.0 && tgt_lsb != 0x00) - tgt_msb = static_cast((short) src - 1); - else - tgt_msb = static_cast((short) src); - - result << setw(2) << hex << setfill('0') - << static_cast(tgt_msb) - << setw(2) << hex << setfill('0') - << static_cast(tgt_lsb); - } - - return result.str(); -} - -string EncodeD2C::encode() -{ - ostringstream result; - float src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - - if (src < -2047.999 || src > 2047.999) { - result << setw(2) << hex << setfill('0') - << static_cast(0x80) - << setw(2) << hex << setfill('0') - << static_cast(0x00); - } else { - unsigned char tgt_lsb = static_cast( - ((unsigned char) ( ((short) src) % 16) << 4) + - ((unsigned char) ( (src - ((short) src)) * 16.0)) ); - - unsigned char tgt_msb; - - if (src < 0.0 && tgt_lsb != 0x00) - tgt_msb = static_cast((short) (src / 16.0) - 1); - else - tgt_msb = static_cast((short) src / 16.0); - - result << setw(2) << hex << setfill('0') - << static_cast(tgt_msb) - << setw(2) << hex << setfill('0') - << static_cast(tgt_lsb); - } - - return result.str(); -} - -string EncodeBDA::encode() -{ - // prepare data - string token; - istringstream stream(m_data); - vector data; - - while (getline(stream, token, '.') != 0) - data.push_back(token); - - ostringstream result; - result << setw(2) << dec << setfill('0') - << static_cast(strtod(data[0].c_str(), NULL)) - << setw(2) << dec << setfill('0') - << static_cast(strtod(data[1].c_str(), NULL)) - << setw(2) << dec << setfill('0') - << static_cast(strtod(data[2].c_str(), NULL) - 2000); - - return result.str(); -} - -string EncodeHDA::encode() -{ - // prepare data - string token; - istringstream stream(m_data); - vector data; - - while (getline(stream, token, '.') != 0) - data.push_back(token); - - ostringstream result; - result << setw(2) << hex << setfill('0') - << static_cast(strtod(data[0].c_str(), NULL)) - << setw(2) << hex << setfill('0') - << static_cast(strtod(data[1].c_str(), NULL)) - << setw(2) << hex << setfill('0') - << static_cast(strtod(data[2].c_str(), NULL) - 2000); - - return result.str(); -} - -string EncodeBTI::encode() -{ - // prepare data - string token; - istringstream stream(m_data); - vector data; - - while (getline(stream, token, ':') != 0) - data.push_back(token); - - ostringstream result; - result << setw(2) << dec << setfill('0') - << static_cast(strtod(data[0].c_str(), NULL)) - << setw(2) << dec << setfill('0') - << static_cast(strtod(data[1].c_str(), NULL)) - << setw(2) << dec << setfill('0') - << static_cast(strtod(data[2].c_str(), NULL)); - - return result.str(); -} - -string EncodeHTI::encode() -{ - // prepare data - string token; - istringstream stream(m_data); - vector data; - - while (getline(stream, token, ':') != 0) - data.push_back(token); - - ostringstream result; - result << setw(2) << hex << setfill('0') - << static_cast(strtod(data[0].c_str(), NULL)) - << setw(2) << hex << setfill('0') - << static_cast(strtod(data[1].c_str(), NULL)) - << setw(2) << hex << setfill('0') - << static_cast(strtod(data[2].c_str(), NULL)); - - return result.str(); -} - -string EncodeBDY::encode() -{ - const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; - short day = 7; - - for (short i = 0; i < 7; i++) - if (strcasecmp(days[i], m_data.c_str()) == 0) - day = i; - - ostringstream result; - result << setw(2) << hex << setfill('0') << day; - - return result.str(); -} - -string EncodeHDY::encode() -{ - const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; - short day = 8; - - for (short i = 0; i < 7; i++) - if (strcasecmp(days[i], m_data.c_str()) == 0) - day = i + 1; - - ostringstream result; - result << setw(2) << hex << setfill('0') << day; - - return result.str(); -} - -string EncodeTTM::encode() -{ - // prepare data - string token; - istringstream stream(m_data); - vector data; - - while (getline(stream, token, ':') != 0) - data.push_back(token); - - ostringstream result; - result << setw(2) << hex << setfill('0') - << static_cast( (strtod(data[0].c_str(), NULL) * 6) - + (strtod(data[1].c_str(), NULL) / 10) ); - - return result.str(); -} - diff --git a/src/lib/ebus/encode.h b/src/lib/ebus/encode.h deleted file mode 100644 index e5367086..00000000 --- a/src/lib/ebus/encode.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (C) Roland Jax 2012-2014 - * - * This file is part of ebusd. - * - * ebusd is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ebusd is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ebusd. If not, see http://www.gnu.org/licenses/. - */ - -#ifndef LIBEBUS_ENCODE_H_ -#define LIBEBUS_ENCODE_H_ - -#include - -using namespace std; - -class Encode -{ - -public: - Encode(const string& data, const string& factor = ""); - virtual ~Encode() {} - - virtual string encode() = 0; - -protected: - string m_data; - float m_factor; - -}; - - -class EncodeHEX : public Encode -{ - -public: - EncodeHEX(const string& data) : Encode(data) {} - ~EncodeHEX() {} - - string encode(); - -}; - -class EncodeUCH : public Encode -{ - -public: - EncodeUCH(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeUCH() {} - - string encode(); - -}; - -class EncodeSCH : public Encode -{ - -public: - EncodeSCH(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeSCH() {} - - string encode(); - -}; - -class EncodeUIN : public Encode -{ - -public: - EncodeUIN(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeUIN() {} - - string encode(); - -}; - -class EncodeSIN : public Encode -{ - -public: - EncodeSIN(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeSIN() {} - - string encode(); - -}; - -class EncodeULG : public Encode -{ - -public: - EncodeULG(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeULG() {} - - string encode(); - -}; - -class EncodeSLG : public Encode -{ - -public: - EncodeSLG(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeSLG() {} - - string encode(); - -}; - -class EncodeFLT : public Encode -{ - -public: - EncodeFLT(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeFLT() {} - - string encode(); - -}; - -class EncodeSTR : public Encode -{ - -public: - EncodeSTR(const string& data) : Encode(data) {} - ~EncodeSTR() {} - - string encode(); - -}; - -class EncodeBCD : public Encode -{ - -public: - EncodeBCD(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeBCD() {} - - string encode(); - -}; - -class EncodeD1B : public Encode -{ - -public: - EncodeD1B(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeD1B() {} - - string encode(); - -}; - -class EncodeD1C : public Encode -{ - -public: - EncodeD1C(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeD1C() {} - - string encode(); - -}; - -class EncodeD2B : public Encode -{ - -public: - EncodeD2B(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeD2B() {} - - string encode(); - -}; - -class EncodeD2C : public Encode -{ - -public: - EncodeD2C(const string& data, const string& factor) - : Encode(data, factor) {} - ~EncodeD2C() {} - - string encode(); - -}; - -class EncodeBDA : public Encode -{ - -public: - EncodeBDA(const string& data) : Encode(data) {} - ~EncodeBDA() {} - - string encode(); - -}; - -class EncodeHDA : public Encode -{ - -public: - EncodeHDA(const string& data) : Encode(data) {} - ~EncodeHDA() {} - - string encode(); - -}; - -class EncodeBTI : public Encode -{ - -public: - EncodeBTI(const string& data) : Encode(data) {} - ~EncodeBTI() {} - - string encode(); - -}; - -class EncodeHTI : public Encode -{ - -public: - EncodeHTI(const string& data) : Encode(data) {} - ~EncodeHTI() {} - - string encode(); - -}; - -class EncodeBDY : public Encode -{ - -public: - EncodeBDY(const string& data) : Encode(data) {} - ~EncodeBDY() {} - - string encode(); - -}; - -class EncodeHDY : public Encode -{ - -public: - EncodeHDY(const string& data) : Encode(data) {} - ~EncodeHDY() {} - - string encode(); - -}; - -class EncodeTTM : public Encode -{ - -public: - EncodeTTM(const string& data) : Encode(data) {} - ~EncodeTTM() {} - - string encode(); - -}; - -#endif // LIBEBUS_ENCODE_H_