API allow display/change failover-only setting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
diff --git a/API-README b/API-README
index 8e099c4..ee9a704 100644
--- a/API-README
+++ b/API-README
@@ -122,7 +122,9 @@ The list of requests - a (*) means it requires privileged access - and replies a
ADL in use=X, <- Y or N if any GPU has ADL
Strategy=Name, <- the current pool strategy
Log Interval=N, <- log interval (--log N)
- Device Code=GPU ICA | <- spaced list of compiled devices
+ Device Code=GPU ICA , <- spaced list of compiled devices
+ OS=Linux/Apple/..., <- operating System
+ Failover-Only=true/false | <- failover-only setting
summary SUMMARY The status summary of the miner
e.g. Elapsed=NNN,Found Blocks=N,Getworks=N,...|
@@ -275,6 +277,10 @@ The list of requests - a (*) means it requires privileged access - and replies a
check|cmd COMMAND Exists=Y/N, <- 'cmd' exists in this version
Access=Y/N| <- you have access to use 'cmd'
+ failover-only|true/false (*)
+ none There is no reply section just the STATUS section
+ stating what failover-only was set to
+
When you enable, disable or restart a GPU or PGA, you will also get Thread messages
in the cgminer status window
@@ -327,6 +333,16 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
+API V1.16
+
+Added API commands:
+ 'failover-only'
+
+Modified API commands:
+ 'config' - include failover-only state
+
+----------
+
API V1.15 (cgminer v2.6.1)
Added API commands:
diff --git a/api.c b/api.c
index 557aa5e..8dd7d90 100644
--- a/api.c
+++ b/api.c
@@ -166,7 +166,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.15";
+static const char *APIVERSION = "1.16";
static const char *DEAD = "Dead";
static const char *SICK = "Sick";
static const char *NOSTART = "NoStart";
@@ -184,6 +184,9 @@ static const char *YES = "Y";
static const char *NO = "N";
static const char *NULLSTR = "(null)";
+static const char *TRUESTR = "true";
+static const char *FALSESTR = "false";
+
static const char *DEVICECODE = ""
#ifdef HAVE_OPENCL
"GPU "
@@ -376,6 +379,9 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_CHECK 72
#define MSG_POOLPRIO 73
#define MSG_DUPPID 74
+#define MSG_MISBOOL 75
+#define MSG_INVBOOL 76
+#define MSG_FOO 77
enum code_severity {
SEVERITY_ERR,
@@ -403,6 +409,7 @@ enum code_parameters {
PARAM_POOL,
PARAM_STR,
PARAM_BOTH,
+ PARAM_BOOL,
PARAM_NONE
};
@@ -524,6 +531,9 @@ struct CODES {
{ SEVERITY_SUCC, MSG_MINESTATS,PARAM_NONE, "CGMiner stats" },
{ SEVERITY_ERR, MSG_MISCHK, PARAM_NONE, "Missing check cmd" },
{ SEVERITY_SUCC, MSG_CHECK, PARAM_NONE, "Check command" },
+ { SEVERITY_ERR, MSG_MISBOOL, PARAM_NONE, "Missing parameter: true/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_FAIL, 0, 0, NULL }
};
@@ -928,7 +938,7 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
sprintf(buf, "%.15f", *((double *)(root->data)));
break;
case API_BOOL:
- sprintf(buf, "%s", *((bool *)(root->data)) ? "true" : "false");
+ sprintf(buf, "%s", *((bool *)(root->data)) ? TRUESTR : FALSESTR);
break;
case API_TIMEVAL:
sprintf(buf, "%ld.%06ld",
@@ -1133,6 +1143,9 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
case PARAM_BOTH:
sprintf(buf, codes[i].description, paramid, param2);
break;
+ case PARAM_BOOL:
+ sprintf(buf, codes[i].description, paramid ? TRUESTR : FALSESTR);
+ break;
case PARAM_NONE:
default:
strcpy(buf, codes[i].description);
@@ -1233,6 +1246,7 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
root = api_add_int(root, "Log Interval", &opt_log_interval, false);
root = api_add_const(root, "Device Code", DEVICECODE, false);
root = api_add_const(root, "OS", OSINFO, false);
+ root = api_add_bool(root, "Failover-Only", &opt_fail_only, false);
root = print_data(root, buf, isjson);
if (isjson)
@@ -1240,8 +1254,7 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
strcat(io_buffer, buf);
}
-static const char*
-status2str(enum alive status)
+static const char *status2str(enum alive status)
{
switch (status) {
case LIFE_WELL:
@@ -2704,6 +2717,27 @@ static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
strcat(io_buffer, JSON_CLOSE);
}
+static void failoveronly(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
+{
+ if (param == NULL || *param == '\0') {
+ strcpy(io_buffer, message(MSG_MISBOOL, 0, NULL, isjson));
+ return;
+ }
+
+ *param = tolower(*param);
+
+ if (*param != 't' && *param != 'f') {
+ strcpy(io_buffer, message(MSG_INVBOOL, 0, NULL, isjson));
+ return;
+ }
+
+ bool tf = (*param == 't');
+
+ opt_fail_only = tf;;
+
+ strcpy(io_buffer, message(MSG_FOO, tf, NULL, isjson));
+}
+
static void checkcommand(__maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
struct CMDS {
@@ -2754,6 +2788,7 @@ struct CMDS {
{ "restart", dorestart, true },
{ "stats", minerstats, false },
{ "check", checkcommand, false },
+ { "failover-only", failoveronly, true },
{ NULL, NULL, false }
};
diff --git a/cgminer.c b/cgminer.c
index 171c94c..15b7198 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -130,7 +130,7 @@ bool use_curses;
#endif
static bool opt_submit_stale = true;
static int opt_shares;
-static bool opt_fail_only;
+bool opt_fail_only;
bool opt_autofan;
bool opt_autoengine;
bool opt_noadl;
diff --git a/miner.h b/miner.h
index 5afa071..af66e85 100644
--- a/miner.h
+++ b/miner.h
@@ -551,6 +551,7 @@ extern bool opt_protocol;
extern char *opt_kernel_path;
extern char *opt_socks_proxy;
extern char *cgminer_path;
+extern bool opt_fail_only;
extern bool opt_autofan;
extern bool opt_autoengine;
extern bool use_curses;