mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
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:
1 parent
56ee56af2e
commit
e2c4ed6be3
2 files changed
+16
-7
No files matched your search
+10
-6
@@ -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)
|
void json_char_to_html(uint8_t c)
|
||||||
{
|
{
|
||||||
if (c < 0x20 || c > 0x7e || c == '"' || c == '\\')
|
if (c < 0x20 || c > 0x7e || c == '"' || c == '\\')
|
||||||
@@ -872,14 +879,11 @@ void send_status(void)
|
|||||||
sfp_send_data(sfp, 238, 1);
|
sfp_send_data(sfp, 238, 1);
|
||||||
}
|
}
|
||||||
slen += strtox(outbuf + slen,"\",\"sfp_vendor\":\"");
|
slen += strtox(outbuf + slen,"\",\"sfp_vendor\":\"");
|
||||||
for (uint8_t s = 0; s < 16 && sfp_module_vendor[sfp][s]; s++)
|
str_x_to_html(sfp_module_vendor[sfp]);
|
||||||
json_char_to_html(sfp_module_vendor[sfp][s]);
|
|
||||||
slen += strtox(outbuf + slen,"\",\"sfp_model\":\"");
|
slen += strtox(outbuf + slen,"\",\"sfp_model\":\"");
|
||||||
for (uint8_t s = 0; s < 16 && sfp_module_model[sfp][s]; s++)
|
str_x_to_html(sfp_module_model[sfp]);
|
||||||
json_char_to_html(sfp_module_model[sfp][s]);
|
|
||||||
slen += strtox(outbuf + slen,"\",\"sfp_serial\":\"");
|
slen += strtox(outbuf + slen,"\",\"sfp_serial\":\"");
|
||||||
for (uint8_t s = 0; s < 16 && sfp_module_serial[sfp][s]; s++)
|
str_x_to_html(sfp_module_serial[sfp]);
|
||||||
json_char_to_html(sfp_module_serial[sfp][s]);
|
|
||||||
slen += strtox(outbuf + slen,"\",\"sfp_los\":");
|
slen += strtox(outbuf + slen,"\",\"sfp_los\":");
|
||||||
if (machine.sfp_port[sfp].pin_los == GPIO_NA) {
|
if (machine.sfp_port[sfp].pin_los == GPIO_NA) {
|
||||||
slen += strtox(outbuf + slen,"null");
|
slen += strtox(outbuf + slen,"null");
|
||||||
|
|||||||
@@ -88,7 +88,12 @@ bool sfp_read_field(__xdata char *dst, uint8_t sfp, uint8_t start, uint8_t lengt
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
dst[length] = NUL;
|
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] == ' ')
|
while (length > 0 && dst[--length] == ' ')
|
||||||
dst[length] = NUL;
|
dst[length] = NUL;
|
||||||
|
|||||||
Reference in new issue
Block a user