radiacode icon indicating copy to clipboard operation
radiacode copied to clipboard

Issues on Radiacode 102 via USB

Open leandroalbero opened this issue 1 year ago • 3 comments

Describe the bug

When running any of the examples with a Radiacode 102, the program execution stops after a while

To reproduce

Start any of the included examples, in this case I have used webserver.py

Desktop/FW:

  • OS: MacOS Sonoma (23A5276g)
  • Packages installed by the poetry env.
  • Radiacode 102
    • FW v04.02
    • BOOT 04.00

Additional context

(radiacode-py3.11) (base) leandro-m1@Leandros-M1-Max radiacode % poetry run python3 radiacode-examples/webserver.py
<will use USB connection
Rates updated, sending to 0 connected clients
======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
Rates updated, sending to 0 connected clients
Rates updated, sending to 0 connected clients
Rates updated, sending to 0 connected clients
Rates updated, sending to 0 connected clients
Spectrum updated
Rates updated, sending to 1 connected clients
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<process() done, defined at /Users/leandro-m1/radiacode/radiacode-examples/webserver.py:44> exception=error('unpack_from requires a buffer of at least 4 bytes for unpacking 4 bytes at offset 0 (actual buffer size is 0)')>
Traceback (most recent call last):
  File "/Users/leandro-m1/radiacode/radiacode-examples/webserver.py", line 48, in process
    databuf = app.rc_conn.data_buf()
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/radiacode.py", line 134, in data_buf
    r = self.read_request(VS.DATA_BUF)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/radiacode.py", line 60, in read_request
    r = self.execute(b'\x26\x08', struct.pack('<I', int(command_id)))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/radiacode.py", line 54, in execute
    response = self._connection.execute(full_request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/transports/usb.py", line 28, in execute
    response_length = struct.unpack_from('<I', data)[0]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack_from requires a buffer of at least 4 bytes for unpacking 4 bytes at offset 0 (actual buffer size is 0)
Error handling request
Traceback (most recent call last):
  File "/Users/leandro-m1/radiacode/.venv/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/.venv/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode-examples/webserver.py", line 28, in handle_spectrum
    spectrum = cn.spectrum_accum() if accum else cn.spectrum()
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/radiacode.py", line 142, in spectrum_accum
    r = self.read_request(VS.SPEC_ACCUM)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/radiacode.py", line 60, in read_request
    r = self.execute(b'\x26\x08', struct.pack('<I', int(command_id)))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/leandro-m1/radiacode/radiacode/radiacode.py", line 56, in execute
    assert req_header == resp_header, f'req={req_header.hex()} resp={resp_header.hex()}'
           ^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: req=2608008c resp=2608008b

Let me know if you need any more information, I don't know if the 102 is supposed to even work with this library. Note: I've checked #9 , but still facing this issue on v0.2.0 Thanks!

leandroalbero avatar Jul 02 '23 19:07 leandroalbero

I've tried 4.02 and 4.05 firmware on Linux and M1 Macos and can't reproduce this issue.

Looks like a data race (response to the second request with header from the first request), but webserver.py is single threaded (asycio).

p.s. have you noticed any issues with bluepy on macos? I've commented out some code to make it work, https://github.com/IanHarvey/bluepy/issues/404 didn't help.

cdump avatar Jul 08 '23 08:07 cdump

@cdump

p.s. have you noticed any issues with bluepy on macos? I've commented out some code to make it work, IanHarvey/bluepy#404 didn't help.

Bluepy unlikely will support macOS anytime soon according to author: https://github.com/IanHarvey/bluepy/issues/44#issuecomment-407177324

I also found it's running fine with some code commented out in radiacode.py.

wilsonlmh avatar Sep 05 '23 04:09 wilsonlmh

Just confirming that after #9 , the 102 works well for me on Ubuntu 22.04LTS amd64. Currently using v0.2.2

ckuethe avatar Sep 22 '23 23:09 ckuethe