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

usb serial terminal buffer issue #885

Open
jordens opened this issue Apr 24, 2024 · 2 comments
Open

usb serial terminal buffer issue #885

jordens opened this issue Apr 24, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jordens
Copy link
Member

jordens commented Apr 24, 2024

I made the iir_ch array a bit longer (20x1) to show the issue in dual-iir:

When hitting list on a larger struct over the serial terminal, it truncates output at some variable length and doesn't print everything. I played with the buffers a bit but couldn't quickly figure out where the issue was.


>
Input was empty?

> list
/dual_iir/afe/0: "G1" [default]
/dual_iir/afe/1: "G1" [default]
/dual_iir/iir_ch/0/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/1/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/2/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/3/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/4/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/5/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/6/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/7/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/8/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/9/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/10/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/11/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/12/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/13/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/14/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/15/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/16/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/17/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/18/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/19/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/allow_hold: false [default]
/dual_iir/force_hold: false [default]
/dual_iir/telemetry_period: 10 [default]
/dual_iir/stream_target: {"ip":[0,0,0,0],"port":0} [default]
/dual_iir/signal_generator/0/signal: "Cosine" [default]
/dual_iir/signal_generator/0/frequency: 1000.0 [default]
/dual_iir/signal_generator/0/symmetry: 0.5 [default]
/dual_iir: 0.0 [default]
/dual_iir/signal_generator/0/phase: 0.0 [default
Input was empty?

>
Input was empty?

> list
/dual_iir/afe/0: "G1" [default]
/dual_iir/afe/1: "G1" [default]
/dual_iir/iir_ch/0/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/1/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/2/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/3/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/4/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/5/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/6/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/7/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/8/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/9/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/10/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/11/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/12/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/13/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/14/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/15/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/16/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/17/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/18/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/19/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [defau
Input was empty?

>
Input was empty?

> list
/dual_iir/afe/0: "G1" [default]
/dual_iir/afe/1: "G1" [default]
/dual_iir/iir_ch/0/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/1/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/2/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/3/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/4/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/5/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/6/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/7/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/8/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/9/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/10/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/11/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/12/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/13/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/14/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/15/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/16/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/17/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/18/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/iir_ch/19/0: {"ba":[1.0,0.0,0.0,0.0,0.0],"u":0.0,"min":-32767.0,"max":32767.0} [default]
/dual_iir/allow_hold: false [default]
/dual_iir/force_hold: false [default]
/dual_iir/telemetry_period: 10 [default]
/dual_iir/stream_target: {"ip":[0,0,0,0],"port":0} [default]
/dual_iir/signal_generator/0/signal: "Cosine" [default]
/dual_iir/signal_generator/0/frequency: 1000.0 [default/dual_iir/signal_generator/0/symmetry: 0.5 [default]
/dual_iir/s
Input was empty?

>
ommand "\u{1b}" not found. Try 'help'.

>
@jordens jordens added the bug Something isn't working label Apr 24, 2024
@jordens jordens added this to the 0.10 milestone May 6, 2024
@ryan-summers
Copy link
Member

ryan-summers commented Jun 20, 2024

So ultimately this is governed by the underlying SerialPort buffer size, which is 1024 bytes. The reason we can send more than that is because on each USB serial write, we can potentially send 64 bytes out the USB interface (if the EP is in a state to transmit) every time a write!() happens to the USB port.

If we wanted to guarantee that this would be resolved, we would need to increase the SerialPort write_store buffer size to something like 4KB.

I suspect that Booster does not have this issue (even though it can print a large settings structure) because the CPU is running at a slower speed than Stabilizer, which means it takes longer actual amounts of time to progress through listing, serializing, and transmitting the settings structure, which allows more data to be transmitted via USB while the CPU is processing data.

However, this is always going to be a cat-and-mouse game if we're using Stabilizer as a library, since a library user could always make a larger and larger settings structure. We could allow the buffer to be passed into the constructor via some generic StabilizerSettings parameter to allow customization.

@jordens
Copy link
Member Author

jordens commented Jun 20, 2024

Isn't there a way to keep the buffer small and make this async "blocking", i.e. use an async fn write() that does not discard when the buffer is full but suspends for another task to drain the buffer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants