diff --git a/src/ebusctl/ebusctl.cpp b/src/ebusctl/ebusctl.cpp index 930e6ede..da642266 100644 --- a/src/ebusctl/ebusctl.cpp +++ b/src/ebusctl/ebusctl.cpp @@ -30,6 +30,8 @@ #include #include +using namespace std; + Appl& A = Appl::Instance(true); void define_args() @@ -66,21 +68,21 @@ int main(int argc, char* argv[]) A.parseArgs(argc, argv); if (strcasecmp(A.getArg(0).c_str(), "feed") == 0) { - std::string dev(A.getOptVal("device")); + string dev(A.getOptVal("device")); Port port(dev, true); port.open(); if(port.isOpen() == true) { - std::cout << "openPort successful." << std::endl; + cout << "openPort successful." << endl; - std::fstream file(A.getOptVal("file"), std::ios::in | std::ios::binary); + fstream file(A.getOptVal("file"), ios::in | ios::binary); - if(file.is_open() == true) { + if (file.is_open() == true) { while (file.eof() == false) { unsigned char byte = file.get(); - std::cout << std::hex << std::setw(2) << std::setfill('0') - << static_cast(byte) << std::endl; + cout << hex << setw(2) << setfill('0') + << static_cast(byte) << endl; port.send(&byte, 1); usleep(A.getOptVal("time")); @@ -89,13 +91,13 @@ int main(int argc, char* argv[]) file.close(); } else - std::cout << "error opening file " << A.getOptVal("file") << std::endl; + cout << "error opening file " << A.getOptVal("file") << endl; port.close(); if(port.isOpen() == false) - std::cout << "closePort successful." << std::endl; + cout << "closePort successful." << endl; } else - std::cout << "error opening device " << A.getOptVal("device") << std::endl; + cout << "error opening device " << A.getOptVal("device") << endl; } else { @@ -104,7 +106,7 @@ int main(int argc, char* argv[]) if (socket != NULL) { // build message - std::string message(A.getArg(0)); + string message(A.getArg(0)); for (int i = 1; i < A.numArgs(); i++) { message += " "; message += A.getArg(i); @@ -118,13 +120,13 @@ int main(int argc, char* argv[]) datalen = socket->recv(data, sizeof(data)-1); data[datalen] = '\0'; - std::cout << data; + cout << data; delete socket; } else - std::cout << "error connecting to " << A.getOptVal("server") - << ":" << A.getOptVal("port") << std::endl; + cout << "error connecting to " << A.getOptVal("server") + << ":" << A.getOptVal("port") << endl; delete client; } diff --git a/src/ebusd/baseloop.cpp b/src/ebusd/baseloop.cpp index 40fbadd7..6bcf1958 100644 --- a/src/ebusd/baseloop.cpp +++ b/src/ebusd/baseloop.cpp @@ -22,6 +22,8 @@ #include "logger.h" #include "appl.h" +using namespace std; + extern Logger& L; extern Appl& A; @@ -64,14 +66,14 @@ BaseLoop::~BaseLoop() void BaseLoop::start() { for (;;) { - std::string result; + string result; // recv new message from client NetMessage* message = m_netQueue.remove(); - std::string data = message->getData(); + string data = message->getData(); - data.erase(std::remove(data.begin(), data.end(), '\r'), data.end()); - data.erase(std::remove(data.begin(), data.end(), '\n'), data.end()); + data.erase(remove(data.begin(), data.end(), '\r'), data.end()); + data.erase(remove(data.begin(), data.end(), '\n'), data.end()); L.log(bas, event, ">>> %s", data.c_str()); @@ -94,18 +96,18 @@ void BaseLoop::start() } } -std::string BaseLoop::decodeMessage(const std::string& data) +string BaseLoop::decodeMessage(const string& data) { - std::ostringstream result; - std::string cycdata, polldata; + ostringstream result; + string cycdata, polldata; int index; // prepare data - std::string token; - std::istringstream stream(data); - std::vector cmd; + string token; + istringstream stream(data); + vector cmd; - while (std::getline(stream, token, ' ') != 0) + while (getline(stream, token, ' ') != 0) cmd.push_back(token); if (cmd.size() == 0) @@ -145,9 +147,9 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; } - std::string busCommand(A.getOptVal("address")); + string busCommand(A.getOptVal("address")); busCommand += m_commands->getBusCommand(index); - std::transform(busCommand.begin(), busCommand.end(), busCommand.begin(), tolower); + transform(busCommand.begin(), busCommand.end(), busCommand.begin(), ::tolower); BusMessage* message = new BusMessage(busCommand, false, false); L.log(bas, trace, " msg: %s", busCommand.c_str()); @@ -186,12 +188,12 @@ std::string BaseLoop::decodeMessage(const std::string& data) if (index >= 0) { - std::string busCommand(A.getOptVal("address")); + string busCommand(A.getOptVal("address")); busCommand += m_commands->getBusCommand(index); // encode data Command* command = new Command(index, (*m_commands)[index], cmd[3]); - std::string value = command->calcData(); + string value = command->calcData(); if (value[0] != '-') { busCommand += value; } else { @@ -200,7 +202,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; } - std::transform(busCommand.begin(), busCommand.end(), busCommand.begin(), tolower); + transform(busCommand.begin(), busCommand.end(), busCommand.begin(), ::tolower); BusMessage* message = new BusMessage(busCommand, false, false); L.log(bas, event, " msg: %s", busCommand.c_str()); @@ -266,10 +268,10 @@ std::string BaseLoop::decodeMessage(const std::string& data) } { - std::string busCommand(A.getOptVal("address")); - cmd[1].erase(std::remove_if(cmd[1].begin(), cmd[1].end(), isspace), cmd[1].end()); + string busCommand(A.getOptVal("address")); + cmd[1].erase(remove_if(cmd[1].begin(), cmd[1].end(), ::isspace), cmd[1].end()); busCommand += cmd[1]; - std::transform(busCommand.begin(), busCommand.end(), busCommand.begin(), tolower); + transform(busCommand.begin(), busCommand.end(), busCommand.begin(), ::tolower); BusMessage* message = new BusMessage(busCommand, false, false); L.log(bas, trace, " msg: %s", busCommand.c_str()); @@ -305,19 +307,19 @@ std::string BaseLoop::decodeMessage(const std::string& data) if (strcasecmp(cmd[1].c_str(), "RESULT") == 0) { // TODO format scan results for (size_t i = 0; i < m_commands->sizeScanDB(); i++) - result << m_commands->getScanData(i) << std::endl; + result << m_commands->getScanData(i) << endl; break; } - result << "usage: 'scan'" << std::endl - << " 'scan full'" << std::endl + result << "usage: 'scan'" << endl + << " 'scan full'" << endl << " 'scan result'"; break; case ct_log: if (cmd.size() != 3 ) { - result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl + result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << endl << " 'log level level' (level: error|event|trace|debug)"; break; } @@ -335,7 +337,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; } - result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl + result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << endl << " 'log level level' (level: error|event|trace|debug)"; break; @@ -383,21 +385,21 @@ std::string BaseLoop::decodeMessage(const std::string& data) } case ct_help: - result << "commands:" << std::endl - << " get - fetch ebus data 'get class cmd (sub)'" << std::endl - << " set - set ebus values 'set class cmd value'" << std::endl - << " 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 - << " - 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 - << " dump - toggle dump state 'dump'" << std::endl << std::endl - << " reload - reload ebus configuration 'reload'" << std::endl << std::endl - << " stop - stop daemon 'stop'" << std::endl - << " quit - close connection 'quit'" << std::endl << std::endl + result << "commands:" << endl + << " get - fetch ebus data 'get class cmd (sub)'" << endl + << " set - set ebus values 'set class cmd value'" << endl + << " cyc - fetch cycle data 'cyc class cmd (sub)'" << endl + << " hex - send given hex value 'hex type value' (value: ZZPBSBNNDx)" << endl << endl + << " scan - scan ebus kown addresses 'scan'" << endl + << " - scan ebus all addresses 'scan full'" << endl + << " - show results 'scan result'" << endl << endl + << " log - change log areas 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << endl + << " - change log level 'log level level' (level: error|event|trace|debug)" << endl << endl + << " raw - toggle log raw data 'raw'" << endl + << " dump - toggle dump state 'dump'" << endl << endl + << " reload - reload ebus configuration 'reload'" << endl << endl + << " stop - stop daemon 'stop'" << endl + << " quit - close connection 'quit'" << endl << endl << " help - print this page 'help'"; break; diff --git a/src/ebusd/baseloop.h b/src/ebusd/baseloop.h index 20cb833c..d45556ba 100644 --- a/src/ebusd/baseloop.h +++ b/src/ebusd/baseloop.h @@ -24,6 +24,8 @@ #include "network.h" #include "busloop.h" +using namespace std; + /** \file baseloop.h */ /** possible client commands */ @@ -87,7 +89,7 @@ private: * @param item the client command to compare. * @return the founded client command type. */ - CommandType getCase(const std::string& item) + CommandType getCase(const string& item) { if (strcasecmp(item.c_str(), "GET") == 0) return ct_get; if (strcasecmp(item.c_str(), "SET") == 0) return ct_set; @@ -108,7 +110,7 @@ private: * @param data the data string to decode * @return result string to send back to client */ - std::string decodeMessage(const std::string& data); + string decodeMessage(const string& data); }; diff --git a/src/ebusd/busloop.cpp b/src/ebusd/busloop.cpp index ba854569..06292767 100644 --- a/src/ebusd/busloop.cpp +++ b/src/ebusd/busloop.cpp @@ -23,10 +23,12 @@ #include #include +using namespace std; + extern Logger& L; extern Appl& A; -BusMessage::BusMessage(const std::string command, const bool poll, const bool scan) +BusMessage::BusMessage(const string command, const bool poll, const bool scan) : m_poll(poll), m_scan(scan), m_command(command), m_result(), m_resultCode(RESULT_OK) { unsigned char dstAddress = m_command[1]; @@ -42,9 +44,9 @@ BusMessage::BusMessage(const std::string command, const bool poll, const bool sc pthread_cond_init(&m_cond, NULL); } -const std::string BusMessage::getMessageStr() +const string BusMessage::getMessageStr() { - std::string result; + string result; if (m_resultCode >= 0) { if (m_type == masterSlave) { @@ -57,7 +59,7 @@ const std::string BusMessage::getMessageStr() result = "success"; } else - result = "error: "+std::string(getResultCodeCStr()); + result = "error: "+string(getResultCodeCStr()); return result; } @@ -154,7 +156,7 @@ void* BusLoop::run() if (sendRetries < m_sendRetries) { sendRetries++; L.log(bus, trace, " send retry %d", sendRetries); - message->setResult(std::string(), RESULT_OK); + message->setResult(string(), RESULT_OK); } else { sendRetries = 0; @@ -233,7 +235,7 @@ int BusLoop::writeDumpFile(const char* byte) { int ret = 0; - std::ofstream fs(m_dumpFile.c_str(), std::ios::out | std::ios::binary | std::ios::app); + ofstream fs(m_dumpFile.c_str(), ios::out | ios::binary | ios::app); if (fs == 0) return -1; @@ -241,7 +243,7 @@ int BusLoop::writeDumpFile(const char* byte) fs.write(byte, 1); if (fs.tellp() >= m_dumpSize * 1024) { - std::string oldfile; + string oldfile; oldfile += m_dumpFile; oldfile += ".old"; ret = rename(m_dumpFile.c_str(), oldfile.c_str()); @@ -322,7 +324,7 @@ void BusLoop::analyseCycData() L.log(cyc, debug, " search skipped - string too short"); } else { - std::string tmp; + string tmp; tmp += (*m_commands)[index][1]; tmp += " "; tmp += (*m_commands)[index][2]; @@ -339,7 +341,7 @@ void BusLoop::analyseCycData() void BusLoop::collectSlave() { - std::vector::iterator it; + vector::iterator it; for (int i = 0; i < 2; i++) { bool found = false; @@ -423,7 +425,7 @@ int BusLoop::acquireBus() BusMessage* BusLoop::sendCommand() { unsigned char recvByte; - std::string result; + string result; SymbolString slaveData; int retval = RESULT_OK; @@ -638,15 +640,15 @@ void BusLoop::addPollMessage() } else { // TODO: implement as methode from class commands? - std::string tmp; + 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 busCommand(A.getOptVal("address")); + string busCommand(A.getOptVal("address")); busCommand += m_commands->getBusCommand(index); - std::transform(busCommand.begin(), busCommand.end(), busCommand.begin(), tolower); + transform(busCommand.begin(), busCommand.end(), busCommand.begin(), ::tolower); BusMessage* message = new BusMessage(busCommand, true, false); L.log(bus, trace, " msg: %s", busCommand.c_str()); @@ -657,22 +659,22 @@ void BusLoop::addPollMessage() void BusLoop::addScanMessage() { - std::string busCommand(A.getOptVal("address")); - std::stringstream sstr; + string busCommand(A.getOptVal("address")); + stringstream sstr; if (m_scanFull == true) { for (; m_scanIndex <= 0xFF; m_scanIndex++) { if (isMaster(m_scanIndex) == false && m_scanIndex != SYN && m_scanIndex != ESC && m_scanIndex != BROADCAST) { - sstr << std::nouppercase << std::setw(2) << std::setfill('0') - << std::hex << m_scanIndex; + sstr << nouppercase << setw(2) << setfill('0') + << hex << m_scanIndex; break; } } } else { - sstr << std::nouppercase << std::setw(2) << std::setfill('0') - << std::hex << static_cast(m_slave[m_scanIndex]); + sstr << nouppercase << setw(2) << setfill('0') + << hex << static_cast(m_slave[m_scanIndex]); if (m_scanIndex+1 >= m_slave.size()) m_scan = false; @@ -685,7 +687,7 @@ void BusLoop::addScanMessage() busCommand += sstr.str(); busCommand += "070400"; - std::transform(busCommand.begin(), busCommand.end(), busCommand.begin(), tolower); + transform(busCommand.begin(), busCommand.end(), busCommand.begin(), ::tolower); L.log(bus, event, " scanning address %s", sstr.str().c_str()); diff --git a/src/ebusd/busloop.h b/src/ebusd/busloop.h index bc0f56b4..ec18ebc3 100644 --- a/src/ebusd/busloop.h +++ b/src/ebusd/busloop.h @@ -27,6 +27,8 @@ #include "symbol.h" #include "result.h" +using namespace std; + /** \file busloop.h */ /** the maximum time [us] allowed for retrieving a byte from an addressed slave */ @@ -53,7 +55,7 @@ public: * @param poll true if message type is polling. * @param scan true if message type is scanning. */ - BusMessage(const std::string command, const bool poll, const bool scan); + BusMessage(const string command, const bool poll, const bool scan); /** * @brief destructor. @@ -106,7 +108,7 @@ public: * @brief return the message string or error result string. * @return the message string or error result string. */ - const std::string getMessageStr(); + const string getMessageStr(); /** * @brief return polling flag of message type. @@ -213,7 +215,7 @@ public: * @brief set the name of dump file. * @param dumpFile the file name of dump file. */ - void setDumpFile(const std::string& dumpFile) { m_dumpFile = dumpFile; } + void setDumpFile(const string& dumpFile) { m_dumpFile = dumpFile; } /** * @brief set the max size of dump file. @@ -234,7 +236,7 @@ private: Port* m_port; /** the name of dump file*/ - std::string m_dumpFile; + string m_dumpFile; /** max. size of dump file */ long m_dumpSize; @@ -278,7 +280,7 @@ private: double m_pollInterval; /** vector with collected slave addresses */ - std::vector m_slave; + vector m_slave; /** true if bus scanning for collected slave addresses is active */ bool m_scan; diff --git a/src/ebusd/ebusd.cpp b/src/ebusd/ebusd.cpp index eb98fe9c..fbc85345 100644 --- a/src/ebusd/ebusd.cpp +++ b/src/ebusd/ebusd.cpp @@ -28,6 +28,8 @@ #include #include +using namespace std; + Appl& A = Appl::Instance(); Daemon& D = Daemon::Instance(); Logger& L = Logger::Instance(); diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index f9f99030..f202d22f 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -30,6 +30,7 @@ #include #endif +using namespace std; extern Logger& L; extern Appl& A; @@ -129,7 +130,7 @@ void* Connection::run() message.waitSignal(); L.log(net, debug, "[%05d] result added", getID()); - std::string result = message.getResult(); + string result = message.getResult(); if (m_socket->isValid() == true) m_socket->send(result.c_str(), result.size()); @@ -277,7 +278,7 @@ void* Network::run() void Network::cleanConnections() { - std::list::iterator c_it; + list::iterator c_it; for (c_it = m_connections.begin(); c_it != m_connections.end(); c_it++) { if ((*c_it)->isRunning() == false) { Connection* connection = *c_it; diff --git a/src/ebusd/network.h b/src/ebusd/network.h index 18b02d29..35f6e47f 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -26,6 +26,8 @@ #include "thread.h" #include +using namespace std; + /** forward declaration for class connection */ class Connection; @@ -40,7 +42,7 @@ public: * @brief constructs a new instance with message and source client address. * @param data from client. */ - NetMessage(const std::string data) : m_data(data) + NetMessage(const string data) : m_data(data) { pthread_mutex_init(&m_mutex, NULL); pthread_cond_init(&m_cond, NULL); @@ -65,19 +67,19 @@ public: * @brief get the data string. * @return the data string. */ - std::string getData() const { return m_data; } + string getData() const { return m_data; } /** * @brief get the result string. * @return the result string. */ - std::string getResult() const { return m_result; } + string getResult() const { return m_result; } /** * @brief set the result string. * @return the result string. */ - void setResult(const std::string result) { m_result = result; } + void setResult(const string result) { m_result = result; } /** * @brief wait on notification. @@ -104,10 +106,10 @@ public: private: /** the data string */ - std::string m_data; + string m_data; /** the result string */ - std::string m_result; + string m_result; /** mutex variable for exclusive lock */ pthread_mutex_t m_mutex; @@ -209,7 +211,7 @@ public: private: /** container for active connections */ - std::list m_connections; + list m_connections; /** remote queue for network messages */ WQueue* m_netQueue; diff --git a/src/lib/ebus/command.cpp b/src/lib/ebus/command.cpp index 795a3740..37fefaf4 100644 --- a/src/lib/ebus/command.cpp +++ b/src/lib/ebus/command.cpp @@ -27,7 +27,7 @@ #include #include -std::string Command::calcData() +string Command::calcData() { // encode - only first entry will be encoded // ToDo: if more parts are needed, they will be implemented @@ -39,7 +39,7 @@ std::string Command::calcData() return m_result; } -std::string Command::calcResult(const cmd_t& cmd) +string Command::calcResult(const cmd_t& cmd) { int elements = strtol(m_command[9].c_str(), NULL, 10); @@ -81,10 +81,10 @@ std::string Command::calcResult(const cmd_t& cmd) return m_result; } -void Command::calcSub(const std::string& part, const std::string& position, - const std::string& type, const std::string& factor) +void Command::calcSub(const string& part, const string& position, + const string& type, const string& factor) { - std::string data; + string data; // Master Data if (strcasecmp(part.c_str(), "MD") == 0) { @@ -121,18 +121,18 @@ void Command::calcSub(const std::string& part, const std::string& position, decode(data, position, type, factor); } -void Command::decode(const std::string& data, const std::string& position, - const std::string& type, const std::string& factor) +void Command::decode(const string& data, const string& position, + const string& type, const string& factor) { - std::ostringstream result, value; + ostringstream result, value; Decode* help = NULL; // prepare position - std::string token; - std::istringstream stream(position); - std::vector pos; + string token; + istringstream stream(position); + vector pos; - while (std::getline(stream, token, ',') != 0) + while (getline(stream, token, ',') != 0) pos.push_back(strtol(token.c_str(), NULL, 10)); if (strcasecmp(type.c_str(), "HEX") == 0) { @@ -251,10 +251,10 @@ void Command::decode(const std::string& data, const std::string& position, delete help; } -void Command::encode(const std::string& data, const std::string& type, - const std::string& factor) +void Command::encode(const string& data, const string& type, + const string& factor) { - std::ostringstream result; + ostringstream result; Encode* help = NULL; if (strcasecmp(type.c_str(), "HEX") == 0) { diff --git a/src/lib/ebus/command.h b/src/lib/ebus/command.h index 2c725ce4..b90a374a 100644 --- a/src/lib/ebus/command.h +++ b/src/lib/ebus/command.h @@ -23,7 +23,9 @@ #include #include -typedef std::vector cmd_t; +using namespace std; + +typedef vector cmd_t; typedef cmd_t::const_iterator cmdCI_t; class Command @@ -31,31 +33,31 @@ class Command public: Command(int index, cmd_t command) : m_index(index), m_command(command) {} - Command(int index, cmd_t command, std::string data) + 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 std::string& data) { m_data = data; } - std::string getData() const { return m_data; } - std::string calcData(); + void setData(const string& data) { m_data = data; } + string getData() const { return m_data; } + string calcData(); - std::string calcResult(const cmd_t& cmd); + string calcResult(const cmd_t& cmd); private: int m_index; cmd_t m_command; - std::string m_data; - std::string m_result; - std::string m_error; + string m_data; + string m_result; + string m_error; - void calcSub(const std::string& part, const std::string& position, - const std::string& type, const std::string& factor); + void calcSub(const string& part, const string& position, + const string& type, const string& factor); - void decode(const std::string& data, const std::string& position, - const std::string& type, const std::string& factor); + void decode(const string& data, const string& position, + const string& type, const string& factor); - void encode(const std::string& data, const std::string& type, - const std::string& factor); + void encode(const string& data, const string& type, + const string& factor); }; diff --git a/src/lib/ebus/commands.cpp b/src/lib/ebus/commands.cpp index dfb0ee28..3f781799 100644 --- a/src/lib/ebus/commands.cpp +++ b/src/lib/ebus/commands.cpp @@ -25,6 +25,8 @@ #include #include +using namespace std; + Commands::~Commands() { for (mapCI_t iter = m_pollDB.begin(); iter != m_pollDB.end(); ++iter) @@ -62,26 +64,26 @@ void Commands::printCommands() const for (cmdDBCI_t i = m_cmdDB.begin(); i != m_cmdDB.end(); i++) { printCommand(*i); - std::cout << std::endl; + cout << endl; } } -int Commands::findCommand(const std::string& data) const +int Commands::findCommand(const string& data) const { // no commands definend if (m_cmdDB.size() == 0) return -2; // preapre string for searching command - std::string token; - std::istringstream isstr(data); - std::vector cmd; + string token; + istringstream isstr(data); + vector cmd; // split stream - while (std::getline(isstr, token, ' ') != 0) + while (getline(isstr, token, ' ') != 0) cmd.push_back(token); - std::size_t index; + size_t index; cmdDBCI_t i = m_cmdDB.begin(); // walk through commands - GET @@ -123,25 +125,25 @@ int Commands::findCommand(const std::string& data) const return -1; } -std::string Commands::getBusCommand(const int index) const +string Commands::getBusCommand(const int index) const { cmd_t command = m_cmdDB.at(index); - std::string cmd; - std::stringstream sstr; + 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 << std::setw(2) << std::hex << std::setfill('0') << command[7]; + sstr << setw(2) << hex << setfill('0') << command[7]; cmd += sstr.str(); // NN cmd += command[8]; // Dx return cmd; } -int Commands::storeCycData(const std::string& data) const +int Commands::storeCycData(const string& data) const { // no commands defined if (m_cycDB.size() == 0) @@ -152,14 +154,14 @@ int Commands::storeCycData(const std::string& data) const return -3; // prepare string for searching command - std::string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2)); + 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++) { - std::string command = getBusCommand(iter->first); + string command = getBusCommand(iter->first); // skip wrong search string length if (command.length() > search.length()) @@ -175,7 +177,7 @@ int Commands::storeCycData(const std::string& data) const return -1; } -std::string Commands::getCycData(int index) const +string Commands::getCycData(int index) const { mapCI_t iter = m_cycDB.find(index); if (iter != m_cycDB.end()) @@ -202,17 +204,17 @@ int Commands::nextPollCommand() return -1; } -void Commands::storePollData(const std::string& data) const +void Commands::storePollData(const 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)); + 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++) { - std::string command = getBusCommand(iter->first); + string command = getBusCommand(iter->first); // skip wrong search string length if (command.length() > search.length()) @@ -224,7 +226,7 @@ void Commands::storePollData(const std::string& data) const } } -std::string Commands::getPollData(const int index) const +string Commands::getPollData(const int index) const { mapCI_t iter = m_pollDB.find(index); if (iter != m_pollDB.end()) @@ -233,9 +235,9 @@ std::string Commands::getPollData(const int index) const return ""; } -void Commands::storeScanData(const std::string& data) +void Commands::storeScanData(const string& data) { - std::vector::const_iterator iter = m_scanDB.begin(); + vector::const_iterator iter = m_scanDB.begin(); bool found = false; // walk through scan data @@ -253,6 +255,6 @@ void Commands::printCommand(const cmd_t& command) const return; for (cmdCI_t i = command.begin(); i != command.end(); i++) - std::cout << *i << ';'; + cout << *i << ';'; } diff --git a/src/lib/ebus/commands.h b/src/lib/ebus/commands.h index d927b15c..a696a955 100644 --- a/src/lib/ebus/commands.h +++ b/src/lib/ebus/commands.h @@ -25,12 +25,14 @@ #include #include -typedef std::vector cmdDB_t; +using namespace std; + +typedef vector cmdDB_t; typedef cmdDB_t::const_iterator cmdDBCI_t; -typedef std::map map_t; +typedef map map_t; typedef map_t::const_iterator mapCI_t; -typedef std::pair pair_t; +typedef pair pair_t; class Commands { @@ -42,34 +44,34 @@ public: void addCommand(const cmd_t& command); void printCommands() const; - std::size_t sizeCmdDB() const { return m_cmdDB.size(); } - std::size_t sizeCycDB() const { return m_cycDB.size(); } - std::size_t sizePollDB() const { return m_pollDB.size(); } - std::size_t sizeScanDB() const { return m_scanDB.size(); } + 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 std::size_t& index) const { return m_cmdDB[index]; } + cmd_t const& operator[](const size_t& index) const { return m_cmdDB[index]; } - int findCommand(const std::string& data) const; + int findCommand(const string& data) const; - std::string getCmdType(const int index) const { return std::string(m_cmdDB.at(index)[0]); } - std::string getBusCommand(const int index) const; + string getCmdType(const int index) const { return string(m_cmdDB.at(index)[0]); } + string getBusCommand(const int index) const; - int storeCycData(const std::string& data) const; - std::string getCycData(int index) const; + int storeCycData(const string& data) const; + string getCycData(int index) const; int nextPollCommand(); - void storePollData(const std::string& data) const; - std::string getPollData(const int index) const; + void storePollData(const string& data) const; + string getPollData(const int index) const; - void storeScanData(const std::string& data); - std::string getScanData(const int index) const { return m_scanDB[index]; } + 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; - std::vector m_scanDB; + vector m_scanDB; void printCommand(const cmd_t& command) const; diff --git a/src/lib/ebus/configfile.cpp b/src/lib/ebus/configfile.cpp index eddf4dba..11019af0 100644 --- a/src/lib/ebus/configfile.cpp +++ b/src/lib/ebus/configfile.cpp @@ -22,19 +22,21 @@ #include #include -void ConfigFileCSV::parse(std::istream& is, Commands& commands) +using namespace std; + +void ConfigFileCSV::parse(istream& is, Commands& commands) { - std::string line; + string line; // read lines - while (std::getline(is, line) != 0) { + while (getline(is, line) != 0) { cmd_t row; - std::string column; + string column; - std::istringstream isstr(line); + istringstream isstr(line); // walk through columns - while (std::getline(isstr, column, ';') != 0) + while (getline(isstr, column, ';') != 0) row.push_back(column); // skip empty and commented rows @@ -46,7 +48,7 @@ void ConfigFileCSV::parse(std::istream& is, Commands& commands) }; -ConfigCommands::ConfigCommands(const std::string path, const FileType type) +ConfigCommands::ConfigCommands(const string path, const FileType type) { m_path = path; m_configfile = NULL; @@ -70,10 +72,10 @@ void ConfigCommands::setType(const FileType type) Commands* ConfigCommands::getCommands() { Commands* commands = new Commands(); - std::vector::const_iterator i = m_files.begin(); + vector::const_iterator i = m_files.begin(); for(; i != m_files.end(); i++) { - std::fstream file((*i).c_str(), std::ios::in); + fstream file((*i).c_str(), ios::in); if(file.is_open() == true) { m_configfile->parse(file, *commands); @@ -83,7 +85,7 @@ Commands* ConfigCommands::getCommands() return commands; }; -void ConfigCommands::addFiles(const std::string path, const std::string extension) +void ConfigCommands::addFiles(const string path, const string extension) { DIR* dir = opendir(path.c_str()); @@ -95,18 +97,18 @@ void ConfigCommands::addFiles(const std::string path, const std::string extensio while (d != NULL) { if (d->d_type == DT_DIR) { - std::string fn = d->d_name; + string fn = d->d_name; if (fn != "." && fn != "..") { - const std::string p = path + "/" + d->d_name; + const string p = path + "/" + d->d_name; addFiles(p, extension); } } else if (d->d_type == DT_REG) { - std::string fn = d->d_name; + string fn = d->d_name; - if (fn.find(extension, (fn.length() - extension.length())) != std::string::npos) { - const std::string p = path + "/" + 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); } } diff --git a/src/lib/ebus/configfile.h b/src/lib/ebus/configfile.h index 8fb82c1b..f6f37563 100644 --- a/src/lib/ebus/configfile.h +++ b/src/lib/ebus/configfile.h @@ -24,6 +24,8 @@ #include #include +using namespace std; + /** \file configfile.h */ /** available file endings / types. */ @@ -48,7 +50,7 @@ public: * @param is open input stream for reading. * @param commands object as datastore. */ - virtual void parse(std::istream& is, Commands& commands) = 0; + virtual void parse(istream& is, Commands& commands) = 0; }; @@ -69,7 +71,7 @@ public: * @param is open input stream for reading. * @param commands object as datastore. */ - void parse(std::istream& is, Commands& commands); + void parse(istream& is, Commands& commands); }; @@ -85,7 +87,7 @@ public: * @param path to configuration files. * @param type to parse. */ - ConfigCommands(const std::string path, const FileType type); + ConfigCommands(const string path, const FileType type); /** * @brief destructor. @@ -109,20 +111,20 @@ private: ConfigFile* m_configfile; /** main path for configuration files */ - std::string m_path; + string m_path; /** valid file extension */ - std::string m_extension; + string m_extension; /** vector of configuration files */ - std::vector m_files; + vector m_files; /** * @brief parse path for given file extension. * @param path to configuration files. * @param extension with file type. */ - void addFiles(const std::string path, const std::string extension); + void addFiles(const string path, const string extension); }; diff --git a/src/lib/ebus/decode.cpp b/src/lib/ebus/decode.cpp index 49ca9e22..b86bed97 100644 --- a/src/lib/ebus/decode.cpp +++ b/src/lib/ebus/decode.cpp @@ -26,19 +26,21 @@ #include #include -Decode::Decode(const std::string& data, const std::string& factor) +using namespace std; + +Decode::Decode(const string& data, const string& factor) : m_data(data) { - if ((factor.find_first_not_of("0123456789.") == std::string::npos) == true) + if ((factor.find_first_not_of("0123456789.") == string::npos) == true) m_factor = static_cast(strtod(factor.c_str(), NULL)); else m_factor = 1.0; } -std::string DecodeHEX::decode() +string DecodeHEX::decode() { - std::ostringstream result; + ostringstream result; for (size_t i = 0; i < m_data.length()/2; i++) result << m_data.substr(i*2, 2) << " "; @@ -46,112 +48,112 @@ std::string DecodeHEX::decode() return result.str().substr(0, result.str().length()-1); } -std::string DecodeUCH::decode() +string DecodeUCH::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; unsigned short x; ss >> x; - std::ostringstream result; - result << std::setprecision(3) << std::fixed << static_cast(x * m_factor); + ostringstream result; + result << setprecision(3) << fixed << static_cast(x * m_factor); return result.str(); } -std::string DecodeSCH::decode() +string DecodeSCH::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; unsigned short x; ss >> x; - std::ostringstream result; + ostringstream result; if ((x & 0x80) == 0x80) - result << std::setprecision(3) << std::fixed + result << setprecision(3) << fixed << static_cast(static_cast(- ( ((unsigned char) (~ x)) + 1) ) * m_factor); else - result << std::setprecision(3) << std::fixed + result << setprecision(3) << fixed << static_cast(static_cast(x) * m_factor); return result.str(); } -std::string DecodeUIN::decode() +string DecodeUIN::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; unsigned short x; ss >> x; - std::ostringstream result; - result << std::setprecision(3) << std::fixed << static_cast(x * m_factor); + ostringstream result; + result << setprecision(3) << fixed << static_cast(x * m_factor); return result.str(); } -std::string DecodeSIN::decode() +string DecodeSIN::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; unsigned short x; ss >> x; - std::ostringstream result; - result << std::setprecision(3) << std::fixed << static_cast(static_cast(x) * m_factor); + ostringstream result; + result << setprecision(3) << fixed << static_cast(static_cast(x) * m_factor); return result.str(); } -std::string DecodeULG::decode() +string DecodeULG::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; unsigned int x; ss >> x; - std::ostringstream result; - result << std::setprecision(3) << std::fixed << static_cast(x * m_factor); + ostringstream result; + result << setprecision(3) << fixed << static_cast(x * m_factor); return result.str(); } -std::string DecodeSLG::decode() +string DecodeSLG::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; unsigned int x; ss >> x; - std::ostringstream result; - result << std::setprecision(3) << std::fixed <(static_cast(x) * m_factor); + ostringstream result; + result << setprecision(3) << fixed <(static_cast(x) * m_factor); return result.str(); } -std::string DecodeFLT::decode() +string DecodeFLT::decode() { - std::stringstream ss; - ss << std::hex << m_data; + stringstream ss; + ss << hex << m_data; short x; ss >> x; - std::ostringstream result; - result << std::setprecision(3) << std::fixed << static_cast(x / 1000.0 * m_factor); + ostringstream result; + result << setprecision(3) << fixed << static_cast(x / 1000.0 * m_factor); return result.str(); } -std::string DecodeSTR::decode() +string DecodeSTR::decode() { - std::ostringstream result; + 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)); @@ -162,9 +164,9 @@ std::string DecodeSTR::decode() return result.str().substr(0, result.str().length()-1); } -std::string DecodeBCD::decode() +string DecodeBCD::decode() { - std::ostringstream result; + ostringstream result; unsigned char src = strtol(m_data.c_str(), NULL, 16); if ((src & 0x0F) > 0x09 || ((src >> 4) & 0x0F) > 0x09) @@ -175,9 +177,9 @@ std::string DecodeBCD::decode() return result.str(); } -std::string DecodeD1B::decode() +string DecodeD1B::decode() { - std::ostringstream result; + ostringstream result; unsigned char src = strtol(m_data.c_str(), NULL, 16); if ((src & 0x80) == 0x80) @@ -188,9 +190,9 @@ std::string DecodeD1B::decode() return result.str(); } -std::string DecodeD1C::decode() +string DecodeD1C::decode() { - std::ostringstream result; + ostringstream result; unsigned char src = strtol(m_data.c_str(), NULL, 16); if (src > 0xC8) @@ -201,9 +203,9 @@ std::string DecodeD1C::decode() return result.str(); } -std::string DecodeD2B::decode() +string DecodeD2B::decode() { - std::ostringstream result; + 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)); @@ -218,9 +220,9 @@ std::string DecodeD2B::decode() return result.str(); } -std::string DecodeD2C::decode() +string DecodeD2C::decode() { - std::ostringstream result; + 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)); @@ -237,9 +239,9 @@ std::string DecodeD2C::decode() return result.str(); } -std::string DecodeBDA::decode() +string DecodeBDA::decode() { - std::ostringstream result; + ostringstream result; Decode* decode; short array[3]; for (int i = 0; i < 3; i++) { @@ -248,30 +250,30 @@ std::string DecodeBDA::decode() delete decode; } - result << std::setw(2) << std::setfill('0') << array[0] << "." - << std::setw(2) << std::setfill('0') << array[1] << "." + result << setw(2) << setfill('0') << array[0] << "." + << setw(2) << setfill('0') << array[1] << "." << array[2] + 2000; return result.str(); } -std::string DecodeHDA::decode() +string DecodeHDA::decode() { - std::ostringstream result; + 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 << std::setw(2) << std::setfill('0') << dd << "." - << std::setw(2) << std::setfill('0') << mm << "." + result << setw(2) << setfill('0') << dd << "." + << setw(2) << setfill('0') << mm << "." << yy + 2000; return result.str(); } -std::string DecodeBTI::decode() +string DecodeBTI::decode() { - std::ostringstream result; + ostringstream result; Decode* decode; short array[3]; for (int i = 0; i < 3; i++) { @@ -280,32 +282,32 @@ std::string DecodeBTI::decode() delete decode; } - result << std::setw(2) << std::setfill('0') << array[0] << ":" - << std::setw(2) << std::setfill('0') << array[1] << ":" - << std::setw(2) << std::setfill('0') << array[2]; + result << setw(2) << setfill('0') << array[0] << ":" + << setw(2) << setfill('0') << array[1] << ":" + << setw(2) << setfill('0') << array[2]; return result.str(); } -std::string DecodeHTI::decode() +string DecodeHTI::decode() { - std::ostringstream result; + 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 << std::setw(2) << std::setfill('0') << hh << ":" - << std::setw(2) << std::setfill('0') << mm << ":" - << std::setw(2) << std::setfill('0') << ss; + result << setw(2) << setfill('0') << hh << ":" + << setw(2) << setfill('0') << mm << ":" + << setw(2) << setfill('0') << ss; return result.str(); } -std::string DecodeBDY::decode() +string DecodeBDY::decode() { const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; - std::ostringstream result; + ostringstream result; short day = static_cast(strtol(m_data.c_str(), NULL, 16)); if (day < 0 || day > 6) @@ -316,11 +318,11 @@ std::string DecodeBDY::decode() return result.str(); } -std::string DecodeHDY::decode() +string DecodeHDY::decode() { const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; - std::ostringstream result; + ostringstream result; short day = static_cast(strtol(m_data.c_str(), NULL, 16)) - 1; if (day < 0 || day > 6) @@ -331,14 +333,14 @@ std::string DecodeHDY::decode() return result.str(); } -std::string DecodeTTM::decode() +string DecodeTTM::decode() { - std::ostringstream result; + 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 << std::setw(2) << std::setfill('0') << hh << ":" - << std::setw(2) << std::setfill('0') << mm; + 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 index da1d087f..73c8d2a4 100644 --- a/src/lib/ebus/decode.h +++ b/src/lib/ebus/decode.h @@ -22,17 +22,19 @@ #include +using namespace std; + class Decode { public: - Decode(const std::string& data, const std::string& factor = ""); + Decode(const string& data, const string& factor = ""); virtual ~Decode() {} - virtual std::string decode() = 0; + virtual string decode() = 0; protected: - std::string m_data; + string m_data; float m_factor; }; @@ -42,10 +44,10 @@ class DecodeHEX : public Decode { public: - DecodeHEX(const std::string& data) : Decode(data) {} + DecodeHEX(const string& data) : Decode(data) {} ~DecodeHEX() {} - std::string decode(); + string decode(); }; @@ -53,11 +55,11 @@ class DecodeUCH : public Decode { public: - DecodeUCH(const std::string& data, const std::string& factor) + DecodeUCH(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeUCH() {} - std::string decode(); + string decode(); }; @@ -65,11 +67,11 @@ class DecodeSCH : public Decode { public: - DecodeSCH(const std::string& data, const std::string& factor) + DecodeSCH(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeSCH() {} - std::string decode(); + string decode(); }; @@ -77,11 +79,11 @@ class DecodeUIN : public Decode { public: - DecodeUIN(const std::string& data, const std::string& factor) + DecodeUIN(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeUIN() {} - std::string decode(); + string decode(); }; @@ -89,11 +91,11 @@ class DecodeSIN : public Decode { public: - DecodeSIN(const std::string& data, const std::string& factor) + DecodeSIN(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeSIN() {} - std::string decode(); + string decode(); }; @@ -101,11 +103,11 @@ class DecodeULG : public Decode { public: - DecodeULG(const std::string& data, const std::string& factor) + DecodeULG(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeULG() {} - std::string decode(); + string decode(); }; @@ -113,11 +115,11 @@ class DecodeSLG : public Decode { public: - DecodeSLG(const std::string& data, const std::string& factor) + DecodeSLG(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeSLG() {} - std::string decode(); + string decode(); }; @@ -125,11 +127,11 @@ class DecodeFLT : public Decode { public: - DecodeFLT(const std::string& data, const std::string& factor) + DecodeFLT(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeFLT() {} - std::string decode(); + string decode(); }; @@ -137,10 +139,10 @@ class DecodeSTR : public Decode { public: - DecodeSTR(std::string data) : Decode(data) {} + DecodeSTR(string data) : Decode(data) {} ~DecodeSTR() {} - std::string decode(); + string decode(); }; @@ -148,11 +150,11 @@ class DecodeBCD : public Decode { public: - DecodeBCD(const std::string& data, const std::string& factor) + DecodeBCD(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeBCD() {} - std::string decode(); + string decode(); }; @@ -160,11 +162,11 @@ class DecodeD1B : public Decode { public: - DecodeD1B(const std::string& data, const std::string& factor) + DecodeD1B(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeD1B() {} - std::string decode(); + string decode(); }; @@ -172,11 +174,11 @@ class DecodeD1C : public Decode { public: - DecodeD1C(const std::string& data, const std::string& factor) + DecodeD1C(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeD1C() {} - std::string decode(); + string decode(); }; @@ -184,11 +186,11 @@ class DecodeD2B : public Decode { public: - DecodeD2B(const std::string& data, const std::string& factor) + DecodeD2B(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeD2B() {} - std::string decode(); + string decode(); }; @@ -196,11 +198,11 @@ class DecodeD2C : public Decode { public: - DecodeD2C(const std::string& data, const std::string& factor) + DecodeD2C(const string& data, const string& factor) : Decode(data, factor) {} ~DecodeD2C() {} - std::string decode(); + string decode(); }; @@ -208,10 +210,10 @@ class DecodeBDA : public Decode { public: - DecodeBDA(const std::string& data) : Decode(data) {} + DecodeBDA(const string& data) : Decode(data) {} ~DecodeBDA() {} - std::string decode(); + string decode(); }; @@ -219,10 +221,10 @@ class DecodeHDA : public Decode { public: - DecodeHDA(const std::string& data) : Decode(data) {} + DecodeHDA(const string& data) : Decode(data) {} ~DecodeHDA() {} - std::string decode(); + string decode(); }; @@ -230,10 +232,10 @@ class DecodeBTI : public Decode { public: - DecodeBTI(const std::string& data) : Decode(data) {} + DecodeBTI(const string& data) : Decode(data) {} ~DecodeBTI() {} - std::string decode(); + string decode(); }; @@ -241,10 +243,10 @@ class DecodeHTI : public Decode { public: - DecodeHTI(const std::string& data) : Decode(data) {} + DecodeHTI(const string& data) : Decode(data) {} ~DecodeHTI() {} - std::string decode(); + string decode(); }; @@ -252,10 +254,10 @@ class DecodeBDY : public Decode { public: - DecodeBDY(const std::string& data) : Decode(data) {} + DecodeBDY(const string& data) : Decode(data) {} ~DecodeBDY() {} - std::string decode(); + string decode(); }; @@ -263,10 +265,10 @@ class DecodeHDY : public Decode { public: - DecodeHDY(const std::string& data) : Decode(data) {} + DecodeHDY(const string& data) : Decode(data) {} ~DecodeHDY() {} - std::string decode(); + string decode(); }; @@ -274,10 +276,10 @@ class DecodeTTM : public Decode { public: - DecodeTTM(const std::string& data) : Decode(data) {} + DecodeTTM(const string& data) : Decode(data) {} ~DecodeTTM() {} - std::string decode(); + string decode(); }; diff --git a/src/lib/ebus/encode.cpp b/src/lib/ebus/encode.cpp index 37d14eb5..42b58dc2 100644 --- a/src/lib/ebus/encode.cpp +++ b/src/lib/ebus/encode.cpp @@ -26,158 +26,160 @@ #include #include -Encode::Encode(const std::string& data, const std::string& factor) +using namespace std; + +Encode::Encode(const string& data, const string& factor) : m_data(data) { - if ((factor.find_first_not_of("0123456789.") == std::string::npos) == true) + if ((factor.find_first_not_of("0123456789.") == string::npos) == true) m_factor = static_cast(strtod(factor.c_str(), NULL)); else m_factor = 1.0; } -std::string EncodeHEX::encode() +string EncodeHEX::encode() { - m_data.erase(std::remove_if(m_data.begin(), m_data.end(), isspace), m_data.end()); + m_data.erase(remove_if(m_data.begin(), m_data.end(), ::isspace), m_data.end()); return m_data; } -std::string EncodeUCH::encode() +string EncodeUCH::encode() { - std::ostringstream result; + ostringstream result; unsigned short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << std::setw(2) << std::hex << std::setfill('0') << src; + result << setw(2) << hex << setfill('0') << src; return result.str().substr(result.str().length()-2,2); } -std::string EncodeSCH::encode() +string EncodeSCH::encode() { - std::ostringstream result; + ostringstream result; short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); if (src < -127 || src > 127) - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(0x80); else - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(src); return result.str().substr(result.str().length()-2,2); } -std::string EncodeUIN::encode() +string EncodeUIN::encode() { - std::ostringstream result; + ostringstream result; unsigned short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << std::setw(4) << std::hex << std::setfill('0') << src; + result << setw(4) << hex << setfill('0') << src; return result.str().substr(2,2) + result.str().substr(0,2); } -std::string EncodeSIN::encode() +string EncodeSIN::encode() { - std::ostringstream result; + ostringstream result; short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << std::setw(4) << std::hex << std::setfill('0') << src; + result << setw(4) << hex << setfill('0') << src; return result.str().substr(2,2) + result.str().substr(0,2); } -std::string EncodeULG::encode() +string EncodeULG::encode() { - std::ostringstream result; + ostringstream result; unsigned long src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << std::setw(8) << std::hex << std::setfill('0') << src; + 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); } -std::string EncodeSLG::encode() +string EncodeSLG::encode() { - std::ostringstream result; + ostringstream result; int src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); - result << std::setw(8) << std::hex << std::setfill('0') << src; + 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); } -std::string EncodeFLT::encode() +string EncodeFLT::encode() { - std::ostringstream result; + ostringstream result; short src = static_cast(strtod(m_data.c_str(), NULL) * 1000.0 / m_factor); - result << std::setw(4) << std::hex << std::setfill('0') << src; + result << setw(4) << hex << setfill('0') << src; return result.str().substr(2,2) + result.str().substr(0,2); } -std::string EncodeSTR::encode() +string EncodeSTR::encode() { - std::ostringstream result; + ostringstream result; for (size_t i = 0; i < m_data.length(); i++) - result << std::setw(2) << std::hex << std::setfill('0') << static_cast(m_data[i]); + result << setw(2) << hex << setfill('0') << static_cast(m_data[i]); return result.str(); } -std::string EncodeBCD::encode() +string EncodeBCD::encode() { - std::ostringstream result; + ostringstream result; short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); if (src > 99) - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(0xFF); else - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast( ((src / 10) << 4) | (src % 10) ); return result.str().substr(result.str().length()-2,2); } -std::string EncodeD1B::encode() +string EncodeD1B::encode() { - std::ostringstream result; + ostringstream result; short src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); if (src < -127 || src > 127) - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(0x80); else - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(src); return result.str().substr(result.str().length()-2,2); } -std::string EncodeD1C::encode() +string EncodeD1C::encode() { - std::ostringstream result; + ostringstream result; float src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); if (src < 0.0 || src > 100.0) - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(0xFF); else - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(src * 2.0); return result.str(); } -std::string EncodeD2B::encode() +string EncodeD2B::encode() { - std::ostringstream result; + ostringstream result; float src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); if (src < -127.999 || src > 127.999) { - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(0x80) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(0x00); } else { unsigned char tgt_lsb = static_cast((src - ((short) src)) * 256.0); @@ -188,24 +190,24 @@ std::string EncodeD2B::encode() else tgt_msb = static_cast((short) src); - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(tgt_msb) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(tgt_lsb); } return result.str(); } -std::string EncodeD2C::encode() +string EncodeD2C::encode() { - std::ostringstream result; + ostringstream result; float src = static_cast(strtod(m_data.c_str(), NULL) / m_factor); if (src < -2047.999 || src > 2047.999) { - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(0x80) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(0x00); } else { unsigned char tgt_lsb = static_cast( @@ -219,100 +221,100 @@ std::string EncodeD2C::encode() else tgt_msb = static_cast((short) src / 16.0); - result << std::setw(2) << std::hex << std::setfill('0') + result << setw(2) << hex << setfill('0') << static_cast(tgt_msb) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(tgt_lsb); } return result.str(); } -std::string EncodeBDA::encode() +string EncodeBDA::encode() { // prepare data - std::string token; - std::istringstream stream(m_data); - std::vector data; + string token; + istringstream stream(m_data); + vector data; - while (std::getline(stream, token, '.') != 0) + while (getline(stream, token, '.') != 0) data.push_back(token); - std::ostringstream result; - result << std::setw(2) << std::dec << std::setfill('0') + ostringstream result; + result << setw(2) << dec << setfill('0') << static_cast(strtod(data[0].c_str(), NULL)) - << std::setw(2) << std::dec << std::setfill('0') + << setw(2) << dec << setfill('0') << static_cast(strtod(data[1].c_str(), NULL)) - << std::setw(2) << std::dec << std::setfill('0') + << setw(2) << dec << setfill('0') << static_cast(strtod(data[2].c_str(), NULL) - 2000); return result.str(); } -std::string EncodeHDA::encode() +string EncodeHDA::encode() { // prepare data - std::string token; - std::istringstream stream(m_data); - std::vector data; + string token; + istringstream stream(m_data); + vector data; - while (std::getline(stream, token, '.') != 0) + while (getline(stream, token, '.') != 0) data.push_back(token); - std::ostringstream result; - result << std::setw(2) << std::hex << std::setfill('0') + ostringstream result; + result << setw(2) << hex << setfill('0') << static_cast(strtod(data[0].c_str(), NULL)) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(strtod(data[1].c_str(), NULL)) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(strtod(data[2].c_str(), NULL) - 2000); return result.str(); } -std::string EncodeBTI::encode() +string EncodeBTI::encode() { // prepare data - std::string token; - std::istringstream stream(m_data); - std::vector data; + string token; + istringstream stream(m_data); + vector data; - while (std::getline(stream, token, ':') != 0) + while (getline(stream, token, ':') != 0) data.push_back(token); - std::ostringstream result; - result << std::setw(2) << std::dec << std::setfill('0') + ostringstream result; + result << setw(2) << dec << setfill('0') << static_cast(strtod(data[0].c_str(), NULL)) - << std::setw(2) << std::dec << std::setfill('0') + << setw(2) << dec << setfill('0') << static_cast(strtod(data[1].c_str(), NULL)) - << std::setw(2) << std::dec << std::setfill('0') + << setw(2) << dec << setfill('0') << static_cast(strtod(data[2].c_str(), NULL)); return result.str(); } -std::string EncodeHTI::encode() +string EncodeHTI::encode() { // prepare data - std::string token; - std::istringstream stream(m_data); - std::vector data; + string token; + istringstream stream(m_data); + vector data; - while (std::getline(stream, token, ':') != 0) + while (getline(stream, token, ':') != 0) data.push_back(token); - std::ostringstream result; - result << std::setw(2) << std::hex << std::setfill('0') + ostringstream result; + result << setw(2) << hex << setfill('0') << static_cast(strtod(data[0].c_str(), NULL)) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(strtod(data[1].c_str(), NULL)) - << std::setw(2) << std::hex << std::setfill('0') + << setw(2) << hex << setfill('0') << static_cast(strtod(data[2].c_str(), NULL)); return result.str(); } -std::string EncodeBDY::encode() +string EncodeBDY::encode() { const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; short day = 7; @@ -321,13 +323,13 @@ std::string EncodeBDY::encode() if (strcasecmp(days[i], m_data.c_str()) == 0) day = i; - std::ostringstream result; - result << std::setw(2) << std::hex << std::setfill('0') << day; + ostringstream result; + result << setw(2) << hex << setfill('0') << day; return result.str(); } -std::string EncodeHDY::encode() +string EncodeHDY::encode() { const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"}; short day = 8; @@ -336,24 +338,24 @@ std::string EncodeHDY::encode() if (strcasecmp(days[i], m_data.c_str()) == 0) day = i + 1; - std::ostringstream result; - result << std::setw(2) << std::hex << std::setfill('0') << day; + ostringstream result; + result << setw(2) << hex << setfill('0') << day; return result.str(); } -std::string EncodeTTM::encode() +string EncodeTTM::encode() { // prepare data - std::string token; - std::istringstream stream(m_data); - std::vector data; + string token; + istringstream stream(m_data); + vector data; - while (std::getline(stream, token, ':') != 0) + while (getline(stream, token, ':') != 0) data.push_back(token); - std::ostringstream result; - result << std::setw(2) << std::hex << std::setfill('0') + ostringstream result; + result << setw(2) << hex << setfill('0') << static_cast( (strtod(data[0].c_str(), NULL) * 6) + (strtod(data[1].c_str(), NULL) / 10) ); diff --git a/src/lib/ebus/encode.h b/src/lib/ebus/encode.h index 7d87d45d..e5367086 100644 --- a/src/lib/ebus/encode.h +++ b/src/lib/ebus/encode.h @@ -22,17 +22,19 @@ #include +using namespace std; + class Encode { public: - Encode(const std::string& data, const std::string& factor = ""); + Encode(const string& data, const string& factor = ""); virtual ~Encode() {} - virtual std::string encode() = 0; + virtual string encode() = 0; protected: - std::string m_data; + string m_data; float m_factor; }; @@ -42,10 +44,10 @@ class EncodeHEX : public Encode { public: - EncodeHEX(const std::string& data) : Encode(data) {} + EncodeHEX(const string& data) : Encode(data) {} ~EncodeHEX() {} - std::string encode(); + string encode(); }; @@ -53,11 +55,11 @@ class EncodeUCH : public Encode { public: - EncodeUCH(const std::string& data, const std::string& factor) + EncodeUCH(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeUCH() {} - std::string encode(); + string encode(); }; @@ -65,11 +67,11 @@ class EncodeSCH : public Encode { public: - EncodeSCH(const std::string& data, const std::string& factor) + EncodeSCH(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeSCH() {} - std::string encode(); + string encode(); }; @@ -77,11 +79,11 @@ class EncodeUIN : public Encode { public: - EncodeUIN(const std::string& data, const std::string& factor) + EncodeUIN(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeUIN() {} - std::string encode(); + string encode(); }; @@ -89,11 +91,11 @@ class EncodeSIN : public Encode { public: - EncodeSIN(const std::string& data, const std::string& factor) + EncodeSIN(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeSIN() {} - std::string encode(); + string encode(); }; @@ -101,11 +103,11 @@ class EncodeULG : public Encode { public: - EncodeULG(const std::string& data, const std::string& factor) + EncodeULG(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeULG() {} - std::string encode(); + string encode(); }; @@ -113,11 +115,11 @@ class EncodeSLG : public Encode { public: - EncodeSLG(const std::string& data, const std::string& factor) + EncodeSLG(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeSLG() {} - std::string encode(); + string encode(); }; @@ -125,11 +127,11 @@ class EncodeFLT : public Encode { public: - EncodeFLT(const std::string& data, const std::string& factor) + EncodeFLT(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeFLT() {} - std::string encode(); + string encode(); }; @@ -137,10 +139,10 @@ class EncodeSTR : public Encode { public: - EncodeSTR(const std::string& data) : Encode(data) {} + EncodeSTR(const string& data) : Encode(data) {} ~EncodeSTR() {} - std::string encode(); + string encode(); }; @@ -148,11 +150,11 @@ class EncodeBCD : public Encode { public: - EncodeBCD(const std::string& data, const std::string& factor) + EncodeBCD(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeBCD() {} - std::string encode(); + string encode(); }; @@ -160,11 +162,11 @@ class EncodeD1B : public Encode { public: - EncodeD1B(const std::string& data, const std::string& factor) + EncodeD1B(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeD1B() {} - std::string encode(); + string encode(); }; @@ -172,11 +174,11 @@ class EncodeD1C : public Encode { public: - EncodeD1C(const std::string& data, const std::string& factor) + EncodeD1C(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeD1C() {} - std::string encode(); + string encode(); }; @@ -184,11 +186,11 @@ class EncodeD2B : public Encode { public: - EncodeD2B(const std::string& data, const std::string& factor) + EncodeD2B(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeD2B() {} - std::string encode(); + string encode(); }; @@ -196,11 +198,11 @@ class EncodeD2C : public Encode { public: - EncodeD2C(const std::string& data, const std::string& factor) + EncodeD2C(const string& data, const string& factor) : Encode(data, factor) {} ~EncodeD2C() {} - std::string encode(); + string encode(); }; @@ -208,10 +210,10 @@ class EncodeBDA : public Encode { public: - EncodeBDA(const std::string& data) : Encode(data) {} + EncodeBDA(const string& data) : Encode(data) {} ~EncodeBDA() {} - std::string encode(); + string encode(); }; @@ -219,10 +221,10 @@ class EncodeHDA : public Encode { public: - EncodeHDA(const std::string& data) : Encode(data) {} + EncodeHDA(const string& data) : Encode(data) {} ~EncodeHDA() {} - std::string encode(); + string encode(); }; @@ -230,10 +232,10 @@ class EncodeBTI : public Encode { public: - EncodeBTI(const std::string& data) : Encode(data) {} + EncodeBTI(const string& data) : Encode(data) {} ~EncodeBTI() {} - std::string encode(); + string encode(); }; @@ -241,10 +243,10 @@ class EncodeHTI : public Encode { public: - EncodeHTI(const std::string& data) : Encode(data) {} + EncodeHTI(const string& data) : Encode(data) {} ~EncodeHTI() {} - std::string encode(); + string encode(); }; @@ -252,10 +254,10 @@ class EncodeBDY : public Encode { public: - EncodeBDY(const std::string& data) : Encode(data) {} + EncodeBDY(const string& data) : Encode(data) {} ~EncodeBDY() {} - std::string encode(); + string encode(); }; @@ -263,10 +265,10 @@ class EncodeHDY : public Encode { public: - EncodeHDY(const std::string& data) : Encode(data) {} + EncodeHDY(const string& data) : Encode(data) {} ~EncodeHDY() {} - std::string encode(); + string encode(); }; @@ -274,10 +276,10 @@ class EncodeTTM : public Encode { public: - EncodeTTM(const std::string& data) : Encode(data) {} + EncodeTTM(const string& data) : Encode(data) {} ~EncodeTTM() {} - std::string encode(); + string encode(); }; diff --git a/src/lib/ebus/port.cpp b/src/lib/ebus/port.cpp index 856ce198..9dcc9e66 100644 --- a/src/lib/ebus/port.cpp +++ b/src/lib/ebus/port.cpp @@ -33,6 +33,8 @@ #include #endif +using namespace std; + bool Device::isOpen() { if (isValid() == false) @@ -130,7 +132,7 @@ unsigned char Device::getByte() } -void DeviceSerial::openDevice(const std::string deviceName, const bool noDeviceCheck) +void DeviceSerial::openDevice(const string deviceName, const bool noDeviceCheck) { m_noDeviceCheck = noDeviceCheck; @@ -188,7 +190,7 @@ void DeviceSerial::closeDevice() } -void DeviceNetwork::openDevice(const std::string deviceName, const bool noDeviceCheck) +void DeviceNetwork::openDevice(const string deviceName, const bool noDeviceCheck) { m_noDeviceCheck = noDeviceCheck; @@ -245,7 +247,7 @@ void DeviceNetwork::closeDevice() } -Port::Port(const std::string deviceName, const bool noDeviceCheck) +Port::Port(const string deviceName, const bool noDeviceCheck) : m_deviceName(deviceName), m_noDeviceCheck(noDeviceCheck) { m_device = NULL; diff --git a/src/lib/ebus/port.h b/src/lib/ebus/port.h index 31724946..0dd82c85 100644 --- a/src/lib/ebus/port.h +++ b/src/lib/ebus/port.h @@ -25,6 +25,8 @@ #include #include +using namespace std; + /** \file port.h */ /** available device types. */ @@ -62,7 +64,7 @@ public: * @param deviceName to determine device type. * @param noDeviceCheck en-/disable device check. */ - virtual void openDevice(const std::string deviceName, const bool noDeviceCheck) = 0; + virtual void openDevice(const string deviceName, const bool noDeviceCheck) = 0; /** * @brief virtual close function for closing opened file descriptor @@ -114,7 +116,7 @@ protected: bool m_noDeviceCheck; /** queue for received bytes */ - std::queue m_recvBuffer; + queue m_recvBuffer; /** receive buffer */ unsigned char m_buffer[MAX_READ_SIZE]; @@ -145,7 +147,7 @@ public: * @param deviceName to determine device type. * @param noDeviceCheck en-/disable device check. */ - void openDevice(const std::string deviceName, const bool noDeviceCheck); + void openDevice(const string deviceName, const bool noDeviceCheck); /** * @brief close function for closing opened file descriptor @@ -175,7 +177,7 @@ public: * @param deviceName to determine device type. * @param noDeviceCheck en-/disable device check. */ - void openDevice(const std::string deviceName, const bool noDeviceCheck); + void openDevice(const string deviceName, const bool noDeviceCheck); /** * @brief close opened file descriptor @@ -198,7 +200,7 @@ public: * @param deviceName to determine device type. * @param noDeviceCheck en-/disable device check. */ - Port(const std::string deviceName, const bool noDeviceCheck); + Port(const string deviceName, const bool noDeviceCheck); /** * @brief destructor. @@ -253,7 +255,7 @@ public: private: /** the device name */ - std::string m_deviceName; + string m_deviceName; /** the device instance */ Device* m_device; diff --git a/src/lib/ebus/test/test_commands.cpp b/src/lib/ebus/test/test_commands.cpp index cfd76e9a..6dc0a981 100644 --- a/src/lib/ebus/test/test_commands.cpp +++ b/src/lib/ebus/test/test_commands.cpp @@ -25,22 +25,24 @@ #include #include +using namespace std; + // will be part of cfg csv class -void readCSV(std::istream& is, Commands& commands){ - std::string line; +void readCSV(istream& is, Commands& commands){ + string line; // read lines - while (std::getline(is, line) != 0) { - std::vector row; - std::string column; + while (getline(is, line) != 0) { + vector row; + string column; int count; count = 0; - std::istringstream stream(line); + istringstream stream(line); // walk through columns - while (std::getline(stream, column, ';') != 0) { + while (getline(stream, column, ';') != 0) { row.push_back(column); count++; } @@ -52,29 +54,29 @@ void readCSV(std::istream& is, Commands& commands){ int main() { Commands* commands = ConfigCommands("test", ft_csv).getCommands(); - std::cout << "Commands: " << commands->sizeCmdDB() << std::endl; + cout << "Commands: " << commands->sizeCmdDB() << endl; - //~ std::string data("g ci password pin1"); - std::string data("s vwxmk DesiredTemp"); + //~ string data("g ci password pin1"); + string data("s vwxmk DesiredTemp"); int index = commands->findCommand(data); - std::cout << "found at index: " << index << std::endl; + cout << "found at index: " << index << endl; // prepare data - std::string token; - std::istringstream stream(data); - std::vector cmd; + string token; + istringstream stream(data); + vector cmd; // split stream - while (std::getline(stream, token, ' ') != 0) + while (getline(stream, token, ' ') != 0) cmd.push_back(token); //~ Command* command = new Command(index, (*commands)[index], "ff15b509030d2c0035000401000000cf00"); Command* command = new Command(index, (*commands)[index], "19.0"); - //~ std::string result = command->calcResult(cmd); - std::string result = command->calcData(); - std::cout << "result: " << result << std::endl; + //~ string result = command->calcResult(cmd); + string result = command->calcData(); + cout << "result: " << result << endl; delete command; diff --git a/src/lib/ebus/test/test_configfile.cpp b/src/lib/ebus/test/test_configfile.cpp index 90e78f71..df3d2ce9 100644 --- a/src/lib/ebus/test/test_configfile.cpp +++ b/src/lib/ebus/test/test_configfile.cpp @@ -24,18 +24,20 @@ #include #include +using namespace std; + int main() { - std::string dir("test"); + string dir("test"); ConfigCommands config(dir, ft_csv); Commands* commands = config.getCommands(); - std::cout << "size: " << commands->sizeCmdDB() << std::endl; + cout << "size: " << commands->sizeCmdDB() << endl; commands->findCommand("g ci Password"); - std::cout << (*commands)[0][0] << std::endl; + cout << (*commands)[0][0] << endl; delete commands; diff --git a/src/lib/ebus/test/test_decode.cpp b/src/lib/ebus/test/test_decode.cpp index d9df8858..346bda96 100644 --- a/src/lib/ebus/test/test_decode.cpp +++ b/src/lib/ebus/test/test_decode.cpp @@ -21,23 +21,25 @@ #include #include +using namespace std; + int main() { Decode* help_dec = NULL; - std::cout << std::endl; + cout << endl; // HEX { const char* hex[] = {"53706569636865722020"}; for (size_t i = 0; i < sizeof(hex)/sizeof(hex[0]); i++) { help_dec = new DecodeHEX(hex[i]); - std::cout << "DecodeHEX: " << std::setw(20) << hex[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeHEX: " << setw(20) << hex[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // UCH @@ -45,12 +47,12 @@ int main() const char* uch[] = {"00", "01", "7f", "80", "fe", "ff", "a1"}; for (size_t i = 0; i < sizeof(uch)/sizeof(uch[0]); i++) { help_dec = new DecodeUCH(uch[i], "1.0"); - std::cout << "DecodeUCH: " << std::setw(20) << uch[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeUCH: " << setw(20) << uch[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // SCH @@ -58,12 +60,12 @@ int main() const char* sch[] = {"00", "01", "7f", "80", "fe", "ff", "a1"}; for (size_t i = 0; i < sizeof(sch)/sizeof(sch[0]); i++) { help_dec = new DecodeSCH(sch[i], "1.0"); - std::cout << "DecodeSCH: " << std::setw(20) << sch[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeSCH: " << setw(20) << sch[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // UIN @@ -71,12 +73,12 @@ int main() const char* uin[] = {"0000", "0001", "7fff", "8000", "fffe", "ffff", "a1b2"}; for (size_t i = 0; i < sizeof(uin)/sizeof(uin[0]); i++) { help_dec = new DecodeUIN(uin[i], "1.0"); - std::cout << "DecodeUIN: " << std::setw(20) << uin[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeUIN: " << setw(20) << uin[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // SIN @@ -84,12 +86,12 @@ int main() const char* sin[] = {"0000", "0001", "7fff", "8000", "fffe", "ffff", "a1b2"}; for (size_t i = 0; i < sizeof(sin)/sizeof(sin[0]); i++) { help_dec = new DecodeSIN(sin[i], "1.0"); - std::cout << "DecodeSIN: " << std::setw(20) << sin[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeSIN: " << setw(20) << sin[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // ULG @@ -97,12 +99,12 @@ int main() const char* ulg[] = {"00000000", "00000001", "7fffffff", "80000000", "fffffffe", "ffffffff", "a1b2c3d4"}; for (size_t i = 0; i < sizeof(ulg)/sizeof(ulg[0]); i++) { help_dec = new DecodeULG(ulg[i], "1.0"); - std::cout << "DecodeULG: " << std::setw(20) << ulg[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeULG: " << setw(20) << ulg[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // SLG @@ -110,12 +112,12 @@ int main() const char* slg[] = {"00000000", "00000001", "7fffffff", "80000000", "fffffffe", "ffffffff", "a1b2c3d4"}; for (size_t i = 0; i < sizeof(slg)/sizeof(slg[0]); i++) { help_dec = new DecodeSLG(slg[i], "1.0"); - std::cout << "DecodeSLG: " << std::setw(20) << slg[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeSLG: " << setw(20) << slg[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // FLT @@ -123,12 +125,12 @@ int main() const char* flt[] = {"0000", "081b", "2532", "2689", "0851"}; for (size_t i = 0; i < sizeof(flt)/sizeof(flt[0]); i++) { help_dec = new DecodeFLT(flt[i], "1.0"); - std::cout << "DecodeFLT: " << std::setw(20) << flt[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeFLT: " << setw(20) << flt[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // STR @@ -136,12 +138,12 @@ int main() const char* str[] = {"53706569636865722020", "5644363030" }; for (size_t i = 0; i < sizeof(str)/sizeof(str[0]); i++) { help_dec = new DecodeSTR(str[i]); - std::cout << "DecodeSTR: " << std::setw(20) << str[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeSTR: " << setw(20) << str[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // BCD @@ -149,12 +151,12 @@ int main() const char* bcd[] = {"00", "01", "02", "03", "12", "99"}; for (size_t i = 0; i < sizeof(bcd)/sizeof(bcd[0]); i++) { help_dec = new DecodeBCD(bcd[i], "1.0"); - std::cout << "DecodeBCD: " << std::setw(20) << bcd[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeBCD: " << setw(20) << bcd[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // D1B @@ -162,12 +164,12 @@ int main() const char* d1b[] = {"00", "01", "7f", "81", "80"}; for (size_t i = 0; i < sizeof(d1b)/sizeof(d1b[0]); i++) { help_dec = new DecodeD1B(d1b[i], "1.0"); - std::cout << "DecodeD1B: " << std::setw(20) << d1b[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeD1B: " << setw(20) << d1b[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // D1C @@ -175,12 +177,12 @@ int main() const char* d1c[] = {"00", "64", "c8"}; for (size_t i = 0; i < sizeof(d1c)/sizeof(d1c[0]); i++) { help_dec = new DecodeD1C(d1c[i], "1.0"); - std::cout << "DecodeD1C: " << std::setw(20) << d1c[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeD1C: " << setw(20) << d1c[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // D2B @@ -188,12 +190,12 @@ int main() const char* d2b[] = {"0000", "0100", "ffff", "00ff", "0080", "0180", "ff7f"}; for (size_t i = 0; i < sizeof(d2b)/sizeof(d2b[0]); i++) { help_dec = new DecodeD2B(d2b[i], "1.0"); - std::cout << "DecodeD2B: " << std::setw(20) << d2b[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeD2B: " << setw(20) << d2b[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // D2C @@ -201,12 +203,12 @@ int main() const char* d2c[] = {"0000", "0100", "ffff", "f0ff", "0080", "0180", "ff7f"}; for (size_t i = 0; i < sizeof(d2c)/sizeof(d2c[0]); i++) { help_dec = new DecodeD2C(d2c[i], "1.0"); - std::cout << "DecodeD2C: " << std::setw(20) << d2c[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeD2C: " << setw(20) << d2c[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // BDA @@ -214,12 +216,12 @@ int main() const char* bda[] = {"171113", "220901"}; for (size_t i = 0; i < sizeof(bda)/sizeof(bda[0]); i++) { help_dec = new DecodeBDA(bda[i]); - std::cout << "DecodeBDA: " << std::setw(20) << bda[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeBDA: " << setw(20) << bda[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // HDA @@ -227,12 +229,12 @@ int main() const char* hda[] = {"010101", "1f0c1b"}; for (size_t i = 0; i < sizeof(hda)/sizeof(hda[0]); i++) { help_dec = new DecodeHDA(hda[i]); - std::cout << "DecodeHDA: " << std::setw(20) << hda[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeHDA: " << setw(20) << hda[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // BTI @@ -240,12 +242,12 @@ int main() const char* bti[] = {"010101", "174209", "235959"}; for (size_t i = 0; i < sizeof(bti)/sizeof(bti[0]); i++) { help_dec = new DecodeBTI(bti[i]); - std::cout << "DecodeBTI: " << std::setw(20) << bti[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeBTI: " << setw(20) << bti[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // HTI @@ -253,12 +255,12 @@ int main() const char* hti[] = {"010101", "112a09", "173b3b"}; for (size_t i = 0; i < sizeof(hti)/sizeof(hti[0]); i++) { help_dec = new DecodeHTI(hti[i]); - std::cout << "DecodeHTI: " << std::setw(20) << hti[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeHTI: " << setw(20) << hti[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // BDY @@ -266,12 +268,12 @@ int main() const char* bdy[] = {"01", "03", "06", "07"}; for (size_t i = 0; i < sizeof(bdy)/sizeof(bdy[0]); i++) { help_dec = new DecodeBDY(bdy[i]); - std::cout << "DecodeBDY: " << std::setw(20) << bdy[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeBDY: " << setw(20) << bdy[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // HDY @@ -279,12 +281,12 @@ int main() const char* hdy[] = {"01", "03", "07", "08"}; for (size_t i = 0; i < sizeof(hdy)/sizeof(hdy[0]); i++) { help_dec = new DecodeHDY(hdy[i]); - std::cout << "DecodeHDY: " << std::setw(20) << hdy[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeHDY: " << setw(20) << hdy[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } // TTM @@ -292,12 +294,12 @@ int main() const char* ttm[] = {"00", "23", "4f", "90"}; for (size_t i = 0; i < sizeof(ttm)/sizeof(ttm[0]); i++) { help_dec = new DecodeTTM(ttm[i]); - std::cout << "DecodeTTM: " << std::setw(20) << ttm[i] << " = " << help_dec->decode() << std::endl; + cout << "DecodeTTM: " << setw(20) << ttm[i] << " = " << help_dec->decode() << endl; delete help_dec; } - std::cout << std::endl; + cout << endl; } return 0; diff --git a/src/lib/ebus/test/test_encode.cpp b/src/lib/ebus/test/test_encode.cpp index 5cc97abe..3e3bc887 100644 --- a/src/lib/ebus/test/test_encode.cpp +++ b/src/lib/ebus/test/test_encode.cpp @@ -21,23 +21,25 @@ #include #include +using namespace std; + int main() { Encode* help_enc = NULL; - std::cout << std::endl; + cout << endl; // HEX { const char* hex[] = {"53 70 65 69 63 68 65 72 20 20"}; for (size_t i = 0; i < sizeof(hex)/sizeof(hex[0]); i++) { help_enc = new EncodeHEX(hex[i]); - std::cout << "EncodeHEX: " << std::setw(20) << hex[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeHEX: " << setw(20) << hex[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // UCH @@ -45,12 +47,12 @@ int main() const char* uch[] = {"0", "1", "127", "128", "254", "255", "161"}; for (size_t i = 0; i < sizeof(uch)/sizeof(uch[0]); i++) { help_enc = new EncodeUCH(uch[i], "1.0"); - std::cout << "EncodeUCH: " << std::setw(20) << uch[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeUCH: " << setw(20) << uch[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // SCH @@ -58,12 +60,12 @@ int main() const char* sch[] = {"0", "1", "127", "-128", "-2", "-1", "-95"}; for (size_t i = 0; i < sizeof(sch)/sizeof(sch[0]); i++) { help_enc = new EncodeSCH(sch[i], "1.0"); - std::cout << "EncodeSCH: " << std::setw(20) << sch[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeSCH: " << setw(20) << sch[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // UIN @@ -71,12 +73,12 @@ int main() const char* uin[] = {"0", "1", "32767", "32768", "65534", "65535", "41394"}; for (size_t i = 0; i < sizeof(uin)/sizeof(uin[0]); i++) { help_enc = new EncodeUIN(uin[i], "1.0"); - std::cout << "EncodeUIN: " << std::setw(20) << uin[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeUIN: " << setw(20) << uin[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // SIN @@ -84,12 +86,12 @@ int main() const char* sin[] = {"0", "1", "32767", "-32768", "-2", "-1", "-24142"}; for (size_t i = 0; i < sizeof(sin)/sizeof(sin[0]); i++) { help_enc = new EncodeSIN(sin[i], "1.0"); - std::cout << "EncodeSIN: " << std::setw(20) << sin[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeSIN: " << setw(20) << sin[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // ULG @@ -97,12 +99,12 @@ int main() const char* ulg[] = {"0", "1", "2147483647", "2147483648", "4294967294", "4294967295", "2712847316"}; for (size_t i = 0; i < sizeof(ulg)/sizeof(ulg[0]); i++) { help_enc = new EncodeULG(ulg[i], "1.0"); - std::cout << "EncodeULG: " << std::setw(20) << ulg[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeULG: " << setw(20) << ulg[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // SLG @@ -110,12 +112,12 @@ int main() const char* slg[] = {"0", "1", "2147483647", "-2147483648", "-2", "-1", "-1582119980"}; for (size_t i = 0; i < sizeof(slg)/sizeof(slg[0]); i++) { help_enc = new EncodeSLG(slg[i], "1.0"); - std::cout << "EncodeSLG: " << std::setw(20) << slg[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeSLG: " << setw(20) << slg[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // FLT @@ -123,12 +125,12 @@ int main() const char* flt[] = {"0.000", "2.075", "9.522", "9.865", "2.129"}; for (size_t i = 0; i < sizeof(flt)/sizeof(flt[0]); i++) { help_enc = new EncodeFLT(flt[i], "1.0"); - std::cout << "EncodeFLT: " << std::setw(20) << flt[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeFLT: " << setw(20) << flt[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // STR @@ -136,12 +138,12 @@ int main() const char* str[] = {"Speicher ", "VD600" }; for (size_t i = 0; i < sizeof(str)/sizeof(str[0]); i++) { help_enc = new EncodeSTR(str[i]); - std::cout << "EncodeSTR: " << std::setw(20) << str[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeSTR: " << setw(20) << str[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // BCD @@ -149,12 +151,12 @@ int main() const char* bcd[] = {"0", "1", "2", "3", "12", "99"}; for (size_t i = 0; i < sizeof(bcd)/sizeof(bcd[0]); i++) { help_enc = new EncodeBCD(bcd[i], "1.0"); - std::cout << "EncodeBCD: " << std::setw(20) << bcd[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeBCD: " << setw(20) << bcd[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // D1B @@ -162,12 +164,12 @@ int main() const char* d1b[] = {"00", "01", "127", "-127", "-128"}; for (size_t i = 0; i < sizeof(d1b)/sizeof(d1b[0]); i++) { help_enc = new EncodeD1B(d1b[i], "1.0"); - std::cout << "EncodeD1B: " << std::setw(20) << d1b[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeD1B: " << setw(20) << d1b[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // D1C @@ -175,12 +177,12 @@ int main() const char* d1c[] = {"0", "50", "100"}; for (size_t i = 0; i < sizeof(d1c)/sizeof(d1c[0]); i++) { help_enc = new EncodeD1C(d1c[i], "1.0"); - std::cout << "EncodeD1C: " << std::setw(20) << d1c[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeD1C: " << setw(20) << d1c[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // D2B @@ -188,12 +190,12 @@ int main() const char* d2b[] = {"0", "0.00390625", "-0.00390625", "-1", "-128", "-127.99609375", "127.99609375"}; for (size_t i = 0; i < sizeof(d2b)/sizeof(d2b[0]); i++) { help_enc = new EncodeD2B(d2b[i], "1.0"); - std::cout << "EncodeD2B: " << std::setw(20) << d2b[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeD2B: " << setw(20) << d2b[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // D2C @@ -201,12 +203,12 @@ int main() const char* d2c[] = {"0", "0.0625", "-0.0625", "-1", "-2048", "-2047.9375", "2047.9375"}; for (size_t i = 0; i < sizeof(d2c)/sizeof(d2c[0]); i++) { help_enc = new EncodeD2C(d2c[i], "1.0"); - std::cout << "EncodeD2C: " << std::setw(20) << d2c[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeD2C: " << setw(20) << d2c[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // BDA @@ -214,12 +216,12 @@ int main() const char* bda[] = {"17.11.2013", "22.09.2001"}; for (size_t i = 0; i < sizeof(bda)/sizeof(bda[0]); i++) { help_enc = new EncodeBDA(bda[i]); - std::cout << "EncodeBDA: " << std::setw(20) << bda[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeBDA: " << setw(20) << bda[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // HDA @@ -227,12 +229,12 @@ int main() const char* hda[] = {"01.01.2001", "31.12.2027"}; for (size_t i = 0; i < sizeof(hda)/sizeof(hda[0]); i++) { help_enc = new EncodeHDA(hda[i]); - std::cout << "EncodeHDA: " << std::setw(20) << hda[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeHDA: " << setw(20) << hda[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // BTI @@ -240,12 +242,12 @@ int main() const char* bti[] = {"01:01:01", "17:42:09", "23:59:59"}; for (size_t i = 0; i < sizeof(bti)/sizeof(bti[0]); i++) { help_enc = new EncodeBTI(bti[i]); - std::cout << "EncodeBTI: " << std::setw(20) << bti[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeBTI: " << setw(20) << bti[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // HTI @@ -253,12 +255,12 @@ int main() const char* hti[] = {"01:01:01", "17:42:09", "23:59:59"}; for (size_t i = 0; i < sizeof(hti)/sizeof(hti[0]); i++) { help_enc = new EncodeHTI(hti[i]); - std::cout << "EncodeHTI: " << std::setw(20) << hti[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeHTI: " << setw(20) << hti[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // BDY @@ -266,12 +268,12 @@ int main() const char* bdy[] = {"Tue", "Thu", "Sun", "Err"}; for (size_t i = 0; i < sizeof(bdy)/sizeof(bdy[0]); i++) { help_enc = new EncodeBDY(bdy[i]); - std::cout << "EncodeBDY: " << std::setw(20) << bdy[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeBDY: " << setw(20) << bdy[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } @@ -280,12 +282,12 @@ int main() const char* hdy[] = {"Mon", "Wed", "Sun", "Err"}; for (size_t i = 0; i < sizeof(hdy)/sizeof(hdy[0]); i++) { help_enc = new EncodeHDY(hdy[i]); - std::cout << "EncodeHDY: " << std::setw(20) << hdy[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeHDY: " << setw(20) << hdy[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } // TTM @@ -293,12 +295,12 @@ int main() const char* ttm[] = {"00:00", "05:50", "13:10", "24:00"}; for (size_t i = 0; i < sizeof(ttm)/sizeof(ttm[0]); i++) { help_enc = new EncodeTTM(ttm[i]); - std::cout << "EncodeTTM: " << std::setw(20) << ttm[i] << " = " << help_enc->encode() << std::endl; + cout << "EncodeTTM: " << setw(20) << ttm[i] << " = " << help_enc->encode() << endl; delete help_enc; } - std::cout << std::endl; + cout << endl; } return 0; diff --git a/src/lib/ebus/test/test_port.cpp b/src/lib/ebus/test/test_port.cpp index 2aae9808..ebdd8ea4 100644 --- a/src/lib/ebus/test/test_port.cpp +++ b/src/lib/ebus/test/test_port.cpp @@ -21,15 +21,17 @@ #include #include +using namespace std; + int main () { - std::string dev("/dev/ttyUSB20"); + string dev("/dev/ttyUSB20"); Port port(dev, true); port.open(); if(port.isOpen() == true) - std::cout << "openPort successful." << std::endl; + cout << "openPort successful." << endl; int count = 0; @@ -40,8 +42,8 @@ int main () for (int i = 0; i < bytes_read; i++) byte = port.byte(); - std::cout << std::hex << std::setw(2) << std::setfill('0') - << static_cast(byte) << std::endl; + cout << hex << setw(2) << setfill('0') + << static_cast(byte) << endl; bytes_read = 0; @@ -51,7 +53,7 @@ int main () port.close(); if(port.isOpen() == false) - std::cout << "closePort successful." << std::endl; + cout << "closePort successful." << endl; return 0; diff --git a/src/lib/utils/appl.cpp b/src/lib/utils/appl.cpp index 628d84d2..f56d8c1a 100644 --- a/src/lib/utils/appl.cpp +++ b/src/lib/utils/appl.cpp @@ -22,6 +22,8 @@ #include #include +using namespace std; + Appl& Appl::Instance(const bool command) { static Appl instance(command); @@ -64,7 +66,7 @@ void Appl::addOption(const char* name, const char* shortname, OptVal optval, void Appl::parseArgs(int argc, char* argv[]) { - std::vector _argv(argv, argv + argc); + vector _argv(argv, argv + argc); m_argv = _argv; // walk through all arguments @@ -74,7 +76,7 @@ void Appl::parseArgs(int argc, char* argv[]) if (_argv[i].rfind("--") == 0 && _argv[i].size() > 2) { // is next item an added argument? - if (i+1 < argc && _argv[i+1].rfind("-", 0) == std::string::npos) { + if (i+1 < argc && _argv[i+1].rfind("-", 0) == string::npos) { if (checkOption(_argv[i].substr(2), _argv[i+1]) == false) printHelp(); } @@ -90,7 +92,7 @@ void Appl::parseArgs(int argc, char* argv[]) for (size_t j = 1; j < _argv[i].size(); j++) { // only last charater could have an argument - if (i+1 < argc && _argv[i+1].rfind("-", 0) == std::string::npos + if (i+1 < argc && _argv[i+1].rfind("-", 0) == string::npos && j+1 == _argv[i].size()) { if (checkOption(_argv[i].substr(j,1), _argv[i+1]) == false) printHelp(); @@ -108,7 +110,7 @@ void Appl::parseArgs(int argc, char* argv[]) if (m_needCommand == true) { for (int i = 1; i < argc; i++) { - if (_argv[i].rfind("-", 0) != std::string::npos) { + if (_argv[i].rfind("-", 0) != string::npos) { i++; continue; } @@ -116,14 +118,14 @@ void Appl::parseArgs(int argc, char* argv[]) } if (m_arguments.size() == 0) { - std::cerr << std::endl << "command needed" << std::endl; + cerr << endl << "command needed" << endl; printHelp(); } } } -bool Appl::checkOption(const std::string& option, const std::string& value) +bool Appl::checkOption(const string& option, const string& value) { if (strcmp(option.c_str(), "settings") == 0) printSettings(); @@ -139,8 +141,8 @@ bool Appl::checkOption(const std::string& option, const std::string& value) // need this option and argument? if (o_it->optiontype == ot_mandatory && value.size() == 0) { - std::cerr << std::endl << "option requires an argument '" - << option << "'" << std::endl; + cerr << endl << "option requires an argument '" + << option << "'" << endl; return false; } @@ -153,11 +155,11 @@ bool Appl::checkOption(const std::string& option, const std::string& value) } } - std::cerr << std::endl << "unknown option '" << option << "'" << std::endl; + cerr << endl << "unknown option '" << option << "'" << endl; return false; } -void Appl::setOptVal(const char* option, const std::string value, DataType datatype) +void Appl::setOptVal(const char* option, const string value, DataType datatype) { switch (datatype) { case dt_bool: @@ -182,69 +184,69 @@ void Appl::setOptVal(const char* option, const std::string value, DataType datat void Appl::printVersion() { - std::cerr << m_version << std::endl; + cerr << m_version << endl; exit(EXIT_SUCCESS); } void Appl::printHelp() { - std::cerr << std::endl << "Usage:" << std::endl << " " + cerr << endl << "Usage:" << endl << " " << m_argv[0].substr(m_argv[0].find_last_of("/\\") + 1) << " [OPTIONS...]" ; if (m_needCommand == true) - std::cerr << " COMMAND {ARGS...}" << std::endl << std::endl; + cerr << " COMMAND {ARGS...}" << endl << endl; else - std::cerr << std::endl << std::endl; + cerr << endl << endl; for (o_it = m_opts.begin(); o_it < m_opts.end(); o_it++) { if (strcmp(o_it->name, "__text_only__") == 0) - std::cerr << o_it->description << std::endl; + cerr << o_it->description << endl; else { const char* c = (strlen(o_it->shortname) == 1) ? o_it->shortname : " "; - std::cerr << ((strcmp(c, " ") == 0) ? " " : "-") << c + cerr << ((strcmp(c, " ") == 0) ? " " : "-") << c << " | --" << o_it->name << "\t" << o_it->description - << std::endl; + << endl; } } - std::cerr << " | --settings\n-v | --version\n-h | --help" << std::endl << std::endl; + cerr << " | --settings\n-v | --version\n-h | --help" << endl << endl; exit(EXIT_SUCCESS); } void Appl::printSettings() { - std::cerr << std::endl << "Settings:" << std::endl << std::endl; + cerr << endl << "Settings:" << endl << endl; for (o_it = m_opts.begin(); o_it < m_opts.end(); o_it++) { if (strcmp(o_it->name, "__text_only__") == 0) continue; const char* c = (strlen(o_it->shortname) == 1) ? o_it->shortname : " "; - std::cerr << ((strcmp(c, " ") == 0) ? " " : "-") << c + cerr << ((strcmp(c, " ") == 0) ? " " : "-") << c << " | --" << o_it->name << " = "; if (o_it->datatype == dt_bool) { if (getOptVal(o_it->name) == true) - std::cerr << "yes" << std::endl; + cerr << "yes" << endl; else - std::cerr << "no" << std::endl; + cerr << "no" << endl; } else if (o_it->datatype == dt_int) { - std::cerr << getOptVal(o_it->name) << std::endl; + cerr << getOptVal(o_it->name) << endl; } else if (o_it->datatype == dt_long) { - std::cerr << getOptVal(o_it->name) << std::endl; + cerr << getOptVal(o_it->name) << endl; } else if (o_it->datatype == dt_float) { - std::cerr << getOptVal(o_it->name) << std::endl; + cerr << getOptVal(o_it->name) << endl; } else if (o_it->datatype == dt_string) { - std::cerr << getOptVal(o_it->name) << std::endl; + cerr << getOptVal(o_it->name) << endl; } } - std::cerr << std::endl; + cerr << endl; exit(EXIT_SUCCESS); } diff --git a/src/lib/utils/appl.h b/src/lib/utils/appl.h index 39e6037c..8e988deb 100644 --- a/src/lib/utils/appl.h +++ b/src/lib/utils/appl.h @@ -25,6 +25,8 @@ #include #include +using namespace std; + /** \file appl.h */ /** the available data types. */ @@ -178,7 +180,7 @@ public: * @param num number of interested argument. * @return string value. */ - std::string getArg(const int num) const { return m_arguments[num]; } + string getArg(const int num) const { return m_arguments[num]; } private: /** private constructor - singleton pattern */ @@ -187,15 +189,15 @@ private: Appl& operator=(const Appl&); /** application options */ - std::vector m_opts; - std::vector::const_iterator o_it; + vector m_opts; + vector::const_iterator o_it; /** map option - value */ - std::map m_optvals; - std::map::iterator ov_it; + map m_optvals; + map::iterator ov_it; /** given arguments */ - std::vector m_argv; + vector m_argv; /** application version string */ const char* m_version; @@ -204,14 +206,14 @@ private: bool m_needCommand; /** arguments (argument 0 = command) string */ - std::vector m_arguments; + vector m_arguments; /** * @brief checks the passed parameter if this is a valid option. * @param option to check. * @param value to save if paramter is a valid option. */ - bool checkOption(const std::string& option, const std::string& value); + bool checkOption(const string& option, const string& value); /** * @brief save the passed value to option. @@ -219,7 +221,7 @@ private: * @param value to save. * @param datatype of given option. */ - void setOptVal(const char* option, const std::string value, DataType datatype); + void setOptVal(const char* option, const string value, DataType datatype); /** * @brief print application version. diff --git a/src/lib/utils/daemon.cpp b/src/lib/utils/daemon.cpp index 36ecd155..5aa7adcb 100644 --- a/src/lib/utils/daemon.cpp +++ b/src/lib/utils/daemon.cpp @@ -26,6 +26,8 @@ #include #include +using namespace std; + Daemon& Daemon::Instance() { static Daemon instance; @@ -44,7 +46,7 @@ void Daemon::run(const char* pidfile) pid = fork(); if (pid < 0) { - std::cerr << "daemon fork() failed." << std::endl; + cerr << "daemon fork() failed." << endl; exit(EXIT_FAILURE); } @@ -62,14 +64,14 @@ void Daemon::run(const char* pidfile) // Create a new SID for the child process and // detach the process from the parent (normally a shell) if (setsid() < 0) { - std::cerr << "daemon setsid() failed." << std::endl; + cerr << "daemon setsid() failed." << endl; exit(EXIT_FAILURE); } // Change the current working directory. This prevents the current // directory from being locked; hence not being able to remove it. if (chdir("/tmp") < 0) { //DAEMON_WORKDIR - std::cerr << "daemon chdir() failed." << std::endl; + cerr << "daemon chdir() failed." << endl; exit(EXIT_FAILURE); } @@ -80,7 +82,7 @@ void Daemon::run(const char* pidfile) // write pidfile and try to lock it if (pidfile_open() == false) { - std::cerr << "can't open pidfile: %s" << m_pidfile << std::endl; + cerr << "can't open pidfile: %s" << m_pidfile << endl; exit(EXIT_FAILURE); } diff --git a/src/lib/utils/logger.cpp b/src/lib/utils/logger.cpp index b47a6d81..70b410f1 100644 --- a/src/lib/utils/logger.cpp +++ b/src/lib/utils/logger.cpp @@ -28,6 +28,8 @@ #include #include +using namespace std; + /** static char array with logging area names */ static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus", "cyc" }; @@ -37,19 +39,19 @@ static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "deb /** inline function of log2 */ inline double Log2(double n) { return log(n) / log(2); } -int calcAreas(const std::string areas) +int calcAreas(const string areas) { int m_areas = 0; // prepare data - std::string token; - std::istringstream stream(areas); - std::vector cmd; + string token; + istringstream stream(areas); + vector cmd; - while (std::getline(stream, token, ',') != 0) + while (getline(stream, token, ',') != 0) cmd.push_back(token); - for (std::vector::iterator it = cmd.begin() ; it != cmd.end(); ++it) + for (vector::iterator it = cmd.begin() ; it != cmd.end(); ++it) for (int i = 0; i < Size_of_Areas; i++) { if (strcasecmp("ALL", it->c_str()) == 0) return (pow(2, (int)Size_of_Areas) - 1); @@ -61,7 +63,7 @@ int calcAreas(const std::string areas) return m_areas; } -int calcLevel(const std::string level) +int calcLevel(const string level) { int m_level = event; for (int i = 0; i < Size_of_Level; i++) @@ -72,7 +74,7 @@ int calcLevel(const std::string level) } -LogMessage::LogMessage(const int area, const int level, const std::string text, const bool running) +LogMessage::LogMessage(const int area, const int level, const string text, const bool running) : m_area(area), m_level(level), m_text(text), m_running(running) { char time[24]; @@ -87,7 +89,7 @@ LogMessage::LogMessage(const int area, const int level, const std::string text, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec/1000); - m_time = std::string(time); + m_time = string(time); } @@ -122,23 +124,23 @@ void* LogSink::run() void LogConsole::write(const LogMessage& message) const { - std::cout << message.getTime() << " [" + cout << message.getTime() << " [" << AreaNames[(int)Log2(message.getArea())] << " " << LevelNames[message.getLevel()] << "] " - << message.getText() << std::endl; + << message.getText() << endl; } void LogFile::write(const LogMessage& message) const { - std::fstream file(m_file.c_str(), std::ios::out | std::ios::app); + fstream file(m_file.c_str(), ios::out | ios::app); if (file.is_open() == true) { file << message.getTime() << " [" << AreaNames[(int)Log2(message.getArea())] << " " << LevelNames[message.getLevel()] << "] " - << message.getText() << std::endl; + << message.getText() << endl; file.close(); } } @@ -160,7 +162,7 @@ Logger::~Logger() Logger& Logger::operator+=(LogSink* sink) { sinkCI_t itEnd = m_sinks.end(); - sinkCI_t it = std::find(m_sinks.begin(), itEnd, sink); + sinkCI_t it = find(m_sinks.begin(), itEnd, sink); if (it == itEnd) m_sinks.push_back(sink); @@ -171,7 +173,7 @@ Logger& Logger::operator+=(LogSink* sink) Logger& Logger::operator-=(const LogSink* sink) { sinkCI_t itEnd = m_sinks.end(); - sinkCI_t it = std::find(m_sinks.begin(), itEnd, sink); + sinkCI_t it = find(m_sinks.begin(), itEnd, sink); if (it == itEnd) return (*this); @@ -183,7 +185,7 @@ Logger& Logger::operator-=(const LogSink* sink) return (*this); } -void Logger::log(const int area, const int level, const std::string& data, ...) +void Logger::log(const int area, const int level, const string& data, ...) { if (m_running == true) { char* tmp; @@ -191,7 +193,7 @@ void Logger::log(const int area, const int level, const std::string& data, ...) va_start(ap, data); if (vasprintf(&tmp, data.c_str(), ap) != -1) { - std::string buffer(tmp); + string buffer(tmp); m_logQueue.add(new LogMessage(area, level, buffer)); } diff --git a/src/lib/utils/logger.h b/src/lib/utils/logger.h index 354a8887..3cde40c2 100644 --- a/src/lib/utils/logger.h +++ b/src/lib/utils/logger.h @@ -28,6 +28,8 @@ #include #include +using namespace std; + /** \file logger.h */ /** available types for all subsystems */ @@ -50,10 +52,10 @@ enum LevelType { }; /** global function to get calculate logging areas */ -int calcAreas(const std::string areas); +int calcAreas(const string areas); /** global function to get calculate logging level */ -int calcLevel(const std::string level); +int calcLevel(const string level); /** * @brief class which describes a logging message itself. @@ -69,7 +71,7 @@ public: * @param text the logging message. * @param running the status of logging subsystem. */ - LogMessage(const int area, const int level, const std::string text, const bool running=true); + LogMessage(const int area, const int level, const string text, const bool running=true); /** * @brief get the logging area. @@ -87,7 +89,7 @@ public: * @brief get the logging text. * @return the logging text. */ - std::string getText() const { return (m_text.c_str()); } + string getText() const { return (m_text.c_str()); } /** * @brief status of logging subsystem. @@ -99,7 +101,7 @@ public: * @brief get the logging timestamp. * @return the logging timestamp. */ - std::string getTime() const { return (m_time.c_str()); } + string getTime() const { return (m_time.c_str()); } private: /** the logging area */ @@ -109,13 +111,13 @@ private: int m_level; /** the logging message */ - std::string m_text; + string m_text; /** true if this instance is running */ bool m_running; /** the logging timestamp */ - std::string m_time; + string m_time; }; @@ -232,7 +234,7 @@ public: private: /** the logging file */ - std::string m_file; + string m_file; /** * @brief write the logging message to specific log file. @@ -281,7 +283,7 @@ public: * @param text the logging message. * @param ... possible 'variable argument lists'. */ - void log(const int area, const int level, const std::string& text, ...); + void log(const int area, const int level, const string& text, ...); /** * @brief returns the sink at the specified index. @@ -308,8 +310,8 @@ private: Logger& operator=(const Logger&); /** typedefs for a vector of type LogSink* */ - typedef std::vector sink_t; - typedef std::vector::iterator sinkCI_t; + typedef vector sink_t; + typedef vector::iterator sinkCI_t; /** vector of available logging sinks */ sink_t m_sinks; diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index eb06454e..240fe4ba 100644 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -24,6 +24,8 @@ #include #include +using namespace std; + TCPSocket::TCPSocket(int sfd, struct sockaddr_in* address) : m_sfd(sfd) { char ip[17]; @@ -41,7 +43,7 @@ bool TCPSocket::isValid() } -TCPSocket* TCPClient::connect(const std::string& server, const int& port) +TCPSocket* TCPClient::connect(const string& server, const int& port) { struct sockaddr_in address; int ret; diff --git a/src/lib/utils/tcpsocket.h b/src/lib/utils/tcpsocket.h index 142e7da2..e8ba2d55 100644 --- a/src/lib/utils/tcpsocket.h +++ b/src/lib/utils/tcpsocket.h @@ -23,6 +23,8 @@ #include #include +using namespace std; + /** * @brief class for low level tcp socket operations. (open, close, send, receive). */ @@ -65,7 +67,7 @@ public: * @brief returns the ip address. * @return the ip address. */ - std::string getIP() const { return m_ip; } + string getIP() const { return m_ip; } /** * @brief returns the file descriptor. @@ -87,7 +89,7 @@ private: int m_port; /** ip address of tcp socket */ - std::string m_ip; + string m_ip; /** * @brief private constructor, limited access only for friend classes. @@ -111,7 +113,7 @@ public: * @param port the tcp port. * @return pointer to an opened tcp socket. */ - TCPSocket* connect(const std::string& server, const int& port); + TCPSocket* connect(const string& server, const int& port); }; @@ -127,7 +129,7 @@ public: * @param port the tcp port. * @param address the ip address. */ - TCPServer(const int port, const std::string address) + TCPServer(const int port, const string address) : m_lfd(0), m_port(port), m_address(address), m_listening(false) {} /** @@ -161,7 +163,7 @@ private: int m_port; /** listening tcp socket ip address */ - std::string m_address; + string m_address; /** true if object is already listening */ bool m_listening; diff --git a/src/lib/utils/wqueue.h b/src/lib/utils/wqueue.h index 468885a4..6964c476 100644 --- a/src/lib/utils/wqueue.h +++ b/src/lib/utils/wqueue.h @@ -23,6 +23,8 @@ #include #include +using namespace std; + /** * @brief queue class template for all kinds data types with exclusiv lock. */ @@ -117,7 +119,7 @@ public: private: /** the queue itself */ - std::list m_queue; + list m_queue; /** mutex variable for exclusive lock */ pthread_mutex_t m_mutex;