1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

Merge pull request #1569 from OlegHahm/pyterm_timer

pyterm: adds timer function
This commit is contained in:
Oleg Hahm 2014-08-13 13:33:10 -04:00
commit a9ded6337e

View File

@ -403,11 +403,25 @@ class SerCmd(cmd.Cmd):
sys.stderr.write("JSON regex with ID %s not found" % line)
def do_PYTERM_init(self, line):
"""Pyterm command: Add an startup command. (Only useful in
"""Pyterm command: Add a startup command. (Only useful in
addition with /save).
"""
self.init_cmd.append(line.strip())
def do_PYTERM_timer(self, line):
"""Pyterm command: Scheduler a timer."""
line = line.strip()
argv = line.partition(' ')
if (len(argv[2]) == 0):
sys.stderr.write("Usage: /timer <interval> <command>\n")
return
interval = int(argv[0])
cmd = argv[2]
self.logger.info("Schedule %s to fire after %i seconds" % (cmd, interval))
t = threading.Timer(interval, self.timer_handler, (cmd,))
t.start()
def load_config(self):
"""Internal function to laod configuration from file.
"""
@ -445,6 +459,16 @@ class SerCmd(cmd.Cmd):
if opt not in self.__dict__:
self.__dict__[opt] = self.config.get(sec, opt)
def timer_handler(self, line):
"""Handles a scheduled timer event.
Args:
line (str): the command line to be executed, when the timer
fires.
"""
self.logger.debug("Firing timer with %s" % line)
self.onecmd(self.precmd(line + '\n'))
def process_line(self, line):
"""Processes a valid line from node that should be printed and
possibly forwarded.