Skip to content

Instantly share code, notes, and snippets.

@csete
Created July 16, 2013 15:03
Show Gist options
  • Save csete/6009541 to your computer and use it in GitHub Desktop.
Save csete/6009541 to your computer and use it in GitHub Desktop.
Patch to apply to gr-fcdproplus for making it work on kernel 3.8-based systems. Discussion: https://github.com/csete/gqrx/pull/88
diff --git a/lib/fcdproplus_impl.cc b/lib/fcdproplus_impl.cc
index beef6ba..f8f9085 100644
--- a/lib/fcdproplus_impl.cc
+++ b/lib/fcdproplus_impl.cc
@@ -124,8 +124,8 @@ namespace gr {
/* setup the control part */
d_control_handle =NULL;
hid_init();
- d_control_handle = hid_open ( FCDPROPLUS_VENDOR_ID ,FCDPROPLUS_PRODUCT_ID,NULL );
- if(d_control_handle == NULL ) {
+ d_path = hid_get_path ( FCDPROPLUS_VENDOR_ID ,FCDPROPLUS_PRODUCT_ID,NULL );
+ if(d_path == NULL ) {
throw std::runtime_error("FunCube Dongle V2.0 soundcard found but not controlpart.");
}
else {
@@ -138,8 +138,12 @@ namespace gr {
*/
aucBuf[0] = 0; // Report ID. Ignored by HID Class firmware as only config'd for one report
aucBuf[1] = FCD_HID_CMD_QUERY;
+ d_control_handle = hid_open_path(d_path);
+ if (!d_control_handle)
+ return;
hid_write(d_control_handle,aucBuf,65);
hid_read(d_control_handle,aucBuf,65);
+ hid_close(d_control_handle);
std::cerr <<"Result of Action :+++++" << std::endl;
for(int i=2;i<15;i++)
std::cerr << aucBuf[i];
@@ -152,9 +156,6 @@ namespace gr {
*/
fcdproplus_impl::~fcdproplus_impl()
{
- if(d_control_handle !=0) {
- hid_close(d_control_handle);
- }
hid_exit();
}
@@ -178,9 +179,13 @@ namespace gr {
aucBuf[3] = (unsigned char)(nfreq>>8);
aucBuf[4] = (unsigned char)(nfreq>>16);
aucBuf[5] = (unsigned char)(nfreq>>24);
+ d_control_handle = hid_open_path(d_path);
+ if (!d_control_handle)
+ return;
hid_write(d_control_handle, aucBuf, 65);
aucBuf[1]=0;
hid_read(d_control_handle, aucBuf, 65);
+ hid_close(d_control_handle);
if (aucBuf[0]==FCD_HID_CMD_SET_FREQUENCY_HZ && aucBuf[1]==1) {
nfreq = 0;
nfreq = (unsigned int) aucBuf[2];
@@ -211,8 +216,12 @@ namespace gr {
else {
aucBuf[2]=0;
}
+ d_control_handle = hid_open_path(d_path);
+ if (!d_control_handle)
+ return;
hid_write(d_control_handle, aucBuf, 65);
hid_read(d_control_handle, aucBuf, 65);
+ hid_close(d_control_handle);
if(aucBuf[0] == FCD_HID_CMD_SET_LNA_GAIN) {
if (gain != 0) {
std::cerr <<" Lna gain enabled" << std::endl;
@@ -238,8 +247,12 @@ namespace gr {
else {
aucBuf[2]=0;
}
+ d_control_handle = hid_open_path(d_path);
+ if (!d_control_handle)
+ return;
hid_write(d_control_handle, aucBuf, 65);
hid_read(d_control_handle, aucBuf, 65);
+ hid_close(d_control_handle);
if(aucBuf[0] == FCD_HID_CMD_SET_MIXER_GAIN) {
if (gain != 0) {
std::cerr <<" Mixer gain enabled" << std::endl;
@@ -278,8 +291,12 @@ namespace gr {
aucBuf[0] = 0; // Report ID. Ignored by HID Class firmware as only config'd for one report
aucBuf[1] = FCD_HID_CMD_SET_IF_GAIN;
aucBuf[2] = (unsigned char) gain;
+ d_control_handle = hid_open_path(d_path);
+ if (!d_control_handle)
+ return;
hid_write(d_control_handle, aucBuf, 65);
hid_read(d_control_handle, aucBuf, 65);
+ hid_close(d_control_handle);
if(aucBuf[0] == FCD_HID_CMD_SET_IF_GAIN) {
std::cerr <<"If gain set to: "<< gain <<std::endl;
}
diff --git a/lib/fcdproplus_impl.h b/lib/fcdproplus_impl.h
index 1644ce7..18efa83 100644
--- a/lib/fcdproplus_impl.h
+++ b/lib/fcdproplus_impl.h
@@ -32,6 +32,7 @@ namespace gr {
{
private:
gr::audio::source::sptr fcd; /*!< The audio input source */
+ char *d_path; /*!< handle to control the device, set frequency, etc */
hid_device *d_control_handle; /*!< handle to control the device, set frequency, etc */
unsigned int d_freq_req; /*!< The latest requested frequency in Khz */
unsigned char aucBuf[65]; /*!< Buffers to read/write control messages to the dongle */
diff --git a/lib/hid/hid.c b/lib/hid/hid.c
index 38f6753..1cfc2a5 100644
--- a/lib/hid/hid.c
+++ b/lib/hid/hid.c
@@ -592,6 +592,35 @@ hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const
return handle;
}
+char* hid_get_path(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
+{
+ struct hid_device_info *devs, *cur_dev;
+ char *path_to_open = NULL;
+
+ devs = hid_enumerate(vendor_id, product_id);
+ cur_dev = devs;
+ while (cur_dev) {
+ if (cur_dev->vendor_id == vendor_id &&
+ cur_dev->product_id == product_id) {
+ if (serial_number) {
+ if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
+ path_to_open = strdup(cur_dev->path);
+ break;
+ }
+ }
+ else {
+ path_to_open = strdup(cur_dev->path);
+ break;
+ }
+ }
+ cur_dev = cur_dev->next;
+ }
+
+ hid_free_enumeration(devs);
+
+ return path_to_open;
+}
+
hid_device * HID_API_EXPORT hid_open_path(const char *path)
{
hid_device *dev = NULL;
diff --git a/lib/hid/hidapi.h b/lib/hid/hidapi.h
index e58e8a4..cf4df7d 100644
--- a/lib/hid/hidapi.h
+++ b/lib/hid/hidapi.h
@@ -157,6 +157,7 @@ extern "C" {
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
+ HID_API_EXPORT char * HID_API_CALL hid_get_path(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment