Skip to content

Commit

Permalink
bug fix key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fredclausen committed Jan 3, 2025
1 parent bffcfb8 commit 7de3cb9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
10 changes: 5 additions & 5 deletions rootfs/webapp/acarshub.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def generateClientMessage(message_type, json_message):
# add in the message_type key because the parent object didn't have it
client_message.update({"message_type": message_type})

# enrich message using udpate_keys
# enrich message using update_keys
acarshub_helpers.update_keys(client_message)

return client_message
Expand Down Expand Up @@ -453,8 +453,8 @@ def init_listeners(special_message=""):
global thread_database
global thread_scheduler
global thread_html_generator
global thread_adsb_listner
global thread_adsb
# global thread_adsb_listner
# global thread_adsb
# REMOVE AFTER AIRFRAMES IS UPDATED ####
global vdlm2_feeder_thread
global acars_feeder_thread
Expand Down Expand Up @@ -697,8 +697,8 @@ def main_connect():

# need visibility of the global thread object
global thread_html_generator
global thread_adsb
global thread_adsb_stop_event
# global thread_adsb
# global thread_adsb_stop_event

recent_options = {"loading": True, "done_loading": False}

Expand Down
29 changes: 18 additions & 11 deletions rootfs/webapp/acarshub_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ def update_keys(json_message):
json_message["libacars"] = libacars_formatted(json_message["libacars"])

if has_specified_key(json_message, "icao"):
try:
json_message["icao_hex"] = format(int(json_message["icao"]), "X")
except Exception as e:
acarshub_logging.log(
f"Unable to convert icao to hex: {json_message['icao']}",
"update_keys",
LOG_LEVEL["WARNING"],
)
acarshub_logging.acars_traceback(e, "update_keys")
json_message["icao_hex"] = try_format_as_int(json_message["icao"], "icao")

if has_specified_key(json_message, "flight") and has_specified_key(
json_message, "icao_hex"
Expand All @@ -129,7 +121,7 @@ def update_keys(json_message):
json_message["icao_url"] = flight_finder(hex_code=json_message["icao_hex"])

if has_specified_key(json_message, "toaddr"):
json_message["toaddr_hex"] = format(int(json_message["toaddr"]), "X")
json_message["toaddr_hex"] = try_format_as_int(json_message["toaddr"], "toaddr")

toaddr_icao, toaddr_name = acarshub_database.lookup_groundstation(
json_message["toaddr_hex"]
Expand All @@ -139,7 +131,9 @@ def update_keys(json_message):
json_message["toaddr_decoded"] = f"{toaddr_name} ({toaddr_icao})"

if has_specified_key(json_message, "fromaddr"):
json_message["fromaddr_hex"] = format(int(json_message["fromaddr"]), "X")
json_message["fromaddr_hex"] = try_format_as_int(
json_message["fromaddr"], "fromaddr"
)

fromaddr_icao, fromaddr_name = acarshub_database.lookup_groundstation(
json_message["fromaddr_hex"]
Expand All @@ -157,6 +151,19 @@ def update_keys(json_message):
json_message["label_type"] = "Unknown Message Label"


def try_format_as_int(value, key, as_type="X"):
try:
return format(int(value), as_type)
except Exception as e:
acarshub_logging.log(
f"Unable to convert {key}:{value} to hex. Using 0",
"try_format_as_int",
LOG_LEVEL["WARNING"],
)
acarshub_logging.acars_traceback(e, "try_format_as_int")
return "0"


def flight_finder(callsign=None, hex_code=None, url=True):
global ADSB_URL

Expand Down
2 changes: 1 addition & 1 deletion version-nextgen
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.7.0
v3.7.1

0 comments on commit 7de3cb9

Please sign in to comment.