satdump/src-core/dsp/device/dev.h

73 lines
2.5 KiB
C
Raw Permalink Normal View History

2025-03-18 08:01:02 +01:00
#pragma once
#include "dsp/block.h"
2025-04-15 19:06:12 +01:00
#include <cstdint>
2025-03-18 08:01:02 +01:00
2025-03-18 19:23:15 +01:00
// TODOREWORK DOCUMENT
2025-03-18 08:01:02 +01:00
namespace satdump
{
namespace ndsp
{
2025-03-18 19:23:15 +01:00
struct DeviceInfo
{
2025-04-21 23:17:21 +02:00
std::string type; // SDR Type ID string
std::string name; // Display name
2025-04-22 19:56:59 +02:00
nlohmann::json cfg; // Default parameters for the block to use THIS device (eg, Serial). Applied with set_cfg
2025-04-21 23:17:21 +02:00
nlohmann::json params; // List of additional parameters that may be device-specific (eg, Airspy Mini vs Airspy R2)
2025-03-21 12:07:38 +01:00
2025-05-10 13:33:28 +02:00
bool operator==(const DeviceInfo &b) { return ((type == b.type) && (name == b.type) && (cfg == b.cfg) && (params == b.params)); }
2025-03-21 12:07:38 +01:00
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DeviceInfo, type, name, cfg, params)
2025-03-18 19:23:15 +01:00
};
2025-03-18 08:01:02 +01:00
class DeviceBlock : public Block
{
2025-03-21 12:07:38 +01:00
private:
2025-04-21 23:17:21 +02:00
bool work() { throw satdump_exception("Device Source and/or Sync does not implement work. Should NOT have been called!"); }
2025-03-21 12:07:38 +01:00
2025-04-22 19:56:59 +02:00
public:
// TODOREWORK?
enum device_mode_t
{
MODE_NORMAL = 0,
MODE_SINGLE_RX = 1,
MODE_SINGLE_TX = 2,
};
2025-03-21 12:07:38 +01:00
protected:
DeviceInfo devInfo;
2025-04-22 19:56:59 +02:00
device_mode_t devMode = MODE_NORMAL;
2025-03-21 12:07:38 +01:00
2025-03-18 08:01:02 +01:00
public:
2025-04-21 23:17:21 +02:00
DeviceBlock(std::string id, std::vector<BlockIO> in = {}, std::vector<BlockIO> out = {}) : Block(id, in, out) {}
2025-04-15 07:51:27 +02:00
2025-04-22 19:56:59 +02:00
virtual void setDevInfo(DeviceInfo i, device_mode_t m)
2025-04-15 07:51:27 +02:00
{
2025-04-22 19:56:59 +02:00
devInfo = i, devMode = m;
2025-04-15 07:51:27 +02:00
set_cfg(devInfo.cfg);
}
2025-03-25 21:33:06 +01:00
2025-04-22 19:56:59 +02:00
// TODOREWORK helper functions for basic functions
2025-04-15 19:06:12 +01:00
virtual double getStreamSamplerate(int id, bool output) = 0;
2025-04-22 19:56:59 +02:00
virtual void setStreamSamplerate(int id, bool output, double samplerate) = 0;
virtual double getStreamFrequency(int id, bool output) = 0;
virtual void setStreamFrequency(int id, bool output, double frequency) = 0;
2025-03-21 12:07:38 +01:00
};
struct RequestDeviceListEvent
{
std::vector<DeviceInfo> &i;
DeviceBlock::device_mode_t m;
2025-03-21 12:07:38 +01:00
};
std::vector<DeviceInfo> getDeviceList(DeviceBlock::device_mode_t m);
2025-03-21 12:07:38 +01:00
struct RequestDeviceInstanceEvent
{
DeviceInfo info;
std::vector<std::shared_ptr<DeviceBlock>> &i;
2025-03-18 08:01:02 +01:00
};
2025-03-21 12:07:38 +01:00
2025-04-22 19:56:59 +02:00
std::shared_ptr<DeviceBlock> getDeviceInstanceFromInfo(DeviceInfo i, DeviceBlock::device_mode_t m);
2025-04-15 07:51:27 +02:00
} // namespace ndsp
} // namespace satdump