forked from mattdy/flightpi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SbsMessage.py
56 lines (45 loc) · 1.44 KB
/
SbsMessage.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
"""
SbsMessage.py
Parses SBS-1 ADS-B messages into a workable Python object
Inspiration from https://github.com/kanflo/ADS-B-funhouse/blob/master/sbs1.py
Matt Dyson
24/01/18
Part of FlightPi - http://github.com/mattdy/flightpi
"""
import logging
log = logging.getLogger('root')
class SbsMessageType:
ES_IDENT_AND_CATEGORY = 1
ES_SURFACE_POS = 2
ES_AIRBORNE_POS = 3
ES_AIRBORNE_VEL = 4
SURVEILLANCE_ALT = 5
SURVEILLANCE_ID = 6
AIR_TO_AIR = 7
ALL_CALL_REPLY = 8
class SbsMessage:
def __init__(self, input):
self.parts = input.split(",")
if self.parts[0] != "MSG":
raise ValueError("Invalid message")
self.transmissionType = self.getPart(1)
self.sessionID = self.getPart(2)
self.aircraftID = self.getPart(3)
self.icao24 = self.getPart(4)
self.flightID = self.getPart(5)
self.callsign = self.getPart(10)
self.altitude = self.getint(11)
self.groundSpeed = self.getPart(12)
self.track = self.getPart(13)
self.verticalRate = self.getPart(16)
self.squawk = self.getPart(17)
# log.info(self.squawk) # for viewing parts of messages
def getPart(self, index):
fetch = self.parts[index].strip()
if(fetch==''): return None
return fetch
def getint(self,index):
fetch = self.parts[index].strip()
fetch = int(fetch)
if(fetch==''): return None
return fetch