1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00

PlutoSDRBox: use channels registered at contruction time

This commit is contained in:
f4exb 2021-04-25 22:28:40 +02:00
parent b04cc965e1
commit 54222ff016
3 changed files with 96 additions and 78 deletions

View File

@ -36,16 +36,12 @@ DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
m_lpfFIRlog2Decim(0),
m_lpfFIRRxGain(0),
m_lpfFIRTxGain(0),
m_ctx(0),
m_devPhy(0),
m_devRx(0),
m_devTx(0),
m_chnRx0i(0),
m_chnRx0q(0),
m_chnTx0i(0),
m_chnTx0q(0),
m_rxBuf(0),
m_txBuf(0),
m_ctx(nullptr),
m_devPhy(nullptr),
m_devRx(nullptr),
m_devTx(nullptr),
m_rxBuf(nullptr),
m_txBuf(nullptr),
m_xoInitial(0),
m_temp(0.0f)
{
@ -64,16 +60,40 @@ DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
m_valid = m_ctx && m_devPhy && m_devRx && m_devTx;
if (m_valid) {
if (m_valid)
{
std::regex channelIdReg("voltage([0-9]+)");
getXO();
// int nb_channels = iio_device_get_channels_count(m_devRx);
// for (int i = 0; i < nb_channels; i++) {
// iio_channel_disable(iio_device_get_channel(m_devRx, i));
// }
// nb_channels = iio_device_get_channels_count(m_devTx);
// for (int i = 0; i < nb_channels; i++) {
// iio_channel_disable(iio_device_get_channel(m_devTx, i));
// }
int nbRxChannels = iio_device_get_channels_count(m_devRx);
for (int i = 0; i < nbRxChannels; i++)
{
iio_channel *chn = iio_device_get_channel(m_devRx, i);
std::string channelId(iio_channel_get_id(chn));
if (std::regex_match(channelId, channelIdReg))
{
m_rxChannelIds.append(QString(channelId.c_str()));
m_rxChannels.append(chn);
qDebug("DevicePlutoSDRBox::DevicePlutoSDRBox: Rx: %s", channelId.c_str());
}
}
int nbTxChannels = iio_device_get_channels_count(m_devTx);
for (int i = 0; i < nbTxChannels; i++)
{
iio_channel *chn = iio_device_get_channel(m_devTx, i);
std::string channelId(iio_channel_get_id(chn));
if (std::regex_match(channelId, channelIdReg))
{
m_txChannelIds.append(QString(channelId.c_str()));
m_txChannels.append(chn);
qDebug("DevicePlutoSDRBox::DevicePlutoSDRBox: Tx: %s", channelId.c_str());
}
}
}
}
@ -259,14 +279,11 @@ bool DevicePlutoSDRBox::openRx()
{
if (!m_valid) { return false; }
if (!m_chnRx0i) {
m_chnRx0i = iio_device_find_channel(m_devRx, "voltage0", false);
}
if (m_rxChannels.size() > 0)
{
iio_channel_enable(m_rxChannels.at(0));
if (m_chnRx0i) {
iio_channel_enable(m_chnRx0i);
const struct iio_data_format *df = iio_channel_get_data_format(m_chnRx0i);
const struct iio_data_format *df = iio_channel_get_data_format(m_rxChannels.at(0));
qDebug("DevicePlutoSDRBox::openRx channel I: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
df->length,
df->bits,
@ -276,19 +293,18 @@ bool DevicePlutoSDRBox::openRx()
df->with_scale? "true" : "false",
df->scale,
df->repeat);
} else {
}
else
{
std::cerr << "DevicePlutoSDRBox::openRx: failed" << std::endl;
return false;
}
if (!m_chnRx0q) {
m_chnRx0q = iio_device_find_channel(m_devRx, "voltage1", false);
}
if (m_rxChannels.size() > 1)
{
iio_channel_enable(m_rxChannels.at(1));
if (m_chnRx0q) {
iio_channel_enable(m_chnRx0q);
const struct iio_data_format* df = iio_channel_get_data_format(m_chnRx0q);
const struct iio_data_format* df = iio_channel_get_data_format(m_rxChannels.at(1));
qDebug("DevicePlutoSDRBox::openRx channel Q: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
df->length,
df->bits,
@ -300,7 +316,8 @@ bool DevicePlutoSDRBox::openRx()
df->repeat);
return true;
}
else {
else
{
std::cerr << "DevicePlutoSDRBox::openRx: failed" << std::endl;
return false;
}
@ -310,13 +327,10 @@ bool DevicePlutoSDRBox::openTx()
{
if (!m_valid) { return false; }
if (!m_chnTx0i) {
m_chnTx0i = iio_device_find_channel(m_devTx, "voltage0", true);
}
if (m_chnTx0i) {
iio_channel_enable(m_chnTx0i);
const struct iio_data_format *df = iio_channel_get_data_format(m_chnTx0i);
if (m_txChannels.size() > 0)
{
iio_channel_enable(m_txChannels.at(0));
const struct iio_data_format *df = iio_channel_get_data_format(m_txChannels.at(0));
qDebug("DevicePlutoSDRBox::openTx: channel I: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
df->length,
df->bits,
@ -326,18 +340,17 @@ bool DevicePlutoSDRBox::openTx()
df->with_scale? "true" : "false",
df->scale,
df->repeat);
} else {
}
else
{
std::cerr << "DevicePlutoSDRBox::openTx: failed to open I channel" << std::endl;
return false;
}
if (!m_chnTx0q) {
m_chnTx0q = iio_device_find_channel(m_devTx, "voltage1", true);
}
if (m_chnTx0q) {
iio_channel_enable(m_chnTx0q);
const struct iio_data_format *df = iio_channel_get_data_format(m_chnTx0q);
if (m_txChannels.size() > 1)
{
iio_channel_enable(m_txChannels.at(1));
const struct iio_data_format *df = iio_channel_get_data_format(m_txChannels.at(1));
qDebug("DevicePlutoSDRBox::openTx: channel Q: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
df->length,
df->bits,
@ -348,7 +361,9 @@ bool DevicePlutoSDRBox::openTx()
df->scale,
df->repeat);
return true;
} else {
}
else
{
std::cerr << "DevicePlutoSDRBox::openTx: failed to open Q channel" << std::endl;
return false;
}
@ -356,14 +371,14 @@ bool DevicePlutoSDRBox::openTx()
void DevicePlutoSDRBox::closeRx()
{
if (m_chnRx0i) { iio_channel_disable(m_chnRx0i); }
if (m_chnRx0q) { iio_channel_disable(m_chnRx0q); }
if (m_rxChannels.size() > 0) { iio_channel_disable(m_rxChannels.at(0)); }
if (m_rxChannels.size() > 1) { iio_channel_disable(m_rxChannels.at(1)); }
}
void DevicePlutoSDRBox::closeTx()
{
if (m_chnTx0i) { iio_channel_disable(m_chnTx0i); }
if (m_chnTx0q) { iio_channel_disable(m_chnTx0q); }
if (m_txChannels.size() > 0) { iio_channel_disable(m_txChannels.at(0)); }
if (m_txChannels.size() > 1) { iio_channel_disable(m_txChannels.at(1)); }
}
struct iio_buffer *DevicePlutoSDRBox::createRxBuffer(unsigned int size, bool cyclic)
@ -454,16 +469,16 @@ char* DevicePlutoSDRBox::rxBufferEnd()
if (m_rxBuf) {
return (char *) iio_buffer_end(m_rxBuf);
} else {
return 0;
return nullptr;
}
}
char* DevicePlutoSDRBox::rxBufferFirst()
{
if (m_rxBuf) {
return (char *) iio_buffer_first(m_rxBuf, m_chnRx0i);
return (char *) iio_buffer_first(m_rxBuf, m_rxChannels.at(0));
} else {
return 0;
return nullptr;
}
}
@ -481,26 +496,26 @@ char* DevicePlutoSDRBox::txBufferEnd()
if (m_txBuf) {
return (char *) iio_buffer_end(m_txBuf);
} else {
return 0;
return nullptr;
}
}
char* DevicePlutoSDRBox::txBufferFirst()
{
if (m_txBuf) {
return (char *) iio_buffer_first(m_txBuf, m_chnTx0i);
return (char *) iio_buffer_first(m_txBuf, m_txChannels.at(0));
} else {
return 0;
return nullptr;
}
}
void DevicePlutoSDRBox::txChannelConvert(int16_t *dst, int16_t *src)
{
if (m_chnTx0i) {
iio_channel_convert_inverse(m_chnTx0i, &dst[0], &src[0]);
if (m_txChannels.size() > 0) {
iio_channel_convert_inverse(m_txChannels.at(0), &dst[0], &src[0]);
}
if (m_chnTx0q) {
iio_channel_convert_inverse(m_chnTx0q, &dst[1], &src[1]);
if (m_txChannels.size() > 1) {
iio_channel_convert_inverse(m_txChannels.at(1), &dst[1], &src[1]);
}
}

View File

@ -21,8 +21,11 @@
#include <sstream>
#include <stdint.h>
#include <sys/types.h>
#include "deviceplutosdrscan.h"
#include <QList>
#include <QString>
#include "deviceplutosdrscan.h"
#include "export.h"
#if defined(_MSC_VER)
@ -30,6 +33,8 @@
typedef SSIZE_T ssize_t;
#endif
struct iio_channel;
class DEVICES_API DevicePlutoSDRBox
{
public:
@ -75,19 +80,18 @@ public:
void set_params(DeviceType devType, const std::vector<std::string> &params);
bool get_param(DeviceType devType, const std::string &param, std::string &value);
bool openRx();
bool openTx();
void closeRx();
void closeTx();
bool openRx(); //!< Open first Rx (Rx0)
bool openTx(); //!< Open first Tx (Tx0)
void closeRx(); //!< Close first Rx (Rx0)
void closeTx(); //!< Close first Tx (Tx0)
int getNbRx() const { return m_rxChannels.size() / 2; }
int getNbTx() const { return m_txChannels.size() / 2; }
struct iio_buffer *createRxBuffer(unsigned int size, bool cyclic);
struct iio_buffer *createTxBuffer(unsigned int size, bool cyclic);
void deleteRxBuffer();
void deleteTxBuffer();
ssize_t getRxSampleSize();
ssize_t getTxSampleSize();
struct iio_channel *getRxChannel0() { return m_chnRx0i; }
struct iio_channel *getTxChannel0I() { return m_chnTx0i; }
struct iio_channel *getTxChannel0Q() { return m_chnTx0q; }
ssize_t rxBufferRefill();
ssize_t txBufferPush();
std::ptrdiff_t rxBufferStep();
@ -119,15 +123,15 @@ private:
struct iio_device *m_devPhy;
struct iio_device *m_devRx;
struct iio_device *m_devTx;
struct iio_channel *m_chnRx0i;
struct iio_channel* m_chnRx0q;
struct iio_channel *m_chnTx0i;
struct iio_channel *m_chnTx0q;
struct iio_buffer *m_rxBuf;
struct iio_buffer *m_txBuf;
bool m_valid;
int64_t m_xoInitial;
float m_temp;
QList<QString> m_rxChannelIds;
QList<iio_channel*> m_rxChannels;
QList<QString> m_txChannelIds;
QList<iio_channel*> m_txChannels;
bool parseSampleRates(const std::string& rateStr, SampleRates& sampleRates);
void setFilter(const std::string& filterConfigStr);

View File

@ -113,7 +113,6 @@ void PlutoSDRInputThread::run()
{
m_buf[ihs++] = *((int16_t *) p_dat);
m_buf[ihs++] = *(((int16_t *) p_dat) + 1);
// iio_channel_convert(m_plutoBox->getRxChannel0(), (void *) &m_bufConv[ihs], (const void *) &m_buf[ihs]);
}
if (m_iqOrder) {