Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo: Transmitting audio to the radio over RFCOMM #5

Open
wants to merge 5 commits into
base: demo/audiorx_demo_unescape
Choose a base branch
from

Conversation

spohtl
Copy link

@spohtl spohtl commented Jan 5, 2025

As promised, here's the TX demo. I hope the code speaks for itself, it's fairly straightforward.

The only real problems I had were with the timing of TX, especially the PTT release command. If the command gets sent immediately after the end of audio transmission, the radio gets stuck in transmit. I wonder if this has anything to do with frame buffering and reordering in my laptop's BT driver. In other words, this delay might be necessary on my machine but might not be on others, and it might need to be a different length. If it is related to buffering, maybe there's a way to manually flush the buffers?

@spohtl spohtl changed the title Demo: Transmittion audio to the radio over RFCOMM Demo: Transmitting audio to the radio over RFCOMM Jan 5, 2025
@khusmann
Copy link
Owner

khusmann commented Jan 5, 2025

Very cool!! Not in a position to test it atm but will soon!

I don't think that's a PTT release command -- looks to me like a READ_STATUS (power status, that is), checking the battery voltage. Structure is:

0xff -- start flag
0x01 -- version
0x00 -- flags
0x02 -- payload size (n_bytes)
0x00, 0x02 -- command set (CommandGroup.BASIC)
0x00, 0x05 -- command (BasicCommand.READ_STATUS)
0x00, 0x02 -- payload (read_status_body: PowerStatusType.BATTERY_VOLTAGE)

The HT app is constantly spamming these voltage requests (and setting the device GPS position, etc).

See https://github.com/khusmann/benlink/blob/main/src/benlink/internal/protocol/gaia_frame.py for more info on how these serial commands are put together. (Over serial the command Messages are wrapped in gaia frames)

In my btsnoop logs I don't see any time gap between the end of the sbc frame and the ending {0x7e, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e} command... weird we have to delay.

So maybe a buffering issue like you say? maybe try tcflush() on the rfcomm socket? (that was the best suggestion I could come up with chatgpt's help...)

Or maybe a firmware issue -- perhaps the 0x7e ... 0x7e is supposed to toggle the PTT, but doesn't, and then the other read request just knocks it out of the bad state. I remember hearing folks complaining that in one firmware the device got stuck in transmit while transmitting in KISS -- could be because the continual spam of voltage requests by the app always acted as a PTT release. What firmware are you running?

Does {0x7e, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e} activate the PTT? Or do you need to start sending sbc data for transmit to go in transmit mode?

@khusmann
Copy link
Owner

khusmann commented Jan 5, 2025

Ok, just tried it out and it runs beautifully!

I discovered that it works just fine without sending any commands on the command channel -- Here's the results of a bunch of conditions:

InitMsg InitMsg (after tx) Delay Before Close Socket Result
      tx hangs
    X tx hangs
  X   tx hangs
  X X success
X     tx hangs
X   X success
X X   tx hangs
X X X success

(none of these involved sending anything on the cmd channel)

So it looks like you can send the InitMsg before or after the sbc clip, and then delay before closing the socket and it doesn't hang? Lmk if you get the same or different results with your device / env...

@spohtl
Copy link
Author

spohtl commented Jan 5, 2025

D'oh, I misunderstood the command structure and figured it's a command you haven't implemented it yet.

You're right, just the delay before a socket close works well. I also found that a delay before sending the init command also works without closing the socket. I still wonder why the delays are necessary. I tried playing with waiting for the socket to drain and flushing it, but no luck.

I'm on the latest firmware (7.15)

@khusmann
Copy link
Owner

khusmann commented Jan 6, 2025

I also found that a delay before sending the init command also works without closing the socket.

Hmm really? Weird -- on my system I don't need any delays on the init command (socket can stay open). Tx only hangs if 1) socket closes too soon or 2) no init command is sent (and it can go before or after the audio clip) -- the only timing problem I'm seeing is the socket closing too soon.

@khusmann
Copy link
Owner

khusmann commented Jan 6, 2025

I've just pushed the test case I'm really curious about -- with that setup it unkeys the PTT just fine on my end, leaving the socket still open... Does it get stuck in tx on yours?

Edit: One more variable I just thought of -- how long is the tx you're sending? Mine is about 4s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants