|
|
|
@ -178,16 +178,31 @@ static USBDescriptor vcom_strings[] = {
@@ -178,16 +178,31 @@ static USBDescriptor vcom_strings[] = {
|
|
|
|
|
{0, NULL}, // version
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
check if one string contains another |
|
|
|
|
*/ |
|
|
|
|
static bool string_contains(const char *haystack, const char *needle) |
|
|
|
|
{ |
|
|
|
|
uint8_t needle_len = strlen(needle); |
|
|
|
|
while (*haystack) { |
|
|
|
|
if (strncmp(haystack, needle, needle_len) == 0) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
haystack++; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
handle substitution of variables in strings for USB descriptors |
|
|
|
|
*/ |
|
|
|
|
static char *string_substitute(const char *str) |
|
|
|
|
{ |
|
|
|
|
uint8_t new_len = strlen(str); |
|
|
|
|
if (strstr(str, "%BOARD%")) { |
|
|
|
|
if (string_contains(str, "%BOARD%")) { |
|
|
|
|
new_len += strlen(HAL_BOARD_NAME) - 7; |
|
|
|
|
} |
|
|
|
|
if (strstr(str, "%SERIAL%")) { |
|
|
|
|
if (string_contains(str, "%SERIAL%")) { |
|
|
|
|
new_len += 24 - 8; |
|
|
|
|
} |
|
|
|
|
char *str2 = malloc(new_len+1); |
|
|
|
|