serial_win: Find BMP comport by serial number.
This commit is contained in:
parent
3eb51ce94f
commit
fca8593d92
@ -37,9 +37,6 @@
|
|||||||
#include "jlink.h"
|
#include "jlink.h"
|
||||||
#include "cmsis_dap.h"
|
#include "cmsis_dap.h"
|
||||||
|
|
||||||
#define VENDOR_ID_BMP 0x1d50
|
|
||||||
#define PRODUCT_ID_BMP 0x6018
|
|
||||||
|
|
||||||
#define VENDOR_ID_STLINK 0x0483
|
#define VENDOR_ID_STLINK 0x0483
|
||||||
#define PRODUCT_ID_STLINK_MASK 0xffe0
|
#define PRODUCT_ID_STLINK_MASK 0xffe0
|
||||||
#define PRODUCT_ID_STLINK_GROUP 0x3740
|
#define PRODUCT_ID_STLINK_GROUP 0x3740
|
||||||
|
@ -14,6 +14,9 @@ void platform_buffer_flush(void);
|
|||||||
#define SET_IDLE_STATE(x)
|
#define SET_IDLE_STATE(x)
|
||||||
#define SET_RUN_STATE(x)
|
#define SET_RUN_STATE(x)
|
||||||
|
|
||||||
|
#define VENDOR_ID_BMP 0x1d50
|
||||||
|
#define PRODUCT_ID_BMP 0x6018
|
||||||
|
|
||||||
typedef enum bmp_type_s {
|
typedef enum bmp_type_s {
|
||||||
BMP_TYPE_NONE = 0,
|
BMP_TYPE_NONE = 0,
|
||||||
BMP_TYPE_BMP,
|
BMP_TYPE_BMP,
|
||||||
|
@ -23,17 +23,59 @@
|
|||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
#include "cl_utils.h"
|
#include "cl_utils.h"
|
||||||
|
|
||||||
HANDLE hComm;
|
static HANDLE hComm;
|
||||||
|
|
||||||
|
static char *find_bmp_by_serial(const char *serial)
|
||||||
|
{
|
||||||
|
char regpath[258];
|
||||||
|
/* First find the containers of the BMP comports */
|
||||||
|
sprintf(regpath,
|
||||||
|
"SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_%04X&PID_%04X\\%s",
|
||||||
|
VENDOR_ID_BMP, PRODUCT_ID_BMP, serial);
|
||||||
|
HKEY hkeySection;
|
||||||
|
LSTATUS res;
|
||||||
|
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &hkeySection);
|
||||||
|
if (res != ERROR_SUCCESS)
|
||||||
|
return NULL;
|
||||||
|
BYTE prefix[128];
|
||||||
|
DWORD maxlen = sizeof(prefix);
|
||||||
|
res = RegQueryValueEx(hkeySection, "ParentIdPrefix", NULL, NULL, prefix,
|
||||||
|
&maxlen);
|
||||||
|
RegCloseKey(hkeySection);
|
||||||
|
if (res != ERROR_SUCCESS)
|
||||||
|
return NULL;
|
||||||
|
printf("prefix %s\n", prefix);
|
||||||
|
sprintf(regpath,
|
||||||
|
"SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_%04X&PID_%04X&MI_00\\%s"
|
||||||
|
"&0000\\Device Parameters",
|
||||||
|
VENDOR_ID_BMP, PRODUCT_ID_BMP, prefix);
|
||||||
|
printf("%s\n", regpath);
|
||||||
|
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &hkeySection);
|
||||||
|
if (res != ERROR_SUCCESS) {
|
||||||
|
printf("Failuere\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
BYTE port[128];
|
||||||
|
maxlen = sizeof(port);
|
||||||
|
res = RegQueryValueEx(hkeySection, "PortName", NULL, NULL, port, &maxlen);
|
||||||
|
RegCloseKey(hkeySection);
|
||||||
|
if (res != ERROR_SUCCESS)
|
||||||
|
return NULL;
|
||||||
|
printf("Portname %s\n", port);
|
||||||
|
return strdup((char*)port);
|
||||||
|
}
|
||||||
|
|
||||||
int serial_open(BMP_CL_OPTIONS_t *cl_opts, char * serial)
|
int serial_open(BMP_CL_OPTIONS_t *cl_opts, char * serial)
|
||||||
{
|
{
|
||||||
(void) serial; /* FIXME: Does Windows allow open with USB serial no? */
|
(void) serial; /* FIXME: Does Windows allow open with USB serial no? */
|
||||||
|
char device[256];
|
||||||
|
if (!cl_opts->opt_device)
|
||||||
|
cl_opts->opt_device = find_bmp_by_serial(serial);
|
||||||
if (!cl_opts->opt_device) {
|
if (!cl_opts->opt_device) {
|
||||||
DEBUG_WARN("Specify the serial device to use!\n");
|
DEBUG_WARN("Unexpected problems finding the device!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char device[256];
|
if (strstr(cl_opts->opt_device, "\\\\.\\")) {
|
||||||
if (strstr(device, "\\\\.\\")) {
|
|
||||||
strncpy(device, cl_opts->opt_device, sizeof(device) - 1);
|
strncpy(device, cl_opts->opt_device, sizeof(device) - 1);
|
||||||
} else {
|
} else {
|
||||||
strcpy(device, "\\\\.\\");
|
strcpy(device, "\\\\.\\");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user