Skip to content

Commit be4d83e

Browse files
committed
Add serial numbers to JSON output
Serial numbers are now included in the JSON output for devices that have them. This completes the JSON output enhancements to match the text output. Example: "serial": "00015919101424154549"
1 parent 83ec8d7 commit be4d83e

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

uhubctl.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,15 +1452,9 @@ char* create_port_status_json(int port, int port_status, const struct descriptor
14521452
char *flags_json = create_status_flags_json(port_status);
14531453
char *hr_json = create_human_readable_json(port_status);
14541454

1455-
// For USB3 hubs, get link state and port speed capability
1455+
// For USB3 hubs, get link state
14561456
const char* link_state_str = NULL;
1457-
const char* port_speed_str = NULL;
14581457
if (port_status & USB_SS_PORT_STAT_POWER) {
1459-
// Check port speed capability
1460-
if ((port_status & USB_SS_PORT_STAT_SPEED) == USB_PORT_STAT_SPEED_5GBPS) {
1461-
port_speed_str = "5gbps";
1462-
}
1463-
14641458
int link_state = port_status & USB_PORT_STAT_LINK_STATE;
14651459
switch (link_state) {
14661460
case USB_SS_PORT_LS_U0: link_state_str = "U0"; break;
@@ -1526,7 +1520,7 @@ char* create_port_status_json(int port, int port_status, const struct descriptor
15261520

15271521
// Return port with basic device info
15281522
// Note: even when ignored, parameters still count towards total
1529-
return mkjson(MKJSON_OBJ, 16,
1523+
return mkjson(MKJSON_OBJ, 17,
15301524
MKJSON_INT, "port", port,
15311525
MKJSON_STRING, "status", status_hex,
15321526
MKJSON_JSON_FREE, "flags", flags_json,
@@ -1541,6 +1535,7 @@ char* create_port_status_json(int port, int port_status, const struct descriptor
15411535
MKJSON_STRING, "usb_version", usb_version,
15421536
MKJSON_STRING, "device_version", device_version,
15431537
MKJSON_INT, "nconfigs", desc.bNumConfigurations,
1538+
ds->serial[0] ? MKJSON_STRING : MKJSON_IGN_STRING, "serial", ds->serial,
15441539
is_mass_storage ? MKJSON_BOOL : MKJSON_IGN_BOOL, "is_mass_storage", is_mass_storage,
15451540
MKJSON_STRING, "description", ds->description[0] ? ds->description : NULL
15461541
);

0 commit comments

Comments
 (0)