mirror of
https://github.com/30hours/3lips.git
synced 2024-11-18 12:33:58 +00:00
AdsbAssociator almost ready
This commit is contained in:
parent
32401c9031
commit
aaab58d2ea
2 changed files with 78 additions and 5 deletions
|
@ -3,6 +3,8 @@
|
|||
@author 30hours
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
class AdsbAssociator:
|
||||
|
||||
"""
|
||||
|
@ -21,14 +23,44 @@ class AdsbAssociator:
|
|||
@brief Constructor for the AdsbAssociator class.
|
||||
"""
|
||||
|
||||
def process(self, assoc_detections_list):
|
||||
def process(self, radar_list, radar_data):
|
||||
|
||||
"""
|
||||
@brief Associate detections from 2+ radars.
|
||||
@param assoc_detections_list (list): List of JSON associated detections.
|
||||
@return str: JSON of associated detections.
|
||||
@param radar_list (list): List of radars to associate.
|
||||
@param radar_data (dict): Radar data for list of radars.
|
||||
@return dict: Associated detections by [hex][radar].
|
||||
"""
|
||||
|
||||
assoc_detections = {}
|
||||
|
||||
for radar in radar_list:
|
||||
|
||||
if radar_data[radar]["config"] is not None:
|
||||
|
||||
# get URL for adsb2truth
|
||||
url = self.generate_api_url(radar, radar_data[radar])
|
||||
|
||||
# get ADSB detections
|
||||
try:
|
||||
response = requests.get(url, timeout=1)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
adsb_detections = data
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error fetching data from {url}: {e}")
|
||||
adsb_detections = None
|
||||
|
||||
# associate radar and truth
|
||||
print(adsb_detections, flush=True)
|
||||
|
||||
|
||||
|
||||
#print(radar_list, flush=True)
|
||||
#print(radar_data, flush=True)
|
||||
|
||||
|
||||
|
||||
def process_1_radar(self, radar_detections, adsb_detections):
|
||||
|
||||
"""
|
||||
|
@ -38,4 +70,37 @@ class AdsbAssociator:
|
|||
@return str: JSON of associated detections.
|
||||
"""
|
||||
|
||||
def generate_api_url(self, radar, radar_data):
|
||||
|
||||
"""
|
||||
@brief Generate an adsb2dd API endpoint for each radar.
|
||||
@see adsb2dd at https://github.com/30hours/adsb2dd.
|
||||
@param radar (str): Radar to run adsb2dd.
|
||||
@param radar_data (dict): Radar data for this radar.
|
||||
@return str: adsb2dd API for radar.
|
||||
"""
|
||||
|
||||
rx_lat = radar_data['config']['location']['rx']['latitude']
|
||||
rx_lon = radar_data['config']['location']['rx']['longitude']
|
||||
rx_alt = radar_data['config']['location']['rx']['altitude']
|
||||
tx_lat = radar_data['config']['location']['tx']['latitude']
|
||||
tx_lon = radar_data['config']['location']['tx']['longitude']
|
||||
tx_alt = radar_data['config']['location']['tx']['altitude']
|
||||
fc = radar_data['config']['capture']['fc']
|
||||
adsb = radar_data['config']['truth']['adsb']['ip']
|
||||
|
||||
api_url = "http://adsb2dd.30hours.dev/api/dd"
|
||||
|
||||
api_query = (
|
||||
api_url +
|
||||
"?rx=" + str(rx_lat) + "," +
|
||||
str(rx_lon) + "," +
|
||||
str(rx_alt) +
|
||||
"&tx=" + str(tx_lat) + "," +
|
||||
str(tx_lon) + "," +
|
||||
str(tx_alt) +
|
||||
"&fc=" + str(fc) +
|
||||
"&server=" + "http://" + str(adsb)
|
||||
)
|
||||
|
||||
return api_query
|
||||
|
|
|
@ -81,6 +81,14 @@ async def event():
|
|||
# main processing
|
||||
for item in api_event:
|
||||
|
||||
# extract dict for item
|
||||
#radar_dict_item = {key: None for key in item["server"]}
|
||||
radar_dict_item = {
|
||||
key: radar_dict[key]
|
||||
for key in item["server"]
|
||||
if key in radar_dict
|
||||
}
|
||||
|
||||
# associator selection
|
||||
if item["associator"] == "adsb-associator":
|
||||
associator = adsbAssociator
|
||||
|
@ -95,7 +103,7 @@ async def event():
|
|||
print("Error: Coord reg invalid.")
|
||||
return
|
||||
|
||||
print(radar, flush=True)
|
||||
associated_dets = associator.process(item["server"], radar_dict_item)
|
||||
|
||||
# delete old API requests
|
||||
api_event = [
|
||||
|
|
Loading…
Reference in a new issue