pj-bridge
Bridge a delimiter-framed TCP binary stream into JSON over WebSocket for PlotJuggler or stdout (if file).
Mode: PlotJuggler runs the WebSocket Server. The bridge connects as a WebSocket client and pushes JSON messages.
What’s in this repo
derive_struct.py— Parse a C header (typedef struct { ... } Name;) and derive the Pythonstructformat and expanded field labels.stream_parser.py— Connect to the device (or read a.binfile), parse [DE AD BE EF][COUNT][MSG_ID][PAYLOAD] × COUNT batches into NDJSON (one JSON per line), or into CSV with--csv.socket_client.py— Read NDJSON (stdin or file) and forward to PlotJuggler’s WebSocket Server.bridge.py— One-process solution: connect to device, parse, and forward to PlotJuggler (no shell pipes needed) or stdout (if file, as NDJSON or CSV with--csv).streamer.py— Library API (PlotJugglerStreamer) to run the parse-and-forward pipeline in-process from any byte source (e.g. a serial port), no subprocess or shell pipes.
Requirements
-
Python 3.12+
-
Device emits batches framed like:
[ 0xDE 0xAD 0xBE 0xEF ][ COUNT:1 byte ][MSG_ID:2 bytes][ PAYLOAD ] * COUNT -
The payload is a packed C struct defined in a header file.
-
PlotJuggler with the WebSocket Server plugin enabled (Protocol: JSON).
Install
python3.12 -m venv .venv
source .venv/bin/activate
pip install -e .
Start PlotJuggler’s WebSocket Server
- In PlotJuggler: Streaming → WebSocket Server
- Protocol: JSON
- Port: for example 9871
- Click Start
Start Bridge
Connect to device, parse batches, forward to PJ.
Default TCP port is 5000; default WS URL is ws://127.0.0.1:9871.
Timestamps are in milliseconds by default (--ts-scale 1e-3).
python3 bridge.py \
--host 192.168.1.91 \
--struct-header /path/to/telemetry.h \
--struct-name MyStruct \
--name-prefix "device_a."
Notes:
- Add
--controller-out-sizeif using a struct withHiddenHighLevelControllerOutputData_sto specify size (ex: 109) (this isCONTROLLER_OUTPUT_DATA_SIZEvalue inhigh_level_controller_common.h) - Add
--ignore-errorsonly applies to file conversions, streaming always ignores errors regardless of this flag - Add
--csvwith--fileto write CSV instead of NDJSON (see Parsing log files). File conversions only — passing it with--hostis an error, since TCP mode forwards JSON to PlotJuggler. - Add
--ws-url ws://<pj_host>:9871if PlotJuggler runs elsewhere. - If needed, guard against corrupted batches with
--max-frames-per-batch N. - To fall back to single
[DELIM][PAYLOAD](no COUNT), pass--no-counted-batch.
Two-process pipeline (for debugging)
- Derive the struct (optional sanity check). Prints JSON describing the derived
struct_fmt,fields, andrecord_size.
python3 derive_struct.py \
--header /path/to/telemetry.h \
--struct-name MyStruct \
- Parse from device to NDJSON:
python3 stream_parser.py \
--host 192.168.1.91 \
--struct-header /path/to/telemetry.h \
--struct-name MyStruct \
--name-prefix "device_a."
- Forward NDJSON to PlotJuggler:
python3 stream_parser.py --host 192.168.1.91 --struct-header /path/to/telemetry.h --struct-name MyStruct | python3 socket_client.py --ws-url ws://127.0.0.1:9871
Use as a library
The same pipeline is importable, so a host application can supply its own byte
source instead of TCP or a file. PlotJugglerStreamer takes a blocking
read_fn() -> bytes (return b"" when idle), derives the struct from a header,
parses 0xDEADBEEF batches, and forwards JSON to PlotJuggler's WebSocket
Server on a background thread.
from pj_bridge import PlotJugglerStreamer
streamer = PlotJugglerStreamer(
read_fn=lambda: ser.read(max(1, ser.in_waiting)), # e.g. a pyserial port
struct_header="/path/to/telemetry.h",
struct_name="MyStruct",
ts_field="timestamp",
ws_url="ws://127.0.0.1:9871",
)
streamer.start()
# ...
streamer.stop()
stop() ends the reader and the WebSocket sender even if PlotJuggler's server
was never up. Pass on_connect / on_disconnect callbacks to be notified when
the WebSocket link to PlotJuggler is established or drops (they run on the event
loop, so keep them cheap and marshal any UI work to your own thread):
PlotJugglerStreamer(
...,
on_connect=lambda: print("connected to PlotJuggler"),
on_disconnect=lambda: print("PlotJuggler link dropped"),
)
Other public names: derive_struct, DelimitedRecordParser, ws_sender,
source_reader_to_queue.
Field naming
-
All non-timestamp fields are emitted with the optional prefix:
--name-prefix "device_a."
Example JSON:
{"t": 1727370023.415, "device_a.ax": 0.02, "device_a.ay": -0.01, "device_a.az": 9.81}
-
Arrays like
float gyro[3];becomedevice_a.gyro[0],device_a.gyro[1],device_a.gyro[2].
Timestamp (t)
- If
--ts-field ts_msis provided,t = ts_ms * --ts-scale(default1e-3, ms → seconds). - If no
--ts-fieldis set, arrival time is used (time.time()in seconds). - If your device time is relative (since boot) and you want wall-clock, you can add an epoch offset in code; ask if you want a ready-made flag for that.
Parsing log files
stream-parser reads either source and writes to stdout:
- Live over TCP, using
--host - Offline from stored binary log files, using
--file
By default it emits NDJSON (one JSON object per line). Add --csv to get CSV
directly, ready for Excel, Pandas, or visualization tools.
Straight to CSV (recommended)
# offline log file
stream-parser --file capture.bin --struct-header telemetry.h --struct-name MyStruct --csv > logs.csv
# live TCP stream
stream-parser --host 192.168.1.91 --struct-header telemetry.h --struct-name MyStruct --csv > live.csv
pj-bridge accepts the same flags for its --file mode, so either entry point works:
pj-bridge --file capture.bin --struct-header telemetry.h --struct-name MyStruct --csv > logs.csv
With --host, pj-bridge forwards JSON to PlotJuggler instead, so --csv is
rejected there rather than silently ignored.
Options:
--csv-delimiter ';'to change the column separator (default,).--no-headerto omit the header row.
Column order follows the parser's field order, and the header is taken from the
first record — the same layout json-to-csv produces, so existing CSVs stay
comparable.
Via NDJSON and json-to-csv
json-to-csv converts NDJSON on stdin into CSV on stdout. All JSON lines must
contain the same fields (the parsers ensure this).
stream-parser --file capture.bin ... | json-to-csv > logs.csv
This produces byte-identical output to --csv, but every record is serialized
to JSON, written to a pipe, and parsed back again. Prefer --csv
unless you actually want the NDJSON, for example to feed socket-client
or to inspect individual records.
Uninstall
- Deactivate the venv and remove the project directory, or run
pip uninstall pj-bridgeinside the venv (if installed as a package).
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pj_bridge-1.4.0.tar.gz.
File metadata
- Download URL: pj_bridge-1.4.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35be2f9416b41d0f68041620eef8605abd419848fed614775e4356bfef5c15d5
|
|
| MD5 |
86ed6eddcb2a62e7e90e1c7445fa89c7
|
|
| BLAKE2b-256 |
a5ed8add3f7cc46fb33f83ec6b1a9939afd33fcb230cd2a41ed5548957b1705e
|
Provenance
The following attestation bundles were made for pj_bridge-1.4.0.tar.gz:
Publisher:
pypi-release.yml on DephyInc/pj-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pj_bridge-1.4.0.tar.gz -
Subject digest:
35be2f9416b41d0f68041620eef8605abd419848fed614775e4356bfef5c15d5 - Sigstore transparency entry: 2373005899
- Sigstore integration time:
-
Permalink:
DephyInc/pj-bridge@858e1293c194336d7ddd7d00c236d13f63866f13 -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/DephyInc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@858e1293c194336d7ddd7d00c236d13f63866f13 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pj_bridge-1.4.0-py3-none-any.whl.
File metadata
- Download URL: pj_bridge-1.4.0-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bde5a071e47c41bb4dace9b4e7260a85fc7a69dd4ac1ae5136c4b190677f4caf
|
|
| MD5 |
0fbb8763b2694747d24765eddff760e0
|
|
| BLAKE2b-256 |
534b15c2ace47911162df81e702c5605b73c3ba949008e883935d59160870ff7
|
Provenance
The following attestation bundles were made for pj_bridge-1.4.0-py3-none-any.whl:
Publisher:
pypi-release.yml on DephyInc/pj-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pj_bridge-1.4.0-py3-none-any.whl -
Subject digest:
bde5a071e47c41bb4dace9b4e7260a85fc7a69dd4ac1ae5136c4b190677f4caf - Sigstore transparency entry: 2373005926
- Sigstore integration time:
-
Permalink:
DephyInc/pj-bridge@858e1293c194336d7ddd7d00c236d13f63866f13 -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/DephyInc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@858e1293c194336d7ddd7d00c236d13f63866f13 -
Trigger Event:
push
-
Statement type: