SoapySDR  0.8.0-gab626068
Vendor and platform neutral SDR interface library
Device.hpp
Go to the documentation of this file.
1 
13 #pragma once
14 #include <SoapySDR/Config.hpp>
15 #include <SoapySDR/Types.hpp>
16 #include <SoapySDR/Constants.h>
17 #include <SoapySDR/Errors.h>
18 #include <vector>
19 #include <string>
20 #include <complex>
21 #include <cstddef> //size_t
22 
23 namespace SoapySDR
24 {
25 
27 class Stream;
28 
33 {
34 public:
35 
37  virtual ~Device(void);
38 
44  static KwargsList enumerate(const Kwargs &args = Kwargs());
45 
52  static KwargsList enumerate(const std::string &args);
53 
63  static Device *make(const Kwargs &args = Kwargs());
64 
74  static Device *make(const std::string &args);
75 
81  static void unmake(Device *device);
82 
83  /*******************************************************************
84  * Parallel support
85  ******************************************************************/
86 
95  static std::vector<Device *> make(const KwargsList &argsList);
96 
105  static std::vector<Device *> make(const std::vector<std::string> &argsList);
106 
114  static void unmake(const std::vector<Device *> &devices);
115 
116  /*******************************************************************
117  * Identification API
118  ******************************************************************/
119 
125  virtual std::string getDriverKey(void) const;
126 
132  virtual std::string getHardwareKey(void) const;
133 
141  virtual Kwargs getHardwareInfo(void) const;
142 
143  /*******************************************************************
144  * Channels API
145  ******************************************************************/
146 
153  virtual void setFrontendMapping(const int direction, const std::string &mapping);
154 
160  virtual std::string getFrontendMapping(const int direction) const;
161 
165  virtual size_t getNumChannels(const int direction) const;
166 
177  virtual Kwargs getChannelInfo(const int direction, const size_t channel) const;
178 
185  virtual bool getFullDuplex(const int direction, const size_t channel) const;
186 
187  /*******************************************************************
188  * Stream API
189  ******************************************************************/
190 
197  virtual std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
198 
208  virtual std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
209 
216  virtual ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const;
217 
267  virtual Stream *setupStream(
268  const int direction,
269  const std::string &format,
270  const std::vector<size_t> &channels = std::vector<size_t>(),
271  const Kwargs &args = Kwargs());
272 
278  virtual void closeStream(Stream *stream);
279 
289  virtual size_t getStreamMTU(Stream *stream) const;
290 
308  virtual int activateStream(
309  Stream *stream,
310  const int flags = 0,
311  const long long timeNs = 0,
312  const size_t numElems = 0);
313 
328  virtual int deactivateStream(
329  Stream *stream,
330  const int flags = 0,
331  const long long timeNs = 0);
332 
352  virtual int readStream(
353  Stream *stream,
354  void * const *buffs,
355  const size_t numElems,
356  int &flags,
357  long long &timeNs,
358  const long timeoutUs = 100000);
359 
379  virtual int writeStream(
380  Stream *stream,
381  const void * const *buffs,
382  const size_t numElems,
383  int &flags,
384  const long long timeNs = 0,
385  const long timeoutUs = 100000);
386 
407  virtual int readStreamStatus(
408  Stream *stream,
409  size_t &chanMask,
410  int &flags,
411  long long &timeNs,
412  const long timeoutUs = 100000);
413 
414  /*******************************************************************
415  * Direct buffer access API
416  ******************************************************************/
417 
427  virtual size_t getNumDirectAccessBuffers(Stream *stream);
428 
442  virtual int getDirectAccessBufferAddrs(Stream *stream, const size_t handle, void **buffs);
443 
464  virtual int acquireReadBuffer(
465  Stream *stream,
466  size_t &handle,
467  const void **buffs,
468  int &flags,
469  long long &timeNs,
470  const long timeoutUs = 100000);
471 
479  virtual void releaseReadBuffer(
480  Stream *stream,
481  const size_t handle);
482 
501  virtual int acquireWriteBuffer(
502  Stream *stream,
503  size_t &handle,
504  void **buffs,
505  const long timeoutUs = 100000);
506 
522  virtual void releaseWriteBuffer(
523  Stream *stream,
524  const size_t handle,
525  const size_t numElems,
526  int &flags,
527  const long long timeNs = 0);
528 
529  /*******************************************************************
530  * Antenna API
531  ******************************************************************/
532 
539  virtual std::vector<std::string> listAntennas(const int direction, const size_t channel) const;
540 
547  virtual void setAntenna(const int direction, const size_t channel, const std::string &name);
548 
555  virtual std::string getAntenna(const int direction, const size_t channel) const;
556 
557  /*******************************************************************
558  * Frontend corrections API
559  ******************************************************************/
560 
567  virtual bool hasDCOffsetMode(const int direction, const size_t channel) const;
568 
575  virtual void setDCOffsetMode(const int direction, const size_t channel, const bool automatic);
576 
583  virtual bool getDCOffsetMode(const int direction, const size_t channel) const;
584 
591  virtual bool hasDCOffset(const int direction, const size_t channel) const;
592 
599  virtual void setDCOffset(const int direction, const size_t channel, const std::complex<double> &offset);
600 
607  virtual std::complex<double> getDCOffset(const int direction, const size_t channel) const;
608 
615  virtual bool hasIQBalance(const int direction, const size_t channel) const;
616 
623  virtual void setIQBalance(const int direction, const size_t channel, const std::complex<double> &balance);
624 
631  virtual std::complex<double> getIQBalance(const int direction, const size_t channel) const;
632 
639  virtual bool hasIQBalanceMode(const int direction, const size_t channel) const;
640 
647  virtual void setIQBalanceMode(const int direction, const size_t channel, const bool automatic);
648 
655  virtual bool getIQBalanceMode(const int direction, const size_t channel) const;
656 
663  virtual bool hasFrequencyCorrection(const int direction, const size_t channel) const;
664 
671  virtual void setFrequencyCorrection(const int direction, const size_t channel, const double value);
672 
679  virtual double getFrequencyCorrection(const int direction, const size_t channel) const;
680 
681  /*******************************************************************
682  * Gain API
683  ******************************************************************/
684 
692  virtual std::vector<std::string> listGains(const int direction, const size_t channel) const;
693 
700  virtual bool hasGainMode(const int direction, const size_t channel) const;
701 
708  virtual void setGainMode(const int direction, const size_t channel, const bool automatic);
709 
716  virtual bool getGainMode(const int direction, const size_t channel) const;
717 
725  virtual void setGain(const int direction, const size_t channel, const double value);
726 
734  virtual void setGain(const int direction, const size_t channel, const std::string &name, const double value);
735 
742  virtual double getGain(const int direction, const size_t channel) const;
743 
751  virtual double getGain(const int direction, const size_t channel, const std::string &name) const;
752 
759  virtual Range getGainRange(const int direction, const size_t channel) const;
760 
768  virtual Range getGainRange(const int direction, const size_t channel, const std::string &name) const;
769 
770  /*******************************************************************
771  * Frequency API
772  ******************************************************************/
773 
801  virtual void setFrequency(const int direction, const size_t channel, const double frequency, const Kwargs &args = Kwargs());
802 
819  virtual void setFrequency(const int direction, const size_t channel, const std::string &name, const double frequency, const Kwargs &args = Kwargs());
820 
829  virtual double getFrequency(const int direction, const size_t channel) const;
830 
838  virtual double getFrequency(const int direction, const size_t channel, const std::string &name) const;
839 
847  virtual std::vector<std::string> listFrequencies(const int direction, const size_t channel) const;
848 
855  virtual RangeList getFrequencyRange(const int direction, const size_t channel) const;
856 
864  virtual RangeList getFrequencyRange(const int direction, const size_t channel, const std::string &name) const;
865 
872  virtual ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const;
873 
874  /*******************************************************************
875  * Sample Rate API
876  ******************************************************************/
877 
884  virtual void setSampleRate(const int direction, const size_t channel, const double rate);
885 
892  virtual double getSampleRate(const int direction, const size_t channel) const;
893 
901  virtual std::vector<double> listSampleRates(const int direction, const size_t channel) const;
902 
909  virtual RangeList getSampleRateRange(const int direction, const size_t channel) const;
910 
911  /*******************************************************************
912  * Bandwidth API
913  ******************************************************************/
914 
921  virtual void setBandwidth(const int direction, const size_t channel, const double bw);
922 
929  virtual double getBandwidth(const int direction, const size_t channel) const;
930 
938  virtual std::vector<double> listBandwidths(const int direction, const size_t channel) const;
939 
946  virtual RangeList getBandwidthRange(const int direction, const size_t channel) const;
947 
948  /*******************************************************************
949  * Clocking API
950  ******************************************************************/
951 
956  virtual void setMasterClockRate(const double rate);
957 
962  virtual double getMasterClockRate(void) const;
963 
968  virtual RangeList getMasterClockRates(void) const;
969 
974  virtual void setReferenceClockRate(const double rate);
975 
980  virtual double getReferenceClockRate(void) const;
981 
986  virtual RangeList getReferenceClockRates(void) const;
987 
992  virtual std::vector<std::string> listClockSources(void) const;
993 
998  virtual void setClockSource(const std::string &source);
999 
1004  virtual std::string getClockSource(void) const;
1005 
1006  /*******************************************************************
1007  * Time API
1008  ******************************************************************/
1009 
1014  virtual std::vector<std::string> listTimeSources(void) const;
1015 
1020  virtual void setTimeSource(const std::string &source);
1021 
1026  virtual std::string getTimeSource(void) const;
1027 
1033  virtual bool hasHardwareTime(const std::string &what = "") const;
1034 
1041  virtual long long getHardwareTime(const std::string &what = "") const;
1042 
1049  virtual void setHardwareTime(const long long timeNs, const std::string &what = "");
1050 
1059  virtual void setCommandTime(const long long timeNs, const std::string &what = "");
1060 
1061  /*******************************************************************
1062  * Sensor API
1063  ******************************************************************/
1064 
1070  virtual std::vector<std::string> listSensors(void) const;
1071 
1078  virtual ArgInfo getSensorInfo(const std::string &key) const;
1079 
1087  virtual std::string readSensor(const std::string &key) const;
1088 
1095  template <typename Type>
1096  Type readSensor(const std::string &key) const;
1097 
1105  virtual std::vector<std::string> listSensors(const int direction, const size_t channel) const;
1106 
1115  virtual ArgInfo getSensorInfo(const int direction, const size_t channel, const std::string &key) const;
1116 
1126  virtual std::string readSensor(const int direction, const size_t channel, const std::string &key) const;
1127 
1136  template <typename Type>
1137  Type readSensor(const int direction, const size_t channel, const std::string &key) const;
1138 
1139  /*******************************************************************
1140  * Register API
1141  ******************************************************************/
1142 
1147  virtual std::vector<std::string> listRegisterInterfaces(void) const;
1148 
1157  virtual void writeRegister(const std::string &name, const unsigned addr, const unsigned value);
1158 
1165  virtual unsigned readRegister(const std::string &name, const unsigned addr) const;
1166 
1175  virtual void writeRegister(const unsigned addr, const unsigned value);
1176 
1183  virtual unsigned readRegister(const unsigned addr) const;
1184 
1193  virtual void writeRegisters(const std::string &name, const unsigned addr, const std::vector<unsigned> &value);
1194 
1202  virtual std::vector<unsigned> readRegisters(const std::string &name, const unsigned addr, const size_t length) const;
1203 
1204  /*******************************************************************
1205  * Settings API
1206  ******************************************************************/
1207 
1212  virtual ArgInfoList getSettingInfo(void) const;
1213 
1220  virtual void writeSetting(const std::string &key, const std::string &value);
1221 
1228  template <typename Type>
1229  void writeSetting(const std::string &key, const Type &value);
1230 
1236  virtual std::string readSetting(const std::string &key) const;
1237 
1244  template <typename Type>
1245  Type readSetting(const std::string &key);
1246 
1253  virtual ArgInfoList getSettingInfo(const int direction, const size_t channel) const;
1254 
1263  virtual void writeSetting(const int direction, const size_t channel, const std::string &key, const std::string &value);
1264 
1273  template <typename Type>
1274  void writeSetting(const int direction, const size_t channel, const std::string &key, const Type &value);
1275 
1283  virtual std::string readSetting(const int direction, const size_t channel, const std::string &key) const;
1284 
1293  template <typename Type>
1294  Type readSetting(const int direction, const size_t channel, const std::string &key);
1295 
1296  /*******************************************************************
1297  * GPIO API
1298  ******************************************************************/
1299 
1303  virtual std::vector<std::string> listGPIOBanks(void) const;
1304 
1310  virtual void writeGPIO(const std::string &bank, const unsigned value);
1311 
1318  virtual void writeGPIO(const std::string &bank, const unsigned value, const unsigned mask);
1319 
1325  virtual unsigned readGPIO(const std::string &bank) const;
1326 
1333  virtual void writeGPIODir(const std::string &bank, const unsigned dir);
1334 
1342  virtual void writeGPIODir(const std::string &bank, const unsigned dir, const unsigned mask);
1343 
1350  virtual unsigned readGPIODir(const std::string &bank) const;
1351 
1352  /*******************************************************************
1353  * I2C API
1354  ******************************************************************/
1355 
1363  virtual void writeI2C(const int addr, const std::string &data);
1364 
1373  virtual std::string readI2C(const int addr, const size_t numBytes);
1374 
1375  /*******************************************************************
1376  * SPI API
1377  ******************************************************************/
1378 
1393  virtual unsigned transactSPI(const int addr, const unsigned data, const size_t numBits);
1394 
1395  /*******************************************************************
1396  * UART API
1397  ******************************************************************/
1398 
1403  virtual std::vector<std::string> listUARTs(void) const;
1404 
1412  virtual void writeUART(const std::string &which, const std::string &data);
1413 
1422  virtual std::string readUART(const std::string &which, const long timeoutUs = 100000) const;
1423 
1424  /*******************************************************************
1425  * Native Access API
1426  ******************************************************************/
1427 
1434  virtual void* getNativeDeviceHandle(void) const;
1435 };
1436 
1437 }
1438 
1439 template <typename Type>
1440 Type SoapySDR::Device::readSensor(const std::string &key) const
1441 {
1442  return SoapySDR::StringToSetting<Type>(this->readSensor(key));
1443 }
1444 
1445 template <typename Type>
1446 Type SoapySDR::Device::readSensor(const int direction, const size_t channel, const std::string &key) const
1447 {
1448  return SoapySDR::StringToSetting<Type>(this->readSensor(direction, channel, key));
1449 }
1450 
1451 template <typename Type>
1452 void SoapySDR::Device::writeSetting(const std::string &key, const Type &value)
1453 {
1454  this->writeSetting(key, SoapySDR::SettingToString(value));
1455 }
1456 
1457 template <typename Type>
1458 Type SoapySDR::Device::readSetting(const std::string &key)
1459 {
1460  return SoapySDR::StringToSetting<Type>(this->readSetting(key));
1461 }
1462 
1463 template <typename Type>
1464 void SoapySDR::Device::writeSetting(const int direction, const size_t channel, const std::string &key, const Type &value)
1465 {
1466  this->writeSetting(direction, channel, key, SoapySDR::SettingToString(value));
1467 }
1468 
1469 template <typename Type>
1470 Type SoapySDR::Device::readSetting(const int direction, const size_t channel, const std::string &key)
1471 {
1472  return SoapySDR::StringToSetting<Type>(this->readSetting(direction, channel, key));
1473 }
SOAPY_SDR_API
#define SOAPY_SDR_API
Definition: Config.h:41
SoapySDR::Device::readSetting
virtual std::string readSetting(const std::string &key) const
SoapySDR::Range
Definition: Types.hpp:63
SoapySDR::Device
Definition: Device.hpp:32
SoapySDR::SettingToString
std::string SettingToString(const Type &s)
Definition: Types.hpp:242
SoapySDR::Device::writeSetting
virtual void writeSetting(const std::string &key, const std::string &value)
SoapySDR::RangeList
std::vector< Range > RangeList
Definition: Types.hpp:91
SoapySDR
Definition: ConverterPrimitives.hpp:14
Constants.h
SoapySDR::ArgInfoList
std::vector< ArgInfo > ArgInfoList
Definition: Types.hpp:148
Config.hpp
SoapySDR::Kwargs
std::map< std::string, std::string > Kwargs
Typedef for a dictionary of key-value string arguments.
Definition: Types.hpp:23
SoapySDR::Device::readSensor
virtual std::string readSensor(const std::string &key) const
Errors.h
SoapySDR::KwargsList
std::vector< Kwargs > KwargsList
Typedef for a list of key-word dictionaries.
Definition: Types.hpp:38
SoapySDR::ArgInfo
Definition: Types.hpp:96
Types.hpp