From: NeilBrown Date: Sun, 30 Dec 2012 20:37:56 +0000 (+1100) Subject: gsmd: allow repeat= arg to be a function. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=8e61c6a25f14fc9d3cafe7a5fd099c64d9a34b2c;p=plato.git gsmd: allow repeat= arg to be a function. This allows commands to be repeated differently, or not at all, depending on arbitrary aspects of state. 'data' support will use this. --- diff --git a/gsm/gsmd.py b/gsm/gsmd.py index 893d6ce..f71e8c6 100644 --- a/gsm/gsmd.py +++ b/gsm/gsmd.py @@ -831,11 +831,18 @@ class GsmD(AtChannel): n = len(cs) now = int(time.time()*1000) for i in range(n): - if self.lastrun[i] == 0 or (cs[i].repeat and - self.lastrun[i] + cs[i].repeat <= now): + if self.lastrun[i] == 0: return (i, 0) - if cs[i].repeat: - delay = (self.lastrun[i] + cs[i].repeat) - now; + repeat = cs[i].repeat + if repeat == None: + repeat = 0 + elif type(repeat) != int: + repeat = repeat(self) + + if repeat and self.lastrun[i] + repeat <= now): + return (i, 0) + if repeat: + delay = (self.lastrun[i] + repeat) - now; if delay < mindelay: mindelay = delay return (0, mindelay)