Skip to content
Snippets Groups Projects
Commit 136b12a1 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Switch to enum

parent 0e2ff75b
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,18 @@ import (
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
)
const (
AccessLevelR AccessLevel = 1
AccessLevelW AccessLevel = 2
AccessLevelRW AccessLevel = 3
AccessLevelRN AccessLevel = 5
AccessLevelRWN AccessLevel = 7
)
type (
AccessLevel int
)
var ignoredTopics = []string{
mqttTopic + "/bridge/groups",
mqttTopic + "/bridge/definitions",
......@@ -63,20 +75,12 @@ func (bDev *BridgeDevice) SetTopic() string {
return bDev.GetTopic() + "/set"
}
func getAccessType(level int) string {
switch level {
case 1:
return "R"
case 2:
return "W"
case 3:
return "RW"
case 5:
return "RN"
case 7:
return "RWN"
func (l AccessLevel) String() string {
return [...]string{"R", "W", "RW", "RN", "RWN"}[l]
}
return ""
func (l AccessLevel) EnumIndex() int {
return int(l)
}
func (bDev *BridgeDevice) dump() {
......@@ -102,11 +106,11 @@ func (bDev *BridgeDevice) dump() {
features := ""
if len(expose.Features) > 0 {
for _, feature := range expose.Features {
features += fmt.Sprintf("- %s[%s]-%s-(%s){%s}\n", feature.Name, feature.Type, getAccessType(feature.Access), feature.Unit, feature.Property)
features += fmt.Sprintf("- %s[%s]-%s-(%s){%s}\n", feature.Name, feature.Type, AccessLevel(feature.Access), feature.Unit, feature.Property)
}
features = strings.TrimSuffix(features, "\n")
}
expTab.AppendRow(table.Row{expose.Name, expose.Type, getAccessType(expose.Access), expose.Unit, values, features})
expTab.AppendRow(table.Row{expose.Name, expose.Type, AccessLevel(expose.Access), expose.Unit, values, features})
}
fmt.Println(expTab.Render())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment