This commit is contained in:
zhongjin 2022-12-13 22:49:24 +08:00
parent 2c28feba3c
commit 976b35a753

View File

@ -1,10 +1,16 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from HackRF import HackRF
from PPM import PPM
from ModeS import ModeS
from getopt import getopt, GetoptError
import os,csv,sys
import numpy as np
import binascii
import socket # 导入 socket 模块
class ADSB_Encoder:
def _set_vars(self,alt,lat,lon,capability,imgap,nicsup,rp,gnd,sstat,tc,icao,callsign,time,filename,speed,vspeed,heading):
@ -42,33 +48,61 @@ class ADSB_Encoder:
self.longitude, self.surface)
df17_velocity = modes.vel_heading_encode(self.capability, self.icao, self.speed, self.heading, self.vspeed)
df17_callsign = modes.callsign_encode(self.capability, self.icao, self.callsign)
m = "".join(map("0x{:02x}".format,df17_pos_even))
ma = "*" + m.replace("0x","").upper() + ";\n"
print(ma)
m = "".join(map("0x{:02x}".format,df17_pos_odd))
mb = "*" + m.replace("0x","").upper() + ";\n"
print(mb)
ppm = PPM()
df17_array_position = ppm.frame_1090es_ppm_modulate(df17_pos_even, df17_pos_odd)
df17_array_velocity = ppm.frame_1090es_ppm_modulate(df17_velocity, df17_velocity)
df17_array_callsign = ppm.frame_1090es_ppm_modulate(df17_callsign, df17_callsign)
m = "".join(map("0x{:02x}".format,df17_velocity))
mc = "*" + m.replace("0x","").upper() + ";\n"
print(mc)
hackrf = HackRF()
m = "".join(map("0x{:02x}".format,df17_callsign))
md = "*" + m.replace("0x","").upper() + ";\n"
print(md)
HOST = '127.0.0.1'
PORT = 30001
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall(str.encode(ma))
s.sendall(str.encode(mb))
s.sendall(str.encode(mc))
s.sendall(str.encode(md))
s.close()
#ppm = PPM()
#df17_array_position = ppm.frame_1090es_ppm_modulate(df17_pos_even, df17_pos_odd)
#df17_array_velocity = ppm.frame_1090es_ppm_modulate(df17_velocity, df17_velocity)
#df17_array_callsign = ppm.frame_1090es_ppm_modulate(df17_callsign, df17_callsign)
#hackrf = HackRF()
#Position
samples_array = hackrf.hackrf_raw_IQ_format(df17_array_position)
samples = samples+samples_array
gap_array = ppm.addGap(self.intermessagegap)
samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
samples = samples+samples_array
#samples_array = hackrf.hackrf_raw_IQ_format(df17_array_position)
#samples = samples+samples_array
#gap_array = ppm.addGap(self.intermessagegap)
#samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
#samples = samples+samples_array
#Velocity
samples_array = hackrf.hackrf_raw_IQ_format(df17_array_velocity)
samples = samples+samples_array
gap_array = ppm.addGap(self.intermessagegap)
samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
samples = samples+samples_array
#samples_array = hackrf.hackrf_raw_IQ_format(df17_array_velocity)
#samples = samples+samples_array
#gap_array = ppm.addGap(self.intermessagegap)
#samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
#samples = samples+samples_array
#Callsign
samples_array = hackrf.hackrf_raw_IQ_format(df17_array_callsign)
samples = samples+samples_array
gap_array = ppm.addGap(self.intermessagegap)
samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
samples = samples+samples_array
#samples_array = hackrf.hackrf_raw_IQ_format(df17_array_callsign)
#samples = samples+samples_array
#gap_array = ppm.addGap(self.intermessagegap)
#samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
#samples = samples+samples_array
return samples
def writeOutputFile(self, data):
@ -109,7 +143,7 @@ def usage(msg=False):
def main():
alt,lat,lon,capability,imgap,nicsup,rp,gnd,sstat,tc,icao,callsign,time,filename,speed,vspeed,heading = \
27000,38.919909,-75.5884171,5,99564,0,1,False,0,11,'0x75008F','pynny',0,'Samples_256K.iq8s',300,0,0
27000,28.81001,113.2,5,99564,0,1,False,0,11,'0x75008F','pynny',0,'Samples_256K.iq8s',300,0,0
try:
(opts, args) = getopt(sys.argv[1:], 'hi:a:s:v:b:c:t:r:o:', \
['help','icao=','lat=','long=','altitude=','speed=','vspeed=','bearing=','callsign=',
@ -142,11 +176,11 @@ def main():
encoder = ADSB_Encoder()
encoder._set_vars(alt,lat,lon,capability,imgap,nicsup,rp,gnd,sstat,tc,icao,callsign,time,filename,speed,vspeed,heading)
#attrs = vars(encoder)
#print(', '.join("%s: %s" % item for item in attrs.items()))
attrs = vars(encoder)
print(', '.join("%s: %s" % item for item in attrs.items()))
data = encoder.encode()
encoder.writeOutputFile(data)
#encoder.writeOutputFile(data)
if __name__ == "__main__":
main()