本文整理汇总了Python中Timer.Timer.check方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.check方法的具体用法?Python Timer.check怎么用?Python Timer.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer.Timer
的用法示例。
在下文中一共展示了Timer.check方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: monitor
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import check [as 别名]
def monitor():
"""Send discovery and monitor messages, and capture any responses"""
# Define the schedule of message polling
sendSwitchTimer = Timer(5, 1) # every n seconds offset by initial 1
switch_state = 0 # OFF
radio.receiver()
decoded = None
while True:
# See if there is a payload, and if there is, process it
if radio.isReceiveWaiting():
#trace("receiving payload")
payload = radio.receive()
try:
decoded = OpenHEMS.decode(payload)
except OpenHEMS.OpenHEMSException as e:
warning("Can't decode payload:" + str(e))
continue
OpenHEMS.showMessage(decoded)
updateDirectory(decoded)
logMessage(decoded)
#TODO: Should remember report time of each device,
#and reschedule command messages to avoid their transmit slot
#making it less likely to miss an incoming message due to
#the radio being in transmit mode
# handle messages with zero recs in them silently
#trace(decoded)
if len(decoded["recs"]) == 0:
print("Empty record:%s" % decoded)
else:
# assume only 1 rec in a join, for now
if decoded["recs"][0]["paramid"] == OpenHEMS.PARAM_JOIN:
#TODO: write OpenHEMS.getFromMessage("header_mfrid")
# send back a JOIN ACK, so that join light stops flashing
response = OpenHEMS.alterMessage(JOIN_ACK_MESSAGE,
header_mfrid=decoded["header"]["mfrid"],
header_productid=decoded["header"]["productid"],
header_sensorid=decoded["header"]["sensorid"])
p = OpenHEMS.encode(response)
radio.transmitter()
radio.transmit(p)
radio.receiver()
if sendSwitchTimer.check() and decoded != None:
request = OpenHEMS.alterMessage(SWITCH_MESSAGE,
header_sensorid=decoded["header"]["sensorid"],
recs_0_value=switch_state)
p = OpenHEMS.encode(request)
radio.transmitter()
radio.transmit(p)
radio.receiver()
switch_state = (switch_state+1) % 2 # toggle
示例2: monitor
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import check [as 别名]
def monitor():
"""Send discovery and monitor messages, and capture any responses"""
# Define the schedule of message polling
sendSwitchTimer = Timer(60, 1) # every n seconds offset by initial 1
switch_state = 0 # OFF
radio.receiver()
decoded = None
while True:
# See if there is a payload, and if there is, process it
if radio.isReceiveWaiting():
trace("receiving payload")
payload = radio.receive()
try:
decoded = OpenHEMS.decode(payload)
except OpenHEMS.OpenHEMSException as e:
print("Can't decode payload:" + str(e))
continue
OpenHEMS.showMessage(decoded)
updateDirectory(decoded)
logMessage(decoded)
#TODO: Should remember report time of each device,
#and reschedule command messages to avoid their transmit slot
#making it less likely to miss an incoming message due to
#the radio being in transmit mode
# assume only 1 rec in a join, for now
if len(decoded["recs"])>0 and decoded["recs"][0]["paramid"] == OpenHEMS.PARAM_JOIN:
#TODO: write OpenHEMS.getFromMessage("header_mfrid")
response = OpenHEMS.alterMessage(MESSAGE_JOIN_ACK,
header_mfrid=decoded["header"]["mfrid"],
header_productid=decoded["header"]["productid"],
header_sensorid=decoded["header"]["sensorid"])
p = OpenHEMS.encode(response)
radio.transmitter()
radio.transmit(p)
radio.receiver()
if sendSwitchTimer.check() and decoded != None and decoded["header"]["productid"] in [Devices.PRODUCTID_C1_MONITOR, Devices.PRODUCTID_R1_MONITOR_AND_CONTROL]:
request = OpenHEMS.alterMessage(MESSAGE_SWITCH,
header_sensorid=decoded["header"]["sensorid"],
recs_0_value=switch_state)
p = OpenHEMS.encode(request)
radio.transmitter()
radio.transmit(p)
radio.receiver()
switch_state = (switch_state+1) % 2 # toggle