Browse Source

RPC: "devscan" command to probe for new devices

Luke Dashjr 12 years ago
parent
commit
7469a81139
2 changed files with 42 additions and 0 deletions
  1. 11 0
      README.RPC
  2. 31 0
      api.c

+ 11 - 0
README.RPC

@@ -145,6 +145,10 @@ The list of requests - a (*) means it requires privileged access - and replies a
                               Will not report PGAs if PGA mining is disabled
                               Will not report PGAs if PGA mining is disabled
                               Will not report CPUs if CPU mining is disabled
                               Will not report CPUs if CPU mining is disabled
 
 
+ devscan|info  DEVS           Probes for a device specified by info, which is
+                              the same format as the --scan-serial command line
+                              option
+
  devdetail     DEVS           Each available device with their fixed details
  devdetail     DEVS           Each available device with their fixed details
                               e.g. GPU=0,Driver=opencl,Kernel=diablo,Model=...|
                               e.g. GPU=0,Driver=opencl,Kernel=diablo,Model=...|
 
 
@@ -410,6 +414,13 @@ api-example.py - a Python script to access the API
 Feature Changelog for external applications using the API:
 Feature Changelog for external applications using the API:
 
 
 
 
+API V1.25.1
+
+Added API commands:
+ 'devscan'
+
+----------
+
 API V1.25 (BFGMiner v3.0.1)
 API V1.25 (BFGMiner v3.0.1)
 
 
 Modified API commands:
 Modified API commands:

+ 31 - 0
api.c

@@ -320,6 +320,8 @@ static const char *JSON_PARAMETER = "parameter";
 #define MSG_ZERSUM 96
 #define MSG_ZERSUM 96
 #define MSG_ZERNOSUM 97
 #define MSG_ZERNOSUM 97
 
 
+#define MSG_DEVSCAN 0x100
+
 enum code_severity {
 enum code_severity {
 	SEVERITY_ERR,
 	SEVERITY_ERR,
 	SEVERITY_WARN,
 	SEVERITY_WARN,
@@ -329,6 +331,7 @@ enum code_severity {
 };
 };
 
 
 enum code_parameters {
 enum code_parameters {
+	PARAM_COUNT,
 	PARAM_GPU,
 	PARAM_GPU,
 	PARAM_PGA,
 	PARAM_PGA,
 	PARAM_CPU,
 	PARAM_CPU,
@@ -494,6 +497,7 @@ struct CODES {
  { SEVERITY_ERR,   MSG_ZERINV,	PARAM_STR,	"Invalid zero parameter '%s'" },
  { SEVERITY_ERR,   MSG_ZERINV,	PARAM_STR,	"Invalid zero parameter '%s'" },
  { SEVERITY_SUCC,  MSG_ZERSUM,	PARAM_STR,	"Zeroed %s stats with summary" },
  { SEVERITY_SUCC,  MSG_ZERSUM,	PARAM_STR,	"Zeroed %s stats with summary" },
  { SEVERITY_SUCC,  MSG_ZERNOSUM, PARAM_STR,	"Zeroed %s stats without summary" },
  { SEVERITY_SUCC,  MSG_ZERNOSUM, PARAM_STR,	"Zeroed %s stats without summary" },
+ { SEVERITY_SUCC,  MSG_DEVSCAN, PARAM_COUNT,	"Added %d new device(s)" },
  { SEVERITY_FAIL, 0, 0, NULL }
  { SEVERITY_FAIL, 0, 0, NULL }
 };
 };
 
 
@@ -1184,6 +1188,7 @@ static void message(struct io_data *io_data, int messageid, int paramid, char *p
 			severity[1] = '\0';
 			severity[1] = '\0';
 
 
 			switch(codes[i].params) {
 			switch(codes[i].params) {
+				case PARAM_COUNT:
 				case PARAM_GPU:
 				case PARAM_GPU:
 				case PARAM_PGA:
 				case PARAM_PGA:
 				case PARAM_CPU:
 				case PARAM_CPU:
@@ -1583,6 +1588,31 @@ static void gpudev(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *p
 }
 }
 #endif
 #endif
 
 
+static void devscan(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, __maybe_unused char group)
+{
+	int n;
+	bool io_open = false;
+	
+	applog(LOG_DEBUG, "RPC: request to scan %s for devices",
+	       param);
+	
+	if (param && !param[0])
+		param = NULL;
+	
+	n = scan_serial(param);
+	
+	message(io_data, MSG_DEVSCAN, n, NULL, isjson);
+	
+	io_open = io_add(io_data, isjson ? COMSTR JSON_DEVS : _DEVS COMSTR);
+
+	n = total_devices - n;
+	for (int i = n; i < total_devices; ++i)
+		devdetail_an(io_data, get_devices(i), isjson, i > n);
+	
+	if (isjson && io_open)
+		io_close(io_data);
+}
+
 #ifdef HAVE_AN_FPGA
 #ifdef HAVE_AN_FPGA
 static void pgadev(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
 static void pgadev(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
 {
 {
@@ -3072,6 +3102,7 @@ struct CMDS {
 } cmds[] = {
 } cmds[] = {
 	{ "version",		apiversion,	false },
 	{ "version",		apiversion,	false },
 	{ "config",		minerconfig,	false },
 	{ "config",		minerconfig,	false },
+	{ "devscan",		devscan,	false },
 	{ "devs",		devstatus,	false },
 	{ "devs",		devstatus,	false },
 	{ "devdetail",	devdetail,	false },
 	{ "devdetail",	devdetail,	false },
 	{ "pools",		poolstatus,	false },
 	{ "pools",		poolstatus,	false },