check on bug

main
DustyP 9 months ago
parent b52a425754
commit 7e1303cb9c

@ -179,29 +179,11 @@ func (dc *DerbyClock) readLoop() {
continue continue
} }
// If we hit a newline, this might be the end of all results
if b[0] == '\n' {
// Check if we should consider the race complete
dc.mu.Lock()
if dc.status == StatusRunning {
dc.status = StatusFinished
dc.mu.Unlock()
// Send race complete event
dc.eventChan <- Event{Type: EventRaceComplete}
} else {
dc.mu.Unlock()
}
// Clear the buffer after a newline
buffer = buffer[:0]
}
// Add the byte to our buffer // Add the byte to our buffer
buffer = append(buffer, b[0]) buffer = append(buffer, b[0])
// Check for race start signal "C\r\n" // Check for race start signal "C\r\n"
if len(buffer) >= 3 && string(buffer[len(buffer)-3:]) == "C\r\n" { if b[0] == 'C' {
dc.mu.Lock() dc.mu.Lock()
dc.status = StatusRunning dc.status = StatusRunning
dc.mu.Unlock() dc.mu.Unlock()
@ -212,11 +194,7 @@ func (dc *DerbyClock) readLoop() {
// Clear the buffer // Clear the buffer
buffer = buffer[:0] buffer = buffer[:0]
continue continue
} } else if b[0] == ' ' {
// Check for lane result pattern (n=t.ttttc)
// We need to look for an equals sign followed by digits, a period, more digits, and a finish character
if b[0] == ' ' {
// These characters could indicate a complete result or a separator // These characters could indicate a complete result or a separator
// Try to extract a result from the buffer // Try to extract a result from the buffer
dc.mu.Lock() dc.mu.Lock()
@ -231,8 +209,22 @@ func (dc *DerbyClock) readLoop() {
// Clear the buffer after a result is extracted // Clear the buffer after a result is extracted
buffer = buffer[:0] buffer = buffer[:0]
dc.mu.Unlock() dc.mu.Unlock()
} } else if b[0] == '\n' {
// Check if we should consider the race complete
dc.mu.Lock()
if dc.status == StatusRunning {
dc.status = StatusFinished
dc.mu.Unlock()
// Send race complete event
dc.eventChan <- Event{Type: EventRaceComplete}
} else {
dc.mu.Unlock()
}
// Clear the buffer after a newline
buffer = buffer[:0]
}
} }
} }
} }

Loading…
Cancel
Save