Redhawk FEI采样率容差检查失败?

时间:2017-12-24 16:29:36

标签: redhawksdr

当我尝试通过IDE进行分配时,我正在构建Redhawk 2.1.2 FEI设备并遇到容忍检查失败(没有尝试过python接口或任何东西)。该请求是8 MHz,我得到的返回值为7999999.93575246725231409 Hz,在20%容差范围内是可以接受的,但我仍然会收到此错误:

2017-12-24 11:27:10 DEBUG FrontendTunerDevice:484 -  allocateCapacity - SR requested: 8000000.000000  SR got: 7999999.935752
2017-12-24 11:27:10 INFO  FrontendTunerDevice:490 - allocateCapacity(0): returned sr 7999999.935752 does not meet tolerance criteria of 20.000000 percent

来自frontendInterfaces/libsrc/cpp/fe_tuner_device.cpp的违规代码:

// check tolerances
if( (floatingPointCompare(frontend_tuner_allocation.sample_rate,0)!=0) &&
    (floatingPointCompare(frontend_tuner_status[tuner_id].sample_rate,frontend_tuner_allocation.sample_rate)<0 || 
     floatingPointCompare(frontend_tuner_status[tuner_id].sample_rate,frontend_tuner_allocation.sample_rate+frontend_tuner_allocation.sample_rate * frontend_tuner_allocation.sample_rate_tolerance/100.0)>0 ))
{
    std::ostringstream eout;
    eout<<std::fixed<<"allocateCapacity("<<int(tuner_id)<<"): returned sr "<<frontend_tuner_status[tuner_id].sample_rate<<" does not meet tolerance criteria of "<<frontend_tuner_allocation.sample_rate_tolerance<<" percent";
    LOG_INFO(FrontendTunerDevice<TunerStatusStructType>, eout.str());
    throw std::logic_error(eout.str().c_str());
}

来自frontendInterfaces/libsrc/cpp/fe_tuner_device.h的函数:

inline double floatingPointCompare(double lhs, double rhs, size_t places = 1){
    return round((lhs-rhs)*pow(10,places));
    /*if(round((lhs-rhs)*(pow(10,places))) == 0)
        return 0; // equal
    if(lhs<rhs)
        return -1; // lhs < rhs
    return 1; // lhs > rhs*/
}

我实际上已经复制到非Redhawk C ++程序中,我用它来测试设备接口和检查传递。我把所有东西都打破了,发现差异,并注意到在Redhawk中,从设备返回的采样率(或者至少打印到屏幕上)与Redhawk外部的采样率略有不同 - 只是一小部分Hz:

// in Redhawk using cout::precision(17)
Sample Rate: 7999999.93575246725231409
// outside Redhawk using cout::precision(17)
Sample Rate: 7999999.96948242187500000

我不知道为什么返回的实际采样率存在差异,但在Redhawk版本中,它只是使得检查的第二部分失败了:

floatingPointCompare(7999999.93575246725231409,8000000.00000000000000000)<0
1

基本上是因为:

double a = 7999999.93575246725231409 - 8000000.00000000000000000; // = -0.06424753274768591
double b = pow(10,1); // = 10.00000000000000000
double c = a*b;       // = -0.6424753274 
double d = round(c);  // = -1.00000000000000000

因此,如果返回的采样率小于请求值超过0.049999 Hz,则无论容差%,分配都会失败?也许我在这里错过了一些东西。

2 个答案:

答案 0 :(得分:1)

公差检查指定为最小数量加上一个增量,而不是与请求数量的差异(正负)。

答案 1 :(得分:0)

应该有一个文档在某个地方详细描述了这个,但我去了FMRdsSimulator设备的来源。

    // For FEI tolerance, it is not a +/- it's give me this or better.

    float minAcceptableSampleRate = request.sample_rate;

    float maxAcceptableSampleRate = (1 + request.sample_rate_tolerance/100.0) * request.sample_rate;

这应该解释分配失败的原因。