pothosware / SoapySDRPlay2

Soapy SDR plugin for SDRPlay
MIT License
50 stars 11 forks source link

Fix unability to switch RSP2 AM port at runtime #30

Closed vsonnier closed 6 years ago

vsonnier commented 6 years ago

Greetings @guruofquality, @SDRplay and last but not least @cjcliffe :) This PR intend to fix the issue reported in CubicSDR issue https://github.com/cjcliffe/CubicSDR/issues/508.

The reported problem was the impossibility to change RSP 2 AM port at runtime, and was oberved on OSX, Linux, and myself saw it on Windows 7 x64. (latest API v2.10)

For me, the following additional calls does the trick after calling mir_sdr_AmPortSelect(amPort):

      if (streamActive) {
          mir_sdr_Reinit(&gRdB, 0.0, 0.0, mir_sdr_BW_Undefined, mir_sdr_IF_Undefined, mir_sdr_LO_Undefined, lnaState, &gRdBsystem, mir_sdr_USE_RSP_SET_GR, &sps, mir_sdr_CHANGE_AM_PORT);
      }
      //We apparently need to re-apply the current ant_sel
      mir_sdr_RSPII_AntennaControl(antSel);

The clue to solve the problem was mostly inspired by @fcrohas RSP2 support branch (commit) later superseded by the @SDRplay own patch. The difference between the two was that @fcrohas added a call to mir_sdr_Reinit() after the change of AM port, which @SDRplay branch didn't, while the API doc §3.25 indeed suggested it was needed: mir_sdr_CHANGE_AM_PORT: (preceeded by mir_sdr_AmPortSelect()) requires Uninit/Init

Still it was apparently not enough to make it work, because I needed to recall mir_sdr_RSPII_AntennaControl(antSel) for make the thing switch.

Could you please @SDRplay review this patch, to be sure it works regardless of the platform.

I should also mention that CubicSDR v0.22 has a bit buggy "Runtime Settings" management where RSP specific settings lie, adding confusion to this issue. I think I've solved that aspect on the current CubicSDR master (https://github.com/cjcliffe/CubicSDR/commit/33aa0cade6c2f8e515c7faeda789952ec346f55f and later) so please test the patch with it.

vsonnier commented 6 years ago

Thanks to SDRplay Support, some adjustements on the previous code were made which should work right so we have finally this after calling mir_sdr_AmPortSelect(amPort):


      //If Port A/B (amPort == 0) is requested
      //call the ant_sel to set the choice between A and B again, as advised by SDRPlay Support. 
      if (amPort == 0) {
          mir_sdr_RSPII_AntennaControl(antSel);
      }

      //Required : call Reinit as Specs and SDRPlay Support advised,
      //after the previous 2 API calls has been made (which can be made in any order)
      if (streamActive) {
          mir_sdr_Reinit(&gRdB, 0.0, 0.0, mir_sdr_BW_Undefined, mir_sdr_IF_Undefined, mir_sdr_LO_Undefined, lnaState, &gRdBsystem, mir_sdr_USE_RSP_SET_GR, &sps, mir_sdr_CHANGE_AM_PORT);
      }

I'm waiting for confirmation that it is working on Linux, then it'll be fine to push this PR forward I think.

vsonnier commented 6 years ago

Apparently @dunaybd saw the problem fixed with this code on a Linux Mint 18.2. Could you please accept this PR, @guruofquality ? Thanks in advance.

guruofquality commented 6 years ago

@vsonnier Yea, sure. I guess no one had any objections. FYI, you should have repo access now

vsonnier commented 6 years ago

@guruofquality Awesome, thanks !

starvald commented 6 years ago

vsonnier can you reopen the issue about port selection not working in gqrx, just pulled latest git but still only have RX in antenna selection.

guruofquality commented 6 years ago

@starvald Just to point out, that if there was a fix needed in SoapySDRPlay. Then for GQRX, you either need 1) the same fix applied to the SDRPlay support in gr-osmosdr or 2) make sure the gr-osmosdr is built with soapysdr support and gqrx is selecting the SDRPlay through the soapy support and SoapySDRPlay. Might be something to double check anyway..

starvald commented 6 years ago

using driver=sdrplay,soapy=0 device string.

compiled from git using arch aur. soapysdr-git, soapysdrplay-git, gr-osmosdr-nonfree-git then gqrx-git only get RX antenna. if i redo the steps but modify soapysdrplay-git to use fcrohas repo i get A,B and HiZ.

vsonnier commented 6 years ago

@starvald Hello ! The previous issue was about RSP2 novelties implementations. This GQRX issue is clearly another beast, for what I saw here and there, with it's own burden of pain. So you can open a new issue, but I fear it is a Gqrx problem not supporting all the exposed SoapySDRplay module services. So yes it lists "RX" under Antenna in Gqrx, because it requests the list of antenna by the Soapy Antenna API, fine. Likewise, Gqrx knows of the standard controls (AGC, PPM, Gains)...etc because they have a standard SoapySDR call for them.

Problem is all the non-standard options, including AM port and Antenna selection on RSP2 must be enumerated dynamically using the dedicated Settings API like: SoapySDR::ArgInfoList SoapySDRPlay::getSettingInfo(void) then used with readSetting, writeSetting the way CubicSDR does in a universal way.

When @SDRplay contributed the RSP2 changes, he chose to implement the changes with this "universal" settings, while @fcrohas chose to implement them as "antennas", that is why the later shows up within GQRX and not the former.

So the problem is on gr-osmosdr / Gqrx not supporting the SoapySDR API completly or incorrectly. And it's not a matter of just having A/B / High-Z or not, they are missing all the the specific settings the SoapySDR exposes.

For instance with RSP2, Cubic shows all these 'Runtime settings' additional controls : rsp2_settings_cr

starvald commented 6 years ago

thanks vsonnier, i'll carry on with fcrohas repo then.