Commit 41226f180d9b61ef4b730d298d1219166cb1fc5f

Con Kolivas 2014-02-24T19:51:48

Add a --hfa-name command that allows one to specify the unique opname for a hashfast device.

diff --git a/cgminer.c b/cgminer.c
index 3ea68c0..c4e8a7e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1310,6 +1310,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--hfa-fan",
 		     set_hfa_fan, NULL, NULL,
 		     "Set fanspeed percentage for hashfast, single value or range (default: 10-85)"),
+	OPT_WITH_ARG("--hfa-name",
+		     opt_set_charp, NULL, &opt_hfa_name,
+		     "Set a unique name for a single hashfast device specified with --usb or the first device found"),
 	OPT_WITH_ARG("--hfa-ntime-roll",
 		     opt_set_intval, NULL, &opt_hfa_ntime_roll,
 		     opt_hidden),
diff --git a/driver-hashfast.c b/driver-hashfast.c
index 32e2737..f741c5a 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -27,6 +27,7 @@ bool opt_hfa_dfu_boot;
 int opt_hfa_fan_default = HFA_FAN_DEFAULT;
 int opt_hfa_fan_max = HFA_FAN_MAX;
 int opt_hfa_fan_min = HFA_FAN_MIN;
+char *opt_hfa_name;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Support for the CRC's used in header (CRC-8) and packet body (CRC-32)
@@ -316,14 +317,29 @@ struct op_nameframe {
 	char name[32];
 } __attribute__((packed));
 
-/* If no opname or an invalid opname is set, change it to the serial number if
- * it exists, or a random name based on timestamp if not. */
-static void hfa_choose_opname(struct cgpu_info *hashfast, struct hashfast_info *info)
+static void hfa_write_opname(struct cgpu_info *hashfast, struct hashfast_info *info)
 {
 	const uint8_t opcode = HF_USB_CMD(OP_NAME);
 	struct op_nameframe nameframe;
 	struct hf_header *h = (struct hf_header *)&nameframe;
 	const int tx_length = sizeof(struct op_nameframe);
+
+	memset(&nameframe, 0, sizeof(nameframe));
+	strncpy(nameframe.name, info->op_name, 30);
+	h->preamble = HF_PREAMBLE;
+	h->operation_code = hfa_cmds[opcode].cmd;
+	h->core_address = 1;
+	h->data_length = 32 / 4;
+	h->crc8 = hfa_crc8((unsigned char *)h);
+	applog(LOG_DEBUG, "%s %d: Opname being set to %s", hashfast->drv->name,
+	       hashfast->device_id, info->op_name);
+	__hfa_send_frame(hashfast, opcode, tx_length, (uint8_t *)&nameframe);
+}
+
+/* If no opname or an invalid opname is set, change it to the serial number if
+ * it exists, or a random name based on timestamp if not. */
+static void hfa_choose_opname(struct cgpu_info *hashfast, struct hashfast_info *info)
+{
 	uint64_t usecs;
 
 	if (info->serial_number)
@@ -335,16 +351,7 @@ static void hfa_choose_opname(struct cgpu_info *hashfast, struct hashfast_info *
 		usecs = (uint64_t)(tv_now.tv_sec) * (uint64_t)1000000 + (uint64_t)tv_now.tv_usec;
 		sprintf(info->op_name, "%lx", usecs);
 	}
-	memset(&nameframe, 0, sizeof(nameframe));
-	strncpy(nameframe.name, info->op_name, 32);
-	h->preamble = HF_PREAMBLE;
-	h->operation_code = hfa_cmds[opcode].cmd;
-	h->core_address = 1;
-	h->data_length = 32 / 4;
-	h->crc8 = hfa_crc8((unsigned char *)h);
-	applog(LOG_DEBUG, "%s %d: Opname being set to %s", hashfast->drv->name,
-	       hashfast->device_id, info->op_name);
-	__hfa_send_frame(hashfast, opcode, tx_length, (uint8_t *)&nameframe);
+	hfa_write_opname(hashfast, info);
 }
 
 static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
@@ -774,6 +781,17 @@ static struct cgpu_info *hfa_detect_one(libusb_device *dev, struct usb_find_devi
 	if (!add_cgpu(hashfast))
 		return NULL;
 
+	if (opt_hfa_name) {
+		struct hashfast_info *info = hashfast->device_data;
+
+		strncpy(info->op_name, opt_hfa_name, 30);
+		applog(LOG_NOTICE, "%s %d %03d:%03d: Writing name %s", hashfast->drv->name,
+		       hashfast->device_id, hashfast->usbinfo.bus_number, hashfast->usbinfo.device_address,
+		       info->op_name);
+		hfa_write_opname(hashfast, info);
+		opt_hfa_name = NULL;
+	}
+
 	return hashfast;
 }
 
diff --git a/driver-hashfast.h b/driver-hashfast.h
index be8f141..b578046 100644
--- a/driver-hashfast.h
+++ b/driver-hashfast.h
@@ -27,6 +27,7 @@ int opt_hfa_fan_max;
 int opt_hfa_fan_min;
 
 char *set_hfa_fan(char *arg);
+char *opt_hfa_name;
 
 #define HASHFAST_MINER_THREADS 1
 #define HFA_CLOCK_DEFAULT 550