Loading salt/drone/scripts/bridge.py +26 −12 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ class CrazyflieConnection: def __init__(self, uri, receive_callback): self.uri = uri self.receive_callback = receive_callback self._platform_information_packet = None # self._platform_information_packet = None self._cf = Crazyflie() Loading @@ -51,7 +51,7 @@ class CrazyflieConnection: else: # Add a callback so we can check that any data is coming back from the copter self._cf.packet_received.add_callback(self._cf._check_for_initial_packet_cb) self._cf.packet_received.add_callback(self._get_initial_packet) # self._cf.packet_received.add_callback(self._get_initial_packet) self._cf.platform.fetch_platform_informations(self._fetched_platform_information) except Exception as ex: # pylint: disable=W0703 Loading @@ -68,9 +68,10 @@ class CrazyflieConnection: # Variable used to keep main loop occupied until disconnect self.is_connected = False def _get_initial_packet(self, pk): self._platform_information_packet = pk self._cf.packet_received.remove_callback(self._get_initial_packet) # def _get_initial_packet(self, pk): # if pk.port == CRTPPort.LINKCTRL and pk.channel == 1: # self._platform_information_packet = pk # self._cf.packet_received.remove_callback(self._get_initial_packet) def _fetched_platform_information(self): self._cf.connected_ts = datetime.datetime.now() Loading @@ -82,9 +83,12 @@ class CrazyflieConnection: self._cf.packet_received.add_callback(self.receive_callback) def send(self, pk): print('Send ' + str(pk)) print('Serial send:', pk) self._cf.send_packet(pk) # def get_platform_information_packet(self): # return self._platform_information_packet def _connection_failed(self, link_uri, msg): """Callback when connection initial connection fails (i.e no Crazyflie at the speficied address)""" logger.info('Connection to {} failed: {}'.format(link_uri, msg)) Loading Loading @@ -125,16 +129,15 @@ class ClientConnection: def send(self, pk): pk_bytes = bytearray([pk.get_header()]) + pk.data self._prrt_socket.send(pk_bytes) print('PRRT try sending:', pk_bytes) self._prrt_socket.send_sync(pk_bytes) print('PRRT completed sending') def receive(self): pk_bytes, _ = self._prrt_socket.receive_asap() if len(pk_bytes) > 0: pk = CRTPPacket(pk_bytes[0], pk_bytes[1:]) print('Received: ' + str(pk) + ' Data Length: ' + str(len(pk.data))) if pk.port == CRTPPort.LINKCTRL and pk.channel == 3: return None else: print('PRRT receive:', pk) return pk else: return None Loading @@ -160,7 +163,18 @@ class Bridge: while self._crazyflie_connection.is_connected: pk = self._client_connection.receive() if pk: if pk.port == CRTPPort.LINKCTRL and pk.channel == 3: continue # elif pk.port == CRTPPort.LINKCTRL and pk.channel == 1: # print('platform information request') # platform_information = self._crazyflie_connection.get_platform_information_packet() # if platform_information is not None: # print('platform information reply') # self._client_connection.send(platform_information) # print('platform information reply send') # continue self._crazyflie_connection.send(pk) print('Bridge send finished') self.stop() def stop(self): Loading Loading
salt/drone/scripts/bridge.py +26 −12 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ class CrazyflieConnection: def __init__(self, uri, receive_callback): self.uri = uri self.receive_callback = receive_callback self._platform_information_packet = None # self._platform_information_packet = None self._cf = Crazyflie() Loading @@ -51,7 +51,7 @@ class CrazyflieConnection: else: # Add a callback so we can check that any data is coming back from the copter self._cf.packet_received.add_callback(self._cf._check_for_initial_packet_cb) self._cf.packet_received.add_callback(self._get_initial_packet) # self._cf.packet_received.add_callback(self._get_initial_packet) self._cf.platform.fetch_platform_informations(self._fetched_platform_information) except Exception as ex: # pylint: disable=W0703 Loading @@ -68,9 +68,10 @@ class CrazyflieConnection: # Variable used to keep main loop occupied until disconnect self.is_connected = False def _get_initial_packet(self, pk): self._platform_information_packet = pk self._cf.packet_received.remove_callback(self._get_initial_packet) # def _get_initial_packet(self, pk): # if pk.port == CRTPPort.LINKCTRL and pk.channel == 1: # self._platform_information_packet = pk # self._cf.packet_received.remove_callback(self._get_initial_packet) def _fetched_platform_information(self): self._cf.connected_ts = datetime.datetime.now() Loading @@ -82,9 +83,12 @@ class CrazyflieConnection: self._cf.packet_received.add_callback(self.receive_callback) def send(self, pk): print('Send ' + str(pk)) print('Serial send:', pk) self._cf.send_packet(pk) # def get_platform_information_packet(self): # return self._platform_information_packet def _connection_failed(self, link_uri, msg): """Callback when connection initial connection fails (i.e no Crazyflie at the speficied address)""" logger.info('Connection to {} failed: {}'.format(link_uri, msg)) Loading Loading @@ -125,16 +129,15 @@ class ClientConnection: def send(self, pk): pk_bytes = bytearray([pk.get_header()]) + pk.data self._prrt_socket.send(pk_bytes) print('PRRT try sending:', pk_bytes) self._prrt_socket.send_sync(pk_bytes) print('PRRT completed sending') def receive(self): pk_bytes, _ = self._prrt_socket.receive_asap() if len(pk_bytes) > 0: pk = CRTPPacket(pk_bytes[0], pk_bytes[1:]) print('Received: ' + str(pk) + ' Data Length: ' + str(len(pk.data))) if pk.port == CRTPPort.LINKCTRL and pk.channel == 3: return None else: print('PRRT receive:', pk) return pk else: return None Loading @@ -160,7 +163,18 @@ class Bridge: while self._crazyflie_connection.is_connected: pk = self._client_connection.receive() if pk: if pk.port == CRTPPort.LINKCTRL and pk.channel == 3: continue # elif pk.port == CRTPPort.LINKCTRL and pk.channel == 1: # print('platform information request') # platform_information = self._crazyflie_connection.get_platform_information_packet() # if platform_information is not None: # print('platform information reply') # self._client_connection.send(platform_information) # print('platform information reply send') # continue self._crazyflie_connection.send(pk) print('Bridge send finished') self.stop() def stop(self): Loading