forked from lyusupov/ADSB-Out
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PPM.py
61 lines (49 loc) · 1.64 KB
/
PPM.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
import numpy
from Encoder import Encoder
###############################################################
# Further work on fork
# Copyright (C) 2017 David Robinson
class PPM:
"""The PPM class contains functions about PPM manipulation
"""
def frame_1090es_ppm_modulate(self, even, odd):
"""
Args:
even and odd: The bits you would converted to PPM
Returns:
The bytearray of the PPM data
"""
ppm = [ ]
encoder = Encoder()
for i in range(48): # pause
ppm.append( 0 )
ppm.append( 0xA1 ) # preamble
ppm.append( 0x40 )
for i in range(len(even)):
word16 = numpy.packbits(encoder.manchester_encode(~even[i]))
ppm.append(word16[0])
ppm.append(word16[1])
for i in range(100): # pause
ppm.append( 0 )
ppm.append( 0xA1 ) # preamble
ppm.append( 0x40 )
for i in range(len(odd)):
word16 = numpy.packbits(encoder.manchester_encode(~odd[i]))
ppm.append(word16[0])
ppm.append(word16[1])
for i in range(48): # pause
ppm.append( 0 )
#print '[{}]'.format(', '.join(hex(x) for x in ppm))
return bytearray(ppm)
def addGap(self, gap):
"""
This function will add dead air as a gap between messages
Args:
gap: The number of microseconds to have as a gap
Returns:
The bytearray of the PPM data
"""
ppm = [ ]
for i in range(gap): # pause
ppm.append( 0 )
return bytearray(ppm)