1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-08 01:26:01 -05:00
sdrangel/devices/limesdr/devicelimesdr.cpp

71 lines
2.7 KiB
C++
Raw Normal View History

2017-04-20 12:21:01 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#include <cstring>
#include "devicelimesdr.h"
bool DeviceLimeSDR::setNCOFrequency(lms_device_t *device, bool dir_tx, std::size_t chan, bool enable, float frequency)
{
if (enable)
{
bool positive;
2017-04-20 14:18:50 -04:00
float_type freqs[LMS_NCO_VAL_COUNT];
float_type phos[LMS_NCO_VAL_COUNT];
2017-04-20 12:21:01 -04:00
if (LMS_GetNCOFrequency(device, dir_tx, chan, freqs, phos) < 0)
{
fprintf(stderr, "DeviceLimeSDR::setNCOFrequency: cannot get NCO frequencies and phases\n");
}
if (frequency < 0)
{
positive = false;
frequency = -frequency;
}
else
{
positive = true;
}
freqs[0] = frequency;
2017-04-20 14:18:50 -04:00
if (LMS_SetNCOFrequency(device, dir_tx, chan, freqs, 0.0f) < 0)
2017-04-20 12:21:01 -04:00
{
fprintf(stderr, "DeviceLimeSDR::setNCOFrequency: cannot set frequency to %f\n", frequency);
return false;
}
if (LMS_SetNCOIndex(device, dir_tx, chan, 0, !positive) < 0)
2017-04-20 12:21:01 -04:00
{
fprintf(stderr, "DeviceLimeSDR::setNCOFrequency: cannot set conversion direction %sfreq\n", positive ? "+" : "-");
2017-04-20 12:21:01 -04:00
return false;
}
return true;
}
else
{
if (LMS_SetNCOIndex(device, dir_tx, chan, LMS_NCO_VAL_COUNT, true) < 0)
2017-04-20 12:21:01 -04:00
{
fprintf(stderr, "DeviceLimeSDR::setNCOFrequency: cannot disable NCO\n");
2017-04-20 12:21:01 -04:00
return false;
}
}
}