Initial support for string write
This commit is contained in:
parent
f0f9059ade
commit
8f100f5df3
24
src/term.c
24
src/term.c
|
@ -404,17 +404,26 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
uint8_t size;
|
uint8_t size;
|
||||||
bool is_float;
|
bool is_float;
|
||||||
bool is_signed;
|
bool is_signed;
|
||||||
|
char * str_ptr;
|
||||||
// Data union
|
// Data union
|
||||||
union {
|
union {
|
||||||
float f;
|
float f;
|
||||||
int64_t ll;
|
int64_t ll;
|
||||||
uint8_t a[8];
|
uint8_t a[8];
|
||||||
};
|
};
|
||||||
} data = {.bytes_grown = 0, .size = 0, .is_float = false, .ll = 0, .is_signed = false};
|
} data = {
|
||||||
|
.bytes_grown = 0,
|
||||||
|
.size = 0,
|
||||||
|
.is_float = false,
|
||||||
|
.is_signed = false,
|
||||||
|
.str_ptr = NULL,
|
||||||
|
.ll = 0
|
||||||
|
};
|
||||||
|
|
||||||
for (i = start_offset; i < len + start_offset; i++) {
|
for (i = start_offset; i < len + start_offset; i++) {
|
||||||
data.is_float = false;
|
data.is_float = false;
|
||||||
data.size = 0;
|
data.size = 0;
|
||||||
|
data.str_ptr = NULL;
|
||||||
|
|
||||||
// Handle the next argument
|
// Handle the next argument
|
||||||
if (i < argc - start_offset + 3) {
|
if (i < argc - start_offset + 3) {
|
||||||
|
@ -452,6 +461,12 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
// Try single character
|
// Try single character
|
||||||
if (argv[i][0] == '\'' && argv[i][2] == '\'') {
|
if (argv[i][0] == '\'' && argv[i][2] == '\'') {
|
||||||
data.ll = argv[i][1];
|
data.ll = argv[i][1];
|
||||||
|
} else {
|
||||||
|
// Try string that starts and ends with quote
|
||||||
|
if (argv[i][0] == '\"' && argv[i][strlen(argv[i]) - 1] == '\"') {
|
||||||
|
data.str_ptr = calloc(strlen(argv[i])+0x10, sizeof(char));
|
||||||
|
strncpy(data.str_ptr, argv[i] + 1, strlen(argv[i]) - 2);
|
||||||
|
avrdude_message(MSG_INFO, "argv: %s, malloc: %s\n", argv[i], data.str_ptr);
|
||||||
} else {
|
} else {
|
||||||
avrdude_message(MSG_INFO, "\n%s (write): can't parse data \"%s\"\n",
|
avrdude_message(MSG_INFO, "\n%s (write): can't parse data \"%s\"\n",
|
||||||
progname, argv[i]);
|
progname, argv[i]);
|
||||||
|
@ -460,6 +475,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Print warning if data size might be ambiguous
|
// Print warning if data size might be ambiguous
|
||||||
bool is_hex = (strncmp(argv[i], "0x", 2) == 0);
|
bool is_hex = (strncmp(argv[i], "0x", 2) == 0);
|
||||||
|
@ -491,6 +507,11 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
data.size = 1;
|
data.size = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(data.str_ptr != NULL) {
|
||||||
|
for(int16_t j = 0; j < strlen(data.str_ptr); j++)
|
||||||
|
buf[i - start_offset + data.bytes_grown++] = (uint8_t)data.str_ptr[j];
|
||||||
|
free(data.str_ptr);
|
||||||
|
} else {
|
||||||
buf[i - start_offset + data.bytes_grown] = data.a[0];
|
buf[i - start_offset + data.bytes_grown] = data.a[0];
|
||||||
if (llabs(data.ll) > 0x000000FF || data.size >= 2 || data.is_float)
|
if (llabs(data.ll) > 0x000000FF || data.size >= 2 || data.is_float)
|
||||||
buf[i - start_offset + ++data.bytes_grown] = data.a[1];
|
buf[i - start_offset + ++data.bytes_grown] = data.a[1];
|
||||||
|
@ -505,6 +526,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
buf[i - start_offset + ++data.bytes_grown] = data.a[7];
|
buf[i - start_offset + ++data.bytes_grown] = data.a[7];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// When in "fill" mode, the maximum size is already predefined
|
// When in "fill" mode, the maximum size is already predefined
|
||||||
if (write_mode == WRITE_MODE_FILL)
|
if (write_mode == WRITE_MODE_FILL)
|
||||||
|
|
Loading…
Reference in New Issue