Skip to content

Commit

Permalink
Merge pull request #56 from cubesys-GmbH/fix_cmake_denm_subcausecodes
Browse files Browse the repository at this point in the history
codegen-py: fix missing DENM msg files in CMakeLists.txt
  • Loading branch information
jpbusch authored Jan 8, 2025
2 parents b52620a + 61f1356 commit 7ec3e1c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
24 changes: 24 additions & 0 deletions etsi_its_msgs/etsi_its_denm_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,46 @@ if(${ROS_VERSION} EQUAL 2)
find_package(rosidl_default_generators REQUIRED)

set(msg_files
"msg/AccidentSubCauseCode.msg"
"msg/ActionID.msg"
"msg/AdverseWeatherConditionAdhesionSubCauseCode.msg"
"msg/AdverseWeatherConditionExtremeWeatherConditionSubCauseCode.msg"
"msg/AdverseWeatherConditionPrecipitationSubCauseCode.msg"
"msg/AdverseWeatherConditionVisibilitySubCauseCode.msg"
"msg/AlacarteContainer.msg"
"msg/Altitude.msg"
"msg/AltitudeConfidence.msg"
"msg/AltitudeValue.msg"
"msg/CauseCode.msg"
"msg/CauseCodeType.msg"
"msg/ClosedLanes.msg"
"msg/CollisionRiskSubCauseCode.msg"
"msg/DENM.msg"
"msg/DangerousEndOfQueueSubCauseCode.msg"
"msg/DangerousGoodsBasic.msg"
"msg/DangerousGoodsExtended.msg"
"msg/DangerousSituationSubCauseCode.msg"
"msg/DecentralizedEnvironmentalNotificationMessage.msg"
"msg/DeltaAltitude.msg"
"msg/DeltaLatitude.msg"
"msg/DeltaLongitude.msg"
"msg/DeltaReferencePosition.msg"
"msg/DrivingLaneStatus.msg"
"msg/EmergencyVehicleApproachingSubCauseCode.msg"
"msg/EnergyStorageType.msg"
"msg/EventHistory.msg"
"msg/EventPoint.msg"
"msg/HardShoulderStatus.msg"
"msg/HazardousLocationAnimalOnTheRoadSubCauseCode.msg"
"msg/HazardousLocationDangerousCurveSubCauseCode.msg"
"msg/HazardousLocationObstacleOnTheRoadSubCauseCode.msg"
"msg/HazardousLocationSurfaceConditionSubCauseCode.msg"
"msg/Heading.msg"
"msg/HeadingConfidence.msg"
"msg/HeadingValue.msg"
"msg/HeightLonCarr.msg"
"msg/HumanPresenceOnTheRoadSubCauseCode.msg"
"msg/HumanProblemSubCauseCode.msg"
"msg/ImpactReductionContainer.msg"
"msg/InformationQuality.msg"
"msg/ItineraryPath.msg"
Expand All @@ -59,17 +74,22 @@ if(${ROS_VERSION} EQUAL 2)
"msg/PositionOfOccupants.msg"
"msg/PositionOfPillars.msg"
"msg/PositioningSolutionType.msg"
"msg/PostCrashSubCauseCode.msg"
"msg/ReferenceDenms.msg"
"msg/ReferencePosition.msg"
"msg/RelevanceDistance.msg"
"msg/RelevanceTrafficDirection.msg"
"msg/RequestResponseIndication.msg"
"msg/RescueAndRecoveryWorkInProgressSubCauseCode.msg"
"msg/RestrictedTypes.msg"
"msg/RoadType.msg"
"msg/RoadWorksContainerExtended.msg"
"msg/RoadworksSubCauseCode.msg"
"msg/SemiAxisLength.msg"
"msg/SequenceNumber.msg"
"msg/SignalViolationSubCauseCode.msg"
"msg/SituationContainer.msg"
"msg/SlowVehicleSubCauseCode.msg"
"msg/Speed.msg"
"msg/SpeedConfidence.msg"
"msg/SpeedLimit.msg"
Expand All @@ -78,20 +98,24 @@ if(${ROS_VERSION} EQUAL 2)
"msg/StationType.msg"
"msg/StationarySince.msg"
"msg/StationaryVehicleContainer.msg"
"msg/StationaryVehicleSubCauseCode.msg"
"msg/SubCauseCodeType.msg"
"msg/Temperature.msg"
"msg/Termination.msg"
"msg/TimestampIts.msg"
"msg/Traces.msg"
"msg/TrafficConditionSubCauseCode.msg"
"msg/TrafficRule.msg"
"msg/TransmissionInterval.msg"
"msg/TurningRadius.msg"
"msg/VDS.msg"
"msg/ValidityDuration.msg"
"msg/VehicleBreakdownSubCauseCode.msg"
"msg/VehicleIdentification.msg"
"msg/VehicleMass.msg"
"msg/WMInumber.msg"
"msg/WheelBaseVehicle.msg"
"msg/WrongWayDrivingSubCauseCode.msg"
)

