SoapySDR  0.4.4-gdb459f4f
Vendor and platform neutral SDR interface library
Device.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <SoapySDR/Config.hpp>
13 #include <SoapySDR/Types.hpp>
14 #include <SoapySDR/Constants.h>
15 #include <SoapySDR/Errors.h>
16 #include <vector>
17 #include <string>
18 #include <complex>
19 #include <cstddef> //size_t
20 
21 namespace SoapySDR
22 {
23 
25 class Stream;
26 
31 {
32 public:
33 
35  virtual ~Device(void);
36 
42  static KwargsList enumerate(const Kwargs &args = Kwargs());
43 
50  static KwargsList enumerate(const std::string &args);
51 
64  static Device *make(const Kwargs &args = Kwargs());
65 
78  static Device *make(const std::string &args);
79 
88  static void unmake(Device *device);
89 
90  /*******************************************************************
91  * Identification API
92  ******************************************************************/
93 
99  virtual std::string getDriverKey(void) const;
100 
106  virtual std::string getHardwareKey(void) const;
107 
115  virtual Kwargs getHardwareInfo(void) const;
116 
117  /*******************************************************************
118  * Channels API
119  ******************************************************************/
120 
127  virtual void setFrontendMapping(const int direction, const std::string &mapping);
128 
134  virtual std::string getFrontendMapping(const int direction) const;
135 
139  virtual size_t getNumChannels(const int direction) const;
140 
147  virtual bool getFullDuplex(const int direction, const size_t channel) const;
148 
149  /*******************************************************************
150  * Stream API
151  ******************************************************************/
152 
159  virtual std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
160 
170  virtual std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
171 
178  virtual ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const;
179 
210  virtual Stream *setupStream(
211  const int direction,
212  const std::string &format,
213  const std::vector<size_t> &channels = std::vector<size_t>(),
214  const Kwargs &args = Kwargs());
215 
221  virtual void closeStream(Stream *stream);
222 
232  virtual size_t getStreamMTU(Stream *stream) const;
233 
251  virtual int activateStream(
252  Stream *stream,
253  const int flags = 0,
254  const long long timeNs = 0,
255  const size_t numElems = 0);
256 
271  virtual int deactivateStream(
272  Stream *stream,
273  const int flags = 0,
274  const long long timeNs = 0);
275 
295  virtual int readStream(
296  Stream *stream,
297  void * const *buffs,
298  const size_t numElems,
299  int &flags,
300  long long &timeNs,
301  const long timeoutUs = 100000);
302 
322  virtual int writeStream(
323  Stream *stream,
324  const void * const *buffs,
325  const size_t numElems,
326  int &flags,
327  const long long timeNs = 0,
328  const long timeoutUs = 100000);
329 
350  virtual int readStreamStatus(
351  Stream *stream,
352  size_t &chanMask,
353  int &flags,
354  long long &timeNs,
355  const long timeoutUs = 100000);
356 
357  /*******************************************************************
358  * Direct buffer access API
359  ******************************************************************/
360 
370  virtual size_t getNumDirectAccessBuffers(Stream *stream);
371 
385  virtual int getDirectAccessBufferAddrs(Stream *stream, const size_t handle, void **buffs);
386 
407  virtual int acquireReadBuffer(
408  Stream *stream,
409  size_t &handle,
410  const void **buffs,
411  int &flags,
412  long long &timeNs,
413  const long timeoutUs = 100000);
414 
422  virtual void releaseReadBuffer(
423  Stream *stream,
424  const size_t handle);
425 
446  virtual int acquireWriteBuffer(
447  Stream *stream,
448  size_t &handle,
449  void **buffs,
450  const long timeoutUs = 100000);
451 
467  virtual void releaseWriteBuffer(
468  Stream *stream,
469  const size_t handle,
470  const size_t numElems,
471  int &flags,
472  const long long timeNs = 0);
473 
474  /*******************************************************************
475  * Antenna API
476  ******************************************************************/
477 
484  virtual std::vector<std::string> listAntennas(const int direction, const size_t channel) const;
485 
492  virtual void setAntenna(const int direction, const size_t channel, const std::string &name);
493 
500  virtual std::string getAntenna(const int direction, const size_t channel) const;
501 
502  /*******************************************************************
503  * Frontend corrections API
504  ******************************************************************/
505 
512  virtual bool hasDCOffsetMode(const int direction, const size_t channel) const;
513 
520  virtual void setDCOffsetMode(const int direction, const size_t channel, const bool automatic);
521 
528  virtual bool getDCOffsetMode(const int direction, const size_t channel) const;
529 
536  virtual bool hasDCOffset(const int direction, const size_t channel) const;
537 
544  virtual void setDCOffset(const int direction, const size_t channel, const std::complex<double> &offset);
545 
552  virtual std::complex<double> getDCOffset(const int direction, const size_t channel) const;
553 
560  virtual bool hasIQBalance(const int direction, const size_t channel) const;
561 
568  virtual void setIQBalance(const int direction, const size_t channel, const std::complex<double> &balance);
569 
576  virtual std::complex<double> getIQBalance(const int direction, const size_t channel) const;
577 
578  /*******************************************************************
579  * Gain API
580  ******************************************************************/
581 
589  virtual std::vector<std::string> listGains(const int direction, const size_t channel) const;
590 
597  virtual bool hasGainMode(const int direction, const size_t channel) const;
598 
605  virtual void setGainMode(const int direction, const size_t channel, const bool automatic);
606 
613  virtual bool getGainMode(const int direction, const size_t channel) const;
614 
623  virtual void setGain(const int direction, const size_t channel, const double value);
624 
632  virtual void setGain(const int direction, const size_t channel, const std::string &name, const double value);
633 
640  virtual double getGain(const int direction, const size_t channel) const;
641 
649  virtual double getGain(const int direction, const size_t channel, const std::string &name) const;
650 
657  virtual Range getGainRange(const int direction, const size_t channel) const;
658 
666  virtual Range getGainRange(const int direction, const size_t channel, const std::string &name) const;
667 
668  /*******************************************************************
669  * Frequency API
670  ******************************************************************/
671 
699  virtual void setFrequency(const int direction, const size_t channel, const double frequency, const Kwargs &args = Kwargs());
700 
717  virtual void setFrequency(const int direction, const size_t channel, const std::string &name, const double frequency, const Kwargs &args = Kwargs());
718 
727  virtual double getFrequency(const int direction, const size_t channel) const;
728 
736  virtual double getFrequency(const int direction, const size_t channel, const std::string &name) const;
737 
745  virtual std::vector<std::string> listFrequencies(const int direction, const size_t channel) const;
746 
753  virtual RangeList getFrequencyRange(const int direction, const size_t channel) const;
754 
762  virtual RangeList getFrequencyRange(const int direction, const size_t channel, const std::string &name) const;
763 
770  virtual ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const;
771 
772  /*******************************************************************
773  * Sample Rate API
774  ******************************************************************/
775 
782  virtual void setSampleRate(const int direction, const size_t channel, const double rate);
783 
790  virtual double getSampleRate(const int direction, const size_t channel) const;
791 
798  virtual std::vector<double> listSampleRates(const int direction, const size_t channel) const;
799 
800  /*******************************************************************
801  * Bandwidth API
802  ******************************************************************/
803 
810  virtual void setBandwidth(const int direction, const size_t channel, const double bw);
811 
818  virtual double getBandwidth(const int direction, const size_t channel) const;
819 
826  virtual std::vector<double> listBandwidths(const int direction, const size_t channel) const;
827 
828  /*******************************************************************
829  * Clocking API
830  ******************************************************************/
831 
836  virtual void setMasterClockRate(const double rate);
837 
842  virtual double getMasterClockRate(void) const;
843 
848  virtual RangeList getMasterClockRates(void) const;
849 
854  virtual std::vector<std::string> listClockSources(void) const;
855 
860  virtual void setClockSource(const std::string &source);
861 
866  virtual std::string getClockSource(void) const;
867 
872  virtual std::vector<std::string> listTimeSources(void) const;
873 
878  virtual void setTimeSource(const std::string &source);
879 
884  virtual std::string getTimeSource(void) const;
885 
886  /*******************************************************************
887  * Time API
888  ******************************************************************/
889 
895  virtual bool hasHardwareTime(const std::string &what = "") const;
896 
903  virtual long long getHardwareTime(const std::string &what = "") const;
904 
911  virtual void setHardwareTime(const long long timeNs, const std::string &what = "");
912 
920  virtual void setCommandTime(const long long timeNs, const std::string &what = "");
921 
922  /*******************************************************************
923  * Sensor API
924  ******************************************************************/
925 
931  virtual std::vector<std::string> listSensors(void) const;
932 
939  virtual ArgInfo getSensorInfo(const std::string &name) const;
940 
948  virtual std::string readSensor(const std::string &name) const;
949 
957  virtual std::vector<std::string> listSensors(const int direction, const size_t channel) const;
958 
967  virtual ArgInfo getSensorInfo(const int direction, const size_t channel, const std::string &name) const;
968 
978  virtual std::string readSensor(const int direction, const size_t channel, const std::string &name) const;
979 
980  /*******************************************************************
981  * Register API
982  ******************************************************************/
983 
991  virtual void writeRegister(const unsigned addr, const unsigned value);
992 
998  virtual unsigned readRegister(const unsigned addr) const;
999 
1000  /*******************************************************************
1001  * Settings API
1002  ******************************************************************/
1003 
1008  virtual ArgInfoList getSettingInfo(void) const;
1009 
1016  virtual void writeSetting(const std::string &key, const std::string &value);
1017 
1023  virtual std::string readSetting(const std::string &key) const;
1024 
1025  /*******************************************************************
1026  * GPIO API
1027  ******************************************************************/
1028 
1032  virtual std::vector<std::string> listGPIOBanks(void) const;
1033 
1039  virtual void writeGPIO(const std::string &bank, const unsigned value);
1040 
1047  virtual void writeGPIO(const std::string &bank, const unsigned value, const unsigned mask);
1048 
1054  virtual unsigned readGPIO(const std::string &bank) const;
1055 
1062  virtual void writeGPIODir(const std::string &bank, const unsigned dir);
1063 
1071  virtual void writeGPIODir(const std::string &bank, const unsigned dir, const unsigned mask);
1072 
1079  virtual unsigned readGPIODir(const std::string &bank) const;
1080 
1081  /*******************************************************************
1082  * I2C API
1083  ******************************************************************/
1084 
1092  virtual void writeI2C(const int addr, const std::string &data);
1093 
1102  virtual std::string readI2C(const int addr, const size_t numBytes);
1103 
1104  /*******************************************************************
1105  * SPI API
1106  ******************************************************************/
1107 
1122  virtual unsigned transactSPI(const int addr, const unsigned data, const size_t numBits);
1123 
1124  /*******************************************************************
1125  * UART API
1126  ******************************************************************/
1127 
1132  virtual std::vector<std::string> listUARTs(void) const;
1133 
1141  virtual void writeUART(const std::string &which, const std::string &data);
1142 
1151  virtual std::string readUART(const std::string &which, const long timeoutUs = 100000) const;
1152 
1153 };
1154 
1155 };
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:21
Definition: Device.hpp:30
#define SOAPY_SDR_API
Definition: Config.h:41