Comments (6)
Thanks, glad you found it.
I think the problem is that if you remove usleep()
, the CPU goes to 100% because unixhostdino_main()
is just a tight loop around a read()
. Try using a smaller value for the usleep() and let me know what you discover. Maybe we can make that number configurable.
There's probably a way to make Unix wait for a keypress without using a busy-loop, but I'm not a Unix programming expert, and I didn't want to spend a lot of time on this part of the code. The usleep(1000)
works fine for my needs, which is to run unit tests on a desktop machine. If you have another way of doing this, I'd be curious to know what that is.
from epoxyduino.
I didn't notice that because my tcp socket wrapper is currently blocking indefinitely on accepting new clients and the cpu runs idle because of this. Lets see if I can figure out something. This is nothing that important. I have been developing a HTTP server library for Arduino and got curious what the performance would be on a computer.
from epoxyduino.
I have some ideas how this could be done with select
but now I started to wonder is there a reason why the reading is done in the unixhostduino_main
function rather than in the read
function of the StdioSerial
class? This change would solve my problem already because the sleep could be then removed but I think there are even bigger problems with the current implementation. The Stream class provides a bunch of functions that try to read data until a timeout. Basically they are while loops that call the Stream read() until enough data is received or the timeout is met. With the current implementation it's impossible for those functions to return any data if the buffer of StdioSerial does not contain it already when the call is made but they will wait anyway.
from epoxyduino.
I don't think the Unix/POSIX read()
call can be moved into StdioSerial.read()
because the normal programming pattern on the Arduino is to check Stream.available()
on the serial port, before calling Stream.read()
, so StdioSerial.read()
would never get called. You are correct that the current implementation does not support Stream.readString()
and readStringUntil()
. I rarely use them, so I did not give them any attention. Recall that the primary reason this was created was to allow AUnit unit tests to compile and run on a desktop computer.
The intent of StdioSerial.insertChar()
was that I might have to use a separate thread to read the keyboard, then inject that character into the ring-buffer. That would emulate the parallel processing that occurs on an Arduino chip, where the serial port triggers an interrupt that causes the character to be processed.
from epoxyduino.
Isn't stdin buffered by default already? Is there a reason to "emulate" this? I think the available() function could just use the ioctl function with the FIONREAD command. If the buffering on the application side is really needed It could be also done so that that if the buffer is empty both StdioSerial read and available would trigger a call to read from stdin.
from epoxyduino.
I'm not using the buffered FILE
pointers and <stdio.h>
functions because those are blocking calls. I'm using integer file descriptors and the lowest-level read()
function from the C-library because it's non-blocking. There's no buffering at that level that I'm aware of.
With regards to your "just use the ioctl and FIONREAD", I am not familiar with those. I'd be happy to look at your code if you get it working.
from epoxyduino.
Related Issues (20)
- change project name from UnixHostDuino to EpoxyDuino
- Using avr functions in EEPROM.h HOT 2
- PipeFail test does not finish HOT 4
- snprintf_P is not supported HOT 1
- snprintf formatting does not honour AVR '%S' (i.e. not '%s') for printing F() flash strings HOT 2
- IPAddress::toString() needed HOT 2
- Add support for Windows using MINGW32 HOT 1
- Terminal I/O as under Arduino IDE or terminal emulation program HOT 1
- Print::println() line-ending is inconsistent with Arduino core (a documented change) HOT 6
- Is it possible to override analogRead when testing with AUnit?
- IPAddressTest:6:10: fatal error: AceCommon.h: No such file or directory HOT 1
- Invalid library found in xxx/Arduino/libraries/EpoxyDuino: no headers files (.h) found in xxx/Arduino/libraries/EpoxyDuino HOT 1
- serialEvent() does not seem to work or is not implemented HOT 1
- Error when including U8glib: "Undefined symbols for architecture x86_64"
- Simulated time HOT 3
- std::make_unique HOT 4
- Including LoRa library make error - use of undeclared identifier 'digitalPinToInterrupt' HOT 1
- Add support for ISR. HOT 1
- sizeof(int) gives 4, while AVR int is 2 bytes long HOT 3
- location of EpoxyDuino HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from epoxyduino.