ISISComputingGroup / lewis-ess

Let's write intricate simulators!
GNU General Public License v3.0
21 stars 19 forks source link

Stream timeout mode #262

Closed MikeHart85 closed 6 years ago

MikeHart85 commented 7 years ago

Fixes #261.

Adds a readtimeout attribute to StreamInterface. A ReadTimeout is triggered when the adapter has begun receiving data (IE, a partial command), but has not yet received an InTerminator, and no further data has arrived for the number of milliseconds specified by the readtimeout attribute.

This behaviour is based on the description of ReadTimeout in the Protocol File documentation, which seems to indicate that a timeout can be used to separate commands instead of a terminator.

ReadTimeout = 100; Integer. Affects in commands. The device may send input in pieces (e.g. bytes). When it stops sending, how many milliseconds to wait for more input bytes before giving up? If InTerminator = "", a read timeout is not an error but a valid input termination.

This ReadTimeout is the inverse of what is implemented here, since this is written from the IOC's perspective, but it seems reasonable that it should work the same way in both directions.

Testing

Run the supplied sample device:

$ lewis -k lewis.examples timeout_device

To interact with this device, you must switch telnet into char mode, or use netcat with special tty settings:

$ telnet host port
^]
telnet> mode char
[type command and wait]

$ stty -icanon && nc host port
hello world!
foobar!

The following commands are available:

ReadTimeout is set to 2.5 seconds here.

MikeHart85 commented 7 years ago

Added to release notes.

Yes, implementing this wasn't nearly as bad as I thought it would be, especially since asynchat typically depends on terminators... for a while I thought I might have to rewrite the adapter with a different networking library.

MichaelWedel commented 7 years ago

I've had some time to do the manual tests you suggested, everything works as advertised. This opens up Lewis for a whole new set of typing exercise devices when the timeout is short enough ;)

I'd be happy to merge this if you think it's ready.

MikeHart85 commented 7 years ago

It's probably best to wait for @samueljackson92 to confirm that this does what he needs, and that it's now possible to implement the Eurotherm 2000 emulator he was trying to create.

Apart from that, I think it's ready to go as well.

DominicOram commented 6 years ago

@samueljackson92 is working on a different project now. I've tested this PR with his Eurotherm emulator and it's exactly what we needed. It would be great if this could be put into a minor release soon as we are about to upgrade our Lewis version anyway. Thank you.