소스 검색

fix: make Pluto live LO retune fail loudly and avoid redundant channel lookups

Cache altvoltage1 during Configure(), clear it in cleanup(), and use the cached channel for Tune() instead of calling findChannel on every retune. Tune() now checks the direct iio_channel_attr_write_longlong return code and reports LO write failures back to the caller with the failing frequency and libiio error code.
tags/v0.9.0
Jan Svabenik 1 개월 전
부모
커밋
c93607625d
1개의 변경된 파일16개의 추가작업 그리고 6개의 파일을 삭제
  1. +16
    -6
      internal/platform/plutosdr/pluto_windows.go

+ 16
- 6
internal/platform/plutosdr/pluto_windows.go 파일 보기

@@ -110,6 +110,7 @@ type PlutoDriver struct {
phyDev uintptr // iio_device* (ad9361-phy)
chanI uintptr // iio_channel* TX I
chanQ uintptr // iio_channel* TX Q
chanLO uintptr // iio_channel* TX LO (altvoltage1), cached for Tune()
buf uintptr // iio_buffer*
bufSize int // samples per buffer push

@@ -204,6 +205,7 @@ func (d *PlutoDriver) Configure(_ context.Context, cfg platform.SoapyConfig) err

// TX LO frequency
phyChanLO := d.findChannel(phyDev, "altvoltage1", true) // TX LO
d.chanLO = phyChanLO // cache for Tune()
if phyChanLO != 0 {
freqHz := int64(cfg.CenterFreqHz)
if freqHz <= 0 {
@@ -371,14 +373,21 @@ func (d *PlutoDriver) Flush(_ context.Context) error { return nil }
func (d *PlutoDriver) Tune(_ context.Context, freqHz float64) error {
d.mu.Lock()
defer d.mu.Unlock()
if d.phyDev == 0 {
return fmt.Errorf("pluto: not configured")
if !d.configured || d.chanLO == 0 {
return fmt.Errorf("pluto: not configured or LO channel not available")
}
if d.lib.pChannelAttrWriteLongLong == nil {
return fmt.Errorf("pluto: iio_channel_attr_write_longlong not loaded")
}
phyChanLO := d.findChannel(d.phyDev, "altvoltage1", true)
if phyChanLO == 0 {
return fmt.Errorf("pluto: TX LO channel not found")
cAttr, _ := syscall.BytePtrFromString("frequency")
ret, _, _ := d.lib.pChannelAttrWriteLongLong.Call(
d.chanLO,
uintptr(unsafe.Pointer(cAttr)),
uintptr(int64(freqHz)),
)
if int32(ret) < 0 {
return fmt.Errorf("pluto: LO tune to %.0f Hz failed (iio rc=%d)", freqHz, int32(ret))
}
d.writeChanAttrLL(phyChanLO, "frequency", int64(freqHz))
return nil
}

@@ -420,6 +429,7 @@ func (d *PlutoDriver) cleanup() {
d.disableChannel(d.chanQ)
d.chanQ = 0
}
d.chanLO = 0 // config-only channel, no disable needed
if d.ctx != 0 && d.lib.pDestroyCtx != nil {
d.lib.pDestroyCtx.Call(d.ctx)
d.ctx = 0


불러오는 중...
취소
저장