Commit 96c0c31775f190817ce3c84a3cf4e38499b860d3

Kano 2013-08-19T20:34:37

BTB get version from Firmware

diff --git a/driver-avalon.c b/driver-avalon.c
index 6d5276a..94b0eb2 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -660,6 +660,31 @@ static int bitburner_get_core_voltage(struct cgpu_info *avalon)
 	}
 }
 
+static void bitburner_get_version(struct cgpu_info *avalon)
+{
+	struct avalon_info *info = avalon->device_data;
+	uint8_t buf[3];
+	int err;
+	int amount;
+
+	err = usb_transfer_read(avalon, FTDI_TYPE_IN, BITBURNER_REQUEST,
+			BITBURNER_VALUE, BITBURNER_INDEX_GET_VERSION,
+			(char *)buf, sizeof(buf), &amount,
+			C_GETVERSION);
+	if (unlikely(err != 0 || amount != sizeof(buf))) {
+		applog(LOG_DEBUG, "%s%i: GetVersion failed: err=%d, amt=%d assuming %d.%d.%d",
+			avalon->drv->name, avalon->device_id, err, amount,
+			BITBURNER_VERSION1, BITBURNER_VERSION2, BITBURNER_VERSION3);
+		info->version1 = BITBURNER_VERSION1;
+		info->version2 = BITBURNER_VERSION2;
+		info->version3 = BITBURNER_VERSION3;
+	} else {
+		info->version1 = buf[0];
+		info->version2 = buf[1];
+		info->version3 = buf[2];
+	}
+}
+
 static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found)
 {
 	int baud, miner_count, asic_count, timeout, frequency;
@@ -746,6 +771,8 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
 				BITBURNER_MAX_COREMV);
 		} else
 			bitburner_set_core_voltage(avalon, opt_bitburner_core_voltage);
+
+		bitburner_get_version(avalon);
 	}
 
 	return true;
@@ -1454,6 +1481,7 @@ static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
 {
 	struct api_data *root = NULL;
 	struct avalon_info *info = cgpu->device_data;
+	char buf[64];
 	int i;
 
 	root = api_add_int(root, "baud", &(info->baud), false);
@@ -1481,6 +1509,10 @@ static struct api_data *avalon_api_stats(struct cgpu_info *cgpu)
 		root = api_add_int(root, mcw, &(info->matching_work[i]), false);
 	}
 
+	snprintf(buf, sizeof(buf), "%"PRIu8".%"PRIu8".%"PRIu8,
+			info->version1, info->version2, info->version3);
+	root = api_add_string(root, "version", buf, true);
+
 	return root;
 }
 
diff --git a/driver-avalon.h b/driver-avalon.h
index e8f07c7..6f8f2e1 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -142,8 +142,16 @@ struct avalon_info {
 	bool reset;
 	bool overheat;
 	bool optimal;
+
+	uint8_t version1;
+	uint8_t version2;
+	uint8_t version3;
 };
 
+#define BITBURNER_VERSION1 1
+#define BITBURNER_VERSION2 0
+#define BITBURNER_VERSION3 0
+
 #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
 #define AVALON_READ_SIZE (sizeof(struct avalon_result))
 #define AVALON_ARRAY_SIZE 3
diff --git a/usbutils.h b/usbutils.h
index b14709c..287ef04 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -53,6 +53,7 @@
 #define BITBURNER_VALUE 0x4242
 #define BITBURNER_INDEX_SET_VOLTAGE 1
 #define BITBURNER_INDEX_GET_VOLTAGE 2
+#define BITBURNER_INDEX_GET_VERSION 4
 
 // CMR = 115200 & 57600
 #define FTDI_VALUE_BAUD_CMR_115 0xc068