Skip to content

Commit

Permalink
Keep auto-recorder log file open during breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Jul 24, 2022
1 parent f6d168b commit 0e109a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/auto/auto-recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ func (r *Recorder) receiveRefereeMessage(data []byte, _ *net.UDPAddr) {
if err := r.Recorder.StartWithName(name); err != nil {
log.Println("Failed to start recorder: ", err)
}
} else if r.Recorder.IsRunning() && (isNoGameStage(&message) || !isTeamSet(&message)) {
log.Println("Stop recording")
if err := r.Recorder.Stop(); err != nil {
log.Println("Failed to stop recorder: ", err)
} else if r.Recorder.IsRunning() {
if isPostGame(&message) || !isTeamSet(&message) {
log.Println("Stop recording")
if err := r.Recorder.Stop(); err != nil {
log.Println("Failed to stop recorder: ", err)
}
} else if !r.Recorder.Paused && isBreakStage(&message) {
log.Println("Pause recording")
r.Recorder.Paused = true
} else if r.Recorder.Paused && !isBreakStage(&message) {
log.Println("Resume recording")
r.Recorder.Paused = false
}
}
}
Expand Down Expand Up @@ -83,19 +91,22 @@ func isTeamSet(message *referee.Referee) bool {
*message.Blue.Name != "" && *message.Yellow.Name != ""
}

func isNoGameStage(message *referee.Referee) bool {
func isBreakStage(message *referee.Referee) bool {
switch *message.Stage {
case referee.Referee_EXTRA_HALF_TIME,
referee.Referee_NORMAL_HALF_TIME,
referee.Referee_PENALTY_SHOOTOUT_BREAK,
referee.Referee_POST_GAME,
referee.Referee_EXTRA_TIME_BREAK:
return true
default:
return false
}
}

func isPostGame(message *referee.Referee) bool {
return *message.Stage == referee.Referee_POST_GAME
}

func isPreStage(message *referee.Referee) bool {
switch *message.Stage {
case referee.Referee_NORMAL_FIRST_HALF_PRE,
Expand Down
5 changes: 5 additions & 0 deletions pkg/persistence/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Recorder struct {
Slots []*RecorderSlot
writer Writer
running bool
Paused bool
mutex sync.Mutex
}

Expand Down Expand Up @@ -50,6 +51,7 @@ func (r *Recorder) StartWithName(name string) error {
slot.server.Consumer = r.slotConsumer(slot)
slot.server.Start()
}
r.Paused = false
r.running = true
return nil
}
Expand Down Expand Up @@ -85,6 +87,9 @@ func (r *Recorder) openLogWriter(logFileName string) error {
}

func (r *Recorder) processSlotMessage(slot *RecorderSlot, data []byte) {
if r.Paused {
return
}
timestamp := time.Now().UnixNano()
logMessage := Message{Timestamp: timestamp, MessageType: slot.MessageType, Message: data}
r.mutex.Lock()
Expand Down

0 comments on commit 0e109a5

Please sign in to comment.