Skip to content

Commit

Permalink
Don't use sleep in power control, use GET_PACKET with a longer timeout (
Browse files Browse the repository at this point in the history
  • Loading branch information
cjo20 authored and oskarpearson committed Jan 22, 2017
1 parent 0901263 commit f7ca8b2
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions mmeowlink/handlers/stick.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,10 @@ def __call__ (self, command, repetitions=None, ack_wait_seconds=None):
buf = pkt.assemble( )
log.debug('Sending repeated message %s' % (str(buf).encode('hex')))

self.link.write(buf, repetitions=repetitions)

# The radio takes a while to send all the packets, so wait for a bit before
# trying to talk to the radio, otherwise we can interrupt it.
#
# This multiplication factor is based on
# testing, which shows that it takes 8.04 seconds to send 500 packets
# (8.04/500 =~ 0.016 packets per second).
# We don't want to miss the reply, so take off a bit:
time.sleep((repetitions * 0.016) - 2.2)
self.link.write(buf, repetitions=repetitions, timeout=0.024 * repetitions)

try:
self.wait_for_ack()
self.wait_for_ack(timeout=ack_wait_seconds)
return True
except CommsException, InvalidPacketReceived:
log.error("%s - Response not received - retrying" % time.time())
Expand Down Expand Up @@ -223,7 +214,7 @@ def power_control (self, minutes=None):
self.command = commands.PowerControl(**dict(minutes=minutes, serial=self.serial))
repeater = Repeater(self.link)

status = repeater(self.command, repetitions=500, ack_wait_seconds=20)
status = repeater(self.command, repetitions=500, ack_wait_seconds=12)

if status:
return True
Expand Down

0 comments on commit f7ca8b2

Please sign in to comment.