From 3b381468fd7e1fccdc002df214e599235d408d23 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 20 Sep 2015 11:52:14 +0200 Subject: [PATCH] added info command --- ChangeLog.md | 1 + src/ebusd/mainloop.cpp | 23 +++++++++++++++++++++++ src/ebusd/mainloop.h | 7 +++++++ 3 files changed, 31 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index ce23f2e9..0826ce34 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -22,6 +22,7 @@ * added data type HCD (for Ochsner) * added log entry for scan completion * automatically invalidate cached data of messages with same name+circuit (ignoring level) +* added "info" command ## Changed files https://github.com/john30/ebusd/compare/v1.2.0...master diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index cd3a86fb..4b15a433 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -202,6 +202,8 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn return executeStop(args, running); if (strcasecmp(str, "Q") == 0 || strcasecmp(str, "QUIT") == 0) return executeQuit(args, connected); + if (strcasecmp(str, "I") == 0 || strcasecmp(str, "INFO") == 0) + return executeInfo(args); if (strcasecmp(str, "H") == 0 || strcasecmp(str, "HELP") == 0) return executeHelp(); return "ERR: command not found"; @@ -829,6 +831,26 @@ string MainLoop::executeStop(vector &args, bool& running) " Stop the daemon."; } +string MainLoop::executeInfo(vector &args) +{ + if (args.size() == 0) + return "usage: info\n" + " Report information about the daemon."; + + ostringstream result; + result << "version: " << PACKAGE_STRING << "\n"; + if (m_busHandler->hasSignal()) { + result << "signal: acquired\n"; + result << "symbol rate: " << static_cast(m_busHandler->getSymbolRate()) << "\n"; + } else { + result << "signal: no signal\n"; + } + result << "masters: " << static_cast(m_busHandler->getMasterCount()) << "\n"; + result << "messages: " << static_cast(m_messages->size()); + + return result.str(); +} + string MainLoop::executeQuit(vector &args, bool& connected) { if (args.size() == 1) { @@ -862,6 +884,7 @@ string MainLoop::executeHelp() " dump Toggle dumping raw bytes\n" " reload Reload CSV config files\n" " stop Stop the daemon\n" + " info|i Report information about the daemon\n" " quit|q Close connection\n" " help|h Print help help [COMMAND]"; } diff --git a/src/ebusd/mainloop.h b/src/ebusd/mainloop.h index 76edf589..483310d4 100644 --- a/src/ebusd/mainloop.h +++ b/src/ebusd/mainloop.h @@ -201,6 +201,13 @@ private: */ string executeStop(vector &args, bool& running); + /** + * Execute the info command. + * @param args the arguments passed to the command (starting with the command itself), or empty for help. + * @return the result string. + */ + string executeInfo(vector &args); + /** * Execute the quit command. * @param args the arguments passed to the command (starting with the command itself), or empty for help.