Skip to content

Commit

Permalink
canrunner: Set cyclic transmission on RunMessageTransmitter init
Browse files Browse the repository at this point in the history
Check before starting the transmit loop if cyclic transmission has already been requested and enable it if so.
  • Loading branch information
Olle Sandberg authored and odsod committed Jun 11, 2020
1 parent 644519b commit 7fca08f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/canrunner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ func RunMessageTransmitter(
cyclicTransmissionTicker.Stop()
cyclicTransmissionTicker = nil
}
setCyclicTransmission := func() {
l.Lock()
isCyclicTransmissionEnabled := m.IsCyclicTransmissionEnabled()
l.Unlock()
if isCyclicTransmissionEnabled {
enableCyclicTransmission()
} else {
disableCyclicTransmission()
}
}
transmit := func() error {
l.Lock()
hook := m.BeforeTransmitHook()
Expand All @@ -173,20 +183,14 @@ func RunMessageTransmitter(
}
ctxDone := ctx.Done()
transmitEventChan := m.TransmitEventChan()
setCyclicTransmission()
wakeUpChan := m.WakeUpChan()
for {
select {
case <-ctxDone:
return nil
case <-wakeUpChan:
l.Lock()
isCyclicTransmissionEnabled := m.IsCyclicTransmissionEnabled()
l.Unlock()
if isCyclicTransmissionEnabled {
enableCyclicTransmission()
} else {
disableCyclicTransmission()
}
setCyclicTransmission()
case <-transmitEventChan:
if err := transmit(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions pkg/canrunner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func TestRunMessageTransmitter_TransmitEventMessage(t *testing.T) {
g.Go(func() error {
return canrunner.RunMessageTransmitter(ctx, tx, node, msg, clock)
})
// then message should be queried for if it has cyclic transmission enabled
node.EXPECT().Lock()
msg.EXPECT().IsCyclicTransmissionEnabled()
node.EXPECT().Unlock()
// then the node should be locked
node.EXPECT().Lock()
// and the time should be queried
Expand Down

0 comments on commit 7fca08f

Please sign in to comment.