From fbc40e54a1a42002b73b00a7858dec6300dfacb8 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 9 Jun 2008 23:10:27 +0200 Subject: * digital/io/tools: - added io to test_simu. --- digital/io/tools/io/__init__.py | 1 + digital/io/tools/io/init.py | 6 ++++++ digital/io/tools/io/io.py | 36 ++++++++++++++++++++++++++++++++++++ digital/io/tools/test_simu.py | 14 +++++++++++++- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 digital/io/tools/io/__init__.py create mode 100644 digital/io/tools/io/init.py create mode 100644 digital/io/tools/io/io.py (limited to 'digital') diff --git a/digital/io/tools/io/__init__.py b/digital/io/tools/io/__init__.py new file mode 100644 index 00000000..42e63913 --- /dev/null +++ b/digital/io/tools/io/__init__.py @@ -0,0 +1 @@ +from io import Io diff --git a/digital/io/tools/io/init.py b/digital/io/tools/io/init.py new file mode 100644 index 00000000..12c6bb9a --- /dev/null +++ b/digital/io/tools/io/init.py @@ -0,0 +1,6 @@ +"""Default parameters for io.""" +host = dict ( + trap = ((1, 255), (1, 255), (1, 255), (1, 255), (1, 255), (1, 255)), + sharp_threshold = ((0x7f, 0x90), (0x7f, 0x90), (0x7f, 0x90), + (0x7f, 0x90), (0x7f, 0x90)), + ) diff --git a/digital/io/tools/io/io.py b/digital/io/tools/io/io.py new file mode 100644 index 00000000..8b78a8cc --- /dev/null +++ b/digital/io/tools/io/io.py @@ -0,0 +1,36 @@ +import proto, time + +class Io: + + def __init__ (self, file, time = time.time, **param): + self.proto = proto.Proto (file, time, 0.1) + self.async = False + self.param = param + self.send_param () + + def send_param (self): + p = self.param + for i, t in enumerate (p['trap']): + self.proto.send ('t', 'BBB', i, t[0], t[1]) + for i, t in enumerate (p['sharp_threshold']): + self.proto.send ('h', 'BHH', i, t[0], t[1]) + + def write_eeprom (self): + self.proto.send ('p', 'BB', ord ('E'), ord ('s')) + time.sleep (1) + self.proto.wait (lambda: True) + + def reset (self): + self.proto.send ('w') + self.proto.send ('w', 'H', 0) + self.proto.send ('z') + self.proto.send ('z') + + def close (self): + self.reset () + self.wait (lambda: True) + self.proto.file.close () + + def fileno (self): + return self.proto.fileno () + diff --git a/digital/io/tools/test_simu.py b/digital/io/tools/test_simu.py index b6bae7b2..7f208911 100644 --- a/digital/io/tools/test_simu.py +++ b/digital/io/tools/test_simu.py @@ -7,6 +7,8 @@ import utils.forked from asserv import Asserv import asserv.init +from io import Io +import io.init from proto.popen_io import PopenIO from inter.inter_node import InterNode @@ -30,6 +32,10 @@ class TestSimu (InterNode): self.asserv = Asserv (PopenIO (asserv_cmd), time, **asserv.init.host) self.asserv.async = True self.tk.createfilehandler (self.asserv, READABLE, self.asserv_read) + # Io. + self.io = Io (PopenIO (io_cmd), time, **io.init.host) + self.io.async = True + self.tk.createfilehandler (self.io, READABLE, self.io_read) # Color switch. self.change_color () self.colorVar.trace_variable ('w', self.change_color) @@ -38,17 +44,23 @@ class TestSimu (InterNode): self.forked_hub.kill () import time time.sleep (1) - app.asserv.close () + self.asserv.close () + self.io.close () def asserv_read (self, file, mask): self.asserv.proto.read () self.asserv.proto.sync () + def io_read (self, file, mask): + self.io.proto.read () + self.io.proto.sync () + def step (self): """Overide step to handle retransmissions, could be made cleaner using simulated time.""" InterNode.step (self) self.asserv.proto.sync () + self.io.proto.sync () def change_color (self, *dummy): i = self.colorVar.get () -- cgit v1.2.3