github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/common/enum_mav_sys_status_sensor_extended.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 encode the sensors whose status is sent as part of the SYS_STATUS message in the extended fields.
    12  type MAV_SYS_STATUS_SENSOR_EXTENDED uint64
    13  
    14  const (
    15  	// 0x01 Recovery system (parachute, balloon, retracts etc)
    16  	MAV_SYS_STATUS_RECOVERY_SYSTEM MAV_SYS_STATUS_SENSOR_EXTENDED = 1
    17  )
    18  
    19  var labels_MAV_SYS_STATUS_SENSOR_EXTENDED = map[MAV_SYS_STATUS_SENSOR_EXTENDED]string{
    20  	MAV_SYS_STATUS_RECOVERY_SYSTEM: "MAV_SYS_STATUS_RECOVERY_SYSTEM",
    21  }
    22  
    23  var values_MAV_SYS_STATUS_SENSOR_EXTENDED = map[string]MAV_SYS_STATUS_SENSOR_EXTENDED{
    24  	"MAV_SYS_STATUS_RECOVERY_SYSTEM": MAV_SYS_STATUS_RECOVERY_SYSTEM,
    25  }
    26  
    27  // MarshalText implements the encoding.TextMarshaler interface.
    28  func (e MAV_SYS_STATUS_SENSOR_EXTENDED) MarshalText() ([]byte, error) {
    29  	if e == 0 {
    30  		return []byte("0"), nil
    31  	}
    32  	var names []string
    33  	for i := 0; i < 1; i++ {
    34  		mask := MAV_SYS_STATUS_SENSOR_EXTENDED(1 << i)
    35  		if e&mask == mask {
    36  			names = append(names, labels_MAV_SYS_STATUS_SENSOR_EXTENDED[mask])
    37  		}
    38  	}
    39  	return []byte(strings.Join(names, " | ")), nil
    40  }
    41  
    42  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    43  func (e *MAV_SYS_STATUS_SENSOR_EXTENDED) UnmarshalText(text []byte) error {
    44  	labels := strings.Split(string(text), " | ")
    45  	var mask MAV_SYS_STATUS_SENSOR_EXTENDED
    46  	for _, label := range labels {
    47  		if value, ok := values_MAV_SYS_STATUS_SENSOR_EXTENDED[label]; ok {
    48  			mask |= value
    49  		} else if value, err := strconv.Atoi(label); err == nil {
    50  			mask |= MAV_SYS_STATUS_SENSOR_EXTENDED(value)
    51  		} else {
    52  			return fmt.Errorf("invalid label '%s'", label)
    53  		}
    54  	}
    55  	*e = mask
    56  	return nil
    57  }
    58  
    59  // String implements the fmt.Stringer interface.
    60  func (e MAV_SYS_STATUS_SENSOR_EXTENDED) String() string {
    61  	val, _ := e.MarshalText()
    62  	return string(val)
    63  }