LimeSDR support (7)

pull/27/head
f4exb 2017-04-14 18:30:37 +02:00
rodzic 43c4d79443
commit 67bb7353a8
4 zmienionych plików z 123 dodań i 35 usunięć

Wyświetl plik

@ -28,8 +28,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
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)
@ -46,7 +45,6 @@ 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),
@ -62,6 +60,7 @@ struct DeviceLimeSDRParams
*/ */
bool open(lms_info_str_t deviceStr); bool open(lms_info_str_t deviceStr);
void close(); void close();
lms_device_t *getDevice() { return m_dev; }
~DeviceLimeSDRParams() ~DeviceLimeSDRParams()
{ {

Wyświetl plik

@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 DEVICES_LIMESDR_DEVICELIMESDRSHARED_H_
#define DEVICES_LIMESDR_DEVICELIMESDRSHARED_H_
#include <cstddef>
#include "devicelimesdrparam.h"
/**
* Structure shared by a buddy with other buddies
*/
struct DeviceLimeSDRShared
{
DeviceLimeSDRParams *m_deviceParams; //!< unique hardware device parameters
std::size_t m_channel; //!< logical device channel number (-1 if none)
DeviceLimeSDRShared() :
m_deviceParams(0),
m_channel(-1)
{}
~DeviceLimeSDRShared()
{}
};
#endif /* DEVICES_LIMESDR_DEVICELIMESDRSHARED_H_ */

Wyświetl plik

@ -15,8 +15,12 @@
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include <QMutexLocker> #include <QMutexLocker>
#include <cstddef>
#include <string.h> #include <string.h>
#include "lime/LimeSuite.h"
#include "limesdrinput.h" #include "limesdrinput.h"
#include "limesdr/devicelimesdrparam.h"
LimeSDRInput::LimeSDRInput(DeviceSourceAPI *deviceAPI) : LimeSDRInput::LimeSDRInput(DeviceSourceAPI *deviceAPI) :
@ -42,33 +46,40 @@ bool LimeSDRInput::openDevice()
if (m_deviceAPI->getSourceBuddies().size() > 0) // look source sibling first if (m_deviceAPI->getSourceBuddies().size() > 0) // look source sibling first
{ {
DeviceSinkAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; DeviceSinkAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
m_deviceParams = *(sourceBuddy->getBuddySharedPtr()); // copy parameters m_deviceShared = *(sourceBuddy->getBuddySharedPtr()); // copy shared data
DeviceLimeSDRParams *deviceParams = m_deviceShared.m_deviceParams; // get device parameters
if (m_deviceAPI->getSourceBuddies().size() == m_deviceParams.m_nbRxChannels) if (deviceParams == 0)
{
qCritical("LimeSDRInput::openDevice: cannot get device parameters from Rx buddy");
return false; // the device params should have been created by the buddy
}
if (m_deviceAPI->getSourceBuddies().size() == deviceParams->m_nbRxChannels)
{ {
return false; // no more Rx channels available in device return false; // no more Rx channels available in device
} }
// look for unused channel number // look for unused channel number
char *busyChannels = new char[m_deviceParams.m_nbRxChannels]; char *busyChannels = new char[deviceParams->m_nbRxChannels];
memset(busyChannels, 0, m_deviceParams.m_nbRxChannels); memset(busyChannels, 0, deviceParams->m_nbRxChannels);
for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++) for (int i = 0; i < m_deviceAPI->getSourceBuddies().size(); i++)
{ {
DeviceSinkAPI *buddy = m_deviceAPI->getSourceBuddies()[i]; DeviceSinkAPI *buddy = m_deviceAPI->getSourceBuddies()[i];
DeviceLimeSDRParams *buddyParms = buddy->getBuddySharedPtr(); DeviceLimeSDRShared *buddyShared = buddy->getBuddySharedPtr();
busyChannels[buddyParms->m_channel] = 1; busyChannels[buddyShared->m_channel] = 1;
} }
int ch = 0; std::size_t ch = 0;
for (;ch < m_deviceParams.m_nbRxChannels; ch++) for (;ch < deviceParams->m_nbRxChannels; ch++)
{ {
if (busyChannels[ch] == 0) { if (busyChannels[ch] == 0) {
break; // first available is the good one break; // first available is the good one
} }
} }
m_deviceParams.m_channel = ch; m_deviceShared.m_channel = ch;
delete[] busyChannels; delete[] busyChannels;
} }
// look for Tx buddies and get reference to common parameters // look for Tx buddies and get reference to common parameters
@ -76,63 +87,101 @@ bool LimeSDRInput::openDevice()
else if (m_deviceAPI->getSinkBuddies().size() > 0) // then sink else if (m_deviceAPI->getSinkBuddies().size() > 0) // then sink
{ {
DeviceSinkAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; DeviceSinkAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
m_deviceParams = *(sinkBuddy->getBuddySharedPtr()); // copy parameters m_deviceShared = *(sinkBuddy->getBuddySharedPtr()); // copy parameters
m_deviceParams.m_channel = 0; // take first channel
if (m_deviceShared.m_deviceParams == 0)
{
qCritical("LimeSDRInput::openDevice: cannot get device parameters from Tx buddy");
return false; // the device params should have been created by the buddy
}
m_deviceShared.m_channel = 0; // take first channel
} }
// There are no buddies then create the first LimeSDR common parameters // There are no buddies then create the first LimeSDR common parameters
// open the device this will also populate common fields // open the device this will also populate common fields
// take the first Rx channel // take the first Rx channel
else else
{ {
m_deviceParams.open((lms_info_str_t) qPrintable(m_deviceAPI->getSampleSourceSerial())); m_deviceShared.m_deviceParams = new DeviceLimeSDRParams();
m_deviceParams.m_channel = 0; // take first channel m_deviceShared.m_deviceParams->open((lms_info_str_t) qPrintable(m_deviceAPI->getSampleSourceSerial()));
m_deviceShared.m_channel = 0; // take first channel
} }
m_deviceAPI->setBuddySharedPtr(&m_deviceParams); // propagate common parameters to API m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API
// TODO: acquire the channel // acquire the channel
if (LMS_EnableChannel(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, true) != 0)
{
qCritical("LimeSDRInput::openDevice: cannot enable Rx channel %u", m_deviceShared.m_channel);
return false;
}
// set up the stream
m_streamId.channel = m_deviceShared.m_channel; //channel number
m_streamId.channel.fifoSize = 1024 * 1024; //fifo size in samples TODO: adjust if necessary
m_streamId.throughputVsLatency = 1.0; //optimize for max throughput
m_streamId.isTx = false; //RX channel
m_streamId.dataFmt = lms_stream_t::LMS_FMT_I12; //12-bit integers
if (LMS_SetupStream(m_deviceShared.m_deviceParams->getDevice(), &m_streamId) != 0)
{
qCritical("LimeSDRInput::openDevice: cannot setup the stream on Rx channel %u", m_deviceShared.m_channel);
return false;
}
// TODO: start / stop streaming is done in the thread. You will need to pass the stream Id to the thread at thread creation
return true; return true;
} }
void LimeSDRInput::closeDevice() void LimeSDRInput::closeDevice()
{ {
// TODO: release the channel // destroy the stream
// No buddies effectively close the device LMS_DestroyStream(m_deviceShared.m_deviceParams->getDevice(), &m_streamId);
if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0))
// release the channel
if (LMS_EnableChannel(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, false) != 0)
{ {
m_deviceParams.close(); qWarning("LimeSDRInput::closeDevice: cannot disable Rx channel %u", m_deviceShared.m_channel);
} }
m_deviceParams.m_dev = 0; m_deviceShared.m_channel = -1;
// No buddies so effectively close the device
if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0))
{
m_deviceShared.m_deviceParams->close();
delete m_deviceShared.m_deviceParams;
m_deviceShared.m_deviceParams = 0;
}
} }
bool LimeSDRInput::start() bool LimeSDRInput::start()
{ {
QMutexLocker mutexLocker(&m_mutex); if (!m_deviceShared.m_dev) {
if (!m_deviceParams.m_dev) {
return false; return false;
} }
if (m_running) stop(); if (m_running) stop();
if ((m_limeSDRInputThread = new LimeSDRInputThread(m_deviceParams.m_dev, &m_sampleFifo)) == 0) if ((m_limeSDRInputThread = new LimeSDRInputThread(m_deviceShared.m_deviceParams->getDevice(), &m_sampleFifo)) == 0)
{ {
qFatal("LimeSDRInput::start: out of memory"); qFatal("LimeSDRInput::start: out of memory");
stop(); stop();
return false; return false;
} }
m_limeSDRInputThread->setSamplerate(m_settings.m_devSampleRate); m_limeSDRInputThread->setSamplerate(m_deviceShared.m_deviceParams->m_sampleRate);
m_limeSDRInputThread->setLog2Decimation(m_settings.m_log2Decim); m_limeSDRInputThread->setLog2Decimation(m_settings.m_log2SoftDecim);
m_limeSDRInputThread->setFcPos((int) m_settings.m_fcPos); m_limeSDRInputThread->setFcPos((int) m_settings.m_fcPos);
m_limeSDRInputThread->startWork(); m_limeSDRInputThread->startWork();
mutexLocker.unlock();
applySettings(m_settings, true); applySettings(m_settings, true);
m_running = true; m_running = true;
@ -141,8 +190,6 @@ bool LimeSDRInput::start()
void LimeSDRInput::stop() void LimeSDRInput::stop()
{ {
QMutexLocker mutexLocker(&m_mutex);
if (m_limeSDRInputThread != 0) if (m_limeSDRInputThread != 0)
{ {
m_limeSDRInputThread->stopWork(); m_limeSDRInputThread->stopWork();

Wyświetl plik

@ -19,7 +19,7 @@
#include <QString> #include <QString>
#include "dsp/devicesamplesource.h" #include "dsp/devicesamplesource.h"
#include "limesdr/devicelimesdrparam.h" #include "limesdr/devicelimesdrshared.h"
#include "limesdrinputsettings.h" #include "limesdrinputsettings.h"
class DeviceSourceAPI; class DeviceSourceAPI;
@ -48,7 +48,9 @@ private:
LimeSDRInputThread* m_limeSDRInputThread; LimeSDRInputThread* m_limeSDRInputThread;
QString m_deviceDescription; QString m_deviceDescription;
bool m_running; bool m_running;
DeviceLimeSDRParams m_deviceParams; DeviceLimeSDRShared m_deviceShared;
lms_stream_t m_streamId;
bool openDevice(); bool openDevice();
void closeDevice(); void closeDevice();