-
Notifications
You must be signed in to change notification settings - Fork 9
[serial] Review Terminal Emulation Over Serial #60
Comments
My idea is that the
|
To analyse and filter it is necessary to parse a pretty much random string. Not random because we don't know what comes back, but random because everything might get lost or changed on the way to the buffer in the software we can access. Therefore it makes sense to apply a general purpose parser framework to do the string parsing and filtering for us. It might be more stable and faster than anything we can write ourselves, and also included error handling, which our code might not have in this depth. The basic structure of a successful response looks like follows:
We can see that the command output is surrounded by our command at first and the prompt at last. In between might or might not be a command output. If there is a command output, it will be appended by an EOL statement. The grammar has the following features:
|
Another problem is the {prompt}. How do we know what is the {prompt}? Every system or user might set a different one, right? The first idea, was to simply send an {EOL} and take the whole response, which should be a {prompt} as such. But that doesn't always work, because some parts in the prompt can change, e.g. the time or path. Therefore I will try to set |
Implements the idea described in GitHub Issue #60. The idea here is the following. The main function of our serial class on top of the already existing pyserial is a commandline like interface. We send a `cmd()` and receive it's output back. The corresponding method currently sends the command over the pyserial interface and reads from it what comes back. Everything until the end of the command is removed from the output and also the prompt after the command and everything that follows it. Then the filtered output is returned. If some step before takes longer then the timeout, then the function returns the incomplete parsing result. The last output and confidence about it's result are stored in the object for a later review by the user. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
Implements the idea described in GitHub Issue #60. The idea here is the following. The main function of our serial class on top of the already existing pyserial is a commandline like interface. We send a `cmd()` and receive it's output back. The corresponding method currently sends the command over the pyserial interface and reads from it what comes back. Everything until the end of the command is removed from the output and also the prompt after the command and everything that follows it. Then the filtered output is returned. If some step before takes longer then the timeout, then the function returns the incomplete parsing result. The last output and confidence about it's result are stored in the object for a later review by the user. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
Makes testing easier and the program itself more flexible. Also increases the likeness of this interface to serial_conn. See GitHub Issue #60. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
Added tests for Object creation, a basic cmd() and 2 cases for the read_until methods. The last method needed an additonal unit test, because start_strip and end_strip should be tested separately. See GitHub Issue #60. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
the command should force the user to react to outputs that don't meet the prompt. See GitHub Issue #60. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
After reviewing the current code at the Stammtisch, some additional changes were proposed:
|
from last friday The idea of reading single bytes in a blocking manner and looping until happens seems to be a bad feeling in Python, simply based on my instinct. There is a reason, why more bytes can be assigned to be read and there should be a better way to do it. To find meaningful alternatives I'm going to ask stackoverflow for advice. |
I found a way to read everything that comes as a response to sending a command over the wire: Currently This is a good thing, because code we don't have to implement, we also don't have to maintain. :) |
Here is the default interface, provided by pyserial overwrites |
Feedback from today's Stammtisch:
Todo from today's Stammtisch:
Conclusion
|
Profiling of slow readall() callsI found that the Profiling InvestigationBecause we've never done a profiling task in Python, the first step is to investigate profiling tools. Resources
ToolsProfilers:
Profile Viewers:
Proposed Profiling Process
some data
Conclusions
|
Filedescriptor Blocking
Blockinghttp://www.kegel.com/dkftpbench/nonblocking.html
Open reads: Conclusions
|
TermIOs blocking configuration options
Important flags:
Canonical and noncanonical mode
In Pyserial
Further Reading
Conclusion
|
Might |
current solutionAlthough I start to feel rather unhappy with def cmd(self, msg):
self.write(msg.strip() + "\n")
return "\n".join(self.readall().replace("\r","").split("\n")[1:-1]) In detail:
|
the feedback from today's Stammtisch:
Results:
This means that the current "sunshine" implementation of |
According to the research in Issue #60 (#60), the simplest implementation for best case scenarios is only 2 lines. This commit implements those 2 lines instead of the complex behaviour before. Issue #69 (#69) shall improve or replace that method with a more practical implementation, if that is not already finished with Issue #61 (#61). See Github Issue #60 for details. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com> Acked-by: Steffen Sledz <sledz@dresearch-fe.de> Acked-by: Eik Binschek <binschek@dresearch-fe.de>
Implements the idea described in GitHub Issue #60. The idea here is the following. The main function of our serial class on top of the already existing pyserial is a commandline like interface. We send a `cmd()` and receive it's output back. The corresponding method currently sends the command over the pyserial interface and reads from it what comes back. Everything until the end of the command is removed from the output and also the prompt after the command and everything that follows it. Then the filtered output is returned. If some step before takes longer then the timeout, then the function returns the incomplete parsing result. The last output and confidence about it's result are stored in the object for a later review by the user. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
Makes testing easier and the program itself more flexible. Also increases the likeness of this interface to serial_conn. See GitHub Issue #60. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
Added tests for Object creation, a basic cmd() and 2 cases for the read_until methods. The last method needed an additonal unit test, because start_strip and end_strip should be tested separately. See GitHub Issue #60. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
the command should force the user to react to outputs that don't meet the prompt. See GitHub Issue #60. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
According to the research in Issue #60 (#60), the simplest implementation for best case scenarios is only 2 lines. This commit implements those 2 lines instead of the complex behaviour before. Issue #69 (#69) shall improve or replace that method with a more practical implementation, if that is not already finished with Issue #61 (#61). See Github Issue #60 for details. Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com> Acked-by: Steffen Sledz <sledz@dresearch-fe.de> Acked-by: Eik Binschek <binschek@dresearch-fe.de>
ACKs come from the decision made in the last Stammtisch. Issue is assumed finished. |
Situation
The current implementation of
SerialConn
already offers a simple interface:It is very likely that the functionality can be improved, now that we have more experience with the interface and the pyserial framework.
Task
Look into the
serial_conn
module and review the implementation of thecmd()
interface and fundamental functionality. An implementation that only considers the best case is fine, because error handling will be added in another step.Notes
f-review-serial-cmd
The text was updated successfully, but these errors were encountered: