Skip to content

Commit 4f3f58d

Browse files
authored
Merge pull request #108 from lack/intel/disable_all_nmea_messages
intel/disable all nmea messages
2 parents c12d70d + fa91434 commit 4f3f58d

File tree

7 files changed

+651
-96
lines changed

7 files changed

+651
-96
lines changed

addons/intel/e810.go

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
type E810Opts struct {
2121
EnableDefaultConfig bool `json:"enableDefaultConfig"`
22-
UblxCmds []E810UblxCmds `json:"ublxCmds"`
22+
UblxCmds UblxCmdList `json:"ublxCmds"`
2323
DevicePins map[string]map[string]string `json:"pins"`
2424
DpllSettings map[string]uint64 `json:"settings"`
2525
PhaseOffsetPins map[string]map[string]string `json:"phaseOffsetPins"`
@@ -57,63 +57,14 @@ done
5757
echo "Disabled all SMA and U.FL Connections"
5858
`
5959

60-
var unitTest bool
61-
var clockChain = &ClockChain{}
60+
var (
61+
unitTest bool
62+
clockChain = &ClockChain{}
63+
)
6264

6365
// For mocking DPLL pin info
6466
var DpllPins = []*dpll_netlink.PinInfo{}
6567

66-
func getDefaultUblxCmds() []E810UblxCmds {
67-
// Ublx command to output NAV-CLOCK every second
68-
cfgMsgNavClock := E810UblxCmds{
69-
ReportOutput: false,
70-
Args: []string{"-p", "CFG-MSG,1,34,1"},
71-
}
72-
// Ublx command to output NAV-STATUS every second
73-
cfgMsgNavStatus := E810UblxCmds{
74-
ReportOutput: false,
75-
Args: []string{"-p", "CFG-MSG,1,3,1"},
76-
}
77-
78-
// Ublx command to disable SA messages
79-
cfgMsgDisableSA := E810UblxCmds{
80-
ReportOutput: false,
81-
Args: []string{"-p", "CFG-MSG,0xf0,0x02,0"},
82-
}
83-
// Ublx command to disable SV messages
84-
cfgMsgDisableSV := E810UblxCmds{
85-
ReportOutput: false,
86-
Args: []string{"-p", "CFG-MSG,0xf0,0x03,0"},
87-
}
88-
// Ublx command to disable VTG messages
89-
cfgMsgDisableVTG := E810UblxCmds{
90-
ReportOutput: false,
91-
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_VTG_I2C,0"},
92-
}
93-
// Ublx command to disable GST messages
94-
cfgMsgDisableGST := E810UblxCmds{
95-
ReportOutput: false,
96-
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_GST_I2C,0"},
97-
}
98-
// Ublx command to disable ZDA messages
99-
cfgMsgDisableZDA := E810UblxCmds{
100-
ReportOutput: false,
101-
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_ZDA_I2C,0"},
102-
}
103-
// Ublx command to disable GBS messages
104-
cfgMsgDisableGBS := E810UblxCmds{
105-
ReportOutput: false,
106-
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_GBS_I2C,0"},
107-
}
108-
// Ublx command to save configuration to storage
109-
cfgSave := E810UblxCmds{
110-
ReportOutput: false,
111-
Args: []string{"-p", "SAVE"},
112-
}
113-
return []E810UblxCmds{cfgMsgNavClock, cfgMsgNavStatus, cfgMsgDisableSA, cfgMsgDisableSV,
114-
cfgMsgDisableVTG, cfgMsgDisableGST, cfgMsgDisableZDA, cfgMsgDisableGBS, cfgSave}
115-
}
116-
11768
func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) error {
11869
glog.Info("calling onPTPConfigChange for e810 plugin")
11970
var e810Opts E810Opts
@@ -159,7 +110,7 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
159110
for _, phc := range phcs {
160111
pinPath = fmt.Sprintf("/sys/class/net/%s/device/ptp/%s/pins/%s", device, phc.Name(), pin)
161112
glog.Infof("echo %s > %s", value, pinPath)
162-
err = os.WriteFile(pinPath, []byte(value), 0666)
113+
err = os.WriteFile(pinPath, []byte(value), 0o666)
163114
if err != nil {
164115
glog.Error("e810 failed to write " + value + " to " + pinPath + ": " + err.Error())
165116
}
@@ -211,11 +162,11 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
211162
}
212163

213164
func AfterRunPTPCommandE810(data *interface{}, nodeProfile *ptpv1.PtpProfile, command string) error {
165+
pluginData := (*data).(*E810PluginData)
214166
glog.Info("calling AfterRunPTPCommandE810 for e810 plugin")
215167
var e810Opts E810Opts
216168
var err error
217169
var optsByteArray []byte
218-
var stdout []byte
219170

220171
e810Opts.EnableDefaultConfig = false
221172

@@ -229,22 +180,10 @@ func AfterRunPTPCommandE810(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
229180
switch command {
230181
case "gpspipe":
231182
glog.Infof("AfterRunPTPCommandE810 doing ublx config for command: %s", command)
232-
for _, ublxOpt := range append(e810Opts.UblxCmds, getDefaultUblxCmds()...) {
233-
ublxArgs := ublxOpt.Args
234-
glog.Infof("Running /usr/bin/ubxtool with args %s", strings.Join(ublxArgs, ", "))
235-
stdout, _ = exec.Command("/usr/local/bin/ubxtool", ublxArgs...).CombinedOutput()
236-
//stdout, err = exec.Command("/usr/local/bin/ubxtool", "-p", "STATUS").CombinedOutput()
237-
if data != nil && ublxOpt.ReportOutput {
238-
_data := *data
239-
glog.Infof("Saving status to hwconfig: %s", string(stdout))
240-
var pluginData = _data.(*E810PluginData)
241-
_pluginData := *pluginData
242-
statusString := fmt.Sprintf("ublx data: %s", string(stdout))
243-
*_pluginData.hwplugins = append(*_pluginData.hwplugins, statusString)
244-
} else {
245-
glog.Infof("Not saving status to hwconfig: %s", string(stdout))
246-
}
247-
}
183+
// Execute user-supplied UblxCmds first:
184+
*pluginData.hwplugins = append(*pluginData.hwplugins, e810Opts.UblxCmds.runAll()...)
185+
// Finish with the default commands:
186+
*pluginData.hwplugins = append(*pluginData.hwplugins, defaultUblxCmds().runAll()...)
248187
case "tbc-ho-exit":
249188
_, err = clockChain.EnterNormalTBC()
250189
if err != nil {
@@ -277,7 +216,7 @@ func PopulateHwConfigE810(data *interface{}, hwconfigs *[]ptpv1.HwConfig) error
277216
//*hwconfigs = append(*hwconfigs, hwConfig)
278217
if data != nil {
279218
_data := *data
280-
var pluginData = _data.(*E810PluginData)
219+
pluginData := _data.(*E810PluginData)
281220
_pluginData := *pluginData
282221
if _pluginData.hwplugins != nil {
283222
for _, _hwconfig := range *_pluginData.hwplugins {
@@ -299,7 +238,8 @@ func E810(name string) (*plugin.Plugin, *interface{}) {
299238
glog.Infof("registering e810 plugin")
300239
hwplugins := []string{}
301240
pluginData := E810PluginData{hwplugins: &hwplugins}
302-
_plugin := plugin.Plugin{Name: "e810",
241+
_plugin := plugin.Plugin{
242+
Name: "e810",
303243
OnPTPConfigChange: OnPTPConfigChangeE810,
304244
AfterRunPTPCommand: AfterRunPTPCommandE810,
305245
PopulateHwConfig: PopulateHwConfigE810,

addons/intel/e810_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package intel
2+
3+
import (
4+
"slices"
5+
"testing"
6+
7+
ptpv1 "github.com/k8snetworkplumbingwg/ptp-operator/api/v1"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func Test_E810(t *testing.T) {
12+
p, d := E810("e810")
13+
assert.NotNil(t, p)
14+
assert.NotNil(t, d)
15+
16+
p, d = E810("not_e810")
17+
assert.Nil(t, p)
18+
assert.Nil(t, d)
19+
}
20+
21+
func Test_AfterRunPTPCommandE810(t *testing.T) {
22+
unitTest = true
23+
profile, err := loadProfile("./testdata/profile-tgm.yaml")
24+
assert.NoError(t, err)
25+
p, d := E810("e810")
26+
data := (*d).(*E810PluginData)
27+
28+
err = p.AfterRunPTPCommand(d, profile, "bad command")
29+
assert.NoError(t, err)
30+
31+
mockExec, execRestore := setupExecMock()
32+
defer execRestore()
33+
mockExec.setDefaults("output", nil)
34+
err = p.AfterRunPTPCommand(d, profile, "gpspipe")
35+
assert.NoError(t, err)
36+
// Ensure all 9 required calls are the last 9:
37+
requiredUblxCmds := []string{
38+
"CFG-MSG,1,34,1",
39+
"CFG-MSG,1,3,1",
40+
"CFG-MSG,0xf0,0x02,0",
41+
"CFG-MSG,0xf0,0x03,0",
42+
"CFG-MSGOUT-NMEA_ID_VTG_I2C,0",
43+
"CFG-MSGOUT-NMEA_ID_GST_I2C,0",
44+
"CFG-MSGOUT-NMEA_ID_ZDA_I2C,0",
45+
"CFG-MSGOUT-NMEA_ID_GBS_I2C,0",
46+
"SAVE",
47+
}
48+
found := make([]string, 0, len(requiredUblxCmds))
49+
for _, call := range mockExec.actualCalls {
50+
for _, arg := range call.args {
51+
if slices.Contains(requiredUblxCmds, arg) {
52+
found = append(found, arg)
53+
}
54+
}
55+
}
56+
assert.Equal(t, requiredUblxCmds, found)
57+
// And expect 3 of them to have produced output (as specified in the profile)
58+
assert.Equal(t, 3, len(*data.hwplugins))
59+
}
60+
61+
func Test_PopulateHwConfdigE810(t *testing.T) {
62+
p, d := E810("e810")
63+
data := (*d).(*E810PluginData)
64+
err := p.PopulateHwConfig(d, nil)
65+
assert.NoError(t, err)
66+
67+
output := []ptpv1.HwConfig{}
68+
err = p.PopulateHwConfig(d, &output)
69+
assert.NoError(t, err)
70+
assert.Equal(t, 0, len(output))
71+
72+
data.hwplugins = &[]string{"A", "B", "C"}
73+
err = p.PopulateHwConfig(d, &output)
74+
assert.NoError(t, err)
75+
assert.Equal(t, []ptpv1.HwConfig{
76+
{
77+
DeviceID: "e810",
78+
Status: "A",
79+
},
80+
{
81+
DeviceID: "e810",
82+
Status: "B",
83+
},
84+
{
85+
DeviceID: "e810",
86+
Status: "C",
87+
},
88+
},
89+
output)
90+
}

addons/intel/e825.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var pluginNameE825 = "e825"
2222
// E825Opts is the options structure for e825 plugin
2323
type E825Opts struct {
2424
EnableDefaultConfig bool `json:"enableDefaultConfig"`
25-
UblxCmds []E810UblxCmds `json:"ublxCmds"`
25+
UblxCmds UblxCmdList `json:"ublxCmds"`
2626
DevicePins map[string]map[string]string `json:"pins"`
2727
DpllSettings map[string]uint64 `json:"settings"`
2828
PhaseOffsetPins map[string]map[string]string `json:"phaseOffsetPins"`
@@ -96,7 +96,7 @@ func OnPTPConfigChangeE825(_ *interface{}, nodeProfile *ptpv1.PtpProfile) error
9696
for _, phc := range phcs {
9797
pinPath := fmt.Sprintf("/sys/class/net/%s/device/ptp/%s/pins/%s", device, phc.Name(), pin)
9898
glog.Infof("echo %s > %s", value, pinPath)
99-
err = os.WriteFile(pinPath, []byte(value), 0666)
99+
err = os.WriteFile(pinPath, []byte(value), 0o666)
100100
if err != nil {
101101
glog.Error("e825 failed to write " + value + " to " + pinPath + ": " + err.Error())
102102
}
@@ -155,11 +155,11 @@ func OnPTPConfigChangeE825(_ *interface{}, nodeProfile *ptpv1.PtpProfile) error
155155

156156
// AfterRunPTPCommandE825 performs actions after certain PTP commands for e825 plugin
157157
func AfterRunPTPCommandE825(data *interface{}, nodeProfile *ptpv1.PtpProfile, command string) error {
158+
pluginData := (*data).(*E825PluginData)
158159
glog.Info("calling AfterRunPTPCommandE825 for e825 plugin")
159160
var e825Opts E825Opts
160161
var err error
161162
var optsByteArray []byte
162-
var stdout []byte
163163

164164
e825Opts.EnableDefaultConfig = false
165165

@@ -172,23 +172,11 @@ func AfterRunPTPCommandE825(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
172172
}
173173
switch command {
174174
case "gpspipe":
175-
glog.Infof("AfterRunPTPCommandE825 doing ublx config for command: %s", command)
176-
for _, ublxOpt := range append(e825Opts.UblxCmds, getDefaultUblxCmds()...) {
177-
ublxArgs := ublxOpt.Args
178-
glog.Infof("Running /usr/bin/ubxtool with args %s", strings.Join(ublxArgs, ", "))
179-
stdout, _ = exec.Command("/usr/local/bin/ubxtool", ublxArgs...).CombinedOutput()
180-
//stdout, err = exec.Command("/usr/local/bin/ubxtool", "-p", "STATUS").CombinedOutput()
181-
if data != nil && ublxOpt.ReportOutput {
182-
_data := *data
183-
glog.Infof("Saving status to hwconfig: %s", string(stdout))
184-
var pluginData = _data.(*E825PluginData)
185-
_pluginData := *pluginData
186-
statusString := fmt.Sprintf("ublx data: %s", string(stdout))
187-
*_pluginData.hwplugins = append(*_pluginData.hwplugins, statusString)
188-
} else {
189-
glog.Infof("Not saving status to hwconfig: %s", string(stdout))
190-
}
191-
}
175+
glog.Infof("AfterRunPTPCommandE810 doing ublx config for command: %s", command)
176+
// Execute user-supplied UblxCmds first:
177+
*pluginData.hwplugins = append(*pluginData.hwplugins, e825Opts.UblxCmds.runAll()...)
178+
// Finish with the default commands:
179+
*pluginData.hwplugins = append(*pluginData.hwplugins, defaultUblxCmds().runAll()...)
192180
case "tbc-ho-exit":
193181
_, err = clockChain.EnterNormalTBC()
194182
if err != nil {
@@ -222,7 +210,7 @@ func PopulateHwConfigE825(data *interface{}, hwconfigs *[]ptpv1.HwConfig) error
222210
//*hwconfigs = append(*hwconfigs, hwConfig)
223211
if data != nil {
224212
_data := *data
225-
var pluginData = _data.(*E825PluginData)
213+
pluginData := _data.(*E825PluginData)
226214
_pluginData := *pluginData
227215
if _pluginData.hwplugins != nil {
228216
for _, _hwconfig := range *_pluginData.hwplugins {
@@ -245,7 +233,8 @@ func E825(name string) (*plugin.Plugin, *interface{}) {
245233
glog.Infof("registering e825 plugin")
246234
hwplugins := []string{}
247235
pluginData := E825PluginData{hwplugins: &hwplugins}
248-
_plugin := plugin.Plugin{Name: "e825",
236+
_plugin := plugin.Plugin{
237+
Name: "e825",
249238
OnPTPConfigChange: OnPTPConfigChangeE825,
250239
AfterRunPTPCommand: AfterRunPTPCommandE825,
251240
PopulateHwConfig: PopulateHwConfigE825,

0 commit comments

Comments
 (0)