Giter Site home page Giter Site logo

Comments (6)

guruofquality avatar guruofquality commented on May 25, 2024

The implementation is transparently calling bladerf_get_gain and bladerf_set_gain:

So it might be a bug in libbladerf. You can put a few prints in there to confirm its libbladerf?

from soapybladerf.

drahosj avatar drahosj commented on May 25, 2024

from soapybladerf.

KarlL2 avatar KarlL2 commented on May 25, 2024

Thanks @drahosj, it seems I first need to explicitly disable the gain, before I can set it.

I don't know if it's the expected/usual behavior.

There still seem to be other errors on the libbladerf part, see Nuand/bladeRF#731 .

from soapybladerf.

KarlL2 avatar KarlL2 commented on May 25, 2024

I found what the real issue was, for the BladeRF2.

In BladeRF test_gain.c, there is

/* Enable channel (necessary for RX gain changes to register
* on bladerf2) */
status = bladerf_enable_module(dev, ch, true);

I've currently updated the SoapyBladeRF code to this

void bladeRF_SoapySDR::setGain(const int direction, const size_t channel, const double value)
{
    // Enable channel (necessary for RX gain changes to register on bladerf2)
    // See bladeRF/host/libraries/libbladeRF_test/test_ctrl/src/test_gain.c
    int ret = bladerf_enable_module(_dev, _toch(direction, channel), true);
    if (ret != 0)
    {
        SoapySDR::logf(SOAPY_SDR_ERROR, "bladerf_enable_module returned %s", _err2str(ret).c_str());
        throw std::runtime_error("setGain() " + _err2str(ret));
    }

    ret = bladerf_set_gain(_dev, _toch(direction, channel), bladerf_gain(std::round(value)));
    if (ret != 0)
    {
        SoapySDR::logf(SOAPY_SDR_ERROR, "bladerf_set_gain(%f) returned %s", value, _err2str(ret).c_str());
        throw std::runtime_error("setGain() " + _err2str(ret));
    }
}

I'm not sure if it's possible to know if the channel is already enabled to avoid redoing it, nor if it causes issues if it's already opened.

Also this might make more sense for the BladeRF code to take care of that...

from soapybladerf.

guruofquality avatar guruofquality commented on May 25, 2024

It seems like we should be able to call bladerf_enable_module in the constructor then. Can you try removing it from setup/closeStream, and move them to the constructor instead?

from soapybladerf.

KarlL2 avatar KarlL2 commented on May 25, 2024

It seems to be working (I haven't done extensive tests). I removed the bladerf_enable_module calls from setupStream and closeStream and created a simple function to enable or disable all channels in both directions, that I call in the constructor and destructor:

void bladeRF_SoapySDR::_enable_or_disable_module(const bool enable, const bool throwOnError) {
  std::vector<int> directions;
  directions.push_back(SOAPY_SDR_RX);
  directions.push_back(SOAPY_SDR_TX);

  std::vector<size_t> channels;
  channels.push_back(0);
  if (_isBladeRF2)
    channels.push_back(1);

  for (const auto dir : directions) {
    for (const auto ch : channels)
    {
      const int ret = bladerf_enable_module(_dev, _toch(dir, ch), enable);
      if (ret != 0)
      {
        SoapySDR::logf(SOAPY_SDR_ERROR, "bladerf_enable_module(%s) returned %s", enable ? "true" : "false", _err2str(ret).c_str());
        if (throwOnError)
          throw std::runtime_error("bladerf_enable_module() " + _err2str(ret));
      }
    }
  }

  directions.clear();
  channels.clear();
}

from soapybladerf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.