SoapySDR  0.5.4-g68d0793c
Vendor and platform neutral SDR interface library
Device.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #include <SoapySDR/Config.hpp>
14 #include <SoapySDR/Types.hpp>
15 #include <SoapySDR/Constants.h>
16 #include <SoapySDR/Errors.h>
17 #include <vector>
18 #include <string>
19 #include <complex>
20 #include <cstddef> //size_t
21 
22 namespace SoapySDR
23 {
24 
26 class Stream;
27 
32 {
33 public:
34 
36  virtual ~Device(void);
37 
43  static KwargsList enumerate(const Kwargs &args = Kwargs());
44 
51  static KwargsList enumerate(const std::string &args);
52 
62  static Device *make(const Kwargs &args = Kwargs());
63 
73  static Device *make(const std::string &args);
74 
83  static void unmake(Device *device);
84 
85  /*******************************************************************
86  * Identification API
87  ******************************************************************/
88 
94  virtual std::string getDriverKey(void) const;
95 
101  virtual std::string getHardwareKey(void) const;
102 
110  virtual Kwargs getHardwareInfo(void) const;
111 
112  /*******************************************************************
113  * Channels API
114  ******************************************************************/
115 
122  virtual void setFrontendMapping(const int direction, const std::string &mapping);
123 
129  virtual std::string getFrontendMapping(const int direction) const;
130 
134  virtual size_t getNumChannels(const int direction) const;
135 
146  virtual Kwargs getChannelInfo(const int direction, const size_t channel) const;
147 
154  virtual bool getFullDuplex(const int direction, const size_t channel) const;
155 
156  /*******************************************************************
157  * Stream API
158  ******************************************************************/
159 
166  virtual std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
167 
177  virtual std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
178 
185  virtual ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const;
186 
217  virtual Stream *setupStream(
218  const int direction,
219  const std::string &format,
220  const std::vector<size_t> &channels = std::vector<size_t>(),
221  const Kwargs &args = Kwargs());
222 
228  virtual void closeStream(Stream *stream);
229 
239  virtual size_t getStreamMTU(Stream *stream) const;
240 
258  virtual int activateStream(
259  Stream *stream,
260  const int flags = 0,
261  const long long timeNs = 0,
262  const size_t numElems = 0);
263 
278  virtual int deactivateStream(
279  Stream *stream,
280  const int flags = 0,
281  const long long timeNs = 0);
282 
302  virtual int readStream(
303  Stream *stream,
304  void * const *buffs,
305  const size_t numElems,
306  int &flags,
307  long long &timeNs,
308  const long timeoutUs = 100000);
309 
329  virtual int writeStream(
330  Stream *stream,
331  const void * const *buffs,
332  const size_t numElems,
333  int &flags,
334  const long long timeNs = 0,
335  const long timeoutUs = 100000);
336 
357  virtual int readStreamStatus(
358  Stream *stream,
359  size_t &chanMask,
360  int &flags,
361  long long &timeNs,
362  const long timeoutUs = 100000);
363 
364  /*******************************************************************
365  * Direct buffer access API
366  ******************************************************************/
367 
377  virtual size_t getNumDirectAccessBuffers(Stream *stream);
378 
392  virtual int getDirectAccessBufferAddrs(Stream *stream, const size_t handle, void **buffs);
393 
414  virtual int acquireReadBuffer(
415  Stream *stream,
416  size_t &handle,
417  const void **buffs,
418  int &flags,
419  long long &timeNs,
420  const long timeoutUs = 100000);
421 
429  virtual void releaseReadBuffer(
430  Stream *stream,
431  const size_t handle);
432 
451  virtual int acquireWriteBuffer(
452  Stream *stream,
453  size_t &handle,
454  void **buffs,
455  const long timeoutUs = 100000);
456 
472  virtual void releaseWriteBuffer(
473  Stream *stream,
474  const size_t handle,
475  const size_t numElems,
476  int &flags,
477  const long long timeNs = 0);
478 
479  /*******************************************************************
480  * Antenna API
481  ******************************************************************/
482 
489  virtual std::vector<std::string> listAntennas(const int direction, const size_t channel) const;
490 
497  virtual void setAntenna(const int direction, const size_t channel, const std::string &name);
498 
505  virtual std::string getAntenna(const int direction, const size_t channel) const;
506 
507  /*******************************************************************
508  * Frontend corrections API
509  ******************************************************************/
510 
517  virtual bool hasDCOffsetMode(const int direction, const size_t channel) const;
518 
525  virtual void setDCOffsetMode(const int direction, const size_t channel, const bool automatic);
526 
533  virtual bool getDCOffsetMode(const int direction, const size_t channel) const;
534 
541  virtual bool hasDCOffset(const int direction, const size_t channel) const;
542 
549  virtual void setDCOffset(const int direction, const size_t channel, const std::complex<double> &offset);
550 
557  virtual std::complex<double> getDCOffset(const int direction, const size_t channel) const;
558 
565  virtual bool hasIQBalance(const int direction, const size_t channel) const;
566 
573  virtual void setIQBalance(const int direction, const size_t channel, const std::complex<double> &balance);
574 
581  virtual std::complex<double> getIQBalance(const int direction, const size_t channel) const;
582 
583  /*******************************************************************
584  * Gain API
585  ******************************************************************/
586 
594  virtual std::vector<std::string> listGains(const int direction, const size_t channel) const;
595 
602  virtual bool hasGainMode(const int direction, const size_t channel) const;
603 
610  virtual void setGainMode(const int direction, const size_t channel, const bool automatic);
611 
618  virtual bool getGainMode(const int direction, const size_t channel) const;
619 
627  virtual void setGain(const int direction, const size_t channel, const double value);
628 
636  virtual void setGain(const int direction, const size_t channel, const std::string &name, const double value);
637 
644  virtual double getGain(const int direction, const size_t channel) const;
645 
653  virtual double getGain(const int direction, const size_t channel, const std::string &name) const;
654 
661  virtual Range getGainRange(const int direction, const size_t channel) const;
662 
670  virtual Range getGainRange(const int direction, const size_t channel, const std::string &name) const;
671 
672  /*******************************************************************
673  * Frequency API
674  ******************************************************************/
675 
703  virtual void setFrequency(const int direction, const size_t channel, const double frequency, const Kwargs &args = Kwargs());
704 
721  virtual void setFrequency(const int direction, const size_t channel, const std::string &name, const double frequency, const Kwargs &args = Kwargs());
722 
731  virtual double getFrequency(const int direction, const size_t channel) const;
732 
740  virtual double getFrequency(const int direction, const size_t channel, const std::string &name) const;
741 
749  virtual std::vector<std::string> listFrequencies(const int direction, const size_t channel) const;
750 
757  virtual RangeList getFrequencyRange(const int direction, const size_t channel) const;
758 
766  virtual RangeList getFrequencyRange(const int direction, const size_t channel, const std::string &name) const;
767 
774  virtual ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const;
775 
776  /*******************************************************************
777  * Sample Rate API
778  ******************************************************************/
779 
786  virtual void setSampleRate(const int direction, const size_t channel, const double rate);
787 
794  virtual double getSampleRate(const int direction, const size_t channel) const;
795 
802  virtual std::vector<double> listSampleRates(const int direction, const size_t channel) const;
803 
804  /*******************************************************************
805  * Bandwidth API
806  ******************************************************************/
807 
814  virtual void setBandwidth(const int direction, const size_t channel, const double bw);
815 
822  virtual double getBandwidth(const int direction, const size_t channel) const;
823 
831  virtual std::vector<double> listBandwidths(const int direction, const size_t channel) const;
832 
839  virtual RangeList getBandwidthRange(const int direction, const size_t channel) const;
840 
841  /*******************************************************************
842  * Clocking API
843  ******************************************************************/
844 
849  virtual void setMasterClockRate(const double rate);
850 
855  virtual double getMasterClockRate(void) const;
856 
861  virtual RangeList getMasterClockRates(void) const;
862 
867  virtual std::vector<std::string> listClockSources(void) const;
868 
873  virtual void setClockSource(const std::string &source);
874 
879  virtual std::string getClockSource(void) const;
880 
881  /*******************************************************************
882  * Time API
883  ******************************************************************/
884 
889  virtual std::vector<std::string> listTimeSources(void) const;
890 
895  virtual void setTimeSource(const std::string &source);
896 
901  virtual std::string getTimeSource(void) const;
902 
908  virtual bool hasHardwareTime(const std::string &what = "") const;
909 
916  virtual long long getHardwareTime(const std::string &what = "") const;
917 
924  virtual void setHardwareTime(const long long timeNs, const std::string &what = "");
925 
934  virtual void setCommandTime(const long long timeNs, const std::string &what = "");
935 
936  /*******************************************************************
937  * Sensor API
938  ******************************************************************/
939 
945  virtual std::vector<std::string> listSensors(void) const;
946 
953  virtual ArgInfo getSensorInfo(const std::string &name) const;
954 
962  virtual std::string readSensor(const std::string &name) const;
963 
971  virtual std::vector<std::string> listSensors(const int direction, const size_t channel) const;
972 
981  virtual ArgInfo getSensorInfo(const int direction, const size_t channel, const std::string &name) const;
982 
992  virtual std::string readSensor(const int direction, const size_t channel, const std::string &name) const;
993 
994  /*******************************************************************
995  * Register API
996  ******************************************************************/
997 
1002  virtual std::vector<std::string> listRegisterInterfaces(void) const;
1003 
1012  virtual void writeRegister(const std::string &name, const unsigned addr, const unsigned value);
1013 
1020  virtual unsigned readRegister(const std::string &name, const unsigned addr) const;
1021 
1030  virtual void writeRegister(const unsigned addr, const unsigned value);
1031 
1038  virtual unsigned readRegister(const unsigned addr) const;
1039 
1040  /*******************************************************************
1041  * Settings API
1042  ******************************************************************/
1043 
1048  virtual ArgInfoList getSettingInfo(void) const;
1049 
1056  virtual void writeSetting(const std::string &key, const std::string &value);
1057 
1063  virtual std::string readSetting(const std::string &key) const;
1064 
1071  virtual ArgInfoList getSettingInfo(const int direction, const size_t channel) const;
1072 
1081  virtual void writeSetting(const int direction, const size_t channel, const std::string &key, const std::string &value);
1082 
1090  virtual std::string readSetting(const int direction, const size_t channel, const std::string &key) const;
1091 
1092  /*******************************************************************
1093  * GPIO API
1094  ******************************************************************/
1095 
1099  virtual std::vector<std::string> listGPIOBanks(void) const;
1100 
1106  virtual void writeGPIO(const std::string &bank, const unsigned value);
1107 
1114  virtual void writeGPIO(const std::string &bank, const unsigned value, const unsigned mask);
1115 
1121  virtual unsigned readGPIO(const std::string &bank) const;
1122 
1129  virtual void writeGPIODir(const std::string &bank, const unsigned dir);
1130 
1138  virtual void writeGPIODir(const std::string &bank, const unsigned dir, const unsigned mask);
1139 
1146  virtual unsigned readGPIODir(const std::string &bank) const;
1147 
1148  /*******************************************************************
1149  * I2C API
1150  ******************************************************************/
1151 
1159  virtual void writeI2C(const int addr, const std::string &data);
1160 
1169  virtual std::string readI2C(const int addr, const size_t numBytes);
1170 
1171  /*******************************************************************
1172  * SPI API
1173  ******************************************************************/
1174 
1189  virtual unsigned transactSPI(const int addr, const unsigned data, const size_t numBits);
1190 
1191  /*******************************************************************
1192  * UART API
1193  ******************************************************************/
1194 
1199  virtual std::vector<std::string> listUARTs(void) const;
1200 
1208  virtual void writeUART(const std::string &which, const std::string &data);
1209 
1218  virtual std::string readUART(const std::string &which, const long timeoutUs = 100000) const;
1219 
1220 };
1221 
1222 };
Definition: Types.hpp:30
std::vector< Kwargs > KwargsList
Typedef for a list of key-word dictionaries.
Definition: Types.hpp:25
std::vector< ArgInfo > ArgInfoList
Definition: Types.hpp:112
std::map< std::string, std::string > Kwargs
Typedef for a dictionary of key-value string arguments.
Definition: Types.hpp:22
std::vector< Range > RangeList
Definition: Types.hpp:55
Definition: Types.hpp:60
Definition: Device.hpp:22
Definition: Device.hpp:31
#define SOAPY_SDR_API
Definition: Config.h:41