From a22942cd6284bd394961ebcfd64a22d4769b17d8 Mon Sep 17 00:00:00 2001 From: TedSjoblom <36690474+TedSjoblom@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:23:05 +0200 Subject: [PATCH] digitraffic added --- README.md | 4 ++++ bin/main.py | 63 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2006947..a900710 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,11 @@ python3 bin/main.py --log-level 10 -r rise -e ted --publish log --subscribe digi ``` +## Record +```bash +sudo docker run --rm --network host --name mcap-logger --volume ~/rec:/rec ghcr.io/rise-maritime/keelson:0.3.7-pre.51 "mcap-record --output_path rec -k rise/v0/ted/**" +``` diff --git a/bin/main.py b/bin/main.py index cdee386..9d00f5f 100644 --- a/bin/main.py +++ b/bin/main.py @@ -159,41 +159,80 @@ def sub_digitraffic_data(data): payload_target_description.data_source.source.append(DataSource.Source.AIS_PROVIDER) payload_target_description.timestamp.FromNanoseconds(time_now) - # MMSI - mmsi = str(data.key_expr).split("/")[-2] - payload_target.mmsi = int(mmsi) - payload_target_description.mmsi = int(mmsi) + if str(data.key_expr).split("/")[-1] == "location": + logging.debug(f"Location: {data_dict}") + + mmsi = str(data.key_expr).split("/")[-2] + payload_target.mmsi = int(mmsi) # NAVIGATIONN STATUS - status = data_dict.navStat + status = data_dict["navStat"] payload_target.navigation_status = set_navigation_status_enum(status) # ROT, SOG, COG, HDG - payload_target.rate_of_turn_degrees_per_minute = data_dict.rot - payload_target.speed_over_ground_knots = data_dict.sog - payload_target.course_over_ground_knots = data_dict.cog - payload_target.heading_degrees = data_dict.heading + payload_target.rate_of_turn_degrees_per_minute = data_dict["rot"] + payload_target.speed_over_ground_knots = data_dict["sog"] + payload_target.course_over_ground_knots = data_dict["cog"] + payload_target.heading_degrees = data_dict["heading"] if AIS_DB.get(str(mmsi)): - latitude_adj, longitude_adj = position_to_common_center_point(data_dict.lat, data_dict.lon, data_dict.heading, AIS_DB[str( + latitude_adj, longitude_adj = position_to_common_center_point(data_dict["lat"], data_dict["lon"], data_dict["heading"], AIS_DB[str( mmsi)]["to_bow"], AIS_DB[str(mmsi)]["to_stern"], AIS_DB[str(mmsi)]["to_port"], AIS_DB[str(mmsi)]["to_starboard"]) payload_target.latitude_degrees = latitude_adj payload_target.longitude_degrees = longitude_adj else: - payload_target.latitude_degrees = data_dict.lat - payload_target.longitude_degrees = data_dict.lon + payload_target.latitude_degrees = data_dict["lat"] + payload_target.longitude_degrees = data_dict["lon"] publish_message(payload_target, "target", mmsi, session, args, logging) elif str(data.key_expr).split("/")[-1] == "metadata": logging.debug(f"Metadata: {data_dict}") + # MMSI + mmsi = str(data.key_expr).split("/")[-2] + payload_target.mmsi = int(mmsi) + payload_target_description.mmsi = int(mmsi) + + payload_target_description.name = data_dict["name"] + payload_target_description.callsign = data_dict["callSign"] + payload_target_description.vessel_type = set_target_type_enum(data_dict["type"]) + payload_target_description.imo = data_dict["imo"] + + width = data_dict["refC"] + data_dict["refD"] + length = data_dict["refB"] + data_dict["refA"] + + new_to_bow = length / 2 + new_to_stern = -length / 2 + new_to_starboard = width / 2 + new_to_port = -width / 2 + + payload_target_description.to_bow_meters = new_to_bow + payload_target_description.to_stern_meters = new_to_stern + payload_target_description.to_starboard_meters = new_to_starboard + payload_target_description.to_port_meters = new_to_port + + payload_target_description.destination = data_dict["destination"] + payload_target_description.draft_meters = data_dict["draught"] + payload_target_description.estimated_time_of_arrival = str(data_dict["eta"]) + + # for AIS position correction + AIS_DB[str(mmsi)] = { + "to_bow": data_dict["refA"], + "to_stern": data_dict["refB"], + "to_starboard": data_dict["refD"], + "to_port": data_dict["refC"] + } + publish_message(payload_target_description, "target_description", + mmsi, session, args, logging) + + else: logging.warning(f"Unknown data: {data_dict}")