mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-24 03:02:29 -04:00
LimeSDR support (6)
This commit is contained in:
parent
bb812b4b47
commit
527b5ef2f5
@ -94,5 +94,12 @@ bool DeviceLimeSDRParams::open(lms_info_str_t deviceStr)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceLimeSDRParams::close()
|
||||||
|
{
|
||||||
|
if (m_dev)
|
||||||
|
{
|
||||||
|
LMS_Close(m_dev);
|
||||||
|
m_dev = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
struct DeviceLimeSDRParams
|
struct DeviceLimeSDRParams
|
||||||
{
|
{
|
||||||
lms_device_t *m_dev; //!< device handle if the party has ownership else 0
|
lms_device_t *m_dev; //!< device handle if the party has ownership else 0
|
||||||
|
int m_channel; //!< logical device channel number (-1 if none)
|
||||||
int m_nbRxChannels; //!< number of Rx channels (normally 2, we'll see if we really use it...)
|
int m_nbRxChannels; //!< number of Rx channels (normally 2, we'll see if we really use it...)
|
||||||
int m_nbTxChannels; //!< number of Tx channels (normally 2, we'll see if we really use it...)
|
int m_nbTxChannels; //!< number of Tx channels (normally 2, we'll see if we really use it...)
|
||||||
lms_range_t m_lpfRangeRx; //!< Low pass filter range information (Rx side)
|
lms_range_t m_lpfRangeRx; //!< Low pass filter range information (Rx side)
|
||||||
@ -45,6 +46,7 @@ struct DeviceLimeSDRParams
|
|||||||
|
|
||||||
DeviceLimeSDRParams() :
|
DeviceLimeSDRParams() :
|
||||||
m_dev(0),
|
m_dev(0),
|
||||||
|
m_channel(-1),
|
||||||
m_nbRxChannels(0),
|
m_nbRxChannels(0),
|
||||||
m_nbTxChannels(0),
|
m_nbTxChannels(0),
|
||||||
m_sampleRate(1e6),
|
m_sampleRate(1e6),
|
||||||
@ -59,18 +61,11 @@ struct DeviceLimeSDRParams
|
|||||||
* Opens and initialize the device and obtain information (# channels, ranges, ...)
|
* Opens and initialize the device and obtain information (# channels, ranges, ...)
|
||||||
*/
|
*/
|
||||||
bool open(lms_info_str_t deviceStr);
|
bool open(lms_info_str_t deviceStr);
|
||||||
|
void close();
|
||||||
|
|
||||||
~DeviceLimeSDRParams()
|
~DeviceLimeSDRParams()
|
||||||
{
|
{
|
||||||
if (m_dev)
|
|
||||||
{
|
|
||||||
LMS_Close(m_dev);
|
|
||||||
m_dev = 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void close();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DEVICES_LIMESDR_DEVICELIMESDRPARAM_H_ */
|
#endif /* DEVICES_LIMESDR_DEVICELIMESDRPARAM_H_ */
|
||||||
|
153
plugins/samplesource/limesdrinput/limesdrinput.cpp
Normal file
153
plugins/samplesource/limesdrinput/limesdrinput.cpp
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <QMutexLocker>
|
||||||
|
#include <string.h>
|
||||||
|
#include "limesdrinput.h"
|
||||||
|
|
||||||
|
|
||||||
|
LimeSDRInput::LimeSDRInput(DeviceSourceAPI *deviceAPI) :
|
||||||
|
m_deviceAPI(deviceAPI),
|
||||||
|
m_settings(),
|
||||||
|
m_limeSDRInputThread(0),
|
||||||
|
m_deviceDescription(),
|
||||||
|
m_running(false)
|
||||||
|
{
|
||||||
|
openDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
LimeSDRInput::~LimeSDRInput()
|
||||||
|
{
|
||||||
|
if (m_running) stop();
|
||||||
|
closeDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LimeSDRInput::openDevice()
|
||||||
|
{
|
||||||
|
// look for Rx buddies and get reference to common parameters
|
||||||
|
// if there is a channel left take the first available
|
||||||
|
if (m_deviceAPI->getSourceBuddies().size() > 0) // look source sibling first
|
||||||
|
{
|
||||||
|
DeviceSinkAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
|
||||||
|
m_deviceParams = *(sourceBuddy->getBuddySharedPtr()); // copy parameters
|
||||||
|
|
||||||
|
if (m_deviceAPI->getSourceBuddies().size() == m_deviceParams.m_nbRxChannels)
|
||||||
|
{
|
||||||
|
return false; // no more Rx channels available in device
|
||||||
|
}
|
||||||
|
// look for unused channel number
|
||||||
|
char *busyChannels = new char[m_deviceParams.m_nbRxChannels];
|
||||||
|
memset(busyChannels, 0, m_deviceParams.m_nbRxChannels);
|
||||||
|
|
||||||
|
for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++)
|
||||||
|
{
|
||||||
|
DeviceSinkAPI *buddy = m_deviceAPI->getSourceBuddies()[i];
|
||||||
|
DeviceLimeSDRParams *buddyParms = buddy->getBuddySharedPtr();
|
||||||
|
busyChannels[buddyParms->m_channel] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ch = 0;
|
||||||
|
|
||||||
|
for (;ch < m_deviceParams.m_nbRxChannels; ch++)
|
||||||
|
{
|
||||||
|
if (busyChannels[ch] == 0) {
|
||||||
|
break; // first available is the good one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceParams.m_channel = ch;
|
||||||
|
delete[] busyChannels;
|
||||||
|
}
|
||||||
|
// look for Tx buddies and get reference to common parameters
|
||||||
|
// take the first Rx channel
|
||||||
|
else if (m_deviceAPI->getSinkBuddies().size() > 0) // then sink
|
||||||
|
{
|
||||||
|
DeviceSinkAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
|
||||||
|
m_deviceParams = *(sinkBuddy->getBuddySharedPtr()); // copy parameters
|
||||||
|
m_deviceParams.m_channel = 0; // take first channel
|
||||||
|
}
|
||||||
|
// There are no buddies then create the first LimeSDR common parameters
|
||||||
|
// open the device this will also populate common fields
|
||||||
|
// take the first Rx channel
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_deviceParams.open((lms_info_str_t) qPrintable(m_deviceAPI->getSampleSourceSerial()));
|
||||||
|
m_deviceParams.m_channel = 0; // take first channel
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceAPI->setBuddySharedPtr(&m_deviceParams); // propagate common parameters to API
|
||||||
|
|
||||||
|
// TODO: acquire the channel
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LimeSDRInput::closeDevice()
|
||||||
|
{
|
||||||
|
// TODO: release the channel
|
||||||
|
|
||||||
|
// No buddies effectively close the device
|
||||||
|
if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0))
|
||||||
|
{
|
||||||
|
m_deviceParams.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LimeSDRInput::start(int device)
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
|
if (!m_deviceParams.m_dev) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_running) stop();
|
||||||
|
|
||||||
|
if ((m_limeSDRInputThread = new LimeSDRInputThread(m_deviceParams.m_dev, &m_sampleFifo)) == 0)
|
||||||
|
{
|
||||||
|
qFatal("LimeSDRInput::start: out of memory");
|
||||||
|
stop();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_limeSDRInputThread->setSamplerate(m_settings.m_devSampleRate);
|
||||||
|
m_limeSDRInputThread->setLog2Decimation(m_settings.m_log2Decim);
|
||||||
|
m_limeSDRInputThread->setFcPos((int) m_settings.m_fcPos);
|
||||||
|
|
||||||
|
m_limeSDRInputThread->startWork();
|
||||||
|
|
||||||
|
mutexLocker.unlock();
|
||||||
|
|
||||||
|
applySettings(m_settings, true);
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LimeSDRInput::stop()
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
|
if (m_limeSDRInputThread != 0)
|
||||||
|
{
|
||||||
|
m_limeSDRInputThread->stopWork();
|
||||||
|
delete m_limeSDRInputThread;
|
||||||
|
m_limeSDRInputThread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_running = false;
|
||||||
|
}
|
||||||
|
|
58
plugins/samplesource/limesdrinput/limesdrinput.h
Normal file
58
plugins/samplesource/limesdrinput/limesdrinput.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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/>. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef PLUGINS_SAMPLESOURCE_LIMESDRINPUT_LIMESDRINPUT_H_
|
||||||
|
#define PLUGINS_SAMPLESOURCE_LIMESDRINPUT_LIMESDRINPUT_H_
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include "dsp/devicesamplesource.h"
|
||||||
|
#include "limesdr/devicelimesdrparam.h"
|
||||||
|
#include "limesdrinputsettings.h"
|
||||||
|
|
||||||
|
class DeviceSourceAPI;
|
||||||
|
class LimeSDRInputThread;
|
||||||
|
struct DeviceLimeSDRParams;
|
||||||
|
|
||||||
|
class LimeSDRInput : public DeviceSampleSource
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LimeSDRInput(DeviceSourceAPI *deviceAPI);
|
||||||
|
virtual ~LimeSDRInput();
|
||||||
|
|
||||||
|
virtual bool start(int device);
|
||||||
|
virtual void stop();
|
||||||
|
|
||||||
|
virtual const QString& getDeviceDescription() const;
|
||||||
|
virtual int getSampleRate() const;
|
||||||
|
virtual quint64 getCenterFrequency() const;
|
||||||
|
|
||||||
|
virtual bool handleMessage(const Message& message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeviceSourceAPI *m_deviceAPI;
|
||||||
|
QMutex m_mutex;
|
||||||
|
LimeSDRInputSettings m_settings;
|
||||||
|
LimeSDRInputThread* m_limeSDRInputThread;
|
||||||
|
QString m_deviceDescription;
|
||||||
|
bool m_running;
|
||||||
|
DeviceLimeSDRParams m_deviceParams;
|
||||||
|
|
||||||
|
bool openDevice();
|
||||||
|
void closeDevice();
|
||||||
|
bool applySettings(const LimeSDRInputSettings& settings, bool force);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PLUGINS_SAMPLESOURCE_LIMESDRINPUT_LIMESDRINPUT_H_ */
|
25
plugins/samplesource/limesdrinput/limesdrinputsettings.h
Normal file
25
plugins/samplesource/limesdrinput/limesdrinputsettings.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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/>. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef PLUGINS_SAMPLESOURCE_LIMESDRINPUT_LIMESDRINPUTSETTINGS_H_
|
||||||
|
#define PLUGINS_SAMPLESOURCE_LIMESDRINPUT_LIMESDRINPUTSETTINGS_H_
|
||||||
|
|
||||||
|
struct LimeSDRInputSettings
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PLUGINS_SAMPLESOURCE_LIMESDRINPUT_LIMESDRINPUTSETTINGS_H_ */
|
Loading…
x
Reference in New Issue
Block a user