Perseus support (2)

This commit is contained in:
f4exb 2018-02-06 18:49:22 +01:00
parent 84b5e4b4ce
commit fb2114a9f3
8 changed files with 462 additions and 0 deletions

View File

@ -28,4 +28,9 @@ else(BUILD_DEBIAN)
add_subdirectory(plutosdr)
endif(LIBUSB_FOUND AND LIBIIO_FOUND)
find_package(LibPerseus)
if(LIBUSB_FOUND AND LIBPERSEUS_FOUND)
add_subdirectory(perseus)
endif()
endif (BUILD_DEBIAN)

View File

@ -0,0 +1,48 @@
project(perseusdevice)
set (CMAKE_CXX_STANDARD 11)
set(perseusdevice_SOURCES
deviceperseus.cpp
deviceperseusscan.cpp
)
set(perseusdevice_HEADERS
deviceperseus.h
deviceperseusscan.h
)
if (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBPERSEUSSRC}
)
else (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBPERSEUS_INCLUDE_DIR}
)
endif (BUILD_DEBIAN)
#add_definitions(${QT_DEFINITIONS})
#add_definitions(-DQT_SHARED)
add_library(perseusdevice SHARED
${perseusdevice_SOURCES}
)
if (BUILD_DEBIAN)
target_link_libraries(perseusdevice
perseus
sdrbase
)
else (BUILD_DEBIAN)
target_link_libraries(perseusdevice
${LIBPERSEUS_LIBRARIES}
sdrbase
)
endif (BUILD_DEBIAN)
install(TARGETS perseusdevice DESTINATION lib)

View File

@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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 "perseus-sdr.h"
#include "deviceperseus.h"
DevicePerseus::DevicePerseus()
{
m_nbDevices = perseus_init();
}
DevicePerseus::~DevicePerseus()
{
perseus_exit();
}
DevicePerseus& DevicePerseus::instance()
{
static DevicePerseus inst;
return inst;
}

View File

@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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_PERSEUS_DEVICEPERSEUS_H_
#define DEVICES_PERSEUS_DEVICEPERSEUS_H_
#include "deviceperseusscan.h"
class DevicePerseus
{
public:
static DevicePerseus& instance();
void scan() { m_scan.scan(m_nbDevices); }
void getSerials(std::vector<std::string>& serials) const { m_scan.getSerials(serials); }
protected:
DevicePerseus();
DevicePerseus(const DevicePerseus&) : m_nbDevices(0) {}
DevicePerseus& operator=(const DevicePerseus& other __attribute__((unused))) { return *this; }
~DevicePerseus();
private:
int m_nbDevices;
DevicePerseusScan m_scan;
};
#endif /* DEVICES_PERSEUS_DEVICEPERSEUS_H_ */

View File

@ -0,0 +1,116 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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 "deviceperseusscan.h"
#include "perseus-sdr.h"
#include <sstream>
#include <QtGlobal>
void DevicePerseusScan::scan(int nbDevices)
{
if (nbDevices == 0) {
qInfo("DevicePerseusScan::scan: no Perseus devices");
return;
}
perseus_descr *descr;
eeprom_prodid prodid;
for (int deviceIndex = 0; deviceIndex < nbDevices; deviceIndex++)
{
if ((descr = perseus_open(deviceIndex)) == 0) {
qCritical("DevicePerseusScan::scan: open error: %s\n", perseus_errorstr());
continue;
}
// if (perseus_firmware_download(descr, 0) < 0) {
// qCritical("DevicePerseusScan::scan: firmware download error: %s", perseus_errorstr());
// continue;
// }
// else
// {
// qInfo("DevicePerseusScan::scan: device #%d firmware downloaded", deviceIndex);
// }
if (perseus_get_product_id(descr,&prodid) < 0) {
qCritical("DevicePerseusScan::scan: get product id error: %s", perseus_errorstr());
perseus_close(descr);
continue;
}
else
{
uint32_t sigA = (prodid.signature[5]<<16) + prodid.signature[4];
uint32_t sigB = (prodid.signature[3]<<16) + prodid.signature[2];
uint32_t sigC = (prodid.signature[1]<<16) + prodid.signature[0];
std::stringstream ss;
ss << prodid.sn << "-" << std::hex << sigA << "-" << sigB << "-" << sigC;
m_scans.push_back({ss.str(), prodid.sn, deviceIndex});
m_serialMap[m_scans.back().m_serial] = &m_scans.back();
perseus_close(descr);
}
}
}
const std::string* DevicePerseusScan::getSerialAt(unsigned int index) const
{
if (index < m_scans.size()) {
return &(m_scans[index].m_serial);
} else {
return 0;
}
}
uint16_t DevicePerseusScan::getSerialNumberAt(unsigned int index) const
{
if (index < m_scans.size()) {
return m_scans[index].m_serialNumber;
} else {
return 0;
}
}
int DevicePerseusScan::getSequenceAt(unsigned int index) const
{
if (index < m_scans.size()) {
return m_scans[index].m_sequence;
} else {
return 0;
}
}
int DevicePerseusScan::getSequenceFromSerial(const std::string& serial) const
{
std::map<std::string, DeviceScan*>::const_iterator it = m_serialMap.find(serial);
if (it == m_serialMap.end()) {
return -1;
} else {
return ((it->second)->m_sequence);
}
}
void DevicePerseusScan::getSerials(std::vector<std::string>& serials) const
{
std::vector<DeviceScan>::const_iterator it = m_scans.begin();
serials.clear();
for (; it != m_scans.end(); ++it) {
serials.push_back(it->m_serial);
}
}

