-
-
Notifications
You must be signed in to change notification settings - Fork 370
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
feat(simu): cross-platform connection of host serial ports to simu radio #5584
feat(simu): cross-platform connection of host serial ports to simu radio #5584
Conversation
9a00027
to
1b6a405
Compare
Would this allow to connect an external module (e.g. ELRS RX-as-TX bidirectional connected) to the simulator? |
The task was explicitly not to require to communicate within the simulator with physical internal or external RF modules, as the serial communication with them has too tight timing constraints, which typical computer OS, w/o real-time capabilities, would not be able to adhere to: https://edgetx.org/contest_companion_phy_ser/ |
If ELRS RX-as-TX currently works on AUX1 or AUX2, then maybe, with absolutely no guarantees of reliability given the impossibility of guaranteeing timing on a general purpose OS. If you're going to try it for god's sake make sure you've got your props off. |
I tried this PR unter Linux: selecting a serial device like |
I tried both the prebuilt AppImage as well as a self-compiled version: in both variants I can't successfully choose a serial device. |
Did you see if data flowed between the simulator and the serial port, or did you just check to see if the dropdown had the correct value selected when you opened the serial device dialog again? I've just fixed the issue where the dialog wouldn't select the currently-connected port when it opens :) |
Just tried with yout latest update (both pre-built app-image as well as self-build)
|
And I want to say that it would be a real cool feature if |
It's not expected to persist across restarts of the simulator.
Interesting, it's working for me (on linux and windows) with a GPS plugged in to the host. a) How are you configuring the simulated radio? |
It might be cool, but it won't happen in this PR. (I've had a poke through and it looks like you'd need to wait for #4102 to go in) |
Ok, no problem ;-)
Maybe we are talking of different things. |
I've just had a poke around, and it doesn't.
If you set |
Mmh, that's a pity! |
I suspect that the point of |
@wimalopaan See: #2562 |
The baudrate should be user settable I think, and not fixed 9600Bd |
The baudrate on the host will be set to whatever the radio has set it to. opentxsimulator.cpp:167 -> opentxsimulator.cpp:144 -> opentxsimulator.cpp:678 -> simulatormainwindow.cpp:160 -> hostserialconnector.cpp:136 |
Here the files and sections from previous post with links for easier reading: |
Yes, I was aware of that fact but did not find the link to your new code ... |
Many thanks ;-) |
I still wonder about the best way to achieve the goal to attach an ELRS-module to the simu ... |
Something like the approach in this PR but instead of connecting the simulated AUX1/AUX2 to a host serial port, you'd be connecting the simulated internal or external module to the host hardware in some way? OR you could extend the module handling code to support having a third (or fourth) serial-connected (no module heartbeat for sync, for example) module on AUX1/AUX2 and use this PR to connect it to the host. |
Actually I hestitate to use a serial device. I think of a pipe/socket or shared-memory to communicate with a kind of module-simulator ... |
Whoops, this is what happens when I test with re: the LUA loopback test: turns out that QByteArray::fromRawData doesn't copy the data it's given but points directly to it. And with the timing for the the GPS driver it just happened to be that the data got sent before the buffer got overwritten. But when sending data from LUA, the buffer got overwritten for each character while the queue of QT signals grew. Also fixed in latest push, at least that's what it looks like on my machine :) |
Looking good so far... both fixes working fine here on Linux :) edit: and Windows |
Now just need to find someone with a mac 😆 |
Welp... github blocked my email reply... Got someone in mind already, just need to send him a reminder to test this as we were discussing this just before EdgeTX fest so would have been forgotten in the chaos of getting ready for that. |
Works for me now, I can output on AUX1 and AUX2. Very cool, thanks! |
I went a little bit further:
and - voila - the simulator now can talk to my rx-as-tx ELRS and to my receiver and all crsf-devices attached to that receiver. This is really cool. |
Are chances that thhis PR gets into 2.11? |
f499d9f
to
0593241
Compare
The above mentioned script you may find on: https://github.com/wimalopaan/LUA |
Maybe we can extend this PR (later) to add a new option: not only select a host-serial for AUX1 or AUX2 but also for internal or external modul. |
Tested this PR for a while now and had no problems. |
What platform(s) are you using? Just waiting for @JimB40 to confirm it is working on MacOS, as it has been tested on Linux and Windows. Until it is merged, builds for all platforms are available via the Checks tab as with all other PRs ;) btw, while it would at best be material for a different PR, I strongly doubt internal/external module will be possible, as the timing requirements are too critical. serial is relatively easy, especially as there is OS level drivers and support for it, but microsecond timing for module communications on general purpose operating systems is a whole different story. |
I tested it only on Linux (arch-linux). I wrote the above mentioned LUA-scripts and now I can steer all models from the desktop ;-) A video of the bench: https://youtu.be/6hBYG1nIjNw As long as the ELRS module receives channel data with a least 5Hz it switches to transmit-mode and sends RADIO_ID packets to the simulator. As you can see the communication is slower than on a real radio. If this is due to the fact that all is done via LUA or due to the wrong synchronization I don't know. |
Got this msg from @pfeerick Simplest test of the concept with a USB serial adapter is link the TX and RX lines and run the dumb script here... (use the new Tools -> Serial Ports entry to connect the usb uart to the simulator, and don't forget to assign either AUX1 or AUX1 to Lua in radio settings -> hardware 😉 ), and thus testing if RX hears what TX sends. If that works, the PR is complete. not much time to dig into |
That was unfortunately total bulls... from me, thus ignore and read on from next post's second paragraph instead...: |
This is not the case. This PR only changes the simulator so that the simulated radio (e.g. simulated RM TX16S) AUX1 and AUX2 can drive a serial port on the host (e.g. a USB serial adapter) To set up a test, take a USB serial adapter and connect it's RX to it's TX, then test that the simulator can receive what it sends using @pfeerick 's LUA script. I'll try to get a screen recording of how I'm testing that on linux tomorrow when I'm at the right computer. |
Risto is only detailing how to reproduce the expected functionality on HW
side... As simulator should now behave exactly the same as the hw, when the
USB serial adapter is wired in a loopback.
…On Mon, 9 Dec 2024, 10:35 pm Nigel Williams, ***@***.***> wrote:
Take a radio with accessible dual serial ports, like RM TX16S. Take two
wires with Dupont female connectors on both ends. Wire up one wire between
AUX1 RX and AUX2 TX lines. And wire up the second wire between AUX2 RX and
AUX1 TX lines. Flash the firmware binary for TX16S from this PR. Now power
on and attach the radio via top USB to your Mac. HW setup for testing done.
This is not the case. This PR only changes the *simulator* so that the
*simulated* radio (e.g. simulated RM TX16S) AUX1 and AUX2 can drive a
serial port on the host (e.g. a USB serial adapter)
To set up a test, take a USB serial adapter and connect it's RX to it's
TX, then test that the simulator can receive what it sends using @pfeerick
<https://github.com/pfeerick> 's LUA script. I'll try to get a screen
recording of how I'm testing that on linux tomorrow when I'm at the right
computer.
—
Reply to this email directly, view it on GitHub
<#5584 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJ66KLBJV7YRHDABMO37X32EWFAFAVCNFSM6AAAAABPJJCAQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRXHAYDOMJSGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
That makes more sense :) . But in that case you'd need to wire AUX1 TX to AUX1 RX and AUX2 TX to AUX2 RX |
Oh yes indeed... especially as pretty sure Lua (as with any other AUX
assignment) can only use one UART at a time 😅
…On Tue, 10 Dec 2024, 7:38 am Nigel Williams, ***@***.***> wrote:
Risto is only detailing how to reproduce the expected functionality on HW
side... As simulator should now behave exactly the same as the hw, when the
USB serial adapter is wired in a loopback.
That makes more sense :) . But in that case you'd need to wire AUX1 TX to
AUX1 RX and AUX2 TX to AUX2 RX
—
Reply to this email directly, view it on GitHub
<#5584 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJ66KIPTNLH5CSAZ2VJN3T2EYEWZAVCNFSM6AAAAABPJJCAQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRZGU3TOMJYHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@JimB40 has just tested this on MacOS and confirmed that my simple loopback test is working perfectly. Thus this PR is good to go! :) |
@nrw505 Congratulations on winning our fourth developer competition! |
Summary of changes:
It's a bit convoluted because QSerialPort has to belong to the main event loop's thread, not the simulator's thread. We rely on QT's signal management to let us shunt data between the threads nicely.