callat.py

来自「tinyos最新版」· Python 代码 · 共 37 行

PY
37
字号
# This script is in the public domain and has no copyright## CallAt/CallIn are simple utility classes that call a specified# function at a given point in the future.#import simcoreimport net.tinyos.sim.eventclass CallAt:    def __init__(self, when, callback, args = None):        interruptID = simcore.interp.getInterruptID()        def mycallback(interruptEvent):            if (interruptEvent.get_id() != interruptID):                return            simcore.interp.removeEventHandler(self.eventID);            if args != None:                callback(args);            else:                callback();        evclass = net.tinyos.sim.event.InterruptEvent        self.eventID = simcore.interp.addEventHandler(mycallback, evclass);        simcore.interp.interruptInFuture(when, interruptID)    def cancel(self):        simcore.interp.removeEventHandler(self.eventID)class CallIn(CallAt):    def __init__(self, delay, callback, args = None):        when = simcore.sim.getTossimTime() + delay;        CallAt.__init__(self, when, callback, args);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?