Skip to content

Commit 3a39f48

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 a877048 commit 3a39f48

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
@@ -1545,15 +1545,9 @@ char* create_port_status_json(int port, int port_status, const struct descriptor
15451545
char *flags_json = create_status_flags_json(port_status);
15461546
char *hr_json = create_human_readable_json(port_status);
15471547

1548-
// For USB3 hubs, get link state and port speed capability
1548+
// For USB3 hubs, get link state
15491549
const char* link_state_str = NULL;
1550-
const char* port_speed_str = NULL;
15511550
if (port_status & USB_SS_PORT_STAT_POWER) {
1552-
// Check port speed capability
1553-
if ((port_status & USB_SS_PORT_STAT_SPEED) == USB_PORT_STAT_SPEED_5GBPS) {
1554-
port_speed_str = "5gbps";
1555-
}
1556-
15571551
int link_state = port_status & USB_PORT_STAT_LINK_STATE;
15581552
switch (link_state) {
15591553
case USB_SS_PORT_LS_U0: link_state_str = "U0"; break;
@@ -1619,7 +1613,7 @@ char* create_port_status_json(int port, int port_status, const struct descriptor
16191613

16201614
// Return port with basic device info
16211615
// Note: even when ignored, parameters still count towards total
1622-
return mkjson(MKJSON_OBJ, 16,
1616+
return mkjson(MKJSON_OBJ, 17,
16231617
MKJSON_INT, "port", port,
16241618
MKJSON_STRING, "status", status_hex,
16251619
MKJSON_JSON_FREE, "flags", flags_json,
@@ -1634,6 +1628,7 @@ char* create_port_status_json(int port, int port_status, const struct descriptor
16341628
MKJSON_STRING, "usb_version", usb_version,
16351629
MKJSON_STRING, "device_version", device_version,
16361630
MKJSON_INT, "nconfigs", desc.bNumConfigurations,
1631+
ds->serial[0] ? MKJSON_STRING : MKJSON_IGN_STRING, "serial", ds->serial,
16371632
is_mass_storage ? MKJSON_BOOL : MKJSON_IGN_BOOL, "is_mass_storage", is_mass_storage,
16381633
MKJSON_STRING, "description", ds->description[0] ? ds->description : NULL
16391634
);

0 commit comments

Comments
 (0)