github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/minimal/enum_mav_mode_flag.go (about) 1 //autogenerated:yes 2 //nolint:revive,misspell,govet,lll,dupl,gocritic 3 package minimal 4 5 import ( 6 "fmt" 7 "strconv" 8 "strings" 9 ) 10 11 // These flags encode the MAV mode. 12 type MAV_MODE_FLAG uint64 13 14 const ( 15 // 0b10000000 MAV safety set to armed. Motors are enabled / running / can start. Ready to fly. Additional note: this flag is to be ignore when sent in the command MAV_CMD_DO_SET_MODE and MAV_CMD_COMPONENT_ARM_DISARM shall be used instead. The flag can still be used to report the armed state. 16 MAV_MODE_FLAG_SAFETY_ARMED MAV_MODE_FLAG = 128 17 // 0b01000000 remote control input is enabled. 18 MAV_MODE_FLAG_MANUAL_INPUT_ENABLED MAV_MODE_FLAG = 64 19 // 0b00100000 hardware in the loop simulation. All motors / actuators are blocked, but internal software is full operational. 20 MAV_MODE_FLAG_HIL_ENABLED MAV_MODE_FLAG = 32 21 // 0b00010000 system stabilizes electronically its attitude (and optionally position). It needs however further control inputs to move around. 22 MAV_MODE_FLAG_STABILIZE_ENABLED MAV_MODE_FLAG = 16 23 // 0b00001000 guided mode enabled, system flies waypoints / mission items. 24 MAV_MODE_FLAG_GUIDED_ENABLED MAV_MODE_FLAG = 8 25 // 0b00000100 autonomous mode enabled, system finds its own goal positions. Guided flag can be set or not, depends on the actual implementation. 26 MAV_MODE_FLAG_AUTO_ENABLED MAV_MODE_FLAG = 4 27 // 0b00000010 system has a test mode enabled. This flag is intended for temporary system tests and should not be used for stable implementations. 28 MAV_MODE_FLAG_TEST_ENABLED MAV_MODE_FLAG = 2 29 // 0b00000001 Reserved for future use. 30 MAV_MODE_FLAG_CUSTOM_MODE_ENABLED MAV_MODE_FLAG = 1 31 ) 32 33 var labels_MAV_MODE_FLAG = map[MAV_MODE_FLAG]string{ 34 MAV_MODE_FLAG_SAFETY_ARMED: "MAV_MODE_FLAG_SAFETY_ARMED", 35 MAV_MODE_FLAG_MANUAL_INPUT_ENABLED: "MAV_MODE_FLAG_MANUAL_INPUT_ENABLED", 36 MAV_MODE_FLAG_HIL_ENABLED: "MAV_MODE_FLAG_HIL_ENABLED", 37 MAV_MODE_FLAG_STABILIZE_ENABLED: "MAV_MODE_FLAG_STABILIZE_ENABLED", 38 MAV_MODE_FLAG_GUIDED_ENABLED: "MAV_MODE_FLAG_GUIDED_ENABLED", 39 MAV_MODE_FLAG_AUTO_ENABLED: "MAV_MODE_FLAG_AUTO_ENABLED", 40 MAV_MODE_FLAG_TEST_ENABLED: "MAV_MODE_FLAG_TEST_ENABLED", 41 MAV_MODE_FLAG_CUSTOM_MODE_ENABLED: "MAV_MODE_FLAG_CUSTOM_MODE_ENABLED", 42 } 43 44 var values_MAV_MODE_FLAG = map[string]MAV_MODE_FLAG{ 45 "MAV_MODE_FLAG_SAFETY_ARMED": MAV_MODE_FLAG_SAFETY_ARMED, 46 "MAV_MODE_FLAG_MANUAL_INPUT_ENABLED": MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, 47 "MAV_MODE_FLAG_HIL_ENABLED": MAV_MODE_FLAG_HIL_ENABLED, 48 "MAV_MODE_FLAG_STABILIZE_ENABLED": MAV_MODE_FLAG_STABILIZE_ENABLED, 49 "MAV_MODE_FLAG_GUIDED_ENABLED": MAV_MODE_FLAG_GUIDED_ENABLED, 50 "MAV_MODE_FLAG_AUTO_ENABLED": MAV_MODE_FLAG_AUTO_ENABLED, 51 "MAV_MODE_FLAG_TEST_ENABLED": MAV_MODE_FLAG_TEST_ENABLED, 52 "MAV_MODE_FLAG_CUSTOM_MODE_ENABLED": MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, 53 } 54 55 // MarshalText implements the encoding.TextMarshaler interface. 56 func (e MAV_MODE_FLAG) MarshalText() ([]byte, error) { 57 if e == 0 { 58 return []byte("0"), nil 59 } 60 var names []string 61 for i := 0; i < 8; i++ { 62 mask := MAV_MODE_FLAG(1 << i) 63 if e&mask == mask { 64 names = append(names, labels_MAV_MODE_FLAG[mask]) 65 } 66 } 67 return []byte(strings.Join(names, " | ")), nil 68 } 69 70 // UnmarshalText implements the encoding.TextUnmarshaler interface. 71 func (e *MAV_MODE_FLAG) UnmarshalText(text []byte) error { 72 labels := strings.Split(string(text), " | ") 73 var mask MAV_MODE_FLAG 74 for _, label := range labels { 75 if value, ok := values_MAV_MODE_FLAG[label]; ok { 76 mask |= value 77 } else if value, err := strconv.Atoi(label); err == nil { 78 mask |= MAV_MODE_FLAG(value) 79 } else { 80 return fmt.Errorf("invalid label '%s'", label) 81 } 82 } 83 *e = mask 84 return nil 85 } 86 87 // String implements the fmt.Stringer interface. 88 func (e MAV_MODE_FLAG) String() string { 89 val, _ := e.MarshalText() 90 return string(val) 91 }