github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/common/enum_adsb_flags.go (about)

     1  //autogenerated:yes
     2  //nolint:revive,misspell,govet,lll,dupl,gocritic
     3  package common
     4  
     5  import (
     6  	"fmt"
     7  	"strconv"
     8  	"strings"
     9  )
    10  
    11  // These flags indicate status such as data validity of each data source. Set = data valid
    12  type ADSB_FLAGS uint64
    13  
    14  const (
    15  	ADSB_FLAGS_VALID_COORDS            ADSB_FLAGS = 1
    16  	ADSB_FLAGS_VALID_ALTITUDE          ADSB_FLAGS = 2
    17  	ADSB_FLAGS_VALID_HEADING           ADSB_FLAGS = 4
    18  	ADSB_FLAGS_VALID_VELOCITY          ADSB_FLAGS = 8
    19  	ADSB_FLAGS_VALID_CALLSIGN          ADSB_FLAGS = 16
    20  	ADSB_FLAGS_VALID_SQUAWK            ADSB_FLAGS = 32
    21  	ADSB_FLAGS_SIMULATED               ADSB_FLAGS = 64
    22  	ADSB_FLAGS_VERTICAL_VELOCITY_VALID ADSB_FLAGS = 128
    23  	ADSB_FLAGS_BARO_VALID              ADSB_FLAGS = 256
    24  	ADSB_FLAGS_SOURCE_UAT              ADSB_FLAGS = 32768
    25  )
    26  
    27  var labels_ADSB_FLAGS = map[ADSB_FLAGS]string{
    28  	ADSB_FLAGS_VALID_COORDS:            "ADSB_FLAGS_VALID_COORDS",
    29  	ADSB_FLAGS_VALID_ALTITUDE:          "ADSB_FLAGS_VALID_ALTITUDE",
    30  	ADSB_FLAGS_VALID_HEADING:           "ADSB_FLAGS_VALID_HEADING",
    31  	ADSB_FLAGS_VALID_VELOCITY:          "ADSB_FLAGS_VALID_VELOCITY",
    32  	ADSB_FLAGS_VALID_CALLSIGN:          "ADSB_FLAGS_VALID_CALLSIGN",
    33  	ADSB_FLAGS_VALID_SQUAWK:            "ADSB_FLAGS_VALID_SQUAWK",
    34  	ADSB_FLAGS_SIMULATED:               "ADSB_FLAGS_SIMULATED",
    35  	ADSB_FLAGS_VERTICAL_VELOCITY_VALID: "ADSB_FLAGS_VERTICAL_VELOCITY_VALID",
    36  	ADSB_FLAGS_BARO_VALID:              "ADSB_FLAGS_BARO_VALID",
    37  	ADSB_FLAGS_SOURCE_UAT:              "ADSB_FLAGS_SOURCE_UAT",
    38  }
    39  
    40  var values_ADSB_FLAGS = map[string]ADSB_FLAGS{
    41  	"ADSB_FLAGS_VALID_COORDS":            ADSB_FLAGS_VALID_COORDS,
    42  	"ADSB_FLAGS_VALID_ALTITUDE":          ADSB_FLAGS_VALID_ALTITUDE,
    43  	"ADSB_FLAGS_VALID_HEADING":           ADSB_FLAGS_VALID_HEADING,
    44  	"ADSB_FLAGS_VALID_VELOCITY":          ADSB_FLAGS_VALID_VELOCITY,
    45  	"ADSB_FLAGS_VALID_CALLSIGN":          ADSB_FLAGS_VALID_CALLSIGN,
    46  	"ADSB_FLAGS_VALID_SQUAWK":            ADSB_FLAGS_VALID_SQUAWK,
    47  	"ADSB_FLAGS_SIMULATED":               ADSB_FLAGS_SIMULATED,
    48  	"ADSB_FLAGS_VERTICAL_VELOCITY_VALID": ADSB_FLAGS_VERTICAL_VELOCITY_VALID,
    49  	"ADSB_FLAGS_BARO_VALID":              ADSB_FLAGS_BARO_VALID,
    50  	"ADSB_FLAGS_SOURCE_UAT":              ADSB_FLAGS_SOURCE_UAT,
    51  }
    52  
    53  // MarshalText implements the encoding.TextMarshaler interface.
    54  func (e ADSB_FLAGS) MarshalText() ([]byte, error) {
    55  	if e == 0 {
    56  		return []byte("0"), nil
    57  	}
    58  	var names []string
    59  	for i := 0; i < 10; i++ {
    60  		mask := ADSB_FLAGS(1 << i)
    61  		if e&mask == mask {
    62  			names = append(names, labels_ADSB_FLAGS[mask])
    63  		}
    64  	}
    65  	return []byte(strings.Join(names, " | ")), nil
    66  }
    67  
    68  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    69  func (e *ADSB_FLAGS) UnmarshalText(text []byte) error {
    70  	labels := strings.Split(string(text), " | ")
    71  	var mask ADSB_FLAGS
    72  	for _, label := range labels {
    73  		if value, ok := values_ADSB_FLAGS[label]; ok {
    74  			mask |= value
    75  		} else if value, err := strconv.Atoi(label); err == nil {
    76  			mask |= ADSB_FLAGS(value)
    77  		} else {
    78  			return fmt.Errorf("invalid label '%s'", label)
    79  		}
    80  	}
    81  	*e = mask
    82  	return nil
    83  }
    84  
    85  // String implements the fmt.Stringer interface.
    86  func (e ADSB_FLAGS) String() string {
    87  	val, _ := e.MarshalText()
    88  	return string(val)
    89  }