-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconfig.go
123 lines (107 loc) · 4.21 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"reflect"
"github.com/lmatte7/gomesh"
"github.com/urfave/cli/v2"
)
// setConfig sets a radio configuration value on the radio
func setConfig(c *cli.Context) error {
radio := getRadio(c)
defer radio.Close()
err := radio.SetRadioConfig(c.String("key"), c.String("value"))
if err != nil {
return cli.Exit(err, 0)
}
fmt.Printf("%s set successfully\n", c.String("key"))
return nil
}
func setOwner(c *cli.Context) error {
radio := getRadio(c)
defer radio.Close()
return radio.SetRadioOwner(c.String("name"))
}
func printConfig(r gomesh.Radio) error {
configSettings, moduleSettings, err := r.GetRadioConfig()
if err != nil {
return err
}
fmt.Printf("Radio Config:\n")
fmt.Printf("%-40s", "==============================================================================\n")
for _, config := range configSettings {
if deviceConfig := config.Config.GetDevice(); deviceConfig != nil {
printSection("Device Config Options", *deviceConfig)
} else if deviceConfig := config.Config.GetPosition(); deviceConfig != nil {
printSection("Position Config Options", *deviceConfig)
} else if deviceConfig := config.Config.GetPower(); deviceConfig != nil {
printSection("Power Config Options", *deviceConfig)
} else if deviceConfig := config.Config.GetNetwork(); deviceConfig != nil {
printSection("Network Config Options", *deviceConfig)
} else if deviceConfig := config.Config.GetDisplay(); deviceConfig != nil {
printSection("Display Config Options", *deviceConfig)
} else if deviceConfig := config.Config.GetLora(); deviceConfig != nil {
printSection("Lora Config Options", *deviceConfig)
} else if deviceConfig := config.Config.GetBluetooth(); deviceConfig != nil {
printSection("Bluetooth Config Options", *deviceConfig)
}
}
for _, module := range moduleSettings {
if moduleConfig := module.ModuleConfig.GetMqtt(); moduleConfig != nil {
printSection("Mqtt Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetSerial(); moduleConfig != nil {
printSection("Serial Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetExternalNotification(); moduleConfig != nil {
printSection("External Notification Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetStoreForward(); moduleConfig != nil {
printSection("Store Forward Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetRangeTest(); moduleConfig != nil {
printSection("Range Test Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetTelemetry(); moduleConfig != nil {
printSection("Telemetry Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetCannedMessage(); moduleConfig != nil {
printSection("Canned Message Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetAudio(); moduleConfig != nil {
printSection("Audio Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetRemoteHardware(); moduleConfig != nil {
printSection("Serial Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetNeighborInfo(); moduleConfig != nil {
printSection("Neighbor Info Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetAmbientLighting(); moduleConfig != nil {
printSection("Ambient Lighting Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetDetectionSensor(); moduleConfig != nil {
printSection("Detection Sensor Module Options", *moduleConfig)
}
if moduleConfig := module.ModuleConfig.GetPaxcounter(); moduleConfig != nil {
printSection("Pax Counter Module Options", *moduleConfig)
}
}
return nil
}
func showRadioConfig(c *cli.Context) error {
radio := getRadio(c)
defer radio.Close()
return printConfig(radio)
}
func printSection(title string, t interface{}) {
v := reflect.ValueOf(t)
fmt.Printf("\n%-40s", "-------------------------------------------------\n")
fmt.Printf("%-48s|\n", title)
fmt.Printf("%-40s", "-------------------------------------------------\n")
for i := 0; i < v.NumField(); i++ {
if v.Field(i).CanInterface() {
fmt.Printf("%-40s", v.Type().Field(i).Name)
fmt.Printf("%v\n", v.Field(i))
}
}
}