def _route_db_comm_protocol(self, raw_data_encoded): """Routing of the DroneBridge communication protocol packets""" status = False extracted_info = comm_message_extract_info( raw_data_encoded) # returns json bytes [0] and crc bytes [1] try: loaded_json = json.loads(extracted_info[0].decode()) except UnicodeDecodeError: print(self.tag + "Invalid command: Could not decode json message") return False except ValueError: print(self.tag + "ValueError on decoding extracted_info[0]") return False if loaded_json[ 'destination'] == 1 and self.comm_direction == DBDir.DB_TO_UAV and check_package_good( extracted_info): message = self._process_db_comm_protocol_type(loaded_json) if message != "": status = self.sendto_smartphone(message, self.APP_PORT_COMM) else: status = True elif loaded_json['destination'] == 2 and check_package_good( extracted_info): if self.comm_direction == DBDir.DB_TO_UAV: response_drone = self._redirect_comm_to_drone(raw_data_encoded) if response_drone != False and response_drone != None: message = self._process_db_comm_protocol_type(loaded_json) self.sendto_smartphone(message, self.APP_PORT_COMM) status = self.sendto_smartphone(response_drone, self.APP_PORT_COMM) else: message = self._process_db_comm_protocol_type(loaded_json) sentbytes = self.sendto_groundstation( message, DBPort.DB_PORT_COMMUNICATION.value) if sentbytes == None: status = True elif loaded_json['destination'] == 3: if self.comm_direction == DBDir.DB_TO_UAV: status = self.sendto_uav(raw_data_encoded, DBPort.DB_PORT_COMMUNICATION.value) else: change_settings_gopro(loaded_json) elif loaded_json['destination'] == 4: if self.comm_direction == DBDir.DB_TO_UAV: status = self.sendto_smartphone(raw_data_encoded, self.APP_PORT_COMM) else: print(self.tag + "DB_COMM_PROTO: Unknown message destination") return status
def _route_db_comm_protocol(self, raw_data_encoded): status = False extracted_info = comm_message_extract_info( raw_data_encoded) # returns json bytes and crc bytes loaded_json = json.loads(extracted_info[0].decode()) if loaded_json[ 'destination'] == 1 and self.comm_direction == TO_DRONE and check_package_good( extracted_info): message = self._process_db_comm_protocol_type(loaded_json) if message != "": status = self.sendto_smartphone(message, self.COMM_PORT_SMARTPHONE) else: status = True elif loaded_json['destination'] == 2 and check_package_good( extracted_info): if self.comm_direction == TO_DRONE: response_drone = self._redirect_comm_to_drone(raw_data_encoded) if response_drone != False and response_drone != None: message = self._process_db_comm_protocol_type(loaded_json) self.sendto_smartphone(message, self.COMM_PORT_SMARTPHONE) status = self.sendto_smartphone(response_drone, self.COMM_PORT_SMARTPHONE) else: message = self._process_db_comm_protocol_type(loaded_json) sentbytes = self.sendto_groundstation(message, PORT_COMMUNICATION) if sentbytes == None: status = True elif loaded_json['destination'] == 3: if self.comm_direction == TO_DRONE: status = self._sendto_drone(raw_data_encoded, PORT_COMMUNICATION) else: change_settings_gopro(loaded_json) elif loaded_json['destination'] == 4: if self.comm_direction == TO_DRONE: status = self.sendto_smartphone(raw_data_encoded, self.COMM_PORT_SMARTPHONE) else: print(self.tag + "DB_COMM_PROTO: Unknown message destination") return status