Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. /*
  2. * This file is part of the bladeRF project:
  3. * http://www.github.com/nuand/bladeRF
  4. *
  5. * Copyright (C) 2014 Nuand LLC
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <libbladeRF.h>
  29. #include "example_common.h"
  30. #include <unistd.h>
  31.  
  32.  
  33. struct bladerf *example_init(const char *devstr)
  34. {
  35. int status;
  36. struct bladerf *dev;
  37.  
  38. printf("Opening and initializing device...\n\n");
  39.  
  40. status = bladerf_open(&dev, devstr);
  41. if (status != 0) {
  42. fprintf(stderr, "Failed to open device: %s\n",
  43. bladerf_strerror(status));
  44. goto out;
  45. }
  46.  
  47. status = bladerf_set_frequency(dev, BLADERF_MODULE_RX, EXAMPLE_RX_FREQ);
  48. if (status != 0) {
  49. fprintf(stderr, "Failed to set RX frequency: %s\n",
  50. bladerf_strerror(status));
  51. goto out;
  52. } else {
  53. printf("RX frequency: %u Hz\n", EXAMPLE_RX_FREQ);
  54. }
  55.  
  56. status = bladerf_set_sample_rate(dev, BLADERF_MODULE_RX,
  57. EXAMPLE_SAMPLERATE, NULL);
  58. if (status != 0) {
  59. fprintf(stderr, "Failed to set RX sample rate: %s\n",
  60. bladerf_strerror(status));
  61. goto out;
  62. } else {
  63. printf("RX samplerate: %u sps\n", EXAMPLE_SAMPLERATE);
  64. }
  65.  
  66. status = bladerf_set_bandwidth(dev, BLADERF_MODULE_RX,
  67. EXAMPLE_BANDWIDTH, NULL);
  68. if (status != 0) {
  69. fprintf(stderr, "Failed to set RX bandwidth: %s\n",
  70. bladerf_strerror(status));
  71. goto out;
  72. } else {
  73. printf("RX bandwidth: %u Hz\n", EXAMPLE_BANDWIDTH);
  74. }
  75.  
  76. status = bladerf_set_lna_gain(dev, EXAMPLE_RX_LNA);
  77. if (status != 0) {
  78. fprintf(stderr, "Failed to set RX LNA gain: %s\n",
  79. bladerf_strerror(status));
  80. goto out;
  81. } else {
  82. printf("RX LNA Gain: Max\n");
  83. }
  84.  
  85. status = bladerf_set_rxvga1(dev, EXAMPLE_RX_VGA1);
  86. if (status != 0) {
  87. fprintf(stderr, "Failed to set RX VGA1 gain: %s\n",
  88. bladerf_strerror(status));
  89. goto out;
  90. } else {
  91. printf("RX VGA1 gain: %d\n", EXAMPLE_RX_VGA1);
  92. }
  93.  
  94. status = bladerf_set_rxvga2(dev, EXAMPLE_RX_VGA2);
  95. if (status != 0) {
  96. fprintf(stderr, "Failed to set RX VGA2 gain: %s\n",
  97. bladerf_strerror(status));
  98. goto out;
  99. } else {
  100. printf("RX VGA2 gain: %d\n\n", EXAMPLE_RX_VGA2);
  101. }
  102.  
  103. status = bladerf_set_frequency(dev, BLADERF_MODULE_TX, EXAMPLE_TX_FREQ);
  104. if (status != 0) {
  105. fprintf(stderr, "Faield to set TX frequency: %s\n",
  106. bladerf_strerror(status));
  107. goto out;
  108. } else {
  109. printf("TX frequency: %u Hz\n", EXAMPLE_TX_FREQ);
  110. }
  111.  
  112. status = bladerf_set_sample_rate(dev, BLADERF_MODULE_TX,
  113. EXAMPLE_SAMPLERATE, NULL);
  114. if (status != 0) {
  115. fprintf(stderr, "Failed to set TX sample rate: %s\n",
  116. bladerf_strerror(status));
  117. goto out;
  118. } else {
  119. printf("TX samplerate: %u sps\n", EXAMPLE_SAMPLERATE);
  120. }
  121.  
  122. status = bladerf_set_bandwidth(dev, BLADERF_MODULE_TX,
  123. EXAMPLE_BANDWIDTH, NULL);
  124. if (status != 0) {
  125. fprintf(stderr, "Failed to set TX bandwidth: %s\n",
  126. bladerf_strerror(status));
  127. goto out;
  128. } else {
  129. printf("TX bandwidth: %u\n", EXAMPLE_BANDWIDTH);
  130. }
  131.  
  132. status = bladerf_set_txvga1(dev, EXAMPLE_TX_VGA1);
  133. if (status != 0) {
  134. fprintf(stderr, "Failed to set TX VGA1 gain: %s\n",
  135. bladerf_strerror(status));
  136. goto out;
  137. } else {
  138. printf("TX VGA1 gain: %d\n", EXAMPLE_TX_VGA1);
  139. }
  140.  
  141. status = bladerf_set_txvga2(dev, EXAMPLE_TX_VGA2);
  142. if (status != 0) {
  143. fprintf(stderr, "Failed to set TX VGA2 gain: %s\n",
  144. bladerf_strerror(status));
  145. goto out;
  146. } else {
  147. printf("TX VGA2 gain: %d\n\n", EXAMPLE_TX_VGA2);
  148. }
  149.  
  150. status = bladerf_enable_module(dev, BLADERF_MODULE_RX, true);
  151. if (status != 0) {
  152. fprintf(stderr, "Failed to enable RX module: %s\n",
  153. bladerf_strerror(status));
  154. goto out;
  155. }
  156.  
  157. status = bladerf_enable_module(dev, BLADERF_MODULE_TX, true);
  158. if (status != 0) {
  159. fprintf(stderr, "Failed to enable TX module: %s\n",
  160. bladerf_strerror(status));
  161. goto out;
  162. }
  163.  
  164.  
  165. usleep(3000000000);
  166.  
  167.  
  168.  
  169. out:
  170. if (status != 0) {
  171. bladerf_close(dev);
  172. return NULL;
  173. } else {
  174. return dev;
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement