-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·71 lines (58 loc) · 2.32 KB
/
main.py
File metadata and controls
executable file
·71 lines (58 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python3
# (c) Bluemark Innovations BV
# MIT license
import time
from pymavlink import mavutil
from bitstruct import *
import threading
import config # config.py with settings
from modules import odid # opendroneID functions
from modules import adsb # ADSB vehicle functions
from modules import log_file # log opendroneID data to a CSV file
from modules import sbs # for SBS export
if hasattr(config, 'sbs_server_ip_address'): # only enable SBS export if relevant vars have been defined
if hasattr(config, 'sbs_server_port'):
print("SBS export thread started")
sbs_thread = threading.Thread(target=sbs.connect, args=(1,))
sbs_thread.daemon = True
sbs_thread.start()
#setup MAVLink serial link and wait until a heartbeat is received
master = mavutil.mavlink_connection(config.interface, config.baudrate)
master.wait_heartbeat()
# if this var is not defined, make it true
if not hasattr(config, 'print_messages'):
config.print_messages = True
while True:
try:
msg = master.recv_match()
except:
pass
if not msg:
time.sleep(0.1)
continue
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
if msg.get_type() == 'HEARTBEAT':
if config.print_messages == True:
print("%s MAVLink heartbeat received" % current_time)
#print("%s" % msg.to_dict())
if msg.get_type() == 'ADSB_VEHICLE':
if config.print_messages == True:
print("\n%s MAVLink ADS-B vehicle message received" % current_time)
#print("%s" % msg.to_dict())
adsb.print_payload(msg)
if msg.get_type() == 'OPEN_DRONE_ID_MESSAGE_PACK':
if config.print_messages == True:
print("\n%s MAVLink OpenDroneID Message Pack message received" % current_time)
#print("\n%s" % msg.to_dict()) #print raw packet contents
odid.print_message_pack(msg.messages, msg.msg_pack_size)
if hasattr(config, 'log_path'):
if 'filename' not in globals():
global filename
filename = log_file.open_csv(config.log_path)
log_file.write_csv(msg.messages, msg.msg_pack_size,filename)
if hasattr(config, 'sbs_server_ip_address'):
try:
sbs.export(msg.messages, msg.msg_pack_size)
except:
pass