Merge branch 'master' of github.com:yuhu-/ebusd
This commit is contained in:
@@ -153,11 +153,10 @@ void BaseLoop::start()
|
||||
}
|
||||
|
||||
void BaseLoop::logRaw(const unsigned char byte, bool received) {
|
||||
if (received == true) {
|
||||
if (received == true)
|
||||
L.log(bus, event, "<%02x", byte);
|
||||
} else {
|
||||
else
|
||||
L.log(bus, event, ">%02x", byte);
|
||||
}
|
||||
}
|
||||
|
||||
string BaseLoop::decodeMessage(const string& data)
|
||||
@@ -553,7 +552,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 usage: 'find [-v] [-r] [-w] [-p] [name]' or 'find [-v] [-r] [-w] [-p] 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
|
||||
|
||||
+26
-22
@@ -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); }
|
||||
|
||||
|
||||
+15
-85
@@ -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();
|
||||
@@ -89,13 +73,19 @@ bool connect(const char* host, int port, bool once=true)
|
||||
socket->send(message.c_str(), message.size());
|
||||
|
||||
if (strncasecmp(message.c_str(), "QUIT", 4) != 0 && strncasecmp(message.c_str(), "STOP", 4) != 0) {
|
||||
|
||||
char data[1024];
|
||||
size_t datalen;
|
||||
|
||||
datalen = socket->recv(data, sizeof(data)-1);
|
||||
data[datalen] = '\0';
|
||||
do {
|
||||
memset(data, 0, sizeof(data));
|
||||
datalen = socket->recv(data, sizeof(data)-1);
|
||||
|
||||
if (data[datalen-1] != '\n')
|
||||
cout << data;
|
||||
|
||||
} while (data[datalen-1] != '\n');
|
||||
|
||||
data[datalen] = '\0';
|
||||
cout << data;
|
||||
}
|
||||
else
|
||||
@@ -124,72 +114,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<string> 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<const char*>("server"), A.getOptVal<int>("port"), false);
|
||||
else if (cmd.size() == 2)
|
||||
ret = connect(cmd[1].c_str(), A.getOptVal<int>("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<const char*>("server"), A.getOptVal<int>("port"));
|
||||
if (A.missingCommand() == true)
|
||||
connect(A.getOptVal<const char*>("server"), A.getOptVal<int>("port"), false);
|
||||
else
|
||||
connect(A.getOptVal<const char*>("server"), A.getOptVal<int>("port"), true);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user