mirror of https://github.com/ftl/tetra-pei
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
761 B
Go
41 lines
761 B
Go
3 years ago
|
package ctrl
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
// AIModeByName returns the AIMode with the given name
|
||
|
func AIModeByName(name string) (AIMode, error) {
|
||
|
sanitized := strings.ToUpper(strings.TrimSpace(name))
|
||
|
result, ok := AIModesByName[sanitized]
|
||
|
if !ok {
|
||
|
return 0, fmt.Errorf("invalid operating mode %s", name)
|
||
|
}
|
||
|
return result, nil
|
||
|
}
|
||
|
|
||
|
// AIMode represents an operating mode according to [PEI] 6.17.4
|
||
|
type AIMode byte
|
||
|
|
||
|
func (m AIMode) String() string {
|
||
|
for k, v := range AIModesByName {
|
||
|
if v == m {
|
||
|
return k
|
||
|
}
|
||
|
}
|
||
|
return "UNKNOWN"
|
||
|
}
|
||
|
|
||
|
// All supported operating modes
|
||
|
const (
|
||
|
TMO AIMode = iota
|
||
|
DMO
|
||
|
)
|
||
|
|
||
|
// AIModesByName maps all supported operating modes by their string representation
|
||
|
var AIModesByName = map[string]AIMode{
|
||
|
"TMO": TMO,
|
||
|
"DMO": DMO,
|
||
|
}
|