Hardware Reference
In-Depth Information
Instead you should limit the number of places to look by writing something very simple, and
testing it. Only then should you add more complexity, step by step. Also, before working
with pesky real-world hardware that makes it harder to see what's going on (and so harder to
ind bugs) you'll irst simulate the hardware in software.
Figure 12-1, earlier, identiied the major blocks needed for your door controller system. he irst
step is to implement it in Python. Enter Listing 12-1 in a new ile called door_controller.py .
Listing 12-1 The Initial Code for the Door Controller
#!/usr/bin/env python
“””Door Lock: System to control an electric door lock
class AuthToken:
def __init__(self, id, secret):
self.id=id
self.secret=secret
class TestDoorController:
def send_open_pulse(self):
print “unlock the door”
class BasicAuthenticator:
id = “Andrew”
secretPassword = “1234”
def check(self,token):
print “checking input of '” + token.id + “', ;
password: “ + token.secret + “, against secret password ;
'” + self.secretPassword +”'”
result = (token.secret == self.secretPassword) & ;
(token.id == self.id)
print “authentication is: “ + str(result)
return result
class TestInput:
def getInput(self):
print “checking for input”
authToken = AuthToken(“Andrew”,”1234”)
return authToken
def main():
authInput = TestInput()
continued
Search WWH ::




Custom Search