Skip to content

Commit f866aa1

Browse files
committed
Replace cJSON with mkjson and fix JSON output issues
- Replace cJSON library (3,443 lines) with lightweight mkjson (357 lines) - Fix mkjson bug: change %Ld to %lld for proper 64-bit integer handling - Add missing JSON fields: device descriptions, USB3 link states, serial numbers - Fix USB3 detection by checking hub->super_speed flag instead of port status bits - Fix buffer allocations with proper size calculations - Handle all alternate settings in interfaces array - Replace unsafe string operations (strcpy/strcat) with snprintf - Change 'speed_bits' field to 'speed_bps' for consistency - Document JSON output option (-j) in README Addresses feedback from PR #575. Tested on macOS and Linux.
1 parent 3a39f48 commit f866aa1

File tree

3 files changed

+329
-165
lines changed

3 files changed

+329
-165
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ are port numbers for all hubs in chain, starting from root hub for a given USB b
239239
This address is semi-stable - it will not change if you unplug/replug (or turn off/on)
240240
USB device into the same physical USB port (this method is also used in Linux kernel).
241241

242+
To get the status in machine-readable JSON format, use `-j` option:
243+
244+
uhubctl -j
245+
246+
This will output status of all hubs and ports in JSON format, making it easy to integrate
247+
uhubctl with other tools and scripts. The JSON output includes all the same information
248+
as the text output, including hub info, port status, connected devices, and their properties.
249+
242250

243251
Linux USB permissions
244252
=====================

mkjson.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ char *mkjson( enum mkjson_container_type otype, int count, ... )
202202
else
203203
intval = va_arg( ap, long long int );
204204

205-
if ( allsprintf( chunks + i, "%s%Ld", prefix, intval ) == -1 ) chunks[i] = NULL;
205+
if ( allsprintf( chunks + i, "%s%lld", prefix, intval ) == -1 ) chunks[i] = NULL;
206206
break;
207207

208208
// double / long double

0 commit comments

Comments
 (0)