rosidl_generate_interfaces(${PROJECT_NAME}
Expand Down
23 changes: 17 additions & 6 deletions utils/codegen/codegen-py/asn1ToConversionHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,22 @@ def findDependenciesOfConversionHeaders(parent_file_path: str, type: str, file_l
new_file_list.append(msg_type)
new_file_list = findDependenciesOfConversionHeaders(f"{os.path.dirname(parent_file_path)}/{msg_type}.h", type, new_file_list)

# make sure there are no duplicates and sort alphabetically
new_file_list = sorted(list(set(new_file_list)))

return new_file_list

def additionalMessageTypes(path: str, msg_type: str) -> List[str]:
additional = []

for f in glob.glob(os.path.join(path, "*.h")):
msg_filename = os.path.splitext(os.path.basename(f))[0]
if msg_type == "DENM" and msg_filename.endswith("SubCauseCode"):
additional.append(msg_filename)

return additional

def sortHeaderFiles(files: List[str]) -> List[str]:
# make sure there are no duplicates and sort alphabetically
return sorted(list(set(files)))

def main():

args = parseCli()
Expand Down Expand Up @@ -206,11 +217,11 @@ def main():
elif args.type == "vam_ts":
msg_type = "VAM"
header_files = findDependenciesOfConversionHeaders(os.path.join(args.output_dir, f"convert{msg_type}.h"), args.type, [f"convert{msg_type}"])
header_files += additionalMessageTypes(args.output_dir, msg_type)
header_files = sortHeaderFiles(header_files)

for f in glob.glob(os.path.join(args.output_dir, "*.h")):
header_filename = os.path.splitext(os.path.basename(f))[0]
if msg_type == "DENM" and header_filename.endswith("SubCauseCode"):
# keep all SubCauseCode variants for DENM
continue
if header_filename not in header_files:
os.remove(f)

Expand Down
25 changes: 18 additions & 7 deletions utils/codegen/codegen-py/asn1ToRosMsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,22 @@ def findDependenciesOfRosMessageType(parent_file_path: str, file_list: List[str]
new_file_list.append(msg_type)
new_file_list = findDependenciesOfRosMessageType(f"{os.path.dirname(parent_file_path)}/{msg_type}.msg", new_file_list)

# make sure there are no duplicates and sort alphabetically
new_file_list = sorted(list(set(new_file_list)))

return new_file_list

def additionalMessageTypes(path: str, msg_type: str) -> List[str]:
additional = []

for f in glob.glob(os.path.join(path, "*.msg")):
msg_filename = os.path.splitext(os.path.basename(f))[0]
if msg_type == "DENM" and msg_filename.endswith("SubCauseCode"):
additional.append(msg_filename)

return additional

def sortMessageFiles(files: List[str]) -> List[str]:
# make sure there are no duplicates and sort alphabetically
return sorted(list(set(files)))

def generateCMakeLists(msg_files: list, file_path: str, type: str) -> None:
with open(file_path, "w") as f:
msg_file_lines = "\n".join([f" \"msg/{msg_file}.msg\"" for msg_file in msg_files])
Expand Down Expand Up @@ -233,15 +244,15 @@ def main():
elif args.type == "vam_ts":
msg_type = "VAM"
msg_files = findDependenciesOfRosMessageType(os.path.join(args.output_dir, f"{msg_type}.msg"), [msg_type])
msg_files += additionalMessageTypes(args.output_dir, msg_type)
msg_files = sortMessageFiles(msg_files)

print("Generating CMakeLists.txt ...")
generateCMakeLists(msg_files, os.path.join(args.output_dir, "../CMakeLists.txt"), args.type)
print("Removing files not required for top-level message type ...")
for f in glob.glob(os.path.join(args.output_dir, "*.msg")):
msg_filename = os.path.splitext(os.path.basename(f))[0]
if msg_type == "DENM" and msg_filename.endswith("SubCauseCode"):
# keep all SubCauseCode variants for DENM
continue
elif msg_filename not in msg_files:
if msg_filename not in msg_files:
os.remove(f)

print(f"Generated {len(msg_files)} ROS .msg files for {msg_type}")
Expand Down

0 comments on commit 7ec3e1c

Please sign in to comment.