View File

@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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_PERSEUS_DEVICEPERSEUSSCAN_H_
#define DEVICES_PERSEUS_DEVICEPERSEUSSCAN_H_
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
#include <QString>
class DevicePerseusScan
{
public:
struct DeviceScan
{
std::string m_serial;
uint16_t m_serialNumber;
int m_sequence;
};
void scan(int nbDevices);
int getNbActiveDevices() const { return m_scans.size(); }
const std::string* getSerialAt(unsigned int index) const;
uint16_t getSerialNumberAt(unsigned int index) const ;
int getSequenceAt(unsigned int index) const ;
int getSequenceFromSerial(const std::string& serial) const;
void getSerials(std::vector<std::string>& serials) const;
private:
std::vector<DeviceScan> m_scans;
std::map<std::string, DeviceScan*> m_serialMap;
};
#endif /* DEVICES_PERSEUS_DEVICEPERSEUSSCAN_H_ */

View File

@ -0,0 +1,115 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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 <QtPlugin>
#include <QAction>
#include <perseus-sdr.h>
#include <device/devicesourceapi.h>
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "airspyhfplugin.h"
#include "airspyhfgui.h"
const PluginDescriptor PerseusPlugin::m_pluginDescriptor = {
QString("Perseus Input"),
QString("3.12.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
const QString PerseusPlugin::m_hardwareID = "Perseus";
const QString PerseusPlugin::m_deviceTypeID = PERSEUS_DEVICE_TYPE_ID;
const int AirspyHFPlugin::m_maxDevices = 32;
PerseusPlugin::PerseusPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& PerseusPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void PerseusPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSource(m_deviceTypeID, this);
}
PluginInterface::SamplingDevices PerseusPlugin::enumSampleSources()
{
DevicePerseus::instance().scan();
std::vector<std::string> serials;
DevicePerseus::instance().getSerials(serials);
std::vector<std::string>::const_iterator it = serials.begin();
int i;
SamplingDevices result;
for (i = 0; it != serials.end(); ++it, ++i)
{
QString serial_str = QString::fromLocal8Bit(it->c_str());
QString displayedName(QString("Perseus[%1] %2").arg(i).arg(serial_str));
result.append(SamplingDevice(displayedName,
m_hardwareID,
m_deviceTypeID,
serial_str,
i,
PluginInterface::SamplingDevice::PhysicalDevice,
true,
1,
0));
qDebug("PerseusPlugin::enumSampleSources: enumerated PlutoSDR device #%d", i);
}
return result;
}
PluginInstanceGUI* PerseusPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
if (sourceId == m_deviceTypeID)
{
PerseusGui* gui = new PerseusGui(deviceUISet);
*widget = gui;
return gui;
}
else
{
return 0;
}
}
DeviceSampleSource *PerseusPlugin::createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI)
{
if (sourceId == m_deviceTypeID)
{
PerseusInput* input = new PerseusInput(deviceAPI);
return input;
}
else
{
return 0;
}
}

View File

@ -0,0 +1,53 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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 INCLUDE_PERSEUSPLUGIN_H
#define INCLUDE_PERSEUSPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
#define PERSEUS_DEVICE_TYPE_ID "sdrangel.samplesource.perseus"
class PluginAPI;
class PerseusPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID PERSEUS_DEVICE_TYPE_ID)
public:
explicit PerseusPlugin(QObject* parent = 0);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
virtual SamplingDevices enumSampleSources();
virtual PluginInstanceGUI* createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet);
virtual DeviceSampleSource* createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI);
static const QString m_hardwareID;
static const QString m_deviceTypeID;
static const int m_maxDevices;
private:
static const PluginDescriptor m_pluginDescriptor;
};
#endif // INCLUDE_PERSEUSPLUGIN_H