Skip to content

Commit

Permalink
Merge pull request #482 from bitcraze/rik/link_error_callback
Browse files Browse the repository at this point in the history
Add callback for handling link errors in disconnected state
  • Loading branch information
gemenerik authored Oct 7, 2024
2 parents c87fc89 + 2e7ddcc commit aeb49b6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cflib/crazyflie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def __init__(self, link=None, ro_cache=None, rw_cache=None):

# Called if establishing of the link fails (i.e times out)
self.connection_failed = Caller()
# Called if link driver has an error while state is DISCONNECTED
self.disconnected_link_error = Caller()
# Called for every packet received
self.packet_received = Caller()
# Called for every packet sent
Expand Down Expand Up @@ -198,10 +200,12 @@ def _link_error_cb(self, errmsg):
self.link = None
if (self.state == State.INITIALIZED):
self.connection_failed.call(self.link_uri, errmsg)
if (self.state == State.CONNECTED or
elif (self.state == State.CONNECTED or
self.state == State.SETUP_FINISHED):
self.disconnected.call(self.link_uri)
self.connection_lost.call(self.link_uri, errmsg)
elif (self.state == State.DISCONNECTED):
self.disconnected_link_error.call(self.link_uri, errmsg)
self.state = State.DISCONNECTED

def _link_quality_cb(self, percentage):
Expand Down

0 comments on commit aeb49b6

Please sign in to comment.