fix(channel6): ignore 'no value' signal for drive mode

This commit is contained in:
Cyrille Nofficial 2022-08-18 18:22:24 +02:00
parent 4f17175e01
commit 14d5c605e7
2 changed files with 17 additions and 3 deletions

View File

@ -21,7 +21,7 @@ const (
)
var (
serialLineRegex = regexp.MustCompile(`(?P<timestamp>\d+),(?P<channel_1>\d+),(?P<channel_2>\d+),(?P<channel_3>\d+),(?P<channel_4>\d+),(?P<channel_5>\d+),(?P<channel_6>\d+),(?P<channel_7>\d+),(?P<channel_8>\d+),(?P<frequency>\d+)`)
serialLineRegex = regexp.MustCompile(`(?P<timestamp>\d+),(?P<channel_1>\d+),(?P<channel_2>\d+),(?P<channel_3>\d+),(?P<channel_4>\d+),(?P<channel_5>\d+),(?P<channel_6>-?\d+),(?P<channel_7>\d+),(?P<channel_8>\d+),(?P<frequency>\d+)`)
DefaultPwmThrottle = PWMConfig{
Min: MinPwmThrottle,
Max: MaxPwmThrottle,
@ -255,6 +255,10 @@ func (a *Part) processChannel6(v string) {
zap.S().Errorf("invalid value for channel6 'drive-mode', should be an int: %v", err)
return
}
if value < 0 {
// No value, ignore it
return
}
if value > 1800 {
if a.driveMode != events.DriveMode_PILOT {
zap.S().Infof("Update channel 6 'drive-mode' with value %v, new user_mode: %v", value, events.DriveMode_PILOT)

View File

@ -81,9 +81,9 @@ func TestArduinoPart_Update(t *testing.T) {
fmt.Sprintf("12345,%d,%d,%d,%d,%d,%d,%d,%d,50\n", channel1, channel2, channel3, channel4, channel5, channel6, channel7, channel8),
defaultPwmThrottleConfig, -1., -1.,
events.DriveMode_USER, false},
{"Unparsable line",
{"Invalid line",
"12350,invalid line\n", defaultPwmThrottleConfig,
-1., -1., events.DriveMode_USER, false},
-1., -1., events.DriveMode_INVALID, false},
{"Switch record on",
fmt.Sprintf("12355,%d,%d,%d,%d,%d,%d,%d,%d,50\n", channel1, channel2, channel3, channel4, 998, channel6, channel7, channel8),
defaultPwmThrottleConfig, -1., -1., events.DriveMode_USER, true},
@ -150,6 +150,15 @@ func TestArduinoPart_Update(t *testing.T) {
{"Use 2nd rc: use channels 7 and 8",
fmt.Sprintf("12440,%d,%d,%d,%d,%d,%d,%d,%d,50\n", 1000, 1000, 1950, channel4, channel5, channel6, 2000, 2008),
defaultPwmThrottleConfig, 1., 1, events.DriveMode_USER, false},
{"Drive Mode: user",
fmt.Sprintf("12430,%d,%d,%d,%d,%d,%d,%d,%d,50\n", channel1, channel6, channel3, channel4, channel5, 900, channel7, channel8),
defaultPwmThrottleConfig, -1., -1., events.DriveMode_USER, false},
{"Drive Mode: pilot",
fmt.Sprintf("12430,%d,%d,%d,%d,%d,%d,%d,%d,50\n", channel1, channel6, channel3, channel4, channel5, 1950, channel7, channel8),
defaultPwmThrottleConfig, -1., -1., events.DriveMode_PILOT, false},
{"Drive Mode: no value",
fmt.Sprintf("12430,%d,%d,%d,%d,%d,%d,%d,%d,50\n", channel1, channel6, channel3, channel4, channel5, -1, channel7, channel8),
defaultPwmThrottleConfig, -1., -1., events.DriveMode_INVALID, false},
}
for _, c := range cases {
@ -165,6 +174,7 @@ func TestArduinoPart_Update(t *testing.T) {
}
a.pwmThrottleConfig = c.throttlePwmConfig
a.driveMode = events.DriveMode_INVALID
time.Sleep(10 * time.Millisecond)
a.mutex.Lock()