-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdump1090writer.py
82 lines (75 loc) · 2.72 KB
/
dump1090writer.py
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
72
73
74
75
76
77
78
79
80
81
82
import socket
import time
import sys
import os
import asyncore
import threading
import mlat.client.output
#import output
import math
class Dump1090Writer:
def __init__(self):
self.conn = None
self.sock = None
def connect(self):
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect(('127.0.0.1', 30004))
self.conn = mlat.client.output.BeastConnection(None, self.sock, socket.AF_INET, socket.SOCK_STREAM, ('127.0.0.1', 30004))
#self.conn = mlat.client.output.BasestationConnection(None, self.sock, socket.AF_INET, socket.SOCK_STREAM, ('127.0.0.1', 30004))
except:
print('Cannot connect to dump1090 (yet?)')
#self.conn.connect_now()
#self.conn.connected = True
def send_msg(self, msg):
if self.conn is None or not self.conn.connected:
self.connect()
# Format as beast message
speed = float(msg['ground_speed']) * 1.94384 # m/s in kt
track = math.radians(float(msg['track']))
ns = speed * math.cos(track)
ew = speed * math.sin(track)
#print('send_position')
anon = False
if msg['address'].lower()[0:2] == 'DD' or msg['address'].lower()[0:1] == '1':
anon = True
self.conn.send_position(None, int(msg['address'], 16), float(msg['latitude']), float(msg['longitude']), float(msg['altitude']) * 3.28084,
ns, ew, int(float(msg['climb_rate']) * 196.85), msg['registration'], None, None, None, anon, False)
asyncore.loop(count=1)
if __name__ == '__main__':
# Only for testing
w = Dump1090Writer()
w.connect()
print(w.conn.connected)
while True:
w.send_msg({
'pps_offset': '0.842',
'frequency': '868.191',
'aircraft_type': '8',
'address_type': '2',
'address': 'AAAAAA',
'timestamp': '145021',
'latitude': '+50.36201',
'longitude': '+9.22168',
'altitude': '555',
'climb_rate': '+0.0',
'ground_speed': '100',
'track': '270.0',
'turn_rate': '+0.0',
'magic_number': '4',
'gps_status': '03x05',
'channel': '00',
'flarm_timeslot': '_',
'ogn_timeslot': 'o',
'frequency_offset': '-9.23',
'decode_quality': '50.8',
'signal_quality': '67.0',
'demodulator_type': '0',
'error_count': '0',
'distance': '0.0',
'bearing': '000.0',
'phi': '+80.4',
'multichannel': None,
'baro_altitude': None,
'registration': 'D-EABC'})
time.sleep(0.1)