diff --git a/src/ebusd/baseloop.cpp b/src/ebusd/baseloop.cpp index fbc84dda..07b4c11e 100644 --- a/src/ebusd/baseloop.cpp +++ b/src/ebusd/baseloop.cpp @@ -553,7 +553,7 @@ string BaseLoop::decodeMessage(const string& data) result << "commands:" << endl << " read - read ebus values 'read [-v] [-f] [-m seconds] [class] name' or 'read [-v] [-f] [-m seconds] class name field'" << endl << " write - write ebus values 'write class name value[;value]*' or 'write -h ZZPBSBNNDx'" << endl - << " find - find ebus values 'find [name]' or 'find class name'" << endl + << " find - find ebus values 'find [name]' or 'find class name'" << endl << endl << " scan - scan ebus known addresses 'scan'" << endl << " - scan ebus all addresses 'scan full'" << endl << " - show scan results 'scan result'" << endl << endl diff --git a/src/lib/utils/appl.h b/src/lib/utils/appl.h index ceab8218..98196183 100644 --- a/src/lib/utils/appl.h +++ b/src/lib/utils/appl.h @@ -31,34 +31,29 @@ using namespace std; /** @brief the available data types. */ enum DataType { - dt_none, /*!< default for __text_only__ */ - dt_bool, /*!< boolean */ - dt_hex, /*!< hex integer */ - dt_int, /*!< dec integer */ - dt_long, /*!< long */ - dt_float, /*!< float */ - dt_string /*!< string */ + dt_none, //!< default for __text_only__ + dt_bool, //!< boolean + dt_hex, //!< hex integer + dt_int, //!< dec integer + dt_long, //!< long + dt_float, //!< float + dt_string //!< string }; /** @brief option types. */ enum OptionType { - ot_none, /*!< no option type is needed */ - ot_optional, /*!< a value is optional */ - ot_mandatory /*!< a value is mandatory */ + ot_none, //!< no option type is needed + ot_optional, //!< a value is optional + ot_mandatory //!< a value is mandatory }; /** @brief structure for defining application options */ typedef struct { - /** long option name */ - const char* name; - /** short option name */ - const char* shortname; - /** description for this option */ - const char* description; - /** data type for this option */ - DataType datatype; - /** indicates whether an option takes an argument */ - OptionType optiontype; + const char* name; //!< long option name + const char* shortname; //!< short option name + const char* description; //!< description for this option + DataType datatype; //!< data type for this option + OptionType optiontype; //!< indicates whether an option takes an argument } opt_t; /** @@ -67,12 +62,16 @@ typedef struct { union OptVal { /** boolean */ bool b; + /** integer */ int i; + /** long */ long l; + /** float */ float f; + /** string */ const char* c; @@ -80,26 +79,31 @@ union OptVal { * @brief clear memory */ OptVal() { memset(this, 0, sizeof(OptVal)); } + /** * @brief create boolean type * @param _b the boolean */ OptVal(bool _b) : b(_b) {} + /** * @brief create integer type * @param _i the integer */ OptVal(int _i) : i(_i) {} + /** * @brief create long type * @param _l the long */ OptVal(long _l) : l(_l) {} + /** * @brief create float type * @param _f the float */ OptVal(float _f) : f(_f) {} + /** * @brief create string type * @param _c the string @@ -191,8 +195,8 @@ public: string getCommand() const { return m_command; } /** - * @brief returns the string of given command. - * @return the command string. + * @brief Get whether a command string is missing. + * @return true if a command string is missing. */ bool missingCommand() const { return (m_command.size() == 0 ? true : false); } diff --git a/src/tools/ebusctl.cpp b/src/tools/ebusctl.cpp index e97e1854..3a1ec332 100644 --- a/src/tools/ebusctl.cpp +++ b/src/tools/ebusctl.cpp @@ -47,23 +47,7 @@ void define_args() } -enum CommandType { - ct_open, - ct_exit, - ct_help, - ct_invalid -}; - -CommandType getCase(const string& item) -{ - if (strcasecmp(item.c_str(), "OPEN") == 0) return ct_open; - if (strcasecmp(item.c_str(), "EXIT") == 0) return ct_exit; - if (strcasecmp(item.c_str(), "HELP") == 0) return ct_help; - - return ct_invalid; -} - -bool connect(const char* host, int port, bool once=true) +bool connect(const char* host, int port, bool once) { TCPClient* client = new TCPClient(); @@ -124,72 +108,12 @@ int main(int argc, char* argv[]) // parse arguments if (A.parseArgs(argc, argv) == false) - return EXIT_SUCCESS; + exit(EXIT_FAILURE); - if (A.missingCommand() == true) { - cout << "interactive mode started." << endl; - - bool running = true; - - do { - string input, token; - vector cmd; - - cout << "$: "; - getline(cin, input); - - // prepare input - istringstream stream(input); - while (getline(stream, token, ' ') != 0) - cmd.push_back(token); - - if (cmd.size() == 0) - cout << "command missing" << endl; - - switch (getCase(cmd[0])) { - case ct_invalid: - cout << "command not found" << endl; - break; - - case ct_open: - { - bool ret = true; - cout << "connect to..." << endl; - if (cmd.size() == 1) - ret = connect(A.getOptVal("server"), A.getOptVal("port"), false); - else if (cmd.size() == 2) - ret = connect(cmd[1].c_str(), A.getOptVal("port"), false); - else if (cmd.size() == 3) - ret = connect(cmd[1].c_str(), atoi(cmd[2].c_str()), false); - else - cout << "open [host [port]]" << endl; - - running = ret; - } - - break; - - case ct_exit: - running = false; - break; - - case ct_help: - cout << "commands:" << endl - << " open - open connection to ebusd 'open [host [port]]'" << endl - << " exit - exit ebusctl" << endl - << " help - print this page" << endl; - break; - - default: - break; - } - - } while (running == true); - - exit(EXIT_SUCCESS); - } - - connect(A.getOptVal("server"), A.getOptVal("port")); + if (A.missingCommand() == true) + connect(A.getOptVal("server"), A.getOptVal("port"), false); + else + connect(A.getOptVal("server"), A.getOptVal("port"), true); exit(EXIT_SUCCESS); }