annotate MonitorDev.py @ 7:51b22c1cfe2c

Config file
author darius
date Sat, 29 Sep 2007 14:40:17 +0000
parents 45d9895a5020
children 24c7e85c3efd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
1 #!/usr/bin/env python
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
2
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
3 ############################################################################
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
4 # Monitoring/control interface to hardware for beermon
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
5 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
6 # $Id: MonitorDev.py,v 1.1 2007/09/29 14:39:59 darius Exp $
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
7 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
8 # Depends on: Python 2.3 (I think)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
9 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
10 ############################################################################
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
11 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
12 # Copyright (C) 2007 Daniel O'Connor. All rights reserved.
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
13 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
14 # Redistribution and use in source and binary forms, with or without
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
15 # modification, are permitted provided that the following conditions
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
16 # are met:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
17 # 1. Redistributions of source code must retain the above copyright
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
18 # notice, this list of conditions and the following disclaimer.
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
19 # 2. Redistributions in binary form must reproduce the above copyright
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
20 # notice, this list of conditions and the following disclaimer in the
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
21 # documentation and/or other materials provided with the distribution.
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
22 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
23 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
26 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
33 # SUCH DAMAGE.
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
34 #
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
35 ############################################################################
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
36
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
37 import threading, re, time, pexpect
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
38
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
39 class MonitorDev(threading.Thread):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
40 """This class continually polls the hardware for temperature
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
41 readings and accepts state changes to heat & cool"""
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
42
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
43 # Match a ROM ID (eg 00:11:22:33:44:55:66:77)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
44 romre = re.compile('([0-9a-f]{2}:){7}[0-9a-f]{2}')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
45 # Match the prompt
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
46 promptre = re.compile('> ')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
47
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
48 # Dictionary of sensor IDs & temperatures
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
49 temps = {}
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
50 # Dictionary of sensor IDs & epoch times
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
51 lastUpdate = {}
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
52
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
53 # List of all device IDs
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
54 devs = []
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
55 # List of temperature sensor IDs
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
56 tempdevs = []
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
57
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
58 # Lock to gate access to the comms
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
59 commsLock = None
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
60
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
61 currState = 'idle'
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
62
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
63 lastHeatOn = 0
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
64 lastHeatOff = 0
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
65 lastCoolOn = 0
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
66 lastCoolOff = 0
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
67
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
68 def __init__(self, _log, conf):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
69 global log
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
70 log = _log
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
71 threading.Thread.__init__(self)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
72
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
73 # Collect parameters
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
74 self.coolRelay = conf.getint('hardware', 'coolRelay')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
75 self.heatRelay = conf.getint('hardware', 'heatRelay')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
76 self.fermenterId = conf.get('hardware', 'fermenterId')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
77 self.fridgeId = conf.get('hardware', 'fridgeId')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
78 self.ambientId = conf.get('hardware', 'ambientId')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
79 self.minCoolOnTime = conf.getfloat('hardware', 'minCoolOnTime')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
80 self.minCoolOffTime = conf.getfloat('hardware', 'minCoolOffTime')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
81 self.minHeatOnTime = conf.getfloat('hardware', 'minHeatOnTime')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
82 self.minHeatOffTime = conf.getfloat('hardware', 'minHeatOffTime')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
83 self.minHeatOvershoot = conf.getfloat('hardware', 'minHeatOvershoot')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
84 self.minCoolOvershoot = conf.getfloat('hardware', 'minCoolOvershoot')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
85
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
86 # Setup locking & spawn SSH
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
87 self.commsLock = threading.Lock()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
88 self.p = pexpect.spawn('/usr/bin/ssh', ['-xt', '-enone', '-i', '/home/darius/.ssh/id_wrt', 'root@wrt', '(echo logged in; microcom -D/dev/cua/1)'])
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
89 assert(self.p.expect('logged in') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
90 self.p.timeout = 3
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
91 self.setspeed()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
92
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
93 # Search for 1-wire modules
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
94 self.devs = self.find1wire()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
95 self.tempdevs = filter(self.istemp, self.devs)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
96
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
97 log.debug("fermenterId - %s" % (self.fermenterId))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
98 log.debug("fridgeId - %s" % (self.fridgeId))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
99 log.debug("ambientId - %s" % (self.ambientId))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
100 log.debug("minCoolOnTime - %d, minCoolOffTime - %d" %
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
101 (self.minCoolOnTime, self.minCoolOffTime))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
102 log.debug("minHeatOnTime - %d, minHeatOffTime - %d" %
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
103 (self.minHeatOnTime, self.minHeatOffTime))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
104 log.debug("minHeatOvershoot - %3.2f, minCoolOvershoot - %3.2f" %
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
105 (self.minHeatOvershoot, self.minCoolOvershoot))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
106 self.start()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
107
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
108 def setspeed(self):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
109 self.commsLock.acquire()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
110 self.p.send('~')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
111 assert(self.p.expect('t - set terminal') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
112 self.p.send('t')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
113 assert(self.p.expect('p - set speed') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
114 self.p.send('p')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
115 assert(self.p.expect('f - 38400') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
116 self.p.send('f')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
117 assert(self.p.expect('done!') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
118 self.commsLock.release()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
119
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
120 def find1wire(self):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
121 self.commsLock.acquire()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
122 self.p.sendline('')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
123 assert(self.p.expect('> ') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
124 self.p.sendline('sr')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
125 # Echo
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
126 assert(self.p.expect('sr') == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
127
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
128 # Send a new line which will give us a command prompt to stop on
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
129 # later. We could use read() but that would make the code a lot
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
130 # uglier
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
131 self.p.sendline('')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
132
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
133 devlist = []
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
134
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
135 # Loop until we get the command prompt (> ) collecting ROM IDs
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
136 while True:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
137 idx = self.p.expect([self.romre, self.promptre])
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
138 if (idx == 0):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
139 # Matched a ROM
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
140 #print "Found ROM " + self.p.match.group()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
141 devlist.append(self.p.match.group(0))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
142 elif (idx == 1):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
143 # Matched prompt, exit
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
144 break
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
145 else:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
146 # Unpossible!
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
147 self.commsLock.release()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
148 raise SystemError()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
149
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
150 self.commsLock.release()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
151
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
152 return(devlist)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
153
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
154 def istemp(self, id):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
155 [family, a, b, c, d, e, f, g] = id.split(':')
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
156 if (family == '10'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
157 return True
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
158 else:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
159 return False
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
160
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
161 def updateTemps(self):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
162 for i in self.tempdevs:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
163 try:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
164 self.temps[i] = float(self.readTemp(i))
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
165 self.lastUpdate[i] = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
166 except OWReadError:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
167 # Ignore this - just results in no update reflected by lastUpdate
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
168 pass
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
169
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
170 return(self.temps)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
171
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
172 def readTemp(self, id):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
173 self.commsLock.acquire()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
174 cmd = 'te ' + id
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
175 self.p.sendline(cmd)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
176 # Echo
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
177 assert(self.p.expect(cmd) == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
178 # Eat EOL left from expect
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
179 self.p.readline()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
180
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
181 line = self.p.readline().strip()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
182 self.commsLock.release()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
183 # 'CRC mismatch' can mean that we picked the wrong ROM..
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
184 if (re.match('CRC mismatch', line) != None):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
185 raise OWReadError
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
186
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
187 return(line)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
188
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
189 def setState(self, state):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
190 if (state == 'cool'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
191 relay = 1 << self.coolRelay
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
192 elif (state == 'heat'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
193 relay = 1 << self.heatRelay
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
194 elif (state == 'idle'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
195 relay = 0
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
196 else:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
197 raise(ValueError)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
198
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
199 if (state == self.currState):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
200 return
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
201
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
202 # Keep track of when we last turned off or on
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
203 if (state == 'cool'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
204 if (self.currState == 'heat'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
205 self.lastHeatOff = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
206 self.lastCoolOn = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
207 elif (state == 'heat'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
208 if (self.currState == 'cool'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
209 self.lastCoolOff = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
210 self.lastHeatOn = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
211 else:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
212 if (self.currState == 'cool'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
213 self.lastCoolOff = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
214 if (self.currState == 'heat'):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
215 self.lastHeatOff = time.time()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
216
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
217 self.currState = state
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
218
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
219 self.commsLock.acquire()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
220 # Need the extra spaces cause the parser in the micro is busted
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
221 cmd = 'out c %02x' % relay
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
222 self.p.sendline(cmd)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
223 # Echo
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
224 assert(self.p.expect(cmd) == 0)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
225 self.commsLock.release()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
226
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
227 def polltemps(self, temps):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
228 while True:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
229 for d in temps:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
230 #print d
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
231 t = gettemp(p, d)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
232 print "%s -> %s" % (d, t)
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
233 print
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
234
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
235 def run(self):
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
236 while True:
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
237 self.updateTemps()
45d9895a5020 Split into seperate files.
darius
parents:
diff changeset
238