Commit bd4d04b260e4973a4538ae3b120cf92a7e9dd2a4

Kano 2013-04-27T00:07:42

bflsc add volt stats

diff --git a/driver-bflsc.c b/driver-bflsc.c
index 7ca551d..021870c 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -68,7 +68,7 @@ struct bflsc_dev {
 	// Stats
 	float temp1;
 	float temp2;
-	float vcc1; // TODO? get V also
+	float vcc1;
 	float vcc2;
 	float vmain;
 	float temp1_max;
@@ -866,7 +866,7 @@ static void get_bflsc_statline_before(char *buf, struct cgpu_info *bflsc)
 	}
 	rd_unlock(&(sc_info->stat_lock));
 
-	tailsprintf(buf, "max%5.1fC%4.2fV | ", temp, vcc1);
+	tailsprintf(buf, " max%3.0fC %4.2fV | ", temp, vcc1);
 }
 
 static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount)
@@ -987,13 +987,16 @@ static void bflsc_flash_led(struct cgpu_info *bflsc, int dev)
 static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 {
 	struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
-	char buf[BFLSC_BUFSIZ+1];
+	char temp_buf[BFLSC_BUFSIZ+1];
+	char volt_buf[BFLSC_BUFSIZ+1];
+	char *tmp;
 	int err, amount;
 	char *firstname, **fields, *lf;
 	char xlink[17];
 	int count;
 	bool res;
 	float temp, temp1, temp2;
+	float vcc1, vcc2, vmain;
 
 	// Device is gone
 	if (bflsc->usbinfo.nodev)
@@ -1026,7 +1029,29 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 		return false;
 	}
 
-	err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE);
+	err = usb_ftdi_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE);
+	if (err < 0 || amount < 1) {
+		mutex_unlock(&(bflsc->device_mutex));
+		if (err < 0) {
+			applog(LOG_ERR, "%s%i: Error: Get%s temp return invalid/timed out (%d:%d)",
+					bflsc->drv->name, bflsc->device_id, xlink, amount, err);
+		} else {
+			applog(LOG_ERR, "%s%i: Error: Get%s temp returned nothing (%d:%d)",
+					bflsc->drv->name, bflsc->device_id, xlink, amount, err);
+		}
+		return false;
+	}
+
+	// N.B. we only get the voltages if the temp succeeds - temp is the important one
+	err = write_to_dev(bflsc, dev, BFLSC_VOLTAGE, BFLSC_VOLTAGE_LEN, &amount, C_REQUESTVOLTS);
+	if (err < 0 || amount != BFLSC_VOLTAGE_LEN) {
+		mutex_unlock(&(bflsc->device_mutex));
+		applog(LOG_ERR, "%s%i: Error: Request%s volts invalid/timed out (%d:%d)",
+				bflsc->drv->name, bflsc->device_id, xlink, amount, err);
+		return false;
+	}
+
+	err = usb_ftdi_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE);
 	if (err < 0 || amount < 1) {
 		mutex_unlock(&(bflsc->device_mutex));
 		if (err < 0) {
@@ -1041,12 +1066,14 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 
 	mutex_unlock(&(bflsc->device_mutex));
 	
-	res = breakdown(ALLCOLON, buf, &count, &firstname, &fields, &lf);
+	res = breakdown(ALLCOLON, temp_buf, &count, &firstname, &fields, &lf);
 	if (lf)
 		*lf = '\0';
 	if (!res || count != 2 || !lf) {
-		applog(LOG_WARNING, "%s%i: Invalid%s temp reply: '%s%s'",
-				bflsc->drv->name, bflsc->device_id, xlink, buf, lf ? LFSTR : BLANK);
+		tmp = str_text(temp_buf);
+		applog(LOG_WARNING, "%s%i: Invalid%s temp reply: '%s'",
+				bflsc->drv->name, bflsc->device_id, xlink, tmp);
+		free(tmp);
 		freebreakdown(&count, &firstname, &fields);
 		dev_error(bflsc, REASON_DEV_COMMS_ERROR);
 		return false;
@@ -1055,6 +1082,33 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
 	temp = temp1 = (float)atoi(fields[0]);
 	temp2 = (float)atoi(fields[1]);
 
+	res = breakdown(NOCOLON, volt_buf, &count, &firstname, &fields, &lf);
+	if (lf)
+		*lf = '\0';
+	if (!res || count != 3 || !lf) {
+		tmp = str_text(volt_buf);
+		applog(LOG_WARNING, "%s%i: Invalid%s volt reply: '%s'",
+				bflsc->drv->name, bflsc->device_id, xlink, tmp);
+		free(tmp);
+		freebreakdown(&count, &firstname, &fields);
+		dev_error(bflsc, REASON_DEV_COMMS_ERROR);
+		return false;
+	}
+
+	vcc1 = (float)atoi(fields[0]) / 1000.0;
+	vcc2 = (float)atoi(fields[1]) / 1000.0;
+	vmain = (float)atoi(fields[2]) / 1000.0;
+	if (vcc1 > 0 || vcc2 > 0 || vmain > 0) {
+		wr_lock(&(sc_info->stat_lock));
+		if (vcc1 > 0)
+			sc_info->sc_devs[dev].vcc1 = vcc1;
+		if (vcc2 > 0)
+			sc_info->sc_devs[dev].vcc2 = vcc2;
+		if (vmain > 0)
+			sc_info->sc_devs[dev].vmain = vmain;
+		wr_unlock(&(sc_info->stat_lock));
+	}
+
 	if (temp1 > 0 || temp2 > 0) {
 		wr_lock(&(sc_info->stat_lock));
 		sc_info->sc_devs[dev].temp1 = temp1;
diff --git a/usbutils.c b/usbutils.c
index 80080da..a472310 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -296,6 +296,7 @@ static const char *C_QUEJOB_S = "QueJob";
 static const char *C_QUEJOBSTATUS_S = "QueJobStatus";
 static const char *C_QUEFLUSH_S = "QueFlush";
 static const char *C_QUEFLUSHREPLY_S = "QueFlushReply";
+static const char *C_REQUESTVOLTS_S = "RequestVolts";
 
 #ifdef EOL
 #undef EOL
@@ -763,6 +764,7 @@ static void cgusb_check_init()
 		usb_commands[C_QUEJOBSTATUS] = C_QUEJOBSTATUS_S;
 		usb_commands[C_QUEFLUSH] = C_QUEFLUSH_S;
 		usb_commands[C_QUEFLUSHREPLY] = C_QUEFLUSHREPLY_S;
+		usb_commands[C_REQUESTVOLTS] = C_REQUESTVOLTS_S;
 
 		stats_initialised = true;
 	}
diff --git a/usbutils.h b/usbutils.h
index db279ce..928a8a5 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -133,6 +133,7 @@ enum usb_cmds {
 	C_QUEJOBSTATUS,
 	C_QUEFLUSH,
 	C_QUEFLUSHREPLY,
+	C_REQUESTVOLTS,
 	C_MAX
 };