From 6fa8b4ac8787f085438584c7c647a5ca6ee60aba Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 5 Sep 2017 16:23:10 +0200 Subject: [PATCH] PlutoSDR: added common parameters and shared structure --- devices/plutosdr/CMakeLists.txt | 4 ++ devices/plutosdr/deviceplutosdrparams.cpp | 40 +++++++++++++ devices/plutosdr/deviceplutosdrparams.h | 47 ++++++++++++++++ devices/plutosdr/deviceplutosdrshared.cpp | 20 +++++++ devices/plutosdr/deviceplutosdrshared.h | 56 +++++++++++++++++++ .../plutosdrinput/plutosdrinput.cpp | 20 +++++++ .../plutosdrinput/plutosdrinput.h | 6 +- 7 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 devices/plutosdr/deviceplutosdrparams.cpp create mode 100644 devices/plutosdr/deviceplutosdrparams.h create mode 100644 devices/plutosdr/deviceplutosdrshared.cpp create mode 100644 devices/plutosdr/deviceplutosdrshared.h diff --git a/devices/plutosdr/CMakeLists.txt b/devices/plutosdr/CMakeLists.txt index f7524d954..5ed884f8f 100644 --- a/devices/plutosdr/CMakeLists.txt +++ b/devices/plutosdr/CMakeLists.txt @@ -6,12 +6,16 @@ set(plutosdrdevice_SOURCES deviceplutosdr.cpp deviceplutosdrbox.cpp deviceplutosdrscan.cpp + deviceplutosdrparams.cpp + deviceplutosdrshared.cpp ) set(plutosdrdevice_HEADERS deviceplutosdr.h deviceplutsdrobox.h deviceplutosdrscan.h + deviceplutosdrparams.h + deviceplutosdrshared.h ) if (BUILD_DEBIAN) diff --git a/devices/plutosdr/deviceplutosdrparams.cpp b/devices/plutosdr/deviceplutosdrparams.cpp new file mode 100644 index 000000000..8fc495321 --- /dev/null +++ b/devices/plutosdr/deviceplutosdrparams.cpp @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "deviceplutosdrparams.h" + +#include "deviceplutosdr.h" + +DevicePlutoSDRParams::DevicePlutoSDRParams() : + m_box(0) +{ +} + +DevicePlutoSDRParams::~DevicePlutoSDRParams() +{ +} + +bool DevicePlutoSDRParams::open(const std::string& serial) +{ + m_box = DevicePlutoSDR::getDeviceFromSerial(serial); + return m_box != 0; +} + +void DevicePlutoSDRParams::close() +{ + delete m_box; + m_box = 0; +} diff --git a/devices/plutosdr/deviceplutosdrparams.h b/devices/plutosdr/deviceplutosdrparams.h new file mode 100644 index 000000000..946106159 --- /dev/null +++ b/devices/plutosdr/deviceplutosdrparams.h @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef DEVICES_PLUTOSDR_DEVICEPLUTOSDRPARAMS_H_ +#define DEVICES_PLUTOSDR_DEVICEPLUTOSDRPARAMS_H_ + +#include + +class DevicePlutoSDRBox; + +/** + * This structure refers to one physical device shared among parties (logical devices represented by + * the DeviceSinkAPI or DeviceSourceAPI). + * It allows storing information on the common resources in one place and is shared among participants. + * There is only one copy that is constructed by the first participant and destroyed by the last. + * A participant knows it is the first or last by checking the lists of buddies (Rx + Tx). + */ +struct DevicePlutoSDRParams +{ +public: + DevicePlutoSDRParams(); + ~DevicePlutoSDRParams(); + + bool open(const std::string& serial); + void close(); + + DevicePlutoSDRBox *getBox() { return m_box; } + +private: + DevicePlutoSDRBox *m_box; +}; + + +#endif /* DEVICES_PLUTOSDR_DEVICEPLUTOSDRPARAMS_H_ */ diff --git a/devices/plutosdr/deviceplutosdrshared.cpp b/devices/plutosdr/deviceplutosdrshared.cpp new file mode 100644 index 000000000..d3d30bc0e --- /dev/null +++ b/devices/plutosdr/deviceplutosdrshared.cpp @@ -0,0 +1,20 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "deviceplutosdrshared.h" + +const float DevicePlutoSDRShared::m_sampleFifoLengthInSeconds = 0.25; +const int DevicePlutoSDRShared::m_sampleFifoMinSize = 48000; // 192kS/s knee diff --git a/devices/plutosdr/deviceplutosdrshared.h b/devices/plutosdr/deviceplutosdrshared.h new file mode 100644 index 000000000..9e8657882 --- /dev/null +++ b/devices/plutosdr/deviceplutosdrshared.h @@ -0,0 +1,56 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef DEVICES_PLUTOSDR_DEVICEPLUTOSDRSHARED_H_ +#define DEVICES_PLUTOSDR_DEVICEPLUTOSDRSHARED_H_ + +/** + * Structure shared by a buddy with other buddies + */ +class DevicePlutoSDRShared +{ +public: + /** + * Expose own samples processing thread control + */ + class ThreadInterface + { + public: + virtual void startWork() = 0; + virtual void stopWork() = 0; + virtual void setDeviceSampleRate(int sampleRate) = 0; + virtual bool isRunning() = 0; + }; + + DevicePlutoSDRParams *m_deviceParams; //!< unique hardware device parameters + ThreadInterface *m_thread; //!< holds the thread address if started else 0 + bool m_threadWasRunning; //!< flag to know if thread needs to be resumed after suspend + + static const float m_sampleFifoLengthInSeconds; + static const int m_sampleFifoMinSize; + + DevicePlutoSDRShared() : + m_deviceParams(0), + m_thread(0), + m_threadWasRunning(false) + {} + + ~DevicePlutoSDRShared() + {} +}; + + +#endif /* DEVICES_PLUTOSDR_DEVICEPLUTOSDRSHARED_H_ */ diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index 868d93617..2e0b8a627 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -87,3 +87,23 @@ bool PlutoSDRInput::handleMessage(const Message& message) return false; } } + +bool PlutoSDRInput::openDevice() +{ + +} + +void PlutoSDRInput::closeDevice() +{ + +} + +void PlutoSDRInput::suspendBuddies() +{ + +} + +void PlutoSDRInput::resumeBuddies() +{ + +} diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.h b/plugins/samplesource/plutosdrinput/plutosdrinput.h index 2f2660b70..4b1672219 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.h +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.h @@ -67,8 +67,12 @@ public: QString m_deviceDescription; PlutoSDRInputSettings m_settings; bool m_running; - QMutex m_mutex; + + bool openDevice(); + void closeDevice(); + void suspendBuddies(); + void resumeBuddies(); };