Create a door controller simulator

The simulator fakes up some libraries so that the main door controller
script can be tested without needing a Raspberry Pi.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2015-04-22 20:46:03 -04:00
parent 668260c7b2
commit 8faf31c86f
7 changed files with 76 additions and 0 deletions

18
simulator/RPi/GPIO.py Normal file
View File

@ -0,0 +1,18 @@
print("Using fake GPIO driver.")
BOARD = "board"
IN = "input"
OUT = "output"
def cleanup():
print("> GPIO: cleaning up!")
def output(pin, voltage):
state = "on" if (voltage == 1) else "off"
print("> GPIO setting pin %s to %s." % (pin, state))
def setmode(mode):
print("> GPIO setting mode: %s." % mode)
def setup(pin, iomode):
print("> GPIO setting up pin: %s, %s." % (pin, iomode))

View File

15
simulator/__init__.py Normal file
View File

@ -0,0 +1,15 @@
import os
import sys
#######################################################
# #
# Add simulator/ directory to the module search path. #
# #
#######################################################
sys.path.insert(0, os.path.join(os.getcwd(), "simulator"))
print("Welcome to the Workantile Door System Simulator!")
import doors
from doors import *

1
simulator/doors.py Symbolic link
View File

@ -0,0 +1 @@
../doors.py

18
simulator/serial.py Normal file
View File

@ -0,0 +1,18 @@
print("Using fake serial driver.")
import random
import string
class Serial:
def __init__(self, path, baudrate, timeout):
self.path = path
self.baudrate = baudrate
self.timeout = timeout
def read(self, count):
lst = [random.choice(string.hexdigits) for n in range(count - 2)]
ret = "A" + "".join(lst) + "D"
return ret.encode()
def flushInput(self):
pass

View File

View File

@ -0,0 +1,24 @@
print("Using fake urllib module.")
import random
class Request:
def __init__(self, url):
self.url = url
def __enter__(self):
return self
def __exit__(self, type, value, tb):
pass
def read(self):
if random.randint(0, 1) == 0:
return "OK".encode()
return "ERROR".encode()
def urlopen(url):
print("> URLLIB: opening url %s" % url)
return Request(url)