From 26b77a4b409a6b0243ea209827e4e3c1a2790b33 Mon Sep 17 00:00:00 2001 From: gomavlib-bot Date: Sat, 23 Sep 2023 09:35:56 +0000 Subject: [PATCH] (automatic) update dialects to rev https://github.com/mavlink/mavlink/tree/c313a2f36f26532f9c16393098318292ea044324 --- pkg/dialects/all/enum_mav_cmd.go | 252 ++++++++++++++++-- .../enum_accelcal_vehicle_pos.go | 49 ++-- .../enum_camera_feedback_flags.go | 46 ++-- .../ardupilotmega/enum_camera_status_types.go | 48 ++-- .../ardupilotmega/enum_copter_mode.go | 66 +++-- .../ardupilotmega/enum_deepstall_stage.go | 48 ++-- .../ardupilotmega/enum_device_op_bustype.go | 43 ++- .../ardupilotmega/enum_ekf_status_flags.go | 32 ++- .../ardupilotmega/enum_gimbal_axis.go | 44 ++- .../enum_gimbal_axis_calibration_required.go | 44 ++- .../enum_gimbal_axis_calibration_status.go | 44 ++- .../ardupilotmega/enum_gopro_burst_rate.go | 50 ++-- .../ardupilotmega/enum_gopro_capture_mode.go | 49 ++-- .../ardupilotmega/enum_gopro_charging.go | 43 ++- .../ardupilotmega/enum_gopro_command.go | 58 ++-- .../ardupilotmega/enum_gopro_field_of_view.go | 44 ++- .../ardupilotmega/enum_gopro_frame_rate.go | 55 ++-- .../enum_gopro_heartbeat_flags.go | 22 +- .../enum_gopro_heartbeat_status.go | 45 ++-- .../ardupilotmega/enum_gopro_model.go | 46 ++-- .../enum_gopro_photo_resolution.go | 46 ++-- .../enum_gopro_protune_colour.go | 43 ++- .../enum_gopro_protune_exposure.go | 62 +++-- .../ardupilotmega/enum_gopro_protune_gain.go | 46 ++-- .../enum_gopro_protune_sharpness.go | 44 ++- .../enum_gopro_protune_white_balance.go | 46 ++-- .../enum_gopro_request_status.go | 43 ++- .../ardupilotmega/enum_gopro_resolution.go | 55 ++-- .../enum_gopro_video_settings_flags.go | 22 +- .../ardupilotmega/enum_heading_type.go | 43 ++- .../ardupilotmega/enum_led_control_pattern.go | 44 ++- .../ardupilotmega/enum_limit_module.go | 24 +- .../ardupilotmega/enum_limits_state.go | 47 ++-- pkg/dialects/ardupilotmega/enum_mav_cmd.go | 232 ++++++++++++++-- ...um_mav_cmd_do_aux_function_switch_level.go | 44 ++- .../ardupilotmega/enum_mav_mode_gimbal.go | 48 ++-- ...enum_mav_remote_log_data_block_commands.go | 43 ++- ...enum_mav_remote_log_data_block_statuses.go | 43 ++- .../enum_osd_param_config_error.go | 45 ++-- .../enum_osd_param_config_type.go | 50 ++-- .../ardupilotmega/enum_pid_tuning_axis.go | 47 ++-- pkg/dialects/ardupilotmega/enum_plane_mode.go | 65 +++-- .../ardupilotmega/enum_rally_flags.go | 23 +- pkg/dialects/ardupilotmega/enum_rover_mode.go | 53 ++-- .../ardupilotmega/enum_scripting_cmd.go | 45 ++-- pkg/dialects/ardupilotmega/enum_speed_type.go | 43 ++- pkg/dialects/ardupilotmega/enum_sub_mode.go | 50 ++-- .../ardupilotmega/enum_tracker_mode.go | 47 ++-- pkg/dialects/asluav/enum_gsm_link_type.go | 46 ++-- pkg/dialects/asluav/enum_gsm_modem_type.go | 43 ++- pkg/dialects/asluav/enum_mav_cmd.go | 202 ++++++++++++-- .../enum_avss_horsefly_operation_mode.go | 46 ++-- .../avssuas/enum_avss_m300_operation_mode.go | 55 ++-- .../enum_mav_avss_command_failure_reason.go | 44 ++- pkg/dialects/avssuas/enum_mav_cmd.go | 207 ++++++++++++-- .../common/enum_actuator_configuration.go | 47 ++-- .../common/enum_actuator_output_function.go | 74 +++-- .../common/enum_adsb_altitude_type.go | 43 ++- pkg/dialects/common/enum_adsb_emitter_type.go | 61 +++-- pkg/dialects/common/enum_adsb_flags.go | 31 ++- pkg/dialects/common/enum_ais_flags.go | 34 ++- pkg/dialects/common/enum_ais_nav_status.go | 57 ++-- pkg/dialects/common/enum_ais_type.go | 141 ++++++++-- .../common/enum_attitude_target_typemask.go | 27 +- pkg/dialects/common/enum_autotune_axis.go | 25 +- pkg/dialects/common/enum_camera_cap_flags.go | 33 ++- pkg/dialects/common/enum_camera_mode.go | 44 ++- .../common/enum_camera_tracking_mode.go | 44 ++- .../enum_camera_tracking_status_flags.go | 44 ++- .../enum_camera_tracking_target_data.go | 25 +- pkg/dialects/common/enum_camera_zoom_type.go | 46 ++-- pkg/dialects/common/enum_can_filter_op.go | 44 ++- .../common/enum_cellular_config_response.go | 46 ++-- .../enum_cellular_network_failed_reason.go | 45 ++-- .../enum_cellular_network_radio_type.go | 46 ++-- .../common/enum_cellular_status_flag.go | 54 ++-- .../common/enum_comp_metadata_type.go | 47 ++-- .../common/enum_esc_connection_type.go | 47 ++-- pkg/dialects/common/enum_esc_failure_flags.go | 29 +- .../common/enum_estimator_status_flags.go | 33 ++- pkg/dialects/common/enum_failure_type.go | 49 ++-- pkg/dialects/common/enum_failure_unit.go | 56 ++-- pkg/dialects/common/enum_fence_action.go | 49 ++-- pkg/dialects/common/enum_fence_breach.go | 45 ++-- pkg/dialects/common/enum_fence_mitigate.go | 44 ++- .../common/enum_firmware_version_type.go | 46 ++-- .../common/enum_gimbal_device_cap_flags.go | 35 ++- .../common/enum_gimbal_device_error_flags.go | 31 ++- .../common/enum_gimbal_device_flags.go | 31 ++- .../common/enum_gimbal_manager_cap_flags.go | 37 ++- .../common/enum_gimbal_manager_flags.go | 31 ++- pkg/dialects/common/enum_gps_fix_type.go | 50 ++-- .../common/enum_gps_input_ignore_flags.go | 29 +- pkg/dialects/common/enum_gripper_actions.go | 43 ++- .../common/enum_highres_imu_updated_flags.go | 36 ++- .../common/enum_hil_sensor_updated_flags.go | 36 ++- pkg/dialects/common/enum_hl_failure_flag.go | 35 ++- .../common/enum_landing_target_type.go | 45 ++-- pkg/dialects/common/enum_mag_cal_status.go | 49 ++-- .../common/enum_mav_arm_auth_denied_reason.go | 47 ++-- .../common/enum_mav_battery_charge_state.go | 49 ++-- pkg/dialects/common/enum_mav_battery_fault.go | 30 ++- .../common/enum_mav_battery_function.go | 46 ++-- pkg/dialects/common/enum_mav_battery_mode.go | 44 ++- pkg/dialects/common/enum_mav_battery_type.go | 46 ++-- pkg/dialects/common/enum_mav_cmd.go | 200 ++++++++++++-- .../common/enum_mav_collision_action.go | 48 ++-- pkg/dialects/common/enum_mav_collision_src.go | 43 ++- .../common/enum_mav_collision_threat_level.go | 44 ++- pkg/dialects/common/enum_mav_data_stream.go | 50 ++-- .../common/enum_mav_distance_sensor.go | 46 ++-- .../common/enum_mav_do_reposition_flags.go | 22 +- .../common/enum_mav_estimator_type.go | 50 ++-- .../enum_mav_event_current_sequence_flags.go | 42 ++- .../common/enum_mav_event_error_reason.go | 42 ++- pkg/dialects/common/enum_mav_frame.go | 63 +++-- pkg/dialects/common/enum_mav_ftp_err.go | 52 ++-- pkg/dialects/common/enum_mav_ftp_opcode.go | 59 ++-- .../common/enum_mav_generator_status_flag.go | 44 ++- pkg/dialects/common/enum_mav_goto.go | 45 ++-- pkg/dialects/common/enum_mav_landed_state.go | 46 ++-- .../common/enum_mav_mission_result.go | 57 ++-- pkg/dialects/common/enum_mav_mission_type.go | 45 ++-- pkg/dialects/common/enum_mav_mode.go | 52 ++-- pkg/dialects/common/enum_mav_mount_mode.go | 48 ++-- .../common/enum_mav_odid_arm_status.go | 43 ++- .../common/enum_mav_odid_auth_type.go | 47 ++-- .../common/enum_mav_odid_category_eu.go | 45 ++-- pkg/dialects/common/enum_mav_odid_class_eu.go | 49 ++-- .../enum_mav_odid_classification_type.go | 43 ++- .../common/enum_mav_odid_desc_type.go | 44 ++- .../common/enum_mav_odid_height_ref.go | 43 ++- pkg/dialects/common/enum_mav_odid_hor_acc.go | 54 ++-- pkg/dialects/common/enum_mav_odid_id_type.go | 46 ++-- .../common/enum_mav_odid_operator_id_type.go | 42 ++- .../enum_mav_odid_operator_location_type.go | 44 ++- .../common/enum_mav_odid_speed_acc.go | 46 ++-- pkg/dialects/common/enum_mav_odid_status.go | 46 ++-- pkg/dialects/common/enum_mav_odid_time_acc.go | 57 ++-- pkg/dialects/common/enum_mav_odid_ua_type.go | 57 ++-- pkg/dialects/common/enum_mav_odid_ver_acc.go | 48 ++-- .../common/enum_mav_param_ext_type.go | 52 ++-- pkg/dialects/common/enum_mav_param_type.go | 51 ++-- pkg/dialects/common/enum_mav_power_status.go | 27 +- .../common/enum_mav_protocol_capability.go | 39 ++- pkg/dialects/common/enum_mav_result.go | 51 ++-- pkg/dialects/common/enum_mav_roi.go | 46 ++-- .../common/enum_mav_sensor_orientation.go | 83 ++++-- pkg/dialects/common/enum_mav_severity.go | 49 ++-- .../common/enum_mav_sys_status_sensor.go | 53 +++- .../enum_mav_sys_status_sensor_extended.go | 22 +- .../common/enum_mav_tunnel_payload_type.go | 52 ++-- pkg/dialects/common/enum_mav_vtol_state.go | 46 ++-- .../common/enum_mav_winch_status_flag.go | 35 ++- .../common/enum_mavlink_data_stream_type.go | 47 ++-- pkg/dialects/common/enum_mission_state.go | 47 ++-- pkg/dialects/common/enum_motor_test_order.go | 44 ++- .../common/enum_motor_test_throttle_type.go | 45 ++-- .../common/enum_nav_vtol_land_options.go | 44 ++- .../common/enum_orbit_yaw_behaviour.go | 46 ++-- pkg/dialects/common/enum_parachute_action.go | 44 ++- pkg/dialects/common/enum_param_ack.go | 45 ++-- .../common/enum_position_target_typemask.go | 33 ++- .../common/enum_precision_land_mode.go | 44 ++- .../enum_preflight_storage_mission_action.go | 44 ++- ...enum_preflight_storage_parameter_action.go | 46 ++-- pkg/dialects/common/enum_rc_type.go | 43 ++- .../enum_rtk_baseline_coordinate_system.go | 43 ++- .../common/enum_serial_control_dev.go | 56 ++-- .../common/enum_serial_control_flag.go | 26 +- pkg/dialects/common/enum_set_focus_type.go | 48 ++-- pkg/dialects/common/enum_storage_status.go | 45 ++-- pkg/dialects/common/enum_storage_type.go | 50 ++-- .../common/enum_storage_usage_flag.go | 45 ++-- pkg/dialects/common/enum_tune_format.go | 43 ++- .../common/enum_uavcan_node_health.go | 45 ++-- pkg/dialects/common/enum_uavcan_node_mode.go | 46 ++-- .../common/enum_utm_data_avail_flags.go | 29 +- pkg/dialects/common/enum_utm_flight_state.go | 46 ++-- .../common/enum_video_stream_status_flags.go | 23 +- pkg/dialects/common/enum_video_stream_type.go | 45 ++-- .../common/enum_vtol_transition_heading.go | 46 ++-- .../common/enum_wifi_config_ap_mode.go | 45 ++-- .../common/enum_wifi_config_ap_response.go | 47 ++-- pkg/dialects/common/enum_winch_actions.go | 51 ++-- .../enum_airlink_auth_response_type.go | 43 ++- .../development/enum_airspeed_sensor_flags.go | 23 +- .../enum_mav_battery_status_flags.go | 41 ++- pkg/dialects/development/enum_mav_cmd.go | 208 +++++++++++++-- .../development/enum_mav_mode_property.go | 23 +- .../development/enum_mav_standard_mode.go | 51 ++-- .../enum_param_transaction_action.go | 44 ++- .../enum_param_transaction_transport.go | 43 ++- ...target_absolute_sensor_capability_flags.go | 26 +- .../development/enum_target_obs_frame.go | 45 ++-- .../development/enum_wifi_network_security.go | 47 ++-- .../icarous/enum_icarous_fms_state.go | 47 ++-- .../icarous/enum_icarous_track_band_types.go | 44 ++- pkg/dialects/matrixpilot/enum_mav_cmd.go | 201 ++++++++++++-- .../enum_mav_preflight_storage_action.go | 48 ++-- pkg/dialects/storm32/enum_mav_cmd.go | 235 ++++++++++++++-- pkg/dialects/storm32/enum_mav_qshot_mode.go | 51 ++-- .../enum_mav_storm32_camera_prearm_flags.go | 22 +- ...um_mav_storm32_gimbal_manager_cap_flags.go | 22 +- .../enum_mav_storm32_gimbal_manager_client.go | 50 ++-- .../enum_mav_storm32_gimbal_manager_flags.go | 33 ++- ...enum_mav_storm32_gimbal_manager_profile.go | 47 ++-- .../enum_mav_storm32_gimbal_prearm_flags.go | 34 ++- .../enum_mav_storm32_tunnel_payload_type.go | 47 ++-- .../storm32/enum_radio_link_stats_flags.go | 22 +- .../storm32/enum_radio_rc_channels_flags.go | 23 +- .../ualberta/enum_ualberta_autopilot_mode.go | 46 ++-- .../ualberta/enum_ualberta_nav_mode.go | 45 ++-- .../ualberta/enum_ualberta_pilot_mode.go | 44 ++- .../enum_uavionix_adsb_emergency_status.go | 49 ++-- ...num_uavionix_adsb_out_cfg_aircraft_size.go | 57 ++-- ...um_uavionix_adsb_out_cfg_gps_offset_lat.go | 49 ++-- ...um_uavionix_adsb_out_cfg_gps_offset_lon.go | 43 ++- .../enum_uavionix_adsb_out_dynamic_gps_fix.go | 47 ++-- .../enum_uavionix_adsb_out_dynamic_state.go | 26 +- .../enum_uavionix_adsb_out_rf_select.go | 24 +- .../uavionix/enum_uavionix_adsb_rf_health.go | 25 +- 222 files changed, 6440 insertions(+), 4764 deletions(-) diff --git a/pkg/dialects/all/enum_mav_cmd.go b/pkg/dialects/all/enum_mav_cmd.go index 90d2996a2..97e7c128e 100644 --- a/pkg/dialects/all/enum_mav_cmd.go +++ b/pkg/dialects/all/enum_mav_cmd.go @@ -4,7 +4,7 @@ package all import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -718,40 +718,244 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_PRS_SHUTDOWN: "MAV_CMD_PRS_SHUTDOWN", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_DO_SET_RESUME_REPEAT_DIST": MAV_CMD_DO_SET_RESUME_REPEAT_DIST, + "MAV_CMD_DO_SPRAYER": MAV_CMD_DO_SPRAYER, + "MAV_CMD_DO_SEND_SCRIPT_MESSAGE": MAV_CMD_DO_SEND_SCRIPT_MESSAGE, + "MAV_CMD_DO_AUX_FUNCTION": MAV_CMD_DO_AUX_FUNCTION, + "MAV_CMD_NAV_ALTITUDE_WAIT": MAV_CMD_NAV_ALTITUDE_WAIT, + "MAV_CMD_POWER_OFF_INITIATED": MAV_CMD_POWER_OFF_INITIATED, + "MAV_CMD_SOLO_BTN_FLY_CLICK": MAV_CMD_SOLO_BTN_FLY_CLICK, + "MAV_CMD_SOLO_BTN_FLY_HOLD": MAV_CMD_SOLO_BTN_FLY_HOLD, + "MAV_CMD_SOLO_BTN_PAUSE_CLICK": MAV_CMD_SOLO_BTN_PAUSE_CLICK, + "MAV_CMD_FIXED_MAG_CAL": MAV_CMD_FIXED_MAG_CAL, + "MAV_CMD_FIXED_MAG_CAL_FIELD": MAV_CMD_FIXED_MAG_CAL_FIELD, + "MAV_CMD_SET_EKF_SOURCE_SET": MAV_CMD_SET_EKF_SOURCE_SET, + "MAV_CMD_DO_START_MAG_CAL": MAV_CMD_DO_START_MAG_CAL, + "MAV_CMD_DO_ACCEPT_MAG_CAL": MAV_CMD_DO_ACCEPT_MAG_CAL, + "MAV_CMD_DO_CANCEL_MAG_CAL": MAV_CMD_DO_CANCEL_MAG_CAL, + "MAV_CMD_ACCELCAL_VEHICLE_POS": MAV_CMD_ACCELCAL_VEHICLE_POS, + "MAV_CMD_DO_SEND_BANNER": MAV_CMD_DO_SEND_BANNER, + "MAV_CMD_SET_FACTORY_TEST_MODE": MAV_CMD_SET_FACTORY_TEST_MODE, + "MAV_CMD_GIMBAL_RESET": MAV_CMD_GIMBAL_RESET, + "MAV_CMD_GIMBAL_AXIS_CALIBRATION_STATUS": MAV_CMD_GIMBAL_AXIS_CALIBRATION_STATUS, + "MAV_CMD_GIMBAL_REQUEST_AXIS_CALIBRATION": MAV_CMD_GIMBAL_REQUEST_AXIS_CALIBRATION, + "MAV_CMD_GIMBAL_FULL_RESET": MAV_CMD_GIMBAL_FULL_RESET, + "MAV_CMD_FLASH_BOOTLOADER": MAV_CMD_FLASH_BOOTLOADER, + "MAV_CMD_BATTERY_RESET": MAV_CMD_BATTERY_RESET, + "MAV_CMD_DEBUG_TRAP": MAV_CMD_DEBUG_TRAP, + "MAV_CMD_SCRIPTING": MAV_CMD_SCRIPTING, + "MAV_CMD_NAV_SCRIPT_TIME": MAV_CMD_NAV_SCRIPT_TIME, + "MAV_CMD_NAV_ATTITUDE_TIME": MAV_CMD_NAV_ATTITUDE_TIME, + "MAV_CMD_GUIDED_CHANGE_SPEED": MAV_CMD_GUIDED_CHANGE_SPEED, + "MAV_CMD_GUIDED_CHANGE_ALTITUDE": MAV_CMD_GUIDED_CHANGE_ALTITUDE, + "MAV_CMD_GUIDED_CHANGE_HEADING": MAV_CMD_GUIDED_CHANGE_HEADING, + "MAV_CMD_EXTERNAL_POSITION_ESTIMATE": MAV_CMD_EXTERNAL_POSITION_ESTIMATE, + "MAV_CMD_RESET_MPPT": MAV_CMD_RESET_MPPT, + "MAV_CMD_PAYLOAD_CONTROL": MAV_CMD_PAYLOAD_CONTROL, + "MAV_CMD_DO_FIGURE_EIGHT": MAV_CMD_DO_FIGURE_EIGHT, + "MAV_CMD_PARAM_TRANSACTION": MAV_CMD_PARAM_TRANSACTION, + "MAV_CMD_SET_FENCE_BREACH_ACTION": MAV_CMD_SET_FENCE_BREACH_ACTION, + "MAV_CMD_DO_UPGRADE": MAV_CMD_DO_UPGRADE, + "MAV_CMD_GROUP_START": MAV_CMD_GROUP_START, + "MAV_CMD_GROUP_END": MAV_CMD_GROUP_END, + "MAV_CMD_DO_SET_STANDARD_MODE": MAV_CMD_DO_SET_STANDARD_MODE, + "MAV_CMD_SET_AT_S_PARAM": MAV_CMD_SET_AT_S_PARAM, + "MAV_CMD_STORM32_DO_GIMBAL_MANAGER_CONTROL_PITCHYAW": MAV_CMD_STORM32_DO_GIMBAL_MANAGER_CONTROL_PITCHYAW, + "MAV_CMD_STORM32_DO_GIMBAL_MANAGER_SETUP": MAV_CMD_STORM32_DO_GIMBAL_MANAGER_SETUP, + "MAV_CMD_QSHOT_DO_CONFIGURE": MAV_CMD_QSHOT_DO_CONFIGURE, + "MAV_CMD_PRS_SET_ARM": MAV_CMD_PRS_SET_ARM, + "MAV_CMD_PRS_GET_ARM": MAV_CMD_PRS_GET_ARM, + "MAV_CMD_PRS_GET_BATTERY": MAV_CMD_PRS_GET_BATTERY, + "MAV_CMD_PRS_GET_ERR": MAV_CMD_PRS_GET_ERR, + "MAV_CMD_PRS_SET_ARM_ALTI": MAV_CMD_PRS_SET_ARM_ALTI, + "MAV_CMD_PRS_GET_ARM_ALTI": MAV_CMD_PRS_GET_ARM_ALTI, + "MAV_CMD_PRS_SHUTDOWN": MAV_CMD_PRS_SHUTDOWN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_accelcal_vehicle_pos.go b/pkg/dialects/ardupilotmega/enum_accelcal_vehicle_pos.go index 2394b3e28..adc42d32f 100644 --- a/pkg/dialects/ardupilotmega/enum_accelcal_vehicle_pos.go +++ b/pkg/dialects/ardupilotmega/enum_accelcal_vehicle_pos.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type ACCELCAL_VEHICLE_POS uint32 @@ -31,40 +31,41 @@ var labels_ACCELCAL_VEHICLE_POS = map[ACCELCAL_VEHICLE_POS]string{ ACCELCAL_VEHICLE_POS_FAILED: "ACCELCAL_VEHICLE_POS_FAILED", } +var values_ACCELCAL_VEHICLE_POS = map[string]ACCELCAL_VEHICLE_POS{ + "ACCELCAL_VEHICLE_POS_LEVEL": ACCELCAL_VEHICLE_POS_LEVEL, + "ACCELCAL_VEHICLE_POS_LEFT": ACCELCAL_VEHICLE_POS_LEFT, + "ACCELCAL_VEHICLE_POS_RIGHT": ACCELCAL_VEHICLE_POS_RIGHT, + "ACCELCAL_VEHICLE_POS_NOSEDOWN": ACCELCAL_VEHICLE_POS_NOSEDOWN, + "ACCELCAL_VEHICLE_POS_NOSEUP": ACCELCAL_VEHICLE_POS_NOSEUP, + "ACCELCAL_VEHICLE_POS_BACK": ACCELCAL_VEHICLE_POS_BACK, + "ACCELCAL_VEHICLE_POS_SUCCESS": ACCELCAL_VEHICLE_POS_SUCCESS, + "ACCELCAL_VEHICLE_POS_FAILED": ACCELCAL_VEHICLE_POS_FAILED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ACCELCAL_VEHICLE_POS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ACCELCAL_VEHICLE_POS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ACCELCAL_VEHICLE_POS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ACCELCAL_VEHICLE_POS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ACCELCAL_VEHICLE_POS - for _, label := range labels { - found := false - for value, l := range labels_ACCELCAL_VEHICLE_POS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ACCELCAL_VEHICLE_POS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ACCELCAL_VEHICLE_POS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ACCELCAL_VEHICLE_POS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_camera_feedback_flags.go b/pkg/dialects/ardupilotmega/enum_camera_feedback_flags.go index 671fc78bf..b65a75724 100644 --- a/pkg/dialects/ardupilotmega/enum_camera_feedback_flags.go +++ b/pkg/dialects/ardupilotmega/enum_camera_feedback_flags.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type CAMERA_FEEDBACK_FLAGS uint32 @@ -30,40 +30,38 @@ var labels_CAMERA_FEEDBACK_FLAGS = map[CAMERA_FEEDBACK_FLAGS]string{ CAMERA_FEEDBACK_OPENLOOP: "CAMERA_FEEDBACK_OPENLOOP", } +var values_CAMERA_FEEDBACK_FLAGS = map[string]CAMERA_FEEDBACK_FLAGS{ + "CAMERA_FEEDBACK_PHOTO": CAMERA_FEEDBACK_PHOTO, + "CAMERA_FEEDBACK_VIDEO": CAMERA_FEEDBACK_VIDEO, + "CAMERA_FEEDBACK_BADEXPOSURE": CAMERA_FEEDBACK_BADEXPOSURE, + "CAMERA_FEEDBACK_CLOSEDLOOP": CAMERA_FEEDBACK_CLOSEDLOOP, + "CAMERA_FEEDBACK_OPENLOOP": CAMERA_FEEDBACK_OPENLOOP, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_FEEDBACK_FLAGS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAMERA_FEEDBACK_FLAGS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAMERA_FEEDBACK_FLAGS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAMERA_FEEDBACK_FLAGS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAMERA_FEEDBACK_FLAGS - for _, label := range labels { - found := false - for value, l := range labels_CAMERA_FEEDBACK_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAMERA_FEEDBACK_FLAGS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAMERA_FEEDBACK_FLAGS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAMERA_FEEDBACK_FLAGS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_camera_status_types.go b/pkg/dialects/ardupilotmega/enum_camera_status_types.go index 505525844..70a7f5619 100644 --- a/pkg/dialects/ardupilotmega/enum_camera_status_types.go +++ b/pkg/dialects/ardupilotmega/enum_camera_status_types.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type CAMERA_STATUS_TYPES uint32 @@ -36,40 +36,40 @@ var labels_CAMERA_STATUS_TYPES = map[CAMERA_STATUS_TYPES]string{ CAMERA_STATUS_TYPE_LOWSTOREV: "CAMERA_STATUS_TYPE_LOWSTOREV", } +var values_CAMERA_STATUS_TYPES = map[string]CAMERA_STATUS_TYPES{ + "CAMERA_STATUS_TYPE_HEARTBEAT": CAMERA_STATUS_TYPE_HEARTBEAT, + "CAMERA_STATUS_TYPE_TRIGGER": CAMERA_STATUS_TYPE_TRIGGER, + "CAMERA_STATUS_TYPE_DISCONNECT": CAMERA_STATUS_TYPE_DISCONNECT, + "CAMERA_STATUS_TYPE_ERROR": CAMERA_STATUS_TYPE_ERROR, + "CAMERA_STATUS_TYPE_LOWBATT": CAMERA_STATUS_TYPE_LOWBATT, + "CAMERA_STATUS_TYPE_LOWSTORE": CAMERA_STATUS_TYPE_LOWSTORE, + "CAMERA_STATUS_TYPE_LOWSTOREV": CAMERA_STATUS_TYPE_LOWSTOREV, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_STATUS_TYPES) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAMERA_STATUS_TYPES { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAMERA_STATUS_TYPES[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAMERA_STATUS_TYPES) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAMERA_STATUS_TYPES - for _, label := range labels { - found := false - for value, l := range labels_CAMERA_STATUS_TYPES { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAMERA_STATUS_TYPES[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAMERA_STATUS_TYPES) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAMERA_STATUS_TYPES[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_copter_mode.go b/pkg/dialects/ardupilotmega/enum_copter_mode.go index 11ceccc21..d899d2bf2 100644 --- a/pkg/dialects/ardupilotmega/enum_copter_mode.go +++ b/pkg/dialects/ardupilotmega/enum_copter_mode.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // A mapping of copter flight modes for custom_mode field of heartbeat. @@ -66,40 +66,58 @@ var labels_COPTER_MODE = map[COPTER_MODE]string{ COPTER_MODE_AUTO_RTL: "COPTER_MODE_AUTO_RTL", } +var values_COPTER_MODE = map[string]COPTER_MODE{ + "COPTER_MODE_STABILIZE": COPTER_MODE_STABILIZE, + "COPTER_MODE_ACRO": COPTER_MODE_ACRO, + "COPTER_MODE_ALT_HOLD": COPTER_MODE_ALT_HOLD, + "COPTER_MODE_AUTO": COPTER_MODE_AUTO, + "COPTER_MODE_GUIDED": COPTER_MODE_GUIDED, + "COPTER_MODE_LOITER": COPTER_MODE_LOITER, + "COPTER_MODE_RTL": COPTER_MODE_RTL, + "COPTER_MODE_CIRCLE": COPTER_MODE_CIRCLE, + "COPTER_MODE_LAND": COPTER_MODE_LAND, + "COPTER_MODE_DRIFT": COPTER_MODE_DRIFT, + "COPTER_MODE_SPORT": COPTER_MODE_SPORT, + "COPTER_MODE_FLIP": COPTER_MODE_FLIP, + "COPTER_MODE_AUTOTUNE": COPTER_MODE_AUTOTUNE, + "COPTER_MODE_POSHOLD": COPTER_MODE_POSHOLD, + "COPTER_MODE_BRAKE": COPTER_MODE_BRAKE, + "COPTER_MODE_THROW": COPTER_MODE_THROW, + "COPTER_MODE_AVOID_ADSB": COPTER_MODE_AVOID_ADSB, + "COPTER_MODE_GUIDED_NOGPS": COPTER_MODE_GUIDED_NOGPS, + "COPTER_MODE_SMART_RTL": COPTER_MODE_SMART_RTL, + "COPTER_MODE_FLOWHOLD": COPTER_MODE_FLOWHOLD, + "COPTER_MODE_FOLLOW": COPTER_MODE_FOLLOW, + "COPTER_MODE_ZIGZAG": COPTER_MODE_ZIGZAG, + "COPTER_MODE_SYSTEMID": COPTER_MODE_SYSTEMID, + "COPTER_MODE_AUTOROTATE": COPTER_MODE_AUTOROTATE, + "COPTER_MODE_AUTO_RTL": COPTER_MODE_AUTO_RTL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e COPTER_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_COPTER_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_COPTER_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *COPTER_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask COPTER_MODE - for _, label := range labels { - found := false - for value, l := range labels_COPTER_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_COPTER_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e COPTER_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_COPTER_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_deepstall_stage.go b/pkg/dialects/ardupilotmega/enum_deepstall_stage.go index 4d5bbcd2f..1207dcbcd 100644 --- a/pkg/dialects/ardupilotmega/enum_deepstall_stage.go +++ b/pkg/dialects/ardupilotmega/enum_deepstall_stage.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // Deepstall flight stage. @@ -37,40 +37,40 @@ var labels_DEEPSTALL_STAGE = map[DEEPSTALL_STAGE]string{ DEEPSTALL_STAGE_LAND: "DEEPSTALL_STAGE_LAND", } +var values_DEEPSTALL_STAGE = map[string]DEEPSTALL_STAGE{ + "DEEPSTALL_STAGE_FLY_TO_LANDING": DEEPSTALL_STAGE_FLY_TO_LANDING, + "DEEPSTALL_STAGE_ESTIMATE_WIND": DEEPSTALL_STAGE_ESTIMATE_WIND, + "DEEPSTALL_STAGE_WAIT_FOR_BREAKOUT": DEEPSTALL_STAGE_WAIT_FOR_BREAKOUT, + "DEEPSTALL_STAGE_FLY_TO_ARC": DEEPSTALL_STAGE_FLY_TO_ARC, + "DEEPSTALL_STAGE_ARC": DEEPSTALL_STAGE_ARC, + "DEEPSTALL_STAGE_APPROACH": DEEPSTALL_STAGE_APPROACH, + "DEEPSTALL_STAGE_LAND": DEEPSTALL_STAGE_LAND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e DEEPSTALL_STAGE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_DEEPSTALL_STAGE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_DEEPSTALL_STAGE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *DEEPSTALL_STAGE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask DEEPSTALL_STAGE - for _, label := range labels { - found := false - for value, l := range labels_DEEPSTALL_STAGE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_DEEPSTALL_STAGE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e DEEPSTALL_STAGE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_DEEPSTALL_STAGE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_device_op_bustype.go b/pkg/dialects/ardupilotmega/enum_device_op_bustype.go index 111422a7b..b83130373 100644 --- a/pkg/dialects/ardupilotmega/enum_device_op_bustype.go +++ b/pkg/dialects/ardupilotmega/enum_device_op_bustype.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // Bus types for device operations. @@ -22,40 +22,35 @@ var labels_DEVICE_OP_BUSTYPE = map[DEVICE_OP_BUSTYPE]string{ DEVICE_OP_BUSTYPE_SPI: "DEVICE_OP_BUSTYPE_SPI", } +var values_DEVICE_OP_BUSTYPE = map[string]DEVICE_OP_BUSTYPE{ + "DEVICE_OP_BUSTYPE_I2C": DEVICE_OP_BUSTYPE_I2C, + "DEVICE_OP_BUSTYPE_SPI": DEVICE_OP_BUSTYPE_SPI, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e DEVICE_OP_BUSTYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_DEVICE_OP_BUSTYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_DEVICE_OP_BUSTYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *DEVICE_OP_BUSTYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask DEVICE_OP_BUSTYPE - for _, label := range labels { - found := false - for value, l := range labels_DEVICE_OP_BUSTYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_DEVICE_OP_BUSTYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e DEVICE_OP_BUSTYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_DEVICE_OP_BUSTYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_ekf_status_flags.go b/pkg/dialects/ardupilotmega/enum_ekf_status_flags.go index 2fc048dc8..d1ac19937 100644 --- a/pkg/dialects/ardupilotmega/enum_ekf_status_flags.go +++ b/pkg/dialects/ardupilotmega/enum_ekf_status_flags.go @@ -49,12 +49,27 @@ var labels_EKF_STATUS_FLAGS = map[EKF_STATUS_FLAGS]string{ EKF_UNINITIALIZED: "EKF_UNINITIALIZED", } +var values_EKF_STATUS_FLAGS = map[string]EKF_STATUS_FLAGS{ + "EKF_ATTITUDE": EKF_ATTITUDE, + "EKF_VELOCITY_HORIZ": EKF_VELOCITY_HORIZ, + "EKF_VELOCITY_VERT": EKF_VELOCITY_VERT, + "EKF_POS_HORIZ_REL": EKF_POS_HORIZ_REL, + "EKF_POS_HORIZ_ABS": EKF_POS_HORIZ_ABS, + "EKF_POS_VERT_ABS": EKF_POS_VERT_ABS, + "EKF_POS_VERT_AGL": EKF_POS_VERT_AGL, + "EKF_CONST_POS_MODE": EKF_CONST_POS_MODE, + "EKF_PRED_POS_HORIZ_REL": EKF_PRED_POS_HORIZ_REL, + "EKF_PRED_POS_HORIZ_ABS": EKF_PRED_POS_HORIZ_ABS, + "EKF_UNINITIALIZED": EKF_UNINITIALIZED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e EKF_STATUS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_EKF_STATUS_FLAGS { + for i := 0; i < 11; i++ { + mask := EKF_STATUS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_EKF_STATUS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -65,19 +80,12 @@ func (e *EKF_STATUS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask EKF_STATUS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_EKF_STATUS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_EKF_STATUS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/ardupilotmega/enum_gimbal_axis.go b/pkg/dialects/ardupilotmega/enum_gimbal_axis.go index 81a57dd43..1b13071c2 100644 --- a/pkg/dialects/ardupilotmega/enum_gimbal_axis.go +++ b/pkg/dialects/ardupilotmega/enum_gimbal_axis.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GIMBAL_AXIS uint32 @@ -24,40 +24,36 @@ var labels_GIMBAL_AXIS = map[GIMBAL_AXIS]string{ GIMBAL_AXIS_ROLL: "GIMBAL_AXIS_ROLL", } +var values_GIMBAL_AXIS = map[string]GIMBAL_AXIS{ + "GIMBAL_AXIS_YAW": GIMBAL_AXIS_YAW, + "GIMBAL_AXIS_PITCH": GIMBAL_AXIS_PITCH, + "GIMBAL_AXIS_ROLL": GIMBAL_AXIS_ROLL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_AXIS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GIMBAL_AXIS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GIMBAL_AXIS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GIMBAL_AXIS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GIMBAL_AXIS - for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_AXIS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GIMBAL_AXIS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GIMBAL_AXIS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GIMBAL_AXIS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_required.go b/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_required.go index 24e1de212..cc5d878cd 100644 --- a/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_required.go +++ b/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_required.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GIMBAL_AXIS_CALIBRATION_REQUIRED uint32 @@ -24,40 +24,36 @@ var labels_GIMBAL_AXIS_CALIBRATION_REQUIRED = map[GIMBAL_AXIS_CALIBRATION_REQUIR GIMBAL_AXIS_CALIBRATION_REQUIRED_FALSE: "GIMBAL_AXIS_CALIBRATION_REQUIRED_FALSE", } +var values_GIMBAL_AXIS_CALIBRATION_REQUIRED = map[string]GIMBAL_AXIS_CALIBRATION_REQUIRED{ + "GIMBAL_AXIS_CALIBRATION_REQUIRED_UNKNOWN": GIMBAL_AXIS_CALIBRATION_REQUIRED_UNKNOWN, + "GIMBAL_AXIS_CALIBRATION_REQUIRED_TRUE": GIMBAL_AXIS_CALIBRATION_REQUIRED_TRUE, + "GIMBAL_AXIS_CALIBRATION_REQUIRED_FALSE": GIMBAL_AXIS_CALIBRATION_REQUIRED_FALSE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_AXIS_CALIBRATION_REQUIRED) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GIMBAL_AXIS_CALIBRATION_REQUIRED { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GIMBAL_AXIS_CALIBRATION_REQUIRED[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GIMBAL_AXIS_CALIBRATION_REQUIRED) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GIMBAL_AXIS_CALIBRATION_REQUIRED - for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_AXIS_CALIBRATION_REQUIRED { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GIMBAL_AXIS_CALIBRATION_REQUIRED[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GIMBAL_AXIS_CALIBRATION_REQUIRED) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GIMBAL_AXIS_CALIBRATION_REQUIRED[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_status.go b/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_status.go index 0b8c5fe1c..f3d38c52c 100644 --- a/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_status.go +++ b/pkg/dialects/ardupilotmega/enum_gimbal_axis_calibration_status.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GIMBAL_AXIS_CALIBRATION_STATUS uint32 @@ -24,40 +24,36 @@ var labels_GIMBAL_AXIS_CALIBRATION_STATUS = map[GIMBAL_AXIS_CALIBRATION_STATUS]s GIMBAL_AXIS_CALIBRATION_STATUS_FAILED: "GIMBAL_AXIS_CALIBRATION_STATUS_FAILED", } +var values_GIMBAL_AXIS_CALIBRATION_STATUS = map[string]GIMBAL_AXIS_CALIBRATION_STATUS{ + "GIMBAL_AXIS_CALIBRATION_STATUS_IN_PROGRESS": GIMBAL_AXIS_CALIBRATION_STATUS_IN_PROGRESS, + "GIMBAL_AXIS_CALIBRATION_STATUS_SUCCEEDED": GIMBAL_AXIS_CALIBRATION_STATUS_SUCCEEDED, + "GIMBAL_AXIS_CALIBRATION_STATUS_FAILED": GIMBAL_AXIS_CALIBRATION_STATUS_FAILED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_AXIS_CALIBRATION_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GIMBAL_AXIS_CALIBRATION_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GIMBAL_AXIS_CALIBRATION_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GIMBAL_AXIS_CALIBRATION_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GIMBAL_AXIS_CALIBRATION_STATUS - for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_AXIS_CALIBRATION_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GIMBAL_AXIS_CALIBRATION_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GIMBAL_AXIS_CALIBRATION_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GIMBAL_AXIS_CALIBRATION_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_burst_rate.go b/pkg/dialects/ardupilotmega/enum_gopro_burst_rate.go index 367439b12..062b68252 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_burst_rate.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_burst_rate.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_BURST_RATE uint32 @@ -42,40 +42,42 @@ var labels_GOPRO_BURST_RATE = map[GOPRO_BURST_RATE]string{ GOPRO_BURST_RATE_30_IN_6_SECOND: "GOPRO_BURST_RATE_30_IN_6_SECOND", } +var values_GOPRO_BURST_RATE = map[string]GOPRO_BURST_RATE{ + "GOPRO_BURST_RATE_3_IN_1_SECOND": GOPRO_BURST_RATE_3_IN_1_SECOND, + "GOPRO_BURST_RATE_5_IN_1_SECOND": GOPRO_BURST_RATE_5_IN_1_SECOND, + "GOPRO_BURST_RATE_10_IN_1_SECOND": GOPRO_BURST_RATE_10_IN_1_SECOND, + "GOPRO_BURST_RATE_10_IN_2_SECOND": GOPRO_BURST_RATE_10_IN_2_SECOND, + "GOPRO_BURST_RATE_10_IN_3_SECOND": GOPRO_BURST_RATE_10_IN_3_SECOND, + "GOPRO_BURST_RATE_30_IN_1_SECOND": GOPRO_BURST_RATE_30_IN_1_SECOND, + "GOPRO_BURST_RATE_30_IN_2_SECOND": GOPRO_BURST_RATE_30_IN_2_SECOND, + "GOPRO_BURST_RATE_30_IN_3_SECOND": GOPRO_BURST_RATE_30_IN_3_SECOND, + "GOPRO_BURST_RATE_30_IN_6_SECOND": GOPRO_BURST_RATE_30_IN_6_SECOND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_BURST_RATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_BURST_RATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_BURST_RATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_BURST_RATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_BURST_RATE - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_BURST_RATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_BURST_RATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_BURST_RATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_BURST_RATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_capture_mode.go b/pkg/dialects/ardupilotmega/enum_gopro_capture_mode.go index 564d9cfb9..e21a51c21 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_capture_mode.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_capture_mode.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_CAPTURE_MODE uint32 @@ -39,40 +39,41 @@ var labels_GOPRO_CAPTURE_MODE = map[GOPRO_CAPTURE_MODE]string{ GOPRO_CAPTURE_MODE_UNKNOWN: "GOPRO_CAPTURE_MODE_UNKNOWN", } +var values_GOPRO_CAPTURE_MODE = map[string]GOPRO_CAPTURE_MODE{ + "GOPRO_CAPTURE_MODE_VIDEO": GOPRO_CAPTURE_MODE_VIDEO, + "GOPRO_CAPTURE_MODE_PHOTO": GOPRO_CAPTURE_MODE_PHOTO, + "GOPRO_CAPTURE_MODE_BURST": GOPRO_CAPTURE_MODE_BURST, + "GOPRO_CAPTURE_MODE_TIME_LAPSE": GOPRO_CAPTURE_MODE_TIME_LAPSE, + "GOPRO_CAPTURE_MODE_MULTI_SHOT": GOPRO_CAPTURE_MODE_MULTI_SHOT, + "GOPRO_CAPTURE_MODE_PLAYBACK": GOPRO_CAPTURE_MODE_PLAYBACK, + "GOPRO_CAPTURE_MODE_SETUP": GOPRO_CAPTURE_MODE_SETUP, + "GOPRO_CAPTURE_MODE_UNKNOWN": GOPRO_CAPTURE_MODE_UNKNOWN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_CAPTURE_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_CAPTURE_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_CAPTURE_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_CAPTURE_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_CAPTURE_MODE - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_CAPTURE_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_CAPTURE_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_CAPTURE_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_CAPTURE_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_charging.go b/pkg/dialects/ardupilotmega/enum_gopro_charging.go index c76a4e15a..c23cd9687 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_charging.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_charging.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_CHARGING uint32 @@ -21,40 +21,35 @@ var labels_GOPRO_CHARGING = map[GOPRO_CHARGING]string{ GOPRO_CHARGING_ENABLED: "GOPRO_CHARGING_ENABLED", } +var values_GOPRO_CHARGING = map[string]GOPRO_CHARGING{ + "GOPRO_CHARGING_DISABLED": GOPRO_CHARGING_DISABLED, + "GOPRO_CHARGING_ENABLED": GOPRO_CHARGING_ENABLED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_CHARGING) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_CHARGING { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_CHARGING[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_CHARGING) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_CHARGING - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_CHARGING { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_CHARGING[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_CHARGING) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_CHARGING[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_command.go b/pkg/dialects/ardupilotmega/enum_gopro_command.go index 35bac8b31..6b048d2ad 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_command.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_command.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_COMMAND uint32 @@ -66,40 +66,50 @@ var labels_GOPRO_COMMAND = map[GOPRO_COMMAND]string{ GOPRO_COMMAND_CHARGING: "GOPRO_COMMAND_CHARGING", } +var values_GOPRO_COMMAND = map[string]GOPRO_COMMAND{ + "GOPRO_COMMAND_POWER": GOPRO_COMMAND_POWER, + "GOPRO_COMMAND_CAPTURE_MODE": GOPRO_COMMAND_CAPTURE_MODE, + "GOPRO_COMMAND_SHUTTER": GOPRO_COMMAND_SHUTTER, + "GOPRO_COMMAND_BATTERY": GOPRO_COMMAND_BATTERY, + "GOPRO_COMMAND_MODEL": GOPRO_COMMAND_MODEL, + "GOPRO_COMMAND_VIDEO_SETTINGS": GOPRO_COMMAND_VIDEO_SETTINGS, + "GOPRO_COMMAND_LOW_LIGHT": GOPRO_COMMAND_LOW_LIGHT, + "GOPRO_COMMAND_PHOTO_RESOLUTION": GOPRO_COMMAND_PHOTO_RESOLUTION, + "GOPRO_COMMAND_PHOTO_BURST_RATE": GOPRO_COMMAND_PHOTO_BURST_RATE, + "GOPRO_COMMAND_PROTUNE": GOPRO_COMMAND_PROTUNE, + "GOPRO_COMMAND_PROTUNE_WHITE_BALANCE": GOPRO_COMMAND_PROTUNE_WHITE_BALANCE, + "GOPRO_COMMAND_PROTUNE_COLOUR": GOPRO_COMMAND_PROTUNE_COLOUR, + "GOPRO_COMMAND_PROTUNE_GAIN": GOPRO_COMMAND_PROTUNE_GAIN, + "GOPRO_COMMAND_PROTUNE_SHARPNESS": GOPRO_COMMAND_PROTUNE_SHARPNESS, + "GOPRO_COMMAND_PROTUNE_EXPOSURE": GOPRO_COMMAND_PROTUNE_EXPOSURE, + "GOPRO_COMMAND_TIME": GOPRO_COMMAND_TIME, + "GOPRO_COMMAND_CHARGING": GOPRO_COMMAND_CHARGING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_COMMAND) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_COMMAND { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_COMMAND[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_COMMAND) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_COMMAND - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_COMMAND { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_COMMAND[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_COMMAND) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_COMMAND[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_field_of_view.go b/pkg/dialects/ardupilotmega/enum_gopro_field_of_view.go index 85deb919e..3c60a30e6 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_field_of_view.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_field_of_view.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_FIELD_OF_VIEW uint32 @@ -24,40 +24,36 @@ var labels_GOPRO_FIELD_OF_VIEW = map[GOPRO_FIELD_OF_VIEW]string{ GOPRO_FIELD_OF_VIEW_NARROW: "GOPRO_FIELD_OF_VIEW_NARROW", } +var values_GOPRO_FIELD_OF_VIEW = map[string]GOPRO_FIELD_OF_VIEW{ + "GOPRO_FIELD_OF_VIEW_WIDE": GOPRO_FIELD_OF_VIEW_WIDE, + "GOPRO_FIELD_OF_VIEW_MEDIUM": GOPRO_FIELD_OF_VIEW_MEDIUM, + "GOPRO_FIELD_OF_VIEW_NARROW": GOPRO_FIELD_OF_VIEW_NARROW, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_FIELD_OF_VIEW) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_FIELD_OF_VIEW { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_FIELD_OF_VIEW[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_FIELD_OF_VIEW) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_FIELD_OF_VIEW - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_FIELD_OF_VIEW { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_FIELD_OF_VIEW[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_FIELD_OF_VIEW) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_FIELD_OF_VIEW[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_frame_rate.go b/pkg/dialects/ardupilotmega/enum_gopro_frame_rate.go index a0214af55..b6b21f075 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_frame_rate.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_frame_rate.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_FRAME_RATE uint32 @@ -57,40 +57,47 @@ var labels_GOPRO_FRAME_RATE = map[GOPRO_FRAME_RATE]string{ GOPRO_FRAME_RATE_12_5: "GOPRO_FRAME_RATE_12_5", } +var values_GOPRO_FRAME_RATE = map[string]GOPRO_FRAME_RATE{ + "GOPRO_FRAME_RATE_12": GOPRO_FRAME_RATE_12, + "GOPRO_FRAME_RATE_15": GOPRO_FRAME_RATE_15, + "GOPRO_FRAME_RATE_24": GOPRO_FRAME_RATE_24, + "GOPRO_FRAME_RATE_25": GOPRO_FRAME_RATE_25, + "GOPRO_FRAME_RATE_30": GOPRO_FRAME_RATE_30, + "GOPRO_FRAME_RATE_48": GOPRO_FRAME_RATE_48, + "GOPRO_FRAME_RATE_50": GOPRO_FRAME_RATE_50, + "GOPRO_FRAME_RATE_60": GOPRO_FRAME_RATE_60, + "GOPRO_FRAME_RATE_80": GOPRO_FRAME_RATE_80, + "GOPRO_FRAME_RATE_90": GOPRO_FRAME_RATE_90, + "GOPRO_FRAME_RATE_100": GOPRO_FRAME_RATE_100, + "GOPRO_FRAME_RATE_120": GOPRO_FRAME_RATE_120, + "GOPRO_FRAME_RATE_240": GOPRO_FRAME_RATE_240, + "GOPRO_FRAME_RATE_12_5": GOPRO_FRAME_RATE_12_5, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_FRAME_RATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_FRAME_RATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_FRAME_RATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_FRAME_RATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_FRAME_RATE - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_FRAME_RATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_FRAME_RATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_FRAME_RATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_FRAME_RATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_flags.go b/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_flags.go index bf2881936..a84ec3605 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_flags.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_flags.go @@ -18,12 +18,17 @@ var labels_GOPRO_HEARTBEAT_FLAGS = map[GOPRO_HEARTBEAT_FLAGS]string{ GOPRO_FLAG_RECORDING: "GOPRO_FLAG_RECORDING", } +var values_GOPRO_HEARTBEAT_FLAGS = map[string]GOPRO_HEARTBEAT_FLAGS{ + "GOPRO_FLAG_RECORDING": GOPRO_FLAG_RECORDING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_HEARTBEAT_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GOPRO_HEARTBEAT_FLAGS { + for i := 0; i < 1; i++ { + mask := GOPRO_HEARTBEAT_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GOPRO_HEARTBEAT_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -34,19 +39,12 @@ func (e *GOPRO_HEARTBEAT_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GOPRO_HEARTBEAT_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GOPRO_HEARTBEAT_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GOPRO_HEARTBEAT_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_status.go b/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_status.go index 78cdf0095..a91efd14f 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_status.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_heartbeat_status.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_HEARTBEAT_STATUS uint32 @@ -27,40 +27,37 @@ var labels_GOPRO_HEARTBEAT_STATUS = map[GOPRO_HEARTBEAT_STATUS]string{ GOPRO_HEARTBEAT_STATUS_ERROR: "GOPRO_HEARTBEAT_STATUS_ERROR", } +var values_GOPRO_HEARTBEAT_STATUS = map[string]GOPRO_HEARTBEAT_STATUS{ + "GOPRO_HEARTBEAT_STATUS_DISCONNECTED": GOPRO_HEARTBEAT_STATUS_DISCONNECTED, + "GOPRO_HEARTBEAT_STATUS_INCOMPATIBLE": GOPRO_HEARTBEAT_STATUS_INCOMPATIBLE, + "GOPRO_HEARTBEAT_STATUS_CONNECTED": GOPRO_HEARTBEAT_STATUS_CONNECTED, + "GOPRO_HEARTBEAT_STATUS_ERROR": GOPRO_HEARTBEAT_STATUS_ERROR, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_HEARTBEAT_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_HEARTBEAT_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_HEARTBEAT_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_HEARTBEAT_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_HEARTBEAT_STATUS - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_HEARTBEAT_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_HEARTBEAT_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_HEARTBEAT_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_HEARTBEAT_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_model.go b/pkg/dialects/ardupilotmega/enum_gopro_model.go index 9222a46ff..c6041938b 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_model.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_model.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_MODEL uint32 @@ -30,40 +30,38 @@ var labels_GOPRO_MODEL = map[GOPRO_MODEL]string{ GOPRO_MODEL_HERO_4_BLACK: "GOPRO_MODEL_HERO_4_BLACK", } +var values_GOPRO_MODEL = map[string]GOPRO_MODEL{ + "GOPRO_MODEL_UNKNOWN": GOPRO_MODEL_UNKNOWN, + "GOPRO_MODEL_HERO_3_PLUS_SILVER": GOPRO_MODEL_HERO_3_PLUS_SILVER, + "GOPRO_MODEL_HERO_3_PLUS_BLACK": GOPRO_MODEL_HERO_3_PLUS_BLACK, + "GOPRO_MODEL_HERO_4_SILVER": GOPRO_MODEL_HERO_4_SILVER, + "GOPRO_MODEL_HERO_4_BLACK": GOPRO_MODEL_HERO_4_BLACK, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_MODEL) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_MODEL { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_MODEL[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_MODEL) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_MODEL - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_MODEL { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_MODEL[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_MODEL) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_MODEL[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_photo_resolution.go b/pkg/dialects/ardupilotmega/enum_gopro_photo_resolution.go index 3e220bfbb..7dfb4e664 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_photo_resolution.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_photo_resolution.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_PHOTO_RESOLUTION uint32 @@ -30,40 +30,38 @@ var labels_GOPRO_PHOTO_RESOLUTION = map[GOPRO_PHOTO_RESOLUTION]string{ GOPRO_PHOTO_RESOLUTION_12MP_WIDE: "GOPRO_PHOTO_RESOLUTION_12MP_WIDE", } +var values_GOPRO_PHOTO_RESOLUTION = map[string]GOPRO_PHOTO_RESOLUTION{ + "GOPRO_PHOTO_RESOLUTION_5MP_MEDIUM": GOPRO_PHOTO_RESOLUTION_5MP_MEDIUM, + "GOPRO_PHOTO_RESOLUTION_7MP_MEDIUM": GOPRO_PHOTO_RESOLUTION_7MP_MEDIUM, + "GOPRO_PHOTO_RESOLUTION_7MP_WIDE": GOPRO_PHOTO_RESOLUTION_7MP_WIDE, + "GOPRO_PHOTO_RESOLUTION_10MP_WIDE": GOPRO_PHOTO_RESOLUTION_10MP_WIDE, + "GOPRO_PHOTO_RESOLUTION_12MP_WIDE": GOPRO_PHOTO_RESOLUTION_12MP_WIDE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_PHOTO_RESOLUTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_PHOTO_RESOLUTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_PHOTO_RESOLUTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_PHOTO_RESOLUTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_PHOTO_RESOLUTION - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_PHOTO_RESOLUTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_PHOTO_RESOLUTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_PHOTO_RESOLUTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_PHOTO_RESOLUTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_protune_colour.go b/pkg/dialects/ardupilotmega/enum_gopro_protune_colour.go index 19ad268d2..51f60c8d9 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_protune_colour.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_protune_colour.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_PROTUNE_COLOUR uint32 @@ -21,40 +21,35 @@ var labels_GOPRO_PROTUNE_COLOUR = map[GOPRO_PROTUNE_COLOUR]string{ GOPRO_PROTUNE_COLOUR_NEUTRAL: "GOPRO_PROTUNE_COLOUR_NEUTRAL", } +var values_GOPRO_PROTUNE_COLOUR = map[string]GOPRO_PROTUNE_COLOUR{ + "GOPRO_PROTUNE_COLOUR_STANDARD": GOPRO_PROTUNE_COLOUR_STANDARD, + "GOPRO_PROTUNE_COLOUR_NEUTRAL": GOPRO_PROTUNE_COLOUR_NEUTRAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_PROTUNE_COLOUR) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_PROTUNE_COLOUR { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_PROTUNE_COLOUR[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_PROTUNE_COLOUR) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_PROTUNE_COLOUR - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_PROTUNE_COLOUR { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_PROTUNE_COLOUR[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_PROTUNE_COLOUR) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_PROTUNE_COLOUR[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_protune_exposure.go b/pkg/dialects/ardupilotmega/enum_gopro_protune_exposure.go index 19e0c8ae6..2ac476333 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_protune_exposure.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_protune_exposure.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_PROTUNE_EXPOSURE uint32 @@ -78,40 +78,54 @@ var labels_GOPRO_PROTUNE_EXPOSURE = map[GOPRO_PROTUNE_EXPOSURE]string{ GOPRO_PROTUNE_EXPOSURE_POS_5_0: "GOPRO_PROTUNE_EXPOSURE_POS_5_0", } +var values_GOPRO_PROTUNE_EXPOSURE = map[string]GOPRO_PROTUNE_EXPOSURE{ + "GOPRO_PROTUNE_EXPOSURE_NEG_5_0": GOPRO_PROTUNE_EXPOSURE_NEG_5_0, + "GOPRO_PROTUNE_EXPOSURE_NEG_4_5": GOPRO_PROTUNE_EXPOSURE_NEG_4_5, + "GOPRO_PROTUNE_EXPOSURE_NEG_4_0": GOPRO_PROTUNE_EXPOSURE_NEG_4_0, + "GOPRO_PROTUNE_EXPOSURE_NEG_3_5": GOPRO_PROTUNE_EXPOSURE_NEG_3_5, + "GOPRO_PROTUNE_EXPOSURE_NEG_3_0": GOPRO_PROTUNE_EXPOSURE_NEG_3_0, + "GOPRO_PROTUNE_EXPOSURE_NEG_2_5": GOPRO_PROTUNE_EXPOSURE_NEG_2_5, + "GOPRO_PROTUNE_EXPOSURE_NEG_2_0": GOPRO_PROTUNE_EXPOSURE_NEG_2_0, + "GOPRO_PROTUNE_EXPOSURE_NEG_1_5": GOPRO_PROTUNE_EXPOSURE_NEG_1_5, + "GOPRO_PROTUNE_EXPOSURE_NEG_1_0": GOPRO_PROTUNE_EXPOSURE_NEG_1_0, + "GOPRO_PROTUNE_EXPOSURE_NEG_0_5": GOPRO_PROTUNE_EXPOSURE_NEG_0_5, + "GOPRO_PROTUNE_EXPOSURE_ZERO": GOPRO_PROTUNE_EXPOSURE_ZERO, + "GOPRO_PROTUNE_EXPOSURE_POS_0_5": GOPRO_PROTUNE_EXPOSURE_POS_0_5, + "GOPRO_PROTUNE_EXPOSURE_POS_1_0": GOPRO_PROTUNE_EXPOSURE_POS_1_0, + "GOPRO_PROTUNE_EXPOSURE_POS_1_5": GOPRO_PROTUNE_EXPOSURE_POS_1_5, + "GOPRO_PROTUNE_EXPOSURE_POS_2_0": GOPRO_PROTUNE_EXPOSURE_POS_2_0, + "GOPRO_PROTUNE_EXPOSURE_POS_2_5": GOPRO_PROTUNE_EXPOSURE_POS_2_5, + "GOPRO_PROTUNE_EXPOSURE_POS_3_0": GOPRO_PROTUNE_EXPOSURE_POS_3_0, + "GOPRO_PROTUNE_EXPOSURE_POS_3_5": GOPRO_PROTUNE_EXPOSURE_POS_3_5, + "GOPRO_PROTUNE_EXPOSURE_POS_4_0": GOPRO_PROTUNE_EXPOSURE_POS_4_0, + "GOPRO_PROTUNE_EXPOSURE_POS_4_5": GOPRO_PROTUNE_EXPOSURE_POS_4_5, + "GOPRO_PROTUNE_EXPOSURE_POS_5_0": GOPRO_PROTUNE_EXPOSURE_POS_5_0, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_PROTUNE_EXPOSURE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_PROTUNE_EXPOSURE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_PROTUNE_EXPOSURE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_PROTUNE_EXPOSURE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_PROTUNE_EXPOSURE - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_PROTUNE_EXPOSURE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_PROTUNE_EXPOSURE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_PROTUNE_EXPOSURE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_PROTUNE_EXPOSURE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_protune_gain.go b/pkg/dialects/ardupilotmega/enum_gopro_protune_gain.go index f5e108b33..966547323 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_protune_gain.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_protune_gain.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_PROTUNE_GAIN uint32 @@ -30,40 +30,38 @@ var labels_GOPRO_PROTUNE_GAIN = map[GOPRO_PROTUNE_GAIN]string{ GOPRO_PROTUNE_GAIN_6400: "GOPRO_PROTUNE_GAIN_6400", } +var values_GOPRO_PROTUNE_GAIN = map[string]GOPRO_PROTUNE_GAIN{ + "GOPRO_PROTUNE_GAIN_400": GOPRO_PROTUNE_GAIN_400, + "GOPRO_PROTUNE_GAIN_800": GOPRO_PROTUNE_GAIN_800, + "GOPRO_PROTUNE_GAIN_1600": GOPRO_PROTUNE_GAIN_1600, + "GOPRO_PROTUNE_GAIN_3200": GOPRO_PROTUNE_GAIN_3200, + "GOPRO_PROTUNE_GAIN_6400": GOPRO_PROTUNE_GAIN_6400, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_PROTUNE_GAIN) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_PROTUNE_GAIN { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_PROTUNE_GAIN[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_PROTUNE_GAIN) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_PROTUNE_GAIN - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_PROTUNE_GAIN { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_PROTUNE_GAIN[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_PROTUNE_GAIN) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_PROTUNE_GAIN[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_protune_sharpness.go b/pkg/dialects/ardupilotmega/enum_gopro_protune_sharpness.go index 2a9393109..a04c001e1 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_protune_sharpness.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_protune_sharpness.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_PROTUNE_SHARPNESS uint32 @@ -24,40 +24,36 @@ var labels_GOPRO_PROTUNE_SHARPNESS = map[GOPRO_PROTUNE_SHARPNESS]string{ GOPRO_PROTUNE_SHARPNESS_HIGH: "GOPRO_PROTUNE_SHARPNESS_HIGH", } +var values_GOPRO_PROTUNE_SHARPNESS = map[string]GOPRO_PROTUNE_SHARPNESS{ + "GOPRO_PROTUNE_SHARPNESS_LOW": GOPRO_PROTUNE_SHARPNESS_LOW, + "GOPRO_PROTUNE_SHARPNESS_MEDIUM": GOPRO_PROTUNE_SHARPNESS_MEDIUM, + "GOPRO_PROTUNE_SHARPNESS_HIGH": GOPRO_PROTUNE_SHARPNESS_HIGH, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_PROTUNE_SHARPNESS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_PROTUNE_SHARPNESS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_PROTUNE_SHARPNESS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_PROTUNE_SHARPNESS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_PROTUNE_SHARPNESS - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_PROTUNE_SHARPNESS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_PROTUNE_SHARPNESS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_PROTUNE_SHARPNESS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_PROTUNE_SHARPNESS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_protune_white_balance.go b/pkg/dialects/ardupilotmega/enum_gopro_protune_white_balance.go index 0b01acf38..6d8b000dd 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_protune_white_balance.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_protune_white_balance.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_PROTUNE_WHITE_BALANCE uint32 @@ -30,40 +30,38 @@ var labels_GOPRO_PROTUNE_WHITE_BALANCE = map[GOPRO_PROTUNE_WHITE_BALANCE]string{ GOPRO_PROTUNE_WHITE_BALANCE_RAW: "GOPRO_PROTUNE_WHITE_BALANCE_RAW", } +var values_GOPRO_PROTUNE_WHITE_BALANCE = map[string]GOPRO_PROTUNE_WHITE_BALANCE{ + "GOPRO_PROTUNE_WHITE_BALANCE_AUTO": GOPRO_PROTUNE_WHITE_BALANCE_AUTO, + "GOPRO_PROTUNE_WHITE_BALANCE_3000K": GOPRO_PROTUNE_WHITE_BALANCE_3000K, + "GOPRO_PROTUNE_WHITE_BALANCE_5500K": GOPRO_PROTUNE_WHITE_BALANCE_5500K, + "GOPRO_PROTUNE_WHITE_BALANCE_6500K": GOPRO_PROTUNE_WHITE_BALANCE_6500K, + "GOPRO_PROTUNE_WHITE_BALANCE_RAW": GOPRO_PROTUNE_WHITE_BALANCE_RAW, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_PROTUNE_WHITE_BALANCE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_PROTUNE_WHITE_BALANCE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_PROTUNE_WHITE_BALANCE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_PROTUNE_WHITE_BALANCE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_PROTUNE_WHITE_BALANCE - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_PROTUNE_WHITE_BALANCE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_PROTUNE_WHITE_BALANCE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_PROTUNE_WHITE_BALANCE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_PROTUNE_WHITE_BALANCE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_request_status.go b/pkg/dialects/ardupilotmega/enum_gopro_request_status.go index db4ed29c1..a0dbc1176 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_request_status.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_request_status.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_REQUEST_STATUS uint32 @@ -21,40 +21,35 @@ var labels_GOPRO_REQUEST_STATUS = map[GOPRO_REQUEST_STATUS]string{ GOPRO_REQUEST_FAILED: "GOPRO_REQUEST_FAILED", } +var values_GOPRO_REQUEST_STATUS = map[string]GOPRO_REQUEST_STATUS{ + "GOPRO_REQUEST_SUCCESS": GOPRO_REQUEST_SUCCESS, + "GOPRO_REQUEST_FAILED": GOPRO_REQUEST_FAILED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_REQUEST_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_REQUEST_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_REQUEST_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_REQUEST_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_REQUEST_STATUS - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_REQUEST_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_REQUEST_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_REQUEST_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_REQUEST_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_resolution.go b/pkg/dialects/ardupilotmega/enum_gopro_resolution.go index b18d801c3..13b337d26 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_resolution.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_resolution.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type GOPRO_RESOLUTION uint32 @@ -57,40 +57,47 @@ var labels_GOPRO_RESOLUTION = map[GOPRO_RESOLUTION]string{ GOPRO_RESOLUTION_4k_SUPERVIEW: "GOPRO_RESOLUTION_4k_SUPERVIEW", } +var values_GOPRO_RESOLUTION = map[string]GOPRO_RESOLUTION{ + "GOPRO_RESOLUTION_480p": GOPRO_RESOLUTION_480p, + "GOPRO_RESOLUTION_720p": GOPRO_RESOLUTION_720p, + "GOPRO_RESOLUTION_960p": GOPRO_RESOLUTION_960p, + "GOPRO_RESOLUTION_1080p": GOPRO_RESOLUTION_1080p, + "GOPRO_RESOLUTION_1440p": GOPRO_RESOLUTION_1440p, + "GOPRO_RESOLUTION_2_7k_17_9": GOPRO_RESOLUTION_2_7k_17_9, + "GOPRO_RESOLUTION_2_7k_16_9": GOPRO_RESOLUTION_2_7k_16_9, + "GOPRO_RESOLUTION_2_7k_4_3": GOPRO_RESOLUTION_2_7k_4_3, + "GOPRO_RESOLUTION_4k_16_9": GOPRO_RESOLUTION_4k_16_9, + "GOPRO_RESOLUTION_4k_17_9": GOPRO_RESOLUTION_4k_17_9, + "GOPRO_RESOLUTION_720p_SUPERVIEW": GOPRO_RESOLUTION_720p_SUPERVIEW, + "GOPRO_RESOLUTION_1080p_SUPERVIEW": GOPRO_RESOLUTION_1080p_SUPERVIEW, + "GOPRO_RESOLUTION_2_7k_SUPERVIEW": GOPRO_RESOLUTION_2_7k_SUPERVIEW, + "GOPRO_RESOLUTION_4k_SUPERVIEW": GOPRO_RESOLUTION_4k_SUPERVIEW, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_RESOLUTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GOPRO_RESOLUTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GOPRO_RESOLUTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GOPRO_RESOLUTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GOPRO_RESOLUTION - for _, label := range labels { - found := false - for value, l := range labels_GOPRO_RESOLUTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GOPRO_RESOLUTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GOPRO_RESOLUTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GOPRO_RESOLUTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_gopro_video_settings_flags.go b/pkg/dialects/ardupilotmega/enum_gopro_video_settings_flags.go index 57119e9f3..71ec4c759 100644 --- a/pkg/dialects/ardupilotmega/enum_gopro_video_settings_flags.go +++ b/pkg/dialects/ardupilotmega/enum_gopro_video_settings_flags.go @@ -18,12 +18,17 @@ var labels_GOPRO_VIDEO_SETTINGS_FLAGS = map[GOPRO_VIDEO_SETTINGS_FLAGS]string{ GOPRO_VIDEO_SETTINGS_TV_MODE: "GOPRO_VIDEO_SETTINGS_TV_MODE", } +var values_GOPRO_VIDEO_SETTINGS_FLAGS = map[string]GOPRO_VIDEO_SETTINGS_FLAGS{ + "GOPRO_VIDEO_SETTINGS_TV_MODE": GOPRO_VIDEO_SETTINGS_TV_MODE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GOPRO_VIDEO_SETTINGS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GOPRO_VIDEO_SETTINGS_FLAGS { + for i := 0; i < 1; i++ { + mask := GOPRO_VIDEO_SETTINGS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GOPRO_VIDEO_SETTINGS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -34,19 +39,12 @@ func (e *GOPRO_VIDEO_SETTINGS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GOPRO_VIDEO_SETTINGS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GOPRO_VIDEO_SETTINGS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GOPRO_VIDEO_SETTINGS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/ardupilotmega/enum_heading_type.go b/pkg/dialects/ardupilotmega/enum_heading_type.go index 21c51ca40..ce4fa12f3 100644 --- a/pkg/dialects/ardupilotmega/enum_heading_type.go +++ b/pkg/dialects/ardupilotmega/enum_heading_type.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type HEADING_TYPE uint32 @@ -19,40 +19,35 @@ var labels_HEADING_TYPE = map[HEADING_TYPE]string{ HEADING_TYPE_HEADING: "HEADING_TYPE_HEADING", } +var values_HEADING_TYPE = map[string]HEADING_TYPE{ + "HEADING_TYPE_COURSE_OVER_GROUND": HEADING_TYPE_COURSE_OVER_GROUND, + "HEADING_TYPE_HEADING": HEADING_TYPE_HEADING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e HEADING_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_HEADING_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_HEADING_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *HEADING_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask HEADING_TYPE - for _, label := range labels { - found := false - for value, l := range labels_HEADING_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_HEADING_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e HEADING_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_HEADING_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_led_control_pattern.go b/pkg/dialects/ardupilotmega/enum_led_control_pattern.go index 2cf33bc94..f3b8d87b7 100644 --- a/pkg/dialects/ardupilotmega/enum_led_control_pattern.go +++ b/pkg/dialects/ardupilotmega/enum_led_control_pattern.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type LED_CONTROL_PATTERN uint32 @@ -24,40 +24,36 @@ var labels_LED_CONTROL_PATTERN = map[LED_CONTROL_PATTERN]string{ LED_CONTROL_PATTERN_CUSTOM: "LED_CONTROL_PATTERN_CUSTOM", } +var values_LED_CONTROL_PATTERN = map[string]LED_CONTROL_PATTERN{ + "LED_CONTROL_PATTERN_OFF": LED_CONTROL_PATTERN_OFF, + "LED_CONTROL_PATTERN_FIRMWAREUPDATE": LED_CONTROL_PATTERN_FIRMWAREUPDATE, + "LED_CONTROL_PATTERN_CUSTOM": LED_CONTROL_PATTERN_CUSTOM, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e LED_CONTROL_PATTERN) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_LED_CONTROL_PATTERN { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_LED_CONTROL_PATTERN[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *LED_CONTROL_PATTERN) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask LED_CONTROL_PATTERN - for _, label := range labels { - found := false - for value, l := range labels_LED_CONTROL_PATTERN { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_LED_CONTROL_PATTERN[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e LED_CONTROL_PATTERN) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_LED_CONTROL_PATTERN[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_limit_module.go b/pkg/dialects/ardupilotmega/enum_limit_module.go index 2b3360bfd..a46144d72 100644 --- a/pkg/dialects/ardupilotmega/enum_limit_module.go +++ b/pkg/dialects/ardupilotmega/enum_limit_module.go @@ -24,12 +24,19 @@ var labels_LIMIT_MODULE = map[LIMIT_MODULE]string{ LIMIT_ALTITUDE: "LIMIT_ALTITUDE", } +var values_LIMIT_MODULE = map[string]LIMIT_MODULE{ + "LIMIT_GPSLOCK": LIMIT_GPSLOCK, + "LIMIT_GEOFENCE": LIMIT_GEOFENCE, + "LIMIT_ALTITUDE": LIMIT_ALTITUDE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e LIMIT_MODULE) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_LIMIT_MODULE { + for i := 0; i < 3; i++ { + mask := LIMIT_MODULE(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_LIMIT_MODULE[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -40,19 +47,12 @@ func (e *LIMIT_MODULE) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask LIMIT_MODULE for _, label := range labels { - found := false - for value, l := range labels_LIMIT_MODULE { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_LIMIT_MODULE[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/ardupilotmega/enum_limits_state.go b/pkg/dialects/ardupilotmega/enum_limits_state.go index 857e79518..5aa4b0e5e 100644 --- a/pkg/dialects/ardupilotmega/enum_limits_state.go +++ b/pkg/dialects/ardupilotmega/enum_limits_state.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type LIMITS_STATE uint32 @@ -33,40 +33,39 @@ var labels_LIMITS_STATE = map[LIMITS_STATE]string{ LIMITS_RECOVERED: "LIMITS_RECOVERED", } +var values_LIMITS_STATE = map[string]LIMITS_STATE{ + "LIMITS_INIT": LIMITS_INIT, + "LIMITS_DISABLED": LIMITS_DISABLED, + "LIMITS_ENABLED": LIMITS_ENABLED, + "LIMITS_TRIGGERED": LIMITS_TRIGGERED, + "LIMITS_RECOVERING": LIMITS_RECOVERING, + "LIMITS_RECOVERED": LIMITS_RECOVERED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e LIMITS_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_LIMITS_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_LIMITS_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *LIMITS_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask LIMITS_STATE - for _, label := range labels { - found := false - for value, l := range labels_LIMITS_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_LIMITS_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e LIMITS_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_LIMITS_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_mav_cmd.go b/pkg/dialects/ardupilotmega/enum_mav_cmd.go index 89182f6bf..a19418b93 100644 --- a/pkg/dialects/ardupilotmega/enum_mav_cmd.go +++ b/pkg/dialects/ardupilotmega/enum_mav_cmd.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -639,40 +639,224 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_EXTERNAL_POSITION_ESTIMATE: "MAV_CMD_EXTERNAL_POSITION_ESTIMATE", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_DO_SET_RESUME_REPEAT_DIST": MAV_CMD_DO_SET_RESUME_REPEAT_DIST, + "MAV_CMD_DO_SPRAYER": MAV_CMD_DO_SPRAYER, + "MAV_CMD_DO_SEND_SCRIPT_MESSAGE": MAV_CMD_DO_SEND_SCRIPT_MESSAGE, + "MAV_CMD_DO_AUX_FUNCTION": MAV_CMD_DO_AUX_FUNCTION, + "MAV_CMD_NAV_ALTITUDE_WAIT": MAV_CMD_NAV_ALTITUDE_WAIT, + "MAV_CMD_POWER_OFF_INITIATED": MAV_CMD_POWER_OFF_INITIATED, + "MAV_CMD_SOLO_BTN_FLY_CLICK": MAV_CMD_SOLO_BTN_FLY_CLICK, + "MAV_CMD_SOLO_BTN_FLY_HOLD": MAV_CMD_SOLO_BTN_FLY_HOLD, + "MAV_CMD_SOLO_BTN_PAUSE_CLICK": MAV_CMD_SOLO_BTN_PAUSE_CLICK, + "MAV_CMD_FIXED_MAG_CAL": MAV_CMD_FIXED_MAG_CAL, + "MAV_CMD_FIXED_MAG_CAL_FIELD": MAV_CMD_FIXED_MAG_CAL_FIELD, + "MAV_CMD_SET_EKF_SOURCE_SET": MAV_CMD_SET_EKF_SOURCE_SET, + "MAV_CMD_DO_START_MAG_CAL": MAV_CMD_DO_START_MAG_CAL, + "MAV_CMD_DO_ACCEPT_MAG_CAL": MAV_CMD_DO_ACCEPT_MAG_CAL, + "MAV_CMD_DO_CANCEL_MAG_CAL": MAV_CMD_DO_CANCEL_MAG_CAL, + "MAV_CMD_ACCELCAL_VEHICLE_POS": MAV_CMD_ACCELCAL_VEHICLE_POS, + "MAV_CMD_DO_SEND_BANNER": MAV_CMD_DO_SEND_BANNER, + "MAV_CMD_SET_FACTORY_TEST_MODE": MAV_CMD_SET_FACTORY_TEST_MODE, + "MAV_CMD_GIMBAL_RESET": MAV_CMD_GIMBAL_RESET, + "MAV_CMD_GIMBAL_AXIS_CALIBRATION_STATUS": MAV_CMD_GIMBAL_AXIS_CALIBRATION_STATUS, + "MAV_CMD_GIMBAL_REQUEST_AXIS_CALIBRATION": MAV_CMD_GIMBAL_REQUEST_AXIS_CALIBRATION, + "MAV_CMD_GIMBAL_FULL_RESET": MAV_CMD_GIMBAL_FULL_RESET, + "MAV_CMD_FLASH_BOOTLOADER": MAV_CMD_FLASH_BOOTLOADER, + "MAV_CMD_BATTERY_RESET": MAV_CMD_BATTERY_RESET, + "MAV_CMD_DEBUG_TRAP": MAV_CMD_DEBUG_TRAP, + "MAV_CMD_SCRIPTING": MAV_CMD_SCRIPTING, + "MAV_CMD_NAV_SCRIPT_TIME": MAV_CMD_NAV_SCRIPT_TIME, + "MAV_CMD_NAV_ATTITUDE_TIME": MAV_CMD_NAV_ATTITUDE_TIME, + "MAV_CMD_GUIDED_CHANGE_SPEED": MAV_CMD_GUIDED_CHANGE_SPEED, + "MAV_CMD_GUIDED_CHANGE_ALTITUDE": MAV_CMD_GUIDED_CHANGE_ALTITUDE, + "MAV_CMD_GUIDED_CHANGE_HEADING": MAV_CMD_GUIDED_CHANGE_HEADING, + "MAV_CMD_EXTERNAL_POSITION_ESTIMATE": MAV_CMD_EXTERNAL_POSITION_ESTIMATE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_mav_cmd_do_aux_function_switch_level.go b/pkg/dialects/ardupilotmega/enum_mav_cmd_do_aux_function_switch_level.go index c2fe77b6b..12b447f9e 100644 --- a/pkg/dialects/ardupilotmega/enum_mav_cmd_do_aux_function_switch_level.go +++ b/pkg/dialects/ardupilotmega/enum_mav_cmd_do_aux_function_switch_level.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL uint32 @@ -24,40 +24,36 @@ var labels_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL = map[MAV_CMD_DO_AUX_FUNCTION_SW MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_HIGH: "MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_HIGH", } +var values_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL = map[string]MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL{ + "MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_LOW": MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_LOW, + "MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_MIDDLE": MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_MIDDLE, + "MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_HIGH": MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL_HIGH, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD_DO_AUX_FUNCTION_SWITCH_LEVEL[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_mav_mode_gimbal.go b/pkg/dialects/ardupilotmega/enum_mav_mode_gimbal.go index 833c381e4..32a1ff16d 100644 --- a/pkg/dialects/ardupilotmega/enum_mav_mode_gimbal.go +++ b/pkg/dialects/ardupilotmega/enum_mav_mode_gimbal.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type MAV_MODE_GIMBAL uint32 @@ -36,40 +36,40 @@ var labels_MAV_MODE_GIMBAL = map[MAV_MODE_GIMBAL]string{ MAV_MODE_GIMBAL_RATE_CMD_TIMEOUT: "MAV_MODE_GIMBAL_RATE_CMD_TIMEOUT", } +var values_MAV_MODE_GIMBAL = map[string]MAV_MODE_GIMBAL{ + "MAV_MODE_GIMBAL_UNINITIALIZED": MAV_MODE_GIMBAL_UNINITIALIZED, + "MAV_MODE_GIMBAL_CALIBRATING_PITCH": MAV_MODE_GIMBAL_CALIBRATING_PITCH, + "MAV_MODE_GIMBAL_CALIBRATING_ROLL": MAV_MODE_GIMBAL_CALIBRATING_ROLL, + "MAV_MODE_GIMBAL_CALIBRATING_YAW": MAV_MODE_GIMBAL_CALIBRATING_YAW, + "MAV_MODE_GIMBAL_INITIALIZED": MAV_MODE_GIMBAL_INITIALIZED, + "MAV_MODE_GIMBAL_ACTIVE": MAV_MODE_GIMBAL_ACTIVE, + "MAV_MODE_GIMBAL_RATE_CMD_TIMEOUT": MAV_MODE_GIMBAL_RATE_CMD_TIMEOUT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_MODE_GIMBAL) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_MODE_GIMBAL { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_MODE_GIMBAL[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_MODE_GIMBAL) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_MODE_GIMBAL - for _, label := range labels { - found := false - for value, l := range labels_MAV_MODE_GIMBAL { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_MODE_GIMBAL[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_MODE_GIMBAL) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_MODE_GIMBAL[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_commands.go b/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_commands.go index e96b96099..3851585f3 100644 --- a/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_commands.go +++ b/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_commands.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // Special ACK block numbers control activation of dataflash log streaming. @@ -22,40 +22,35 @@ var labels_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS = map[MAV_REMOTE_LOG_DATA_BLOCK_CO MAV_REMOTE_LOG_DATA_BLOCK_START: "MAV_REMOTE_LOG_DATA_BLOCK_START", } +var values_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS = map[string]MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS{ + "MAV_REMOTE_LOG_DATA_BLOCK_STOP": MAV_REMOTE_LOG_DATA_BLOCK_STOP, + "MAV_REMOTE_LOG_DATA_BLOCK_START": MAV_REMOTE_LOG_DATA_BLOCK_START, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS - for _, label := range labels { - found := false - for value, l := range labels_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_REMOTE_LOG_DATA_BLOCK_COMMANDS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_statuses.go b/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_statuses.go index 206e350fa..887d91019 100644 --- a/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_statuses.go +++ b/pkg/dialects/ardupilotmega/enum_mav_remote_log_data_block_statuses.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // Possible remote log data block statuses. @@ -22,40 +22,35 @@ var labels_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES = map[MAV_REMOTE_LOG_DATA_BLOCK_ST MAV_REMOTE_LOG_DATA_BLOCK_ACK: "MAV_REMOTE_LOG_DATA_BLOCK_ACK", } +var values_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES = map[string]MAV_REMOTE_LOG_DATA_BLOCK_STATUSES{ + "MAV_REMOTE_LOG_DATA_BLOCK_NACK": MAV_REMOTE_LOG_DATA_BLOCK_NACK, + "MAV_REMOTE_LOG_DATA_BLOCK_ACK": MAV_REMOTE_LOG_DATA_BLOCK_ACK, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_REMOTE_LOG_DATA_BLOCK_STATUSES) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_REMOTE_LOG_DATA_BLOCK_STATUSES) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_REMOTE_LOG_DATA_BLOCK_STATUSES - for _, label := range labels { - found := false - for value, l := range labels_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_REMOTE_LOG_DATA_BLOCK_STATUSES) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_REMOTE_LOG_DATA_BLOCK_STATUSES[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_osd_param_config_error.go b/pkg/dialects/ardupilotmega/enum_osd_param_config_error.go index 3de5fc205..f0fac172e 100644 --- a/pkg/dialects/ardupilotmega/enum_osd_param_config_error.go +++ b/pkg/dialects/ardupilotmega/enum_osd_param_config_error.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // The error type for the OSD parameter editor. @@ -24,40 +24,37 @@ var labels_OSD_PARAM_CONFIG_ERROR = map[OSD_PARAM_CONFIG_ERROR]string{ OSD_PARAM_INVALID_PARAMETER: "OSD_PARAM_INVALID_PARAMETER", } +var values_OSD_PARAM_CONFIG_ERROR = map[string]OSD_PARAM_CONFIG_ERROR{ + "OSD_PARAM_SUCCESS": OSD_PARAM_SUCCESS, + "OSD_PARAM_INVALID_SCREEN": OSD_PARAM_INVALID_SCREEN, + "OSD_PARAM_INVALID_PARAMETER_INDEX": OSD_PARAM_INVALID_PARAMETER_INDEX, + "OSD_PARAM_INVALID_PARAMETER": OSD_PARAM_INVALID_PARAMETER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e OSD_PARAM_CONFIG_ERROR) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_OSD_PARAM_CONFIG_ERROR { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_OSD_PARAM_CONFIG_ERROR[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *OSD_PARAM_CONFIG_ERROR) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask OSD_PARAM_CONFIG_ERROR - for _, label := range labels { - found := false - for value, l := range labels_OSD_PARAM_CONFIG_ERROR { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_OSD_PARAM_CONFIG_ERROR[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e OSD_PARAM_CONFIG_ERROR) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_OSD_PARAM_CONFIG_ERROR[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_osd_param_config_type.go b/pkg/dialects/ardupilotmega/enum_osd_param_config_type.go index f22680ba8..be8ad0b2a 100644 --- a/pkg/dialects/ardupilotmega/enum_osd_param_config_type.go +++ b/pkg/dialects/ardupilotmega/enum_osd_param_config_type.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // The type of parameter for the OSD parameter editor. @@ -34,40 +34,42 @@ var labels_OSD_PARAM_CONFIG_TYPE = map[OSD_PARAM_CONFIG_TYPE]string{ OSD_PARAM_NUM_TYPES: "OSD_PARAM_NUM_TYPES", } +var values_OSD_PARAM_CONFIG_TYPE = map[string]OSD_PARAM_CONFIG_TYPE{ + "OSD_PARAM_NONE": OSD_PARAM_NONE, + "OSD_PARAM_SERIAL_PROTOCOL": OSD_PARAM_SERIAL_PROTOCOL, + "OSD_PARAM_SERVO_FUNCTION": OSD_PARAM_SERVO_FUNCTION, + "OSD_PARAM_AUX_FUNCTION": OSD_PARAM_AUX_FUNCTION, + "OSD_PARAM_FLIGHT_MODE": OSD_PARAM_FLIGHT_MODE, + "OSD_PARAM_FAILSAFE_ACTION": OSD_PARAM_FAILSAFE_ACTION, + "OSD_PARAM_FAILSAFE_ACTION_1": OSD_PARAM_FAILSAFE_ACTION_1, + "OSD_PARAM_FAILSAFE_ACTION_2": OSD_PARAM_FAILSAFE_ACTION_2, + "OSD_PARAM_NUM_TYPES": OSD_PARAM_NUM_TYPES, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e OSD_PARAM_CONFIG_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_OSD_PARAM_CONFIG_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_OSD_PARAM_CONFIG_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *OSD_PARAM_CONFIG_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask OSD_PARAM_CONFIG_TYPE - for _, label := range labels { - found := false - for value, l := range labels_OSD_PARAM_CONFIG_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_OSD_PARAM_CONFIG_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e OSD_PARAM_CONFIG_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_OSD_PARAM_CONFIG_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_pid_tuning_axis.go b/pkg/dialects/ardupilotmega/enum_pid_tuning_axis.go index 7ce5aa8e1..6756537d2 100644 --- a/pkg/dialects/ardupilotmega/enum_pid_tuning_axis.go +++ b/pkg/dialects/ardupilotmega/enum_pid_tuning_axis.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type PID_TUNING_AXIS uint32 @@ -27,40 +27,39 @@ var labels_PID_TUNING_AXIS = map[PID_TUNING_AXIS]string{ PID_TUNING_LANDING: "PID_TUNING_LANDING", } +var values_PID_TUNING_AXIS = map[string]PID_TUNING_AXIS{ + "PID_TUNING_ROLL": PID_TUNING_ROLL, + "PID_TUNING_PITCH": PID_TUNING_PITCH, + "PID_TUNING_YAW": PID_TUNING_YAW, + "PID_TUNING_ACCZ": PID_TUNING_ACCZ, + "PID_TUNING_STEER": PID_TUNING_STEER, + "PID_TUNING_LANDING": PID_TUNING_LANDING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PID_TUNING_AXIS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PID_TUNING_AXIS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PID_TUNING_AXIS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PID_TUNING_AXIS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PID_TUNING_AXIS - for _, label := range labels { - found := false - for value, l := range labels_PID_TUNING_AXIS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PID_TUNING_AXIS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PID_TUNING_AXIS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PID_TUNING_AXIS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_plane_mode.go b/pkg/dialects/ardupilotmega/enum_plane_mode.go index 644c73aa8..e53f87405 100644 --- a/pkg/dialects/ardupilotmega/enum_plane_mode.go +++ b/pkg/dialects/ardupilotmega/enum_plane_mode.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // A mapping of plane flight modes for custom_mode field of heartbeat. @@ -64,40 +64,57 @@ var labels_PLANE_MODE = map[PLANE_MODE]string{ PLANE_MODE_THERMAL: "PLANE_MODE_THERMAL", } +var values_PLANE_MODE = map[string]PLANE_MODE{ + "PLANE_MODE_MANUAL": PLANE_MODE_MANUAL, + "PLANE_MODE_CIRCLE": PLANE_MODE_CIRCLE, + "PLANE_MODE_STABILIZE": PLANE_MODE_STABILIZE, + "PLANE_MODE_TRAINING": PLANE_MODE_TRAINING, + "PLANE_MODE_ACRO": PLANE_MODE_ACRO, + "PLANE_MODE_FLY_BY_WIRE_A": PLANE_MODE_FLY_BY_WIRE_A, + "PLANE_MODE_FLY_BY_WIRE_B": PLANE_MODE_FLY_BY_WIRE_B, + "PLANE_MODE_CRUISE": PLANE_MODE_CRUISE, + "PLANE_MODE_AUTOTUNE": PLANE_MODE_AUTOTUNE, + "PLANE_MODE_AUTO": PLANE_MODE_AUTO, + "PLANE_MODE_RTL": PLANE_MODE_RTL, + "PLANE_MODE_LOITER": PLANE_MODE_LOITER, + "PLANE_MODE_TAKEOFF": PLANE_MODE_TAKEOFF, + "PLANE_MODE_AVOID_ADSB": PLANE_MODE_AVOID_ADSB, + "PLANE_MODE_GUIDED": PLANE_MODE_GUIDED, + "PLANE_MODE_INITIALIZING": PLANE_MODE_INITIALIZING, + "PLANE_MODE_QSTABILIZE": PLANE_MODE_QSTABILIZE, + "PLANE_MODE_QHOVER": PLANE_MODE_QHOVER, + "PLANE_MODE_QLOITER": PLANE_MODE_QLOITER, + "PLANE_MODE_QLAND": PLANE_MODE_QLAND, + "PLANE_MODE_QRTL": PLANE_MODE_QRTL, + "PLANE_MODE_QAUTOTUNE": PLANE_MODE_QAUTOTUNE, + "PLANE_MODE_QACRO": PLANE_MODE_QACRO, + "PLANE_MODE_THERMAL": PLANE_MODE_THERMAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PLANE_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PLANE_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PLANE_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PLANE_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PLANE_MODE - for _, label := range labels { - found := false - for value, l := range labels_PLANE_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PLANE_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PLANE_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PLANE_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_rally_flags.go b/pkg/dialects/ardupilotmega/enum_rally_flags.go index a1bf97892..dfc98f886 100644 --- a/pkg/dialects/ardupilotmega/enum_rally_flags.go +++ b/pkg/dialects/ardupilotmega/enum_rally_flags.go @@ -22,12 +22,18 @@ var labels_RALLY_FLAGS = map[RALLY_FLAGS]string{ LAND_IMMEDIATELY: "LAND_IMMEDIATELY", } +var values_RALLY_FLAGS = map[string]RALLY_FLAGS{ + "FAVORABLE_WIND": FAVORABLE_WIND, + "LAND_IMMEDIATELY": LAND_IMMEDIATELY, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e RALLY_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_RALLY_FLAGS { + for i := 0; i < 2; i++ { + mask := RALLY_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_RALLY_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -38,19 +44,12 @@ func (e *RALLY_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask RALLY_FLAGS for _, label := range labels { - found := false - for value, l := range labels_RALLY_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_RALLY_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/ardupilotmega/enum_rover_mode.go b/pkg/dialects/ardupilotmega/enum_rover_mode.go index 1b556be8e..50d017246 100644 --- a/pkg/dialects/ardupilotmega/enum_rover_mode.go +++ b/pkg/dialects/ardupilotmega/enum_rover_mode.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // A mapping of rover flight modes for custom_mode field of heartbeat. @@ -40,40 +40,45 @@ var labels_ROVER_MODE = map[ROVER_MODE]string{ ROVER_MODE_INITIALIZING: "ROVER_MODE_INITIALIZING", } +var values_ROVER_MODE = map[string]ROVER_MODE{ + "ROVER_MODE_MANUAL": ROVER_MODE_MANUAL, + "ROVER_MODE_ACRO": ROVER_MODE_ACRO, + "ROVER_MODE_STEERING": ROVER_MODE_STEERING, + "ROVER_MODE_HOLD": ROVER_MODE_HOLD, + "ROVER_MODE_LOITER": ROVER_MODE_LOITER, + "ROVER_MODE_FOLLOW": ROVER_MODE_FOLLOW, + "ROVER_MODE_SIMPLE": ROVER_MODE_SIMPLE, + "ROVER_MODE_AUTO": ROVER_MODE_AUTO, + "ROVER_MODE_RTL": ROVER_MODE_RTL, + "ROVER_MODE_SMART_RTL": ROVER_MODE_SMART_RTL, + "ROVER_MODE_GUIDED": ROVER_MODE_GUIDED, + "ROVER_MODE_INITIALIZING": ROVER_MODE_INITIALIZING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ROVER_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ROVER_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ROVER_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ROVER_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ROVER_MODE - for _, label := range labels { - found := false - for value, l := range labels_ROVER_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ROVER_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ROVER_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ROVER_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_scripting_cmd.go b/pkg/dialects/ardupilotmega/enum_scripting_cmd.go index 982888c8f..44628079b 100644 --- a/pkg/dialects/ardupilotmega/enum_scripting_cmd.go +++ b/pkg/dialects/ardupilotmega/enum_scripting_cmd.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type SCRIPTING_CMD uint32 @@ -27,40 +27,37 @@ var labels_SCRIPTING_CMD = map[SCRIPTING_CMD]string{ SCRIPTING_CMD_STOP_AND_RESTART: "SCRIPTING_CMD_STOP_AND_RESTART", } +var values_SCRIPTING_CMD = map[string]SCRIPTING_CMD{ + "SCRIPTING_CMD_REPL_START": SCRIPTING_CMD_REPL_START, + "SCRIPTING_CMD_REPL_STOP": SCRIPTING_CMD_REPL_STOP, + "SCRIPTING_CMD_STOP": SCRIPTING_CMD_STOP, + "SCRIPTING_CMD_STOP_AND_RESTART": SCRIPTING_CMD_STOP_AND_RESTART, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e SCRIPTING_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_SCRIPTING_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_SCRIPTING_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *SCRIPTING_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask SCRIPTING_CMD - for _, label := range labels { - found := false - for value, l := range labels_SCRIPTING_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_SCRIPTING_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e SCRIPTING_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_SCRIPTING_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_speed_type.go b/pkg/dialects/ardupilotmega/enum_speed_type.go index 356fcf679..0ce8e5950 100644 --- a/pkg/dialects/ardupilotmega/enum_speed_type.go +++ b/pkg/dialects/ardupilotmega/enum_speed_type.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) type SPEED_TYPE uint32 @@ -19,40 +19,35 @@ var labels_SPEED_TYPE = map[SPEED_TYPE]string{ SPEED_TYPE_GROUNDSPEED: "SPEED_TYPE_GROUNDSPEED", } +var values_SPEED_TYPE = map[string]SPEED_TYPE{ + "SPEED_TYPE_AIRSPEED": SPEED_TYPE_AIRSPEED, + "SPEED_TYPE_GROUNDSPEED": SPEED_TYPE_GROUNDSPEED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e SPEED_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_SPEED_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_SPEED_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *SPEED_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask SPEED_TYPE - for _, label := range labels { - found := false - for value, l := range labels_SPEED_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_SPEED_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e SPEED_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_SPEED_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_sub_mode.go b/pkg/dialects/ardupilotmega/enum_sub_mode.go index 9bc3b6f2f..38e81fa32 100644 --- a/pkg/dialects/ardupilotmega/enum_sub_mode.go +++ b/pkg/dialects/ardupilotmega/enum_sub_mode.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // A mapping of sub flight modes for custom_mode field of heartbeat. @@ -34,40 +34,42 @@ var labels_SUB_MODE = map[SUB_MODE]string{ SUB_MODE_MANUAL: "SUB_MODE_MANUAL", } +var values_SUB_MODE = map[string]SUB_MODE{ + "SUB_MODE_STABILIZE": SUB_MODE_STABILIZE, + "SUB_MODE_ACRO": SUB_MODE_ACRO, + "SUB_MODE_ALT_HOLD": SUB_MODE_ALT_HOLD, + "SUB_MODE_AUTO": SUB_MODE_AUTO, + "SUB_MODE_GUIDED": SUB_MODE_GUIDED, + "SUB_MODE_CIRCLE": SUB_MODE_CIRCLE, + "SUB_MODE_SURFACE": SUB_MODE_SURFACE, + "SUB_MODE_POSHOLD": SUB_MODE_POSHOLD, + "SUB_MODE_MANUAL": SUB_MODE_MANUAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e SUB_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_SUB_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_SUB_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *SUB_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask SUB_MODE - for _, label := range labels { - found := false - for value, l := range labels_SUB_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_SUB_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e SUB_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_SUB_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ardupilotmega/enum_tracker_mode.go b/pkg/dialects/ardupilotmega/enum_tracker_mode.go index bdc83a17d..2ab33b8a7 100644 --- a/pkg/dialects/ardupilotmega/enum_tracker_mode.go +++ b/pkg/dialects/ardupilotmega/enum_tracker_mode.go @@ -4,7 +4,7 @@ package ardupilotmega import ( "fmt" - "strings" + "strconv" ) // A mapping of antenna tracker flight modes for custom_mode field of heartbeat. @@ -28,40 +28,39 @@ var labels_TRACKER_MODE = map[TRACKER_MODE]string{ TRACKER_MODE_INITIALIZING: "TRACKER_MODE_INITIALIZING", } +var values_TRACKER_MODE = map[string]TRACKER_MODE{ + "TRACKER_MODE_MANUAL": TRACKER_MODE_MANUAL, + "TRACKER_MODE_STOP": TRACKER_MODE_STOP, + "TRACKER_MODE_SCAN": TRACKER_MODE_SCAN, + "TRACKER_MODE_SERVO_TEST": TRACKER_MODE_SERVO_TEST, + "TRACKER_MODE_AUTO": TRACKER_MODE_AUTO, + "TRACKER_MODE_INITIALIZING": TRACKER_MODE_INITIALIZING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e TRACKER_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_TRACKER_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_TRACKER_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *TRACKER_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask TRACKER_MODE - for _, label := range labels { - found := false - for value, l := range labels_TRACKER_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_TRACKER_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e TRACKER_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_TRACKER_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/asluav/enum_gsm_link_type.go b/pkg/dialects/asluav/enum_gsm_link_type.go index 204a37411..da4272d0b 100644 --- a/pkg/dialects/asluav/enum_gsm_link_type.go +++ b/pkg/dialects/asluav/enum_gsm_link_type.go @@ -4,7 +4,7 @@ package asluav import ( "fmt" - "strings" + "strconv" ) type GSM_LINK_TYPE uint32 @@ -30,40 +30,38 @@ var labels_GSM_LINK_TYPE = map[GSM_LINK_TYPE]string{ GSM_LINK_TYPE_4G: "GSM_LINK_TYPE_4G", } +var values_GSM_LINK_TYPE = map[string]GSM_LINK_TYPE{ + "GSM_LINK_TYPE_NONE": GSM_LINK_TYPE_NONE, + "GSM_LINK_TYPE_UNKNOWN": GSM_LINK_TYPE_UNKNOWN, + "GSM_LINK_TYPE_2G": GSM_LINK_TYPE_2G, + "GSM_LINK_TYPE_3G": GSM_LINK_TYPE_3G, + "GSM_LINK_TYPE_4G": GSM_LINK_TYPE_4G, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GSM_LINK_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GSM_LINK_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GSM_LINK_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GSM_LINK_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GSM_LINK_TYPE - for _, label := range labels { - found := false - for value, l := range labels_GSM_LINK_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GSM_LINK_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GSM_LINK_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GSM_LINK_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/asluav/enum_gsm_modem_type.go b/pkg/dialects/asluav/enum_gsm_modem_type.go index ed78b7e8c..37be8cd31 100644 --- a/pkg/dialects/asluav/enum_gsm_modem_type.go +++ b/pkg/dialects/asluav/enum_gsm_modem_type.go @@ -4,7 +4,7 @@ package asluav import ( "fmt" - "strings" + "strconv" ) type GSM_MODEM_TYPE uint32 @@ -21,40 +21,35 @@ var labels_GSM_MODEM_TYPE = map[GSM_MODEM_TYPE]string{ GSM_MODEM_TYPE_HUAWEI_E3372: "GSM_MODEM_TYPE_HUAWEI_E3372", } +var values_GSM_MODEM_TYPE = map[string]GSM_MODEM_TYPE{ + "GSM_MODEM_TYPE_UNKNOWN": GSM_MODEM_TYPE_UNKNOWN, + "GSM_MODEM_TYPE_HUAWEI_E3372": GSM_MODEM_TYPE_HUAWEI_E3372, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GSM_MODEM_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GSM_MODEM_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GSM_MODEM_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GSM_MODEM_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GSM_MODEM_TYPE - for _, label := range labels { - found := false - for value, l := range labels_GSM_MODEM_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GSM_MODEM_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GSM_MODEM_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GSM_MODEM_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/asluav/enum_mav_cmd.go b/pkg/dialects/asluav/enum_mav_cmd.go index 462339300..b23311832 100644 --- a/pkg/dialects/asluav/enum_mav_cmd.go +++ b/pkg/dialects/asluav/enum_mav_cmd.go @@ -4,7 +4,7 @@ package asluav import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -548,40 +548,194 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_PAYLOAD_CONTROL: "MAV_CMD_PAYLOAD_CONTROL", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_RESET_MPPT": MAV_CMD_RESET_MPPT, + "MAV_CMD_PAYLOAD_CONTROL": MAV_CMD_PAYLOAD_CONTROL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/avssuas/enum_avss_horsefly_operation_mode.go b/pkg/dialects/avssuas/enum_avss_horsefly_operation_mode.go index a8a22c5ee..10890e892 100644 --- a/pkg/dialects/avssuas/enum_avss_horsefly_operation_mode.go +++ b/pkg/dialects/avssuas/enum_avss_horsefly_operation_mode.go @@ -4,7 +4,7 @@ package avssuas import ( "fmt" - "strings" + "strconv" ) type AVSS_HORSEFLY_OPERATION_MODE uint32 @@ -30,40 +30,38 @@ var labels_AVSS_HORSEFLY_OPERATION_MODE = map[AVSS_HORSEFLY_OPERATION_MODE]strin MODE_HORSEFLY_DROP: "MODE_HORSEFLY_DROP", } +var values_AVSS_HORSEFLY_OPERATION_MODE = map[string]AVSS_HORSEFLY_OPERATION_MODE{ + "MODE_HORSEFLY_MANUAL_CTRL": MODE_HORSEFLY_MANUAL_CTRL, + "MODE_HORSEFLY_AUTO_TAKEOFF": MODE_HORSEFLY_AUTO_TAKEOFF, + "MODE_HORSEFLY_AUTO_LANDING": MODE_HORSEFLY_AUTO_LANDING, + "MODE_HORSEFLY_NAVI_GO_HOME": MODE_HORSEFLY_NAVI_GO_HOME, + "MODE_HORSEFLY_DROP": MODE_HORSEFLY_DROP, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AVSS_HORSEFLY_OPERATION_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_AVSS_HORSEFLY_OPERATION_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_AVSS_HORSEFLY_OPERATION_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *AVSS_HORSEFLY_OPERATION_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask AVSS_HORSEFLY_OPERATION_MODE - for _, label := range labels { - found := false - for value, l := range labels_AVSS_HORSEFLY_OPERATION_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_AVSS_HORSEFLY_OPERATION_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e AVSS_HORSEFLY_OPERATION_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_AVSS_HORSEFLY_OPERATION_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/avssuas/enum_avss_m300_operation_mode.go b/pkg/dialects/avssuas/enum_avss_m300_operation_mode.go index 03bf55660..680f41b4a 100644 --- a/pkg/dialects/avssuas/enum_avss_m300_operation_mode.go +++ b/pkg/dialects/avssuas/enum_avss_m300_operation_mode.go @@ -4,7 +4,7 @@ package avssuas import ( "fmt" - "strings" + "strconv" ) type AVSS_M300_OPERATION_MODE uint32 @@ -57,40 +57,47 @@ var labels_AVSS_M300_OPERATION_MODE = map[AVSS_M300_OPERATION_MODE]string{ MODE_M300_ENGINE_START: "MODE_M300_ENGINE_START", } +var values_AVSS_M300_OPERATION_MODE = map[string]AVSS_M300_OPERATION_MODE{ + "MODE_M300_MANUAL_CTRL": MODE_M300_MANUAL_CTRL, + "MODE_M300_ATTITUDE": MODE_M300_ATTITUDE, + "MODE_M300_P_GPS": MODE_M300_P_GPS, + "MODE_M300_HOTPOINT_MODE": MODE_M300_HOTPOINT_MODE, + "MODE_M300_ASSISTED_TAKEOFF": MODE_M300_ASSISTED_TAKEOFF, + "MODE_M300_AUTO_TAKEOFF": MODE_M300_AUTO_TAKEOFF, + "MODE_M300_AUTO_LANDING": MODE_M300_AUTO_LANDING, + "MODE_M300_NAVI_GO_HOME": MODE_M300_NAVI_GO_HOME, + "MODE_M300_NAVI_SDK_CTRL": MODE_M300_NAVI_SDK_CTRL, + "MODE_M300_S_SPORT": MODE_M300_S_SPORT, + "MODE_M300_FORCE_AUTO_LANDING": MODE_M300_FORCE_AUTO_LANDING, + "MODE_M300_T_TRIPOD": MODE_M300_T_TRIPOD, + "MODE_M300_SEARCH_MODE": MODE_M300_SEARCH_MODE, + "MODE_M300_ENGINE_START": MODE_M300_ENGINE_START, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AVSS_M300_OPERATION_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_AVSS_M300_OPERATION_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_AVSS_M300_OPERATION_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *AVSS_M300_OPERATION_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask AVSS_M300_OPERATION_MODE - for _, label := range labels { - found := false - for value, l := range labels_AVSS_M300_OPERATION_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_AVSS_M300_OPERATION_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e AVSS_M300_OPERATION_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_AVSS_M300_OPERATION_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/avssuas/enum_mav_avss_command_failure_reason.go b/pkg/dialects/avssuas/enum_mav_avss_command_failure_reason.go index 2aba4ae13..bb0a6eb08 100644 --- a/pkg/dialects/avssuas/enum_mav_avss_command_failure_reason.go +++ b/pkg/dialects/avssuas/enum_mav_avss_command_failure_reason.go @@ -4,7 +4,7 @@ package avssuas import ( "fmt" - "strings" + "strconv" ) type MAV_AVSS_COMMAND_FAILURE_REASON uint32 @@ -24,40 +24,36 @@ var labels_MAV_AVSS_COMMAND_FAILURE_REASON = map[MAV_AVSS_COMMAND_FAILURE_REASON PRS_OTM_NOT_ARMED: "PRS_OTM_NOT_ARMED", } +var values_MAV_AVSS_COMMAND_FAILURE_REASON = map[string]MAV_AVSS_COMMAND_FAILURE_REASON{ + "PRS_NOT_STEADY": PRS_NOT_STEADY, + "PRS_DTM_NOT_ARMED": PRS_DTM_NOT_ARMED, + "PRS_OTM_NOT_ARMED": PRS_OTM_NOT_ARMED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_AVSS_COMMAND_FAILURE_REASON) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_AVSS_COMMAND_FAILURE_REASON { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_AVSS_COMMAND_FAILURE_REASON[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_AVSS_COMMAND_FAILURE_REASON) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_AVSS_COMMAND_FAILURE_REASON - for _, label := range labels { - found := false - for value, l := range labels_MAV_AVSS_COMMAND_FAILURE_REASON { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_AVSS_COMMAND_FAILURE_REASON[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_AVSS_COMMAND_FAILURE_REASON) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_AVSS_COMMAND_FAILURE_REASON[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/avssuas/enum_mav_cmd.go b/pkg/dialects/avssuas/enum_mav_cmd.go index a2f54b1e6..f3082da53 100644 --- a/pkg/dialects/avssuas/enum_mav_cmd.go +++ b/pkg/dialects/avssuas/enum_mav_cmd.go @@ -4,7 +4,7 @@ package avssuas import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -563,40 +563,199 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_PRS_SHUTDOWN: "MAV_CMD_PRS_SHUTDOWN", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_PRS_SET_ARM": MAV_CMD_PRS_SET_ARM, + "MAV_CMD_PRS_GET_ARM": MAV_CMD_PRS_GET_ARM, + "MAV_CMD_PRS_GET_BATTERY": MAV_CMD_PRS_GET_BATTERY, + "MAV_CMD_PRS_GET_ERR": MAV_CMD_PRS_GET_ERR, + "MAV_CMD_PRS_SET_ARM_ALTI": MAV_CMD_PRS_SET_ARM_ALTI, + "MAV_CMD_PRS_GET_ARM_ALTI": MAV_CMD_PRS_GET_ARM_ALTI, + "MAV_CMD_PRS_SHUTDOWN": MAV_CMD_PRS_SHUTDOWN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_actuator_configuration.go b/pkg/dialects/common/enum_actuator_configuration.go index ce658796c..3eae5c2f8 100644 --- a/pkg/dialects/common/enum_actuator_configuration.go +++ b/pkg/dialects/common/enum_actuator_configuration.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actuator configuration, used to change a setting on an actuator. Component information metadata can be used to know which outputs support which commands. @@ -34,40 +34,39 @@ var labels_ACTUATOR_CONFIGURATION = map[ACTUATOR_CONFIGURATION]string{ ACTUATOR_CONFIGURATION_SPIN_DIRECTION2: "ACTUATOR_CONFIGURATION_SPIN_DIRECTION2", } +var values_ACTUATOR_CONFIGURATION = map[string]ACTUATOR_CONFIGURATION{ + "ACTUATOR_CONFIGURATION_NONE": ACTUATOR_CONFIGURATION_NONE, + "ACTUATOR_CONFIGURATION_BEEP": ACTUATOR_CONFIGURATION_BEEP, + "ACTUATOR_CONFIGURATION_3D_MODE_ON": ACTUATOR_CONFIGURATION_3D_MODE_ON, + "ACTUATOR_CONFIGURATION_3D_MODE_OFF": ACTUATOR_CONFIGURATION_3D_MODE_OFF, + "ACTUATOR_CONFIGURATION_SPIN_DIRECTION1": ACTUATOR_CONFIGURATION_SPIN_DIRECTION1, + "ACTUATOR_CONFIGURATION_SPIN_DIRECTION2": ACTUATOR_CONFIGURATION_SPIN_DIRECTION2, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ACTUATOR_CONFIGURATION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ACTUATOR_CONFIGURATION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ACTUATOR_CONFIGURATION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ACTUATOR_CONFIGURATION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ACTUATOR_CONFIGURATION - for _, label := range labels { - found := false - for value, l := range labels_ACTUATOR_CONFIGURATION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ACTUATOR_CONFIGURATION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ACTUATOR_CONFIGURATION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ACTUATOR_CONFIGURATION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_actuator_output_function.go b/pkg/dialects/common/enum_actuator_output_function.go index d96fc3a34..3d17bf854 100644 --- a/pkg/dialects/common/enum_actuator_output_function.go +++ b/pkg/dialects/common/enum_actuator_output_function.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actuator output function. Values greater or equal to 1000 are autopilot-specific. @@ -115,40 +115,66 @@ var labels_ACTUATOR_OUTPUT_FUNCTION = map[ACTUATOR_OUTPUT_FUNCTION]string{ ACTUATOR_OUTPUT_FUNCTION_SERVO16: "ACTUATOR_OUTPUT_FUNCTION_SERVO16", } +var values_ACTUATOR_OUTPUT_FUNCTION = map[string]ACTUATOR_OUTPUT_FUNCTION{ + "ACTUATOR_OUTPUT_FUNCTION_NONE": ACTUATOR_OUTPUT_FUNCTION_NONE, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR1": ACTUATOR_OUTPUT_FUNCTION_MOTOR1, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR2": ACTUATOR_OUTPUT_FUNCTION_MOTOR2, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR3": ACTUATOR_OUTPUT_FUNCTION_MOTOR3, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR4": ACTUATOR_OUTPUT_FUNCTION_MOTOR4, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR5": ACTUATOR_OUTPUT_FUNCTION_MOTOR5, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR6": ACTUATOR_OUTPUT_FUNCTION_MOTOR6, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR7": ACTUATOR_OUTPUT_FUNCTION_MOTOR7, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR8": ACTUATOR_OUTPUT_FUNCTION_MOTOR8, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR9": ACTUATOR_OUTPUT_FUNCTION_MOTOR9, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR10": ACTUATOR_OUTPUT_FUNCTION_MOTOR10, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR11": ACTUATOR_OUTPUT_FUNCTION_MOTOR11, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR12": ACTUATOR_OUTPUT_FUNCTION_MOTOR12, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR13": ACTUATOR_OUTPUT_FUNCTION_MOTOR13, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR14": ACTUATOR_OUTPUT_FUNCTION_MOTOR14, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR15": ACTUATOR_OUTPUT_FUNCTION_MOTOR15, + "ACTUATOR_OUTPUT_FUNCTION_MOTOR16": ACTUATOR_OUTPUT_FUNCTION_MOTOR16, + "ACTUATOR_OUTPUT_FUNCTION_SERVO1": ACTUATOR_OUTPUT_FUNCTION_SERVO1, + "ACTUATOR_OUTPUT_FUNCTION_SERVO2": ACTUATOR_OUTPUT_FUNCTION_SERVO2, + "ACTUATOR_OUTPUT_FUNCTION_SERVO3": ACTUATOR_OUTPUT_FUNCTION_SERVO3, + "ACTUATOR_OUTPUT_FUNCTION_SERVO4": ACTUATOR_OUTPUT_FUNCTION_SERVO4, + "ACTUATOR_OUTPUT_FUNCTION_SERVO5": ACTUATOR_OUTPUT_FUNCTION_SERVO5, + "ACTUATOR_OUTPUT_FUNCTION_SERVO6": ACTUATOR_OUTPUT_FUNCTION_SERVO6, + "ACTUATOR_OUTPUT_FUNCTION_SERVO7": ACTUATOR_OUTPUT_FUNCTION_SERVO7, + "ACTUATOR_OUTPUT_FUNCTION_SERVO8": ACTUATOR_OUTPUT_FUNCTION_SERVO8, + "ACTUATOR_OUTPUT_FUNCTION_SERVO9": ACTUATOR_OUTPUT_FUNCTION_SERVO9, + "ACTUATOR_OUTPUT_FUNCTION_SERVO10": ACTUATOR_OUTPUT_FUNCTION_SERVO10, + "ACTUATOR_OUTPUT_FUNCTION_SERVO11": ACTUATOR_OUTPUT_FUNCTION_SERVO11, + "ACTUATOR_OUTPUT_FUNCTION_SERVO12": ACTUATOR_OUTPUT_FUNCTION_SERVO12, + "ACTUATOR_OUTPUT_FUNCTION_SERVO13": ACTUATOR_OUTPUT_FUNCTION_SERVO13, + "ACTUATOR_OUTPUT_FUNCTION_SERVO14": ACTUATOR_OUTPUT_FUNCTION_SERVO14, + "ACTUATOR_OUTPUT_FUNCTION_SERVO15": ACTUATOR_OUTPUT_FUNCTION_SERVO15, + "ACTUATOR_OUTPUT_FUNCTION_SERVO16": ACTUATOR_OUTPUT_FUNCTION_SERVO16, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ACTUATOR_OUTPUT_FUNCTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ACTUATOR_OUTPUT_FUNCTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ACTUATOR_OUTPUT_FUNCTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ACTUATOR_OUTPUT_FUNCTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ACTUATOR_OUTPUT_FUNCTION - for _, label := range labels { - found := false - for value, l := range labels_ACTUATOR_OUTPUT_FUNCTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ACTUATOR_OUTPUT_FUNCTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ACTUATOR_OUTPUT_FUNCTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ACTUATOR_OUTPUT_FUNCTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_adsb_altitude_type.go b/pkg/dialects/common/enum_adsb_altitude_type.go index 8d2c26a47..c6bc7c122 100644 --- a/pkg/dialects/common/enum_adsb_altitude_type.go +++ b/pkg/dialects/common/enum_adsb_altitude_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of the ADSB altimeter types @@ -22,40 +22,35 @@ var labels_ADSB_ALTITUDE_TYPE = map[ADSB_ALTITUDE_TYPE]string{ ADSB_ALTITUDE_TYPE_GEOMETRIC: "ADSB_ALTITUDE_TYPE_GEOMETRIC", } +var values_ADSB_ALTITUDE_TYPE = map[string]ADSB_ALTITUDE_TYPE{ + "ADSB_ALTITUDE_TYPE_PRESSURE_QNH": ADSB_ALTITUDE_TYPE_PRESSURE_QNH, + "ADSB_ALTITUDE_TYPE_GEOMETRIC": ADSB_ALTITUDE_TYPE_GEOMETRIC, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ADSB_ALTITUDE_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ADSB_ALTITUDE_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ADSB_ALTITUDE_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ADSB_ALTITUDE_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ADSB_ALTITUDE_TYPE - for _, label := range labels { - found := false - for value, l := range labels_ADSB_ALTITUDE_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ADSB_ALTITUDE_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ADSB_ALTITUDE_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ADSB_ALTITUDE_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_adsb_emitter_type.go b/pkg/dialects/common/enum_adsb_emitter_type.go index 4e0696d18..a1293fdd0 100644 --- a/pkg/dialects/common/enum_adsb_emitter_type.go +++ b/pkg/dialects/common/enum_adsb_emitter_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // ADSB classification for the type of vehicle emitting the transponder signal @@ -56,40 +56,53 @@ var labels_ADSB_EMITTER_TYPE = map[ADSB_EMITTER_TYPE]string{ ADSB_EMITTER_TYPE_POINT_OBSTACLE: "ADSB_EMITTER_TYPE_POINT_OBSTACLE", } +var values_ADSB_EMITTER_TYPE = map[string]ADSB_EMITTER_TYPE{ + "ADSB_EMITTER_TYPE_NO_INFO": ADSB_EMITTER_TYPE_NO_INFO, + "ADSB_EMITTER_TYPE_LIGHT": ADSB_EMITTER_TYPE_LIGHT, + "ADSB_EMITTER_TYPE_SMALL": ADSB_EMITTER_TYPE_SMALL, + "ADSB_EMITTER_TYPE_LARGE": ADSB_EMITTER_TYPE_LARGE, + "ADSB_EMITTER_TYPE_HIGH_VORTEX_LARGE": ADSB_EMITTER_TYPE_HIGH_VORTEX_LARGE, + "ADSB_EMITTER_TYPE_HEAVY": ADSB_EMITTER_TYPE_HEAVY, + "ADSB_EMITTER_TYPE_HIGHLY_MANUV": ADSB_EMITTER_TYPE_HIGHLY_MANUV, + "ADSB_EMITTER_TYPE_ROTOCRAFT": ADSB_EMITTER_TYPE_ROTOCRAFT, + "ADSB_EMITTER_TYPE_UNASSIGNED": ADSB_EMITTER_TYPE_UNASSIGNED, + "ADSB_EMITTER_TYPE_GLIDER": ADSB_EMITTER_TYPE_GLIDER, + "ADSB_EMITTER_TYPE_LIGHTER_AIR": ADSB_EMITTER_TYPE_LIGHTER_AIR, + "ADSB_EMITTER_TYPE_PARACHUTE": ADSB_EMITTER_TYPE_PARACHUTE, + "ADSB_EMITTER_TYPE_ULTRA_LIGHT": ADSB_EMITTER_TYPE_ULTRA_LIGHT, + "ADSB_EMITTER_TYPE_UNASSIGNED2": ADSB_EMITTER_TYPE_UNASSIGNED2, + "ADSB_EMITTER_TYPE_UAV": ADSB_EMITTER_TYPE_UAV, + "ADSB_EMITTER_TYPE_SPACE": ADSB_EMITTER_TYPE_SPACE, + "ADSB_EMITTER_TYPE_UNASSGINED3": ADSB_EMITTER_TYPE_UNASSGINED3, + "ADSB_EMITTER_TYPE_EMERGENCY_SURFACE": ADSB_EMITTER_TYPE_EMERGENCY_SURFACE, + "ADSB_EMITTER_TYPE_SERVICE_SURFACE": ADSB_EMITTER_TYPE_SERVICE_SURFACE, + "ADSB_EMITTER_TYPE_POINT_OBSTACLE": ADSB_EMITTER_TYPE_POINT_OBSTACLE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ADSB_EMITTER_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ADSB_EMITTER_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ADSB_EMITTER_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ADSB_EMITTER_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ADSB_EMITTER_TYPE - for _, label := range labels { - found := false - for value, l := range labels_ADSB_EMITTER_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ADSB_EMITTER_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ADSB_EMITTER_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ADSB_EMITTER_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_adsb_flags.go b/pkg/dialects/common/enum_adsb_flags.go index c5e7fe7f5..0a9723b4e 100644 --- a/pkg/dialects/common/enum_adsb_flags.go +++ b/pkg/dialects/common/enum_adsb_flags.go @@ -36,12 +36,26 @@ var labels_ADSB_FLAGS = map[ADSB_FLAGS]string{ ADSB_FLAGS_SOURCE_UAT: "ADSB_FLAGS_SOURCE_UAT", } +var values_ADSB_FLAGS = map[string]ADSB_FLAGS{ + "ADSB_FLAGS_VALID_COORDS": ADSB_FLAGS_VALID_COORDS, + "ADSB_FLAGS_VALID_ALTITUDE": ADSB_FLAGS_VALID_ALTITUDE, + "ADSB_FLAGS_VALID_HEADING": ADSB_FLAGS_VALID_HEADING, + "ADSB_FLAGS_VALID_VELOCITY": ADSB_FLAGS_VALID_VELOCITY, + "ADSB_FLAGS_VALID_CALLSIGN": ADSB_FLAGS_VALID_CALLSIGN, + "ADSB_FLAGS_VALID_SQUAWK": ADSB_FLAGS_VALID_SQUAWK, + "ADSB_FLAGS_SIMULATED": ADSB_FLAGS_SIMULATED, + "ADSB_FLAGS_VERTICAL_VELOCITY_VALID": ADSB_FLAGS_VERTICAL_VELOCITY_VALID, + "ADSB_FLAGS_BARO_VALID": ADSB_FLAGS_BARO_VALID, + "ADSB_FLAGS_SOURCE_UAT": ADSB_FLAGS_SOURCE_UAT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ADSB_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_ADSB_FLAGS { + for i := 0; i < 10; i++ { + mask := ADSB_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_ADSB_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -52,19 +66,12 @@ func (e *ADSB_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask ADSB_FLAGS for _, label := range labels { - found := false - for value, l := range labels_ADSB_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_ADSB_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_ais_flags.go b/pkg/dialects/common/enum_ais_flags.go index 921ff4565..bd40e03ea 100644 --- a/pkg/dialects/common/enum_ais_flags.go +++ b/pkg/dialects/common/enum_ais_flags.go @@ -49,12 +49,29 @@ var labels_AIS_FLAGS = map[AIS_FLAGS]string{ AIS_FLAGS_VALID_NAME: "AIS_FLAGS_VALID_NAME", } +var values_AIS_FLAGS = map[string]AIS_FLAGS{ + "AIS_FLAGS_POSITION_ACCURACY": AIS_FLAGS_POSITION_ACCURACY, + "AIS_FLAGS_VALID_COG": AIS_FLAGS_VALID_COG, + "AIS_FLAGS_VALID_VELOCITY": AIS_FLAGS_VALID_VELOCITY, + "AIS_FLAGS_HIGH_VELOCITY": AIS_FLAGS_HIGH_VELOCITY, + "AIS_FLAGS_VALID_TURN_RATE": AIS_FLAGS_VALID_TURN_RATE, + "AIS_FLAGS_TURN_RATE_SIGN_ONLY": AIS_FLAGS_TURN_RATE_SIGN_ONLY, + "AIS_FLAGS_VALID_DIMENSIONS": AIS_FLAGS_VALID_DIMENSIONS, + "AIS_FLAGS_LARGE_BOW_DIMENSION": AIS_FLAGS_LARGE_BOW_DIMENSION, + "AIS_FLAGS_LARGE_STERN_DIMENSION": AIS_FLAGS_LARGE_STERN_DIMENSION, + "AIS_FLAGS_LARGE_PORT_DIMENSION": AIS_FLAGS_LARGE_PORT_DIMENSION, + "AIS_FLAGS_LARGE_STARBOARD_DIMENSION": AIS_FLAGS_LARGE_STARBOARD_DIMENSION, + "AIS_FLAGS_VALID_CALLSIGN": AIS_FLAGS_VALID_CALLSIGN, + "AIS_FLAGS_VALID_NAME": AIS_FLAGS_VALID_NAME, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AIS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_AIS_FLAGS { + for i := 0; i < 13; i++ { + mask := AIS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_AIS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -65,19 +82,12 @@ func (e *AIS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask AIS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_AIS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_AIS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_ais_nav_status.go b/pkg/dialects/common/enum_ais_nav_status.go index 7a940d4f9..991c148d0 100644 --- a/pkg/dialects/common/enum_ais_nav_status.go +++ b/pkg/dialects/common/enum_ais_nav_status.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Navigational status of AIS vessel, enum duplicated from AIS standard, https://gpsd.gitlab.io/gpsd/AIVDM.html @@ -51,40 +51,49 @@ var labels_AIS_NAV_STATUS = map[AIS_NAV_STATUS]string{ AIS_NAV_UNKNOWN: "AIS_NAV_UNKNOWN", } +var values_AIS_NAV_STATUS = map[string]AIS_NAV_STATUS{ + "UNDER_WAY": UNDER_WAY, + "AIS_NAV_ANCHORED": AIS_NAV_ANCHORED, + "AIS_NAV_UN_COMMANDED": AIS_NAV_UN_COMMANDED, + "AIS_NAV_RESTRICTED_MANOEUVERABILITY": AIS_NAV_RESTRICTED_MANOEUVERABILITY, + "AIS_NAV_DRAUGHT_CONSTRAINED": AIS_NAV_DRAUGHT_CONSTRAINED, + "AIS_NAV_MOORED": AIS_NAV_MOORED, + "AIS_NAV_AGROUND": AIS_NAV_AGROUND, + "AIS_NAV_FISHING": AIS_NAV_FISHING, + "AIS_NAV_SAILING": AIS_NAV_SAILING, + "AIS_NAV_RESERVED_HSC": AIS_NAV_RESERVED_HSC, + "AIS_NAV_RESERVED_WIG": AIS_NAV_RESERVED_WIG, + "AIS_NAV_RESERVED_1": AIS_NAV_RESERVED_1, + "AIS_NAV_RESERVED_2": AIS_NAV_RESERVED_2, + "AIS_NAV_RESERVED_3": AIS_NAV_RESERVED_3, + "AIS_NAV_AIS_SART": AIS_NAV_AIS_SART, + "AIS_NAV_UNKNOWN": AIS_NAV_UNKNOWN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AIS_NAV_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_AIS_NAV_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_AIS_NAV_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *AIS_NAV_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask AIS_NAV_STATUS - for _, label := range labels { - found := false - for value, l := range labels_AIS_NAV_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_AIS_NAV_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e AIS_NAV_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_AIS_NAV_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_ais_type.go b/pkg/dialects/common/enum_ais_type.go index 9a9f8de42..1f56fe6f7 100644 --- a/pkg/dialects/common/enum_ais_type.go +++ b/pkg/dialects/common/enum_ais_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Type of AIS vessel, enum duplicated from AIS standard, https://gpsd.gitlab.io/gpsd/AIVDM.html @@ -224,40 +224,133 @@ var labels_AIS_TYPE = map[AIS_TYPE]string{ AIS_TYPE_OTHER_UNKNOWN: "AIS_TYPE_OTHER_UNKNOWN", } +var values_AIS_TYPE = map[string]AIS_TYPE{ + "AIS_TYPE_UNKNOWN": AIS_TYPE_UNKNOWN, + "AIS_TYPE_RESERVED_1": AIS_TYPE_RESERVED_1, + "AIS_TYPE_RESERVED_2": AIS_TYPE_RESERVED_2, + "AIS_TYPE_RESERVED_3": AIS_TYPE_RESERVED_3, + "AIS_TYPE_RESERVED_4": AIS_TYPE_RESERVED_4, + "AIS_TYPE_RESERVED_5": AIS_TYPE_RESERVED_5, + "AIS_TYPE_RESERVED_6": AIS_TYPE_RESERVED_6, + "AIS_TYPE_RESERVED_7": AIS_TYPE_RESERVED_7, + "AIS_TYPE_RESERVED_8": AIS_TYPE_RESERVED_8, + "AIS_TYPE_RESERVED_9": AIS_TYPE_RESERVED_9, + "AIS_TYPE_RESERVED_10": AIS_TYPE_RESERVED_10, + "AIS_TYPE_RESERVED_11": AIS_TYPE_RESERVED_11, + "AIS_TYPE_RESERVED_12": AIS_TYPE_RESERVED_12, + "AIS_TYPE_RESERVED_13": AIS_TYPE_RESERVED_13, + "AIS_TYPE_RESERVED_14": AIS_TYPE_RESERVED_14, + "AIS_TYPE_RESERVED_15": AIS_TYPE_RESERVED_15, + "AIS_TYPE_RESERVED_16": AIS_TYPE_RESERVED_16, + "AIS_TYPE_RESERVED_17": AIS_TYPE_RESERVED_17, + "AIS_TYPE_RESERVED_18": AIS_TYPE_RESERVED_18, + "AIS_TYPE_RESERVED_19": AIS_TYPE_RESERVED_19, + "AIS_TYPE_WIG": AIS_TYPE_WIG, + "AIS_TYPE_WIG_HAZARDOUS_A": AIS_TYPE_WIG_HAZARDOUS_A, + "AIS_TYPE_WIG_HAZARDOUS_B": AIS_TYPE_WIG_HAZARDOUS_B, + "AIS_TYPE_WIG_HAZARDOUS_C": AIS_TYPE_WIG_HAZARDOUS_C, + "AIS_TYPE_WIG_HAZARDOUS_D": AIS_TYPE_WIG_HAZARDOUS_D, + "AIS_TYPE_WIG_RESERVED_1": AIS_TYPE_WIG_RESERVED_1, + "AIS_TYPE_WIG_RESERVED_2": AIS_TYPE_WIG_RESERVED_2, + "AIS_TYPE_WIG_RESERVED_3": AIS_TYPE_WIG_RESERVED_3, + "AIS_TYPE_WIG_RESERVED_4": AIS_TYPE_WIG_RESERVED_4, + "AIS_TYPE_WIG_RESERVED_5": AIS_TYPE_WIG_RESERVED_5, + "AIS_TYPE_FISHING": AIS_TYPE_FISHING, + "AIS_TYPE_TOWING": AIS_TYPE_TOWING, + "AIS_TYPE_TOWING_LARGE": AIS_TYPE_TOWING_LARGE, + "AIS_TYPE_DREDGING": AIS_TYPE_DREDGING, + "AIS_TYPE_DIVING": AIS_TYPE_DIVING, + "AIS_TYPE_MILITARY": AIS_TYPE_MILITARY, + "AIS_TYPE_SAILING": AIS_TYPE_SAILING, + "AIS_TYPE_PLEASURE": AIS_TYPE_PLEASURE, + "AIS_TYPE_RESERVED_20": AIS_TYPE_RESERVED_20, + "AIS_TYPE_RESERVED_21": AIS_TYPE_RESERVED_21, + "AIS_TYPE_HSC": AIS_TYPE_HSC, + "AIS_TYPE_HSC_HAZARDOUS_A": AIS_TYPE_HSC_HAZARDOUS_A, + "AIS_TYPE_HSC_HAZARDOUS_B": AIS_TYPE_HSC_HAZARDOUS_B, + "AIS_TYPE_HSC_HAZARDOUS_C": AIS_TYPE_HSC_HAZARDOUS_C, + "AIS_TYPE_HSC_HAZARDOUS_D": AIS_TYPE_HSC_HAZARDOUS_D, + "AIS_TYPE_HSC_RESERVED_1": AIS_TYPE_HSC_RESERVED_1, + "AIS_TYPE_HSC_RESERVED_2": AIS_TYPE_HSC_RESERVED_2, + "AIS_TYPE_HSC_RESERVED_3": AIS_TYPE_HSC_RESERVED_3, + "AIS_TYPE_HSC_RESERVED_4": AIS_TYPE_HSC_RESERVED_4, + "AIS_TYPE_HSC_UNKNOWN": AIS_TYPE_HSC_UNKNOWN, + "AIS_TYPE_PILOT": AIS_TYPE_PILOT, + "AIS_TYPE_SAR": AIS_TYPE_SAR, + "AIS_TYPE_TUG": AIS_TYPE_TUG, + "AIS_TYPE_PORT_TENDER": AIS_TYPE_PORT_TENDER, + "AIS_TYPE_ANTI_POLLUTION": AIS_TYPE_ANTI_POLLUTION, + "AIS_TYPE_LAW_ENFORCEMENT": AIS_TYPE_LAW_ENFORCEMENT, + "AIS_TYPE_SPARE_LOCAL_1": AIS_TYPE_SPARE_LOCAL_1, + "AIS_TYPE_SPARE_LOCAL_2": AIS_TYPE_SPARE_LOCAL_2, + "AIS_TYPE_MEDICAL_TRANSPORT": AIS_TYPE_MEDICAL_TRANSPORT, + "AIS_TYPE_NONECOMBATANT": AIS_TYPE_NONECOMBATANT, + "AIS_TYPE_PASSENGER": AIS_TYPE_PASSENGER, + "AIS_TYPE_PASSENGER_HAZARDOUS_A": AIS_TYPE_PASSENGER_HAZARDOUS_A, + "AIS_TYPE_PASSENGER_HAZARDOUS_B": AIS_TYPE_PASSENGER_HAZARDOUS_B, + "AIS_TYPE_PASSENGER_HAZARDOUS_C": AIS_TYPE_PASSENGER_HAZARDOUS_C, + "AIS_TYPE_PASSENGER_HAZARDOUS_D": AIS_TYPE_PASSENGER_HAZARDOUS_D, + "AIS_TYPE_PASSENGER_RESERVED_1": AIS_TYPE_PASSENGER_RESERVED_1, + "AIS_TYPE_PASSENGER_RESERVED_2": AIS_TYPE_PASSENGER_RESERVED_2, + "AIS_TYPE_PASSENGER_RESERVED_3": AIS_TYPE_PASSENGER_RESERVED_3, + "AIS_TYPE_PASSENGER_RESERVED_4": AIS_TYPE_PASSENGER_RESERVED_4, + "AIS_TYPE_PASSENGER_UNKNOWN": AIS_TYPE_PASSENGER_UNKNOWN, + "AIS_TYPE_CARGO": AIS_TYPE_CARGO, + "AIS_TYPE_CARGO_HAZARDOUS_A": AIS_TYPE_CARGO_HAZARDOUS_A, + "AIS_TYPE_CARGO_HAZARDOUS_B": AIS_TYPE_CARGO_HAZARDOUS_B, + "AIS_TYPE_CARGO_HAZARDOUS_C": AIS_TYPE_CARGO_HAZARDOUS_C, + "AIS_TYPE_CARGO_HAZARDOUS_D": AIS_TYPE_CARGO_HAZARDOUS_D, + "AIS_TYPE_CARGO_RESERVED_1": AIS_TYPE_CARGO_RESERVED_1, + "AIS_TYPE_CARGO_RESERVED_2": AIS_TYPE_CARGO_RESERVED_2, + "AIS_TYPE_CARGO_RESERVED_3": AIS_TYPE_CARGO_RESERVED_3, + "AIS_TYPE_CARGO_RESERVED_4": AIS_TYPE_CARGO_RESERVED_4, + "AIS_TYPE_CARGO_UNKNOWN": AIS_TYPE_CARGO_UNKNOWN, + "AIS_TYPE_TANKER": AIS_TYPE_TANKER, + "AIS_TYPE_TANKER_HAZARDOUS_A": AIS_TYPE_TANKER_HAZARDOUS_A, + "AIS_TYPE_TANKER_HAZARDOUS_B": AIS_TYPE_TANKER_HAZARDOUS_B, + "AIS_TYPE_TANKER_HAZARDOUS_C": AIS_TYPE_TANKER_HAZARDOUS_C, + "AIS_TYPE_TANKER_HAZARDOUS_D": AIS_TYPE_TANKER_HAZARDOUS_D, + "AIS_TYPE_TANKER_RESERVED_1": AIS_TYPE_TANKER_RESERVED_1, + "AIS_TYPE_TANKER_RESERVED_2": AIS_TYPE_TANKER_RESERVED_2, + "AIS_TYPE_TANKER_RESERVED_3": AIS_TYPE_TANKER_RESERVED_3, + "AIS_TYPE_TANKER_RESERVED_4": AIS_TYPE_TANKER_RESERVED_4, + "AIS_TYPE_TANKER_UNKNOWN": AIS_TYPE_TANKER_UNKNOWN, + "AIS_TYPE_OTHER": AIS_TYPE_OTHER, + "AIS_TYPE_OTHER_HAZARDOUS_A": AIS_TYPE_OTHER_HAZARDOUS_A, + "AIS_TYPE_OTHER_HAZARDOUS_B": AIS_TYPE_OTHER_HAZARDOUS_B, + "AIS_TYPE_OTHER_HAZARDOUS_C": AIS_TYPE_OTHER_HAZARDOUS_C, + "AIS_TYPE_OTHER_HAZARDOUS_D": AIS_TYPE_OTHER_HAZARDOUS_D, + "AIS_TYPE_OTHER_RESERVED_1": AIS_TYPE_OTHER_RESERVED_1, + "AIS_TYPE_OTHER_RESERVED_2": AIS_TYPE_OTHER_RESERVED_2, + "AIS_TYPE_OTHER_RESERVED_3": AIS_TYPE_OTHER_RESERVED_3, + "AIS_TYPE_OTHER_RESERVED_4": AIS_TYPE_OTHER_RESERVED_4, + "AIS_TYPE_OTHER_UNKNOWN": AIS_TYPE_OTHER_UNKNOWN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AIS_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_AIS_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_AIS_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *AIS_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask AIS_TYPE - for _, label := range labels { - found := false - for value, l := range labels_AIS_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_AIS_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e AIS_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_AIS_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_attitude_target_typemask.go b/pkg/dialects/common/enum_attitude_target_typemask.go index 107c8078a..0a96d545f 100644 --- a/pkg/dialects/common/enum_attitude_target_typemask.go +++ b/pkg/dialects/common/enum_attitude_target_typemask.go @@ -34,12 +34,22 @@ var labels_ATTITUDE_TARGET_TYPEMASK = map[ATTITUDE_TARGET_TYPEMASK]string{ ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE: "ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE", } +var values_ATTITUDE_TARGET_TYPEMASK = map[string]ATTITUDE_TARGET_TYPEMASK{ + "ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE": ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE, + "ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE": ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE, + "ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE": ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE, + "ATTITUDE_TARGET_TYPEMASK_THRUST_BODY_SET": ATTITUDE_TARGET_TYPEMASK_THRUST_BODY_SET, + "ATTITUDE_TARGET_TYPEMASK_THROTTLE_IGNORE": ATTITUDE_TARGET_TYPEMASK_THROTTLE_IGNORE, + "ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE": ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ATTITUDE_TARGET_TYPEMASK) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_ATTITUDE_TARGET_TYPEMASK { + for i := 0; i < 6; i++ { + mask := ATTITUDE_TARGET_TYPEMASK(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_ATTITUDE_TARGET_TYPEMASK[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -50,19 +60,12 @@ func (e *ATTITUDE_TARGET_TYPEMASK) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask ATTITUDE_TARGET_TYPEMASK for _, label := range labels { - found := false - for value, l := range labels_ATTITUDE_TARGET_TYPEMASK { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_ATTITUDE_TARGET_TYPEMASK[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_autotune_axis.go b/pkg/dialects/common/enum_autotune_axis.go index ec704f019..5b4494b06 100644 --- a/pkg/dialects/common/enum_autotune_axis.go +++ b/pkg/dialects/common/enum_autotune_axis.go @@ -28,12 +28,20 @@ var labels_AUTOTUNE_AXIS = map[AUTOTUNE_AXIS]string{ AUTOTUNE_AXIS_YAW: "AUTOTUNE_AXIS_YAW", } +var values_AUTOTUNE_AXIS = map[string]AUTOTUNE_AXIS{ + "AUTOTUNE_AXIS_DEFAULT": AUTOTUNE_AXIS_DEFAULT, + "AUTOTUNE_AXIS_ROLL": AUTOTUNE_AXIS_ROLL, + "AUTOTUNE_AXIS_PITCH": AUTOTUNE_AXIS_PITCH, + "AUTOTUNE_AXIS_YAW": AUTOTUNE_AXIS_YAW, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AUTOTUNE_AXIS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_AUTOTUNE_AXIS { + for i := 0; i < 4; i++ { + mask := AUTOTUNE_AXIS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_AUTOTUNE_AXIS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -44,19 +52,12 @@ func (e *AUTOTUNE_AXIS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask AUTOTUNE_AXIS for _, label := range labels { - found := false - for value, l := range labels_AUTOTUNE_AXIS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_AUTOTUNE_AXIS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_camera_cap_flags.go b/pkg/dialects/common/enum_camera_cap_flags.go index 8395c89a2..a1aa2ce46 100644 --- a/pkg/dialects/common/enum_camera_cap_flags.go +++ b/pkg/dialects/common/enum_camera_cap_flags.go @@ -52,12 +52,28 @@ var labels_CAMERA_CAP_FLAGS = map[CAMERA_CAP_FLAGS]string{ CAMERA_CAP_FLAGS_HAS_TRACKING_GEO_STATUS: "CAMERA_CAP_FLAGS_HAS_TRACKING_GEO_STATUS", } +var values_CAMERA_CAP_FLAGS = map[string]CAMERA_CAP_FLAGS{ + "CAMERA_CAP_FLAGS_CAPTURE_VIDEO": CAMERA_CAP_FLAGS_CAPTURE_VIDEO, + "CAMERA_CAP_FLAGS_CAPTURE_IMAGE": CAMERA_CAP_FLAGS_CAPTURE_IMAGE, + "CAMERA_CAP_FLAGS_HAS_MODES": CAMERA_CAP_FLAGS_HAS_MODES, + "CAMERA_CAP_FLAGS_CAN_CAPTURE_IMAGE_IN_VIDEO_MODE": CAMERA_CAP_FLAGS_CAN_CAPTURE_IMAGE_IN_VIDEO_MODE, + "CAMERA_CAP_FLAGS_CAN_CAPTURE_VIDEO_IN_IMAGE_MODE": CAMERA_CAP_FLAGS_CAN_CAPTURE_VIDEO_IN_IMAGE_MODE, + "CAMERA_CAP_FLAGS_HAS_IMAGE_SURVEY_MODE": CAMERA_CAP_FLAGS_HAS_IMAGE_SURVEY_MODE, + "CAMERA_CAP_FLAGS_HAS_BASIC_ZOOM": CAMERA_CAP_FLAGS_HAS_BASIC_ZOOM, + "CAMERA_CAP_FLAGS_HAS_BASIC_FOCUS": CAMERA_CAP_FLAGS_HAS_BASIC_FOCUS, + "CAMERA_CAP_FLAGS_HAS_VIDEO_STREAM": CAMERA_CAP_FLAGS_HAS_VIDEO_STREAM, + "CAMERA_CAP_FLAGS_HAS_TRACKING_POINT": CAMERA_CAP_FLAGS_HAS_TRACKING_POINT, + "CAMERA_CAP_FLAGS_HAS_TRACKING_RECTANGLE": CAMERA_CAP_FLAGS_HAS_TRACKING_RECTANGLE, + "CAMERA_CAP_FLAGS_HAS_TRACKING_GEO_STATUS": CAMERA_CAP_FLAGS_HAS_TRACKING_GEO_STATUS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_CAP_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_CAMERA_CAP_FLAGS { + for i := 0; i < 12; i++ { + mask := CAMERA_CAP_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_CAMERA_CAP_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -68,19 +84,12 @@ func (e *CAMERA_CAP_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask CAMERA_CAP_FLAGS for _, label := range labels { - found := false - for value, l := range labels_CAMERA_CAP_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_CAMERA_CAP_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_camera_mode.go b/pkg/dialects/common/enum_camera_mode.go index 74050b777..640435c9f 100644 --- a/pkg/dialects/common/enum_camera_mode.go +++ b/pkg/dialects/common/enum_camera_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Camera Modes. @@ -25,40 +25,36 @@ var labels_CAMERA_MODE = map[CAMERA_MODE]string{ CAMERA_MODE_IMAGE_SURVEY: "CAMERA_MODE_IMAGE_SURVEY", } +var values_CAMERA_MODE = map[string]CAMERA_MODE{ + "CAMERA_MODE_IMAGE": CAMERA_MODE_IMAGE, + "CAMERA_MODE_VIDEO": CAMERA_MODE_VIDEO, + "CAMERA_MODE_IMAGE_SURVEY": CAMERA_MODE_IMAGE_SURVEY, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAMERA_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAMERA_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAMERA_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAMERA_MODE - for _, label := range labels { - found := false - for value, l := range labels_CAMERA_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAMERA_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAMERA_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAMERA_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_camera_tracking_mode.go b/pkg/dialects/common/enum_camera_tracking_mode.go index fe780d88e..fe15dec61 100644 --- a/pkg/dialects/common/enum_camera_tracking_mode.go +++ b/pkg/dialects/common/enum_camera_tracking_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Camera tracking modes @@ -25,40 +25,36 @@ var labels_CAMERA_TRACKING_MODE = map[CAMERA_TRACKING_MODE]string{ CAMERA_TRACKING_MODE_RECTANGLE: "CAMERA_TRACKING_MODE_RECTANGLE", } +var values_CAMERA_TRACKING_MODE = map[string]CAMERA_TRACKING_MODE{ + "CAMERA_TRACKING_MODE_NONE": CAMERA_TRACKING_MODE_NONE, + "CAMERA_TRACKING_MODE_POINT": CAMERA_TRACKING_MODE_POINT, + "CAMERA_TRACKING_MODE_RECTANGLE": CAMERA_TRACKING_MODE_RECTANGLE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_TRACKING_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAMERA_TRACKING_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAMERA_TRACKING_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAMERA_TRACKING_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAMERA_TRACKING_MODE - for _, label := range labels { - found := false - for value, l := range labels_CAMERA_TRACKING_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAMERA_TRACKING_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAMERA_TRACKING_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAMERA_TRACKING_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_camera_tracking_status_flags.go b/pkg/dialects/common/enum_camera_tracking_status_flags.go index a12c4f355..088a73e9c 100644 --- a/pkg/dialects/common/enum_camera_tracking_status_flags.go +++ b/pkg/dialects/common/enum_camera_tracking_status_flags.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Camera tracking status flags @@ -25,40 +25,36 @@ var labels_CAMERA_TRACKING_STATUS_FLAGS = map[CAMERA_TRACKING_STATUS_FLAGS]strin CAMERA_TRACKING_STATUS_FLAGS_ERROR: "CAMERA_TRACKING_STATUS_FLAGS_ERROR", } +var values_CAMERA_TRACKING_STATUS_FLAGS = map[string]CAMERA_TRACKING_STATUS_FLAGS{ + "CAMERA_TRACKING_STATUS_FLAGS_IDLE": CAMERA_TRACKING_STATUS_FLAGS_IDLE, + "CAMERA_TRACKING_STATUS_FLAGS_ACTIVE": CAMERA_TRACKING_STATUS_FLAGS_ACTIVE, + "CAMERA_TRACKING_STATUS_FLAGS_ERROR": CAMERA_TRACKING_STATUS_FLAGS_ERROR, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_TRACKING_STATUS_FLAGS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAMERA_TRACKING_STATUS_FLAGS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAMERA_TRACKING_STATUS_FLAGS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAMERA_TRACKING_STATUS_FLAGS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAMERA_TRACKING_STATUS_FLAGS - for _, label := range labels { - found := false - for value, l := range labels_CAMERA_TRACKING_STATUS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAMERA_TRACKING_STATUS_FLAGS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAMERA_TRACKING_STATUS_FLAGS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAMERA_TRACKING_STATUS_FLAGS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_camera_tracking_target_data.go b/pkg/dialects/common/enum_camera_tracking_target_data.go index 663d8647a..d97ac179f 100644 --- a/pkg/dialects/common/enum_camera_tracking_target_data.go +++ b/pkg/dialects/common/enum_camera_tracking_target_data.go @@ -28,12 +28,20 @@ var labels_CAMERA_TRACKING_TARGET_DATA = map[CAMERA_TRACKING_TARGET_DATA]string{ CAMERA_TRACKING_TARGET_DATA_IN_STATUS: "CAMERA_TRACKING_TARGET_DATA_IN_STATUS", } +var values_CAMERA_TRACKING_TARGET_DATA = map[string]CAMERA_TRACKING_TARGET_DATA{ + "CAMERA_TRACKING_TARGET_DATA_NONE": CAMERA_TRACKING_TARGET_DATA_NONE, + "CAMERA_TRACKING_TARGET_DATA_EMBEDDED": CAMERA_TRACKING_TARGET_DATA_EMBEDDED, + "CAMERA_TRACKING_TARGET_DATA_RENDERED": CAMERA_TRACKING_TARGET_DATA_RENDERED, + "CAMERA_TRACKING_TARGET_DATA_IN_STATUS": CAMERA_TRACKING_TARGET_DATA_IN_STATUS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_TRACKING_TARGET_DATA) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_CAMERA_TRACKING_TARGET_DATA { + for i := 0; i < 4; i++ { + mask := CAMERA_TRACKING_TARGET_DATA(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_CAMERA_TRACKING_TARGET_DATA[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -44,19 +52,12 @@ func (e *CAMERA_TRACKING_TARGET_DATA) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask CAMERA_TRACKING_TARGET_DATA for _, label := range labels { - found := false - for value, l := range labels_CAMERA_TRACKING_TARGET_DATA { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_CAMERA_TRACKING_TARGET_DATA[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_camera_zoom_type.go b/pkg/dialects/common/enum_camera_zoom_type.go index b19be08ac..91f4abe70 100644 --- a/pkg/dialects/common/enum_camera_zoom_type.go +++ b/pkg/dialects/common/enum_camera_zoom_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Zoom types for MAV_CMD_SET_CAMERA_ZOOM @@ -31,40 +31,38 @@ var labels_CAMERA_ZOOM_TYPE = map[CAMERA_ZOOM_TYPE]string{ ZOOM_TYPE_HORIZONTAL_FOV: "ZOOM_TYPE_HORIZONTAL_FOV", } +var values_CAMERA_ZOOM_TYPE = map[string]CAMERA_ZOOM_TYPE{ + "ZOOM_TYPE_STEP": ZOOM_TYPE_STEP, + "ZOOM_TYPE_CONTINUOUS": ZOOM_TYPE_CONTINUOUS, + "ZOOM_TYPE_RANGE": ZOOM_TYPE_RANGE, + "ZOOM_TYPE_FOCAL_LENGTH": ZOOM_TYPE_FOCAL_LENGTH, + "ZOOM_TYPE_HORIZONTAL_FOV": ZOOM_TYPE_HORIZONTAL_FOV, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAMERA_ZOOM_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAMERA_ZOOM_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAMERA_ZOOM_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAMERA_ZOOM_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAMERA_ZOOM_TYPE - for _, label := range labels { - found := false - for value, l := range labels_CAMERA_ZOOM_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAMERA_ZOOM_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAMERA_ZOOM_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAMERA_ZOOM_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_can_filter_op.go b/pkg/dialects/common/enum_can_filter_op.go index 8eabfbb3d..fbde2dcf0 100644 --- a/pkg/dialects/common/enum_can_filter_op.go +++ b/pkg/dialects/common/enum_can_filter_op.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type CAN_FILTER_OP uint32 @@ -21,40 +21,36 @@ var labels_CAN_FILTER_OP = map[CAN_FILTER_OP]string{ CAN_FILTER_REMOVE: "CAN_FILTER_REMOVE", } +var values_CAN_FILTER_OP = map[string]CAN_FILTER_OP{ + "CAN_FILTER_REPLACE": CAN_FILTER_REPLACE, + "CAN_FILTER_ADD": CAN_FILTER_ADD, + "CAN_FILTER_REMOVE": CAN_FILTER_REMOVE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CAN_FILTER_OP) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CAN_FILTER_OP { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CAN_FILTER_OP[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CAN_FILTER_OP) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CAN_FILTER_OP - for _, label := range labels { - found := false - for value, l := range labels_CAN_FILTER_OP { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CAN_FILTER_OP[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CAN_FILTER_OP) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CAN_FILTER_OP[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_cellular_config_response.go b/pkg/dialects/common/enum_cellular_config_response.go index 2ff92c2a2..0e8c2378b 100644 --- a/pkg/dialects/common/enum_cellular_config_response.go +++ b/pkg/dialects/common/enum_cellular_config_response.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Possible responses from a CELLULAR_CONFIG message. @@ -31,40 +31,38 @@ var labels_CELLULAR_CONFIG_RESPONSE = map[CELLULAR_CONFIG_RESPONSE]string{ CELLULAR_CONFIG_BLOCKED_PUK_REQUIRED: "CELLULAR_CONFIG_BLOCKED_PUK_REQUIRED", } +var values_CELLULAR_CONFIG_RESPONSE = map[string]CELLULAR_CONFIG_RESPONSE{ + "CELLULAR_CONFIG_RESPONSE_ACCEPTED": CELLULAR_CONFIG_RESPONSE_ACCEPTED, + "CELLULAR_CONFIG_RESPONSE_APN_ERROR": CELLULAR_CONFIG_RESPONSE_APN_ERROR, + "CELLULAR_CONFIG_RESPONSE_PIN_ERROR": CELLULAR_CONFIG_RESPONSE_PIN_ERROR, + "CELLULAR_CONFIG_RESPONSE_REJECTED": CELLULAR_CONFIG_RESPONSE_REJECTED, + "CELLULAR_CONFIG_BLOCKED_PUK_REQUIRED": CELLULAR_CONFIG_BLOCKED_PUK_REQUIRED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CELLULAR_CONFIG_RESPONSE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CELLULAR_CONFIG_RESPONSE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CELLULAR_CONFIG_RESPONSE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CELLULAR_CONFIG_RESPONSE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CELLULAR_CONFIG_RESPONSE - for _, label := range labels { - found := false - for value, l := range labels_CELLULAR_CONFIG_RESPONSE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CELLULAR_CONFIG_RESPONSE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CELLULAR_CONFIG_RESPONSE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CELLULAR_CONFIG_RESPONSE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_cellular_network_failed_reason.go b/pkg/dialects/common/enum_cellular_network_failed_reason.go index a662a0939..771f4ba37 100644 --- a/pkg/dialects/common/enum_cellular_network_failed_reason.go +++ b/pkg/dialects/common/enum_cellular_network_failed_reason.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // These flags are used to diagnose the failure state of CELLULAR_STATUS @@ -28,40 +28,37 @@ var labels_CELLULAR_NETWORK_FAILED_REASON = map[CELLULAR_NETWORK_FAILED_REASON]s CELLULAR_NETWORK_FAILED_REASON_SIM_ERROR: "CELLULAR_NETWORK_FAILED_REASON_SIM_ERROR", } +var values_CELLULAR_NETWORK_FAILED_REASON = map[string]CELLULAR_NETWORK_FAILED_REASON{ + "CELLULAR_NETWORK_FAILED_REASON_NONE": CELLULAR_NETWORK_FAILED_REASON_NONE, + "CELLULAR_NETWORK_FAILED_REASON_UNKNOWN": CELLULAR_NETWORK_FAILED_REASON_UNKNOWN, + "CELLULAR_NETWORK_FAILED_REASON_SIM_MISSING": CELLULAR_NETWORK_FAILED_REASON_SIM_MISSING, + "CELLULAR_NETWORK_FAILED_REASON_SIM_ERROR": CELLULAR_NETWORK_FAILED_REASON_SIM_ERROR, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CELLULAR_NETWORK_FAILED_REASON) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CELLULAR_NETWORK_FAILED_REASON { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CELLULAR_NETWORK_FAILED_REASON[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CELLULAR_NETWORK_FAILED_REASON) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CELLULAR_NETWORK_FAILED_REASON - for _, label := range labels { - found := false - for value, l := range labels_CELLULAR_NETWORK_FAILED_REASON { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CELLULAR_NETWORK_FAILED_REASON[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CELLULAR_NETWORK_FAILED_REASON) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CELLULAR_NETWORK_FAILED_REASON[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_cellular_network_radio_type.go b/pkg/dialects/common/enum_cellular_network_radio_type.go index 03f6a473e..d2558efb9 100644 --- a/pkg/dialects/common/enum_cellular_network_radio_type.go +++ b/pkg/dialects/common/enum_cellular_network_radio_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Cellular network radio type @@ -26,40 +26,38 @@ var labels_CELLULAR_NETWORK_RADIO_TYPE = map[CELLULAR_NETWORK_RADIO_TYPE]string{ CELLULAR_NETWORK_RADIO_TYPE_LTE: "CELLULAR_NETWORK_RADIO_TYPE_LTE", } +var values_CELLULAR_NETWORK_RADIO_TYPE = map[string]CELLULAR_NETWORK_RADIO_TYPE{ + "CELLULAR_NETWORK_RADIO_TYPE_NONE": CELLULAR_NETWORK_RADIO_TYPE_NONE, + "CELLULAR_NETWORK_RADIO_TYPE_GSM": CELLULAR_NETWORK_RADIO_TYPE_GSM, + "CELLULAR_NETWORK_RADIO_TYPE_CDMA": CELLULAR_NETWORK_RADIO_TYPE_CDMA, + "CELLULAR_NETWORK_RADIO_TYPE_WCDMA": CELLULAR_NETWORK_RADIO_TYPE_WCDMA, + "CELLULAR_NETWORK_RADIO_TYPE_LTE": CELLULAR_NETWORK_RADIO_TYPE_LTE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CELLULAR_NETWORK_RADIO_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CELLULAR_NETWORK_RADIO_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CELLULAR_NETWORK_RADIO_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CELLULAR_NETWORK_RADIO_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CELLULAR_NETWORK_RADIO_TYPE - for _, label := range labels { - found := false - for value, l := range labels_CELLULAR_NETWORK_RADIO_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CELLULAR_NETWORK_RADIO_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CELLULAR_NETWORK_RADIO_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CELLULAR_NETWORK_RADIO_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_cellular_status_flag.go b/pkg/dialects/common/enum_cellular_status_flag.go index 16b475529..ad0068962 100644 --- a/pkg/dialects/common/enum_cellular_status_flag.go +++ b/pkg/dialects/common/enum_cellular_status_flag.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // These flags encode the cellular network status @@ -55,40 +55,46 @@ var labels_CELLULAR_STATUS_FLAG = map[CELLULAR_STATUS_FLAG]string{ CELLULAR_STATUS_FLAG_CONNECTED: "CELLULAR_STATUS_FLAG_CONNECTED", } +var values_CELLULAR_STATUS_FLAG = map[string]CELLULAR_STATUS_FLAG{ + "CELLULAR_STATUS_FLAG_UNKNOWN": CELLULAR_STATUS_FLAG_UNKNOWN, + "CELLULAR_STATUS_FLAG_FAILED": CELLULAR_STATUS_FLAG_FAILED, + "CELLULAR_STATUS_FLAG_INITIALIZING": CELLULAR_STATUS_FLAG_INITIALIZING, + "CELLULAR_STATUS_FLAG_LOCKED": CELLULAR_STATUS_FLAG_LOCKED, + "CELLULAR_STATUS_FLAG_DISABLED": CELLULAR_STATUS_FLAG_DISABLED, + "CELLULAR_STATUS_FLAG_DISABLING": CELLULAR_STATUS_FLAG_DISABLING, + "CELLULAR_STATUS_FLAG_ENABLING": CELLULAR_STATUS_FLAG_ENABLING, + "CELLULAR_STATUS_FLAG_ENABLED": CELLULAR_STATUS_FLAG_ENABLED, + "CELLULAR_STATUS_FLAG_SEARCHING": CELLULAR_STATUS_FLAG_SEARCHING, + "CELLULAR_STATUS_FLAG_REGISTERED": CELLULAR_STATUS_FLAG_REGISTERED, + "CELLULAR_STATUS_FLAG_DISCONNECTING": CELLULAR_STATUS_FLAG_DISCONNECTING, + "CELLULAR_STATUS_FLAG_CONNECTING": CELLULAR_STATUS_FLAG_CONNECTING, + "CELLULAR_STATUS_FLAG_CONNECTED": CELLULAR_STATUS_FLAG_CONNECTED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e CELLULAR_STATUS_FLAG) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_CELLULAR_STATUS_FLAG { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_CELLULAR_STATUS_FLAG[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *CELLULAR_STATUS_FLAG) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask CELLULAR_STATUS_FLAG - for _, label := range labels { - found := false - for value, l := range labels_CELLULAR_STATUS_FLAG { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_CELLULAR_STATUS_FLAG[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e CELLULAR_STATUS_FLAG) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_CELLULAR_STATUS_FLAG[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_comp_metadata_type.go b/pkg/dialects/common/enum_comp_metadata_type.go index b4fd574ac..2033bafde 100644 --- a/pkg/dialects/common/enum_comp_metadata_type.go +++ b/pkg/dialects/common/enum_comp_metadata_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Supported component metadata types. These are used in the "general" metadata file returned by COMPONENT_METADATA to provide information about supported metadata types. The types are not used directly in MAVLink messages. @@ -34,40 +34,39 @@ var labels_COMP_METADATA_TYPE = map[COMP_METADATA_TYPE]string{ COMP_METADATA_TYPE_ACTUATORS: "COMP_METADATA_TYPE_ACTUATORS", } +var values_COMP_METADATA_TYPE = map[string]COMP_METADATA_TYPE{ + "COMP_METADATA_TYPE_GENERAL": COMP_METADATA_TYPE_GENERAL, + "COMP_METADATA_TYPE_PARAMETER": COMP_METADATA_TYPE_PARAMETER, + "COMP_METADATA_TYPE_COMMANDS": COMP_METADATA_TYPE_COMMANDS, + "COMP_METADATA_TYPE_PERIPHERALS": COMP_METADATA_TYPE_PERIPHERALS, + "COMP_METADATA_TYPE_EVENTS": COMP_METADATA_TYPE_EVENTS, + "COMP_METADATA_TYPE_ACTUATORS": COMP_METADATA_TYPE_ACTUATORS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e COMP_METADATA_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_COMP_METADATA_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_COMP_METADATA_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *COMP_METADATA_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask COMP_METADATA_TYPE - for _, label := range labels { - found := false - for value, l := range labels_COMP_METADATA_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_COMP_METADATA_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e COMP_METADATA_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_COMP_METADATA_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_esc_connection_type.go b/pkg/dialects/common/enum_esc_connection_type.go index 8ad2beb56..75d08f259 100644 --- a/pkg/dialects/common/enum_esc_connection_type.go +++ b/pkg/dialects/common/enum_esc_connection_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Indicates the ESC connection type. @@ -34,40 +34,39 @@ var labels_ESC_CONNECTION_TYPE = map[ESC_CONNECTION_TYPE]string{ ESC_CONNECTION_TYPE_DSHOT: "ESC_CONNECTION_TYPE_DSHOT", } +var values_ESC_CONNECTION_TYPE = map[string]ESC_CONNECTION_TYPE{ + "ESC_CONNECTION_TYPE_PPM": ESC_CONNECTION_TYPE_PPM, + "ESC_CONNECTION_TYPE_SERIAL": ESC_CONNECTION_TYPE_SERIAL, + "ESC_CONNECTION_TYPE_ONESHOT": ESC_CONNECTION_TYPE_ONESHOT, + "ESC_CONNECTION_TYPE_I2C": ESC_CONNECTION_TYPE_I2C, + "ESC_CONNECTION_TYPE_CAN": ESC_CONNECTION_TYPE_CAN, + "ESC_CONNECTION_TYPE_DSHOT": ESC_CONNECTION_TYPE_DSHOT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ESC_CONNECTION_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ESC_CONNECTION_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ESC_CONNECTION_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ESC_CONNECTION_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ESC_CONNECTION_TYPE - for _, label := range labels { - found := false - for value, l := range labels_ESC_CONNECTION_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ESC_CONNECTION_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ESC_CONNECTION_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ESC_CONNECTION_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_esc_failure_flags.go b/pkg/dialects/common/enum_esc_failure_flags.go index 46a7cddc4..6b1ae899b 100644 --- a/pkg/dialects/common/enum_esc_failure_flags.go +++ b/pkg/dialects/common/enum_esc_failure_flags.go @@ -40,12 +40,24 @@ var labels_ESC_FAILURE_FLAGS = map[ESC_FAILURE_FLAGS]string{ ESC_FAILURE_GENERIC: "ESC_FAILURE_GENERIC", } +var values_ESC_FAILURE_FLAGS = map[string]ESC_FAILURE_FLAGS{ + "ESC_FAILURE_NONE": ESC_FAILURE_NONE, + "ESC_FAILURE_OVER_CURRENT": ESC_FAILURE_OVER_CURRENT, + "ESC_FAILURE_OVER_VOLTAGE": ESC_FAILURE_OVER_VOLTAGE, + "ESC_FAILURE_OVER_TEMPERATURE": ESC_FAILURE_OVER_TEMPERATURE, + "ESC_FAILURE_OVER_RPM": ESC_FAILURE_OVER_RPM, + "ESC_FAILURE_INCONSISTENT_CMD": ESC_FAILURE_INCONSISTENT_CMD, + "ESC_FAILURE_MOTOR_STUCK": ESC_FAILURE_MOTOR_STUCK, + "ESC_FAILURE_GENERIC": ESC_FAILURE_GENERIC, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ESC_FAILURE_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_ESC_FAILURE_FLAGS { + for i := 0; i < 8; i++ { + mask := ESC_FAILURE_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_ESC_FAILURE_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -56,19 +68,12 @@ func (e *ESC_FAILURE_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask ESC_FAILURE_FLAGS for _, label := range labels { - found := false - for value, l := range labels_ESC_FAILURE_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_ESC_FAILURE_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_estimator_status_flags.go b/pkg/dialects/common/enum_estimator_status_flags.go index a9fa6b80b..691e48159 100644 --- a/pkg/dialects/common/enum_estimator_status_flags.go +++ b/pkg/dialects/common/enum_estimator_status_flags.go @@ -52,12 +52,28 @@ var labels_ESTIMATOR_STATUS_FLAGS = map[ESTIMATOR_STATUS_FLAGS]string{ ESTIMATOR_ACCEL_ERROR: "ESTIMATOR_ACCEL_ERROR", } +var values_ESTIMATOR_STATUS_FLAGS = map[string]ESTIMATOR_STATUS_FLAGS{ + "ESTIMATOR_ATTITUDE": ESTIMATOR_ATTITUDE, + "ESTIMATOR_VELOCITY_HORIZ": ESTIMATOR_VELOCITY_HORIZ, + "ESTIMATOR_VELOCITY_VERT": ESTIMATOR_VELOCITY_VERT, + "ESTIMATOR_POS_HORIZ_REL": ESTIMATOR_POS_HORIZ_REL, + "ESTIMATOR_POS_HORIZ_ABS": ESTIMATOR_POS_HORIZ_ABS, + "ESTIMATOR_POS_VERT_ABS": ESTIMATOR_POS_VERT_ABS, + "ESTIMATOR_POS_VERT_AGL": ESTIMATOR_POS_VERT_AGL, + "ESTIMATOR_CONST_POS_MODE": ESTIMATOR_CONST_POS_MODE, + "ESTIMATOR_PRED_POS_HORIZ_REL": ESTIMATOR_PRED_POS_HORIZ_REL, + "ESTIMATOR_PRED_POS_HORIZ_ABS": ESTIMATOR_PRED_POS_HORIZ_ABS, + "ESTIMATOR_GPS_GLITCH": ESTIMATOR_GPS_GLITCH, + "ESTIMATOR_ACCEL_ERROR": ESTIMATOR_ACCEL_ERROR, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ESTIMATOR_STATUS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_ESTIMATOR_STATUS_FLAGS { + for i := 0; i < 12; i++ { + mask := ESTIMATOR_STATUS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_ESTIMATOR_STATUS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -68,19 +84,12 @@ func (e *ESTIMATOR_STATUS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask ESTIMATOR_STATUS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_ESTIMATOR_STATUS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_ESTIMATOR_STATUS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_failure_type.go b/pkg/dialects/common/enum_failure_type.go index 542f4fd2a..a81680988 100644 --- a/pkg/dialects/common/enum_failure_type.go +++ b/pkg/dialects/common/enum_failure_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // List of possible failure type to inject. @@ -40,40 +40,41 @@ var labels_FAILURE_TYPE = map[FAILURE_TYPE]string{ FAILURE_TYPE_INTERMITTENT: "FAILURE_TYPE_INTERMITTENT", } +var values_FAILURE_TYPE = map[string]FAILURE_TYPE{ + "FAILURE_TYPE_OK": FAILURE_TYPE_OK, + "FAILURE_TYPE_OFF": FAILURE_TYPE_OFF, + "FAILURE_TYPE_STUCK": FAILURE_TYPE_STUCK, + "FAILURE_TYPE_GARBAGE": FAILURE_TYPE_GARBAGE, + "FAILURE_TYPE_WRONG": FAILURE_TYPE_WRONG, + "FAILURE_TYPE_SLOW": FAILURE_TYPE_SLOW, + "FAILURE_TYPE_DELAYED": FAILURE_TYPE_DELAYED, + "FAILURE_TYPE_INTERMITTENT": FAILURE_TYPE_INTERMITTENT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e FAILURE_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_FAILURE_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_FAILURE_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *FAILURE_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask FAILURE_TYPE - for _, label := range labels { - found := false - for value, l := range labels_FAILURE_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_FAILURE_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e FAILURE_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_FAILURE_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_failure_unit.go b/pkg/dialects/common/enum_failure_unit.go index fe40d8a47..845d059ca 100644 --- a/pkg/dialects/common/enum_failure_unit.go +++ b/pkg/dialects/common/enum_failure_unit.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // List of possible units where failures can be injected. @@ -46,40 +46,48 @@ var labels_FAILURE_UNIT = map[FAILURE_UNIT]string{ FAILURE_UNIT_SYSTEM_MAVLINK_SIGNAL: "FAILURE_UNIT_SYSTEM_MAVLINK_SIGNAL", } +var values_FAILURE_UNIT = map[string]FAILURE_UNIT{ + "FAILURE_UNIT_SENSOR_GYRO": FAILURE_UNIT_SENSOR_GYRO, + "FAILURE_UNIT_SENSOR_ACCEL": FAILURE_UNIT_SENSOR_ACCEL, + "FAILURE_UNIT_SENSOR_MAG": FAILURE_UNIT_SENSOR_MAG, + "FAILURE_UNIT_SENSOR_BARO": FAILURE_UNIT_SENSOR_BARO, + "FAILURE_UNIT_SENSOR_GPS": FAILURE_UNIT_SENSOR_GPS, + "FAILURE_UNIT_SENSOR_OPTICAL_FLOW": FAILURE_UNIT_SENSOR_OPTICAL_FLOW, + "FAILURE_UNIT_SENSOR_VIO": FAILURE_UNIT_SENSOR_VIO, + "FAILURE_UNIT_SENSOR_DISTANCE_SENSOR": FAILURE_UNIT_SENSOR_DISTANCE_SENSOR, + "FAILURE_UNIT_SENSOR_AIRSPEED": FAILURE_UNIT_SENSOR_AIRSPEED, + "FAILURE_UNIT_SYSTEM_BATTERY": FAILURE_UNIT_SYSTEM_BATTERY, + "FAILURE_UNIT_SYSTEM_MOTOR": FAILURE_UNIT_SYSTEM_MOTOR, + "FAILURE_UNIT_SYSTEM_SERVO": FAILURE_UNIT_SYSTEM_SERVO, + "FAILURE_UNIT_SYSTEM_AVOIDANCE": FAILURE_UNIT_SYSTEM_AVOIDANCE, + "FAILURE_UNIT_SYSTEM_RC_SIGNAL": FAILURE_UNIT_SYSTEM_RC_SIGNAL, + "FAILURE_UNIT_SYSTEM_MAVLINK_SIGNAL": FAILURE_UNIT_SYSTEM_MAVLINK_SIGNAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e FAILURE_UNIT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_FAILURE_UNIT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_FAILURE_UNIT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *FAILURE_UNIT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask FAILURE_UNIT - for _, label := range labels { - found := false - for value, l := range labels_FAILURE_UNIT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_FAILURE_UNIT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e FAILURE_UNIT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_FAILURE_UNIT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_fence_action.go b/pkg/dialects/common/enum_fence_action.go index 29fee3898..8750a4a4b 100644 --- a/pkg/dialects/common/enum_fence_action.go +++ b/pkg/dialects/common/enum_fence_action.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actions following geofence breach. @@ -40,40 +40,41 @@ var labels_FENCE_ACTION = map[FENCE_ACTION]string{ FENCE_ACTION_LAND: "FENCE_ACTION_LAND", } +var values_FENCE_ACTION = map[string]FENCE_ACTION{ + "FENCE_ACTION_NONE": FENCE_ACTION_NONE, + "FENCE_ACTION_GUIDED": FENCE_ACTION_GUIDED, + "FENCE_ACTION_REPORT": FENCE_ACTION_REPORT, + "FENCE_ACTION_GUIDED_THR_PASS": FENCE_ACTION_GUIDED_THR_PASS, + "FENCE_ACTION_RTL": FENCE_ACTION_RTL, + "FENCE_ACTION_HOLD": FENCE_ACTION_HOLD, + "FENCE_ACTION_TERMINATE": FENCE_ACTION_TERMINATE, + "FENCE_ACTION_LAND": FENCE_ACTION_LAND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e FENCE_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_FENCE_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_FENCE_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *FENCE_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask FENCE_ACTION - for _, label := range labels { - found := false - for value, l := range labels_FENCE_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_FENCE_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e FENCE_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_FENCE_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_fence_breach.go b/pkg/dialects/common/enum_fence_breach.go index a089ad358..230cebb91 100644 --- a/pkg/dialects/common/enum_fence_breach.go +++ b/pkg/dialects/common/enum_fence_breach.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type FENCE_BREACH uint32 @@ -27,40 +27,37 @@ var labels_FENCE_BREACH = map[FENCE_BREACH]string{ FENCE_BREACH_BOUNDARY: "FENCE_BREACH_BOUNDARY", } +var values_FENCE_BREACH = map[string]FENCE_BREACH{ + "FENCE_BREACH_NONE": FENCE_BREACH_NONE, + "FENCE_BREACH_MINALT": FENCE_BREACH_MINALT, + "FENCE_BREACH_MAXALT": FENCE_BREACH_MAXALT, + "FENCE_BREACH_BOUNDARY": FENCE_BREACH_BOUNDARY, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e FENCE_BREACH) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_FENCE_BREACH { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_FENCE_BREACH[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *FENCE_BREACH) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask FENCE_BREACH - for _, label := range labels { - found := false - for value, l := range labels_FENCE_BREACH { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_FENCE_BREACH[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e FENCE_BREACH) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_FENCE_BREACH[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_fence_mitigate.go b/pkg/dialects/common/enum_fence_mitigate.go index 8a28ab249..e7bf5bee7 100644 --- a/pkg/dialects/common/enum_fence_mitigate.go +++ b/pkg/dialects/common/enum_fence_mitigate.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actions being taken to mitigate/prevent fence breach @@ -25,40 +25,36 @@ var labels_FENCE_MITIGATE = map[FENCE_MITIGATE]string{ FENCE_MITIGATE_VEL_LIMIT: "FENCE_MITIGATE_VEL_LIMIT", } +var values_FENCE_MITIGATE = map[string]FENCE_MITIGATE{ + "FENCE_MITIGATE_UNKNOWN": FENCE_MITIGATE_UNKNOWN, + "FENCE_MITIGATE_NONE": FENCE_MITIGATE_NONE, + "FENCE_MITIGATE_VEL_LIMIT": FENCE_MITIGATE_VEL_LIMIT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e FENCE_MITIGATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_FENCE_MITIGATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_FENCE_MITIGATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *FENCE_MITIGATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask FENCE_MITIGATE - for _, label := range labels { - found := false - for value, l := range labels_FENCE_MITIGATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_FENCE_MITIGATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e FENCE_MITIGATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_FENCE_MITIGATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_firmware_version_type.go b/pkg/dialects/common/enum_firmware_version_type.go index a49949e9a..0de3f5c34 100644 --- a/pkg/dialects/common/enum_firmware_version_type.go +++ b/pkg/dialects/common/enum_firmware_version_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // These values define the type of firmware release. These values indicate the first version or release of this type. For example the first alpha release would be 64, the second would be 65. @@ -31,40 +31,38 @@ var labels_FIRMWARE_VERSION_TYPE = map[FIRMWARE_VERSION_TYPE]string{ FIRMWARE_VERSION_TYPE_OFFICIAL: "FIRMWARE_VERSION_TYPE_OFFICIAL", } +var values_FIRMWARE_VERSION_TYPE = map[string]FIRMWARE_VERSION_TYPE{ + "FIRMWARE_VERSION_TYPE_DEV": FIRMWARE_VERSION_TYPE_DEV, + "FIRMWARE_VERSION_TYPE_ALPHA": FIRMWARE_VERSION_TYPE_ALPHA, + "FIRMWARE_VERSION_TYPE_BETA": FIRMWARE_VERSION_TYPE_BETA, + "FIRMWARE_VERSION_TYPE_RC": FIRMWARE_VERSION_TYPE_RC, + "FIRMWARE_VERSION_TYPE_OFFICIAL": FIRMWARE_VERSION_TYPE_OFFICIAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e FIRMWARE_VERSION_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_FIRMWARE_VERSION_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_FIRMWARE_VERSION_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *FIRMWARE_VERSION_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask FIRMWARE_VERSION_TYPE - for _, label := range labels { - found := false - for value, l := range labels_FIRMWARE_VERSION_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_FIRMWARE_VERSION_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e FIRMWARE_VERSION_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_FIRMWARE_VERSION_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_gimbal_device_cap_flags.go b/pkg/dialects/common/enum_gimbal_device_cap_flags.go index b35746ce1..86b3be495 100644 --- a/pkg/dialects/common/enum_gimbal_device_cap_flags.go +++ b/pkg/dialects/common/enum_gimbal_device_cap_flags.go @@ -58,12 +58,30 @@ var labels_GIMBAL_DEVICE_CAP_FLAGS = map[GIMBAL_DEVICE_CAP_FLAGS]string{ GIMBAL_DEVICE_CAP_FLAGS_HAS_RC_INPUTS: "GIMBAL_DEVICE_CAP_FLAGS_HAS_RC_INPUTS", } +var values_GIMBAL_DEVICE_CAP_FLAGS = map[string]GIMBAL_DEVICE_CAP_FLAGS{ + "GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT": GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_NEUTRAL": GIMBAL_DEVICE_CAP_FLAGS_HAS_NEUTRAL, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_AXIS": GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_AXIS, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_FOLLOW": GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_FOLLOW, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_LOCK": GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_LOCK, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_AXIS": GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_AXIS, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_FOLLOW": GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_FOLLOW, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_LOCK": GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_LOCK, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_AXIS": GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_AXIS, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_FOLLOW": GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_FOLLOW, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_LOCK": GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_LOCK, + "GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_INFINITE_YAW": GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_INFINITE_YAW, + "GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_YAW_IN_EARTH_FRAME": GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_YAW_IN_EARTH_FRAME, + "GIMBAL_DEVICE_CAP_FLAGS_HAS_RC_INPUTS": GIMBAL_DEVICE_CAP_FLAGS_HAS_RC_INPUTS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_DEVICE_CAP_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GIMBAL_DEVICE_CAP_FLAGS { + for i := 0; i < 14; i++ { + mask := GIMBAL_DEVICE_CAP_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GIMBAL_DEVICE_CAP_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -74,19 +92,12 @@ func (e *GIMBAL_DEVICE_CAP_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GIMBAL_DEVICE_CAP_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_DEVICE_CAP_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GIMBAL_DEVICE_CAP_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_gimbal_device_error_flags.go b/pkg/dialects/common/enum_gimbal_device_error_flags.go index 2f6bf59a3..acb6f9e73 100644 --- a/pkg/dialects/common/enum_gimbal_device_error_flags.go +++ b/pkg/dialects/common/enum_gimbal_device_error_flags.go @@ -46,12 +46,26 @@ var labels_GIMBAL_DEVICE_ERROR_FLAGS = map[GIMBAL_DEVICE_ERROR_FLAGS]string{ GIMBAL_DEVICE_ERROR_FLAGS_NO_MANAGER: "GIMBAL_DEVICE_ERROR_FLAGS_NO_MANAGER", } +var values_GIMBAL_DEVICE_ERROR_FLAGS = map[string]GIMBAL_DEVICE_ERROR_FLAGS{ + "GIMBAL_DEVICE_ERROR_FLAGS_AT_ROLL_LIMIT": GIMBAL_DEVICE_ERROR_FLAGS_AT_ROLL_LIMIT, + "GIMBAL_DEVICE_ERROR_FLAGS_AT_PITCH_LIMIT": GIMBAL_DEVICE_ERROR_FLAGS_AT_PITCH_LIMIT, + "GIMBAL_DEVICE_ERROR_FLAGS_AT_YAW_LIMIT": GIMBAL_DEVICE_ERROR_FLAGS_AT_YAW_LIMIT, + "GIMBAL_DEVICE_ERROR_FLAGS_ENCODER_ERROR": GIMBAL_DEVICE_ERROR_FLAGS_ENCODER_ERROR, + "GIMBAL_DEVICE_ERROR_FLAGS_POWER_ERROR": GIMBAL_DEVICE_ERROR_FLAGS_POWER_ERROR, + "GIMBAL_DEVICE_ERROR_FLAGS_MOTOR_ERROR": GIMBAL_DEVICE_ERROR_FLAGS_MOTOR_ERROR, + "GIMBAL_DEVICE_ERROR_FLAGS_SOFTWARE_ERROR": GIMBAL_DEVICE_ERROR_FLAGS_SOFTWARE_ERROR, + "GIMBAL_DEVICE_ERROR_FLAGS_COMMS_ERROR": GIMBAL_DEVICE_ERROR_FLAGS_COMMS_ERROR, + "GIMBAL_DEVICE_ERROR_FLAGS_CALIBRATION_RUNNING": GIMBAL_DEVICE_ERROR_FLAGS_CALIBRATION_RUNNING, + "GIMBAL_DEVICE_ERROR_FLAGS_NO_MANAGER": GIMBAL_DEVICE_ERROR_FLAGS_NO_MANAGER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_DEVICE_ERROR_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GIMBAL_DEVICE_ERROR_FLAGS { + for i := 0; i < 10; i++ { + mask := GIMBAL_DEVICE_ERROR_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GIMBAL_DEVICE_ERROR_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -62,19 +76,12 @@ func (e *GIMBAL_DEVICE_ERROR_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GIMBAL_DEVICE_ERROR_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_DEVICE_ERROR_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GIMBAL_DEVICE_ERROR_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_gimbal_device_flags.go b/pkg/dialects/common/enum_gimbal_device_flags.go index 98ca8c00a..93e616a29 100644 --- a/pkg/dialects/common/enum_gimbal_device_flags.go +++ b/pkg/dialects/common/enum_gimbal_device_flags.go @@ -46,12 +46,26 @@ var labels_GIMBAL_DEVICE_FLAGS = map[GIMBAL_DEVICE_FLAGS]string{ GIMBAL_DEVICE_FLAGS_RC_MIXED: "GIMBAL_DEVICE_FLAGS_RC_MIXED", } +var values_GIMBAL_DEVICE_FLAGS = map[string]GIMBAL_DEVICE_FLAGS{ + "GIMBAL_DEVICE_FLAGS_RETRACT": GIMBAL_DEVICE_FLAGS_RETRACT, + "GIMBAL_DEVICE_FLAGS_NEUTRAL": GIMBAL_DEVICE_FLAGS_NEUTRAL, + "GIMBAL_DEVICE_FLAGS_ROLL_LOCK": GIMBAL_DEVICE_FLAGS_ROLL_LOCK, + "GIMBAL_DEVICE_FLAGS_PITCH_LOCK": GIMBAL_DEVICE_FLAGS_PITCH_LOCK, + "GIMBAL_DEVICE_FLAGS_YAW_LOCK": GIMBAL_DEVICE_FLAGS_YAW_LOCK, + "GIMBAL_DEVICE_FLAGS_YAW_IN_VEHICLE_FRAME": GIMBAL_DEVICE_FLAGS_YAW_IN_VEHICLE_FRAME, + "GIMBAL_DEVICE_FLAGS_YAW_IN_EARTH_FRAME": GIMBAL_DEVICE_FLAGS_YAW_IN_EARTH_FRAME, + "GIMBAL_DEVICE_FLAGS_ACCEPTS_YAW_IN_EARTH_FRAME": GIMBAL_DEVICE_FLAGS_ACCEPTS_YAW_IN_EARTH_FRAME, + "GIMBAL_DEVICE_FLAGS_RC_EXCLUSIVE": GIMBAL_DEVICE_FLAGS_RC_EXCLUSIVE, + "GIMBAL_DEVICE_FLAGS_RC_MIXED": GIMBAL_DEVICE_FLAGS_RC_MIXED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_DEVICE_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GIMBAL_DEVICE_FLAGS { + for i := 0; i < 10; i++ { + mask := GIMBAL_DEVICE_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GIMBAL_DEVICE_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -62,19 +76,12 @@ func (e *GIMBAL_DEVICE_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GIMBAL_DEVICE_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_DEVICE_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GIMBAL_DEVICE_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_gimbal_manager_cap_flags.go b/pkg/dialects/common/enum_gimbal_manager_cap_flags.go index a551fb87b..ec0183376 100644 --- a/pkg/dialects/common/enum_gimbal_manager_cap_flags.go +++ b/pkg/dialects/common/enum_gimbal_manager_cap_flags.go @@ -64,12 +64,32 @@ var labels_GIMBAL_MANAGER_CAP_FLAGS = map[GIMBAL_MANAGER_CAP_FLAGS]string{ GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL: "GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL", } +var values_GIMBAL_MANAGER_CAP_FLAGS = map[string]GIMBAL_MANAGER_CAP_FLAGS{ + "GIMBAL_MANAGER_CAP_FLAGS_HAS_RETRACT": GIMBAL_MANAGER_CAP_FLAGS_HAS_RETRACT, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_NEUTRAL": GIMBAL_MANAGER_CAP_FLAGS_HAS_NEUTRAL, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_AXIS": GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_AXIS, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_FOLLOW": GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_FOLLOW, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_LOCK": GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_LOCK, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_AXIS": GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_AXIS, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_FOLLOW": GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_FOLLOW, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_LOCK": GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_LOCK, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_AXIS": GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_AXIS, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_FOLLOW": GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_FOLLOW, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_LOCK": GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_LOCK, + "GIMBAL_MANAGER_CAP_FLAGS_SUPPORTS_INFINITE_YAW": GIMBAL_MANAGER_CAP_FLAGS_SUPPORTS_INFINITE_YAW, + "GIMBAL_MANAGER_CAP_FLAGS_SUPPORTS_YAW_IN_EARTH_FRAME": GIMBAL_MANAGER_CAP_FLAGS_SUPPORTS_YAW_IN_EARTH_FRAME, + "GIMBAL_MANAGER_CAP_FLAGS_HAS_RC_INPUTS": GIMBAL_MANAGER_CAP_FLAGS_HAS_RC_INPUTS, + "GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_LOCAL": GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_LOCAL, + "GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL": GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_MANAGER_CAP_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GIMBAL_MANAGER_CAP_FLAGS { + for i := 0; i < 16; i++ { + mask := GIMBAL_MANAGER_CAP_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GIMBAL_MANAGER_CAP_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -80,19 +100,12 @@ func (e *GIMBAL_MANAGER_CAP_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GIMBAL_MANAGER_CAP_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_MANAGER_CAP_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GIMBAL_MANAGER_CAP_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_gimbal_manager_flags.go b/pkg/dialects/common/enum_gimbal_manager_flags.go index 5d46c58e4..67f8d6ba3 100644 --- a/pkg/dialects/common/enum_gimbal_manager_flags.go +++ b/pkg/dialects/common/enum_gimbal_manager_flags.go @@ -46,12 +46,26 @@ var labels_GIMBAL_MANAGER_FLAGS = map[GIMBAL_MANAGER_FLAGS]string{ GIMBAL_MANAGER_FLAGS_RC_MIXED: "GIMBAL_MANAGER_FLAGS_RC_MIXED", } +var values_GIMBAL_MANAGER_FLAGS = map[string]GIMBAL_MANAGER_FLAGS{ + "GIMBAL_MANAGER_FLAGS_RETRACT": GIMBAL_MANAGER_FLAGS_RETRACT, + "GIMBAL_MANAGER_FLAGS_NEUTRAL": GIMBAL_MANAGER_FLAGS_NEUTRAL, + "GIMBAL_MANAGER_FLAGS_ROLL_LOCK": GIMBAL_MANAGER_FLAGS_ROLL_LOCK, + "GIMBAL_MANAGER_FLAGS_PITCH_LOCK": GIMBAL_MANAGER_FLAGS_PITCH_LOCK, + "GIMBAL_MANAGER_FLAGS_YAW_LOCK": GIMBAL_MANAGER_FLAGS_YAW_LOCK, + "GIMBAL_MANAGER_FLAGS_YAW_IN_VEHICLE_FRAME": GIMBAL_MANAGER_FLAGS_YAW_IN_VEHICLE_FRAME, + "GIMBAL_MANAGER_FLAGS_YAW_IN_EARTH_FRAME": GIMBAL_MANAGER_FLAGS_YAW_IN_EARTH_FRAME, + "GIMBAL_MANAGER_FLAGS_ACCEPTS_YAW_IN_EARTH_FRAME": GIMBAL_MANAGER_FLAGS_ACCEPTS_YAW_IN_EARTH_FRAME, + "GIMBAL_MANAGER_FLAGS_RC_EXCLUSIVE": GIMBAL_MANAGER_FLAGS_RC_EXCLUSIVE, + "GIMBAL_MANAGER_FLAGS_RC_MIXED": GIMBAL_MANAGER_FLAGS_RC_MIXED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GIMBAL_MANAGER_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GIMBAL_MANAGER_FLAGS { + for i := 0; i < 10; i++ { + mask := GIMBAL_MANAGER_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GIMBAL_MANAGER_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -62,19 +76,12 @@ func (e *GIMBAL_MANAGER_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GIMBAL_MANAGER_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GIMBAL_MANAGER_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GIMBAL_MANAGER_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_gps_fix_type.go b/pkg/dialects/common/enum_gps_fix_type.go index d3d7c65f0..3ac635c98 100644 --- a/pkg/dialects/common/enum_gps_fix_type.go +++ b/pkg/dialects/common/enum_gps_fix_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Type of GPS fix @@ -43,40 +43,42 @@ var labels_GPS_FIX_TYPE = map[GPS_FIX_TYPE]string{ GPS_FIX_TYPE_PPP: "GPS_FIX_TYPE_PPP", } +var values_GPS_FIX_TYPE = map[string]GPS_FIX_TYPE{ + "GPS_FIX_TYPE_NO_GPS": GPS_FIX_TYPE_NO_GPS, + "GPS_FIX_TYPE_NO_FIX": GPS_FIX_TYPE_NO_FIX, + "GPS_FIX_TYPE_2D_FIX": GPS_FIX_TYPE_2D_FIX, + "GPS_FIX_TYPE_3D_FIX": GPS_FIX_TYPE_3D_FIX, + "GPS_FIX_TYPE_DGPS": GPS_FIX_TYPE_DGPS, + "GPS_FIX_TYPE_RTK_FLOAT": GPS_FIX_TYPE_RTK_FLOAT, + "GPS_FIX_TYPE_RTK_FIXED": GPS_FIX_TYPE_RTK_FIXED, + "GPS_FIX_TYPE_STATIC": GPS_FIX_TYPE_STATIC, + "GPS_FIX_TYPE_PPP": GPS_FIX_TYPE_PPP, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GPS_FIX_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GPS_FIX_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GPS_FIX_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GPS_FIX_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GPS_FIX_TYPE - for _, label := range labels { - found := false - for value, l := range labels_GPS_FIX_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GPS_FIX_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GPS_FIX_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GPS_FIX_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_gps_input_ignore_flags.go b/pkg/dialects/common/enum_gps_input_ignore_flags.go index 8fddee0fb..3194a600d 100644 --- a/pkg/dialects/common/enum_gps_input_ignore_flags.go +++ b/pkg/dialects/common/enum_gps_input_ignore_flags.go @@ -39,12 +39,24 @@ var labels_GPS_INPUT_IGNORE_FLAGS = map[GPS_INPUT_IGNORE_FLAGS]string{ GPS_INPUT_IGNORE_FLAG_VERTICAL_ACCURACY: "GPS_INPUT_IGNORE_FLAG_VERTICAL_ACCURACY", } +var values_GPS_INPUT_IGNORE_FLAGS = map[string]GPS_INPUT_IGNORE_FLAGS{ + "GPS_INPUT_IGNORE_FLAG_ALT": GPS_INPUT_IGNORE_FLAG_ALT, + "GPS_INPUT_IGNORE_FLAG_HDOP": GPS_INPUT_IGNORE_FLAG_HDOP, + "GPS_INPUT_IGNORE_FLAG_VDOP": GPS_INPUT_IGNORE_FLAG_VDOP, + "GPS_INPUT_IGNORE_FLAG_VEL_HORIZ": GPS_INPUT_IGNORE_FLAG_VEL_HORIZ, + "GPS_INPUT_IGNORE_FLAG_VEL_VERT": GPS_INPUT_IGNORE_FLAG_VEL_VERT, + "GPS_INPUT_IGNORE_FLAG_SPEED_ACCURACY": GPS_INPUT_IGNORE_FLAG_SPEED_ACCURACY, + "GPS_INPUT_IGNORE_FLAG_HORIZONTAL_ACCURACY": GPS_INPUT_IGNORE_FLAG_HORIZONTAL_ACCURACY, + "GPS_INPUT_IGNORE_FLAG_VERTICAL_ACCURACY": GPS_INPUT_IGNORE_FLAG_VERTICAL_ACCURACY, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GPS_INPUT_IGNORE_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_GPS_INPUT_IGNORE_FLAGS { + for i := 0; i < 8; i++ { + mask := GPS_INPUT_IGNORE_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_GPS_INPUT_IGNORE_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -55,19 +67,12 @@ func (e *GPS_INPUT_IGNORE_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask GPS_INPUT_IGNORE_FLAGS for _, label := range labels { - found := false - for value, l := range labels_GPS_INPUT_IGNORE_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_GPS_INPUT_IGNORE_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_gripper_actions.go b/pkg/dialects/common/enum_gripper_actions.go index 8d5bdb6f7..26876a671 100644 --- a/pkg/dialects/common/enum_gripper_actions.go +++ b/pkg/dialects/common/enum_gripper_actions.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Gripper actions. @@ -22,40 +22,35 @@ var labels_GRIPPER_ACTIONS = map[GRIPPER_ACTIONS]string{ GRIPPER_ACTION_GRAB: "GRIPPER_ACTION_GRAB", } +var values_GRIPPER_ACTIONS = map[string]GRIPPER_ACTIONS{ + "GRIPPER_ACTION_RELEASE": GRIPPER_ACTION_RELEASE, + "GRIPPER_ACTION_GRAB": GRIPPER_ACTION_GRAB, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e GRIPPER_ACTIONS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_GRIPPER_ACTIONS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_GRIPPER_ACTIONS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *GRIPPER_ACTIONS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask GRIPPER_ACTIONS - for _, label := range labels { - found := false - for value, l := range labels_GRIPPER_ACTIONS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_GRIPPER_ACTIONS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e GRIPPER_ACTIONS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_GRIPPER_ACTIONS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_highres_imu_updated_flags.go b/pkg/dialects/common/enum_highres_imu_updated_flags.go index 40023679f..cc5d4388f 100644 --- a/pkg/dialects/common/enum_highres_imu_updated_flags.go +++ b/pkg/dialects/common/enum_highres_imu_updated_flags.go @@ -61,12 +61,31 @@ var labels_HIGHRES_IMU_UPDATED_FLAGS = map[HIGHRES_IMU_UPDATED_FLAGS]string{ HIGHRES_IMU_UPDATED_ALL: "HIGHRES_IMU_UPDATED_ALL", } +var values_HIGHRES_IMU_UPDATED_FLAGS = map[string]HIGHRES_IMU_UPDATED_FLAGS{ + "HIGHRES_IMU_UPDATED_NONE": HIGHRES_IMU_UPDATED_NONE, + "HIGHRES_IMU_UPDATED_XACC": HIGHRES_IMU_UPDATED_XACC, + "HIGHRES_IMU_UPDATED_YACC": HIGHRES_IMU_UPDATED_YACC, + "HIGHRES_IMU_UPDATED_ZACC": HIGHRES_IMU_UPDATED_ZACC, + "HIGHRES_IMU_UPDATED_XGYRO": HIGHRES_IMU_UPDATED_XGYRO, + "HIGHRES_IMU_UPDATED_YGYRO": HIGHRES_IMU_UPDATED_YGYRO, + "HIGHRES_IMU_UPDATED_ZGYRO": HIGHRES_IMU_UPDATED_ZGYRO, + "HIGHRES_IMU_UPDATED_XMAG": HIGHRES_IMU_UPDATED_XMAG, + "HIGHRES_IMU_UPDATED_YMAG": HIGHRES_IMU_UPDATED_YMAG, + "HIGHRES_IMU_UPDATED_ZMAG": HIGHRES_IMU_UPDATED_ZMAG, + "HIGHRES_IMU_UPDATED_ABS_PRESSURE": HIGHRES_IMU_UPDATED_ABS_PRESSURE, + "HIGHRES_IMU_UPDATED_DIFF_PRESSURE": HIGHRES_IMU_UPDATED_DIFF_PRESSURE, + "HIGHRES_IMU_UPDATED_PRESSURE_ALT": HIGHRES_IMU_UPDATED_PRESSURE_ALT, + "HIGHRES_IMU_UPDATED_TEMPERATURE": HIGHRES_IMU_UPDATED_TEMPERATURE, + "HIGHRES_IMU_UPDATED_ALL": HIGHRES_IMU_UPDATED_ALL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e HIGHRES_IMU_UPDATED_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_HIGHRES_IMU_UPDATED_FLAGS { + for i := 0; i < 15; i++ { + mask := HIGHRES_IMU_UPDATED_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_HIGHRES_IMU_UPDATED_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -77,19 +96,12 @@ func (e *HIGHRES_IMU_UPDATED_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask HIGHRES_IMU_UPDATED_FLAGS for _, label := range labels { - found := false - for value, l := range labels_HIGHRES_IMU_UPDATED_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_HIGHRES_IMU_UPDATED_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_hil_sensor_updated_flags.go b/pkg/dialects/common/enum_hil_sensor_updated_flags.go index cfcc311e8..ee6d5c9c8 100644 --- a/pkg/dialects/common/enum_hil_sensor_updated_flags.go +++ b/pkg/dialects/common/enum_hil_sensor_updated_flags.go @@ -61,12 +61,31 @@ var labels_HIL_SENSOR_UPDATED_FLAGS = map[HIL_SENSOR_UPDATED_FLAGS]string{ HIL_SENSOR_UPDATED_RESET: "HIL_SENSOR_UPDATED_RESET", } +var values_HIL_SENSOR_UPDATED_FLAGS = map[string]HIL_SENSOR_UPDATED_FLAGS{ + "HIL_SENSOR_UPDATED_NONE": HIL_SENSOR_UPDATED_NONE, + "HIL_SENSOR_UPDATED_XACC": HIL_SENSOR_UPDATED_XACC, + "HIL_SENSOR_UPDATED_YACC": HIL_SENSOR_UPDATED_YACC, + "HIL_SENSOR_UPDATED_ZACC": HIL_SENSOR_UPDATED_ZACC, + "HIL_SENSOR_UPDATED_XGYRO": HIL_SENSOR_UPDATED_XGYRO, + "HIL_SENSOR_UPDATED_YGYRO": HIL_SENSOR_UPDATED_YGYRO, + "HIL_SENSOR_UPDATED_ZGYRO": HIL_SENSOR_UPDATED_ZGYRO, + "HIL_SENSOR_UPDATED_XMAG": HIL_SENSOR_UPDATED_XMAG, + "HIL_SENSOR_UPDATED_YMAG": HIL_SENSOR_UPDATED_YMAG, + "HIL_SENSOR_UPDATED_ZMAG": HIL_SENSOR_UPDATED_ZMAG, + "HIL_SENSOR_UPDATED_ABS_PRESSURE": HIL_SENSOR_UPDATED_ABS_PRESSURE, + "HIL_SENSOR_UPDATED_DIFF_PRESSURE": HIL_SENSOR_UPDATED_DIFF_PRESSURE, + "HIL_SENSOR_UPDATED_PRESSURE_ALT": HIL_SENSOR_UPDATED_PRESSURE_ALT, + "HIL_SENSOR_UPDATED_TEMPERATURE": HIL_SENSOR_UPDATED_TEMPERATURE, + "HIL_SENSOR_UPDATED_RESET": HIL_SENSOR_UPDATED_RESET, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e HIL_SENSOR_UPDATED_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_HIL_SENSOR_UPDATED_FLAGS { + for i := 0; i < 15; i++ { + mask := HIL_SENSOR_UPDATED_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_HIL_SENSOR_UPDATED_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -77,19 +96,12 @@ func (e *HIL_SENSOR_UPDATED_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask HIL_SENSOR_UPDATED_FLAGS for _, label := range labels { - found := false - for value, l := range labels_HIL_SENSOR_UPDATED_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_HIL_SENSOR_UPDATED_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_hl_failure_flag.go b/pkg/dialects/common/enum_hl_failure_flag.go index 697f17e4a..bab9bf7f9 100644 --- a/pkg/dialects/common/enum_hl_failure_flag.go +++ b/pkg/dialects/common/enum_hl_failure_flag.go @@ -58,12 +58,30 @@ var labels_HL_FAILURE_FLAG = map[HL_FAILURE_FLAG]string{ HL_FAILURE_FLAG_MISSION: "HL_FAILURE_FLAG_MISSION", } +var values_HL_FAILURE_FLAG = map[string]HL_FAILURE_FLAG{ + "HL_FAILURE_FLAG_GPS": HL_FAILURE_FLAG_GPS, + "HL_FAILURE_FLAG_DIFFERENTIAL_PRESSURE": HL_FAILURE_FLAG_DIFFERENTIAL_PRESSURE, + "HL_FAILURE_FLAG_ABSOLUTE_PRESSURE": HL_FAILURE_FLAG_ABSOLUTE_PRESSURE, + "HL_FAILURE_FLAG_3D_ACCEL": HL_FAILURE_FLAG_3D_ACCEL, + "HL_FAILURE_FLAG_3D_GYRO": HL_FAILURE_FLAG_3D_GYRO, + "HL_FAILURE_FLAG_3D_MAG": HL_FAILURE_FLAG_3D_MAG, + "HL_FAILURE_FLAG_TERRAIN": HL_FAILURE_FLAG_TERRAIN, + "HL_FAILURE_FLAG_BATTERY": HL_FAILURE_FLAG_BATTERY, + "HL_FAILURE_FLAG_RC_RECEIVER": HL_FAILURE_FLAG_RC_RECEIVER, + "HL_FAILURE_FLAG_OFFBOARD_LINK": HL_FAILURE_FLAG_OFFBOARD_LINK, + "HL_FAILURE_FLAG_ENGINE": HL_FAILURE_FLAG_ENGINE, + "HL_FAILURE_FLAG_GEOFENCE": HL_FAILURE_FLAG_GEOFENCE, + "HL_FAILURE_FLAG_ESTIMATOR": HL_FAILURE_FLAG_ESTIMATOR, + "HL_FAILURE_FLAG_MISSION": HL_FAILURE_FLAG_MISSION, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e HL_FAILURE_FLAG) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_HL_FAILURE_FLAG { + for i := 0; i < 14; i++ { + mask := HL_FAILURE_FLAG(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_HL_FAILURE_FLAG[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -74,19 +92,12 @@ func (e *HL_FAILURE_FLAG) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask HL_FAILURE_FLAG for _, label := range labels { - found := false - for value, l := range labels_HL_FAILURE_FLAG { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_HL_FAILURE_FLAG[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_landing_target_type.go b/pkg/dialects/common/enum_landing_target_type.go index fe7c4e58a..60a72026f 100644 --- a/pkg/dialects/common/enum_landing_target_type.go +++ b/pkg/dialects/common/enum_landing_target_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Type of landing target @@ -28,40 +28,37 @@ var labels_LANDING_TARGET_TYPE = map[LANDING_TARGET_TYPE]string{ LANDING_TARGET_TYPE_VISION_OTHER: "LANDING_TARGET_TYPE_VISION_OTHER", } +var values_LANDING_TARGET_TYPE = map[string]LANDING_TARGET_TYPE{ + "LANDING_TARGET_TYPE_LIGHT_BEACON": LANDING_TARGET_TYPE_LIGHT_BEACON, + "LANDING_TARGET_TYPE_RADIO_BEACON": LANDING_TARGET_TYPE_RADIO_BEACON, + "LANDING_TARGET_TYPE_VISION_FIDUCIAL": LANDING_TARGET_TYPE_VISION_FIDUCIAL, + "LANDING_TARGET_TYPE_VISION_OTHER": LANDING_TARGET_TYPE_VISION_OTHER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e LANDING_TARGET_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_LANDING_TARGET_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_LANDING_TARGET_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *LANDING_TARGET_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask LANDING_TARGET_TYPE - for _, label := range labels { - found := false - for value, l := range labels_LANDING_TARGET_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_LANDING_TARGET_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e LANDING_TARGET_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_LANDING_TARGET_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mag_cal_status.go b/pkg/dialects/common/enum_mag_cal_status.go index ed4394642..b55cf0e19 100644 --- a/pkg/dialects/common/enum_mag_cal_status.go +++ b/pkg/dialects/common/enum_mag_cal_status.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAG_CAL_STATUS uint32 @@ -31,40 +31,41 @@ var labels_MAG_CAL_STATUS = map[MAG_CAL_STATUS]string{ MAG_CAL_BAD_RADIUS: "MAG_CAL_BAD_RADIUS", } +var values_MAG_CAL_STATUS = map[string]MAG_CAL_STATUS{ + "MAG_CAL_NOT_STARTED": MAG_CAL_NOT_STARTED, + "MAG_CAL_WAITING_TO_START": MAG_CAL_WAITING_TO_START, + "MAG_CAL_RUNNING_STEP_ONE": MAG_CAL_RUNNING_STEP_ONE, + "MAG_CAL_RUNNING_STEP_TWO": MAG_CAL_RUNNING_STEP_TWO, + "MAG_CAL_SUCCESS": MAG_CAL_SUCCESS, + "MAG_CAL_FAILED": MAG_CAL_FAILED, + "MAG_CAL_BAD_ORIENTATION": MAG_CAL_BAD_ORIENTATION, + "MAG_CAL_BAD_RADIUS": MAG_CAL_BAD_RADIUS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAG_CAL_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAG_CAL_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAG_CAL_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAG_CAL_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAG_CAL_STATUS - for _, label := range labels { - found := false - for value, l := range labels_MAG_CAL_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAG_CAL_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAG_CAL_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAG_CAL_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_arm_auth_denied_reason.go b/pkg/dialects/common/enum_mav_arm_auth_denied_reason.go index 7d521facd..a388bd0c1 100644 --- a/pkg/dialects/common/enum_mav_arm_auth_denied_reason.go +++ b/pkg/dialects/common/enum_mav_arm_auth_denied_reason.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ARM_AUTH_DENIED_REASON uint32 @@ -33,40 +33,39 @@ var labels_MAV_ARM_AUTH_DENIED_REASON = map[MAV_ARM_AUTH_DENIED_REASON]string{ MAV_ARM_AUTH_DENIED_REASON_BAD_WEATHER: "MAV_ARM_AUTH_DENIED_REASON_BAD_WEATHER", } +var values_MAV_ARM_AUTH_DENIED_REASON = map[string]MAV_ARM_AUTH_DENIED_REASON{ + "MAV_ARM_AUTH_DENIED_REASON_GENERIC": MAV_ARM_AUTH_DENIED_REASON_GENERIC, + "MAV_ARM_AUTH_DENIED_REASON_NONE": MAV_ARM_AUTH_DENIED_REASON_NONE, + "MAV_ARM_AUTH_DENIED_REASON_INVALID_WAYPOINT": MAV_ARM_AUTH_DENIED_REASON_INVALID_WAYPOINT, + "MAV_ARM_AUTH_DENIED_REASON_TIMEOUT": MAV_ARM_AUTH_DENIED_REASON_TIMEOUT, + "MAV_ARM_AUTH_DENIED_REASON_AIRSPACE_IN_USE": MAV_ARM_AUTH_DENIED_REASON_AIRSPACE_IN_USE, + "MAV_ARM_AUTH_DENIED_REASON_BAD_WEATHER": MAV_ARM_AUTH_DENIED_REASON_BAD_WEATHER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ARM_AUTH_DENIED_REASON) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ARM_AUTH_DENIED_REASON { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ARM_AUTH_DENIED_REASON[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ARM_AUTH_DENIED_REASON) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ARM_AUTH_DENIED_REASON - for _, label := range labels { - found := false - for value, l := range labels_MAV_ARM_AUTH_DENIED_REASON { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ARM_AUTH_DENIED_REASON[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ARM_AUTH_DENIED_REASON) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ARM_AUTH_DENIED_REASON[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_battery_charge_state.go b/pkg/dialects/common/enum_mav_battery_charge_state.go index 3aee9abf6..2ef474d05 100644 --- a/pkg/dialects/common/enum_mav_battery_charge_state.go +++ b/pkg/dialects/common/enum_mav_battery_charge_state.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration for battery charge states. @@ -40,40 +40,41 @@ var labels_MAV_BATTERY_CHARGE_STATE = map[MAV_BATTERY_CHARGE_STATE]string{ MAV_BATTERY_CHARGE_STATE_CHARGING: "MAV_BATTERY_CHARGE_STATE_CHARGING", } +var values_MAV_BATTERY_CHARGE_STATE = map[string]MAV_BATTERY_CHARGE_STATE{ + "MAV_BATTERY_CHARGE_STATE_UNDEFINED": MAV_BATTERY_CHARGE_STATE_UNDEFINED, + "MAV_BATTERY_CHARGE_STATE_OK": MAV_BATTERY_CHARGE_STATE_OK, + "MAV_BATTERY_CHARGE_STATE_LOW": MAV_BATTERY_CHARGE_STATE_LOW, + "MAV_BATTERY_CHARGE_STATE_CRITICAL": MAV_BATTERY_CHARGE_STATE_CRITICAL, + "MAV_BATTERY_CHARGE_STATE_EMERGENCY": MAV_BATTERY_CHARGE_STATE_EMERGENCY, + "MAV_BATTERY_CHARGE_STATE_FAILED": MAV_BATTERY_CHARGE_STATE_FAILED, + "MAV_BATTERY_CHARGE_STATE_UNHEALTHY": MAV_BATTERY_CHARGE_STATE_UNHEALTHY, + "MAV_BATTERY_CHARGE_STATE_CHARGING": MAV_BATTERY_CHARGE_STATE_CHARGING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_BATTERY_CHARGE_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_BATTERY_CHARGE_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_BATTERY_CHARGE_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_BATTERY_CHARGE_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_BATTERY_CHARGE_STATE - for _, label := range labels { - found := false - for value, l := range labels_MAV_BATTERY_CHARGE_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_BATTERY_CHARGE_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_BATTERY_CHARGE_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_BATTERY_CHARGE_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_battery_fault.go b/pkg/dialects/common/enum_mav_battery_fault.go index aab31f8b6..8ac5daaca 100644 --- a/pkg/dialects/common/enum_mav_battery_fault.go +++ b/pkg/dialects/common/enum_mav_battery_fault.go @@ -43,12 +43,25 @@ var labels_MAV_BATTERY_FAULT = map[MAV_BATTERY_FAULT]string{ BATTERY_FAULT_INCOMPATIBLE_CELLS_CONFIGURATION: "BATTERY_FAULT_INCOMPATIBLE_CELLS_CONFIGURATION", } +var values_MAV_BATTERY_FAULT = map[string]MAV_BATTERY_FAULT{ + "MAV_BATTERY_FAULT_DEEP_DISCHARGE": MAV_BATTERY_FAULT_DEEP_DISCHARGE, + "MAV_BATTERY_FAULT_SPIKES": MAV_BATTERY_FAULT_SPIKES, + "MAV_BATTERY_FAULT_CELL_FAIL": MAV_BATTERY_FAULT_CELL_FAIL, + "MAV_BATTERY_FAULT_OVER_CURRENT": MAV_BATTERY_FAULT_OVER_CURRENT, + "MAV_BATTERY_FAULT_OVER_TEMPERATURE": MAV_BATTERY_FAULT_OVER_TEMPERATURE, + "MAV_BATTERY_FAULT_UNDER_TEMPERATURE": MAV_BATTERY_FAULT_UNDER_TEMPERATURE, + "MAV_BATTERY_FAULT_INCOMPATIBLE_VOLTAGE": MAV_BATTERY_FAULT_INCOMPATIBLE_VOLTAGE, + "MAV_BATTERY_FAULT_INCOMPATIBLE_FIRMWARE": MAV_BATTERY_FAULT_INCOMPATIBLE_FIRMWARE, + "BATTERY_FAULT_INCOMPATIBLE_CELLS_CONFIGURATION": BATTERY_FAULT_INCOMPATIBLE_CELLS_CONFIGURATION, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_BATTERY_FAULT) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_BATTERY_FAULT { + for i := 0; i < 9; i++ { + mask := MAV_BATTERY_FAULT(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_BATTERY_FAULT[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -59,19 +72,12 @@ func (e *MAV_BATTERY_FAULT) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_BATTERY_FAULT for _, label := range labels { - found := false - for value, l := range labels_MAV_BATTERY_FAULT { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_BATTERY_FAULT[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_battery_function.go b/pkg/dialects/common/enum_mav_battery_function.go index d315ff77e..63e5f36a3 100644 --- a/pkg/dialects/common/enum_mav_battery_function.go +++ b/pkg/dialects/common/enum_mav_battery_function.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of battery functions @@ -31,40 +31,38 @@ var labels_MAV_BATTERY_FUNCTION = map[MAV_BATTERY_FUNCTION]string{ MAV_BATTERY_FUNCTION_PAYLOAD: "MAV_BATTERY_FUNCTION_PAYLOAD", } +var values_MAV_BATTERY_FUNCTION = map[string]MAV_BATTERY_FUNCTION{ + "MAV_BATTERY_FUNCTION_UNKNOWN": MAV_BATTERY_FUNCTION_UNKNOWN, + "MAV_BATTERY_FUNCTION_ALL": MAV_BATTERY_FUNCTION_ALL, + "MAV_BATTERY_FUNCTION_PROPULSION": MAV_BATTERY_FUNCTION_PROPULSION, + "MAV_BATTERY_FUNCTION_AVIONICS": MAV_BATTERY_FUNCTION_AVIONICS, + "MAV_BATTERY_FUNCTION_PAYLOAD": MAV_BATTERY_FUNCTION_PAYLOAD, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_BATTERY_FUNCTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_BATTERY_FUNCTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_BATTERY_FUNCTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_BATTERY_FUNCTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_BATTERY_FUNCTION - for _, label := range labels { - found := false - for value, l := range labels_MAV_BATTERY_FUNCTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_BATTERY_FUNCTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_BATTERY_FUNCTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_BATTERY_FUNCTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_battery_mode.go b/pkg/dialects/common/enum_mav_battery_mode.go index cf31faaf1..8c853ad25 100644 --- a/pkg/dialects/common/enum_mav_battery_mode.go +++ b/pkg/dialects/common/enum_mav_battery_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Battery mode. Note, the normal operation mode (i.e. when flying) should be reported as MAV_BATTERY_MODE_UNKNOWN to allow message trimming in normal flight. @@ -25,40 +25,36 @@ var labels_MAV_BATTERY_MODE = map[MAV_BATTERY_MODE]string{ MAV_BATTERY_MODE_HOT_SWAP: "MAV_BATTERY_MODE_HOT_SWAP", } +var values_MAV_BATTERY_MODE = map[string]MAV_BATTERY_MODE{ + "MAV_BATTERY_MODE_UNKNOWN": MAV_BATTERY_MODE_UNKNOWN, + "MAV_BATTERY_MODE_AUTO_DISCHARGING": MAV_BATTERY_MODE_AUTO_DISCHARGING, + "MAV_BATTERY_MODE_HOT_SWAP": MAV_BATTERY_MODE_HOT_SWAP, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_BATTERY_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_BATTERY_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_BATTERY_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_BATTERY_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_BATTERY_MODE - for _, label := range labels { - found := false - for value, l := range labels_MAV_BATTERY_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_BATTERY_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_BATTERY_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_BATTERY_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_battery_type.go b/pkg/dialects/common/enum_mav_battery_type.go index 20e8553de..1ed12fde1 100644 --- a/pkg/dialects/common/enum_mav_battery_type.go +++ b/pkg/dialects/common/enum_mav_battery_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of battery types @@ -31,40 +31,38 @@ var labels_MAV_BATTERY_TYPE = map[MAV_BATTERY_TYPE]string{ MAV_BATTERY_TYPE_NIMH: "MAV_BATTERY_TYPE_NIMH", } +var values_MAV_BATTERY_TYPE = map[string]MAV_BATTERY_TYPE{ + "MAV_BATTERY_TYPE_UNKNOWN": MAV_BATTERY_TYPE_UNKNOWN, + "MAV_BATTERY_TYPE_LIPO": MAV_BATTERY_TYPE_LIPO, + "MAV_BATTERY_TYPE_LIFE": MAV_BATTERY_TYPE_LIFE, + "MAV_BATTERY_TYPE_LION": MAV_BATTERY_TYPE_LION, + "MAV_BATTERY_TYPE_NIMH": MAV_BATTERY_TYPE_NIMH, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_BATTERY_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_BATTERY_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_BATTERY_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_BATTERY_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_BATTERY_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_BATTERY_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_BATTERY_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_BATTERY_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_BATTERY_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_cmd.go b/pkg/dialects/common/enum_mav_cmd.go index 77524b7d7..9adc17486 100644 --- a/pkg/dialects/common/enum_mav_cmd.go +++ b/pkg/dialects/common/enum_mav_cmd.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -542,40 +542,192 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_CAN_FORWARD: "MAV_CMD_CAN_FORWARD", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_collision_action.go b/pkg/dialects/common/enum_mav_collision_action.go index 805e07672..0021fbdd0 100644 --- a/pkg/dialects/common/enum_mav_collision_action.go +++ b/pkg/dialects/common/enum_mav_collision_action.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Possible actions an aircraft can take to avoid a collision. @@ -37,40 +37,40 @@ var labels_MAV_COLLISION_ACTION = map[MAV_COLLISION_ACTION]string{ MAV_COLLISION_ACTION_HOVER: "MAV_COLLISION_ACTION_HOVER", } +var values_MAV_COLLISION_ACTION = map[string]MAV_COLLISION_ACTION{ + "MAV_COLLISION_ACTION_NONE": MAV_COLLISION_ACTION_NONE, + "MAV_COLLISION_ACTION_REPORT": MAV_COLLISION_ACTION_REPORT, + "MAV_COLLISION_ACTION_ASCEND_OR_DESCEND": MAV_COLLISION_ACTION_ASCEND_OR_DESCEND, + "MAV_COLLISION_ACTION_MOVE_HORIZONTALLY": MAV_COLLISION_ACTION_MOVE_HORIZONTALLY, + "MAV_COLLISION_ACTION_MOVE_PERPENDICULAR": MAV_COLLISION_ACTION_MOVE_PERPENDICULAR, + "MAV_COLLISION_ACTION_RTL": MAV_COLLISION_ACTION_RTL, + "MAV_COLLISION_ACTION_HOVER": MAV_COLLISION_ACTION_HOVER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_COLLISION_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_COLLISION_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_COLLISION_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_COLLISION_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_COLLISION_ACTION - for _, label := range labels { - found := false - for value, l := range labels_MAV_COLLISION_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_COLLISION_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_COLLISION_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_COLLISION_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_collision_src.go b/pkg/dialects/common/enum_mav_collision_src.go index c037fa2c7..17a0d3f72 100644 --- a/pkg/dialects/common/enum_mav_collision_src.go +++ b/pkg/dialects/common/enum_mav_collision_src.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Source of information about this collision. @@ -22,40 +22,35 @@ var labels_MAV_COLLISION_SRC = map[MAV_COLLISION_SRC]string{ MAV_COLLISION_SRC_MAVLINK_GPS_GLOBAL_INT: "MAV_COLLISION_SRC_MAVLINK_GPS_GLOBAL_INT", } +var values_MAV_COLLISION_SRC = map[string]MAV_COLLISION_SRC{ + "MAV_COLLISION_SRC_ADSB": MAV_COLLISION_SRC_ADSB, + "MAV_COLLISION_SRC_MAVLINK_GPS_GLOBAL_INT": MAV_COLLISION_SRC_MAVLINK_GPS_GLOBAL_INT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_COLLISION_SRC) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_COLLISION_SRC { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_COLLISION_SRC[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_COLLISION_SRC) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_COLLISION_SRC - for _, label := range labels { - found := false - for value, l := range labels_MAV_COLLISION_SRC { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_COLLISION_SRC[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_COLLISION_SRC) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_COLLISION_SRC[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_collision_threat_level.go b/pkg/dialects/common/enum_mav_collision_threat_level.go index ee41b7391..2f22c4199 100644 --- a/pkg/dialects/common/enum_mav_collision_threat_level.go +++ b/pkg/dialects/common/enum_mav_collision_threat_level.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Aircraft-rated danger from this threat. @@ -25,40 +25,36 @@ var labels_MAV_COLLISION_THREAT_LEVEL = map[MAV_COLLISION_THREAT_LEVEL]string{ MAV_COLLISION_THREAT_LEVEL_HIGH: "MAV_COLLISION_THREAT_LEVEL_HIGH", } +var values_MAV_COLLISION_THREAT_LEVEL = map[string]MAV_COLLISION_THREAT_LEVEL{ + "MAV_COLLISION_THREAT_LEVEL_NONE": MAV_COLLISION_THREAT_LEVEL_NONE, + "MAV_COLLISION_THREAT_LEVEL_LOW": MAV_COLLISION_THREAT_LEVEL_LOW, + "MAV_COLLISION_THREAT_LEVEL_HIGH": MAV_COLLISION_THREAT_LEVEL_HIGH, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_COLLISION_THREAT_LEVEL) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_COLLISION_THREAT_LEVEL { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_COLLISION_THREAT_LEVEL[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_COLLISION_THREAT_LEVEL) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_COLLISION_THREAT_LEVEL - for _, label := range labels { - found := false - for value, l := range labels_MAV_COLLISION_THREAT_LEVEL { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_COLLISION_THREAT_LEVEL[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_COLLISION_THREAT_LEVEL) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_COLLISION_THREAT_LEVEL[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_data_stream.go b/pkg/dialects/common/enum_mav_data_stream.go index 6a7e45bd6..49c0fb94a 100644 --- a/pkg/dialects/common/enum_mav_data_stream.go +++ b/pkg/dialects/common/enum_mav_data_stream.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // A data stream is not a fixed set of messages, but rather a @@ -45,40 +45,42 @@ var labels_MAV_DATA_STREAM = map[MAV_DATA_STREAM]string{ MAV_DATA_STREAM_EXTRA3: "MAV_DATA_STREAM_EXTRA3", } +var values_MAV_DATA_STREAM = map[string]MAV_DATA_STREAM{ + "MAV_DATA_STREAM_ALL": MAV_DATA_STREAM_ALL, + "MAV_DATA_STREAM_RAW_SENSORS": MAV_DATA_STREAM_RAW_SENSORS, + "MAV_DATA_STREAM_EXTENDED_STATUS": MAV_DATA_STREAM_EXTENDED_STATUS, + "MAV_DATA_STREAM_RC_CHANNELS": MAV_DATA_STREAM_RC_CHANNELS, + "MAV_DATA_STREAM_RAW_CONTROLLER": MAV_DATA_STREAM_RAW_CONTROLLER, + "MAV_DATA_STREAM_POSITION": MAV_DATA_STREAM_POSITION, + "MAV_DATA_STREAM_EXTRA1": MAV_DATA_STREAM_EXTRA1, + "MAV_DATA_STREAM_EXTRA2": MAV_DATA_STREAM_EXTRA2, + "MAV_DATA_STREAM_EXTRA3": MAV_DATA_STREAM_EXTRA3, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_DATA_STREAM) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_DATA_STREAM { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_DATA_STREAM[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_DATA_STREAM) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_DATA_STREAM - for _, label := range labels { - found := false - for value, l := range labels_MAV_DATA_STREAM { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_DATA_STREAM[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_DATA_STREAM) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_DATA_STREAM[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_distance_sensor.go b/pkg/dialects/common/enum_mav_distance_sensor.go index 5713ce29d..97f4b50af 100644 --- a/pkg/dialects/common/enum_mav_distance_sensor.go +++ b/pkg/dialects/common/enum_mav_distance_sensor.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of distance sensor types @@ -31,40 +31,38 @@ var labels_MAV_DISTANCE_SENSOR = map[MAV_DISTANCE_SENSOR]string{ MAV_DISTANCE_SENSOR_UNKNOWN: "MAV_DISTANCE_SENSOR_UNKNOWN", } +var values_MAV_DISTANCE_SENSOR = map[string]MAV_DISTANCE_SENSOR{ + "MAV_DISTANCE_SENSOR_LASER": MAV_DISTANCE_SENSOR_LASER, + "MAV_DISTANCE_SENSOR_ULTRASOUND": MAV_DISTANCE_SENSOR_ULTRASOUND, + "MAV_DISTANCE_SENSOR_INFRARED": MAV_DISTANCE_SENSOR_INFRARED, + "MAV_DISTANCE_SENSOR_RADAR": MAV_DISTANCE_SENSOR_RADAR, + "MAV_DISTANCE_SENSOR_UNKNOWN": MAV_DISTANCE_SENSOR_UNKNOWN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_DISTANCE_SENSOR) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_DISTANCE_SENSOR { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_DISTANCE_SENSOR[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_DISTANCE_SENSOR) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_DISTANCE_SENSOR - for _, label := range labels { - found := false - for value, l := range labels_MAV_DISTANCE_SENSOR { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_DISTANCE_SENSOR[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_DISTANCE_SENSOR) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_DISTANCE_SENSOR[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_do_reposition_flags.go b/pkg/dialects/common/enum_mav_do_reposition_flags.go index 90ec45f33..f1f9e0f55 100644 --- a/pkg/dialects/common/enum_mav_do_reposition_flags.go +++ b/pkg/dialects/common/enum_mav_do_reposition_flags.go @@ -19,12 +19,17 @@ var labels_MAV_DO_REPOSITION_FLAGS = map[MAV_DO_REPOSITION_FLAGS]string{ MAV_DO_REPOSITION_FLAGS_CHANGE_MODE: "MAV_DO_REPOSITION_FLAGS_CHANGE_MODE", } +var values_MAV_DO_REPOSITION_FLAGS = map[string]MAV_DO_REPOSITION_FLAGS{ + "MAV_DO_REPOSITION_FLAGS_CHANGE_MODE": MAV_DO_REPOSITION_FLAGS_CHANGE_MODE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_DO_REPOSITION_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_DO_REPOSITION_FLAGS { + for i := 0; i < 1; i++ { + mask := MAV_DO_REPOSITION_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_DO_REPOSITION_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -35,19 +40,12 @@ func (e *MAV_DO_REPOSITION_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_DO_REPOSITION_FLAGS for _, label := range labels { - found := false - for value, l := range labels_MAV_DO_REPOSITION_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_DO_REPOSITION_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_estimator_type.go b/pkg/dialects/common/enum_mav_estimator_type.go index fe38f872f..0556dac05 100644 --- a/pkg/dialects/common/enum_mav_estimator_type.go +++ b/pkg/dialects/common/enum_mav_estimator_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of estimator types @@ -43,40 +43,42 @@ var labels_MAV_ESTIMATOR_TYPE = map[MAV_ESTIMATOR_TYPE]string{ MAV_ESTIMATOR_TYPE_AUTOPILOT: "MAV_ESTIMATOR_TYPE_AUTOPILOT", } +var values_MAV_ESTIMATOR_TYPE = map[string]MAV_ESTIMATOR_TYPE{ + "MAV_ESTIMATOR_TYPE_UNKNOWN": MAV_ESTIMATOR_TYPE_UNKNOWN, + "MAV_ESTIMATOR_TYPE_NAIVE": MAV_ESTIMATOR_TYPE_NAIVE, + "MAV_ESTIMATOR_TYPE_VISION": MAV_ESTIMATOR_TYPE_VISION, + "MAV_ESTIMATOR_TYPE_VIO": MAV_ESTIMATOR_TYPE_VIO, + "MAV_ESTIMATOR_TYPE_GPS": MAV_ESTIMATOR_TYPE_GPS, + "MAV_ESTIMATOR_TYPE_GPS_INS": MAV_ESTIMATOR_TYPE_GPS_INS, + "MAV_ESTIMATOR_TYPE_MOCAP": MAV_ESTIMATOR_TYPE_MOCAP, + "MAV_ESTIMATOR_TYPE_LIDAR": MAV_ESTIMATOR_TYPE_LIDAR, + "MAV_ESTIMATOR_TYPE_AUTOPILOT": MAV_ESTIMATOR_TYPE_AUTOPILOT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ESTIMATOR_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ESTIMATOR_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ESTIMATOR_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ESTIMATOR_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ESTIMATOR_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ESTIMATOR_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ESTIMATOR_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ESTIMATOR_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ESTIMATOR_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_event_current_sequence_flags.go b/pkg/dialects/common/enum_mav_event_current_sequence_flags.go index 213126832..193491e38 100644 --- a/pkg/dialects/common/enum_mav_event_current_sequence_flags.go +++ b/pkg/dialects/common/enum_mav_event_current_sequence_flags.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Flags for CURRENT_EVENT_SEQUENCE. @@ -19,40 +19,34 @@ var labels_MAV_EVENT_CURRENT_SEQUENCE_FLAGS = map[MAV_EVENT_CURRENT_SEQUENCE_FLA MAV_EVENT_CURRENT_SEQUENCE_FLAGS_RESET: "MAV_EVENT_CURRENT_SEQUENCE_FLAGS_RESET", } +var values_MAV_EVENT_CURRENT_SEQUENCE_FLAGS = map[string]MAV_EVENT_CURRENT_SEQUENCE_FLAGS{ + "MAV_EVENT_CURRENT_SEQUENCE_FLAGS_RESET": MAV_EVENT_CURRENT_SEQUENCE_FLAGS_RESET, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_EVENT_CURRENT_SEQUENCE_FLAGS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_EVENT_CURRENT_SEQUENCE_FLAGS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_EVENT_CURRENT_SEQUENCE_FLAGS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_EVENT_CURRENT_SEQUENCE_FLAGS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_EVENT_CURRENT_SEQUENCE_FLAGS - for _, label := range labels { - found := false - for value, l := range labels_MAV_EVENT_CURRENT_SEQUENCE_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_EVENT_CURRENT_SEQUENCE_FLAGS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_EVENT_CURRENT_SEQUENCE_FLAGS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_EVENT_CURRENT_SEQUENCE_FLAGS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_event_error_reason.go b/pkg/dialects/common/enum_mav_event_error_reason.go index e3afb4814..976eaf39a 100644 --- a/pkg/dialects/common/enum_mav_event_error_reason.go +++ b/pkg/dialects/common/enum_mav_event_error_reason.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Reason for an event error response. @@ -19,40 +19,34 @@ var labels_MAV_EVENT_ERROR_REASON = map[MAV_EVENT_ERROR_REASON]string{ MAV_EVENT_ERROR_REASON_UNAVAILABLE: "MAV_EVENT_ERROR_REASON_UNAVAILABLE", } +var values_MAV_EVENT_ERROR_REASON = map[string]MAV_EVENT_ERROR_REASON{ + "MAV_EVENT_ERROR_REASON_UNAVAILABLE": MAV_EVENT_ERROR_REASON_UNAVAILABLE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_EVENT_ERROR_REASON) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_EVENT_ERROR_REASON { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_EVENT_ERROR_REASON[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_EVENT_ERROR_REASON) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_EVENT_ERROR_REASON - for _, label := range labels { - found := false - for value, l := range labels_MAV_EVENT_ERROR_REASON { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_EVENT_ERROR_REASON[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_EVENT_ERROR_REASON) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_EVENT_ERROR_REASON[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_frame.go b/pkg/dialects/common/enum_mav_frame.go index a96c1ba4a..b72bdfde8 100644 --- a/pkg/dialects/common/enum_mav_frame.go +++ b/pkg/dialects/common/enum_mav_frame.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Coordinate frames used by MAVLink. Not all frames are supported by all commands, messages, or vehicles. @@ -95,40 +95,55 @@ var labels_MAV_FRAME = map[MAV_FRAME]string{ MAV_FRAME_LOCAL_FLU: "MAV_FRAME_LOCAL_FLU", } +var values_MAV_FRAME = map[string]MAV_FRAME{ + "MAV_FRAME_GLOBAL": MAV_FRAME_GLOBAL, + "MAV_FRAME_LOCAL_NED": MAV_FRAME_LOCAL_NED, + "MAV_FRAME_MISSION": MAV_FRAME_MISSION, + "MAV_FRAME_GLOBAL_RELATIVE_ALT": MAV_FRAME_GLOBAL_RELATIVE_ALT, + "MAV_FRAME_LOCAL_ENU": MAV_FRAME_LOCAL_ENU, + "MAV_FRAME_GLOBAL_INT": MAV_FRAME_GLOBAL_INT, + "MAV_FRAME_GLOBAL_RELATIVE_ALT_INT": MAV_FRAME_GLOBAL_RELATIVE_ALT_INT, + "MAV_FRAME_LOCAL_OFFSET_NED": MAV_FRAME_LOCAL_OFFSET_NED, + "MAV_FRAME_BODY_NED": MAV_FRAME_BODY_NED, + "MAV_FRAME_BODY_OFFSET_NED": MAV_FRAME_BODY_OFFSET_NED, + "MAV_FRAME_GLOBAL_TERRAIN_ALT": MAV_FRAME_GLOBAL_TERRAIN_ALT, + "MAV_FRAME_GLOBAL_TERRAIN_ALT_INT": MAV_FRAME_GLOBAL_TERRAIN_ALT_INT, + "MAV_FRAME_BODY_FRD": MAV_FRAME_BODY_FRD, + "MAV_FRAME_RESERVED_13": MAV_FRAME_RESERVED_13, + "MAV_FRAME_RESERVED_14": MAV_FRAME_RESERVED_14, + "MAV_FRAME_RESERVED_15": MAV_FRAME_RESERVED_15, + "MAV_FRAME_RESERVED_16": MAV_FRAME_RESERVED_16, + "MAV_FRAME_RESERVED_17": MAV_FRAME_RESERVED_17, + "MAV_FRAME_RESERVED_18": MAV_FRAME_RESERVED_18, + "MAV_FRAME_RESERVED_19": MAV_FRAME_RESERVED_19, + "MAV_FRAME_LOCAL_FRD": MAV_FRAME_LOCAL_FRD, + "MAV_FRAME_LOCAL_FLU": MAV_FRAME_LOCAL_FLU, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_FRAME) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_FRAME { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_FRAME[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_FRAME) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_FRAME - for _, label := range labels { - found := false - for value, l := range labels_MAV_FRAME { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_FRAME[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_FRAME) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_FRAME[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_ftp_err.go b/pkg/dialects/common/enum_mav_ftp_err.go index 895a6dce1..8caae86b8 100644 --- a/pkg/dialects/common/enum_mav_ftp_err.go +++ b/pkg/dialects/common/enum_mav_ftp_err.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // MAV FTP error codes (https://mavlink.io/en/services/ftp.html) @@ -50,40 +50,44 @@ var labels_MAV_FTP_ERR = map[MAV_FTP_ERR]string{ MAV_FTP_ERR_FILENOTFOUND: "MAV_FTP_ERR_FILENOTFOUND", } +var values_MAV_FTP_ERR = map[string]MAV_FTP_ERR{ + "MAV_FTP_ERR_NONE": MAV_FTP_ERR_NONE, + "MAV_FTP_ERR_FAIL": MAV_FTP_ERR_FAIL, + "MAV_FTP_ERR_FAILERRNO": MAV_FTP_ERR_FAILERRNO, + "MAV_FTP_ERR_INVALIDDATASIZE": MAV_FTP_ERR_INVALIDDATASIZE, + "MAV_FTP_ERR_INVALIDSESSION": MAV_FTP_ERR_INVALIDSESSION, + "MAV_FTP_ERR_NOSESSIONSAVAILABLE": MAV_FTP_ERR_NOSESSIONSAVAILABLE, + "MAV_FTP_ERR_EOF": MAV_FTP_ERR_EOF, + "MAV_FTP_ERR_UNKNOWNCOMMAND": MAV_FTP_ERR_UNKNOWNCOMMAND, + "MAV_FTP_ERR_FILEEXISTS": MAV_FTP_ERR_FILEEXISTS, + "MAV_FTP_ERR_FILEPROTECTED": MAV_FTP_ERR_FILEPROTECTED, + "MAV_FTP_ERR_FILENOTFOUND": MAV_FTP_ERR_FILENOTFOUND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_FTP_ERR) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_FTP_ERR { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_FTP_ERR[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_FTP_ERR) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_FTP_ERR - for _, label := range labels { - found := false - for value, l := range labels_MAV_FTP_ERR { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_FTP_ERR[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_FTP_ERR) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_FTP_ERR[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_ftp_opcode.go b/pkg/dialects/common/enum_mav_ftp_opcode.go index 51ad33ad7..1d7385364 100644 --- a/pkg/dialects/common/enum_mav_ftp_opcode.go +++ b/pkg/dialects/common/enum_mav_ftp_opcode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // MAV FTP opcodes: https://mavlink.io/en/services/ftp.html @@ -70,40 +70,51 @@ var labels_MAV_FTP_OPCODE = map[MAV_FTP_OPCODE]string{ MAV_FTP_OPCODE_NAK: "MAV_FTP_OPCODE_NAK", } +var values_MAV_FTP_OPCODE = map[string]MAV_FTP_OPCODE{ + "MAV_FTP_OPCODE_NONE": MAV_FTP_OPCODE_NONE, + "MAV_FTP_OPCODE_TERMINATESESSION": MAV_FTP_OPCODE_TERMINATESESSION, + "MAV_FTP_OPCODE_RESETSESSION": MAV_FTP_OPCODE_RESETSESSION, + "MAV_FTP_OPCODE_LISTDIRECTORY": MAV_FTP_OPCODE_LISTDIRECTORY, + "MAV_FTP_OPCODE_OPENFILERO": MAV_FTP_OPCODE_OPENFILERO, + "MAV_FTP_OPCODE_READFILE": MAV_FTP_OPCODE_READFILE, + "MAV_FTP_OPCODE_CREATEFILE": MAV_FTP_OPCODE_CREATEFILE, + "MAV_FTP_OPCODE_WRITEFILE": MAV_FTP_OPCODE_WRITEFILE, + "MAV_FTP_OPCODE_REMOVEFILE": MAV_FTP_OPCODE_REMOVEFILE, + "MAV_FTP_OPCODE_CREATEDIRECTORY": MAV_FTP_OPCODE_CREATEDIRECTORY, + "MAV_FTP_OPCODE_REMOVEDIRECTORY": MAV_FTP_OPCODE_REMOVEDIRECTORY, + "MAV_FTP_OPCODE_OPENFILEWO": MAV_FTP_OPCODE_OPENFILEWO, + "MAV_FTP_OPCODE_TRUNCATEFILE": MAV_FTP_OPCODE_TRUNCATEFILE, + "MAV_FTP_OPCODE_RENAME": MAV_FTP_OPCODE_RENAME, + "MAV_FTP_OPCODE_CALCFILECRC": MAV_FTP_OPCODE_CALCFILECRC, + "MAV_FTP_OPCODE_BURSTREADFILE": MAV_FTP_OPCODE_BURSTREADFILE, + "MAV_FTP_OPCODE_ACK": MAV_FTP_OPCODE_ACK, + "MAV_FTP_OPCODE_NAK": MAV_FTP_OPCODE_NAK, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_FTP_OPCODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_FTP_OPCODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_FTP_OPCODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_FTP_OPCODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_FTP_OPCODE - for _, label := range labels { - found := false - for value, l := range labels_MAV_FTP_OPCODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_FTP_OPCODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_FTP_OPCODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_FTP_OPCODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_generator_status_flag.go b/pkg/dialects/common/enum_mav_generator_status_flag.go index d92b9e0d5..cda87deef 100644 --- a/pkg/dialects/common/enum_mav_generator_status_flag.go +++ b/pkg/dialects/common/enum_mav_generator_status_flag.go @@ -85,12 +85,39 @@ var labels_MAV_GENERATOR_STATUS_FLAG = map[MAV_GENERATOR_STATUS_FLAG]string{ MAV_GENERATOR_STATUS_FLAG_IDLE: "MAV_GENERATOR_STATUS_FLAG_IDLE", } +var values_MAV_GENERATOR_STATUS_FLAG = map[string]MAV_GENERATOR_STATUS_FLAG{ + "MAV_GENERATOR_STATUS_FLAG_OFF": MAV_GENERATOR_STATUS_FLAG_OFF, + "MAV_GENERATOR_STATUS_FLAG_READY": MAV_GENERATOR_STATUS_FLAG_READY, + "MAV_GENERATOR_STATUS_FLAG_GENERATING": MAV_GENERATOR_STATUS_FLAG_GENERATING, + "MAV_GENERATOR_STATUS_FLAG_CHARGING": MAV_GENERATOR_STATUS_FLAG_CHARGING, + "MAV_GENERATOR_STATUS_FLAG_REDUCED_POWER": MAV_GENERATOR_STATUS_FLAG_REDUCED_POWER, + "MAV_GENERATOR_STATUS_FLAG_MAXPOWER": MAV_GENERATOR_STATUS_FLAG_MAXPOWER, + "MAV_GENERATOR_STATUS_FLAG_OVERTEMP_WARNING": MAV_GENERATOR_STATUS_FLAG_OVERTEMP_WARNING, + "MAV_GENERATOR_STATUS_FLAG_OVERTEMP_FAULT": MAV_GENERATOR_STATUS_FLAG_OVERTEMP_FAULT, + "MAV_GENERATOR_STATUS_FLAG_ELECTRONICS_OVERTEMP_WARNING": MAV_GENERATOR_STATUS_FLAG_ELECTRONICS_OVERTEMP_WARNING, + "MAV_GENERATOR_STATUS_FLAG_ELECTRONICS_OVERTEMP_FAULT": MAV_GENERATOR_STATUS_FLAG_ELECTRONICS_OVERTEMP_FAULT, + "MAV_GENERATOR_STATUS_FLAG_ELECTRONICS_FAULT": MAV_GENERATOR_STATUS_FLAG_ELECTRONICS_FAULT, + "MAV_GENERATOR_STATUS_FLAG_POWERSOURCE_FAULT": MAV_GENERATOR_STATUS_FLAG_POWERSOURCE_FAULT, + "MAV_GENERATOR_STATUS_FLAG_COMMUNICATION_WARNING": MAV_GENERATOR_STATUS_FLAG_COMMUNICATION_WARNING, + "MAV_GENERATOR_STATUS_FLAG_COOLING_WARNING": MAV_GENERATOR_STATUS_FLAG_COOLING_WARNING, + "MAV_GENERATOR_STATUS_FLAG_POWER_RAIL_FAULT": MAV_GENERATOR_STATUS_FLAG_POWER_RAIL_FAULT, + "MAV_GENERATOR_STATUS_FLAG_OVERCURRENT_FAULT": MAV_GENERATOR_STATUS_FLAG_OVERCURRENT_FAULT, + "MAV_GENERATOR_STATUS_FLAG_BATTERY_OVERCHARGE_CURRENT_FAULT": MAV_GENERATOR_STATUS_FLAG_BATTERY_OVERCHARGE_CURRENT_FAULT, + "MAV_GENERATOR_STATUS_FLAG_OVERVOLTAGE_FAULT": MAV_GENERATOR_STATUS_FLAG_OVERVOLTAGE_FAULT, + "MAV_GENERATOR_STATUS_FLAG_BATTERY_UNDERVOLT_FAULT": MAV_GENERATOR_STATUS_FLAG_BATTERY_UNDERVOLT_FAULT, + "MAV_GENERATOR_STATUS_FLAG_START_INHIBITED": MAV_GENERATOR_STATUS_FLAG_START_INHIBITED, + "MAV_GENERATOR_STATUS_FLAG_MAINTENANCE_REQUIRED": MAV_GENERATOR_STATUS_FLAG_MAINTENANCE_REQUIRED, + "MAV_GENERATOR_STATUS_FLAG_WARMING_UP": MAV_GENERATOR_STATUS_FLAG_WARMING_UP, + "MAV_GENERATOR_STATUS_FLAG_IDLE": MAV_GENERATOR_STATUS_FLAG_IDLE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_GENERATOR_STATUS_FLAG) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_GENERATOR_STATUS_FLAG { + for i := 0; i < 23; i++ { + mask := MAV_GENERATOR_STATUS_FLAG(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_GENERATOR_STATUS_FLAG[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -101,19 +128,12 @@ func (e *MAV_GENERATOR_STATUS_FLAG) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_GENERATOR_STATUS_FLAG for _, label := range labels { - found := false - for value, l := range labels_MAV_GENERATOR_STATUS_FLAG { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_GENERATOR_STATUS_FLAG[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_goto.go b/pkg/dialects/common/enum_mav_goto.go index f1b6681ed..3e9bf9a39 100644 --- a/pkg/dialects/common/enum_mav_goto.go +++ b/pkg/dialects/common/enum_mav_goto.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actions that may be specified in MAV_CMD_OVERRIDE_GOTO to override mission execution. @@ -28,40 +28,37 @@ var labels_MAV_GOTO = map[MAV_GOTO]string{ MAV_GOTO_HOLD_AT_SPECIFIED_POSITION: "MAV_GOTO_HOLD_AT_SPECIFIED_POSITION", } +var values_MAV_GOTO = map[string]MAV_GOTO{ + "MAV_GOTO_DO_HOLD": MAV_GOTO_DO_HOLD, + "MAV_GOTO_DO_CONTINUE": MAV_GOTO_DO_CONTINUE, + "MAV_GOTO_HOLD_AT_CURRENT_POSITION": MAV_GOTO_HOLD_AT_CURRENT_POSITION, + "MAV_GOTO_HOLD_AT_SPECIFIED_POSITION": MAV_GOTO_HOLD_AT_SPECIFIED_POSITION, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_GOTO) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_GOTO { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_GOTO[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_GOTO) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_GOTO - for _, label := range labels { - found := false - for value, l := range labels_MAV_GOTO { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_GOTO[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_GOTO) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_GOTO[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_landed_state.go b/pkg/dialects/common/enum_mav_landed_state.go index 0a73fb9b8..9da44c7ae 100644 --- a/pkg/dialects/common/enum_mav_landed_state.go +++ b/pkg/dialects/common/enum_mav_landed_state.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of landed detector states @@ -31,40 +31,38 @@ var labels_MAV_LANDED_STATE = map[MAV_LANDED_STATE]string{ MAV_LANDED_STATE_LANDING: "MAV_LANDED_STATE_LANDING", } +var values_MAV_LANDED_STATE = map[string]MAV_LANDED_STATE{ + "MAV_LANDED_STATE_UNDEFINED": MAV_LANDED_STATE_UNDEFINED, + "MAV_LANDED_STATE_ON_GROUND": MAV_LANDED_STATE_ON_GROUND, + "MAV_LANDED_STATE_IN_AIR": MAV_LANDED_STATE_IN_AIR, + "MAV_LANDED_STATE_TAKEOFF": MAV_LANDED_STATE_TAKEOFF, + "MAV_LANDED_STATE_LANDING": MAV_LANDED_STATE_LANDING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_LANDED_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_LANDED_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_LANDED_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_LANDED_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_LANDED_STATE - for _, label := range labels { - found := false - for value, l := range labels_MAV_LANDED_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_LANDED_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_LANDED_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_LANDED_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_mission_result.go b/pkg/dialects/common/enum_mav_mission_result.go index ca6b83e8c..c91ef1eb9 100644 --- a/pkg/dialects/common/enum_mav_mission_result.go +++ b/pkg/dialects/common/enum_mav_mission_result.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Result of mission operation (in a MISSION_ACK message). @@ -64,40 +64,49 @@ var labels_MAV_MISSION_RESULT = map[MAV_MISSION_RESULT]string{ MAV_MISSION_OPERATION_CANCELLED: "MAV_MISSION_OPERATION_CANCELLED", } +var values_MAV_MISSION_RESULT = map[string]MAV_MISSION_RESULT{ + "MAV_MISSION_ACCEPTED": MAV_MISSION_ACCEPTED, + "MAV_MISSION_ERROR": MAV_MISSION_ERROR, + "MAV_MISSION_UNSUPPORTED_FRAME": MAV_MISSION_UNSUPPORTED_FRAME, + "MAV_MISSION_UNSUPPORTED": MAV_MISSION_UNSUPPORTED, + "MAV_MISSION_NO_SPACE": MAV_MISSION_NO_SPACE, + "MAV_MISSION_INVALID": MAV_MISSION_INVALID, + "MAV_MISSION_INVALID_PARAM1": MAV_MISSION_INVALID_PARAM1, + "MAV_MISSION_INVALID_PARAM2": MAV_MISSION_INVALID_PARAM2, + "MAV_MISSION_INVALID_PARAM3": MAV_MISSION_INVALID_PARAM3, + "MAV_MISSION_INVALID_PARAM4": MAV_MISSION_INVALID_PARAM4, + "MAV_MISSION_INVALID_PARAM5_X": MAV_MISSION_INVALID_PARAM5_X, + "MAV_MISSION_INVALID_PARAM6_Y": MAV_MISSION_INVALID_PARAM6_Y, + "MAV_MISSION_INVALID_PARAM7": MAV_MISSION_INVALID_PARAM7, + "MAV_MISSION_INVALID_SEQUENCE": MAV_MISSION_INVALID_SEQUENCE, + "MAV_MISSION_DENIED": MAV_MISSION_DENIED, + "MAV_MISSION_OPERATION_CANCELLED": MAV_MISSION_OPERATION_CANCELLED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_MISSION_RESULT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_MISSION_RESULT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_MISSION_RESULT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_MISSION_RESULT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_MISSION_RESULT - for _, label := range labels { - found := false - for value, l := range labels_MAV_MISSION_RESULT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_MISSION_RESULT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_MISSION_RESULT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_MISSION_RESULT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_mission_type.go b/pkg/dialects/common/enum_mav_mission_type.go index 0f213a6bf..f64b5bad2 100644 --- a/pkg/dialects/common/enum_mav_mission_type.go +++ b/pkg/dialects/common/enum_mav_mission_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Type of mission items being requested/sent in mission protocol. @@ -28,40 +28,37 @@ var labels_MAV_MISSION_TYPE = map[MAV_MISSION_TYPE]string{ MAV_MISSION_TYPE_ALL: "MAV_MISSION_TYPE_ALL", } +var values_MAV_MISSION_TYPE = map[string]MAV_MISSION_TYPE{ + "MAV_MISSION_TYPE_MISSION": MAV_MISSION_TYPE_MISSION, + "MAV_MISSION_TYPE_FENCE": MAV_MISSION_TYPE_FENCE, + "MAV_MISSION_TYPE_RALLY": MAV_MISSION_TYPE_RALLY, + "MAV_MISSION_TYPE_ALL": MAV_MISSION_TYPE_ALL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_MISSION_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_MISSION_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_MISSION_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_MISSION_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_MISSION_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_MISSION_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_MISSION_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_MISSION_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_MISSION_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_mode.go b/pkg/dialects/common/enum_mav_mode.go index bfd7bd6cd..892350a8d 100644 --- a/pkg/dialects/common/enum_mav_mode.go +++ b/pkg/dialects/common/enum_mav_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // These defines are predefined OR-combined mode flags. There is no need to use values from this enum, but it @@ -50,40 +50,44 @@ var labels_MAV_MODE = map[MAV_MODE]string{ MAV_MODE_TEST_ARMED: "MAV_MODE_TEST_ARMED", } +var values_MAV_MODE = map[string]MAV_MODE{ + "MAV_MODE_PREFLIGHT": MAV_MODE_PREFLIGHT, + "MAV_MODE_STABILIZE_DISARMED": MAV_MODE_STABILIZE_DISARMED, + "MAV_MODE_STABILIZE_ARMED": MAV_MODE_STABILIZE_ARMED, + "MAV_MODE_MANUAL_DISARMED": MAV_MODE_MANUAL_DISARMED, + "MAV_MODE_MANUAL_ARMED": MAV_MODE_MANUAL_ARMED, + "MAV_MODE_GUIDED_DISARMED": MAV_MODE_GUIDED_DISARMED, + "MAV_MODE_GUIDED_ARMED": MAV_MODE_GUIDED_ARMED, + "MAV_MODE_AUTO_DISARMED": MAV_MODE_AUTO_DISARMED, + "MAV_MODE_AUTO_ARMED": MAV_MODE_AUTO_ARMED, + "MAV_MODE_TEST_DISARMED": MAV_MODE_TEST_DISARMED, + "MAV_MODE_TEST_ARMED": MAV_MODE_TEST_ARMED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_MODE - for _, label := range labels { - found := false - for value, l := range labels_MAV_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_mount_mode.go b/pkg/dialects/common/enum_mav_mount_mode.go index 0d1ea09d9..47a04f761 100644 --- a/pkg/dialects/common/enum_mav_mount_mode.go +++ b/pkg/dialects/common/enum_mav_mount_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of possible mount operation modes. This message is used by obsolete/deprecated gimbal messages. @@ -37,40 +37,40 @@ var labels_MAV_MOUNT_MODE = map[MAV_MOUNT_MODE]string{ MAV_MOUNT_MODE_HOME_LOCATION: "MAV_MOUNT_MODE_HOME_LOCATION", } +var values_MAV_MOUNT_MODE = map[string]MAV_MOUNT_MODE{ + "MAV_MOUNT_MODE_RETRACT": MAV_MOUNT_MODE_RETRACT, + "MAV_MOUNT_MODE_NEUTRAL": MAV_MOUNT_MODE_NEUTRAL, + "MAV_MOUNT_MODE_MAVLINK_TARGETING": MAV_MOUNT_MODE_MAVLINK_TARGETING, + "MAV_MOUNT_MODE_RC_TARGETING": MAV_MOUNT_MODE_RC_TARGETING, + "MAV_MOUNT_MODE_GPS_POINT": MAV_MOUNT_MODE_GPS_POINT, + "MAV_MOUNT_MODE_SYSID_TARGET": MAV_MOUNT_MODE_SYSID_TARGET, + "MAV_MOUNT_MODE_HOME_LOCATION": MAV_MOUNT_MODE_HOME_LOCATION, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_MOUNT_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_MOUNT_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_MOUNT_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_MOUNT_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_MOUNT_MODE - for _, label := range labels { - found := false - for value, l := range labels_MAV_MOUNT_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_MOUNT_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_MOUNT_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_MOUNT_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_arm_status.go b/pkg/dialects/common/enum_mav_odid_arm_status.go index 5a074eadf..accb713c4 100644 --- a/pkg/dialects/common/enum_mav_odid_arm_status.go +++ b/pkg/dialects/common/enum_mav_odid_arm_status.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_ARM_STATUS uint32 @@ -21,40 +21,35 @@ var labels_MAV_ODID_ARM_STATUS = map[MAV_ODID_ARM_STATUS]string{ MAV_ODID_ARM_STATUS_PRE_ARM_FAIL_GENERIC: "MAV_ODID_ARM_STATUS_PRE_ARM_FAIL_GENERIC", } +var values_MAV_ODID_ARM_STATUS = map[string]MAV_ODID_ARM_STATUS{ + "MAV_ODID_ARM_STATUS_GOOD_TO_ARM": MAV_ODID_ARM_STATUS_GOOD_TO_ARM, + "MAV_ODID_ARM_STATUS_PRE_ARM_FAIL_GENERIC": MAV_ODID_ARM_STATUS_PRE_ARM_FAIL_GENERIC, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_ARM_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_ARM_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_ARM_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_ARM_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_ARM_STATUS - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_ARM_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_ARM_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_ARM_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_ARM_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_auth_type.go b/pkg/dialects/common/enum_mav_odid_auth_type.go index 8ba19a8a3..524528ed1 100644 --- a/pkg/dialects/common/enum_mav_odid_auth_type.go +++ b/pkg/dialects/common/enum_mav_odid_auth_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_AUTH_TYPE uint32 @@ -33,40 +33,39 @@ var labels_MAV_ODID_AUTH_TYPE = map[MAV_ODID_AUTH_TYPE]string{ MAV_ODID_AUTH_TYPE_SPECIFIC_AUTHENTICATION: "MAV_ODID_AUTH_TYPE_SPECIFIC_AUTHENTICATION", } +var values_MAV_ODID_AUTH_TYPE = map[string]MAV_ODID_AUTH_TYPE{ + "MAV_ODID_AUTH_TYPE_NONE": MAV_ODID_AUTH_TYPE_NONE, + "MAV_ODID_AUTH_TYPE_UAS_ID_SIGNATURE": MAV_ODID_AUTH_TYPE_UAS_ID_SIGNATURE, + "MAV_ODID_AUTH_TYPE_OPERATOR_ID_SIGNATURE": MAV_ODID_AUTH_TYPE_OPERATOR_ID_SIGNATURE, + "MAV_ODID_AUTH_TYPE_MESSAGE_SET_SIGNATURE": MAV_ODID_AUTH_TYPE_MESSAGE_SET_SIGNATURE, + "MAV_ODID_AUTH_TYPE_NETWORK_REMOTE_ID": MAV_ODID_AUTH_TYPE_NETWORK_REMOTE_ID, + "MAV_ODID_AUTH_TYPE_SPECIFIC_AUTHENTICATION": MAV_ODID_AUTH_TYPE_SPECIFIC_AUTHENTICATION, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_AUTH_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_AUTH_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_AUTH_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_AUTH_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_AUTH_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_AUTH_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_AUTH_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_AUTH_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_AUTH_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_category_eu.go b/pkg/dialects/common/enum_mav_odid_category_eu.go index 89b91ecad..3ff74697a 100644 --- a/pkg/dialects/common/enum_mav_odid_category_eu.go +++ b/pkg/dialects/common/enum_mav_odid_category_eu.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_CATEGORY_EU uint32 @@ -27,40 +27,37 @@ var labels_MAV_ODID_CATEGORY_EU = map[MAV_ODID_CATEGORY_EU]string{ MAV_ODID_CATEGORY_EU_CERTIFIED: "MAV_ODID_CATEGORY_EU_CERTIFIED", } +var values_MAV_ODID_CATEGORY_EU = map[string]MAV_ODID_CATEGORY_EU{ + "MAV_ODID_CATEGORY_EU_UNDECLARED": MAV_ODID_CATEGORY_EU_UNDECLARED, + "MAV_ODID_CATEGORY_EU_OPEN": MAV_ODID_CATEGORY_EU_OPEN, + "MAV_ODID_CATEGORY_EU_SPECIFIC": MAV_ODID_CATEGORY_EU_SPECIFIC, + "MAV_ODID_CATEGORY_EU_CERTIFIED": MAV_ODID_CATEGORY_EU_CERTIFIED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_CATEGORY_EU) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_CATEGORY_EU { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_CATEGORY_EU[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_CATEGORY_EU) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_CATEGORY_EU - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_CATEGORY_EU { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_CATEGORY_EU[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_CATEGORY_EU) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_CATEGORY_EU[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_class_eu.go b/pkg/dialects/common/enum_mav_odid_class_eu.go index a4409a2e5..fc4f81964 100644 --- a/pkg/dialects/common/enum_mav_odid_class_eu.go +++ b/pkg/dialects/common/enum_mav_odid_class_eu.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_CLASS_EU uint32 @@ -39,40 +39,41 @@ var labels_MAV_ODID_CLASS_EU = map[MAV_ODID_CLASS_EU]string{ MAV_ODID_CLASS_EU_CLASS_6: "MAV_ODID_CLASS_EU_CLASS_6", } +var values_MAV_ODID_CLASS_EU = map[string]MAV_ODID_CLASS_EU{ + "MAV_ODID_CLASS_EU_UNDECLARED": MAV_ODID_CLASS_EU_UNDECLARED, + "MAV_ODID_CLASS_EU_CLASS_0": MAV_ODID_CLASS_EU_CLASS_0, + "MAV_ODID_CLASS_EU_CLASS_1": MAV_ODID_CLASS_EU_CLASS_1, + "MAV_ODID_CLASS_EU_CLASS_2": MAV_ODID_CLASS_EU_CLASS_2, + "MAV_ODID_CLASS_EU_CLASS_3": MAV_ODID_CLASS_EU_CLASS_3, + "MAV_ODID_CLASS_EU_CLASS_4": MAV_ODID_CLASS_EU_CLASS_4, + "MAV_ODID_CLASS_EU_CLASS_5": MAV_ODID_CLASS_EU_CLASS_5, + "MAV_ODID_CLASS_EU_CLASS_6": MAV_ODID_CLASS_EU_CLASS_6, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_CLASS_EU) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_CLASS_EU { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_CLASS_EU[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_CLASS_EU) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_CLASS_EU - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_CLASS_EU { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_CLASS_EU[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_CLASS_EU) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_CLASS_EU[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_classification_type.go b/pkg/dialects/common/enum_mav_odid_classification_type.go index aa22478dd..de9d265af 100644 --- a/pkg/dialects/common/enum_mav_odid_classification_type.go +++ b/pkg/dialects/common/enum_mav_odid_classification_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_CLASSIFICATION_TYPE uint32 @@ -21,40 +21,35 @@ var labels_MAV_ODID_CLASSIFICATION_TYPE = map[MAV_ODID_CLASSIFICATION_TYPE]strin MAV_ODID_CLASSIFICATION_TYPE_EU: "MAV_ODID_CLASSIFICATION_TYPE_EU", } +var values_MAV_ODID_CLASSIFICATION_TYPE = map[string]MAV_ODID_CLASSIFICATION_TYPE{ + "MAV_ODID_CLASSIFICATION_TYPE_UNDECLARED": MAV_ODID_CLASSIFICATION_TYPE_UNDECLARED, + "MAV_ODID_CLASSIFICATION_TYPE_EU": MAV_ODID_CLASSIFICATION_TYPE_EU, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_CLASSIFICATION_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_CLASSIFICATION_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_CLASSIFICATION_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_CLASSIFICATION_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_CLASSIFICATION_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_CLASSIFICATION_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_CLASSIFICATION_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_CLASSIFICATION_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_CLASSIFICATION_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_desc_type.go b/pkg/dialects/common/enum_mav_odid_desc_type.go index ea1b3e7bf..2ce614895 100644 --- a/pkg/dialects/common/enum_mav_odid_desc_type.go +++ b/pkg/dialects/common/enum_mav_odid_desc_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_DESC_TYPE uint32 @@ -24,40 +24,36 @@ var labels_MAV_ODID_DESC_TYPE = map[MAV_ODID_DESC_TYPE]string{ MAV_ODID_DESC_TYPE_EXTENDED_STATUS: "MAV_ODID_DESC_TYPE_EXTENDED_STATUS", } +var values_MAV_ODID_DESC_TYPE = map[string]MAV_ODID_DESC_TYPE{ + "MAV_ODID_DESC_TYPE_TEXT": MAV_ODID_DESC_TYPE_TEXT, + "MAV_ODID_DESC_TYPE_EMERGENCY": MAV_ODID_DESC_TYPE_EMERGENCY, + "MAV_ODID_DESC_TYPE_EXTENDED_STATUS": MAV_ODID_DESC_TYPE_EXTENDED_STATUS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_DESC_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_DESC_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_DESC_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_DESC_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_DESC_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_DESC_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_DESC_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_DESC_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_DESC_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_height_ref.go b/pkg/dialects/common/enum_mav_odid_height_ref.go index f59e1493d..16bb30a1e 100644 --- a/pkg/dialects/common/enum_mav_odid_height_ref.go +++ b/pkg/dialects/common/enum_mav_odid_height_ref.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_HEIGHT_REF uint32 @@ -21,40 +21,35 @@ var labels_MAV_ODID_HEIGHT_REF = map[MAV_ODID_HEIGHT_REF]string{ MAV_ODID_HEIGHT_REF_OVER_GROUND: "MAV_ODID_HEIGHT_REF_OVER_GROUND", } +var values_MAV_ODID_HEIGHT_REF = map[string]MAV_ODID_HEIGHT_REF{ + "MAV_ODID_HEIGHT_REF_OVER_TAKEOFF": MAV_ODID_HEIGHT_REF_OVER_TAKEOFF, + "MAV_ODID_HEIGHT_REF_OVER_GROUND": MAV_ODID_HEIGHT_REF_OVER_GROUND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_HEIGHT_REF) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_HEIGHT_REF { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_HEIGHT_REF[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_HEIGHT_REF) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_HEIGHT_REF - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_HEIGHT_REF { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_HEIGHT_REF[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_HEIGHT_REF) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_HEIGHT_REF[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_hor_acc.go b/pkg/dialects/common/enum_mav_odid_hor_acc.go index 0e38a3c23..0e8d79fbf 100644 --- a/pkg/dialects/common/enum_mav_odid_hor_acc.go +++ b/pkg/dialects/common/enum_mav_odid_hor_acc.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_HOR_ACC uint32 @@ -54,40 +54,46 @@ var labels_MAV_ODID_HOR_ACC = map[MAV_ODID_HOR_ACC]string{ MAV_ODID_HOR_ACC_1_METER: "MAV_ODID_HOR_ACC_1_METER", } +var values_MAV_ODID_HOR_ACC = map[string]MAV_ODID_HOR_ACC{ + "MAV_ODID_HOR_ACC_UNKNOWN": MAV_ODID_HOR_ACC_UNKNOWN, + "MAV_ODID_HOR_ACC_10NM": MAV_ODID_HOR_ACC_10NM, + "MAV_ODID_HOR_ACC_4NM": MAV_ODID_HOR_ACC_4NM, + "MAV_ODID_HOR_ACC_2NM": MAV_ODID_HOR_ACC_2NM, + "MAV_ODID_HOR_ACC_1NM": MAV_ODID_HOR_ACC_1NM, + "MAV_ODID_HOR_ACC_0_5NM": MAV_ODID_HOR_ACC_0_5NM, + "MAV_ODID_HOR_ACC_0_3NM": MAV_ODID_HOR_ACC_0_3NM, + "MAV_ODID_HOR_ACC_0_1NM": MAV_ODID_HOR_ACC_0_1NM, + "MAV_ODID_HOR_ACC_0_05NM": MAV_ODID_HOR_ACC_0_05NM, + "MAV_ODID_HOR_ACC_30_METER": MAV_ODID_HOR_ACC_30_METER, + "MAV_ODID_HOR_ACC_10_METER": MAV_ODID_HOR_ACC_10_METER, + "MAV_ODID_HOR_ACC_3_METER": MAV_ODID_HOR_ACC_3_METER, + "MAV_ODID_HOR_ACC_1_METER": MAV_ODID_HOR_ACC_1_METER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_HOR_ACC) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_HOR_ACC { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_HOR_ACC[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_HOR_ACC) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_HOR_ACC - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_HOR_ACC { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_HOR_ACC[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_HOR_ACC) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_HOR_ACC[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_id_type.go b/pkg/dialects/common/enum_mav_odid_id_type.go index 2491876e6..9e3a59ffc 100644 --- a/pkg/dialects/common/enum_mav_odid_id_type.go +++ b/pkg/dialects/common/enum_mav_odid_id_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_ID_TYPE uint32 @@ -30,40 +30,38 @@ var labels_MAV_ODID_ID_TYPE = map[MAV_ODID_ID_TYPE]string{ MAV_ODID_ID_TYPE_SPECIFIC_SESSION_ID: "MAV_ODID_ID_TYPE_SPECIFIC_SESSION_ID", } +var values_MAV_ODID_ID_TYPE = map[string]MAV_ODID_ID_TYPE{ + "MAV_ODID_ID_TYPE_NONE": MAV_ODID_ID_TYPE_NONE, + "MAV_ODID_ID_TYPE_SERIAL_NUMBER": MAV_ODID_ID_TYPE_SERIAL_NUMBER, + "MAV_ODID_ID_TYPE_CAA_REGISTRATION_ID": MAV_ODID_ID_TYPE_CAA_REGISTRATION_ID, + "MAV_ODID_ID_TYPE_UTM_ASSIGNED_UUID": MAV_ODID_ID_TYPE_UTM_ASSIGNED_UUID, + "MAV_ODID_ID_TYPE_SPECIFIC_SESSION_ID": MAV_ODID_ID_TYPE_SPECIFIC_SESSION_ID, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_ID_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_ID_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_ID_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_ID_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_ID_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_ID_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_ID_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_ID_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_ID_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_operator_id_type.go b/pkg/dialects/common/enum_mav_odid_operator_id_type.go index c392bf0d2..5c12b5ae1 100644 --- a/pkg/dialects/common/enum_mav_odid_operator_id_type.go +++ b/pkg/dialects/common/enum_mav_odid_operator_id_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_OPERATOR_ID_TYPE uint32 @@ -18,40 +18,34 @@ var labels_MAV_ODID_OPERATOR_ID_TYPE = map[MAV_ODID_OPERATOR_ID_TYPE]string{ MAV_ODID_OPERATOR_ID_TYPE_CAA: "MAV_ODID_OPERATOR_ID_TYPE_CAA", } +var values_MAV_ODID_OPERATOR_ID_TYPE = map[string]MAV_ODID_OPERATOR_ID_TYPE{ + "MAV_ODID_OPERATOR_ID_TYPE_CAA": MAV_ODID_OPERATOR_ID_TYPE_CAA, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_OPERATOR_ID_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_OPERATOR_ID_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_OPERATOR_ID_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_OPERATOR_ID_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_OPERATOR_ID_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_OPERATOR_ID_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_OPERATOR_ID_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_OPERATOR_ID_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_OPERATOR_ID_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_operator_location_type.go b/pkg/dialects/common/enum_mav_odid_operator_location_type.go index 7728a72ee..30864661f 100644 --- a/pkg/dialects/common/enum_mav_odid_operator_location_type.go +++ b/pkg/dialects/common/enum_mav_odid_operator_location_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_OPERATOR_LOCATION_TYPE uint32 @@ -24,40 +24,36 @@ var labels_MAV_ODID_OPERATOR_LOCATION_TYPE = map[MAV_ODID_OPERATOR_LOCATION_TYPE MAV_ODID_OPERATOR_LOCATION_TYPE_FIXED: "MAV_ODID_OPERATOR_LOCATION_TYPE_FIXED", } +var values_MAV_ODID_OPERATOR_LOCATION_TYPE = map[string]MAV_ODID_OPERATOR_LOCATION_TYPE{ + "MAV_ODID_OPERATOR_LOCATION_TYPE_TAKEOFF": MAV_ODID_OPERATOR_LOCATION_TYPE_TAKEOFF, + "MAV_ODID_OPERATOR_LOCATION_TYPE_LIVE_GNSS": MAV_ODID_OPERATOR_LOCATION_TYPE_LIVE_GNSS, + "MAV_ODID_OPERATOR_LOCATION_TYPE_FIXED": MAV_ODID_OPERATOR_LOCATION_TYPE_FIXED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_OPERATOR_LOCATION_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_OPERATOR_LOCATION_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_OPERATOR_LOCATION_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_OPERATOR_LOCATION_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_OPERATOR_LOCATION_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_OPERATOR_LOCATION_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_OPERATOR_LOCATION_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_OPERATOR_LOCATION_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_OPERATOR_LOCATION_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_speed_acc.go b/pkg/dialects/common/enum_mav_odid_speed_acc.go index 3608d6489..4f19c0129 100644 --- a/pkg/dialects/common/enum_mav_odid_speed_acc.go +++ b/pkg/dialects/common/enum_mav_odid_speed_acc.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_SPEED_ACC uint32 @@ -30,40 +30,38 @@ var labels_MAV_ODID_SPEED_ACC = map[MAV_ODID_SPEED_ACC]string{ MAV_ODID_SPEED_ACC_0_3_METERS_PER_SECOND: "MAV_ODID_SPEED_ACC_0_3_METERS_PER_SECOND", } +var values_MAV_ODID_SPEED_ACC = map[string]MAV_ODID_SPEED_ACC{ + "MAV_ODID_SPEED_ACC_UNKNOWN": MAV_ODID_SPEED_ACC_UNKNOWN, + "MAV_ODID_SPEED_ACC_10_METERS_PER_SECOND": MAV_ODID_SPEED_ACC_10_METERS_PER_SECOND, + "MAV_ODID_SPEED_ACC_3_METERS_PER_SECOND": MAV_ODID_SPEED_ACC_3_METERS_PER_SECOND, + "MAV_ODID_SPEED_ACC_1_METERS_PER_SECOND": MAV_ODID_SPEED_ACC_1_METERS_PER_SECOND, + "MAV_ODID_SPEED_ACC_0_3_METERS_PER_SECOND": MAV_ODID_SPEED_ACC_0_3_METERS_PER_SECOND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_SPEED_ACC) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_SPEED_ACC { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_SPEED_ACC[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_SPEED_ACC) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_SPEED_ACC - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_SPEED_ACC { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_SPEED_ACC[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_SPEED_ACC) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_SPEED_ACC[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_status.go b/pkg/dialects/common/enum_mav_odid_status.go index 62c69ab95..7617b0bb4 100644 --- a/pkg/dialects/common/enum_mav_odid_status.go +++ b/pkg/dialects/common/enum_mav_odid_status.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_STATUS uint32 @@ -30,40 +30,38 @@ var labels_MAV_ODID_STATUS = map[MAV_ODID_STATUS]string{ MAV_ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE: "MAV_ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE", } +var values_MAV_ODID_STATUS = map[string]MAV_ODID_STATUS{ + "MAV_ODID_STATUS_UNDECLARED": MAV_ODID_STATUS_UNDECLARED, + "MAV_ODID_STATUS_GROUND": MAV_ODID_STATUS_GROUND, + "MAV_ODID_STATUS_AIRBORNE": MAV_ODID_STATUS_AIRBORNE, + "MAV_ODID_STATUS_EMERGENCY": MAV_ODID_STATUS_EMERGENCY, + "MAV_ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE": MAV_ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_STATUS - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_time_acc.go b/pkg/dialects/common/enum_mav_odid_time_acc.go index 4e23a828d..462e74dde 100644 --- a/pkg/dialects/common/enum_mav_odid_time_acc.go +++ b/pkg/dialects/common/enum_mav_odid_time_acc.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_TIME_ACC uint32 @@ -63,40 +63,49 @@ var labels_MAV_ODID_TIME_ACC = map[MAV_ODID_TIME_ACC]string{ MAV_ODID_TIME_ACC_1_5_SECOND: "MAV_ODID_TIME_ACC_1_5_SECOND", } +var values_MAV_ODID_TIME_ACC = map[string]MAV_ODID_TIME_ACC{ + "MAV_ODID_TIME_ACC_UNKNOWN": MAV_ODID_TIME_ACC_UNKNOWN, + "MAV_ODID_TIME_ACC_0_1_SECOND": MAV_ODID_TIME_ACC_0_1_SECOND, + "MAV_ODID_TIME_ACC_0_2_SECOND": MAV_ODID_TIME_ACC_0_2_SECOND, + "MAV_ODID_TIME_ACC_0_3_SECOND": MAV_ODID_TIME_ACC_0_3_SECOND, + "MAV_ODID_TIME_ACC_0_4_SECOND": MAV_ODID_TIME_ACC_0_4_SECOND, + "MAV_ODID_TIME_ACC_0_5_SECOND": MAV_ODID_TIME_ACC_0_5_SECOND, + "MAV_ODID_TIME_ACC_0_6_SECOND": MAV_ODID_TIME_ACC_0_6_SECOND, + "MAV_ODID_TIME_ACC_0_7_SECOND": MAV_ODID_TIME_ACC_0_7_SECOND, + "MAV_ODID_TIME_ACC_0_8_SECOND": MAV_ODID_TIME_ACC_0_8_SECOND, + "MAV_ODID_TIME_ACC_0_9_SECOND": MAV_ODID_TIME_ACC_0_9_SECOND, + "MAV_ODID_TIME_ACC_1_0_SECOND": MAV_ODID_TIME_ACC_1_0_SECOND, + "MAV_ODID_TIME_ACC_1_1_SECOND": MAV_ODID_TIME_ACC_1_1_SECOND, + "MAV_ODID_TIME_ACC_1_2_SECOND": MAV_ODID_TIME_ACC_1_2_SECOND, + "MAV_ODID_TIME_ACC_1_3_SECOND": MAV_ODID_TIME_ACC_1_3_SECOND, + "MAV_ODID_TIME_ACC_1_4_SECOND": MAV_ODID_TIME_ACC_1_4_SECOND, + "MAV_ODID_TIME_ACC_1_5_SECOND": MAV_ODID_TIME_ACC_1_5_SECOND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_TIME_ACC) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_TIME_ACC { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_TIME_ACC[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_TIME_ACC) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_TIME_ACC - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_TIME_ACC { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_TIME_ACC[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_TIME_ACC) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_TIME_ACC[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_ua_type.go b/pkg/dialects/common/enum_mav_odid_ua_type.go index 362ca9657..a8b6389c9 100644 --- a/pkg/dialects/common/enum_mav_odid_ua_type.go +++ b/pkg/dialects/common/enum_mav_odid_ua_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_UA_TYPE uint32 @@ -63,40 +63,49 @@ var labels_MAV_ODID_UA_TYPE = map[MAV_ODID_UA_TYPE]string{ MAV_ODID_UA_TYPE_OTHER: "MAV_ODID_UA_TYPE_OTHER", } +var values_MAV_ODID_UA_TYPE = map[string]MAV_ODID_UA_TYPE{ + "MAV_ODID_UA_TYPE_NONE": MAV_ODID_UA_TYPE_NONE, + "MAV_ODID_UA_TYPE_AEROPLANE": MAV_ODID_UA_TYPE_AEROPLANE, + "MAV_ODID_UA_TYPE_HELICOPTER_OR_MULTIROTOR": MAV_ODID_UA_TYPE_HELICOPTER_OR_MULTIROTOR, + "MAV_ODID_UA_TYPE_GYROPLANE": MAV_ODID_UA_TYPE_GYROPLANE, + "MAV_ODID_UA_TYPE_HYBRID_LIFT": MAV_ODID_UA_TYPE_HYBRID_LIFT, + "MAV_ODID_UA_TYPE_ORNITHOPTER": MAV_ODID_UA_TYPE_ORNITHOPTER, + "MAV_ODID_UA_TYPE_GLIDER": MAV_ODID_UA_TYPE_GLIDER, + "MAV_ODID_UA_TYPE_KITE": MAV_ODID_UA_TYPE_KITE, + "MAV_ODID_UA_TYPE_FREE_BALLOON": MAV_ODID_UA_TYPE_FREE_BALLOON, + "MAV_ODID_UA_TYPE_CAPTIVE_BALLOON": MAV_ODID_UA_TYPE_CAPTIVE_BALLOON, + "MAV_ODID_UA_TYPE_AIRSHIP": MAV_ODID_UA_TYPE_AIRSHIP, + "MAV_ODID_UA_TYPE_FREE_FALL_PARACHUTE": MAV_ODID_UA_TYPE_FREE_FALL_PARACHUTE, + "MAV_ODID_UA_TYPE_ROCKET": MAV_ODID_UA_TYPE_ROCKET, + "MAV_ODID_UA_TYPE_TETHERED_POWERED_AIRCRAFT": MAV_ODID_UA_TYPE_TETHERED_POWERED_AIRCRAFT, + "MAV_ODID_UA_TYPE_GROUND_OBSTACLE": MAV_ODID_UA_TYPE_GROUND_OBSTACLE, + "MAV_ODID_UA_TYPE_OTHER": MAV_ODID_UA_TYPE_OTHER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_UA_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_UA_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_UA_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_UA_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_UA_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_UA_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_UA_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_UA_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_UA_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_odid_ver_acc.go b/pkg/dialects/common/enum_mav_odid_ver_acc.go index e82599c3f..865abca1c 100644 --- a/pkg/dialects/common/enum_mav_odid_ver_acc.go +++ b/pkg/dialects/common/enum_mav_odid_ver_acc.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_ODID_VER_ACC uint32 @@ -36,40 +36,40 @@ var labels_MAV_ODID_VER_ACC = map[MAV_ODID_VER_ACC]string{ MAV_ODID_VER_ACC_1_METER: "MAV_ODID_VER_ACC_1_METER", } +var values_MAV_ODID_VER_ACC = map[string]MAV_ODID_VER_ACC{ + "MAV_ODID_VER_ACC_UNKNOWN": MAV_ODID_VER_ACC_UNKNOWN, + "MAV_ODID_VER_ACC_150_METER": MAV_ODID_VER_ACC_150_METER, + "MAV_ODID_VER_ACC_45_METER": MAV_ODID_VER_ACC_45_METER, + "MAV_ODID_VER_ACC_25_METER": MAV_ODID_VER_ACC_25_METER, + "MAV_ODID_VER_ACC_10_METER": MAV_ODID_VER_ACC_10_METER, + "MAV_ODID_VER_ACC_3_METER": MAV_ODID_VER_ACC_3_METER, + "MAV_ODID_VER_ACC_1_METER": MAV_ODID_VER_ACC_1_METER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ODID_VER_ACC) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ODID_VER_ACC { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ODID_VER_ACC[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ODID_VER_ACC) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ODID_VER_ACC - for _, label := range labels { - found := false - for value, l := range labels_MAV_ODID_VER_ACC { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ODID_VER_ACC[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ODID_VER_ACC) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ODID_VER_ACC[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_param_ext_type.go b/pkg/dialects/common/enum_mav_param_ext_type.go index 92566286c..ff68b1949 100644 --- a/pkg/dialects/common/enum_mav_param_ext_type.go +++ b/pkg/dialects/common/enum_mav_param_ext_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Specifies the datatype of a MAVLink extended parameter. @@ -49,40 +49,44 @@ var labels_MAV_PARAM_EXT_TYPE = map[MAV_PARAM_EXT_TYPE]string{ MAV_PARAM_EXT_TYPE_CUSTOM: "MAV_PARAM_EXT_TYPE_CUSTOM", } +var values_MAV_PARAM_EXT_TYPE = map[string]MAV_PARAM_EXT_TYPE{ + "MAV_PARAM_EXT_TYPE_UINT8": MAV_PARAM_EXT_TYPE_UINT8, + "MAV_PARAM_EXT_TYPE_INT8": MAV_PARAM_EXT_TYPE_INT8, + "MAV_PARAM_EXT_TYPE_UINT16": MAV_PARAM_EXT_TYPE_UINT16, + "MAV_PARAM_EXT_TYPE_INT16": MAV_PARAM_EXT_TYPE_INT16, + "MAV_PARAM_EXT_TYPE_UINT32": MAV_PARAM_EXT_TYPE_UINT32, + "MAV_PARAM_EXT_TYPE_INT32": MAV_PARAM_EXT_TYPE_INT32, + "MAV_PARAM_EXT_TYPE_UINT64": MAV_PARAM_EXT_TYPE_UINT64, + "MAV_PARAM_EXT_TYPE_INT64": MAV_PARAM_EXT_TYPE_INT64, + "MAV_PARAM_EXT_TYPE_REAL32": MAV_PARAM_EXT_TYPE_REAL32, + "MAV_PARAM_EXT_TYPE_REAL64": MAV_PARAM_EXT_TYPE_REAL64, + "MAV_PARAM_EXT_TYPE_CUSTOM": MAV_PARAM_EXT_TYPE_CUSTOM, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_PARAM_EXT_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_PARAM_EXT_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_PARAM_EXT_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_PARAM_EXT_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_PARAM_EXT_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_PARAM_EXT_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_PARAM_EXT_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_PARAM_EXT_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_PARAM_EXT_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_param_type.go b/pkg/dialects/common/enum_mav_param_type.go index 0d0031a66..bf43b6d8a 100644 --- a/pkg/dialects/common/enum_mav_param_type.go +++ b/pkg/dialects/common/enum_mav_param_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Specifies the datatype of a MAVLink parameter. @@ -46,40 +46,43 @@ var labels_MAV_PARAM_TYPE = map[MAV_PARAM_TYPE]string{ MAV_PARAM_TYPE_REAL64: "MAV_PARAM_TYPE_REAL64", } +var values_MAV_PARAM_TYPE = map[string]MAV_PARAM_TYPE{ + "MAV_PARAM_TYPE_UINT8": MAV_PARAM_TYPE_UINT8, + "MAV_PARAM_TYPE_INT8": MAV_PARAM_TYPE_INT8, + "MAV_PARAM_TYPE_UINT16": MAV_PARAM_TYPE_UINT16, + "MAV_PARAM_TYPE_INT16": MAV_PARAM_TYPE_INT16, + "MAV_PARAM_TYPE_UINT32": MAV_PARAM_TYPE_UINT32, + "MAV_PARAM_TYPE_INT32": MAV_PARAM_TYPE_INT32, + "MAV_PARAM_TYPE_UINT64": MAV_PARAM_TYPE_UINT64, + "MAV_PARAM_TYPE_INT64": MAV_PARAM_TYPE_INT64, + "MAV_PARAM_TYPE_REAL32": MAV_PARAM_TYPE_REAL32, + "MAV_PARAM_TYPE_REAL64": MAV_PARAM_TYPE_REAL64, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_PARAM_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_PARAM_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_PARAM_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_PARAM_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_PARAM_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_PARAM_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_PARAM_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_PARAM_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_PARAM_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_power_status.go b/pkg/dialects/common/enum_mav_power_status.go index 3a78462ed..5883129ab 100644 --- a/pkg/dialects/common/enum_mav_power_status.go +++ b/pkg/dialects/common/enum_mav_power_status.go @@ -34,12 +34,22 @@ var labels_MAV_POWER_STATUS = map[MAV_POWER_STATUS]string{ MAV_POWER_STATUS_CHANGED: "MAV_POWER_STATUS_CHANGED", } +var values_MAV_POWER_STATUS = map[string]MAV_POWER_STATUS{ + "MAV_POWER_STATUS_BRICK_VALID": MAV_POWER_STATUS_BRICK_VALID, + "MAV_POWER_STATUS_SERVO_VALID": MAV_POWER_STATUS_SERVO_VALID, + "MAV_POWER_STATUS_USB_CONNECTED": MAV_POWER_STATUS_USB_CONNECTED, + "MAV_POWER_STATUS_PERIPH_OVERCURRENT": MAV_POWER_STATUS_PERIPH_OVERCURRENT, + "MAV_POWER_STATUS_PERIPH_HIPOWER_OVERCURRENT": MAV_POWER_STATUS_PERIPH_HIPOWER_OVERCURRENT, + "MAV_POWER_STATUS_CHANGED": MAV_POWER_STATUS_CHANGED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_POWER_STATUS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_POWER_STATUS { + for i := 0; i < 6; i++ { + mask := MAV_POWER_STATUS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_POWER_STATUS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -50,19 +60,12 @@ func (e *MAV_POWER_STATUS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_POWER_STATUS for _, label := range labels { - found := false - for value, l := range labels_MAV_POWER_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_POWER_STATUS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_protocol_capability.go b/pkg/dialects/common/enum_mav_protocol_capability.go index 460008db3..3924c9891 100644 --- a/pkg/dialects/common/enum_mav_protocol_capability.go +++ b/pkg/dialects/common/enum_mav_protocol_capability.go @@ -74,12 +74,34 @@ var labels_MAV_PROTOCOL_CAPABILITY = map[MAV_PROTOCOL_CAPABILITY]string{ MAV_PROTOCOL_CAPABILITY_PARAM_ENCODE_C_CAST: "MAV_PROTOCOL_CAPABILITY_PARAM_ENCODE_C_CAST", } +var values_MAV_PROTOCOL_CAPABILITY = map[string]MAV_PROTOCOL_CAPABILITY{ + "MAV_PROTOCOL_CAPABILITY_MISSION_FLOAT": MAV_PROTOCOL_CAPABILITY_MISSION_FLOAT, + "MAV_PROTOCOL_CAPABILITY_PARAM_FLOAT": MAV_PROTOCOL_CAPABILITY_PARAM_FLOAT, + "MAV_PROTOCOL_CAPABILITY_MISSION_INT": MAV_PROTOCOL_CAPABILITY_MISSION_INT, + "MAV_PROTOCOL_CAPABILITY_COMMAND_INT": MAV_PROTOCOL_CAPABILITY_COMMAND_INT, + "MAV_PROTOCOL_CAPABILITY_PARAM_ENCODE_BYTEWISE": MAV_PROTOCOL_CAPABILITY_PARAM_ENCODE_BYTEWISE, + "MAV_PROTOCOL_CAPABILITY_FTP": MAV_PROTOCOL_CAPABILITY_FTP, + "MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET": MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET, + "MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED": MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED, + "MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_GLOBAL_INT": MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_GLOBAL_INT, + "MAV_PROTOCOL_CAPABILITY_TERRAIN": MAV_PROTOCOL_CAPABILITY_TERRAIN, + "MAV_PROTOCOL_CAPABILITY_RESERVED3": MAV_PROTOCOL_CAPABILITY_RESERVED3, + "MAV_PROTOCOL_CAPABILITY_FLIGHT_TERMINATION": MAV_PROTOCOL_CAPABILITY_FLIGHT_TERMINATION, + "MAV_PROTOCOL_CAPABILITY_COMPASS_CALIBRATION": MAV_PROTOCOL_CAPABILITY_COMPASS_CALIBRATION, + "MAV_PROTOCOL_CAPABILITY_MAVLINK2": MAV_PROTOCOL_CAPABILITY_MAVLINK2, + "MAV_PROTOCOL_CAPABILITY_MISSION_FENCE": MAV_PROTOCOL_CAPABILITY_MISSION_FENCE, + "MAV_PROTOCOL_CAPABILITY_MISSION_RALLY": MAV_PROTOCOL_CAPABILITY_MISSION_RALLY, + "MAV_PROTOCOL_CAPABILITY_RESERVED2": MAV_PROTOCOL_CAPABILITY_RESERVED2, + "MAV_PROTOCOL_CAPABILITY_PARAM_ENCODE_C_CAST": MAV_PROTOCOL_CAPABILITY_PARAM_ENCODE_C_CAST, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_PROTOCOL_CAPABILITY) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_PROTOCOL_CAPABILITY { + for i := 0; i < 18; i++ { + mask := MAV_PROTOCOL_CAPABILITY(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_PROTOCOL_CAPABILITY[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -90,19 +112,12 @@ func (e *MAV_PROTOCOL_CAPABILITY) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_PROTOCOL_CAPABILITY for _, label := range labels { - found := false - for value, l := range labels_MAV_PROTOCOL_CAPABILITY { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_PROTOCOL_CAPABILITY[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_result.go b/pkg/dialects/common/enum_mav_result.go index e75b22844..2ded1d0e4 100644 --- a/pkg/dialects/common/enum_mav_result.go +++ b/pkg/dialects/common/enum_mav_result.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Result from a MAVLink command (MAV_CMD) @@ -46,40 +46,43 @@ var labels_MAV_RESULT = map[MAV_RESULT]string{ MAV_RESULT_COMMAND_UNSUPPORTED_MAV_FRAME: "MAV_RESULT_COMMAND_UNSUPPORTED_MAV_FRAME", } +var values_MAV_RESULT = map[string]MAV_RESULT{ + "MAV_RESULT_ACCEPTED": MAV_RESULT_ACCEPTED, + "MAV_RESULT_TEMPORARILY_REJECTED": MAV_RESULT_TEMPORARILY_REJECTED, + "MAV_RESULT_DENIED": MAV_RESULT_DENIED, + "MAV_RESULT_UNSUPPORTED": MAV_RESULT_UNSUPPORTED, + "MAV_RESULT_FAILED": MAV_RESULT_FAILED, + "MAV_RESULT_IN_PROGRESS": MAV_RESULT_IN_PROGRESS, + "MAV_RESULT_CANCELLED": MAV_RESULT_CANCELLED, + "MAV_RESULT_COMMAND_LONG_ONLY": MAV_RESULT_COMMAND_LONG_ONLY, + "MAV_RESULT_COMMAND_INT_ONLY": MAV_RESULT_COMMAND_INT_ONLY, + "MAV_RESULT_COMMAND_UNSUPPORTED_MAV_FRAME": MAV_RESULT_COMMAND_UNSUPPORTED_MAV_FRAME, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_RESULT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_RESULT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_RESULT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_RESULT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_RESULT - for _, label := range labels { - found := false - for value, l := range labels_MAV_RESULT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_RESULT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_RESULT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_RESULT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_roi.go b/pkg/dialects/common/enum_mav_roi.go index f4ad1b20c..8ff9b0ac8 100644 --- a/pkg/dialects/common/enum_mav_roi.go +++ b/pkg/dialects/common/enum_mav_roi.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // The ROI (region of interest) for the vehicle. This can be @@ -33,40 +33,38 @@ var labels_MAV_ROI = map[MAV_ROI]string{ MAV_ROI_TARGET: "MAV_ROI_TARGET", } +var values_MAV_ROI = map[string]MAV_ROI{ + "MAV_ROI_NONE": MAV_ROI_NONE, + "MAV_ROI_WPNEXT": MAV_ROI_WPNEXT, + "MAV_ROI_WPINDEX": MAV_ROI_WPINDEX, + "MAV_ROI_LOCATION": MAV_ROI_LOCATION, + "MAV_ROI_TARGET": MAV_ROI_TARGET, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_ROI) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_ROI { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_ROI[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_ROI) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_ROI - for _, label := range labels { - found := false - for value, l := range labels_MAV_ROI { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_ROI[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_ROI) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_ROI[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_sensor_orientation.go b/pkg/dialects/common/enum_mav_sensor_orientation.go index 649b3f84c..8868ceeea 100644 --- a/pkg/dialects/common/enum_mav_sensor_orientation.go +++ b/pkg/dialects/common/enum_mav_sensor_orientation.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of sensor orientation, according to its rotations @@ -142,40 +142,75 @@ var labels_MAV_SENSOR_ORIENTATION = map[MAV_SENSOR_ORIENTATION]string{ MAV_SENSOR_ROTATION_CUSTOM: "MAV_SENSOR_ROTATION_CUSTOM", } +var values_MAV_SENSOR_ORIENTATION = map[string]MAV_SENSOR_ORIENTATION{ + "MAV_SENSOR_ROTATION_NONE": MAV_SENSOR_ROTATION_NONE, + "MAV_SENSOR_ROTATION_YAW_45": MAV_SENSOR_ROTATION_YAW_45, + "MAV_SENSOR_ROTATION_YAW_90": MAV_SENSOR_ROTATION_YAW_90, + "MAV_SENSOR_ROTATION_YAW_135": MAV_SENSOR_ROTATION_YAW_135, + "MAV_SENSOR_ROTATION_YAW_180": MAV_SENSOR_ROTATION_YAW_180, + "MAV_SENSOR_ROTATION_YAW_225": MAV_SENSOR_ROTATION_YAW_225, + "MAV_SENSOR_ROTATION_YAW_270": MAV_SENSOR_ROTATION_YAW_270, + "MAV_SENSOR_ROTATION_YAW_315": MAV_SENSOR_ROTATION_YAW_315, + "MAV_SENSOR_ROTATION_ROLL_180": MAV_SENSOR_ROTATION_ROLL_180, + "MAV_SENSOR_ROTATION_ROLL_180_YAW_45": MAV_SENSOR_ROTATION_ROLL_180_YAW_45, + "MAV_SENSOR_ROTATION_ROLL_180_YAW_90": MAV_SENSOR_ROTATION_ROLL_180_YAW_90, + "MAV_SENSOR_ROTATION_ROLL_180_YAW_135": MAV_SENSOR_ROTATION_ROLL_180_YAW_135, + "MAV_SENSOR_ROTATION_PITCH_180": MAV_SENSOR_ROTATION_PITCH_180, + "MAV_SENSOR_ROTATION_ROLL_180_YAW_225": MAV_SENSOR_ROTATION_ROLL_180_YAW_225, + "MAV_SENSOR_ROTATION_ROLL_180_YAW_270": MAV_SENSOR_ROTATION_ROLL_180_YAW_270, + "MAV_SENSOR_ROTATION_ROLL_180_YAW_315": MAV_SENSOR_ROTATION_ROLL_180_YAW_315, + "MAV_SENSOR_ROTATION_ROLL_90": MAV_SENSOR_ROTATION_ROLL_90, + "MAV_SENSOR_ROTATION_ROLL_90_YAW_45": MAV_SENSOR_ROTATION_ROLL_90_YAW_45, + "MAV_SENSOR_ROTATION_ROLL_90_YAW_90": MAV_SENSOR_ROTATION_ROLL_90_YAW_90, + "MAV_SENSOR_ROTATION_ROLL_90_YAW_135": MAV_SENSOR_ROTATION_ROLL_90_YAW_135, + "MAV_SENSOR_ROTATION_ROLL_270": MAV_SENSOR_ROTATION_ROLL_270, + "MAV_SENSOR_ROTATION_ROLL_270_YAW_45": MAV_SENSOR_ROTATION_ROLL_270_YAW_45, + "MAV_SENSOR_ROTATION_ROLL_270_YAW_90": MAV_SENSOR_ROTATION_ROLL_270_YAW_90, + "MAV_SENSOR_ROTATION_ROLL_270_YAW_135": MAV_SENSOR_ROTATION_ROLL_270_YAW_135, + "MAV_SENSOR_ROTATION_PITCH_90": MAV_SENSOR_ROTATION_PITCH_90, + "MAV_SENSOR_ROTATION_PITCH_270": MAV_SENSOR_ROTATION_PITCH_270, + "MAV_SENSOR_ROTATION_PITCH_180_YAW_90": MAV_SENSOR_ROTATION_PITCH_180_YAW_90, + "MAV_SENSOR_ROTATION_PITCH_180_YAW_270": MAV_SENSOR_ROTATION_PITCH_180_YAW_270, + "MAV_SENSOR_ROTATION_ROLL_90_PITCH_90": MAV_SENSOR_ROTATION_ROLL_90_PITCH_90, + "MAV_SENSOR_ROTATION_ROLL_180_PITCH_90": MAV_SENSOR_ROTATION_ROLL_180_PITCH_90, + "MAV_SENSOR_ROTATION_ROLL_270_PITCH_90": MAV_SENSOR_ROTATION_ROLL_270_PITCH_90, + "MAV_SENSOR_ROTATION_ROLL_90_PITCH_180": MAV_SENSOR_ROTATION_ROLL_90_PITCH_180, + "MAV_SENSOR_ROTATION_ROLL_270_PITCH_180": MAV_SENSOR_ROTATION_ROLL_270_PITCH_180, + "MAV_SENSOR_ROTATION_ROLL_90_PITCH_270": MAV_SENSOR_ROTATION_ROLL_90_PITCH_270, + "MAV_SENSOR_ROTATION_ROLL_180_PITCH_270": MAV_SENSOR_ROTATION_ROLL_180_PITCH_270, + "MAV_SENSOR_ROTATION_ROLL_270_PITCH_270": MAV_SENSOR_ROTATION_ROLL_270_PITCH_270, + "MAV_SENSOR_ROTATION_ROLL_90_PITCH_180_YAW_90": MAV_SENSOR_ROTATION_ROLL_90_PITCH_180_YAW_90, + "MAV_SENSOR_ROTATION_ROLL_90_YAW_270": MAV_SENSOR_ROTATION_ROLL_90_YAW_270, + "MAV_SENSOR_ROTATION_ROLL_90_PITCH_68_YAW_293": MAV_SENSOR_ROTATION_ROLL_90_PITCH_68_YAW_293, + "MAV_SENSOR_ROTATION_PITCH_315": MAV_SENSOR_ROTATION_PITCH_315, + "MAV_SENSOR_ROTATION_ROLL_90_PITCH_315": MAV_SENSOR_ROTATION_ROLL_90_PITCH_315, + "MAV_SENSOR_ROTATION_CUSTOM": MAV_SENSOR_ROTATION_CUSTOM, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_SENSOR_ORIENTATION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_SENSOR_ORIENTATION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_SENSOR_ORIENTATION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_SENSOR_ORIENTATION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_SENSOR_ORIENTATION - for _, label := range labels { - found := false - for value, l := range labels_MAV_SENSOR_ORIENTATION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_SENSOR_ORIENTATION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_SENSOR_ORIENTATION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_SENSOR_ORIENTATION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_severity.go b/pkg/dialects/common/enum_mav_severity.go index 904595445..48a133289 100644 --- a/pkg/dialects/common/enum_mav_severity.go +++ b/pkg/dialects/common/enum_mav_severity.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Indicates the severity level, generally used for status messages to indicate their relative urgency. Based on RFC-5424 using expanded definitions at: http://www.kiwisyslog.com/kb/info:-syslog-message-levels/. @@ -40,40 +40,41 @@ var labels_MAV_SEVERITY = map[MAV_SEVERITY]string{ MAV_SEVERITY_DEBUG: "MAV_SEVERITY_DEBUG", } +var values_MAV_SEVERITY = map[string]MAV_SEVERITY{ + "MAV_SEVERITY_EMERGENCY": MAV_SEVERITY_EMERGENCY, + "MAV_SEVERITY_ALERT": MAV_SEVERITY_ALERT, + "MAV_SEVERITY_CRITICAL": MAV_SEVERITY_CRITICAL, + "MAV_SEVERITY_ERROR": MAV_SEVERITY_ERROR, + "MAV_SEVERITY_WARNING": MAV_SEVERITY_WARNING, + "MAV_SEVERITY_NOTICE": MAV_SEVERITY_NOTICE, + "MAV_SEVERITY_INFO": MAV_SEVERITY_INFO, + "MAV_SEVERITY_DEBUG": MAV_SEVERITY_DEBUG, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_SEVERITY) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_SEVERITY { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_SEVERITY[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_SEVERITY) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_SEVERITY - for _, label := range labels { - found := false - for value, l := range labels_MAV_SEVERITY { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_SEVERITY[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_SEVERITY) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_SEVERITY[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_sys_status_sensor.go b/pkg/dialects/common/enum_mav_sys_status_sensor.go index febb11344..e1f22bc59 100644 --- a/pkg/dialects/common/enum_mav_sys_status_sensor.go +++ b/pkg/dialects/common/enum_mav_sys_status_sensor.go @@ -112,12 +112,48 @@ var labels_MAV_SYS_STATUS_SENSOR = map[MAV_SYS_STATUS_SENSOR]string{ MAV_SYS_STATUS_EXTENSION_USED: "MAV_SYS_STATUS_EXTENSION_USED", } +var values_MAV_SYS_STATUS_SENSOR = map[string]MAV_SYS_STATUS_SENSOR{ + "MAV_SYS_STATUS_SENSOR_3D_GYRO": MAV_SYS_STATUS_SENSOR_3D_GYRO, + "MAV_SYS_STATUS_SENSOR_3D_ACCEL": MAV_SYS_STATUS_SENSOR_3D_ACCEL, + "MAV_SYS_STATUS_SENSOR_3D_MAG": MAV_SYS_STATUS_SENSOR_3D_MAG, + "MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE": MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE, + "MAV_SYS_STATUS_SENSOR_DIFFERENTIAL_PRESSURE": MAV_SYS_STATUS_SENSOR_DIFFERENTIAL_PRESSURE, + "MAV_SYS_STATUS_SENSOR_GPS": MAV_SYS_STATUS_SENSOR_GPS, + "MAV_SYS_STATUS_SENSOR_OPTICAL_FLOW": MAV_SYS_STATUS_SENSOR_OPTICAL_FLOW, + "MAV_SYS_STATUS_SENSOR_VISION_POSITION": MAV_SYS_STATUS_SENSOR_VISION_POSITION, + "MAV_SYS_STATUS_SENSOR_LASER_POSITION": MAV_SYS_STATUS_SENSOR_LASER_POSITION, + "MAV_SYS_STATUS_SENSOR_EXTERNAL_GROUND_TRUTH": MAV_SYS_STATUS_SENSOR_EXTERNAL_GROUND_TRUTH, + "MAV_SYS_STATUS_SENSOR_ANGULAR_RATE_CONTROL": MAV_SYS_STATUS_SENSOR_ANGULAR_RATE_CONTROL, + "MAV_SYS_STATUS_SENSOR_ATTITUDE_STABILIZATION": MAV_SYS_STATUS_SENSOR_ATTITUDE_STABILIZATION, + "MAV_SYS_STATUS_SENSOR_YAW_POSITION": MAV_SYS_STATUS_SENSOR_YAW_POSITION, + "MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL": MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL, + "MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL": MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL, + "MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS": MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS, + "MAV_SYS_STATUS_SENSOR_RC_RECEIVER": MAV_SYS_STATUS_SENSOR_RC_RECEIVER, + "MAV_SYS_STATUS_SENSOR_3D_GYRO2": MAV_SYS_STATUS_SENSOR_3D_GYRO2, + "MAV_SYS_STATUS_SENSOR_3D_ACCEL2": MAV_SYS_STATUS_SENSOR_3D_ACCEL2, + "MAV_SYS_STATUS_SENSOR_3D_MAG2": MAV_SYS_STATUS_SENSOR_3D_MAG2, + "MAV_SYS_STATUS_GEOFENCE": MAV_SYS_STATUS_GEOFENCE, + "MAV_SYS_STATUS_AHRS": MAV_SYS_STATUS_AHRS, + "MAV_SYS_STATUS_TERRAIN": MAV_SYS_STATUS_TERRAIN, + "MAV_SYS_STATUS_REVERSE_MOTOR": MAV_SYS_STATUS_REVERSE_MOTOR, + "MAV_SYS_STATUS_LOGGING": MAV_SYS_STATUS_LOGGING, + "MAV_SYS_STATUS_SENSOR_BATTERY": MAV_SYS_STATUS_SENSOR_BATTERY, + "MAV_SYS_STATUS_SENSOR_PROXIMITY": MAV_SYS_STATUS_SENSOR_PROXIMITY, + "MAV_SYS_STATUS_SENSOR_SATCOM": MAV_SYS_STATUS_SENSOR_SATCOM, + "MAV_SYS_STATUS_PREARM_CHECK": MAV_SYS_STATUS_PREARM_CHECK, + "MAV_SYS_STATUS_OBSTACLE_AVOIDANCE": MAV_SYS_STATUS_OBSTACLE_AVOIDANCE, + "MAV_SYS_STATUS_SENSOR_PROPULSION": MAV_SYS_STATUS_SENSOR_PROPULSION, + "MAV_SYS_STATUS_EXTENSION_USED": MAV_SYS_STATUS_EXTENSION_USED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_SYS_STATUS_SENSOR) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_SYS_STATUS_SENSOR { + for i := 0; i < 32; i++ { + mask := MAV_SYS_STATUS_SENSOR(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_SYS_STATUS_SENSOR[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -128,19 +164,12 @@ func (e *MAV_SYS_STATUS_SENSOR) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_SYS_STATUS_SENSOR for _, label := range labels { - found := false - for value, l := range labels_MAV_SYS_STATUS_SENSOR { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_SYS_STATUS_SENSOR[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_sys_status_sensor_extended.go b/pkg/dialects/common/enum_mav_sys_status_sensor_extended.go index 0a23c2e1d..b49d1abaa 100644 --- a/pkg/dialects/common/enum_mav_sys_status_sensor_extended.go +++ b/pkg/dialects/common/enum_mav_sys_status_sensor_extended.go @@ -19,12 +19,17 @@ var labels_MAV_SYS_STATUS_SENSOR_EXTENDED = map[MAV_SYS_STATUS_SENSOR_EXTENDED]s MAV_SYS_STATUS_RECOVERY_SYSTEM: "MAV_SYS_STATUS_RECOVERY_SYSTEM", } +var values_MAV_SYS_STATUS_SENSOR_EXTENDED = map[string]MAV_SYS_STATUS_SENSOR_EXTENDED{ + "MAV_SYS_STATUS_RECOVERY_SYSTEM": MAV_SYS_STATUS_RECOVERY_SYSTEM, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_SYS_STATUS_SENSOR_EXTENDED) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_SYS_STATUS_SENSOR_EXTENDED { + for i := 0; i < 1; i++ { + mask := MAV_SYS_STATUS_SENSOR_EXTENDED(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_SYS_STATUS_SENSOR_EXTENDED[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -35,19 +40,12 @@ func (e *MAV_SYS_STATUS_SENSOR_EXTENDED) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_SYS_STATUS_SENSOR_EXTENDED for _, label := range labels { - found := false - for value, l := range labels_MAV_SYS_STATUS_SENSOR_EXTENDED { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_SYS_STATUS_SENSOR_EXTENDED[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mav_tunnel_payload_type.go b/pkg/dialects/common/enum_mav_tunnel_payload_type.go index 2195d4605..6a4810620 100644 --- a/pkg/dialects/common/enum_mav_tunnel_payload_type.go +++ b/pkg/dialects/common/enum_mav_tunnel_payload_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAV_TUNNEL_PAYLOAD_TYPE uint32 @@ -48,40 +48,44 @@ var labels_MAV_TUNNEL_PAYLOAD_TYPE = map[MAV_TUNNEL_PAYLOAD_TYPE]string{ MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED9: "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED9", } +var values_MAV_TUNNEL_PAYLOAD_TYPE = map[string]MAV_TUNNEL_PAYLOAD_TYPE{ + "MAV_TUNNEL_PAYLOAD_TYPE_UNKNOWN": MAV_TUNNEL_PAYLOAD_TYPE_UNKNOWN, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED0": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED0, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED1": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED1, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED2": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED2, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED3": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED3, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED4": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED4, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED5": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED5, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED6": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED6, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED7": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED7, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED8": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED8, + "MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED9": MAV_TUNNEL_PAYLOAD_TYPE_STORM32_RESERVED9, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_TUNNEL_PAYLOAD_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_TUNNEL_PAYLOAD_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_TUNNEL_PAYLOAD_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_TUNNEL_PAYLOAD_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_TUNNEL_PAYLOAD_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_TUNNEL_PAYLOAD_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_TUNNEL_PAYLOAD_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_TUNNEL_PAYLOAD_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_TUNNEL_PAYLOAD_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_vtol_state.go b/pkg/dialects/common/enum_mav_vtol_state.go index 13b4306ad..805d06d3e 100644 --- a/pkg/dialects/common/enum_mav_vtol_state.go +++ b/pkg/dialects/common/enum_mav_vtol_state.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Enumeration of VTOL states @@ -31,40 +31,38 @@ var labels_MAV_VTOL_STATE = map[MAV_VTOL_STATE]string{ MAV_VTOL_STATE_FW: "MAV_VTOL_STATE_FW", } +var values_MAV_VTOL_STATE = map[string]MAV_VTOL_STATE{ + "MAV_VTOL_STATE_UNDEFINED": MAV_VTOL_STATE_UNDEFINED, + "MAV_VTOL_STATE_TRANSITION_TO_FW": MAV_VTOL_STATE_TRANSITION_TO_FW, + "MAV_VTOL_STATE_TRANSITION_TO_MC": MAV_VTOL_STATE_TRANSITION_TO_MC, + "MAV_VTOL_STATE_MC": MAV_VTOL_STATE_MC, + "MAV_VTOL_STATE_FW": MAV_VTOL_STATE_FW, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_VTOL_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_VTOL_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_VTOL_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_VTOL_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_VTOL_STATE - for _, label := range labels { - found := false - for value, l := range labels_MAV_VTOL_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_VTOL_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_VTOL_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_VTOL_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mav_winch_status_flag.go b/pkg/dialects/common/enum_mav_winch_status_flag.go index 8ce5ee3db..cfe23c10f 100644 --- a/pkg/dialects/common/enum_mav_winch_status_flag.go +++ b/pkg/dialects/common/enum_mav_winch_status_flag.go @@ -58,12 +58,30 @@ var labels_MAV_WINCH_STATUS_FLAG = map[MAV_WINCH_STATUS_FLAG]string{ MAV_WINCH_STATUS_LOAD_PAYLOAD: "MAV_WINCH_STATUS_LOAD_PAYLOAD", } +var values_MAV_WINCH_STATUS_FLAG = map[string]MAV_WINCH_STATUS_FLAG{ + "MAV_WINCH_STATUS_HEALTHY": MAV_WINCH_STATUS_HEALTHY, + "MAV_WINCH_STATUS_FULLY_RETRACTED": MAV_WINCH_STATUS_FULLY_RETRACTED, + "MAV_WINCH_STATUS_MOVING": MAV_WINCH_STATUS_MOVING, + "MAV_WINCH_STATUS_CLUTCH_ENGAGED": MAV_WINCH_STATUS_CLUTCH_ENGAGED, + "MAV_WINCH_STATUS_LOCKED": MAV_WINCH_STATUS_LOCKED, + "MAV_WINCH_STATUS_DROPPING": MAV_WINCH_STATUS_DROPPING, + "MAV_WINCH_STATUS_ARRESTING": MAV_WINCH_STATUS_ARRESTING, + "MAV_WINCH_STATUS_GROUND_SENSE": MAV_WINCH_STATUS_GROUND_SENSE, + "MAV_WINCH_STATUS_RETRACTING": MAV_WINCH_STATUS_RETRACTING, + "MAV_WINCH_STATUS_REDELIVER": MAV_WINCH_STATUS_REDELIVER, + "MAV_WINCH_STATUS_ABANDON_LINE": MAV_WINCH_STATUS_ABANDON_LINE, + "MAV_WINCH_STATUS_LOCKING": MAV_WINCH_STATUS_LOCKING, + "MAV_WINCH_STATUS_LOAD_LINE": MAV_WINCH_STATUS_LOAD_LINE, + "MAV_WINCH_STATUS_LOAD_PAYLOAD": MAV_WINCH_STATUS_LOAD_PAYLOAD, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_WINCH_STATUS_FLAG) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_WINCH_STATUS_FLAG { + for i := 0; i < 14; i++ { + mask := MAV_WINCH_STATUS_FLAG(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_WINCH_STATUS_FLAG[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -74,19 +92,12 @@ func (e *MAV_WINCH_STATUS_FLAG) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_WINCH_STATUS_FLAG for _, label := range labels { - found := false - for value, l := range labels_MAV_WINCH_STATUS_FLAG { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_WINCH_STATUS_FLAG[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_mavlink_data_stream_type.go b/pkg/dialects/common/enum_mavlink_data_stream_type.go index 1f27ca1bb..108ce149c 100644 --- a/pkg/dialects/common/enum_mavlink_data_stream_type.go +++ b/pkg/dialects/common/enum_mavlink_data_stream_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type MAVLINK_DATA_STREAM_TYPE uint32 @@ -27,40 +27,39 @@ var labels_MAVLINK_DATA_STREAM_TYPE = map[MAVLINK_DATA_STREAM_TYPE]string{ MAVLINK_DATA_STREAM_IMG_PNG: "MAVLINK_DATA_STREAM_IMG_PNG", } +var values_MAVLINK_DATA_STREAM_TYPE = map[string]MAVLINK_DATA_STREAM_TYPE{ + "MAVLINK_DATA_STREAM_IMG_JPEG": MAVLINK_DATA_STREAM_IMG_JPEG, + "MAVLINK_DATA_STREAM_IMG_BMP": MAVLINK_DATA_STREAM_IMG_BMP, + "MAVLINK_DATA_STREAM_IMG_RAW8U": MAVLINK_DATA_STREAM_IMG_RAW8U, + "MAVLINK_DATA_STREAM_IMG_RAW32U": MAVLINK_DATA_STREAM_IMG_RAW32U, + "MAVLINK_DATA_STREAM_IMG_PGM": MAVLINK_DATA_STREAM_IMG_PGM, + "MAVLINK_DATA_STREAM_IMG_PNG": MAVLINK_DATA_STREAM_IMG_PNG, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAVLINK_DATA_STREAM_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAVLINK_DATA_STREAM_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAVLINK_DATA_STREAM_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAVLINK_DATA_STREAM_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAVLINK_DATA_STREAM_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAVLINK_DATA_STREAM_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAVLINK_DATA_STREAM_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAVLINK_DATA_STREAM_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAVLINK_DATA_STREAM_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_mission_state.go b/pkg/dialects/common/enum_mission_state.go index a755127a6..2e0a2a6bd 100644 --- a/pkg/dialects/common/enum_mission_state.go +++ b/pkg/dialects/common/enum_mission_state.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // States of the mission state machine. @@ -36,40 +36,39 @@ var labels_MISSION_STATE = map[MISSION_STATE]string{ MISSION_STATE_COMPLETE: "MISSION_STATE_COMPLETE", } +var values_MISSION_STATE = map[string]MISSION_STATE{ + "MISSION_STATE_UNKNOWN": MISSION_STATE_UNKNOWN, + "MISSION_STATE_NO_MISSION": MISSION_STATE_NO_MISSION, + "MISSION_STATE_NOT_STARTED": MISSION_STATE_NOT_STARTED, + "MISSION_STATE_ACTIVE": MISSION_STATE_ACTIVE, + "MISSION_STATE_PAUSED": MISSION_STATE_PAUSED, + "MISSION_STATE_COMPLETE": MISSION_STATE_COMPLETE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MISSION_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MISSION_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MISSION_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MISSION_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MISSION_STATE - for _, label := range labels { - found := false - for value, l := range labels_MISSION_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MISSION_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MISSION_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MISSION_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_motor_test_order.go b/pkg/dialects/common/enum_motor_test_order.go index 1223b44ce..1f531a1a3 100644 --- a/pkg/dialects/common/enum_motor_test_order.go +++ b/pkg/dialects/common/enum_motor_test_order.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Sequence that motors are tested when using MAV_CMD_DO_MOTOR_TEST. @@ -25,40 +25,36 @@ var labels_MOTOR_TEST_ORDER = map[MOTOR_TEST_ORDER]string{ MOTOR_TEST_ORDER_BOARD: "MOTOR_TEST_ORDER_BOARD", } +var values_MOTOR_TEST_ORDER = map[string]MOTOR_TEST_ORDER{ + "MOTOR_TEST_ORDER_DEFAULT": MOTOR_TEST_ORDER_DEFAULT, + "MOTOR_TEST_ORDER_SEQUENCE": MOTOR_TEST_ORDER_SEQUENCE, + "MOTOR_TEST_ORDER_BOARD": MOTOR_TEST_ORDER_BOARD, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MOTOR_TEST_ORDER) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MOTOR_TEST_ORDER { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MOTOR_TEST_ORDER[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MOTOR_TEST_ORDER) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MOTOR_TEST_ORDER - for _, label := range labels { - found := false - for value, l := range labels_MOTOR_TEST_ORDER { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MOTOR_TEST_ORDER[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MOTOR_TEST_ORDER) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MOTOR_TEST_ORDER[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_motor_test_throttle_type.go b/pkg/dialects/common/enum_motor_test_throttle_type.go index f6d94860a..409457dfa 100644 --- a/pkg/dialects/common/enum_motor_test_throttle_type.go +++ b/pkg/dialects/common/enum_motor_test_throttle_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Defines how throttle value is represented in MAV_CMD_DO_MOTOR_TEST. @@ -28,40 +28,37 @@ var labels_MOTOR_TEST_THROTTLE_TYPE = map[MOTOR_TEST_THROTTLE_TYPE]string{ MOTOR_TEST_COMPASS_CAL: "MOTOR_TEST_COMPASS_CAL", } +var values_MOTOR_TEST_THROTTLE_TYPE = map[string]MOTOR_TEST_THROTTLE_TYPE{ + "MOTOR_TEST_THROTTLE_PERCENT": MOTOR_TEST_THROTTLE_PERCENT, + "MOTOR_TEST_THROTTLE_PWM": MOTOR_TEST_THROTTLE_PWM, + "MOTOR_TEST_THROTTLE_PILOT": MOTOR_TEST_THROTTLE_PILOT, + "MOTOR_TEST_COMPASS_CAL": MOTOR_TEST_COMPASS_CAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MOTOR_TEST_THROTTLE_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MOTOR_TEST_THROTTLE_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MOTOR_TEST_THROTTLE_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MOTOR_TEST_THROTTLE_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MOTOR_TEST_THROTTLE_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MOTOR_TEST_THROTTLE_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MOTOR_TEST_THROTTLE_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MOTOR_TEST_THROTTLE_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MOTOR_TEST_THROTTLE_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_nav_vtol_land_options.go b/pkg/dialects/common/enum_nav_vtol_land_options.go index 102a623b0..13f634038 100644 --- a/pkg/dialects/common/enum_nav_vtol_land_options.go +++ b/pkg/dialects/common/enum_nav_vtol_land_options.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) type NAV_VTOL_LAND_OPTIONS uint32 @@ -25,40 +25,36 @@ var labels_NAV_VTOL_LAND_OPTIONS = map[NAV_VTOL_LAND_OPTIONS]string{ NAV_VTOL_LAND_OPTIONS_HOVER_DESCENT: "NAV_VTOL_LAND_OPTIONS_HOVER_DESCENT", } +var values_NAV_VTOL_LAND_OPTIONS = map[string]NAV_VTOL_LAND_OPTIONS{ + "NAV_VTOL_LAND_OPTIONS_DEFAULT": NAV_VTOL_LAND_OPTIONS_DEFAULT, + "NAV_VTOL_LAND_OPTIONS_FW_DESCENT": NAV_VTOL_LAND_OPTIONS_FW_DESCENT, + "NAV_VTOL_LAND_OPTIONS_HOVER_DESCENT": NAV_VTOL_LAND_OPTIONS_HOVER_DESCENT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e NAV_VTOL_LAND_OPTIONS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_NAV_VTOL_LAND_OPTIONS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_NAV_VTOL_LAND_OPTIONS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *NAV_VTOL_LAND_OPTIONS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask NAV_VTOL_LAND_OPTIONS - for _, label := range labels { - found := false - for value, l := range labels_NAV_VTOL_LAND_OPTIONS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_NAV_VTOL_LAND_OPTIONS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e NAV_VTOL_LAND_OPTIONS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_NAV_VTOL_LAND_OPTIONS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_orbit_yaw_behaviour.go b/pkg/dialects/common/enum_orbit_yaw_behaviour.go index 6f9f6c9c6..d4180b769 100644 --- a/pkg/dialects/common/enum_orbit_yaw_behaviour.go +++ b/pkg/dialects/common/enum_orbit_yaw_behaviour.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Yaw behaviour during orbit flight. @@ -31,40 +31,38 @@ var labels_ORBIT_YAW_BEHAVIOUR = map[ORBIT_YAW_BEHAVIOUR]string{ ORBIT_YAW_BEHAVIOUR_RC_CONTROLLED: "ORBIT_YAW_BEHAVIOUR_RC_CONTROLLED", } +var values_ORBIT_YAW_BEHAVIOUR = map[string]ORBIT_YAW_BEHAVIOUR{ + "ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TO_CIRCLE_CENTER": ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TO_CIRCLE_CENTER, + "ORBIT_YAW_BEHAVIOUR_HOLD_INITIAL_HEADING": ORBIT_YAW_BEHAVIOUR_HOLD_INITIAL_HEADING, + "ORBIT_YAW_BEHAVIOUR_UNCONTROLLED": ORBIT_YAW_BEHAVIOUR_UNCONTROLLED, + "ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TANGENT_TO_CIRCLE": ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TANGENT_TO_CIRCLE, + "ORBIT_YAW_BEHAVIOUR_RC_CONTROLLED": ORBIT_YAW_BEHAVIOUR_RC_CONTROLLED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ORBIT_YAW_BEHAVIOUR) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ORBIT_YAW_BEHAVIOUR { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ORBIT_YAW_BEHAVIOUR[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ORBIT_YAW_BEHAVIOUR) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ORBIT_YAW_BEHAVIOUR - for _, label := range labels { - found := false - for value, l := range labels_ORBIT_YAW_BEHAVIOUR { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ORBIT_YAW_BEHAVIOUR[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ORBIT_YAW_BEHAVIOUR) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ORBIT_YAW_BEHAVIOUR[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_parachute_action.go b/pkg/dialects/common/enum_parachute_action.go index 921d67488..03c768ca6 100644 --- a/pkg/dialects/common/enum_parachute_action.go +++ b/pkg/dialects/common/enum_parachute_action.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Parachute actions. Trigger release and enable/disable auto-release. @@ -25,40 +25,36 @@ var labels_PARACHUTE_ACTION = map[PARACHUTE_ACTION]string{ PARACHUTE_RELEASE: "PARACHUTE_RELEASE", } +var values_PARACHUTE_ACTION = map[string]PARACHUTE_ACTION{ + "PARACHUTE_DISABLE": PARACHUTE_DISABLE, + "PARACHUTE_ENABLE": PARACHUTE_ENABLE, + "PARACHUTE_RELEASE": PARACHUTE_RELEASE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PARACHUTE_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PARACHUTE_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PARACHUTE_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PARACHUTE_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PARACHUTE_ACTION - for _, label := range labels { - found := false - for value, l := range labels_PARACHUTE_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PARACHUTE_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PARACHUTE_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PARACHUTE_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_param_ack.go b/pkg/dialects/common/enum_param_ack.go index 1afaf393a..cf3265334 100644 --- a/pkg/dialects/common/enum_param_ack.go +++ b/pkg/dialects/common/enum_param_ack.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Result from PARAM_EXT_SET message (or a PARAM_SET within a transaction). @@ -28,40 +28,37 @@ var labels_PARAM_ACK = map[PARAM_ACK]string{ PARAM_ACK_IN_PROGRESS: "PARAM_ACK_IN_PROGRESS", } +var values_PARAM_ACK = map[string]PARAM_ACK{ + "PARAM_ACK_ACCEPTED": PARAM_ACK_ACCEPTED, + "PARAM_ACK_VALUE_UNSUPPORTED": PARAM_ACK_VALUE_UNSUPPORTED, + "PARAM_ACK_FAILED": PARAM_ACK_FAILED, + "PARAM_ACK_IN_PROGRESS": PARAM_ACK_IN_PROGRESS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PARAM_ACK) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PARAM_ACK { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PARAM_ACK[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PARAM_ACK) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PARAM_ACK - for _, label := range labels { - found := false - for value, l := range labels_PARAM_ACK { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PARAM_ACK[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PARAM_ACK) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PARAM_ACK[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_position_target_typemask.go b/pkg/dialects/common/enum_position_target_typemask.go index 7da638ac3..ae086e890 100644 --- a/pkg/dialects/common/enum_position_target_typemask.go +++ b/pkg/dialects/common/enum_position_target_typemask.go @@ -52,12 +52,28 @@ var labels_POSITION_TARGET_TYPEMASK = map[POSITION_TARGET_TYPEMASK]string{ POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE: "POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE", } +var values_POSITION_TARGET_TYPEMASK = map[string]POSITION_TARGET_TYPEMASK{ + "POSITION_TARGET_TYPEMASK_X_IGNORE": POSITION_TARGET_TYPEMASK_X_IGNORE, + "POSITION_TARGET_TYPEMASK_Y_IGNORE": POSITION_TARGET_TYPEMASK_Y_IGNORE, + "POSITION_TARGET_TYPEMASK_Z_IGNORE": POSITION_TARGET_TYPEMASK_Z_IGNORE, + "POSITION_TARGET_TYPEMASK_VX_IGNORE": POSITION_TARGET_TYPEMASK_VX_IGNORE, + "POSITION_TARGET_TYPEMASK_VY_IGNORE": POSITION_TARGET_TYPEMASK_VY_IGNORE, + "POSITION_TARGET_TYPEMASK_VZ_IGNORE": POSITION_TARGET_TYPEMASK_VZ_IGNORE, + "POSITION_TARGET_TYPEMASK_AX_IGNORE": POSITION_TARGET_TYPEMASK_AX_IGNORE, + "POSITION_TARGET_TYPEMASK_AY_IGNORE": POSITION_TARGET_TYPEMASK_AY_IGNORE, + "POSITION_TARGET_TYPEMASK_AZ_IGNORE": POSITION_TARGET_TYPEMASK_AZ_IGNORE, + "POSITION_TARGET_TYPEMASK_FORCE_SET": POSITION_TARGET_TYPEMASK_FORCE_SET, + "POSITION_TARGET_TYPEMASK_YAW_IGNORE": POSITION_TARGET_TYPEMASK_YAW_IGNORE, + "POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE": POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e POSITION_TARGET_TYPEMASK) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_POSITION_TARGET_TYPEMASK { + for i := 0; i < 12; i++ { + mask := POSITION_TARGET_TYPEMASK(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_POSITION_TARGET_TYPEMASK[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -68,19 +84,12 @@ func (e *POSITION_TARGET_TYPEMASK) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask POSITION_TARGET_TYPEMASK for _, label := range labels { - found := false - for value, l := range labels_POSITION_TARGET_TYPEMASK { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_POSITION_TARGET_TYPEMASK[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_precision_land_mode.go b/pkg/dialects/common/enum_precision_land_mode.go index 9cb564f27..816b49cd4 100644 --- a/pkg/dialects/common/enum_precision_land_mode.go +++ b/pkg/dialects/common/enum_precision_land_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Precision land modes (used in MAV_CMD_NAV_LAND). @@ -25,40 +25,36 @@ var labels_PRECISION_LAND_MODE = map[PRECISION_LAND_MODE]string{ PRECISION_LAND_MODE_REQUIRED: "PRECISION_LAND_MODE_REQUIRED", } +var values_PRECISION_LAND_MODE = map[string]PRECISION_LAND_MODE{ + "PRECISION_LAND_MODE_DISABLED": PRECISION_LAND_MODE_DISABLED, + "PRECISION_LAND_MODE_OPPORTUNISTIC": PRECISION_LAND_MODE_OPPORTUNISTIC, + "PRECISION_LAND_MODE_REQUIRED": PRECISION_LAND_MODE_REQUIRED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PRECISION_LAND_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PRECISION_LAND_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PRECISION_LAND_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PRECISION_LAND_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PRECISION_LAND_MODE - for _, label := range labels { - found := false - for value, l := range labels_PRECISION_LAND_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PRECISION_LAND_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PRECISION_LAND_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PRECISION_LAND_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_preflight_storage_mission_action.go b/pkg/dialects/common/enum_preflight_storage_mission_action.go index 71f25c64c..9f06b360f 100644 --- a/pkg/dialects/common/enum_preflight_storage_mission_action.go +++ b/pkg/dialects/common/enum_preflight_storage_mission_action.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actions for reading and writing plan information (mission, rally points, geofence) between persistent and volatile storage when using MAV_CMD_PREFLIGHT_STORAGE. @@ -26,40 +26,36 @@ var labels_PREFLIGHT_STORAGE_MISSION_ACTION = map[PREFLIGHT_STORAGE_MISSION_ACTI MISSION_RESET_DEFAULT: "MISSION_RESET_DEFAULT", } +var values_PREFLIGHT_STORAGE_MISSION_ACTION = map[string]PREFLIGHT_STORAGE_MISSION_ACTION{ + "MISSION_READ_PERSISTENT": MISSION_READ_PERSISTENT, + "MISSION_WRITE_PERSISTENT": MISSION_WRITE_PERSISTENT, + "MISSION_RESET_DEFAULT": MISSION_RESET_DEFAULT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PREFLIGHT_STORAGE_MISSION_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PREFLIGHT_STORAGE_MISSION_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PREFLIGHT_STORAGE_MISSION_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PREFLIGHT_STORAGE_MISSION_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PREFLIGHT_STORAGE_MISSION_ACTION - for _, label := range labels { - found := false - for value, l := range labels_PREFLIGHT_STORAGE_MISSION_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PREFLIGHT_STORAGE_MISSION_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PREFLIGHT_STORAGE_MISSION_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PREFLIGHT_STORAGE_MISSION_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_preflight_storage_parameter_action.go b/pkg/dialects/common/enum_preflight_storage_parameter_action.go index 66f5bd2da..c86ec8dd3 100644 --- a/pkg/dialects/common/enum_preflight_storage_parameter_action.go +++ b/pkg/dialects/common/enum_preflight_storage_parameter_action.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Actions for reading/writing parameters between persistent and volatile storage when using MAV_CMD_PREFLIGHT_STORAGE. @@ -32,40 +32,38 @@ var labels_PREFLIGHT_STORAGE_PARAMETER_ACTION = map[PREFLIGHT_STORAGE_PARAMETER_ PARAM_RESET_ALL_DEFAULT: "PARAM_RESET_ALL_DEFAULT", } +var values_PREFLIGHT_STORAGE_PARAMETER_ACTION = map[string]PREFLIGHT_STORAGE_PARAMETER_ACTION{ + "PARAM_READ_PERSISTENT": PARAM_READ_PERSISTENT, + "PARAM_WRITE_PERSISTENT": PARAM_WRITE_PERSISTENT, + "PARAM_RESET_CONFIG_DEFAULT": PARAM_RESET_CONFIG_DEFAULT, + "PARAM_RESET_SENSOR_DEFAULT": PARAM_RESET_SENSOR_DEFAULT, + "PARAM_RESET_ALL_DEFAULT": PARAM_RESET_ALL_DEFAULT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PREFLIGHT_STORAGE_PARAMETER_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PREFLIGHT_STORAGE_PARAMETER_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PREFLIGHT_STORAGE_PARAMETER_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PREFLIGHT_STORAGE_PARAMETER_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PREFLIGHT_STORAGE_PARAMETER_ACTION - for _, label := range labels { - found := false - for value, l := range labels_PREFLIGHT_STORAGE_PARAMETER_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PREFLIGHT_STORAGE_PARAMETER_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PREFLIGHT_STORAGE_PARAMETER_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PREFLIGHT_STORAGE_PARAMETER_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_rc_type.go b/pkg/dialects/common/enum_rc_type.go index b46451106..102cc4c61 100644 --- a/pkg/dialects/common/enum_rc_type.go +++ b/pkg/dialects/common/enum_rc_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // RC type @@ -22,40 +22,35 @@ var labels_RC_TYPE = map[RC_TYPE]string{ RC_TYPE_SPEKTRUM_DSMX: "RC_TYPE_SPEKTRUM_DSMX", } +var values_RC_TYPE = map[string]RC_TYPE{ + "RC_TYPE_SPEKTRUM_DSM2": RC_TYPE_SPEKTRUM_DSM2, + "RC_TYPE_SPEKTRUM_DSMX": RC_TYPE_SPEKTRUM_DSMX, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e RC_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_RC_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_RC_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *RC_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask RC_TYPE - for _, label := range labels { - found := false - for value, l := range labels_RC_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_RC_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e RC_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_RC_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_rtk_baseline_coordinate_system.go b/pkg/dialects/common/enum_rtk_baseline_coordinate_system.go index 74b800639..b633a31ea 100644 --- a/pkg/dialects/common/enum_rtk_baseline_coordinate_system.go +++ b/pkg/dialects/common/enum_rtk_baseline_coordinate_system.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // RTK GPS baseline coordinate system, used for RTK corrections @@ -22,40 +22,35 @@ var labels_RTK_BASELINE_COORDINATE_SYSTEM = map[RTK_BASELINE_COORDINATE_SYSTEM]s RTK_BASELINE_COORDINATE_SYSTEM_NED: "RTK_BASELINE_COORDINATE_SYSTEM_NED", } +var values_RTK_BASELINE_COORDINATE_SYSTEM = map[string]RTK_BASELINE_COORDINATE_SYSTEM{ + "RTK_BASELINE_COORDINATE_SYSTEM_ECEF": RTK_BASELINE_COORDINATE_SYSTEM_ECEF, + "RTK_BASELINE_COORDINATE_SYSTEM_NED": RTK_BASELINE_COORDINATE_SYSTEM_NED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e RTK_BASELINE_COORDINATE_SYSTEM) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_RTK_BASELINE_COORDINATE_SYSTEM { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_RTK_BASELINE_COORDINATE_SYSTEM[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *RTK_BASELINE_COORDINATE_SYSTEM) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask RTK_BASELINE_COORDINATE_SYSTEM - for _, label := range labels { - found := false - for value, l := range labels_RTK_BASELINE_COORDINATE_SYSTEM { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_RTK_BASELINE_COORDINATE_SYSTEM[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e RTK_BASELINE_COORDINATE_SYSTEM) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_RTK_BASELINE_COORDINATE_SYSTEM[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_serial_control_dev.go b/pkg/dialects/common/enum_serial_control_dev.go index 39d480083..149e3d498 100644 --- a/pkg/dialects/common/enum_serial_control_dev.go +++ b/pkg/dialects/common/enum_serial_control_dev.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // SERIAL_CONTROL device types @@ -61,40 +61,48 @@ var labels_SERIAL_CONTROL_DEV = map[SERIAL_CONTROL_DEV]string{ SERIAL_CONTROL_SERIAL9: "SERIAL_CONTROL_SERIAL9", } +var values_SERIAL_CONTROL_DEV = map[string]SERIAL_CONTROL_DEV{ + "SERIAL_CONTROL_DEV_TELEM1": SERIAL_CONTROL_DEV_TELEM1, + "SERIAL_CONTROL_DEV_TELEM2": SERIAL_CONTROL_DEV_TELEM2, + "SERIAL_CONTROL_DEV_GPS1": SERIAL_CONTROL_DEV_GPS1, + "SERIAL_CONTROL_DEV_GPS2": SERIAL_CONTROL_DEV_GPS2, + "SERIAL_CONTROL_DEV_SHELL": SERIAL_CONTROL_DEV_SHELL, + "SERIAL_CONTROL_SERIAL0": SERIAL_CONTROL_SERIAL0, + "SERIAL_CONTROL_SERIAL1": SERIAL_CONTROL_SERIAL1, + "SERIAL_CONTROL_SERIAL2": SERIAL_CONTROL_SERIAL2, + "SERIAL_CONTROL_SERIAL3": SERIAL_CONTROL_SERIAL3, + "SERIAL_CONTROL_SERIAL4": SERIAL_CONTROL_SERIAL4, + "SERIAL_CONTROL_SERIAL5": SERIAL_CONTROL_SERIAL5, + "SERIAL_CONTROL_SERIAL6": SERIAL_CONTROL_SERIAL6, + "SERIAL_CONTROL_SERIAL7": SERIAL_CONTROL_SERIAL7, + "SERIAL_CONTROL_SERIAL8": SERIAL_CONTROL_SERIAL8, + "SERIAL_CONTROL_SERIAL9": SERIAL_CONTROL_SERIAL9, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e SERIAL_CONTROL_DEV) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_SERIAL_CONTROL_DEV { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_SERIAL_CONTROL_DEV[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *SERIAL_CONTROL_DEV) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask SERIAL_CONTROL_DEV - for _, label := range labels { - found := false - for value, l := range labels_SERIAL_CONTROL_DEV { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_SERIAL_CONTROL_DEV[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e SERIAL_CONTROL_DEV) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_SERIAL_CONTROL_DEV[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_serial_control_flag.go b/pkg/dialects/common/enum_serial_control_flag.go index 83d1363fe..ae363f5a7 100644 --- a/pkg/dialects/common/enum_serial_control_flag.go +++ b/pkg/dialects/common/enum_serial_control_flag.go @@ -31,12 +31,21 @@ var labels_SERIAL_CONTROL_FLAG = map[SERIAL_CONTROL_FLAG]string{ SERIAL_CONTROL_FLAG_MULTI: "SERIAL_CONTROL_FLAG_MULTI", } +var values_SERIAL_CONTROL_FLAG = map[string]SERIAL_CONTROL_FLAG{ + "SERIAL_CONTROL_FLAG_REPLY": SERIAL_CONTROL_FLAG_REPLY, + "SERIAL_CONTROL_FLAG_RESPOND": SERIAL_CONTROL_FLAG_RESPOND, + "SERIAL_CONTROL_FLAG_EXCLUSIVE": SERIAL_CONTROL_FLAG_EXCLUSIVE, + "SERIAL_CONTROL_FLAG_BLOCKING": SERIAL_CONTROL_FLAG_BLOCKING, + "SERIAL_CONTROL_FLAG_MULTI": SERIAL_CONTROL_FLAG_MULTI, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e SERIAL_CONTROL_FLAG) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_SERIAL_CONTROL_FLAG { + for i := 0; i < 5; i++ { + mask := SERIAL_CONTROL_FLAG(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_SERIAL_CONTROL_FLAG[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -47,19 +56,12 @@ func (e *SERIAL_CONTROL_FLAG) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask SERIAL_CONTROL_FLAG for _, label := range labels { - found := false - for value, l := range labels_SERIAL_CONTROL_FLAG { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_SERIAL_CONTROL_FLAG[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_set_focus_type.go b/pkg/dialects/common/enum_set_focus_type.go index 6e8256f5d..a76d8f82c 100644 --- a/pkg/dialects/common/enum_set_focus_type.go +++ b/pkg/dialects/common/enum_set_focus_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Focus types for MAV_CMD_SET_CAMERA_FOCUS @@ -37,40 +37,40 @@ var labels_SET_FOCUS_TYPE = map[SET_FOCUS_TYPE]string{ FOCUS_TYPE_AUTO_CONTINUOUS: "FOCUS_TYPE_AUTO_CONTINUOUS", } +var values_SET_FOCUS_TYPE = map[string]SET_FOCUS_TYPE{ + "FOCUS_TYPE_STEP": FOCUS_TYPE_STEP, + "FOCUS_TYPE_CONTINUOUS": FOCUS_TYPE_CONTINUOUS, + "FOCUS_TYPE_RANGE": FOCUS_TYPE_RANGE, + "FOCUS_TYPE_METERS": FOCUS_TYPE_METERS, + "FOCUS_TYPE_AUTO": FOCUS_TYPE_AUTO, + "FOCUS_TYPE_AUTO_SINGLE": FOCUS_TYPE_AUTO_SINGLE, + "FOCUS_TYPE_AUTO_CONTINUOUS": FOCUS_TYPE_AUTO_CONTINUOUS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e SET_FOCUS_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_SET_FOCUS_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_SET_FOCUS_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *SET_FOCUS_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask SET_FOCUS_TYPE - for _, label := range labels { - found := false - for value, l := range labels_SET_FOCUS_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_SET_FOCUS_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e SET_FOCUS_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_SET_FOCUS_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_storage_status.go b/pkg/dialects/common/enum_storage_status.go index 83db14c84..98e95e61b 100644 --- a/pkg/dialects/common/enum_storage_status.go +++ b/pkg/dialects/common/enum_storage_status.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Flags to indicate the status of camera storage. @@ -28,40 +28,37 @@ var labels_STORAGE_STATUS = map[STORAGE_STATUS]string{ STORAGE_STATUS_NOT_SUPPORTED: "STORAGE_STATUS_NOT_SUPPORTED", } +var values_STORAGE_STATUS = map[string]STORAGE_STATUS{ + "STORAGE_STATUS_EMPTY": STORAGE_STATUS_EMPTY, + "STORAGE_STATUS_UNFORMATTED": STORAGE_STATUS_UNFORMATTED, + "STORAGE_STATUS_READY": STORAGE_STATUS_READY, + "STORAGE_STATUS_NOT_SUPPORTED": STORAGE_STATUS_NOT_SUPPORTED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e STORAGE_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_STORAGE_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_STORAGE_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *STORAGE_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask STORAGE_STATUS - for _, label := range labels { - found := false - for value, l := range labels_STORAGE_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_STORAGE_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e STORAGE_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_STORAGE_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_storage_type.go b/pkg/dialects/common/enum_storage_type.go index a03916fbd..960fbf028 100644 --- a/pkg/dialects/common/enum_storage_type.go +++ b/pkg/dialects/common/enum_storage_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Flags to indicate the type of storage. @@ -43,40 +43,42 @@ var labels_STORAGE_TYPE = map[STORAGE_TYPE]string{ STORAGE_TYPE_OTHER: "STORAGE_TYPE_OTHER", } +var values_STORAGE_TYPE = map[string]STORAGE_TYPE{ + "STORAGE_TYPE_UNKNOWN": STORAGE_TYPE_UNKNOWN, + "STORAGE_TYPE_USB_STICK": STORAGE_TYPE_USB_STICK, + "STORAGE_TYPE_SD": STORAGE_TYPE_SD, + "STORAGE_TYPE_MICROSD": STORAGE_TYPE_MICROSD, + "STORAGE_TYPE_CF": STORAGE_TYPE_CF, + "STORAGE_TYPE_CFE": STORAGE_TYPE_CFE, + "STORAGE_TYPE_XQD": STORAGE_TYPE_XQD, + "STORAGE_TYPE_HD": STORAGE_TYPE_HD, + "STORAGE_TYPE_OTHER": STORAGE_TYPE_OTHER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e STORAGE_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_STORAGE_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_STORAGE_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *STORAGE_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask STORAGE_TYPE - for _, label := range labels { - found := false - for value, l := range labels_STORAGE_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_STORAGE_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e STORAGE_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_STORAGE_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_storage_usage_flag.go b/pkg/dialects/common/enum_storage_usage_flag.go index 275ebb4ef..e83c7a98c 100644 --- a/pkg/dialects/common/enum_storage_usage_flag.go +++ b/pkg/dialects/common/enum_storage_usage_flag.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Flags to indicate usage for a particular storage (see STORAGE_INFORMATION.storage_usage and MAV_CMD_SET_STORAGE_USAGE). @@ -28,40 +28,37 @@ var labels_STORAGE_USAGE_FLAG = map[STORAGE_USAGE_FLAG]string{ STORAGE_USAGE_FLAG_LOGS: "STORAGE_USAGE_FLAG_LOGS", } +var values_STORAGE_USAGE_FLAG = map[string]STORAGE_USAGE_FLAG{ + "STORAGE_USAGE_FLAG_SET": STORAGE_USAGE_FLAG_SET, + "STORAGE_USAGE_FLAG_PHOTO": STORAGE_USAGE_FLAG_PHOTO, + "STORAGE_USAGE_FLAG_VIDEO": STORAGE_USAGE_FLAG_VIDEO, + "STORAGE_USAGE_FLAG_LOGS": STORAGE_USAGE_FLAG_LOGS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e STORAGE_USAGE_FLAG) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_STORAGE_USAGE_FLAG { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_STORAGE_USAGE_FLAG[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *STORAGE_USAGE_FLAG) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask STORAGE_USAGE_FLAG - for _, label := range labels { - found := false - for value, l := range labels_STORAGE_USAGE_FLAG { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_STORAGE_USAGE_FLAG[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e STORAGE_USAGE_FLAG) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_STORAGE_USAGE_FLAG[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_tune_format.go b/pkg/dialects/common/enum_tune_format.go index 656ba0f8d..3ca7d2db9 100644 --- a/pkg/dialects/common/enum_tune_format.go +++ b/pkg/dialects/common/enum_tune_format.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Tune formats (used for vehicle buzzer/tone generation). @@ -22,40 +22,35 @@ var labels_TUNE_FORMAT = map[TUNE_FORMAT]string{ TUNE_FORMAT_MML_MODERN: "TUNE_FORMAT_MML_MODERN", } +var values_TUNE_FORMAT = map[string]TUNE_FORMAT{ + "TUNE_FORMAT_QBASIC1_1": TUNE_FORMAT_QBASIC1_1, + "TUNE_FORMAT_MML_MODERN": TUNE_FORMAT_MML_MODERN, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e TUNE_FORMAT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_TUNE_FORMAT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_TUNE_FORMAT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *TUNE_FORMAT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask TUNE_FORMAT - for _, label := range labels { - found := false - for value, l := range labels_TUNE_FORMAT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_TUNE_FORMAT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e TUNE_FORMAT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_TUNE_FORMAT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_uavcan_node_health.go b/pkg/dialects/common/enum_uavcan_node_health.go index 4ff85da05..296e64f45 100644 --- a/pkg/dialects/common/enum_uavcan_node_health.go +++ b/pkg/dialects/common/enum_uavcan_node_health.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Generalized UAVCAN node health @@ -28,40 +28,37 @@ var labels_UAVCAN_NODE_HEALTH = map[UAVCAN_NODE_HEALTH]string{ UAVCAN_NODE_HEALTH_CRITICAL: "UAVCAN_NODE_HEALTH_CRITICAL", } +var values_UAVCAN_NODE_HEALTH = map[string]UAVCAN_NODE_HEALTH{ + "UAVCAN_NODE_HEALTH_OK": UAVCAN_NODE_HEALTH_OK, + "UAVCAN_NODE_HEALTH_WARNING": UAVCAN_NODE_HEALTH_WARNING, + "UAVCAN_NODE_HEALTH_ERROR": UAVCAN_NODE_HEALTH_ERROR, + "UAVCAN_NODE_HEALTH_CRITICAL": UAVCAN_NODE_HEALTH_CRITICAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVCAN_NODE_HEALTH) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVCAN_NODE_HEALTH { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVCAN_NODE_HEALTH[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVCAN_NODE_HEALTH) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVCAN_NODE_HEALTH - for _, label := range labels { - found := false - for value, l := range labels_UAVCAN_NODE_HEALTH { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVCAN_NODE_HEALTH[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVCAN_NODE_HEALTH) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVCAN_NODE_HEALTH[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_uavcan_node_mode.go b/pkg/dialects/common/enum_uavcan_node_mode.go index f0f7a6696..2743aeccc 100644 --- a/pkg/dialects/common/enum_uavcan_node_mode.go +++ b/pkg/dialects/common/enum_uavcan_node_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Generalized UAVCAN node mode @@ -31,40 +31,38 @@ var labels_UAVCAN_NODE_MODE = map[UAVCAN_NODE_MODE]string{ UAVCAN_NODE_MODE_OFFLINE: "UAVCAN_NODE_MODE_OFFLINE", } +var values_UAVCAN_NODE_MODE = map[string]UAVCAN_NODE_MODE{ + "UAVCAN_NODE_MODE_OPERATIONAL": UAVCAN_NODE_MODE_OPERATIONAL, + "UAVCAN_NODE_MODE_INITIALIZATION": UAVCAN_NODE_MODE_INITIALIZATION, + "UAVCAN_NODE_MODE_MAINTENANCE": UAVCAN_NODE_MODE_MAINTENANCE, + "UAVCAN_NODE_MODE_SOFTWARE_UPDATE": UAVCAN_NODE_MODE_SOFTWARE_UPDATE, + "UAVCAN_NODE_MODE_OFFLINE": UAVCAN_NODE_MODE_OFFLINE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVCAN_NODE_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVCAN_NODE_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVCAN_NODE_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVCAN_NODE_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVCAN_NODE_MODE - for _, label := range labels { - found := false - for value, l := range labels_UAVCAN_NODE_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVCAN_NODE_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVCAN_NODE_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVCAN_NODE_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_utm_data_avail_flags.go b/pkg/dialects/common/enum_utm_data_avail_flags.go index 5cdbfdd24..f331758bb 100644 --- a/pkg/dialects/common/enum_utm_data_avail_flags.go +++ b/pkg/dialects/common/enum_utm_data_avail_flags.go @@ -40,12 +40,24 @@ var labels_UTM_DATA_AVAIL_FLAGS = map[UTM_DATA_AVAIL_FLAGS]string{ UTM_DATA_AVAIL_FLAGS_NEXT_WAYPOINT_AVAILABLE: "UTM_DATA_AVAIL_FLAGS_NEXT_WAYPOINT_AVAILABLE", } +var values_UTM_DATA_AVAIL_FLAGS = map[string]UTM_DATA_AVAIL_FLAGS{ + "UTM_DATA_AVAIL_FLAGS_TIME_VALID": UTM_DATA_AVAIL_FLAGS_TIME_VALID, + "UTM_DATA_AVAIL_FLAGS_UAS_ID_AVAILABLE": UTM_DATA_AVAIL_FLAGS_UAS_ID_AVAILABLE, + "UTM_DATA_AVAIL_FLAGS_POSITION_AVAILABLE": UTM_DATA_AVAIL_FLAGS_POSITION_AVAILABLE, + "UTM_DATA_AVAIL_FLAGS_ALTITUDE_AVAILABLE": UTM_DATA_AVAIL_FLAGS_ALTITUDE_AVAILABLE, + "UTM_DATA_AVAIL_FLAGS_RELATIVE_ALTITUDE_AVAILABLE": UTM_DATA_AVAIL_FLAGS_RELATIVE_ALTITUDE_AVAILABLE, + "UTM_DATA_AVAIL_FLAGS_HORIZONTAL_VELO_AVAILABLE": UTM_DATA_AVAIL_FLAGS_HORIZONTAL_VELO_AVAILABLE, + "UTM_DATA_AVAIL_FLAGS_VERTICAL_VELO_AVAILABLE": UTM_DATA_AVAIL_FLAGS_VERTICAL_VELO_AVAILABLE, + "UTM_DATA_AVAIL_FLAGS_NEXT_WAYPOINT_AVAILABLE": UTM_DATA_AVAIL_FLAGS_NEXT_WAYPOINT_AVAILABLE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UTM_DATA_AVAIL_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_UTM_DATA_AVAIL_FLAGS { + for i := 0; i < 8; i++ { + mask := UTM_DATA_AVAIL_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_UTM_DATA_AVAIL_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -56,19 +68,12 @@ func (e *UTM_DATA_AVAIL_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask UTM_DATA_AVAIL_FLAGS for _, label := range labels { - found := false - for value, l := range labels_UTM_DATA_AVAIL_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_UTM_DATA_AVAIL_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_utm_flight_state.go b/pkg/dialects/common/enum_utm_flight_state.go index 2ccbdccc5..a6a14f95b 100644 --- a/pkg/dialects/common/enum_utm_flight_state.go +++ b/pkg/dialects/common/enum_utm_flight_state.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Airborne status of UAS. @@ -31,40 +31,38 @@ var labels_UTM_FLIGHT_STATE = map[UTM_FLIGHT_STATE]string{ UTM_FLIGHT_STATE_NOCTRL: "UTM_FLIGHT_STATE_NOCTRL", } +var values_UTM_FLIGHT_STATE = map[string]UTM_FLIGHT_STATE{ + "UTM_FLIGHT_STATE_UNKNOWN": UTM_FLIGHT_STATE_UNKNOWN, + "UTM_FLIGHT_STATE_GROUND": UTM_FLIGHT_STATE_GROUND, + "UTM_FLIGHT_STATE_AIRBORNE": UTM_FLIGHT_STATE_AIRBORNE, + "UTM_FLIGHT_STATE_EMERGENCY": UTM_FLIGHT_STATE_EMERGENCY, + "UTM_FLIGHT_STATE_NOCTRL": UTM_FLIGHT_STATE_NOCTRL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UTM_FLIGHT_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UTM_FLIGHT_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UTM_FLIGHT_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UTM_FLIGHT_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UTM_FLIGHT_STATE - for _, label := range labels { - found := false - for value, l := range labels_UTM_FLIGHT_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UTM_FLIGHT_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UTM_FLIGHT_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UTM_FLIGHT_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_video_stream_status_flags.go b/pkg/dialects/common/enum_video_stream_status_flags.go index 06ecc3029..50d9e28e4 100644 --- a/pkg/dialects/common/enum_video_stream_status_flags.go +++ b/pkg/dialects/common/enum_video_stream_status_flags.go @@ -22,12 +22,18 @@ var labels_VIDEO_STREAM_STATUS_FLAGS = map[VIDEO_STREAM_STATUS_FLAGS]string{ VIDEO_STREAM_STATUS_FLAGS_THERMAL: "VIDEO_STREAM_STATUS_FLAGS_THERMAL", } +var values_VIDEO_STREAM_STATUS_FLAGS = map[string]VIDEO_STREAM_STATUS_FLAGS{ + "VIDEO_STREAM_STATUS_FLAGS_RUNNING": VIDEO_STREAM_STATUS_FLAGS_RUNNING, + "VIDEO_STREAM_STATUS_FLAGS_THERMAL": VIDEO_STREAM_STATUS_FLAGS_THERMAL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e VIDEO_STREAM_STATUS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_VIDEO_STREAM_STATUS_FLAGS { + for i := 0; i < 2; i++ { + mask := VIDEO_STREAM_STATUS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_VIDEO_STREAM_STATUS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -38,19 +44,12 @@ func (e *VIDEO_STREAM_STATUS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask VIDEO_STREAM_STATUS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_VIDEO_STREAM_STATUS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_VIDEO_STREAM_STATUS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/common/enum_video_stream_type.go b/pkg/dialects/common/enum_video_stream_type.go index 5ca5046d5..5a3530274 100644 --- a/pkg/dialects/common/enum_video_stream_type.go +++ b/pkg/dialects/common/enum_video_stream_type.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Video stream types @@ -28,40 +28,37 @@ var labels_VIDEO_STREAM_TYPE = map[VIDEO_STREAM_TYPE]string{ VIDEO_STREAM_TYPE_MPEG_TS_H264: "VIDEO_STREAM_TYPE_MPEG_TS_H264", } +var values_VIDEO_STREAM_TYPE = map[string]VIDEO_STREAM_TYPE{ + "VIDEO_STREAM_TYPE_RTSP": VIDEO_STREAM_TYPE_RTSP, + "VIDEO_STREAM_TYPE_RTPUDP": VIDEO_STREAM_TYPE_RTPUDP, + "VIDEO_STREAM_TYPE_TCP_MPEG": VIDEO_STREAM_TYPE_TCP_MPEG, + "VIDEO_STREAM_TYPE_MPEG_TS_H264": VIDEO_STREAM_TYPE_MPEG_TS_H264, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e VIDEO_STREAM_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_VIDEO_STREAM_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_VIDEO_STREAM_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *VIDEO_STREAM_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask VIDEO_STREAM_TYPE - for _, label := range labels { - found := false - for value, l := range labels_VIDEO_STREAM_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_VIDEO_STREAM_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e VIDEO_STREAM_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_VIDEO_STREAM_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_vtol_transition_heading.go b/pkg/dialects/common/enum_vtol_transition_heading.go index e2da47b50..1beccb51b 100644 --- a/pkg/dialects/common/enum_vtol_transition_heading.go +++ b/pkg/dialects/common/enum_vtol_transition_heading.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Direction of VTOL transition @@ -31,40 +31,38 @@ var labels_VTOL_TRANSITION_HEADING = map[VTOL_TRANSITION_HEADING]string{ VTOL_TRANSITION_HEADING_ANY: "VTOL_TRANSITION_HEADING_ANY", } +var values_VTOL_TRANSITION_HEADING = map[string]VTOL_TRANSITION_HEADING{ + "VTOL_TRANSITION_HEADING_VEHICLE_DEFAULT": VTOL_TRANSITION_HEADING_VEHICLE_DEFAULT, + "VTOL_TRANSITION_HEADING_NEXT_WAYPOINT": VTOL_TRANSITION_HEADING_NEXT_WAYPOINT, + "VTOL_TRANSITION_HEADING_TAKEOFF": VTOL_TRANSITION_HEADING_TAKEOFF, + "VTOL_TRANSITION_HEADING_SPECIFIED": VTOL_TRANSITION_HEADING_SPECIFIED, + "VTOL_TRANSITION_HEADING_ANY": VTOL_TRANSITION_HEADING_ANY, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e VTOL_TRANSITION_HEADING) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_VTOL_TRANSITION_HEADING { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_VTOL_TRANSITION_HEADING[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *VTOL_TRANSITION_HEADING) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask VTOL_TRANSITION_HEADING - for _, label := range labels { - found := false - for value, l := range labels_VTOL_TRANSITION_HEADING { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_VTOL_TRANSITION_HEADING[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e VTOL_TRANSITION_HEADING) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_VTOL_TRANSITION_HEADING[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_wifi_config_ap_mode.go b/pkg/dialects/common/enum_wifi_config_ap_mode.go index 1f9bd4fb8..f6876935b 100644 --- a/pkg/dialects/common/enum_wifi_config_ap_mode.go +++ b/pkg/dialects/common/enum_wifi_config_ap_mode.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // WiFi Mode. @@ -28,40 +28,37 @@ var labels_WIFI_CONFIG_AP_MODE = map[WIFI_CONFIG_AP_MODE]string{ WIFI_CONFIG_AP_MODE_DISABLED: "WIFI_CONFIG_AP_MODE_DISABLED", } +var values_WIFI_CONFIG_AP_MODE = map[string]WIFI_CONFIG_AP_MODE{ + "WIFI_CONFIG_AP_MODE_UNDEFINED": WIFI_CONFIG_AP_MODE_UNDEFINED, + "WIFI_CONFIG_AP_MODE_AP": WIFI_CONFIG_AP_MODE_AP, + "WIFI_CONFIG_AP_MODE_STATION": WIFI_CONFIG_AP_MODE_STATION, + "WIFI_CONFIG_AP_MODE_DISABLED": WIFI_CONFIG_AP_MODE_DISABLED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e WIFI_CONFIG_AP_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_WIFI_CONFIG_AP_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_WIFI_CONFIG_AP_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *WIFI_CONFIG_AP_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask WIFI_CONFIG_AP_MODE - for _, label := range labels { - found := false - for value, l := range labels_WIFI_CONFIG_AP_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_WIFI_CONFIG_AP_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e WIFI_CONFIG_AP_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_WIFI_CONFIG_AP_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_wifi_config_ap_response.go b/pkg/dialects/common/enum_wifi_config_ap_response.go index d31659202..0b737e8e3 100644 --- a/pkg/dialects/common/enum_wifi_config_ap_response.go +++ b/pkg/dialects/common/enum_wifi_config_ap_response.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Possible responses from a WIFI_CONFIG_AP message. @@ -34,40 +34,39 @@ var labels_WIFI_CONFIG_AP_RESPONSE = map[WIFI_CONFIG_AP_RESPONSE]string{ WIFI_CONFIG_AP_RESPONSE_PASSWORD_ERROR: "WIFI_CONFIG_AP_RESPONSE_PASSWORD_ERROR", } +var values_WIFI_CONFIG_AP_RESPONSE = map[string]WIFI_CONFIG_AP_RESPONSE{ + "WIFI_CONFIG_AP_RESPONSE_UNDEFINED": WIFI_CONFIG_AP_RESPONSE_UNDEFINED, + "WIFI_CONFIG_AP_RESPONSE_ACCEPTED": WIFI_CONFIG_AP_RESPONSE_ACCEPTED, + "WIFI_CONFIG_AP_RESPONSE_REJECTED": WIFI_CONFIG_AP_RESPONSE_REJECTED, + "WIFI_CONFIG_AP_RESPONSE_MODE_ERROR": WIFI_CONFIG_AP_RESPONSE_MODE_ERROR, + "WIFI_CONFIG_AP_RESPONSE_SSID_ERROR": WIFI_CONFIG_AP_RESPONSE_SSID_ERROR, + "WIFI_CONFIG_AP_RESPONSE_PASSWORD_ERROR": WIFI_CONFIG_AP_RESPONSE_PASSWORD_ERROR, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e WIFI_CONFIG_AP_RESPONSE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_WIFI_CONFIG_AP_RESPONSE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_WIFI_CONFIG_AP_RESPONSE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *WIFI_CONFIG_AP_RESPONSE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask WIFI_CONFIG_AP_RESPONSE - for _, label := range labels { - found := false - for value, l := range labels_WIFI_CONFIG_AP_RESPONSE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_WIFI_CONFIG_AP_RESPONSE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e WIFI_CONFIG_AP_RESPONSE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_WIFI_CONFIG_AP_RESPONSE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/common/enum_winch_actions.go b/pkg/dialects/common/enum_winch_actions.go index 41a2ccfbc..2771f6f57 100644 --- a/pkg/dialects/common/enum_winch_actions.go +++ b/pkg/dialects/common/enum_winch_actions.go @@ -4,7 +4,7 @@ package common import ( "fmt" - "strings" + "strconv" ) // Winch actions. @@ -46,40 +46,43 @@ var labels_WINCH_ACTIONS = map[WINCH_ACTIONS]string{ WINCH_LOAD_PAYLOAD: "WINCH_LOAD_PAYLOAD", } +var values_WINCH_ACTIONS = map[string]WINCH_ACTIONS{ + "WINCH_RELAXED": WINCH_RELAXED, + "WINCH_RELATIVE_LENGTH_CONTROL": WINCH_RELATIVE_LENGTH_CONTROL, + "WINCH_RATE_CONTROL": WINCH_RATE_CONTROL, + "WINCH_LOCK": WINCH_LOCK, + "WINCH_DELIVER": WINCH_DELIVER, + "WINCH_HOLD": WINCH_HOLD, + "WINCH_RETRACT": WINCH_RETRACT, + "WINCH_LOAD_LINE": WINCH_LOAD_LINE, + "WINCH_ABANDON_LINE": WINCH_ABANDON_LINE, + "WINCH_LOAD_PAYLOAD": WINCH_LOAD_PAYLOAD, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e WINCH_ACTIONS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_WINCH_ACTIONS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_WINCH_ACTIONS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *WINCH_ACTIONS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask WINCH_ACTIONS - for _, label := range labels { - found := false - for value, l := range labels_WINCH_ACTIONS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_WINCH_ACTIONS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e WINCH_ACTIONS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_WINCH_ACTIONS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/csairlink/enum_airlink_auth_response_type.go b/pkg/dialects/csairlink/enum_airlink_auth_response_type.go index 1cf06e9da..9cf59778a 100644 --- a/pkg/dialects/csairlink/enum_airlink_auth_response_type.go +++ b/pkg/dialects/csairlink/enum_airlink_auth_response_type.go @@ -4,7 +4,7 @@ package csairlink import ( "fmt" - "strings" + "strconv" ) type AIRLINK_AUTH_RESPONSE_TYPE uint32 @@ -21,40 +21,35 @@ var labels_AIRLINK_AUTH_RESPONSE_TYPE = map[AIRLINK_AUTH_RESPONSE_TYPE]string{ AIRLINK_AUTH_OK: "AIRLINK_AUTH_OK", } +var values_AIRLINK_AUTH_RESPONSE_TYPE = map[string]AIRLINK_AUTH_RESPONSE_TYPE{ + "AIRLINK_ERROR_LOGIN_OR_PASS": AIRLINK_ERROR_LOGIN_OR_PASS, + "AIRLINK_AUTH_OK": AIRLINK_AUTH_OK, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AIRLINK_AUTH_RESPONSE_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_AIRLINK_AUTH_RESPONSE_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_AIRLINK_AUTH_RESPONSE_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *AIRLINK_AUTH_RESPONSE_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask AIRLINK_AUTH_RESPONSE_TYPE - for _, label := range labels { - found := false - for value, l := range labels_AIRLINK_AUTH_RESPONSE_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_AIRLINK_AUTH_RESPONSE_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e AIRLINK_AUTH_RESPONSE_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_AIRLINK_AUTH_RESPONSE_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/development/enum_airspeed_sensor_flags.go b/pkg/dialects/development/enum_airspeed_sensor_flags.go index 16a8a918d..e93029de8 100644 --- a/pkg/dialects/development/enum_airspeed_sensor_flags.go +++ b/pkg/dialects/development/enum_airspeed_sensor_flags.go @@ -22,12 +22,18 @@ var labels_AIRSPEED_SENSOR_FLAGS = map[AIRSPEED_SENSOR_FLAGS]string{ AIRSPEED_SENSOR_USING: "AIRSPEED_SENSOR_USING", } +var values_AIRSPEED_SENSOR_FLAGS = map[string]AIRSPEED_SENSOR_FLAGS{ + "AIRSPEED_SENSOR_UNHEALTHY": AIRSPEED_SENSOR_UNHEALTHY, + "AIRSPEED_SENSOR_USING": AIRSPEED_SENSOR_USING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e AIRSPEED_SENSOR_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_AIRSPEED_SENSOR_FLAGS { + for i := 0; i < 2; i++ { + mask := AIRSPEED_SENSOR_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_AIRSPEED_SENSOR_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -38,19 +44,12 @@ func (e *AIRSPEED_SENSOR_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask AIRSPEED_SENSOR_FLAGS for _, label := range labels { - found := false - for value, l := range labels_AIRSPEED_SENSOR_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_AIRSPEED_SENSOR_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/development/enum_mav_battery_status_flags.go b/pkg/dialects/development/enum_mav_battery_status_flags.go index d9a9f7f29..8c9466cd7 100644 --- a/pkg/dialects/development/enum_mav_battery_status_flags.go +++ b/pkg/dialects/development/enum_mav_battery_status_flags.go @@ -95,12 +95,36 @@ var labels_MAV_BATTERY_STATUS_FLAGS = map[MAV_BATTERY_STATUS_FLAGS]string{ MAV_BATTERY_STATUS_FLAGS_EXTENDED: "MAV_BATTERY_STATUS_FLAGS_EXTENDED", } +var values_MAV_BATTERY_STATUS_FLAGS = map[string]MAV_BATTERY_STATUS_FLAGS{ + "MAV_BATTERY_STATUS_FLAGS_NOT_READY_TO_USE": MAV_BATTERY_STATUS_FLAGS_NOT_READY_TO_USE, + "MAV_BATTERY_STATUS_FLAGS_CHARGING": MAV_BATTERY_STATUS_FLAGS_CHARGING, + "MAV_BATTERY_STATUS_FLAGS_CELL_BALANCING": MAV_BATTERY_STATUS_FLAGS_CELL_BALANCING, + "MAV_BATTERY_STATUS_FLAGS_FAULT_CELL_IMBALANCE": MAV_BATTERY_STATUS_FLAGS_FAULT_CELL_IMBALANCE, + "MAV_BATTERY_STATUS_FLAGS_AUTO_DISCHARGING": MAV_BATTERY_STATUS_FLAGS_AUTO_DISCHARGING, + "MAV_BATTERY_STATUS_FLAGS_REQUIRES_SERVICE": MAV_BATTERY_STATUS_FLAGS_REQUIRES_SERVICE, + "MAV_BATTERY_STATUS_FLAGS_BAD_BATTERY": MAV_BATTERY_STATUS_FLAGS_BAD_BATTERY, + "MAV_BATTERY_STATUS_FLAGS_PROTECTIONS_ENABLED": MAV_BATTERY_STATUS_FLAGS_PROTECTIONS_ENABLED, + "MAV_BATTERY_STATUS_FLAGS_FAULT_PROTECTION_SYSTEM": MAV_BATTERY_STATUS_FLAGS_FAULT_PROTECTION_SYSTEM, + "MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_VOLT": MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_VOLT, + "MAV_BATTERY_STATUS_FLAGS_FAULT_UNDER_VOLT": MAV_BATTERY_STATUS_FLAGS_FAULT_UNDER_VOLT, + "MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_TEMPERATURE": MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_TEMPERATURE, + "MAV_BATTERY_STATUS_FLAGS_FAULT_UNDER_TEMPERATURE": MAV_BATTERY_STATUS_FLAGS_FAULT_UNDER_TEMPERATURE, + "MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_CURRENT": MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_CURRENT, + "MAV_BATTERY_STATUS_FLAGS_FAULT_SHORT_CIRCUIT": MAV_BATTERY_STATUS_FLAGS_FAULT_SHORT_CIRCUIT, + "MAV_BATTERY_STATUS_FLAGS_FAULT_INCOMPATIBLE_VOLTAGE": MAV_BATTERY_STATUS_FLAGS_FAULT_INCOMPATIBLE_VOLTAGE, + "MAV_BATTERY_STATUS_FLAGS_FAULT_INCOMPATIBLE_FIRMWARE": MAV_BATTERY_STATUS_FLAGS_FAULT_INCOMPATIBLE_FIRMWARE, + "MAV_BATTERY_STATUS_FLAGS_FAULT_INCOMPATIBLE_CELLS_CONFIGURATION": MAV_BATTERY_STATUS_FLAGS_FAULT_INCOMPATIBLE_CELLS_CONFIGURATION, + "MAV_BATTERY_STATUS_FLAGS_CAPACITY_RELATIVE_TO_FULL": MAV_BATTERY_STATUS_FLAGS_CAPACITY_RELATIVE_TO_FULL, + "MAV_BATTERY_STATUS_FLAGS_EXTENDED": MAV_BATTERY_STATUS_FLAGS_EXTENDED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_BATTERY_STATUS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_BATTERY_STATUS_FLAGS { + for i := 0; i < 20; i++ { + mask := MAV_BATTERY_STATUS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_BATTERY_STATUS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -111,19 +135,12 @@ func (e *MAV_BATTERY_STATUS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_BATTERY_STATUS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_MAV_BATTERY_STATUS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_BATTERY_STATUS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/development/enum_mav_cmd.go b/pkg/dialects/development/enum_mav_cmd.go index c8f7153ba..cda99e721 100644 --- a/pkg/dialects/development/enum_mav_cmd.go +++ b/pkg/dialects/development/enum_mav_cmd.go @@ -4,7 +4,7 @@ package development import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -585,40 +585,200 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_SET_AT_S_PARAM: "MAV_CMD_SET_AT_S_PARAM", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_DO_FIGURE_EIGHT": MAV_CMD_DO_FIGURE_EIGHT, + "MAV_CMD_PARAM_TRANSACTION": MAV_CMD_PARAM_TRANSACTION, + "MAV_CMD_SET_FENCE_BREACH_ACTION": MAV_CMD_SET_FENCE_BREACH_ACTION, + "MAV_CMD_DO_UPGRADE": MAV_CMD_DO_UPGRADE, + "MAV_CMD_GROUP_START": MAV_CMD_GROUP_START, + "MAV_CMD_GROUP_END": MAV_CMD_GROUP_END, + "MAV_CMD_DO_SET_STANDARD_MODE": MAV_CMD_DO_SET_STANDARD_MODE, + "MAV_CMD_SET_AT_S_PARAM": MAV_CMD_SET_AT_S_PARAM, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/development/enum_mav_mode_property.go b/pkg/dialects/development/enum_mav_mode_property.go index 6eb9cf208..4be3ffb7f 100644 --- a/pkg/dialects/development/enum_mav_mode_property.go +++ b/pkg/dialects/development/enum_mav_mode_property.go @@ -25,12 +25,18 @@ var labels_MAV_MODE_PROPERTY = map[MAV_MODE_PROPERTY]string{ MAV_MODE_PROPERTY_NOT_USER_SELECTABLE: "MAV_MODE_PROPERTY_NOT_USER_SELECTABLE", } +var values_MAV_MODE_PROPERTY = map[string]MAV_MODE_PROPERTY{ + "MAV_MODE_PROPERTY_ADVANCED": MAV_MODE_PROPERTY_ADVANCED, + "MAV_MODE_PROPERTY_NOT_USER_SELECTABLE": MAV_MODE_PROPERTY_NOT_USER_SELECTABLE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_MODE_PROPERTY) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_MODE_PROPERTY { + for i := 0; i < 2; i++ { + mask := MAV_MODE_PROPERTY(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_MODE_PROPERTY[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -41,19 +47,12 @@ func (e *MAV_MODE_PROPERTY) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_MODE_PROPERTY for _, label := range labels { - found := false - for value, l := range labels_MAV_MODE_PROPERTY { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_MODE_PROPERTY[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/development/enum_mav_standard_mode.go b/pkg/dialects/development/enum_mav_standard_mode.go index f038bff4c..0ef2bd8fb 100644 --- a/pkg/dialects/development/enum_mav_standard_mode.go +++ b/pkg/dialects/development/enum_mav_standard_mode.go @@ -4,7 +4,7 @@ package development import ( "fmt" - "strings" + "strconv" ) // Standard modes with a well understood meaning across flight stacks and vehicle types. @@ -87,40 +87,43 @@ var labels_MAV_STANDARD_MODE = map[MAV_STANDARD_MODE]string{ MAV_STANDARD_MODE_TAKEOFF: "MAV_STANDARD_MODE_TAKEOFF", } +var values_MAV_STANDARD_MODE = map[string]MAV_STANDARD_MODE{ + "MAV_STANDARD_MODE_NON_STANDARD": MAV_STANDARD_MODE_NON_STANDARD, + "MAV_STANDARD_MODE_POSITION_HOLD": MAV_STANDARD_MODE_POSITION_HOLD, + "MAV_STANDARD_MODE_ORBIT": MAV_STANDARD_MODE_ORBIT, + "MAV_STANDARD_MODE_CRUISE": MAV_STANDARD_MODE_CRUISE, + "MAV_STANDARD_MODE_ALTITUDE_HOLD": MAV_STANDARD_MODE_ALTITUDE_HOLD, + "MAV_STANDARD_MODE_RETURN_HOME": MAV_STANDARD_MODE_RETURN_HOME, + "MAV_STANDARD_MODE_SAFE_RECOVERY": MAV_STANDARD_MODE_SAFE_RECOVERY, + "MAV_STANDARD_MODE_MISSION": MAV_STANDARD_MODE_MISSION, + "MAV_STANDARD_MODE_LAND": MAV_STANDARD_MODE_LAND, + "MAV_STANDARD_MODE_TAKEOFF": MAV_STANDARD_MODE_TAKEOFF, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STANDARD_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_STANDARD_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_STANDARD_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_STANDARD_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_STANDARD_MODE - for _, label := range labels { - found := false - for value, l := range labels_MAV_STANDARD_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_STANDARD_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_STANDARD_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_STANDARD_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/development/enum_param_transaction_action.go b/pkg/dialects/development/enum_param_transaction_action.go index 659569a1d..5c4cec360 100644 --- a/pkg/dialects/development/enum_param_transaction_action.go +++ b/pkg/dialects/development/enum_param_transaction_action.go @@ -4,7 +4,7 @@ package development import ( "fmt" - "strings" + "strconv" ) // Possible parameter transaction actions. @@ -25,40 +25,36 @@ var labels_PARAM_TRANSACTION_ACTION = map[PARAM_TRANSACTION_ACTION]string{ PARAM_TRANSACTION_ACTION_CANCEL: "PARAM_TRANSACTION_ACTION_CANCEL", } +var values_PARAM_TRANSACTION_ACTION = map[string]PARAM_TRANSACTION_ACTION{ + "PARAM_TRANSACTION_ACTION_START": PARAM_TRANSACTION_ACTION_START, + "PARAM_TRANSACTION_ACTION_COMMIT": PARAM_TRANSACTION_ACTION_COMMIT, + "PARAM_TRANSACTION_ACTION_CANCEL": PARAM_TRANSACTION_ACTION_CANCEL, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PARAM_TRANSACTION_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PARAM_TRANSACTION_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PARAM_TRANSACTION_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PARAM_TRANSACTION_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PARAM_TRANSACTION_ACTION - for _, label := range labels { - found := false - for value, l := range labels_PARAM_TRANSACTION_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PARAM_TRANSACTION_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PARAM_TRANSACTION_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PARAM_TRANSACTION_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/development/enum_param_transaction_transport.go b/pkg/dialects/development/enum_param_transaction_transport.go index a9020e833..b4a3270f7 100644 --- a/pkg/dialects/development/enum_param_transaction_transport.go +++ b/pkg/dialects/development/enum_param_transaction_transport.go @@ -4,7 +4,7 @@ package development import ( "fmt" - "strings" + "strconv" ) // Possible transport layers to set and get parameters via mavlink during a parameter transaction. @@ -22,40 +22,35 @@ var labels_PARAM_TRANSACTION_TRANSPORT = map[PARAM_TRANSACTION_TRANSPORT]string{ PARAM_TRANSACTION_TRANSPORT_PARAM_EXT: "PARAM_TRANSACTION_TRANSPORT_PARAM_EXT", } +var values_PARAM_TRANSACTION_TRANSPORT = map[string]PARAM_TRANSACTION_TRANSPORT{ + "PARAM_TRANSACTION_TRANSPORT_PARAM": PARAM_TRANSACTION_TRANSPORT_PARAM, + "PARAM_TRANSACTION_TRANSPORT_PARAM_EXT": PARAM_TRANSACTION_TRANSPORT_PARAM_EXT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e PARAM_TRANSACTION_TRANSPORT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_PARAM_TRANSACTION_TRANSPORT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_PARAM_TRANSACTION_TRANSPORT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *PARAM_TRANSACTION_TRANSPORT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask PARAM_TRANSACTION_TRANSPORT - for _, label := range labels { - found := false - for value, l := range labels_PARAM_TRANSACTION_TRANSPORT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_PARAM_TRANSACTION_TRANSPORT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e PARAM_TRANSACTION_TRANSPORT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_PARAM_TRANSACTION_TRANSPORT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/development/enum_target_absolute_sensor_capability_flags.go b/pkg/dialects/development/enum_target_absolute_sensor_capability_flags.go index 634f7a563..dbf4cd854 100644 --- a/pkg/dialects/development/enum_target_absolute_sensor_capability_flags.go +++ b/pkg/dialects/development/enum_target_absolute_sensor_capability_flags.go @@ -26,12 +26,21 @@ var labels_TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS = map[TARGET_ABSOLUTE_SENSOR_ TARGET_ABSOLUTE_SENSOR_CAPABILITY_RATES: "TARGET_ABSOLUTE_SENSOR_CAPABILITY_RATES", } +var values_TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS = map[string]TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS{ + "TARGET_ABSOLUTE_SENSOR_CAPABILITY_POSITION": TARGET_ABSOLUTE_SENSOR_CAPABILITY_POSITION, + "TARGET_ABSOLUTE_SENSOR_CAPABILITY_VELOCITY": TARGET_ABSOLUTE_SENSOR_CAPABILITY_VELOCITY, + "TARGET_ABSOLUTE_SENSOR_CAPABILITY_ACCELERATION": TARGET_ABSOLUTE_SENSOR_CAPABILITY_ACCELERATION, + "TARGET_ABSOLUTE_SENSOR_CAPABILITY_ATTITUDE": TARGET_ABSOLUTE_SENSOR_CAPABILITY_ATTITUDE, + "TARGET_ABSOLUTE_SENSOR_CAPABILITY_RATES": TARGET_ABSOLUTE_SENSOR_CAPABILITY_RATES, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS { + for i := 0; i < 5; i++ { + mask := TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -42,19 +51,12 @@ func (e *TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS) UnmarshalText(text []byte) err labels := strings.Split(string(text), " | ") var mask TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS for _, label := range labels { - found := false - for value, l := range labels_TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_TARGET_ABSOLUTE_SENSOR_CAPABILITY_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/development/enum_target_obs_frame.go b/pkg/dialects/development/enum_target_obs_frame.go index ffff01c21..9fbbbd7fc 100644 --- a/pkg/dialects/development/enum_target_obs_frame.go +++ b/pkg/dialects/development/enum_target_obs_frame.go @@ -4,7 +4,7 @@ package development import ( "fmt" - "strings" + "strconv" ) // The frame of a target observation from an onboard sensor. @@ -28,40 +28,37 @@ var labels_TARGET_OBS_FRAME = map[TARGET_OBS_FRAME]string{ TARGET_OBS_FRAME_OTHER: "TARGET_OBS_FRAME_OTHER", } +var values_TARGET_OBS_FRAME = map[string]TARGET_OBS_FRAME{ + "TARGET_OBS_FRAME_LOCAL_NED": TARGET_OBS_FRAME_LOCAL_NED, + "TARGET_OBS_FRAME_BODY_FRD": TARGET_OBS_FRAME_BODY_FRD, + "TARGET_OBS_FRAME_LOCAL_OFFSET_NED": TARGET_OBS_FRAME_LOCAL_OFFSET_NED, + "TARGET_OBS_FRAME_OTHER": TARGET_OBS_FRAME_OTHER, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e TARGET_OBS_FRAME) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_TARGET_OBS_FRAME { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_TARGET_OBS_FRAME[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *TARGET_OBS_FRAME) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask TARGET_OBS_FRAME - for _, label := range labels { - found := false - for value, l := range labels_TARGET_OBS_FRAME { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_TARGET_OBS_FRAME[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e TARGET_OBS_FRAME) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_TARGET_OBS_FRAME[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/development/enum_wifi_network_security.go b/pkg/dialects/development/enum_wifi_network_security.go index 44024105e..b15e707c4 100644 --- a/pkg/dialects/development/enum_wifi_network_security.go +++ b/pkg/dialects/development/enum_wifi_network_security.go @@ -4,7 +4,7 @@ package development import ( "fmt" - "strings" + "strconv" ) // WiFi wireless security protocols. @@ -34,40 +34,39 @@ var labels_WIFI_NETWORK_SECURITY = map[WIFI_NETWORK_SECURITY]string{ WIFI_NETWORK_SECURITY_WPA3: "WIFI_NETWORK_SECURITY_WPA3", } +var values_WIFI_NETWORK_SECURITY = map[string]WIFI_NETWORK_SECURITY{ + "WIFI_NETWORK_SECURITY_UNDEFINED": WIFI_NETWORK_SECURITY_UNDEFINED, + "WIFI_NETWORK_SECURITY_OPEN": WIFI_NETWORK_SECURITY_OPEN, + "WIFI_NETWORK_SECURITY_WEP": WIFI_NETWORK_SECURITY_WEP, + "WIFI_NETWORK_SECURITY_WPA1": WIFI_NETWORK_SECURITY_WPA1, + "WIFI_NETWORK_SECURITY_WPA2": WIFI_NETWORK_SECURITY_WPA2, + "WIFI_NETWORK_SECURITY_WPA3": WIFI_NETWORK_SECURITY_WPA3, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e WIFI_NETWORK_SECURITY) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_WIFI_NETWORK_SECURITY { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_WIFI_NETWORK_SECURITY[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *WIFI_NETWORK_SECURITY) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask WIFI_NETWORK_SECURITY - for _, label := range labels { - found := false - for value, l := range labels_WIFI_NETWORK_SECURITY { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_WIFI_NETWORK_SECURITY[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e WIFI_NETWORK_SECURITY) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_WIFI_NETWORK_SECURITY[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/icarous/enum_icarous_fms_state.go b/pkg/dialects/icarous/enum_icarous_fms_state.go index cb005502f..434c2afe5 100644 --- a/pkg/dialects/icarous/enum_icarous_fms_state.go +++ b/pkg/dialects/icarous/enum_icarous_fms_state.go @@ -4,7 +4,7 @@ package icarous import ( "fmt" - "strings" + "strconv" ) type ICAROUS_FMS_STATE uint32 @@ -27,40 +27,39 @@ var labels_ICAROUS_FMS_STATE = map[ICAROUS_FMS_STATE]string{ ICAROUS_FMS_STATE_LAND: "ICAROUS_FMS_STATE_LAND", } +var values_ICAROUS_FMS_STATE = map[string]ICAROUS_FMS_STATE{ + "ICAROUS_FMS_STATE_IDLE": ICAROUS_FMS_STATE_IDLE, + "ICAROUS_FMS_STATE_TAKEOFF": ICAROUS_FMS_STATE_TAKEOFF, + "ICAROUS_FMS_STATE_CLIMB": ICAROUS_FMS_STATE_CLIMB, + "ICAROUS_FMS_STATE_CRUISE": ICAROUS_FMS_STATE_CRUISE, + "ICAROUS_FMS_STATE_APPROACH": ICAROUS_FMS_STATE_APPROACH, + "ICAROUS_FMS_STATE_LAND": ICAROUS_FMS_STATE_LAND, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ICAROUS_FMS_STATE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ICAROUS_FMS_STATE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ICAROUS_FMS_STATE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ICAROUS_FMS_STATE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ICAROUS_FMS_STATE - for _, label := range labels { - found := false - for value, l := range labels_ICAROUS_FMS_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ICAROUS_FMS_STATE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ICAROUS_FMS_STATE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ICAROUS_FMS_STATE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/icarous/enum_icarous_track_band_types.go b/pkg/dialects/icarous/enum_icarous_track_band_types.go index eac27ddf9..eeca05fa5 100644 --- a/pkg/dialects/icarous/enum_icarous_track_band_types.go +++ b/pkg/dialects/icarous/enum_icarous_track_band_types.go @@ -4,7 +4,7 @@ package icarous import ( "fmt" - "strings" + "strconv" ) type ICAROUS_TRACK_BAND_TYPES uint32 @@ -21,40 +21,36 @@ var labels_ICAROUS_TRACK_BAND_TYPES = map[ICAROUS_TRACK_BAND_TYPES]string{ ICAROUS_TRACK_BAND_TYPE_RECOVERY: "ICAROUS_TRACK_BAND_TYPE_RECOVERY", } +var values_ICAROUS_TRACK_BAND_TYPES = map[string]ICAROUS_TRACK_BAND_TYPES{ + "ICAROUS_TRACK_BAND_TYPE_NONE": ICAROUS_TRACK_BAND_TYPE_NONE, + "ICAROUS_TRACK_BAND_TYPE_NEAR": ICAROUS_TRACK_BAND_TYPE_NEAR, + "ICAROUS_TRACK_BAND_TYPE_RECOVERY": ICAROUS_TRACK_BAND_TYPE_RECOVERY, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e ICAROUS_TRACK_BAND_TYPES) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_ICAROUS_TRACK_BAND_TYPES { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_ICAROUS_TRACK_BAND_TYPES[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *ICAROUS_TRACK_BAND_TYPES) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask ICAROUS_TRACK_BAND_TYPES - for _, label := range labels { - found := false - for value, l := range labels_ICAROUS_TRACK_BAND_TYPES { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_ICAROUS_TRACK_BAND_TYPES[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e ICAROUS_TRACK_BAND_TYPES) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_ICAROUS_TRACK_BAND_TYPES[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/matrixpilot/enum_mav_cmd.go b/pkg/dialects/matrixpilot/enum_mav_cmd.go index eabdc62d2..526feb086 100644 --- a/pkg/dialects/matrixpilot/enum_mav_cmd.go +++ b/pkg/dialects/matrixpilot/enum_mav_cmd.go @@ -4,7 +4,7 @@ package matrixpilot import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -545,40 +545,193 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_PREFLIGHT_STORAGE_ADVANCED: "MAV_CMD_PREFLIGHT_STORAGE_ADVANCED", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_PREFLIGHT_STORAGE_ADVANCED": MAV_CMD_PREFLIGHT_STORAGE_ADVANCED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/matrixpilot/enum_mav_preflight_storage_action.go b/pkg/dialects/matrixpilot/enum_mav_preflight_storage_action.go index 9a471bc10..ac828b4ad 100644 --- a/pkg/dialects/matrixpilot/enum_mav_preflight_storage_action.go +++ b/pkg/dialects/matrixpilot/enum_mav_preflight_storage_action.go @@ -4,7 +4,7 @@ package matrixpilot import ( "fmt" - "strings" + "strconv" ) // Action required when performing CMD_PREFLIGHT_STORAGE @@ -37,40 +37,40 @@ var labels_MAV_PREFLIGHT_STORAGE_ACTION = map[MAV_PREFLIGHT_STORAGE_ACTION]strin MAV_PFS_CMD_DO_NOTHING: "MAV_PFS_CMD_DO_NOTHING", } +var values_MAV_PREFLIGHT_STORAGE_ACTION = map[string]MAV_PREFLIGHT_STORAGE_ACTION{ + "MAV_PFS_CMD_READ_ALL": MAV_PFS_CMD_READ_ALL, + "MAV_PFS_CMD_WRITE_ALL": MAV_PFS_CMD_WRITE_ALL, + "MAV_PFS_CMD_CLEAR_ALL": MAV_PFS_CMD_CLEAR_ALL, + "MAV_PFS_CMD_READ_SPECIFIC": MAV_PFS_CMD_READ_SPECIFIC, + "MAV_PFS_CMD_WRITE_SPECIFIC": MAV_PFS_CMD_WRITE_SPECIFIC, + "MAV_PFS_CMD_CLEAR_SPECIFIC": MAV_PFS_CMD_CLEAR_SPECIFIC, + "MAV_PFS_CMD_DO_NOTHING": MAV_PFS_CMD_DO_NOTHING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_PREFLIGHT_STORAGE_ACTION) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_PREFLIGHT_STORAGE_ACTION { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_PREFLIGHT_STORAGE_ACTION[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_PREFLIGHT_STORAGE_ACTION) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_PREFLIGHT_STORAGE_ACTION - for _, label := range labels { - found := false - for value, l := range labels_MAV_PREFLIGHT_STORAGE_ACTION { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_PREFLIGHT_STORAGE_ACTION[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_PREFLIGHT_STORAGE_ACTION) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_PREFLIGHT_STORAGE_ACTION[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/storm32/enum_mav_cmd.go b/pkg/dialects/storm32/enum_mav_cmd.go index 4e4003ef5..e82a80464 100644 --- a/pkg/dialects/storm32/enum_mav_cmd.go +++ b/pkg/dialects/storm32/enum_mav_cmd.go @@ -4,7 +4,7 @@ package storm32 import ( "fmt" - "strings" + "strconv" ) // Commands to be executed by the MAV. They can be executed on user request, or as part of a mission script. If the action is used in a mission, the parameter mapping to the waypoint/mission message is as follows: Param 1, Param 2, Param 3, Param 4, X: Param 5, Y:Param 6, Z:Param 7. This command list is similar what ARINC 424 is for commercial aircraft: A data format how to interpret waypoint/mission data. NaN and INT32_MAX may be used in float/integer params (respectively) to indicate optional/default values (e.g. to use the component's current yaw or latitude rather than a specific value). See https://mavlink.io/en/guide/xml_schema.html#MAV_CMD for information about the structure of the MAV_CMD entries @@ -648,40 +648,227 @@ var labels_MAV_CMD = map[MAV_CMD]string{ MAV_CMD_QSHOT_DO_CONFIGURE: "MAV_CMD_QSHOT_DO_CONFIGURE", } +var values_MAV_CMD = map[string]MAV_CMD{ + "MAV_CMD_NAV_WAYPOINT": MAV_CMD_NAV_WAYPOINT, + "MAV_CMD_NAV_LOITER_UNLIM": MAV_CMD_NAV_LOITER_UNLIM, + "MAV_CMD_NAV_LOITER_TURNS": MAV_CMD_NAV_LOITER_TURNS, + "MAV_CMD_NAV_LOITER_TIME": MAV_CMD_NAV_LOITER_TIME, + "MAV_CMD_NAV_RETURN_TO_LAUNCH": MAV_CMD_NAV_RETURN_TO_LAUNCH, + "MAV_CMD_NAV_LAND": MAV_CMD_NAV_LAND, + "MAV_CMD_NAV_TAKEOFF": MAV_CMD_NAV_TAKEOFF, + "MAV_CMD_NAV_LAND_LOCAL": MAV_CMD_NAV_LAND_LOCAL, + "MAV_CMD_NAV_TAKEOFF_LOCAL": MAV_CMD_NAV_TAKEOFF_LOCAL, + "MAV_CMD_NAV_FOLLOW": MAV_CMD_NAV_FOLLOW, + "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT": MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, + "MAV_CMD_NAV_LOITER_TO_ALT": MAV_CMD_NAV_LOITER_TO_ALT, + "MAV_CMD_DO_FOLLOW": MAV_CMD_DO_FOLLOW, + "MAV_CMD_DO_FOLLOW_REPOSITION": MAV_CMD_DO_FOLLOW_REPOSITION, + "MAV_CMD_DO_ORBIT": MAV_CMD_DO_ORBIT, + "MAV_CMD_NAV_ROI": MAV_CMD_NAV_ROI, + "MAV_CMD_NAV_PATHPLANNING": MAV_CMD_NAV_PATHPLANNING, + "MAV_CMD_NAV_SPLINE_WAYPOINT": MAV_CMD_NAV_SPLINE_WAYPOINT, + "MAV_CMD_NAV_VTOL_TAKEOFF": MAV_CMD_NAV_VTOL_TAKEOFF, + "MAV_CMD_NAV_VTOL_LAND": MAV_CMD_NAV_VTOL_LAND, + "MAV_CMD_NAV_GUIDED_ENABLE": MAV_CMD_NAV_GUIDED_ENABLE, + "MAV_CMD_NAV_DELAY": MAV_CMD_NAV_DELAY, + "MAV_CMD_NAV_PAYLOAD_PLACE": MAV_CMD_NAV_PAYLOAD_PLACE, + "MAV_CMD_NAV_LAST": MAV_CMD_NAV_LAST, + "MAV_CMD_CONDITION_DELAY": MAV_CMD_CONDITION_DELAY, + "MAV_CMD_CONDITION_CHANGE_ALT": MAV_CMD_CONDITION_CHANGE_ALT, + "MAV_CMD_CONDITION_DISTANCE": MAV_CMD_CONDITION_DISTANCE, + "MAV_CMD_CONDITION_YAW": MAV_CMD_CONDITION_YAW, + "MAV_CMD_CONDITION_LAST": MAV_CMD_CONDITION_LAST, + "MAV_CMD_DO_SET_MODE": MAV_CMD_DO_SET_MODE, + "MAV_CMD_DO_JUMP": MAV_CMD_DO_JUMP, + "MAV_CMD_DO_CHANGE_SPEED": MAV_CMD_DO_CHANGE_SPEED, + "MAV_CMD_DO_SET_HOME": MAV_CMD_DO_SET_HOME, + "MAV_CMD_DO_SET_PARAMETER": MAV_CMD_DO_SET_PARAMETER, + "MAV_CMD_DO_SET_RELAY": MAV_CMD_DO_SET_RELAY, + "MAV_CMD_DO_REPEAT_RELAY": MAV_CMD_DO_REPEAT_RELAY, + "MAV_CMD_DO_SET_SERVO": MAV_CMD_DO_SET_SERVO, + "MAV_CMD_DO_REPEAT_SERVO": MAV_CMD_DO_REPEAT_SERVO, + "MAV_CMD_DO_FLIGHTTERMINATION": MAV_CMD_DO_FLIGHTTERMINATION, + "MAV_CMD_DO_CHANGE_ALTITUDE": MAV_CMD_DO_CHANGE_ALTITUDE, + "MAV_CMD_DO_SET_ACTUATOR": MAV_CMD_DO_SET_ACTUATOR, + "MAV_CMD_DO_LAND_START": MAV_CMD_DO_LAND_START, + "MAV_CMD_DO_RALLY_LAND": MAV_CMD_DO_RALLY_LAND, + "MAV_CMD_DO_GO_AROUND": MAV_CMD_DO_GO_AROUND, + "MAV_CMD_DO_REPOSITION": MAV_CMD_DO_REPOSITION, + "MAV_CMD_DO_PAUSE_CONTINUE": MAV_CMD_DO_PAUSE_CONTINUE, + "MAV_CMD_DO_SET_REVERSE": MAV_CMD_DO_SET_REVERSE, + "MAV_CMD_DO_SET_ROI_LOCATION": MAV_CMD_DO_SET_ROI_LOCATION, + "MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET": MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, + "MAV_CMD_DO_SET_ROI_NONE": MAV_CMD_DO_SET_ROI_NONE, + "MAV_CMD_DO_SET_ROI_SYSID": MAV_CMD_DO_SET_ROI_SYSID, + "MAV_CMD_DO_CONTROL_VIDEO": MAV_CMD_DO_CONTROL_VIDEO, + "MAV_CMD_DO_SET_ROI": MAV_CMD_DO_SET_ROI, + "MAV_CMD_DO_DIGICAM_CONFIGURE": MAV_CMD_DO_DIGICAM_CONFIGURE, + "MAV_CMD_DO_DIGICAM_CONTROL": MAV_CMD_DO_DIGICAM_CONTROL, + "MAV_CMD_DO_MOUNT_CONFIGURE": MAV_CMD_DO_MOUNT_CONFIGURE, + "MAV_CMD_DO_MOUNT_CONTROL": MAV_CMD_DO_MOUNT_CONTROL, + "MAV_CMD_DO_SET_CAM_TRIGG_DIST": MAV_CMD_DO_SET_CAM_TRIGG_DIST, + "MAV_CMD_DO_FENCE_ENABLE": MAV_CMD_DO_FENCE_ENABLE, + "MAV_CMD_DO_PARACHUTE": MAV_CMD_DO_PARACHUTE, + "MAV_CMD_DO_MOTOR_TEST": MAV_CMD_DO_MOTOR_TEST, + "MAV_CMD_DO_INVERTED_FLIGHT": MAV_CMD_DO_INVERTED_FLIGHT, + "MAV_CMD_DO_GRIPPER": MAV_CMD_DO_GRIPPER, + "MAV_CMD_DO_AUTOTUNE_ENABLE": MAV_CMD_DO_AUTOTUNE_ENABLE, + "MAV_CMD_NAV_SET_YAW_SPEED": MAV_CMD_NAV_SET_YAW_SPEED, + "MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL": MAV_CMD_DO_SET_CAM_TRIGG_INTERVAL, + "MAV_CMD_DO_MOUNT_CONTROL_QUAT": MAV_CMD_DO_MOUNT_CONTROL_QUAT, + "MAV_CMD_DO_GUIDED_MASTER": MAV_CMD_DO_GUIDED_MASTER, + "MAV_CMD_DO_GUIDED_LIMITS": MAV_CMD_DO_GUIDED_LIMITS, + "MAV_CMD_DO_ENGINE_CONTROL": MAV_CMD_DO_ENGINE_CONTROL, + "MAV_CMD_DO_SET_MISSION_CURRENT": MAV_CMD_DO_SET_MISSION_CURRENT, + "MAV_CMD_DO_LAST": MAV_CMD_DO_LAST, + "MAV_CMD_PREFLIGHT_CALIBRATION": MAV_CMD_PREFLIGHT_CALIBRATION, + "MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS": MAV_CMD_PREFLIGHT_SET_SENSOR_OFFSETS, + "MAV_CMD_PREFLIGHT_UAVCAN": MAV_CMD_PREFLIGHT_UAVCAN, + "MAV_CMD_PREFLIGHT_STORAGE": MAV_CMD_PREFLIGHT_STORAGE, + "MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN": MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, + "MAV_CMD_OVERRIDE_GOTO": MAV_CMD_OVERRIDE_GOTO, + "MAV_CMD_OBLIQUE_SURVEY": MAV_CMD_OBLIQUE_SURVEY, + "MAV_CMD_MISSION_START": MAV_CMD_MISSION_START, + "MAV_CMD_ACTUATOR_TEST": MAV_CMD_ACTUATOR_TEST, + "MAV_CMD_CONFIGURE_ACTUATOR": MAV_CMD_CONFIGURE_ACTUATOR, + "MAV_CMD_COMPONENT_ARM_DISARM": MAV_CMD_COMPONENT_ARM_DISARM, + "MAV_CMD_RUN_PREARM_CHECKS": MAV_CMD_RUN_PREARM_CHECKS, + "MAV_CMD_ILLUMINATOR_ON_OFF": MAV_CMD_ILLUMINATOR_ON_OFF, + "MAV_CMD_GET_HOME_POSITION": MAV_CMD_GET_HOME_POSITION, + "MAV_CMD_INJECT_FAILURE": MAV_CMD_INJECT_FAILURE, + "MAV_CMD_START_RX_PAIR": MAV_CMD_START_RX_PAIR, + "MAV_CMD_GET_MESSAGE_INTERVAL": MAV_CMD_GET_MESSAGE_INTERVAL, + "MAV_CMD_SET_MESSAGE_INTERVAL": MAV_CMD_SET_MESSAGE_INTERVAL, + "MAV_CMD_REQUEST_MESSAGE": MAV_CMD_REQUEST_MESSAGE, + "MAV_CMD_REQUEST_PROTOCOL_VERSION": MAV_CMD_REQUEST_PROTOCOL_VERSION, + "MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES": MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, + "MAV_CMD_REQUEST_CAMERA_INFORMATION": MAV_CMD_REQUEST_CAMERA_INFORMATION, + "MAV_CMD_REQUEST_CAMERA_SETTINGS": MAV_CMD_REQUEST_CAMERA_SETTINGS, + "MAV_CMD_REQUEST_STORAGE_INFORMATION": MAV_CMD_REQUEST_STORAGE_INFORMATION, + "MAV_CMD_STORAGE_FORMAT": MAV_CMD_STORAGE_FORMAT, + "MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS": MAV_CMD_REQUEST_CAMERA_CAPTURE_STATUS, + "MAV_CMD_REQUEST_FLIGHT_INFORMATION": MAV_CMD_REQUEST_FLIGHT_INFORMATION, + "MAV_CMD_RESET_CAMERA_SETTINGS": MAV_CMD_RESET_CAMERA_SETTINGS, + "MAV_CMD_SET_CAMERA_MODE": MAV_CMD_SET_CAMERA_MODE, + "MAV_CMD_SET_CAMERA_ZOOM": MAV_CMD_SET_CAMERA_ZOOM, + "MAV_CMD_SET_CAMERA_FOCUS": MAV_CMD_SET_CAMERA_FOCUS, + "MAV_CMD_SET_STORAGE_USAGE": MAV_CMD_SET_STORAGE_USAGE, + "MAV_CMD_JUMP_TAG": MAV_CMD_JUMP_TAG, + "MAV_CMD_DO_JUMP_TAG": MAV_CMD_DO_JUMP_TAG, + "MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW": MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, + "MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE": MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE, + "MAV_CMD_IMAGE_START_CAPTURE": MAV_CMD_IMAGE_START_CAPTURE, + "MAV_CMD_IMAGE_STOP_CAPTURE": MAV_CMD_IMAGE_STOP_CAPTURE, + "MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE": MAV_CMD_REQUEST_CAMERA_IMAGE_CAPTURE, + "MAV_CMD_DO_TRIGGER_CONTROL": MAV_CMD_DO_TRIGGER_CONTROL, + "MAV_CMD_CAMERA_TRACK_POINT": MAV_CMD_CAMERA_TRACK_POINT, + "MAV_CMD_CAMERA_TRACK_RECTANGLE": MAV_CMD_CAMERA_TRACK_RECTANGLE, + "MAV_CMD_CAMERA_STOP_TRACKING": MAV_CMD_CAMERA_STOP_TRACKING, + "MAV_CMD_VIDEO_START_CAPTURE": MAV_CMD_VIDEO_START_CAPTURE, + "MAV_CMD_VIDEO_STOP_CAPTURE": MAV_CMD_VIDEO_STOP_CAPTURE, + "MAV_CMD_VIDEO_START_STREAMING": MAV_CMD_VIDEO_START_STREAMING, + "MAV_CMD_VIDEO_STOP_STREAMING": MAV_CMD_VIDEO_STOP_STREAMING, + "MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION": MAV_CMD_REQUEST_VIDEO_STREAM_INFORMATION, + "MAV_CMD_REQUEST_VIDEO_STREAM_STATUS": MAV_CMD_REQUEST_VIDEO_STREAM_STATUS, + "MAV_CMD_LOGGING_START": MAV_CMD_LOGGING_START, + "MAV_CMD_LOGGING_STOP": MAV_CMD_LOGGING_STOP, + "MAV_CMD_AIRFRAME_CONFIGURATION": MAV_CMD_AIRFRAME_CONFIGURATION, + "MAV_CMD_CONTROL_HIGH_LATENCY": MAV_CMD_CONTROL_HIGH_LATENCY, + "MAV_CMD_PANORAMA_CREATE": MAV_CMD_PANORAMA_CREATE, + "MAV_CMD_DO_VTOL_TRANSITION": MAV_CMD_DO_VTOL_TRANSITION, + "MAV_CMD_ARM_AUTHORIZATION_REQUEST": MAV_CMD_ARM_AUTHORIZATION_REQUEST, + "MAV_CMD_SET_GUIDED_SUBMODE_STANDARD": MAV_CMD_SET_GUIDED_SUBMODE_STANDARD, + "MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE": MAV_CMD_SET_GUIDED_SUBMODE_CIRCLE, + "MAV_CMD_CONDITION_GATE": MAV_CMD_CONDITION_GATE, + "MAV_CMD_NAV_FENCE_RETURN_POINT": MAV_CMD_NAV_FENCE_RETURN_POINT, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, + "MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION": MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION, + "MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION": MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION, + "MAV_CMD_NAV_RALLY_POINT": MAV_CMD_NAV_RALLY_POINT, + "MAV_CMD_UAVCAN_GET_NODE_INFO": MAV_CMD_UAVCAN_GET_NODE_INFO, + "MAV_CMD_DO_ADSB_OUT_IDENT": MAV_CMD_DO_ADSB_OUT_IDENT, + "MAV_CMD_PAYLOAD_PREPARE_DEPLOY": MAV_CMD_PAYLOAD_PREPARE_DEPLOY, + "MAV_CMD_PAYLOAD_CONTROL_DEPLOY": MAV_CMD_PAYLOAD_CONTROL_DEPLOY, + "MAV_CMD_FIXED_MAG_CAL_YAW": MAV_CMD_FIXED_MAG_CAL_YAW, + "MAV_CMD_DO_WINCH": MAV_CMD_DO_WINCH, + "MAV_CMD_WAYPOINT_USER_1": MAV_CMD_WAYPOINT_USER_1, + "MAV_CMD_WAYPOINT_USER_2": MAV_CMD_WAYPOINT_USER_2, + "MAV_CMD_WAYPOINT_USER_3": MAV_CMD_WAYPOINT_USER_3, + "MAV_CMD_WAYPOINT_USER_4": MAV_CMD_WAYPOINT_USER_4, + "MAV_CMD_WAYPOINT_USER_5": MAV_CMD_WAYPOINT_USER_5, + "MAV_CMD_SPATIAL_USER_1": MAV_CMD_SPATIAL_USER_1, + "MAV_CMD_SPATIAL_USER_2": MAV_CMD_SPATIAL_USER_2, + "MAV_CMD_SPATIAL_USER_3": MAV_CMD_SPATIAL_USER_3, + "MAV_CMD_SPATIAL_USER_4": MAV_CMD_SPATIAL_USER_4, + "MAV_CMD_SPATIAL_USER_5": MAV_CMD_SPATIAL_USER_5, + "MAV_CMD_USER_1": MAV_CMD_USER_1, + "MAV_CMD_USER_2": MAV_CMD_USER_2, + "MAV_CMD_USER_3": MAV_CMD_USER_3, + "MAV_CMD_USER_4": MAV_CMD_USER_4, + "MAV_CMD_USER_5": MAV_CMD_USER_5, + "MAV_CMD_CAN_FORWARD": MAV_CMD_CAN_FORWARD, + "MAV_CMD_DO_SET_RESUME_REPEAT_DIST": MAV_CMD_DO_SET_RESUME_REPEAT_DIST, + "MAV_CMD_DO_SPRAYER": MAV_CMD_DO_SPRAYER, + "MAV_CMD_DO_SEND_SCRIPT_MESSAGE": MAV_CMD_DO_SEND_SCRIPT_MESSAGE, + "MAV_CMD_DO_AUX_FUNCTION": MAV_CMD_DO_AUX_FUNCTION, + "MAV_CMD_NAV_ALTITUDE_WAIT": MAV_CMD_NAV_ALTITUDE_WAIT, + "MAV_CMD_POWER_OFF_INITIATED": MAV_CMD_POWER_OFF_INITIATED, + "MAV_CMD_SOLO_BTN_FLY_CLICK": MAV_CMD_SOLO_BTN_FLY_CLICK, + "MAV_CMD_SOLO_BTN_FLY_HOLD": MAV_CMD_SOLO_BTN_FLY_HOLD, + "MAV_CMD_SOLO_BTN_PAUSE_CLICK": MAV_CMD_SOLO_BTN_PAUSE_CLICK, + "MAV_CMD_FIXED_MAG_CAL": MAV_CMD_FIXED_MAG_CAL, + "MAV_CMD_FIXED_MAG_CAL_FIELD": MAV_CMD_FIXED_MAG_CAL_FIELD, + "MAV_CMD_SET_EKF_SOURCE_SET": MAV_CMD_SET_EKF_SOURCE_SET, + "MAV_CMD_DO_START_MAG_CAL": MAV_CMD_DO_START_MAG_CAL, + "MAV_CMD_DO_ACCEPT_MAG_CAL": MAV_CMD_DO_ACCEPT_MAG_CAL, + "MAV_CMD_DO_CANCEL_MAG_CAL": MAV_CMD_DO_CANCEL_MAG_CAL, + "MAV_CMD_ACCELCAL_VEHICLE_POS": MAV_CMD_ACCELCAL_VEHICLE_POS, + "MAV_CMD_DO_SEND_BANNER": MAV_CMD_DO_SEND_BANNER, + "MAV_CMD_SET_FACTORY_TEST_MODE": MAV_CMD_SET_FACTORY_TEST_MODE, + "MAV_CMD_GIMBAL_RESET": MAV_CMD_GIMBAL_RESET, + "MAV_CMD_GIMBAL_AXIS_CALIBRATION_STATUS": MAV_CMD_GIMBAL_AXIS_CALIBRATION_STATUS, + "MAV_CMD_GIMBAL_REQUEST_AXIS_CALIBRATION": MAV_CMD_GIMBAL_REQUEST_AXIS_CALIBRATION, + "MAV_CMD_GIMBAL_FULL_RESET": MAV_CMD_GIMBAL_FULL_RESET, + "MAV_CMD_FLASH_BOOTLOADER": MAV_CMD_FLASH_BOOTLOADER, + "MAV_CMD_BATTERY_RESET": MAV_CMD_BATTERY_RESET, + "MAV_CMD_DEBUG_TRAP": MAV_CMD_DEBUG_TRAP, + "MAV_CMD_SCRIPTING": MAV_CMD_SCRIPTING, + "MAV_CMD_NAV_SCRIPT_TIME": MAV_CMD_NAV_SCRIPT_TIME, + "MAV_CMD_NAV_ATTITUDE_TIME": MAV_CMD_NAV_ATTITUDE_TIME, + "MAV_CMD_GUIDED_CHANGE_SPEED": MAV_CMD_GUIDED_CHANGE_SPEED, + "MAV_CMD_GUIDED_CHANGE_ALTITUDE": MAV_CMD_GUIDED_CHANGE_ALTITUDE, + "MAV_CMD_GUIDED_CHANGE_HEADING": MAV_CMD_GUIDED_CHANGE_HEADING, + "MAV_CMD_EXTERNAL_POSITION_ESTIMATE": MAV_CMD_EXTERNAL_POSITION_ESTIMATE, + "MAV_CMD_STORM32_DO_GIMBAL_MANAGER_CONTROL_PITCHYAW": MAV_CMD_STORM32_DO_GIMBAL_MANAGER_CONTROL_PITCHYAW, + "MAV_CMD_STORM32_DO_GIMBAL_MANAGER_SETUP": MAV_CMD_STORM32_DO_GIMBAL_MANAGER_SETUP, + "MAV_CMD_QSHOT_DO_CONFIGURE": MAV_CMD_QSHOT_DO_CONFIGURE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_CMD) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_CMD { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_CMD[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_CMD) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_CMD - for _, label := range labels { - found := false - for value, l := range labels_MAV_CMD { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_CMD[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_CMD) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_CMD[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/storm32/enum_mav_qshot_mode.go b/pkg/dialects/storm32/enum_mav_qshot_mode.go index 3c74f0263..96e882411 100644 --- a/pkg/dialects/storm32/enum_mav_qshot_mode.go +++ b/pkg/dialects/storm32/enum_mav_qshot_mode.go @@ -4,7 +4,7 @@ package storm32 import ( "fmt" - "strings" + "strconv" ) // Enumeration of possible shot modes. @@ -46,40 +46,43 @@ var labels_MAV_QSHOT_MODE = map[MAV_QSHOT_MODE]string{ MAV_QSHOT_MODE_HOME_TARGETING: "MAV_QSHOT_MODE_HOME_TARGETING", } +var values_MAV_QSHOT_MODE = map[string]MAV_QSHOT_MODE{ + "MAV_QSHOT_MODE_UNDEFINED": MAV_QSHOT_MODE_UNDEFINED, + "MAV_QSHOT_MODE_DEFAULT": MAV_QSHOT_MODE_DEFAULT, + "MAV_QSHOT_MODE_GIMBAL_RETRACT": MAV_QSHOT_MODE_GIMBAL_RETRACT, + "MAV_QSHOT_MODE_GIMBAL_NEUTRAL": MAV_QSHOT_MODE_GIMBAL_NEUTRAL, + "MAV_QSHOT_MODE_GIMBAL_MISSION": MAV_QSHOT_MODE_GIMBAL_MISSION, + "MAV_QSHOT_MODE_GIMBAL_RC_CONTROL": MAV_QSHOT_MODE_GIMBAL_RC_CONTROL, + "MAV_QSHOT_MODE_POI_TARGETING": MAV_QSHOT_MODE_POI_TARGETING, + "MAV_QSHOT_MODE_SYSID_TARGETING": MAV_QSHOT_MODE_SYSID_TARGETING, + "MAV_QSHOT_MODE_CABLECAM_2POINT": MAV_QSHOT_MODE_CABLECAM_2POINT, + "MAV_QSHOT_MODE_HOME_TARGETING": MAV_QSHOT_MODE_HOME_TARGETING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_QSHOT_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_QSHOT_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_QSHOT_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_QSHOT_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_QSHOT_MODE - for _, label := range labels { - found := false - for value, l := range labels_MAV_QSHOT_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_QSHOT_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_QSHOT_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_QSHOT_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/storm32/enum_mav_storm32_camera_prearm_flags.go b/pkg/dialects/storm32/enum_mav_storm32_camera_prearm_flags.go index 9ed88ba71..622108ab6 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_camera_prearm_flags.go +++ b/pkg/dialects/storm32/enum_mav_storm32_camera_prearm_flags.go @@ -19,12 +19,17 @@ var labels_MAV_STORM32_CAMERA_PREARM_FLAGS = map[MAV_STORM32_CAMERA_PREARM_FLAGS MAV_STORM32_CAMERA_PREARM_FLAGS_CONNECTED: "MAV_STORM32_CAMERA_PREARM_FLAGS_CONNECTED", } +var values_MAV_STORM32_CAMERA_PREARM_FLAGS = map[string]MAV_STORM32_CAMERA_PREARM_FLAGS{ + "MAV_STORM32_CAMERA_PREARM_FLAGS_CONNECTED": MAV_STORM32_CAMERA_PREARM_FLAGS_CONNECTED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_CAMERA_PREARM_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_STORM32_CAMERA_PREARM_FLAGS { + for i := 0; i < 1; i++ { + mask := MAV_STORM32_CAMERA_PREARM_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_STORM32_CAMERA_PREARM_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -35,19 +40,12 @@ func (e *MAV_STORM32_CAMERA_PREARM_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_STORM32_CAMERA_PREARM_FLAGS for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_CAMERA_PREARM_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_STORM32_CAMERA_PREARM_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_cap_flags.go b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_cap_flags.go index 2f9ec81d5..83ef1ed61 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_cap_flags.go +++ b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_cap_flags.go @@ -19,12 +19,17 @@ var labels_MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS = map[MAV_STORM32_GIMBAL_MANAGER MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS_HAS_PROFILES: "MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS_HAS_PROFILES", } +var values_MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS = map[string]MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS{ + "MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS_HAS_PROFILES": MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS_HAS_PROFILES, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS { + for i := 0; i < 1; i++ { + mask := MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -35,19 +40,12 @@ func (e *MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS) UnmarshalText(text []byte) error labels := strings.Split(string(text), " | ") var mask MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_STORM32_GIMBAL_MANAGER_CAP_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_client.go b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_client.go index b8e7c3e01..84a8d802e 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_client.go +++ b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_client.go @@ -4,7 +4,7 @@ package storm32 import ( "fmt" - "strings" + "strconv" ) // Gimbal manager client ID. In a prioritizing profile, the priorities are determined by the implementation; they could e.g. be custom1 > onboard > GCS > autopilot/camera > GCS2 > custom2. @@ -43,40 +43,42 @@ var labels_MAV_STORM32_GIMBAL_MANAGER_CLIENT = map[MAV_STORM32_GIMBAL_MANAGER_CL MAV_STORM32_GIMBAL_MANAGER_CLIENT_CUSTOM2: "MAV_STORM32_GIMBAL_MANAGER_CLIENT_CUSTOM2", } +var values_MAV_STORM32_GIMBAL_MANAGER_CLIENT = map[string]MAV_STORM32_GIMBAL_MANAGER_CLIENT{ + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_NONE": MAV_STORM32_GIMBAL_MANAGER_CLIENT_NONE, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_ONBOARD": MAV_STORM32_GIMBAL_MANAGER_CLIENT_ONBOARD, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_AUTOPILOT": MAV_STORM32_GIMBAL_MANAGER_CLIENT_AUTOPILOT, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_GCS": MAV_STORM32_GIMBAL_MANAGER_CLIENT_GCS, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_CAMERA": MAV_STORM32_GIMBAL_MANAGER_CLIENT_CAMERA, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_GCS2": MAV_STORM32_GIMBAL_MANAGER_CLIENT_GCS2, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_CAMERA2": MAV_STORM32_GIMBAL_MANAGER_CLIENT_CAMERA2, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_CUSTOM": MAV_STORM32_GIMBAL_MANAGER_CLIENT_CUSTOM, + "MAV_STORM32_GIMBAL_MANAGER_CLIENT_CUSTOM2": MAV_STORM32_GIMBAL_MANAGER_CLIENT_CUSTOM2, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_GIMBAL_MANAGER_CLIENT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_STORM32_GIMBAL_MANAGER_CLIENT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_STORM32_GIMBAL_MANAGER_CLIENT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_STORM32_GIMBAL_MANAGER_CLIENT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_STORM32_GIMBAL_MANAGER_CLIENT - for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_GIMBAL_MANAGER_CLIENT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_STORM32_GIMBAL_MANAGER_CLIENT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_STORM32_GIMBAL_MANAGER_CLIENT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_STORM32_GIMBAL_MANAGER_CLIENT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_flags.go b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_flags.go index ce141cd16..ad8817987 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_flags.go +++ b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_flags.go @@ -52,12 +52,28 @@ var labels_MAV_STORM32_GIMBAL_MANAGER_FLAGS = map[MAV_STORM32_GIMBAL_MANAGER_FLA MAV_STORM32_GIMBAL_MANAGER_FLAGS_SET_RELEASE: "MAV_STORM32_GIMBAL_MANAGER_FLAGS_SET_RELEASE", } +var values_MAV_STORM32_GIMBAL_MANAGER_FLAGS = map[string]MAV_STORM32_GIMBAL_MANAGER_FLAGS{ + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_NONE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_NONE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_RC_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_RC_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_ONBOARD_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_ONBOARD_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_AUTOPILOT_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_AUTOPILOT_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_GCS_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_GCS_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CAMERA_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CAMERA_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_GCS2_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_GCS2_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CAMERA2_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CAMERA2_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CUSTOM_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CUSTOM_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CUSTOM2_ACTIVE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_CLIENT_CUSTOM2_ACTIVE, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_SET_SUPERVISON": MAV_STORM32_GIMBAL_MANAGER_FLAGS_SET_SUPERVISON, + "MAV_STORM32_GIMBAL_MANAGER_FLAGS_SET_RELEASE": MAV_STORM32_GIMBAL_MANAGER_FLAGS_SET_RELEASE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_GIMBAL_MANAGER_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_STORM32_GIMBAL_MANAGER_FLAGS { + for i := 0; i < 12; i++ { + mask := MAV_STORM32_GIMBAL_MANAGER_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_STORM32_GIMBAL_MANAGER_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -68,19 +84,12 @@ func (e *MAV_STORM32_GIMBAL_MANAGER_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_STORM32_GIMBAL_MANAGER_FLAGS for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_GIMBAL_MANAGER_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_STORM32_GIMBAL_MANAGER_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_profile.go b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_profile.go index 35ca4a51d..62eb6e165 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_profile.go +++ b/pkg/dialects/storm32/enum_mav_storm32_gimbal_manager_profile.go @@ -4,7 +4,7 @@ package storm32 import ( "fmt" - "strings" + "strconv" ) // Gimbal manager profiles. Only standard profiles are defined. Any implementation can define its own profile(s) in addition, and should use enum values > 16. @@ -34,40 +34,39 @@ var labels_MAV_STORM32_GIMBAL_MANAGER_PROFILE = map[MAV_STORM32_GIMBAL_MANAGER_P MAV_STORM32_GIMBAL_MANAGER_PROFILE_PRIORITY_EXCLUSIVE: "MAV_STORM32_GIMBAL_MANAGER_PROFILE_PRIORITY_EXCLUSIVE", } +var values_MAV_STORM32_GIMBAL_MANAGER_PROFILE = map[string]MAV_STORM32_GIMBAL_MANAGER_PROFILE{ + "MAV_STORM32_GIMBAL_MANAGER_PROFILE_DEFAULT": MAV_STORM32_GIMBAL_MANAGER_PROFILE_DEFAULT, + "MAV_STORM32_GIMBAL_MANAGER_PROFILE_CUSTOM": MAV_STORM32_GIMBAL_MANAGER_PROFILE_CUSTOM, + "MAV_STORM32_GIMBAL_MANAGER_PROFILE_COOPERATIVE": MAV_STORM32_GIMBAL_MANAGER_PROFILE_COOPERATIVE, + "MAV_STORM32_GIMBAL_MANAGER_PROFILE_EXCLUSIVE": MAV_STORM32_GIMBAL_MANAGER_PROFILE_EXCLUSIVE, + "MAV_STORM32_GIMBAL_MANAGER_PROFILE_PRIORITY_COOPERATIVE": MAV_STORM32_GIMBAL_MANAGER_PROFILE_PRIORITY_COOPERATIVE, + "MAV_STORM32_GIMBAL_MANAGER_PROFILE_PRIORITY_EXCLUSIVE": MAV_STORM32_GIMBAL_MANAGER_PROFILE_PRIORITY_EXCLUSIVE, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_GIMBAL_MANAGER_PROFILE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_STORM32_GIMBAL_MANAGER_PROFILE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_STORM32_GIMBAL_MANAGER_PROFILE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_STORM32_GIMBAL_MANAGER_PROFILE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_STORM32_GIMBAL_MANAGER_PROFILE - for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_GIMBAL_MANAGER_PROFILE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_STORM32_GIMBAL_MANAGER_PROFILE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_STORM32_GIMBAL_MANAGER_PROFILE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_STORM32_GIMBAL_MANAGER_PROFILE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/storm32/enum_mav_storm32_gimbal_prearm_flags.go b/pkg/dialects/storm32/enum_mav_storm32_gimbal_prearm_flags.go index 4a9beeedf..bca572fe4 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_gimbal_prearm_flags.go +++ b/pkg/dialects/storm32/enum_mav_storm32_gimbal_prearm_flags.go @@ -55,12 +55,29 @@ var labels_MAV_STORM32_GIMBAL_PREARM_FLAGS = map[MAV_STORM32_GIMBAL_PREARM_FLAGS MAV_STORM32_GIMBAL_PREARM_FLAGS_NTLOGGER_WORKING: "MAV_STORM32_GIMBAL_PREARM_FLAGS_NTLOGGER_WORKING", } +var values_MAV_STORM32_GIMBAL_PREARM_FLAGS = map[string]MAV_STORM32_GIMBAL_PREARM_FLAGS{ + "MAV_STORM32_GIMBAL_PREARM_FLAGS_IS_NORMAL": MAV_STORM32_GIMBAL_PREARM_FLAGS_IS_NORMAL, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_IMUS_WORKING": MAV_STORM32_GIMBAL_PREARM_FLAGS_IMUS_WORKING, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_MOTORS_WORKING": MAV_STORM32_GIMBAL_PREARM_FLAGS_MOTORS_WORKING, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_ENCODERS_WORKING": MAV_STORM32_GIMBAL_PREARM_FLAGS_ENCODERS_WORKING, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_VOLTAGE_OK": MAV_STORM32_GIMBAL_PREARM_FLAGS_VOLTAGE_OK, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_VIRTUALCHANNELS_RECEIVING": MAV_STORM32_GIMBAL_PREARM_FLAGS_VIRTUALCHANNELS_RECEIVING, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_MAVLINK_RECEIVING": MAV_STORM32_GIMBAL_PREARM_FLAGS_MAVLINK_RECEIVING, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_STORM32LINK_QFIX": MAV_STORM32_GIMBAL_PREARM_FLAGS_STORM32LINK_QFIX, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_STORM32LINK_WORKING": MAV_STORM32_GIMBAL_PREARM_FLAGS_STORM32LINK_WORKING, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_CAMERA_CONNECTED": MAV_STORM32_GIMBAL_PREARM_FLAGS_CAMERA_CONNECTED, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_AUX0_LOW": MAV_STORM32_GIMBAL_PREARM_FLAGS_AUX0_LOW, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_AUX1_LOW": MAV_STORM32_GIMBAL_PREARM_FLAGS_AUX1_LOW, + "MAV_STORM32_GIMBAL_PREARM_FLAGS_NTLOGGER_WORKING": MAV_STORM32_GIMBAL_PREARM_FLAGS_NTLOGGER_WORKING, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_GIMBAL_PREARM_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_MAV_STORM32_GIMBAL_PREARM_FLAGS { + for i := 0; i < 13; i++ { + mask := MAV_STORM32_GIMBAL_PREARM_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_MAV_STORM32_GIMBAL_PREARM_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -71,19 +88,12 @@ func (e *MAV_STORM32_GIMBAL_PREARM_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask MAV_STORM32_GIMBAL_PREARM_FLAGS for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_GIMBAL_PREARM_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_MAV_STORM32_GIMBAL_PREARM_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/storm32/enum_mav_storm32_tunnel_payload_type.go b/pkg/dialects/storm32/enum_mav_storm32_tunnel_payload_type.go index fd9ff8d50..4ad69b68c 100644 --- a/pkg/dialects/storm32/enum_mav_storm32_tunnel_payload_type.go +++ b/pkg/dialects/storm32/enum_mav_storm32_tunnel_payload_type.go @@ -4,7 +4,7 @@ package storm32 import ( "fmt" - "strings" + "strconv" ) type MAV_STORM32_TUNNEL_PAYLOAD_TYPE uint32 @@ -33,40 +33,39 @@ var labels_MAV_STORM32_TUNNEL_PAYLOAD_TYPE = map[MAV_STORM32_TUNNEL_PAYLOAD_TYPE MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH3_OUT: "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH3_OUT", } +var values_MAV_STORM32_TUNNEL_PAYLOAD_TYPE = map[string]MAV_STORM32_TUNNEL_PAYLOAD_TYPE{ + "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH1_IN": MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH1_IN, + "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH1_OUT": MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH1_OUT, + "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH2_IN": MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH2_IN, + "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH2_OUT": MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH2_OUT, + "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH3_IN": MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH3_IN, + "MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH3_OUT": MAV_STORM32_TUNNEL_PAYLOAD_TYPE_STORM32_CH3_OUT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e MAV_STORM32_TUNNEL_PAYLOAD_TYPE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_MAV_STORM32_TUNNEL_PAYLOAD_TYPE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_MAV_STORM32_TUNNEL_PAYLOAD_TYPE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *MAV_STORM32_TUNNEL_PAYLOAD_TYPE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask MAV_STORM32_TUNNEL_PAYLOAD_TYPE - for _, label := range labels { - found := false - for value, l := range labels_MAV_STORM32_TUNNEL_PAYLOAD_TYPE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_MAV_STORM32_TUNNEL_PAYLOAD_TYPE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e MAV_STORM32_TUNNEL_PAYLOAD_TYPE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_MAV_STORM32_TUNNEL_PAYLOAD_TYPE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/storm32/enum_radio_link_stats_flags.go b/pkg/dialects/storm32/enum_radio_link_stats_flags.go index 203bebd16..3b42bdf5b 100644 --- a/pkg/dialects/storm32/enum_radio_link_stats_flags.go +++ b/pkg/dialects/storm32/enum_radio_link_stats_flags.go @@ -19,12 +19,17 @@ var labels_RADIO_LINK_STATS_FLAGS = map[RADIO_LINK_STATS_FLAGS]string{ RADIO_LINK_STATS_FLAGS_RSSI_DBM: "RADIO_LINK_STATS_FLAGS_RSSI_DBM", } +var values_RADIO_LINK_STATS_FLAGS = map[string]RADIO_LINK_STATS_FLAGS{ + "RADIO_LINK_STATS_FLAGS_RSSI_DBM": RADIO_LINK_STATS_FLAGS_RSSI_DBM, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e RADIO_LINK_STATS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_RADIO_LINK_STATS_FLAGS { + for i := 0; i < 1; i++ { + mask := RADIO_LINK_STATS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_RADIO_LINK_STATS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -35,19 +40,12 @@ func (e *RADIO_LINK_STATS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask RADIO_LINK_STATS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_RADIO_LINK_STATS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_RADIO_LINK_STATS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/storm32/enum_radio_rc_channels_flags.go b/pkg/dialects/storm32/enum_radio_rc_channels_flags.go index a6acd4814..1c964b6d8 100644 --- a/pkg/dialects/storm32/enum_radio_rc_channels_flags.go +++ b/pkg/dialects/storm32/enum_radio_rc_channels_flags.go @@ -22,12 +22,18 @@ var labels_RADIO_RC_CHANNELS_FLAGS = map[RADIO_RC_CHANNELS_FLAGS]string{ RADIO_RC_CHANNELS_FLAGS_FRAME_MISSED: "RADIO_RC_CHANNELS_FLAGS_FRAME_MISSED", } +var values_RADIO_RC_CHANNELS_FLAGS = map[string]RADIO_RC_CHANNELS_FLAGS{ + "RADIO_RC_CHANNELS_FLAGS_FAILSAFE": RADIO_RC_CHANNELS_FLAGS_FAILSAFE, + "RADIO_RC_CHANNELS_FLAGS_FRAME_MISSED": RADIO_RC_CHANNELS_FLAGS_FRAME_MISSED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e RADIO_RC_CHANNELS_FLAGS) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_RADIO_RC_CHANNELS_FLAGS { + for i := 0; i < 2; i++ { + mask := RADIO_RC_CHANNELS_FLAGS(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_RADIO_RC_CHANNELS_FLAGS[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -38,19 +44,12 @@ func (e *RADIO_RC_CHANNELS_FLAGS) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask RADIO_RC_CHANNELS_FLAGS for _, label := range labels { - found := false - for value, l := range labels_RADIO_RC_CHANNELS_FLAGS { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_RADIO_RC_CHANNELS_FLAGS[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/ualberta/enum_ualberta_autopilot_mode.go b/pkg/dialects/ualberta/enum_ualberta_autopilot_mode.go index e2e6035a8..a3ef22b42 100644 --- a/pkg/dialects/ualberta/enum_ualberta_autopilot_mode.go +++ b/pkg/dialects/ualberta/enum_ualberta_autopilot_mode.go @@ -4,7 +4,7 @@ package ualberta import ( "fmt" - "strings" + "strconv" ) // Available autopilot modes for ualberta uav @@ -28,40 +28,38 @@ var labels_UALBERTA_AUTOPILOT_MODE = map[UALBERTA_AUTOPILOT_MODE]string{ MODE_AUTO_PID_POS: "MODE_AUTO_PID_POS", } +var values_UALBERTA_AUTOPILOT_MODE = map[string]UALBERTA_AUTOPILOT_MODE{ + "MODE_MANUAL_DIRECT": MODE_MANUAL_DIRECT, + "MODE_MANUAL_SCALED": MODE_MANUAL_SCALED, + "MODE_AUTO_PID_ATT": MODE_AUTO_PID_ATT, + "MODE_AUTO_PID_VEL": MODE_AUTO_PID_VEL, + "MODE_AUTO_PID_POS": MODE_AUTO_PID_POS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UALBERTA_AUTOPILOT_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UALBERTA_AUTOPILOT_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UALBERTA_AUTOPILOT_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UALBERTA_AUTOPILOT_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UALBERTA_AUTOPILOT_MODE - for _, label := range labels { - found := false - for value, l := range labels_UALBERTA_AUTOPILOT_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UALBERTA_AUTOPILOT_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UALBERTA_AUTOPILOT_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UALBERTA_AUTOPILOT_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ualberta/enum_ualberta_nav_mode.go b/pkg/dialects/ualberta/enum_ualberta_nav_mode.go index 174261ed2..933282137 100644 --- a/pkg/dialects/ualberta/enum_ualberta_nav_mode.go +++ b/pkg/dialects/ualberta/enum_ualberta_nav_mode.go @@ -4,7 +4,7 @@ package ualberta import ( "fmt" - "strings" + "strconv" ) // Navigation filter mode @@ -27,40 +27,37 @@ var labels_UALBERTA_NAV_MODE = map[UALBERTA_NAV_MODE]string{ NAV_INS_GPS: "NAV_INS_GPS", } +var values_UALBERTA_NAV_MODE = map[string]UALBERTA_NAV_MODE{ + "NAV_AHRS_INIT": NAV_AHRS_INIT, + "NAV_AHRS": NAV_AHRS, + "NAV_INS_GPS_INIT": NAV_INS_GPS_INIT, + "NAV_INS_GPS": NAV_INS_GPS, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UALBERTA_NAV_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UALBERTA_NAV_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UALBERTA_NAV_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UALBERTA_NAV_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UALBERTA_NAV_MODE - for _, label := range labels { - found := false - for value, l := range labels_UALBERTA_NAV_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UALBERTA_NAV_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UALBERTA_NAV_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UALBERTA_NAV_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/ualberta/enum_ualberta_pilot_mode.go b/pkg/dialects/ualberta/enum_ualberta_pilot_mode.go index 558893be8..6d194ffc0 100644 --- a/pkg/dialects/ualberta/enum_ualberta_pilot_mode.go +++ b/pkg/dialects/ualberta/enum_ualberta_pilot_mode.go @@ -4,7 +4,7 @@ package ualberta import ( "fmt" - "strings" + "strconv" ) // Mode currently commanded by pilot @@ -23,40 +23,36 @@ var labels_UALBERTA_PILOT_MODE = map[UALBERTA_PILOT_MODE]string{ PILOT_ROTO: "PILOT_ROTO", } +var values_UALBERTA_PILOT_MODE = map[string]UALBERTA_PILOT_MODE{ + "PILOT_MANUAL": PILOT_MANUAL, + "PILOT_AUTO": PILOT_AUTO, + "PILOT_ROTO": PILOT_ROTO, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UALBERTA_PILOT_MODE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UALBERTA_PILOT_MODE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UALBERTA_PILOT_MODE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UALBERTA_PILOT_MODE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UALBERTA_PILOT_MODE - for _, label := range labels { - found := false - for value, l := range labels_UALBERTA_PILOT_MODE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UALBERTA_PILOT_MODE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UALBERTA_PILOT_MODE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UALBERTA_PILOT_MODE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_emergency_status.go b/pkg/dialects/uavionix/enum_uavionix_adsb_emergency_status.go index 75bdf5474..c6257c5cf 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_emergency_status.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_emergency_status.go @@ -4,7 +4,7 @@ package uavionix import ( "fmt" - "strings" + "strconv" ) // Emergency status encoding @@ -32,40 +32,41 @@ var labels_UAVIONIX_ADSB_EMERGENCY_STATUS = map[UAVIONIX_ADSB_EMERGENCY_STATUS]s UAVIONIX_ADSB_OUT_RESERVED: "UAVIONIX_ADSB_OUT_RESERVED", } +var values_UAVIONIX_ADSB_EMERGENCY_STATUS = map[string]UAVIONIX_ADSB_EMERGENCY_STATUS{ + "UAVIONIX_ADSB_OUT_NO_EMERGENCY": UAVIONIX_ADSB_OUT_NO_EMERGENCY, + "UAVIONIX_ADSB_OUT_GENERAL_EMERGENCY": UAVIONIX_ADSB_OUT_GENERAL_EMERGENCY, + "UAVIONIX_ADSB_OUT_LIFEGUARD_EMERGENCY": UAVIONIX_ADSB_OUT_LIFEGUARD_EMERGENCY, + "UAVIONIX_ADSB_OUT_MINIMUM_FUEL_EMERGENCY": UAVIONIX_ADSB_OUT_MINIMUM_FUEL_EMERGENCY, + "UAVIONIX_ADSB_OUT_NO_COMM_EMERGENCY": UAVIONIX_ADSB_OUT_NO_COMM_EMERGENCY, + "UAVIONIX_ADSB_OUT_UNLAWFUL_INTERFERANCE_EMERGENCY": UAVIONIX_ADSB_OUT_UNLAWFUL_INTERFERANCE_EMERGENCY, + "UAVIONIX_ADSB_OUT_DOWNED_AIRCRAFT_EMERGENCY": UAVIONIX_ADSB_OUT_DOWNED_AIRCRAFT_EMERGENCY, + "UAVIONIX_ADSB_OUT_RESERVED": UAVIONIX_ADSB_OUT_RESERVED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_EMERGENCY_STATUS) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVIONIX_ADSB_EMERGENCY_STATUS { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVIONIX_ADSB_EMERGENCY_STATUS[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVIONIX_ADSB_EMERGENCY_STATUS) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVIONIX_ADSB_EMERGENCY_STATUS - for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_EMERGENCY_STATUS { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVIONIX_ADSB_EMERGENCY_STATUS[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVIONIX_ADSB_EMERGENCY_STATUS) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVIONIX_ADSB_EMERGENCY_STATUS[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_aircraft_size.go b/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_aircraft_size.go index 32289eaec..ff0877756 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_aircraft_size.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_aircraft_size.go @@ -4,7 +4,7 @@ package uavionix import ( "fmt" - "strings" + "strconv" ) // Definitions for aircraft size @@ -48,40 +48,49 @@ var labels_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE = map[UAVIONIX_ADSB_OUT_CFG_AIRCR UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L85_W90M: "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L85_W90M", } +var values_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE = map[string]UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE{ + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_NO_DATA": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_NO_DATA, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L15M_W23M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L15M_W23M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L25M_W28P5M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L25M_W28P5M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L25_34M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L25_34M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L35_33M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L35_33M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L35_38M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L35_38M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L45_39P5M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L45_39P5M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L45_45M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L45_45M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L55_45M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L55_45M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L55_52M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L55_52M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L65_59P5M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L65_59P5M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L65_67M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L65_67M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L75_W72P5M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L75_W72P5M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L75_W80M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L75_W80M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L85_W80M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L85_W80M, + "UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L85_W90M": UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE_L85_W90M, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE - for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVIONIX_ADSB_OUT_CFG_AIRCRAFT_SIZE[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lat.go b/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lat.go index f0e59166b..4a4ba0bb6 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lat.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lat.go @@ -4,7 +4,7 @@ package uavionix import ( "fmt" - "strings" + "strconv" ) // GPS lataral offset encoding @@ -32,40 +32,41 @@ var labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT = map[UAVIONIX_ADSB_OUT_CFG_GPS_ UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_6M: "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_6M", } +var values_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT = map[string]UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT{ + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_NO_DATA": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_NO_DATA, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_LEFT_2M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_LEFT_2M, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_LEFT_4M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_LEFT_4M, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_LEFT_6M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_LEFT_6M, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_0M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_0M, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_2M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_2M, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_4M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_4M, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_6M": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT_RIGHT_6M, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT - for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LAT[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lon.go b/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lon.go index fb0d93650..8083de1ba 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lon.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_out_cfg_gps_offset_lon.go @@ -4,7 +4,7 @@ package uavionix import ( "fmt" - "strings" + "strconv" ) // GPS longitudinal offset encoding @@ -20,40 +20,35 @@ var labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON = map[UAVIONIX_ADSB_OUT_CFG_GPS_ UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_APPLIED_BY_SENSOR: "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_APPLIED_BY_SENSOR", } +var values_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON = map[string]UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON{ + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_NO_DATA": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_NO_DATA, + "UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_APPLIED_BY_SENSOR": UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON_APPLIED_BY_SENSOR, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON - for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVIONIX_ADSB_OUT_CFG_GPS_OFFSET_LON[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_gps_fix.go b/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_gps_fix.go index 8c883e0e5..1b39d56eb 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_gps_fix.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_gps_fix.go @@ -4,7 +4,7 @@ package uavionix import ( "fmt" - "strings" + "strconv" ) // Status for ADS-B transponder dynamic input @@ -28,40 +28,39 @@ var labels_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX = map[UAVIONIX_ADSB_OUT_DYNAMIC_GPS UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_RTK: "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_RTK", } +var values_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX = map[string]UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX{ + "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_NONE_0": UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_NONE_0, + "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_NONE_1": UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_NONE_1, + "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_2D": UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_2D, + "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_3D": UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_3D, + "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_DGPS": UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_DGPS, + "UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_RTK": UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX_RTK, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX) MarshalText() ([]byte, error) { - var names []string - for mask, label := range labels_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX { - if e&mask == mask { - names = append(names, label) - } + name, ok := labels_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX[e] + if !ok { + return nil, fmt.Errorf("invalid value %d", e) } - return []byte(strings.Join(names, " | ")), nil + return []byte(name), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. func (e *UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX) UnmarshalText(text []byte) error { - labels := strings.Split(string(text), " | ") - var mask UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX - for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX { - if l == label { - mask |= value - found = true - break - } - } - if !found { - return fmt.Errorf("invalid label '%s'", label) - } + value, ok := values_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX[string(text)] + if !ok { + return fmt.Errorf("invalid label '%s'", text) } - *e = mask + *e = value return nil } // String implements the fmt.Stringer interface. func (e UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX) String() string { - val, _ := e.MarshalText() - return string(val) + name, ok := labels_UAVIONIX_ADSB_OUT_DYNAMIC_GPS_FIX[e] + if !ok { + return strconv.Itoa(int(e)) + } + return name } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_state.go b/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_state.go index bfafc27ed..8ad093873 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_state.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_out_dynamic_state.go @@ -26,12 +26,21 @@ var labels_UAVIONIX_ADSB_OUT_DYNAMIC_STATE = map[UAVIONIX_ADSB_OUT_DYNAMIC_STATE UAVIONIX_ADSB_OUT_DYNAMIC_STATE_IDENT: "UAVIONIX_ADSB_OUT_DYNAMIC_STATE_IDENT", } +var values_UAVIONIX_ADSB_OUT_DYNAMIC_STATE = map[string]UAVIONIX_ADSB_OUT_DYNAMIC_STATE{ + "UAVIONIX_ADSB_OUT_DYNAMIC_STATE_INTENT_CHANGE": UAVIONIX_ADSB_OUT_DYNAMIC_STATE_INTENT_CHANGE, + "UAVIONIX_ADSB_OUT_DYNAMIC_STATE_AUTOPILOT_ENABLED": UAVIONIX_ADSB_OUT_DYNAMIC_STATE_AUTOPILOT_ENABLED, + "UAVIONIX_ADSB_OUT_DYNAMIC_STATE_NICBARO_CROSSCHECKED": UAVIONIX_ADSB_OUT_DYNAMIC_STATE_NICBARO_CROSSCHECKED, + "UAVIONIX_ADSB_OUT_DYNAMIC_STATE_ON_GROUND": UAVIONIX_ADSB_OUT_DYNAMIC_STATE_ON_GROUND, + "UAVIONIX_ADSB_OUT_DYNAMIC_STATE_IDENT": UAVIONIX_ADSB_OUT_DYNAMIC_STATE_IDENT, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_OUT_DYNAMIC_STATE) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_UAVIONIX_ADSB_OUT_DYNAMIC_STATE { + for i := 0; i < 5; i++ { + mask := UAVIONIX_ADSB_OUT_DYNAMIC_STATE(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_UAVIONIX_ADSB_OUT_DYNAMIC_STATE[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -42,19 +51,12 @@ func (e *UAVIONIX_ADSB_OUT_DYNAMIC_STATE) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask UAVIONIX_ADSB_OUT_DYNAMIC_STATE for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_OUT_DYNAMIC_STATE { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_UAVIONIX_ADSB_OUT_DYNAMIC_STATE[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_out_rf_select.go b/pkg/dialects/uavionix/enum_uavionix_adsb_out_rf_select.go index 4564a1756..12c707925 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_out_rf_select.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_out_rf_select.go @@ -22,12 +22,19 @@ var labels_UAVIONIX_ADSB_OUT_RF_SELECT = map[UAVIONIX_ADSB_OUT_RF_SELECT]string{ UAVIONIX_ADSB_OUT_RF_SELECT_TX_ENABLED: "UAVIONIX_ADSB_OUT_RF_SELECT_TX_ENABLED", } +var values_UAVIONIX_ADSB_OUT_RF_SELECT = map[string]UAVIONIX_ADSB_OUT_RF_SELECT{ + "UAVIONIX_ADSB_OUT_RF_SELECT_STANDBY": UAVIONIX_ADSB_OUT_RF_SELECT_STANDBY, + "UAVIONIX_ADSB_OUT_RF_SELECT_RX_ENABLED": UAVIONIX_ADSB_OUT_RF_SELECT_RX_ENABLED, + "UAVIONIX_ADSB_OUT_RF_SELECT_TX_ENABLED": UAVIONIX_ADSB_OUT_RF_SELECT_TX_ENABLED, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_OUT_RF_SELECT) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_UAVIONIX_ADSB_OUT_RF_SELECT { + for i := 0; i < 3; i++ { + mask := UAVIONIX_ADSB_OUT_RF_SELECT(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_UAVIONIX_ADSB_OUT_RF_SELECT[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -38,19 +45,12 @@ func (e *UAVIONIX_ADSB_OUT_RF_SELECT) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask UAVIONIX_ADSB_OUT_RF_SELECT for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_OUT_RF_SELECT { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_UAVIONIX_ADSB_OUT_RF_SELECT[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil } diff --git a/pkg/dialects/uavionix/enum_uavionix_adsb_rf_health.go b/pkg/dialects/uavionix/enum_uavionix_adsb_rf_health.go index 9bb04bd06..03fb107b9 100644 --- a/pkg/dialects/uavionix/enum_uavionix_adsb_rf_health.go +++ b/pkg/dialects/uavionix/enum_uavionix_adsb_rf_health.go @@ -24,12 +24,20 @@ var labels_UAVIONIX_ADSB_RF_HEALTH = map[UAVIONIX_ADSB_RF_HEALTH]string{ UAVIONIX_ADSB_RF_HEALTH_FAIL_RX: "UAVIONIX_ADSB_RF_HEALTH_FAIL_RX", } +var values_UAVIONIX_ADSB_RF_HEALTH = map[string]UAVIONIX_ADSB_RF_HEALTH{ + "UAVIONIX_ADSB_RF_HEALTH_INITIALIZING": UAVIONIX_ADSB_RF_HEALTH_INITIALIZING, + "UAVIONIX_ADSB_RF_HEALTH_OK": UAVIONIX_ADSB_RF_HEALTH_OK, + "UAVIONIX_ADSB_RF_HEALTH_FAIL_TX": UAVIONIX_ADSB_RF_HEALTH_FAIL_TX, + "UAVIONIX_ADSB_RF_HEALTH_FAIL_RX": UAVIONIX_ADSB_RF_HEALTH_FAIL_RX, +} + // MarshalText implements the encoding.TextMarshaler interface. func (e UAVIONIX_ADSB_RF_HEALTH) MarshalText() ([]byte, error) { var names []string - for mask, label := range labels_UAVIONIX_ADSB_RF_HEALTH { + for i := 0; i < 4; i++ { + mask := UAVIONIX_ADSB_RF_HEALTH(1 << i) if e&mask == mask { - names = append(names, label) + names = append(names, labels_UAVIONIX_ADSB_RF_HEALTH[mask]) } } return []byte(strings.Join(names, " | ")), nil @@ -40,19 +48,12 @@ func (e *UAVIONIX_ADSB_RF_HEALTH) UnmarshalText(text []byte) error { labels := strings.Split(string(text), " | ") var mask UAVIONIX_ADSB_RF_HEALTH for _, label := range labels { - found := false - for value, l := range labels_UAVIONIX_ADSB_RF_HEALTH { - if l == label { - mask |= value - found = true - break - } - } - if !found { + if value, ok := values_UAVIONIX_ADSB_RF_HEALTH[label]; ok { + mask |= value + } else { return fmt.Errorf("invalid label '%s'", label) } } - *e = mask return nil }