Browse Source

Merge commit '2bf08bb' into rpc_debug

Conflicts:
	API-README
	api.c
Luke Dashjr 13 years ago
parent
commit
60285bcd8f
4 changed files with 104 additions and 9 deletions
  1. 25 4
      API-README
  2. 75 3
      api.c
  3. 2 0
      logging.h
  4. 2 2
      miner.c

+ 25 - 4
API-README

@@ -288,6 +288,21 @@ The list of requests - a (*) means it requires privileged access - and replies a
                               Current Block Hash=XXXX..., <- blank if none
                               Current Block Hash=XXXX..., <- blank if none
                               LP=true/false| <- LP is in use on at least 1 pool
                               LP=true/false| <- LP is in use on at least 1 pool
 
 
+ debug|setting (*)
+               DEBUG          Debug settings
+                              The optional commands for 'setting' are the same as
+                              the screen curses debug settings
+                              You can only specify one setting
+                              Only the first character is checked (case insensitive):
+                              Silent, Quiet, Verbose, Debug, RPCProto, PerDevice, Normal
+                              The output fields are (as above):
+                              Silent=true/false,
+                              Quiet=true/false,
+                              Verbose=true/false,
+                              Debug=true/false,
+                              RPCProto=true/false,
+                              PerDevice=true/false|
+
 When you enable, disable or restart a GPU or PGA, you will also get Thread messages
 When you enable, disable or restart a GPU or PGA, you will also get Thread messages
 in the BFGMiner status window
 in the BFGMiner status window
 
 
@@ -307,8 +322,9 @@ windows
 Obviously, the JSON format is simply just the names as given before the '='
 Obviously, the JSON format is simply just the names as given before the '='
 with the values after the '='
 with the values after the '='
 
 
-If you enable BFGMiner debug (-D or --debug) you will also get messages showing
-details of the requests received and the replies
+If you enable BFGMiner debug (-D or --debug) or, when BFGMiner debug is off,
+turn on debug with the API command 'debug|debug' you will also get messages
+showing some details of the requests received and the replies
 
 
 There are included 4 program examples for accessing the API:
 There are included 4 program examples for accessing the API:
 
 
@@ -340,13 +356,18 @@ miner.php - an example web page to access the API
 Feature Changelog for external applications using the API:
 Feature Changelog for external applications using the API:
 
 
 
 
+API V1.19
+
+Added API commands:
+ 'debug'
+
+----------
+
 API V1.18
 API V1.18
 
 
 Modified API commands:
 Modified API commands:
  'stats' - add 'Work Had Roll Time', 'Work Can Roll', 'Work Had Expire',
  'stats' - add 'Work Had Roll Time', 'Work Can Roll', 'Work Had Expire',
 		'Work Roll Time' to the pool stats
 		'Work Roll Time' to the pool stats
-
-Modified API commands:
  'config' - include 'ScanTime'
  'config' - include 'ScanTime'
 
 
 ----------
 ----------

+ 75 - 3
api.c

@@ -166,7 +166,7 @@ static const char SEPARATOR = '|';
 #define SEPSTR "|"
 #define SEPSTR "|"
 static const char GPUSEP = ',';
 static const char GPUSEP = ',';
 
 
-static const char *APIVERSION = "1.18";
+static const char *APIVERSION = "1.19";
 static const char *DEAD = "Dead";
 static const char *DEAD = "Dead";
 static const char *SICK = "Sick";
 static const char *SICK = "Sick";
 static const char *NOSTART = "NoStart";
 static const char *NOSTART = "NoStart";
@@ -259,6 +259,7 @@ static const char *OSINFO =
 #define _MINESTATS	"STATS"
 #define _MINESTATS	"STATS"
 #define _CHECK		"CHECK"
 #define _CHECK		"CHECK"
 #define _MINECOIN	"COIN"
 #define _MINECOIN	"COIN"
+#define _DEBUGSET	"DEBUG"
 
 
 static const char ISJSON = '{';
 static const char ISJSON = '{';
 #define JSON0		"{"
 #define JSON0		"{"
