|
|
|
@ -8,8 +8,11 @@ from collections import namedtuple
@@ -8,8 +8,11 @@ from collections import namedtuple
|
|
|
|
|
from datetime import datetime, timedelta |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__version__ = '0.0.1' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# example time table for the TrapControl |
|
|
|
|
example = ''' |
|
|
|
|
example = ''' |
|
|
|
|
00:00.0 close |
|
|
|
|
00:06.0 open |
|
|
|
|
00:08.0 close |
|
|
|
@ -36,12 +39,12 @@ def parse_time_table(timetable, available_commands):
@@ -36,12 +39,12 @@ def parse_time_table(timetable, available_commands):
|
|
|
|
|
|
|
|
|
|
timetable: |
|
|
|
|
a textual representaion of time and commands like |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
00:12.0 close |
|
|
|
|
00:14.0 open |
|
|
|
|
00:16.0 close |
|
|
|
|
00:18.0 open |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
available_commands: |
|
|
|
|
a dictionary containing the available human readable commands as |
|
|
|
|
keys and the commands to send as values |
|
|
|
@ -56,7 +59,7 @@ def parse_time_table(timetable, available_commands):
@@ -56,7 +59,7 @@ def parse_time_table(timetable, available_commands):
|
|
|
|
|
content_lines = (line.strip() for line in raw_lines) |
|
|
|
|
# remove empty lines |
|
|
|
|
lines = (line for line in content_lines if line) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
timed_commands =[] |
|
|
|
|
for line in lines: |
|
|
|
|
# split the lines into time and command |
|
|
|
@ -113,7 +116,7 @@ def parse_command(command, available_commands):
@@ -113,7 +116,7 @@ def parse_command(command, available_commands):
|
|
|
|
|
{'open': 0, 'close': 1} |
|
|
|
|
|
|
|
|
|
returns the command to send over serial |
|
|
|
|
''' |
|
|
|
|
''' |
|
|
|
|
try: |
|
|
|
|
cmd = available_commands[command.lower()] |
|
|
|
|
except KeyError: |
|
|
|
@ -173,7 +176,7 @@ def run(scheduled_commands, serial_connection):
@@ -173,7 +176,7 @@ def run(scheduled_commands, serial_connection):
|
|
|
|
|
except KeyboardInterrupt: |
|
|
|
|
loop.stop() |
|
|
|
|
loop.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimedCommands(object): |
|
|
|
|
''' lightweight encapsulation of the functions in the module ''' |
|
|
|
@ -187,13 +190,14 @@ class TimedCommands(object):
@@ -187,13 +190,14 @@ class TimedCommands(object):
|
|
|
|
|
''' parses a time table and establishes a serial connection |
|
|
|
|
|
|
|
|
|
timetable: |
|
|
|
|
a file path to an excel file or |
|
|
|
|
a textual representaion of time and commands like |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
00:12.0 close |
|
|
|
|
00:14.0 open |
|
|
|
|
00:16.0 close |
|
|
|
|
00:18.0 open |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
available_commands: |
|
|
|
|
a dictionary containing the available human readable commands |
|
|
|
|
as keys and the commands to send as values. |
|
|
|
@ -215,7 +219,10 @@ class TimedCommands(object):
@@ -215,7 +219,10 @@ class TimedCommands(object):
|
|
|
|
|
# make sure the available commands are a dictionary |
|
|
|
|
cmd_dict = self._ensure_command_dict(available_commands) |
|
|
|
|
# parse the time table into something suitable |
|
|
|
|
self.commands = parse_time_table(timetable, cmd_dict) |
|
|
|
|
if '.xls' in timetable: |
|
|
|
|
self.commands = parse_excel_file(timetable, cmd_dict) |
|
|
|
|
else: |
|
|
|
|
self.commands = parse_time_table(timetable, cmd_dict) |
|
|
|
|
|
|
|
|
|
# establish the serial connection |
|
|
|
|
port = port or find_arduino_port() |
|
|
|
@ -232,7 +239,7 @@ class TimedCommands(object):
@@ -232,7 +239,7 @@ class TimedCommands(object):
|
|
|
|
|
items is used as a human readable command and the first |
|
|
|
|
character of this command will be sent over the wire |
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
if isinstance(iterable, dict): |
|
|
|
|
pairs = list(iterable.items()) |
|
|
|
@ -247,7 +254,7 @@ class TimedCommands(object):
@@ -247,7 +254,7 @@ class TimedCommands(object):
|
|
|
|
|
except: |
|
|
|
|
msg = 'available commands should be a list or dict of strings' |
|
|
|
|
raise TypeError(msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self): |
|
|
|
|
''' run the scheduled commands ''' |
|
|
|
@ -256,8 +263,6 @@ class TimedCommands(object):
@@ -256,8 +263,6 @@ class TimedCommands(object):
|
|
|
|
|
|
|
|
|
|
class TrapControl(TimedCommands): |
|
|
|
|
''' A simple, stripped down version for the magnetic plug trap ''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, timetable): |
|
|
|
|
super().__init__(timetable, ['open', 'close']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|