github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/development/enum_radio_rc_channels_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  // RADIO_RC_CHANNELS flags (bitmask).
    12  type RADIO_RC_CHANNELS_FLAGS uint64
    13  
    14  const (
    15  	// Failsafe is active. The content of the RC channels data in the RADIO_RC_CHANNELS message is implementation dependent.
    16  	RADIO_RC_CHANNELS_FLAGS_FAILSAFE RADIO_RC_CHANNELS_FLAGS = 1
    17  	// Channel data may be out of date. This is set when the receiver is unable to validate incoming data from the transmitter and has therefore resent the last valid data it received.
    18  	RADIO_RC_CHANNELS_FLAGS_OUTDATED RADIO_RC_CHANNELS_FLAGS = 2
    19  )
    20  
    21  var labels_RADIO_RC_CHANNELS_FLAGS = map[RADIO_RC_CHANNELS_FLAGS]string{
    22  	RADIO_RC_CHANNELS_FLAGS_FAILSAFE: "RADIO_RC_CHANNELS_FLAGS_FAILSAFE",
    23  	RADIO_RC_CHANNELS_FLAGS_OUTDATED: "RADIO_RC_CHANNELS_FLAGS_OUTDATED",
    24  }
    25  
    26  var values_RADIO_RC_CHANNELS_FLAGS = map[string]RADIO_RC_CHANNELS_FLAGS{
    27  	"RADIO_RC_CHANNELS_FLAGS_FAILSAFE": RADIO_RC_CHANNELS_FLAGS_FAILSAFE,
    28  	"RADIO_RC_CHANNELS_FLAGS_OUTDATED": RADIO_RC_CHANNELS_FLAGS_OUTDATED,
    29  }
    30  
    31  // MarshalText implements the encoding.TextMarshaler interface.
    32  func (e RADIO_RC_CHANNELS_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 := RADIO_RC_CHANNELS_FLAGS(1 << i)
    39  		if e&mask == mask {
    40  			names = append(names, labels_RADIO_RC_CHANNELS_FLAGS[mask])
    41  		}
    42  	}
    43  	return []byte(strings.Join(names, " | ")), nil
    44  }
    45  
    46  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    47  func (e *RADIO_RC_CHANNELS_FLAGS) UnmarshalText(text []byte) error {
    48  	labels := strings.Split(string(text), " | ")
    49  	var mask RADIO_RC_CHANNELS_FLAGS
    50  	for _, label := range labels {
    51  		if value, ok := values_RADIO_RC_CHANNELS_FLAGS[label]; ok {
    52  			mask |= value
    53  		} else if value, err := strconv.Atoi(label); err == nil {
    54  			mask |= RADIO_RC_CHANNELS_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 RADIO_RC_CHANNELS_FLAGS) String() string {
    65  	val, _ := e.MarshalText()
    66  	return string(val)
    67  }