rtl-sdr.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
  3. * Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de>
  4. * Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __RTL_SDR_H
  20. #define __RTL_SDR_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #include <stdint.h>
  25. #include <rtl-sdr_export.h>
  26. typedef struct rtlsdr_dev rtlsdr_dev_t;
  27. RTLSDR_API uint32_t rtlsdr_get_device_count(void);
  28. RTLSDR_API const char* rtlsdr_get_device_name(uint32_t index);
  29. RTLSDR_API int rtlsdr_open(rtlsdr_dev_t **dev, uint32_t index);
  30. RTLSDR_API int rtlsdr_close(rtlsdr_dev_t *dev);
  31. /* configuration functions */
  32. RTLSDR_API int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq);
  33. /*!
  34. * Get actual frequency the device is tuned to.
  35. *
  36. * \param dev the device handle given by rtlsdr_open()
  37. * \return 0 on error, frequency in Hz otherwise
  38. */
  39. RTLSDR_API uint32_t rtlsdr_get_center_freq(rtlsdr_dev_t *dev);
  40. RTLSDR_API int rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm);
  41. RTLSDR_API int rtlsdr_get_freq_correction(rtlsdr_dev_t *dev);
  42. RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);
  43. RTLSDR_API int rtlsdr_get_tuner_gain(rtlsdr_dev_t *dev);
  44. /* this will select the baseband filters according to the requested sample rate */
  45. RTLSDR_API int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t rate);
  46. /*!
  47. * Get actual sample rate the device is configured to.
  48. *
  49. * \param dev the device handle given by rtlsdr_open()
  50. * \return 0 on error, sample rate in Hz otherwise
  51. */
  52. RTLSDR_API uint32_t rtlsdr_get_sample_rate(rtlsdr_dev_t *dev);
  53. /* streaming functions */
  54. RTLSDR_API int rtlsdr_reset_buffer(rtlsdr_dev_t *dev);
  55. RTLSDR_API int rtlsdr_read_sync(rtlsdr_dev_t *dev, void *buf, int len, int *n_read);
  56. typedef void(*rtlsdr_read_async_cb_t)(unsigned char *buf, uint32_t len, void *ctx);
  57. /*!
  58. * Read samples from the device asynchronously. This function will block until
  59. * it is being canceled using rtlsdr_cancel_async()
  60. *
  61. * NOTE: This function is deprecated and is subject for removal.
  62. *
  63. * \param dev the device handle given by rtlsdr_open()
  64. * \param cb callback function to return received samples
  65. * \param ctx user specific context to pass via the callback function
  66. * \return 0 on success
  67. */
  68. RTLSDR_API int rtlsdr_wait_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx);
  69. /*!
  70. * Read samples from the device asynchronously. This function will block until
  71. * it is being canceled using rtlsdr_cancel_async()
  72. *
  73. * \param dev the device handle given by rtlsdr_open()
  74. * \param cb callback function to return received samples
  75. * \param ctx user specific context to pass via the callback function
  76. * \param buf_num optional buffer count, buf_num * buf_len = overall buffer size
  77. * set to 0 for default buffer count (32)
  78. * \param buf_len optional buffer length, must be multiple of 512,
  79. * set to 0 for default buffer length (16 * 32 * 512)
  80. * \return 0 on success
  81. */
  82. RTLSDR_API int rtlsdr_read_async(rtlsdr_dev_t *dev,
  83. rtlsdr_read_async_cb_t cb,
  84. void *ctx,
  85. uint32_t buf_num,
  86. uint32_t buf_len);
  87. /*!
  88. * Cancel all pending asynchronous operations on the device.
  89. *
  90. * \param dev the device handle given by rtlsdr_open()
  91. * \return 0 on success
  92. */
  93. RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev);
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* __RTL_SDR_H */