def main(): global interface_drone_comm, IP_RX, UDP_Port_RX, fifo_write parsedArgs = parsearguments() interface_drone_comm = parsedArgs.interface_drone_comm mode = parsedArgs.mode IP_RX = parsedArgs.ip_rx UDP_Port_RX = parsedArgs.udp_port_rx frame_type = parsedArgs.frame_type src = find_mac(interface_drone_comm) comm_id = bytes([parsedArgs.comm_id]) print("DB_TEL_GROUND: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(src, UDP_Port_RX, IP_RX, 1606, b'\x01', interface_drone_comm, mode, comm_id, frame_type, b'\x02') print("DB_TEL_GROUND: Opening /root/telemetryfifo1...") fifo_write = open("/root/telemetryfifo1", "wb") print("DB_TEL_GROUND: Opened /root/telemetryfifo1") while True: received = dbprotocol.receive_telemetryfromdrone() if received != False: try: write_tofifos(received) sent = dbprotocol.sendto_smartphone(received, dbprotocol.APP_PORT_TEL) # print("DB_TX_TEL: Sent "+str(sent)+" bytes to sp") except Exception as e: print(e)
def main(): global interface_drone_comm, IP_RX, UDP_Port_RX, UDP_PORT_ANDROID parsedArgs = parsearguments() interface_drone_comm = parsedArgs.interface_drone_comm mode = parsedArgs.mode IP_RX = parsedArgs.ip_rx UDP_Port_RX = parsedArgs.udp_port_rx UDP_PORT_ANDROID = parsedArgs.udp_port_android frame_type = parsedArgs.frame_type src = find_mac(interface_drone_comm) extended_comm_id = bytes( b'\x01' + b'\x01' + bytearray.fromhex(parsedArgs.comm_id)) # <odd><direction><comm_id> # print("DB_TX_Comm: Communication ID: " + comm_id.hex()) # only works in python 3.5+ print("DB_TX_Comm: Communication ID: " + str(extended_comm_id)) dbprotocol = DBProtocol(src, dst, UDP_Port_RX, IP_RX, UDP_PORT_ANDROID, b'\x01', interface_drone_comm, mode, extended_comm_id, frame_type, b'\x04') if mode == 'wifi': dbprotocol.updateRouting() last_keepalive = 0 while True: last_keepalive = dbprotocol.process_smartphonerequests( last_keepalive) # non-blocking time.sleep(0.5)
def main(): global interface_drone_comm, IP_RX, UDP_Port_RX, UDP_PORT_ANDROID parsedArgs = parsearguments() interface_drone_comm = parsedArgs.interface_drone_comm mode = parsedArgs.mode IP_RX = parsedArgs.ip_rx UDP_Port_RX = parsedArgs.udp_port_rx UDP_PORT_ANDROID = parsedArgs.udp_port_android comm_id = bytes([parsedArgs.comm_id]) print("DB_Comm_GROUND: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(UDP_Port_RX, IP_RX, UDP_PORT_ANDROID, DBDir.DB_TO_UAV, interface_drone_comm, mode, comm_id, DBPort.DB_PORT_COMMUNICATION, tag='DB_Comm_GROUND: ') last_keepalive = 0 while True: last_keepalive = dbprotocol.process_smartphonerequests( last_keepalive) # non-blocking time.sleep(0.5)
def main(): """ Example of how to use the DroneBridge python lib to send & receive your custom data. -- Run using root privileges! -- -- set interface_drone_comm to your wifi adapter! -- Run on ground station using the DroneBridge image. If used with EZ-WBC image you need to install some extra packages python3. If not executed on DroneBridge/WBC rpi-image the wifi adapters must be in monitor mode and patched with patches provided by EZ-WBC project. :return: """ udp_port_rx = 5010 # relict - set to some free port - not used ip_rx = "192.168.2.2" # relict - set to something - not used udp_port_smartphone = udp_port_rx # not used - choose any comm_direction = DBDir.DB_TO_UAV # On ground station we want to send stuff to UAV (do not change) interface_drone_comm = "000ee8dcaa2c" # Interface name of your wifi adapter (with DroneBridge & WBC it is the MAC) mode = "m" # not used - tell him to use long range link and not wifi - wifi will be implemented in a later stage communication_id = 201 # Must be same on ground and UAV - identifies a link - choose a number between 0-255 # Channel/packet identifier - must be the same on ground & UAV - ports 1-7 are already assigned # - choose number from 8-255 in byte/hex format dronebridge_port = b'\x08' tag = 'MY_CUST_LINK: ' # Gets written in front of every message produced by DBProtocol class db_protocol = DBProtocol(udp_port_rx, ip_rx, udp_port_smartphone, comm_direction, interface_drone_comm, mode, communication_id, dronebridge_port, tag=tag) while True: # receive a packet, parse it, get payload (pure bytes) my_payload = db_protocol.receive_from_db( custom_timeout=2) # return False if nothing received # alternative: # db_lr_socket = db_protocol.getcommsocket() # get the configured long range socket # my_payload = db_protocol.parse_packet(bytearray(db_lr_socket.recv(2048))) print("Got: " + str(my_payload) + " from the UAV!") # Send something to your custom port: my_new_payload = b'\x05\x05\x05\x06\x06\x07\x07\x01\x02\x03\x04\x05\x06\x07\x08\x09' db_protocol.sendto_uav(my_new_payload, dronebridge_port) print("Sent: " + str(my_new_payload) + " back the UAV!") time.sleep(0.5)
def main(): global SerialPort, UDP_Port_TX, IP_TX parsedArgs = parseArguments() UDP_Port_TX = 1604 mode = parsedArgs.mode frame_type = parsedArgs.frame_type DB_INTERFACE = parsedArgs.DB_INTERFACE src = find_mac(DB_INTERFACE) comm_id = bytes([parsedArgs.comm_id]) # print("DB_TX_Comm: Communication ID: " + comm_id.hex()) # only works in python 3.5+ print("DB_RX_Comm: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(src, UDP_Port_TX, IP_TX, 0, b'\x03', DB_INTERFACE, mode, comm_id, frame_type, b'\x04') while True: dbprotocol.receive_process_datafromgroundstation() # blocking
def main(): global SerialPort, UDP_Port_TX, IP_TX parsedArgs = parseArguments() SerialPort = parsedArgs.serialport UDP_Port_TX = parsedArgs.udp_port_tx istelemetryenabled = False if parsedArgs.enable_telemetry == "yes": istelemetryenabled = True mode = parsedArgs.mode frame_type = parsedArgs.frame_type DB_INTERFACE = parsedArgs.DB_INTERFACE src = find_mac(DB_INTERFACE) comm_id = bytes(b'\x01' + b'\x02' + bytearray.fromhex(parsedArgs.comm_id)) # print("DB_RX_TEL: Communication ID: " + comm_id.hex()) # only works in python 3.5 print("DB_RX_TEL: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(src, dst, UDP_Port_TX, IP_TX, 0, b'\x02', DB_INTERFACE, mode, comm_id, frame_type, b'\x02') if istelemetryenabled: tel_sock = openFCTel_Socket() time.sleep(0.3) while True: # Test # LTM_Frame = b'$TA\x00\x00\x01\x00\xf0\x00\xf1' # dbprotocol.sendto_groundstation(LTM_Frame, b'\x02') # time.sleep(1) # Test end if istelemetryenabled: if tel_sock.read() == b'$': tel_sock.read() # next one is always a 'T' (do not care) LTM_Frame = read_LTM_Frame(tel_sock.read(), tel_sock) dbprotocol.sendto_groundstation(LTM_Frame, b'\x02') # create DroneBridgeFrame and send if LTM_Frame[ 2] == 83: # int("53", 16) --> 0x53 = S in UTF-8 --> sending frame after each status frame dbprotocol.send_dronebridge_frame() dbprotocol.receive_process_datafromgroundstation( ) # to get the beacon frame and its RSSI values if not istelemetryenabled: # DroneBridge LTM Frame is triggered from LTM origin frame. If telemetry is "no" we need to change trigger dbprotocol.send_dronebridge_frame() time.sleep(0.2)
def main(): global SerialPort, UDP_Port_TX, IP_TX parsedArgs = parseArguments() UDP_Port_TX = parsedArgs.udp_port_tx mode = parsedArgs.mode frame_type = parsedArgs.frame_type DB_INTERFACE = parsedArgs.DB_INTERFACE src = find_mac(DB_INTERFACE) extended_comm_id = bytes( b'\x01' + b'\x02' + bytearray.fromhex(parsedArgs.comm_id)) # <odd><direction><comm_id> # print("DB_TX_Comm: Communication ID: " + comm_id.hex()) # only works in python 3.5+ print("DB_RX_Comm: Communication ID: " + str(extended_comm_id)) dbprotocol = DBProtocol(src, dst, UDP_Port_TX, IP_TX, 0, b'\x02', DB_INTERFACE, mode, extended_comm_id, frame_type, b'\x04') #setupVideo(mode) #time.sleep(2) while True: dbprotocol.receive_process_datafromgroundstation() # blocking
def main(): global interface_drone_comm, IP_RX, UDP_Port_RX, UDP_PORT_ANDROID parsedArgs = parsearguments() interface_drone_comm = parsedArgs.interface_drone_comm mode = parsedArgs.mode IP_RX = parsedArgs.ip_rx UDP_Port_RX = parsedArgs.udp_port_rx UDP_PORT_ANDROID = parsedArgs.udp_port_android src = find_mac(interface_drone_comm) comm_id = bytes([parsedArgs.comm_id]) print("DB_Comm_GROUND: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(src, UDP_Port_RX, IP_RX, UDP_PORT_ANDROID, b'\x01', interface_drone_comm, mode, comm_id, b'\x04') last_keepalive = 0 while True: last_keepalive = dbprotocol.process_smartphonerequests( last_keepalive) # non-blocking time.sleep(0.5)
def main(): global SerialPort, UDP_Port_TX, IP_TX parsedArgs = parseArguments() UDP_Port_TX = 1604 mode = parsedArgs.mode DB_INTERFACE = parsedArgs.DB_INTERFACE comm_id = bytes([parsedArgs.comm_id]) # print("DB_TX_Comm: Communication ID: " + comm_id.hex()) # only works in python 3.5+ print("DB_Comm_Air: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(UDP_Port_TX, IP_TX, 0, DBDir.DB_TO_GND, DB_INTERFACE, mode, comm_id, DBPort.DB_PORT_COMMUNICATION, tag='DB_Comm_Air: ') while True: dbprotocol.receive_process_datafromgroundstation() # blocking
def main(): global interface_drone_comm, IP_RX, UDP_Port_RX, fifo_write parsedArgs = parsearguments() interface_drone_comm = parsedArgs.interface_drone_comm mode = parsedArgs.mode IP_RX = parsedArgs.ip_rx UDP_Port_RX = parsedArgs.udp_port_rx frame_type = parsedArgs.frame_type src = find_mac(interface_drone_comm) comm_id = bytes(b'\x01' + b'\x01' + bytearray.fromhex(parsedArgs.comm_id)) # print("DB_TX_TEL: Communication ID: " + comm_id.hex()) # only works in python 3.5 print("DB_TX_TEL: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(src, dst, UDP_Port_RX, IP_RX, 1606, b'\x01', interface_drone_comm, mode, comm_id, frame_type, b'\x02') print("DB_TX_TEL: Opening /root/telemetryfifo1...") fifo_write = open("/root/telemetryfifo1", "wb") print("DB_TX_TEL: Opened /root/telemetryfifo1") while True: received = dbprotocol.receive_telemetryfromdrone() #received= b'$TA\x00\x00\x01\x00\xf0\x00\xf1' #time.sleep(0.15) if received != False: try: if received[2] == 89: # int("59", 16) received = dbprotocol.finish_dronebridge_ltmframe(received) # send a beaconframe so drone telemetry can extract signal strength. MSP RSSI over AUX is also a option # Then RSSI field in LTM would be set correctly. But RSSI would be in % which is worse compared to dbm dbprotocol.send_beacon() write_tofifos(received) sent = dbprotocol.sendto_smartphone( received, dbprotocol.LTM_PORT_SMARTPHONE) #print("DB_TX_TEL: Sent "+str(sent)+" bytes to sp") except Exception as e: print(e)
def main(): global SerialPort, UDP_Port_TX, IP_TX parsedArgs = parseArguments() SerialPort = parsedArgs.serialport UDP_Port_TX = parsedArgs.udp_port_tx mode = parsedArgs.mode DB_INTERFACE = parsedArgs.DB_INTERFACE telemetry_selection_auto = False isLTMTel = True if parsedArgs.telemetry_type == "mavlink": isLTMTel = False elif parsedArgs.telemetry_type == "auto": telemetry_selection_auto = True isLTMTel = False comm_id = bytes([parsedArgs.comm_id]) # print("DB_TEL_AIR: Communication ID: " + comm_id.hex()) # only works in python 3.5 print("DB_TEL_AIR: Communication ID: " + str(comm_id)) dbprotocol = DBProtocol(UDP_Port_TX, IP_TX, 0, DBDir.DB_TO_GND, DB_INTERFACE, mode, comm_id, DBPort.DB_PORT_TELEMETRY, tag='DB_TEL_AIR: ') tel_sock = openFCTel_Socket(parsedArgs.baudrate) time.sleep(0.3) if telemetry_selection_auto: isLTMTel = isitLTM_telemetry(tel_sock) time.sleep(0.3) while True: if isLTMTel: if tel_sock.read() == b'$': tel_sock.read() # next one is always a 'T' (do not care) LTM_Frame = read_LTM_Frame(tel_sock.read(), tel_sock) dbprotocol.sendto_groundstation(LTM_Frame, b'\x02') else: # it is not LTM --> fully transparent link for MavLink and other protocols dbprotocol.sendto_groundstation(tel_sock.read(MavLink_chunksize), b'\x02')