@@ -296,6 +297,7 @@ static const char ISJSON = '{';
 #define JSON_MINESTATS	JSON1 _MINESTATS JSON2
 #define JSON_MINESTATS	JSON1 _MINESTATS JSON2
 #define JSON_CHECK	JSON1 _CHECK JSON2
 #define JSON_CHECK	JSON1 _CHECK JSON2
 #define JSON_MINECOIN	JSON1 _MINECOIN JSON2
 #define JSON_MINECOIN	JSON1 _MINECOIN JSON2
+#define JSON_DEBUGSET	JSON1 _DEBUGSET JSON2
 #define JSON_END	JSON4 JSON5
 #define JSON_END	JSON4 JSON5
 
 
 static const char *JSON_COMMAND = "command";
 static const char *JSON_COMMAND = "command";
@@ -391,6 +393,7 @@ static const char *JSON_PARAMETER = "parameter";
 #define MSG_INVBOOL 76
 #define MSG_INVBOOL 76
 #define MSG_FOO 77
 #define MSG_FOO 77
 #define MSG_MINECOIN 78
 #define MSG_MINECOIN 78
+#define MSG_DEBUGSET 79
 
 
 enum code_severity {
 enum code_severity {
 	SEVERITY_ERR,
 	SEVERITY_ERR,
@@ -544,6 +547,7 @@ struct CODES {
  { SEVERITY_ERR,   MSG_INVBOOL,	PARAM_NONE,	"Invalid parameter should be true or false" },
  { SEVERITY_ERR,   MSG_INVBOOL,	PARAM_NONE,	"Invalid parameter should be true or false" },
  { SEVERITY_SUCC,  MSG_FOO,	PARAM_BOOL,	"Failover-Only set to %s" },
  { SEVERITY_SUCC,  MSG_FOO,	PARAM_BOOL,	"Failover-Only set to %s" },
  { SEVERITY_SUCC,  MSG_MINECOIN,PARAM_NONE,	"BFGMiner coin" },
  { SEVERITY_SUCC,  MSG_MINECOIN,PARAM_NONE,	"BFGMiner coin" },
+ { SEVERITY_SUCC,  MSG_DEBUGSET,PARAM_STR,	"Debug settings" },
  { SEVERITY_FAIL, 0, 0, NULL }
  { SEVERITY_FAIL, 0, 0, NULL }
 };
 };
 
 
@@ -2698,7 +2702,7 @@ static void minecoin(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bo
 #endif
 #endif
 		root = api_add_const(root, "Hash Method", SHA256STR, false);
 		root = api_add_const(root, "Hash Method", SHA256STR, false);
 
 
-        mutex_lock(&ch_lock);
+	mutex_lock(&ch_lock);
 	if (current_fullhash && *current_fullhash) {
 	if (current_fullhash && *current_fullhash) {
 		root = api_add_timeval(root, "Current Block Time", &block_timeval, true);
 		root = api_add_timeval(root, "Current Block Time", &block_timeval, true);
 		root = api_add_string(root, "Current Block Hash", current_fullhash, true);
 		root = api_add_string(root, "Current Block Hash", current_fullhash, true);
@@ -2707,7 +2711,7 @@ static void minecoin(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bo
 		root = api_add_timeval(root, "Current Block Time", &t, true);
 		root = api_add_timeval(root, "Current Block Time", &t, true);
 		root = api_add_const(root, "Current Block Hash", BLANK, false);
 		root = api_add_const(root, "Current Block Hash", BLANK, false);
 	}
 	}
-        mutex_unlock(&ch_lock);
+	mutex_unlock(&ch_lock);
 
 
 	root = api_add_bool(root, "LP", &have_longpoll, false);
 	root = api_add_bool(root, "LP", &have_longpoll, false);
 
 
@@ -2717,6 +2721,73 @@ static void minecoin(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bo
 	strcat(io_buffer, buf);
 	strcat(io_buffer, buf);
 }
 }
 
 
+static void debugstate(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
+{
+	struct api_data *root = NULL;
+	char buf[TMPBUFSIZ];
+
+	if (param == NULL)
+		param = (char *)BLANK;
+	else
+		*param = tolower(*param);
+
+	switch(*param) {
+	case 's':
+		opt_realquiet = true;
+		break;
+	case 'q':
+		opt_quiet ^= true;
+		break;
+	case 'v':
+		opt_log_output ^= true;
+		if (opt_log_output)
+			opt_quiet = false;
+		break;
+	case 'd':
+		opt_debug ^= true;
+		opt_log_output = opt_debug;
+		if (opt_debug)
+			opt_quiet = false;
+		break;
+	case 'r':
+		opt_protocol ^= true;
+		if (opt_protocol)
+			opt_quiet = false;
+		break;
+	case 'p':
+		want_per_device_stats ^= true;
+		opt_log_output = want_per_device_stats;
+		break;
+	case 'n':
+		opt_log_output = false;
+		opt_debug = false;
+		opt_quiet = false;
+		opt_protocol = false;
+		want_per_device_stats = false;
+		break;
+	default:
+		// anything else just reports the settings
+		break;
+	}
+
+	sprintf(io_buffer, isjson
+		? "%s," JSON_DEBUGSET
+		: "%s" _DEBUGSET ",",
+		message(MSG_DEBUGSET, 0, NULL, isjson));
+
+	root = api_add_bool(root, "Silent", &opt_realquiet, false);
+	root = api_add_bool(root, "Quiet", &opt_quiet, false);
+	root = api_add_bool(root, "Verbose", &opt_log_output, false);
+	root = api_add_bool(root, "Debug", &opt_debug, false);
+	root = api_add_bool(root, "RPCProto", &opt_protocol, false);
+	root = api_add_bool(root, "PerDevice", &want_per_device_stats, false);
+
+	root = print_data(root, buf, isjson);
+	if (isjson)
+		strcat(buf, JSON_CLOSE);
+	strcat(io_buffer, buf);
+}
+
 static void checkcommand(__maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
 static void checkcommand(__maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
 
 
 struct CMDS {
 struct CMDS {
@@ -2770,6 +2841,7 @@ struct CMDS {
 	{ "check",		checkcommand,	false },
 	{ "check",		checkcommand,	false },
 	{ "failover-only",	failoveronly,	true },
 	{ "failover-only",	failoveronly,	true },
 	{ "coin",		minecoin,	false },
 	{ "coin",		minecoin,	false },
+	{ "debug",		debugstate,	true },
 	{ NULL,			NULL,		false }
 	{ NULL,			NULL,		false }
 };
 };
 
 

+ 2 - 0
logging.h

@@ -21,6 +21,8 @@ enum {
 extern bool opt_debug;
 extern bool opt_debug;
 extern bool opt_debug_console;
 extern bool opt_debug_console;
 extern bool opt_log_output;
 extern bool opt_log_output;
+extern bool opt_realquiet;
+extern bool want_per_device_stats;
 
 
 /* global log_level, messages with lower or equal prio are logged */
 /* global log_level, messages with lower or equal prio are logged */
 extern int opt_log_level;
 extern int opt_log_level;

+ 2 - 2
miner.c

@@ -89,10 +89,10 @@ bool opt_protocol;
 static bool opt_benchmark;
 static bool opt_benchmark;
 static bool want_longpoll = true;
 static bool want_longpoll = true;
 bool have_longpoll;
 bool have_longpoll;
-static bool want_per_device_stats;
+bool want_per_device_stats;
 bool use_syslog;
 bool use_syslog;
 bool opt_quiet;
 bool opt_quiet;
-static bool opt_realquiet;
+bool opt_realquiet;
 bool opt_loginput;
 bool opt_loginput;
 const int opt_cutofftemp = 95;
 const int opt_cutofftemp = 95;
 static int opt_retries = -1;
 static int opt_retries = -1;