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

     1  //autogenerated:yes
     2  //nolint:revive,misspell,govet,lll,dupl,gocritic
     3  package ardupilotmega
     4  
     5  import (
     6  	"fmt"
     7  	"strconv"
     8  	"strings"
     9  )
    10  
    11  type LIMIT_MODULE uint64
    12  
    13  const (
    14  	// Pre-initialization.
    15  	LIMIT_GPSLOCK LIMIT_MODULE = 1
    16  	// Disabled.
    17  	LIMIT_GEOFENCE LIMIT_MODULE = 2
    18  	// Checking limits.
    19  	LIMIT_ALTITUDE LIMIT_MODULE = 4
    20  )
    21  
    22  var labels_LIMIT_MODULE = map[LIMIT_MODULE]string{
    23  	LIMIT_GPSLOCK:  "LIMIT_GPSLOCK",
    24  	LIMIT_GEOFENCE: "LIMIT_GEOFENCE",
    25  	LIMIT_ALTITUDE: "LIMIT_ALTITUDE",
    26  }
    27  
    28  var values_LIMIT_MODULE = map[string]LIMIT_MODULE{
    29  	"LIMIT_GPSLOCK":  LIMIT_GPSLOCK,
    30  	"LIMIT_GEOFENCE": LIMIT_GEOFENCE,
    31  	"LIMIT_ALTITUDE": LIMIT_ALTITUDE,
    32  }
    33  
    34  // MarshalText implements the encoding.TextMarshaler interface.
    35  func (e LIMIT_MODULE) MarshalText() ([]byte, error) {
    36  	if e == 0 {
    37  		return []byte("0"), nil
    38  	}
    39  	var names []string
    40  	for i := 0; i < 3; i++ {
    41  		mask := LIMIT_MODULE(1 << i)
    42  		if e&mask == mask {
    43  			names = append(names, labels_LIMIT_MODULE[mask])
    44  		}
    45  	}
    46  	return []byte(strings.Join(names, " | ")), nil
    47  }
    48  
    49  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    50  func (e *LIMIT_MODULE) UnmarshalText(text []byte) error {
    51  	labels := strings.Split(string(text), " | ")
    52  	var mask LIMIT_MODULE
    53  	for _, label := range labels {
    54  		if value, ok := values_LIMIT_MODULE[label]; ok {
    55  			mask |= value
    56  		} else if value, err := strconv.Atoi(label); err == nil {
    57  			mask |= LIMIT_MODULE(value)
    58  		} else {
    59  			return fmt.Errorf("invalid label '%s'", label)
    60  		}
    61  	}
    62  	*e = mask
    63  	return nil
    64  }
    65  
    66  // String implements the fmt.Stringer interface.
    67  func (e LIMIT_MODULE) String() string {
    68  	val, _ := e.MarshalText()
    69  	return string(val)
    70  }