Hi Alex,

thank you for your hint. I added the device_name parameter .
Now if the device name is not empty, I try to open the appropriate alsa device. If the device string is empty or opening device failed ( perhaps the device string was misspelled ) I try to autodetect the dongle.

I personally prefer autodetection, as the order of my soundcards may change from boot to boot. So I attach a small patch for gr-fcd to enable autodetection, too.

Volker



Am 01.04.2013 00:29, schrieb Alexandru Csete:
On Thu, Mar 28, 2013 at 11:41 AM, Volker Schroer <dl1...@gmx.de> wrote:
Just for your information:

In imitation of the gr-fcd source I set up a gnuradio source for the funcube
pro+ ( linux only) . To avoid the crashes depending on libusb I used the
hidraw driver.

The source and an example can be found on

https://github.com/dl1ksv/gr-fcdproplus.git

Comments are welcome.
Enjoy it

Hi Volker,

Nice work.
I would recommend letting the user specify the device string and only
use auto-detection if string is empty.

Alex


>From 15f35d9e701e1eaea113d22a0835384751a8bc4d Mon Sep 17 00:00:00 2001
From: dl1ksv <dl1...@gmx.de>
Date: Tue, 2 Apr 2013 11:27:15 +0200
Subject: [PATCH] added autodetect feature to gr-fcd

---
 gr-fcd/lib/fcd_source_c_impl.cc | 46 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/gr-fcd/lib/fcd_source_c_impl.cc b/gr-fcd/lib/fcd_source_c_impl.cc
index 81ccee0..7367334 100644
--- a/gr-fcd/lib/fcd_source_c_impl.cc
+++ b/gr-fcd/lib/fcd_source_c_impl.cc
@@ -29,6 +29,10 @@
 #include <gr_float_to_complex.h>
 #include <gruel/attributes.h>
 
+#include <fstream>
+#include <exception>
+
+
 //#include <iostream>
 //using namespace std;
 
@@ -54,9 +58,49 @@ fcd_source_c_impl::fcd_source_c_impl(const std::string device_name)
     d_freq_req(0)
 {
   gr_float_to_complex_sptr f2c;
+  bool success;
 
   /* Audio source; sample rate fixed at 96kHz */
-  fcd = audio_make_source(96000, device_name, true);
+  if(!device_name.empty())  {
+      try {
+           /* Audio source; sample rate fixed at 192kHz */
+           fcd = audio_make_source(96000, device_name, true);
+           success=true;
+      }
+      catch (std::exception ) {
+          success=false;
+      }
+  }
+  if (! success)  {
+    std::string auto_device_name;
+    auto_device_name.clear();
+    std::string line;
+    std::ifstream cards( "/proc/asound/cards" );
+    if ( cards.is_open() )  {
+        while ( cards.good() )  {
+            getline (cards, line);
+
+            if ( line.find( "USB-Audio - FUNcube Dongle V1.0" ) != std::string::npos )  {
+                int id;
+                std::istringstream( line ) >> id;
+
+                std::ostringstream hw_id;
+                hw_id << "plughw:" << id<<",0"; // build alsa identifier
+                auto_device_name= hw_id.str();
+                break;
+             }
+         }
+         cards.close();
+         if(auto_device_name.empty()) {
+            throw std::runtime_error("No FunCube Dongle  V1.0 found.");
+         }
+     }
+     else {
+     throw std::runtime_error("Alsa not found.");
+     }
+     /* Audio source; sample rate fixed at 96kHz */
+              fcd = audio_make_source(96000,auto_device_name, true);
+  }
 
   /* block to convert stereo audio to a complex stream */
   f2c = gr_make_float_to_complex(1);
-- 
1.8.1.5

_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to