Update __init__.py to handle short report lengths.#18
Conversation
Added a check to readone that prevents a crash if the returned report is shorter than expected
|
It appears that applying that patch caused everything that's returned to be empty. When I reverted to the old code it started returning data again. I was testing why that was, but I didn't figure it out. |
|
loool, I suppose this line: |
|
Oh so nice! There is probably something wrong with the addresses used to read data from the Radex ONE.
But the address is not "simple": |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a safeguard in readOne to prevent crashes when the HID report is shorter than expected.
- Introduces a length check for the received report and early return on incomplete data
- Emits a warning and returns an empty dict when the report is too short
Comments suppressed due to low confidence (1)
src/radexreader/init.py:282
- Add unit tests covering the new branch where
hexaisNoneor shorter than expected to validate this behavior and prevent regressions.
# Check if the returned report has the expected length
|
It look like that there are negative values with current code: with ChatGPT I tried some stupid things, and there is still something wrong, because his helper made never breaks: import csv
# the correct initial values
keyA = 0x04 - 0x04 # => 0x00
keyB = 0x00
keyC = 0x5a + 0x04 # => 0x5e
keyD = 0x00
seen = set()
rows = []
iteration = 1
while iteration <= 10000:
t = (keyA, keyB, keyC, keyD)
if t in seen:
break
seen.add(t)
rows.append([iteration, f"0x{keyA:02x}", f"0x{keyB:02x}", f"0x{keyC:02x}", f"0x{keyD:02x}"])
iteration += 1
keyA += 0x04
keyC -= 0x04
if keyA > 0xff:
keyA -= 0xfe
keyB += 0x01
if keyB > 0xff:
keyB = 0x00
keyC -= 0x01
elif keyC < 0x00:
keyC += 0xff
keyD -= 0x01
if keyD < 0x00:
keyD = 0xff
with open("radex_keys_cycle.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile, delimiter="\t")
writer.writerow(["iteration", "keyA", "keyB", "keyC", "keyD"])
writer.writerows(rows) |


I added a check to readone that prevents a crash if the returned report is shorter than expected.
I encountered an issue with my code crashing due to some of the reports being shorter than expected, this stop-gap addition prevents the code from crashing out.