Repository navigation
Conversation
Dose Counter
More event details
Multi-part messages id databuf
Add SPEC_RESET/SPEC_DIFF decoders and spectrogram diff accessor
- SPEC_RESET (0x207) header is ts(I) only (no calibration), unlike
SPEC_ACCUM/SPECTRUM which use ts+a0+a1+a2.
- SPEC_DIFF (0x206) is the per-channel count diff; version 1 decodes as a
v1-compressed 1024-channel list, version 2 is an experimental
(channel<<4|count) word list.
- Add spectrum_diff()/spectrum_reset_data() methods and a log-analysis tool.
Fix buffered timestamps: base is per-read host now, drop +128s offset
Buffer ts_offset is in 0.01s units relative to read time. The connect-time
base of now+128s pushed timestamps ~128s too late and went stale on long
sessions. Now refresh the base to host now on each data_buf() read.
Skip malformed buffer records and resync instead of stopping
- data-buffer decoder now skips malformed records and re-syncs to the next
plausible record (two-record lookahead) instead of discarding the rest of
the buffer; multi-sample blocks are pre-validated against the remaining
buffer so a corrupt samples_num can't greedily consume the tail
- seq discontinuities are non-fatal
- document the malformed-record handling; add missing COMMAND ids
(RD_VIRT_STRING_BATCH, WR_VIRT_STRING_BATCH, SET_BT_EXCHANGE_ID) and the
verified firmware-descriptor / response layouts from app captures
Add RD_FLASH_AREA decoder and FlashArea descriptor
RD_FLASH_AREA returns the flash region encrypted with a self-seeded LCG
keystream (seed*22695477+1, XOR with seed>>16). Add decode_RC_RD_FLASH_AREA
plus a FlashArea dataclass and RadiaCode.flash_area() method. Document the
wire layout in PROTOCOL.md and correct the earlier note that the area was
opaque/undecrypted. BootSignat is a bit-packed date/time, not a timestamp.
Split flags into per-context typed classes; drop non-detector bits
The record 'flags'/'real_time_flags' fields use a different bit table from
GET_STATUS, established via baksmali disassembly of cs1 and the log-6 trace.
Add RecordFlags (power source, temp state, save-to-db/old-data/range bits)
and RealTimeFlags (alarm-sound/background bits); fix status() tuple bug.
Remove generic platform bits (SpO2, valves, pumps, pressure) that never apply
to a radiation detector from DeviceFlags.
Complete docs; confirm SPEC v1 encoding and drop unobserved v2 SPEC format
- Docs: add missing public API members and record types to the reference;
document spectrum_diff/spectrum_reset_data, DoseCounter, FlashArea and flags.
- Protocol.md: document sequence base/echo, write-command retcodes, init
sequence, extra VS ids, and the SET_LOCAL_TIME + periodic DEVICE_TIME=0
time-sync pattern.
- SPEC_DIFF confirmed as version-1 run-length across 11 capture logs
(incl. a 360-sample plane spectrogram); ts is cumulative live-time and
channel 1023 is the overflow bin.
- Remove the never-observed version-2 SPEC format from the decoder and clamp
SpecFormatVersion to the supported {0,1} set.
Decode SET_EXCHANGE interface/connect status; add record alarm-state bits
SET_EXCHANGE now decodes IF_TYPE (1=USB, 2=BLE) and IF_READY (ready/busy)
into a SetExchange descriptor; connect raises if the interface is busy.
RecordFlags gains dose/count alarm-level bits (0-1, 8-9) and drops the
unobserved bit-16 'Range: Current' flag.
Document firmware-update commands; generalize log references
Add FW_IMAGE_GET_INFO/WRITE/UPDATE (0x0012/13/14)
|
Conveniently, the radiacode app was just updated today, which allowed me to capture and analyze the firmware update procedure too. Not that I recommend anyone try it, but hey you do what you want with your own hardware. 🤷🏻♂️ |
|
Thanks for this PR — the eid=1 multi-sample decoding and the flags table helped me fix a 1. RealTimeData payload is 16 bytes on 4.15, not 15. RealTime is the first record of every read, so a strict parser loses everything after 2. "Old data" records can come after current ones in the same read. 3. Confirmations on 4.15
I can share raw DATA_BUF captures if useful. |
|
Thanks for testing. I don't think I upgraded all of my devices, but I can probably roll back to an older firmware for testing. one thing I found useful was to turn on debug logs in the android app, then pull the logs from |
|
I dumped the history from all my devices so I have v4.14 and v4.15 captures. Won't have time to inspect them for a couple of days, but I'll also have time to accumulate side by side measurements over that interval. Once that's done I can compare the traffic from two devices that should have recorded extremely similar measurements. |
| ) | ||
| return exchange | ||
|
|
||
| def status(self) -> DeviceFlags: |
There was a problem hiding this comment.
breaks the spectrum viewer - show-spectrum.py still calls rc.status().split(':'), update it
next release will required major version bump because interface changed, it's ok.
There was a problem hiding this comment.
Sounds like a good opportunity to add a test suite. It's a little bit evil, but https://github.com/ckuethe/radiacode-log-analysis imports the decoders directly to test whether a payload decodes to the same thing as the android app. I think we can do something similar to test that decoders at least return meaningful dataclasses.
| v = struct.unpack_from('<B', data, pos)[0] | ||
| pos += 1 | ||
| elif vlen == 2: | ||
| v = struct.unpack_from('<H', data, pos)[0] |
There was a problem hiding this comment.
missing last +.
But it should be replaced with existing decode_counts_v1 from spectrum.py, which did't have that bug.
It's non production script, so you are free to use not-so-fancy ways to access that function if it's not exported to the public library API, and btw maybe it's better to move this script from examples to docs/
There was a problem hiding this comment.
Speaking of API exports, I'd like to make _batch_read_vsfrs a public function.
|
Thanks. I've got a day of data from firmware 4.14 and 4.15; will see if I can tighten up those decodes. edit: bunch of captures from the android app, and a script to feed the captures to the python decoders ... https://github.com/ckuethe/radiacode-log-analysis |
Firmware 4.15 appends one byte after rt_flags in gid-0 (RealTimeData) records, growing the body from 15 to 16 bytes; the first 15 bytes keep the same layout. decode_VS_DATA_BUF now auto-detects the body size per buffer (the two sizes are mutually exclusive) and threads it through record sizing/resync/decode, so one decoder handles both firmware versions.
Multi-sample blocks (eid=1) carry a per-sample interval (smpl_time) that the decoder read but ignored, stamping every expanded sample with the group's dt. smpl_time is in the same 10ms units as ts_offset (verified: DoseRateDB blocks tile the single-sample grid exactly at smpl_time*10ms), and samples run oldest->newest from the group timestamp. Timestamp sample i at dt + i*smpl_time*10ms.
The 'off + 7 > n' header guard lets off+7 == n through, so a gid==7 record read data[off+7] == data[n] and raised IndexError. _probe/_detect_realtime_size run outside the decode loop's try/except (and _resync scans raw bytes), so a truncated buffer whose tail decodes as eid=0,gid=7 could crash the decoder. Require off+8 <= n before reading the event byte.
To be revisited later; it does trigger a few times, and recovers a relatively small number of messages in my test loads
|
I'm going to try untangle this, and make new PRs. |
Sorry about the huge diff, I've been working on this for a while, accumulating lots of little changes.
I finally figured out what the
eid=1messages in the data buffer are; they're a batch of messages like rtdata or doseratedb. I updated my toolkit to take advantage of that. https://github.com/ckuethe/radiacode-tools/blob/main/src/rcrtlog.pyMore flags are decoded, so when you're reading the databuf you can tell whether you're getting old records or new ones (here's one of my devices catching up):
Figured out the FlashArea, and then I found https://github.com/WeebDataHoarder/PhytonUtils/ who's apparently done some of the same analysis.
Dose Counter
More event details
Multi-part messages id databuf
Add SPEC_RESET/SPEC_DIFF decoders and spectrogram diff accessor
Fix buffered timestamps: base is per-read host now, drop +128s offset
Buffer ts_offset is in 0.01s units relative to read time. The connect-time base of now+128s pushed timestamps ~128s too late and went stale on long sessions. Now refresh the base to host now on each data_buf() read.
Skip malformed buffer records and resync instead of stopping
Add RD_FLASH_AREA decoder and FlashArea descriptor
RD_FLASH_AREA returns the flash region encrypted with a self-seeded LCG keystream (seed*22695477+1, XOR with seed>>16). Add decode_RC_RD_FLASH_AREA plus a FlashArea dataclass and RadiaCode.flash_area() method. Document the wire layout in PROTOCOL.md and correct the earlier note that the area was opaque/undecrypted. BootSignat is a bit-packed date/time, not a timestamp.
Split flags into per-context typed classes; drop non-detector bits
The record 'flags'/'real_time_flags' fields use a different bit table from GET_STATUS, established via baksmali disassembly of cs1 and the log-6 trace. Add RecordFlags (power source, temp state, save-to-db/old-data/range bits) and RealTimeFlags (alarm-sound/background bits); fix status() tuple bug. Remove generic platform bits (SpO2, valves, pumps, pressure) that never apply to a radiation detector from DeviceFlags.
Complete docs; confirm SPEC v1 encoding and drop unobserved v2 SPEC format
Decode SET_EXCHANGE interface/connect status; add record alarm-state bits
SET_EXCHANGE now decodes IF_TYPE (1=USB, 2=BLE) and IF_READY (ready/busy) into a SetExchange descriptor; connect raises if the interface is busy. RecordFlags gains dose/count alarm-level bits (0-1, 8-9) and drops the unobserved bit-16 'Range: Current' flag.
Document firmware-update commands; generalize log references
Add FW_IMAGE_GET_INFO/WRITE/UPDATE (0x0012/13/14)