3131"""
3232
3333from __future__ import print_function
34+ import monotonic
3435import time
3536import socket
3637import sys
@@ -1296,18 +1297,18 @@ def listener(self, name, msg):
12961297 @handler .forward_loop
12971298 def listener (_ ):
12981299 # Send 1 heartbeat per second
1299- if time . time () - self ._heartbeat_lastsent > 1 :
1300+ if monotonic . monotonic () - self ._heartbeat_lastsent > 1 :
13001301 self ._master .mav .heartbeat_send (mavutil .mavlink .MAV_TYPE_GCS ,
13011302 mavutil .mavlink .MAV_AUTOPILOT_INVALID , 0 , 0 , 0 )
1302- self ._heartbeat_lastsent = time . time ()
1303+ self ._heartbeat_lastsent = monotonic . monotonic ()
13031304
13041305 # Timeouts.
13051306 if self ._heartbeat_started :
1306- if self ._heartbeat_error and self ._heartbeat_error > 0 and time . time (
1307+ if self ._heartbeat_error and self ._heartbeat_error > 0 and monotonic . monotonic (
13071308 ) - self ._heartbeat_lastreceived > self ._heartbeat_error :
13081309 raise APIException ('No heartbeat in %s seconds, aborting.' %
13091310 self ._heartbeat_error )
1310- elif time . time () - self ._heartbeat_lastreceived > self ._heartbeat_warning :
1311+ elif monotonic . monotonic () - self ._heartbeat_lastreceived > self ._heartbeat_warning :
13111312 if self ._heartbeat_timeout == False :
13121313 errprinter ('>>> Link timeout, no heartbeat in last %s seconds' %
13131314 self ._heartbeat_warning )
@@ -1316,7 +1317,7 @@ def listener(_):
13161317 @self .on_message (['HEARTBEAT' ])
13171318 def listener (self , name , msg ):
13181319 self ._heartbeat_system = msg .get_srcSystem ()
1319- self ._heartbeat_lastreceived = time . time ()
1320+ self ._heartbeat_lastreceived = monotonic . monotonic ()
13201321 if self ._heartbeat_timeout :
13211322 errprinter ('>>> ...link restored.' )
13221323 self ._heartbeat_timeout = False
@@ -1326,7 +1327,7 @@ def listener(self, name, msg):
13261327 @handler .forward_loop
13271328 def listener (_ ):
13281329 if self ._heartbeat_lastreceived :
1329- self ._last_heartbeat = time . time () - self ._heartbeat_lastreceived
1330+ self ._last_heartbeat = monotonic . monotonic () - self ._heartbeat_lastreceived
13301331 self .notify_attribute_listeners ('last_heartbeat' , self .last_heartbeat )
13311332
13321333 @property
@@ -2044,7 +2045,7 @@ def initialize(self, rate=4, heartbeat_timeout=30):
20442045 self ._handler .start ()
20452046
20462047 # Start heartbeat polling.
2047- start = time . time ()
2048+ start = monotonic . monotonic ()
20482049 self ._heartbeat_error = heartbeat_timeout or 0
20492050 self ._heartbeat_started = True
20502051 self ._heartbeat_lastreceived = start
0 commit comments