fix: Save and close taking time when Flex or Icom is not connected
This commit is contained in:
@@ -444,8 +444,14 @@ func (b *IcomSerial) write(payload ...byte) error {
|
||||
|
||||
// recv waits for a frame the reader routed to respCh that satisfies match, or
|
||||
// times out. The reader has already discarded echoes and split off scope frames,
|
||||
// so recv only ever sees candidate control replies.
|
||||
// so recv only ever sees candidate control replies. It also bails out at once if
|
||||
// Interrupt() fires (Stop) so an in-flight ReadState — which can be a dozen reads,
|
||||
// each up to icomReadTimeout when the rig is slow — doesn't make Stop/Save-&-Close
|
||||
// wait several seconds for the poll goroutine to finish.
|
||||
func (b *IcomSerial) recv(timeout time.Duration, match func(civ.Decoded) bool) (civ.Decoded, error) {
|
||||
b.dialMu.Lock()
|
||||
cancel := b.dialCancel
|
||||
b.dialMu.Unlock()
|
||||
deadline := time.After(timeout)
|
||||
for {
|
||||
select {
|
||||
@@ -453,6 +459,8 @@ func (b *IcomSerial) recv(timeout time.Duration, match func(civ.Decoded) bool) (
|
||||
if match(f) {
|
||||
return f, nil
|
||||
}
|
||||
case <-cancel:
|
||||
return civ.Decoded{}, fmt.Errorf("icom: interrupted")
|
||||
case <-deadline:
|
||||
return civ.Decoded{}, fmt.Errorf("icom: timeout waiting for response")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user