From 8e61c6a25f14fc9d3cafe7a5fd099c64d9a34b2c Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 31 Dec 2012 07:37:56 +1100 Subject: [PATCH] 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. --- gsm/gsmd.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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) -- 2.39.5