summaryrefslogtreecommitdiff
path: root/digital/io/tools
diff options
context:
space:
mode:
authorNicolas Schodet2008-06-09 23:10:27 +0200
committerNicolas Schodet2008-06-09 23:10:27 +0200
commitfbc40e54a1a42002b73b00a7858dec6300dfacb8 (patch)
tree4a4762772ffd5928c1aef8ea2511133205c24172 /digital/io/tools
parent9ff05ac3625c727556ec7583a6844bbf8439f742 (diff)
* digital/io/tools:
- added io to test_simu.
Diffstat (limited to 'digital/io/tools')
-rw-r--r--digital/io/tools/io/__init__.py1
-rw-r--r--digital/io/tools/io/init.py6
-rw-r--r--digital/io/tools/io/io.py36
-rw-r--r--digital/io/tools/test_simu.py14
4 files changed, 56 insertions, 1 deletions
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 ()