Skip to content

Commit 718e238

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 mvp#575. Tested on macOS and Linux.
1 parent be4d83e commit 718e238

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
@@ -224,6 +224,14 @@ are port numbers for all hubs in chain, starting from root hub for a given USB b
224224
This address is semi-stable - it will not change if you unplug/replug (or turn off/on)
225225
USB device into the same physical USB port (this method is also used in Linux kernel).
226226

227+
To get the status in machine-readable JSON format, use `-j` option:
228+
229+
uhubctl -j
230+
231+
This will output status of all hubs and ports in JSON format, making it easy to integrate
232+
uhubctl with other tools and scripts. The JSON output includes all the same information
233+
as the text output, including hub info, port status, connected devices, and their properties.
234+
227235

228236
Linux USB permissions
229237
=====================

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)