Skip to content
Snippets Groups Projects
Commit bfcf5bd0 authored by Jiandong Chen's avatar Jiandong Chen
Browse files

add draft data process

parent 524e640c
No related branches found
No related tags found
No related merge requests found
__pycache__/
......@@ -10,12 +10,13 @@ find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Ais.msg"
# DEPENDENCIES geometry_msgs # Add packages that above messages depend on, in this case geometry_msgs for Sphere.msg
ament_python_install_package(${PROJECT_NAME})
install(PROGRAMS
scripts/demo.py
DESTINATION lib/${PROJECT_NAME}
)
......
import pyais
from aismsg.msg import AISObject, Radio
def get_AISobj(msg):
decode_msg = pyais.decode(msg)
aisobj = AISObject()
process_data(decode_msg, aisobj)
return aisobj
def get_object_data_from_type(msg_type, obj):
msg_type = int(msg_type)
match msg_type:
case 1 | 2 | 3:
return obj.position
case _:
return None
def process_data(decode_msg, obj):
msg_type = int(decode_msg.asdict()["msg_type"])
process_message_data(decode_msg, get_object_data_from_type(msg_type, obj))
def process_message_data(decode_msg, msg):
decode_msg_dict = decode_msg.asdict()
process_header(decode_msg_dict, msg.ais_header)
for key, value in decode_msg_dict.items():
process_field_data(key, value, msg)
if msg.ais_header.msg_type in (1, 2, 3, 4, 9, 11, 18):
process_radio(decode_msg, msg.radio)
def process_header(decode_msg_dict, header):
header.msg_type = decode_msg_dict["msg_type"]
header.repeat = decode_msg_dict["repeat"]
header.mmsi = str(decode_msg_dict["mmsi"])
def process_field_data(key, value, msg):
if key in ("msg_type", "repeat", "mmsi", "radio", "spare_1"):
return
match key:
case "status":
msg.status = int(value)
case "turn":
msg.turn = float(value)
case "speed":
msg.speed = value
case "accuracy":
msg.accuracy = value
case "lon":
msg.lon = value
case "lat":
msg.lat = value
case "course":
msg.course = value
case "heading":
msg.heading = value
case "second":
msg.second = value
case "maneuver":
msg.maneuver = int(value)
case "raim":
msg.raim = value
case _:
print(f"Unspecified data type \"{key}\" given! Ignore!!")
def process_radio(decode_msg, radio):
radio.status = decode_msg.asdict()["radio"]
radio.is_sotdma = decode_msg.is_sotdma
communication_state = decode_msg.get_communication_state()
for key, value in communication_state.items():
if value == None:
continue
process_radio_field_data(key, value, radio)
def process_radio_field_data(key, value, ros_radio_msg):
match key:
case "sync_state":
ros_radio_msg.sync_state = int(value)
case "received_stations":
ros_radio_msg.receive_station_num = value
case "slot_timeout":
ros_radio_msg.slot_timeout = value
case "slot_number":
ros_radio_msg.slot_num = value
case "slot_offset":
ros_radio_msg.slot_offset = value
case "utc_hour":
ros_radio_msg.utc_hour = value
case "utc_minute":
ros_radio_msg.utc_minute = value
case "keep_flag":
ros_radio_msg.keep_flag = value
case "slot_increment":
ros_radio_msg.slot_increment = value
case "num_slots":
ros_radio_msg.allocate_slot = value
case _:
print(f"Unspecified radio data type \"{key}\" given! Ignore!!")
uint8 msg_type 1
uint8 repeat 0
uint64 mmsi
......@@ -9,16 +9,10 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<depend>geometry_msgs</depend>
<depend>rclcpp</depend>
<depend>rclpy</depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
......
......@@ -11,4 +11,6 @@ for msg in TCPConnection(HOST, port=PORT):
print('*' * 80)
print(decoded_message)
# print('*' * 80)
# print(decoded_message.get_communication_state())
#!/usr/bin/env python3
import pyais
from ais2msg.util import get_AISobj
def demo():
# test type 1
testcase = [
"!AIVDM,1,1,,A,15RTgt0PAso;90TKcjM8h6g208CQ,0*4A", # type 1
"!AIVDM,1,1,,B,25Cjtd0Oj;Jp7ilG7=UkKBoB0<06,0*60", # type 2
"!AIVDM,1,1,,A,38Id705000rRVJhE7cl9n;160000,0*40", # type 3
]
for idx, data in enumerate(testcase):
print("*" * 30 + " type " + str(idx+1) + " " + "*" * 30)
msg = get_AISobj(data)
print(msg.position)
if __name__ == '__main__':
demo()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment