sfp: clean the module strings where they are read

The vendor, model and serial strings are filtered while the EEPROM read
fills the buffers, so the page copies them out as they are. NUL still
ends a string, so a field shorter than its slot reads the same as before.

The three loops in send_status() become one call each. strcpy() cannot
return the length: rtl837x_common.h hides that prototype under
RTLP_HOST_TEST so host builds take the C library version, and a call
that adds its result to slen does not compile there. A small static
helper does the copy instead, and bank 1 drops by 96 bytes.
This commit is contained in:
d00f committed 2026-09-17 22:32:46 +02:00
1 parent 56ee56af2e
commit e2c4ed6be3
2 files changed
+16 -7

No files matched your search

+10 -6
View File
@@ -70,6 +70,13 @@ void char_to_html(char c)
}
static void str_x_to_html(__xdata const char *s)
{
while (*s)
outbuf[slen++] = *s++;
}
void json_char_to_html(uint8_t c)
{
if (c < 0x20 || c > 0x7e || c == '"' || c == '\\')
@@ -872,14 +879,11 @@ void send_status(void)
sfp_send_data(sfp, 238, 1);
}
slen += strtox(outbuf + slen,"\",\"sfp_vendor\":\"");
for (uint8_t s = 0; s < 16 && sfp_module_vendor[sfp][s]; s++)
json_char_to_html(sfp_module_vendor[sfp][s]);
str_x_to_html(sfp_module_vendor[sfp]);
slen += strtox(outbuf + slen,"\",\"sfp_model\":\"");
for (uint8_t s = 0; s < 16 && sfp_module_model[sfp][s]; s++)
json_char_to_html(sfp_module_model[sfp][s]);
str_x_to_html(sfp_module_model[sfp]);
slen += strtox(outbuf + slen,"\",\"sfp_serial\":\"");
for (uint8_t s = 0; s < 16 && sfp_module_serial[sfp][s]; s++)
json_char_to_html(sfp_module_serial[sfp][s]);
str_x_to_html(sfp_module_serial[sfp]);
slen += strtox(outbuf + slen,"\",\"sfp_los\":");
if (machine.sfp_port[sfp].pin_los == GPIO_NA) {
slen += strtox(outbuf + slen,"null");
+6 -1
View File
@@ -88,7 +88,12 @@ bool sfp_read_field(__xdata char *dst, uint8_t sfp, uint8_t start, uint8_t lengt
return false;
dst[length] = NUL;
memcpy(dst, sfp_buf, length);
for (uint8_t i = 0; i < length; i++) {
uint8_t c = sfp_buf[i];
if (c && (c < 0x20 || c > 0x7e || c == '"' || c == '\\'))
c = '.';
dst[i] = c;
}
while (length > 0 && dst[--length] == ' ')
dst[length] = NUL;