github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/development/enum_airspeed_sensor_flags.go (about) 1 //autogenerated:yes 2 //nolint:revive,misspell,govet,lll,dupl,gocritic 3 package development 4 5 import ( 6 "fmt" 7 "strconv" 8 "strings" 9 ) 10 11 // Airspeed sensor flags 12 type AIRSPEED_SENSOR_FLAGS uint64 13 14 const ( 15 // Airspeed sensor is unhealthy 16 AIRSPEED_SENSOR_UNHEALTHY AIRSPEED_SENSOR_FLAGS = 0 17 // True if the data from this sensor is being actively used by the flight controller for guidance, navigation or control. 18 AIRSPEED_SENSOR_USING AIRSPEED_SENSOR_FLAGS = 1 19 ) 20 21 var labels_AIRSPEED_SENSOR_FLAGS = map[AIRSPEED_SENSOR_FLAGS]string{ 22 AIRSPEED_SENSOR_UNHEALTHY: "AIRSPEED_SENSOR_UNHEALTHY", 23 AIRSPEED_SENSOR_USING: "AIRSPEED_SENSOR_USING", 24 } 25 26 var values_AIRSPEED_SENSOR_FLAGS = map[string]AIRSPEED_SENSOR_FLAGS{ 27 "AIRSPEED_SENSOR_UNHEALTHY": AIRSPEED_SENSOR_UNHEALTHY, 28 "AIRSPEED_SENSOR_USING": AIRSPEED_SENSOR_USING, 29 } 30 31 // MarshalText implements the encoding.TextMarshaler interface. 32 func (e AIRSPEED_SENSOR_FLAGS) MarshalText() ([]byte, error) { 33 if e == 0 { 34 return []byte("0"), nil 35 } 36 var names []string 37 for i := 0; i < 2; i++ { 38 mask := AIRSPEED_SENSOR_FLAGS(1 << i) 39 if e&mask == mask { 40 names = append(names, labels_AIRSPEED_SENSOR_FLAGS[mask]) 41 } 42 } 43 return []byte(strings.Join(names, " | ")), nil 44 } 45 46 // UnmarshalText implements the encoding.TextUnmarshaler interface. 47 func (e *AIRSPEED_SENSOR_FLAGS) UnmarshalText(text []byte) error { 48 labels := strings.Split(string(text), " | ") 49 var mask AIRSPEED_SENSOR_FLAGS 50 for _, label := range labels { 51 if value, ok := values_AIRSPEED_SENSOR_FLAGS[label]; ok { 52 mask |= value 53 } else if value, err := strconv.Atoi(label); err == nil { 54 mask |= AIRSPEED_SENSOR_FLAGS(value) 55 } else { 56 return fmt.Errorf("invalid label '%s'", label) 57 } 58 } 59 *e = mask 60 return nil 61 } 62 63 // String implements the fmt.Stringer interface. 64 func (e AIRSPEED_SENSOR_FLAGS) String() string { 65 val, _ := e.MarshalText() 66 return string(val) 67 }