From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gr-fcd/CMakeLists.txt | 10 +-- gr-fcd/doc/CMakeLists.txt | 8 +- gr-fcd/doc/README.fcd | 2 +- gr-fcd/doc/fcd.dox | 2 +- gr-fcd/examples/c++/fcd_nfm_rx.cc | 12 +-- gr-fcd/grc/CMakeLists.txt | 8 +- gr-fcd/include/fcd/fcd_source_c.h | 42 ++++----- gr-fcd/lib/fcd/fcd.c | 4 +- gr-fcd/lib/fcd/fcdhidcmd.h | 2 +- gr-fcd/lib/fcd_source_c_impl.cc | 50 +++++------ gr-fcd/lib/fcd_source_c_impl.h | 10 +-- gr-fcd/lib/hid/hid-libusb.c | 174 +++++++++++++++++++------------------- gr-fcd/lib/hid/hidapi.h | 2 +- gr-fcd/lib/hid/hidmac.c | 128 ++++++++++++++-------------- gr-fcd/lib/hid/hidwin.c | 40 ++++----- gr-fcd/python/CMakeLists.txt | 8 +- gr-fcd/python/__init__.py | 10 +-- gr-fcd/python/qa_fcd.py | 12 +-- gr-fcd/swig/fcd_swig.i | 8 +- 19 files changed, 266 insertions(+), 266 deletions(-) (limited to 'gr-fcd') diff --git a/gr-fcd/CMakeLists.txt b/gr-fcd/CMakeLists.txt index 10dd8b8cd..1185b3a32 100644 --- a/gr-fcd/CMakeLists.txt +++ b/gr-fcd/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2012 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, @@ -44,7 +44,7 @@ else() ENABLE_GR_CORE ENABLE_GR_AUDIO ) -endif() +endif() GR_SET_GLOBAL(GR_FCD_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/lib diff --git a/gr-fcd/doc/CMakeLists.txt b/gr-fcd/doc/CMakeLists.txt index d080b384e..6a4b7962d 100644 --- a/gr-fcd/doc/CMakeLists.txt +++ b/gr-fcd/doc/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2012 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gr-fcd/doc/README.fcd b/gr-fcd/doc/README.fcd index 6fff012b8..83b4da1ce 100644 --- a/gr-fcd/doc/README.fcd +++ b/gr-fcd/doc/README.fcd @@ -8,6 +8,6 @@ imported as: See the Doxygen documentation for details about the blocks available in this package. A quick listing of the details can be found in Python -after importing by using: +after importing by using: help(fcd) diff --git a/gr-fcd/doc/fcd.dox b/gr-fcd/doc/fcd.dox index a4420f6b3..6e07c585b 100644 --- a/gr-fcd/doc/fcd.dox +++ b/gr-fcd/doc/fcd.dox @@ -14,7 +14,7 @@ imported as: See the Doxygen documentation for details about the blocks available in this package. A quick listing of the details can be found in Python -after importing by using: +after importing by using: \code help(fcd) diff --git a/gr-fcd/examples/c++/fcd_nfm_rx.cc b/gr-fcd/examples/c++/fcd_nfm_rx.cc index 97ef7cf19..0ebc5d288 100644 --- a/gr-fcd/examples/c++/fcd_nfm_rx.cc +++ b/gr-fcd/examples/c++/fcd_nfm_rx.cc @@ -1,16 +1,16 @@ /* * Copyright 2011 Free Software Foundation, Inc. - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -19,10 +19,10 @@ /* * Simple GNU Radio C++ example for using the Funcube Dongle. - * + * * Construct a simple narrow band FM receiver using the gr-fcd * block as source. - * + * * This example uses "hw:1" as FCD source device and the default * audio device for output. * @@ -83,7 +83,7 @@ int main(int argc, char **argv) fcd_source_c_sptr fcd = fcd_make_source_c(device); fcd->set_freq_khz(freq); fcd->set_lna_gain(gain); - + // Low pass filter std::vector taps = gr_firdes::low_pass(1.0, 96000, 5000.0, 1000.0); gr_fir_filter_ccf_sptr filter = gr_make_fir_filter_ccf (2, taps); diff --git a/gr-fcd/grc/CMakeLists.txt b/gr-fcd/grc/CMakeLists.txt index 16af2cdba..d1eb00e32 100644 --- a/gr-fcd/grc/CMakeLists.txt +++ b/gr-fcd/grc/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2012 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gr-fcd/include/fcd/fcd_source_c.h b/gr-fcd/include/fcd/fcd_source_c.h index 988925c2e..19c589023 100644 --- a/gr-fcd/include/fcd/fcd_source_c.h +++ b/gr-fcd/include/fcd/fcd_source_c.h @@ -1,17 +1,17 @@ /* -*- c++ -*- */ /* * Copyright 2011-2012 Free Software Foundation, Inc. - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -38,11 +38,11 @@ typedef boost::shared_ptr fcd_source_c_sptr; FCD_API fcd_source_c_sptr fcd_make_source_c(const std::string device_name = ""); /*! \brief Funcube Dongle source block. - * + * * This class provides a Funcube Dongle soure block by wrapping the * USB audio interface and the USB HID control interface of the Funcube * Dongle into one convenient source block. - * + * * The Funcube Dongle needs to have firmware 18f or later for the control * interface to work properly. As of early 2011, FCDs still come with firmware * 18b. You can use qthid 2.2 (not 3) to upgrade the firmware: http://qthid.sf.net @@ -52,42 +52,42 @@ class FCD_API fcd_source_c : virtual public gr_hier_block2 public: /*! \brief Set frequency with Hz resolution. * \param freq The frequency in Hz - * + * * Set the frequency of the Funcube Dongle with 1 Hz resolution applying * the frequency correction set by set_freq_corr(). - * + * * \see set_freq_khz() */ virtual void set_freq(int freq) = 0; /*! \brief Set frequency with Hz resolution. * \param freq The frequency in Hz - * + * * This is a convenience function that uses float parameter in order to allow * using engineering notation in GRC. - * + * * \see set_freq_khz() */ virtual void set_freq(float freq) = 0; - + /*! \brief Set frequency with kHz resolution. * \param freq The frequency in kHz - * + * * Sets the frequency of the Funcube Dongle with 1 kHz resolution * applying the frequency correction set by set_freq_corr(). - * + * * \see set_freq() */ virtual void set_freq_khz(int freq) = 0; - + /*! \brief Set LNA gain. * \param gain The new gain in dB. - * + * * Set the LNA gain in the FCD. Valid range is -5 to 30. Although * the LNA gain in the FCD takes enumerated values corresponding to * 2.5 dB steps, you can can call this method with any float value * and it will be rounded to the nearest valid value. - * + * * By default the LNA gain is set to 20 dB and this is a good value for * most cases. In noisy areas you may try to reduce the gain. */ @@ -105,26 +105,26 @@ public: /*! \brief Set new frequency correction. * \param ppm The new frequency correction in parts per million - * + * * Version 1.1 FCDs (S/N 810 or later) need a correction of -12 ppm. * Earlier FCDs need roughly -120 ppm (default for gr-fcd). - * + * * Ref: http://www.funcubedongle.com/?p=617 */ virtual void set_freq_corr(int ppm) = 0; - + /*! \brief Set DC offset correction. * \param _dci DC correction for I component (-1.0 to 1.0) * \param _dcq DC correction for Q component (-1.0 to 1.0) - * + * * Set DC offset correction in the device. Default is 0.0. */ virtual void set_dc_corr(double _dci, double _dcq) = 0; - + /*! \brief Set IQ phase and gain balance. * \param _gain The gain correction (-1.0 to 1.0) * \param _phase The phase correction (-1.0 to 1.0) - * + * * Set IQ phase and gain balance in the device. The default values * are 0.0 for phase and 1.0 for gain. */ diff --git a/gr-fcd/lib/fcd/fcd.c b/gr-fcd/lib/fcd/fcd.c index ca9050231..011d77be9 100644 --- a/gr-fcd/lib/fcd/fcd.c +++ b/gr-fcd/lib/fcd/fcd.c @@ -1,10 +1,10 @@ /*************************************************************************** * This file is part of Qthid. - * + * * Copyright (C) 2010 Howard Long, G6LVB * CopyRight (C) 2011 Alexandru Csete, OZ9AEC * Mario Lorenz, DL5MLO - * + * * Qthid is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or diff --git a/gr-fcd/lib/fcd/fcdhidcmd.h b/gr-fcd/lib/fcd/fcdhidcmd.h index fad55f15f..1741ede30 100644 --- a/gr-fcd/lib/fcd/fcdhidcmd.h +++ b/gr-fcd/lib/fcd/fcdhidcmd.h @@ -87,7 +87,7 @@ #define FCD_CMD_APP_RESET 255 // Reset to bootloader -typedef enum +typedef enum { TLGE_N5_0DB=0, TLGE_N2_5DB=1, diff --git a/gr-fcd/lib/fcd_source_c_impl.cc b/gr-fcd/lib/fcd_source_c_impl.cc index ca370d9f3..34a221827 100644 --- a/gr-fcd/lib/fcd_source_c_impl.cc +++ b/gr-fcd/lib/fcd_source_c_impl.cc @@ -1,17 +1,17 @@ /* -*- c++ -*- */ /* * Copyright 2011-2012 Free Software Foundation, Inc. - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -46,7 +46,7 @@ static const int MAX_IN = 0; /*!< Maximum number of input streams. */ static const int MIN_OUT = 1; /*!< Minimum number of output streams. */ static const int MAX_OUT = 1; /*!< Maximum number of output streams. */ -fcd_source_c_impl::fcd_source_c_impl(const std::string device_name) +fcd_source_c_impl::fcd_source_c_impl(const std::string device_name) : gr_hier_block2 ("fcd_source_c", gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)), gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))), @@ -54,13 +54,13 @@ fcd_source_c_impl::fcd_source_c_impl(const std::string device_name) d_freq_req(0) { gr_float_to_complex_sptr f2c; - + /* Audio source; sample rate fixed at 96kHz */ fcd = audio_make_source(96000, device_name, true); - + /* block to convert stereo audio to a complex stream */ f2c = gr_make_float_to_complex(1); - + connect(fcd, 0, f2c, 0); connect(fcd, 1, f2c, 1); connect(f2c, 0, self(), 0); @@ -71,15 +71,15 @@ void fcd_source_c_impl::set_freq(int freq) { FCD_MODE_ENUM __GR_ATTR_UNUSED fme; double f = (double)freq; - + /* valid range 50 MHz - 2.0 GHz */ if ((freq < 50000000) || (freq > 2000000000)) { return; } - + d_freq_req = freq; f *= 1.0 + d_freq_corr/1000000.0; - + fme = fcdAppSetFreq((int)f); /* TODO: check fme */ } @@ -89,34 +89,34 @@ void fcd_source_c_impl::set_freq(float freq) { FCD_MODE_ENUM __GR_ATTR_UNUSED fme; double f = (double)freq; - + /* valid range 50 MHz - 2.0 GHz */ if ((freq < 50.0e6) || (freq > 2.0e9)) { return; } - + d_freq_req = (int)freq; f *= 1.0 + d_freq_corr/1000000.0; - + fme = fcdAppSetFreq((int)f); /* TODO: check fme */ } - + // Set frequency with kHz resolution. void fcd_source_c_impl::set_freq_khz(int freq) { FCD_MODE_ENUM __GR_ATTR_UNUSED fme; double f = freq*1000.0; - + /* valid range 50 MHz - 2.0 GHz */ if ((freq < 50000) || (freq > 2000000)) { return; } - + d_freq_req = freq*1000; f *= 1.0 + d_freq_corr/1000000.0; - + fme = fcdAppSetFreqkHz((int)(f/1000.0)); /* TODO: check fme */ } @@ -127,7 +127,7 @@ void fcd_source_c_impl::set_lna_gain(float gain) { FCD_MODE_ENUM __GR_ATTR_UNUSED fme; unsigned char g; - + /* convert to nearest discrete value */ if (gain > 27.5) { g = 14; // 30.0 dB @@ -168,7 +168,7 @@ void fcd_source_c_impl::set_lna_gain(float gain) else { g = 0; // -5.0 dB } - + fme = fcdAppSetParam(FCD_CMD_APP_SET_LNA_GAIN, &g, 1); /* TODO: check fme */ } @@ -207,13 +207,13 @@ void fcd_source_c_impl::set_dc_corr(double _dci, double _dcq) signed short dcq; }; } dcinfo; - + if ((_dci < -1.0) || (_dci > 1.0) || (_dcq < -1.0) || (_dcq > 1.0)) return; - + dcinfo.dci = static_cast(_dci*32768.0); dcinfo.dcq = static_cast(_dcq*32768.0); - + fcdAppSetParam(FCD_CMD_APP_SET_DC_CORR, dcinfo.auc, 4); } @@ -227,12 +227,12 @@ void fcd_source_c_impl::set_iq_corr(double _gain, double _phase) signed short gain; }; } iqinfo; - + if ((_gain < -1.0) || (_gain > 1.0) || (_phase < -1.0) || (_phase > 1.0)) return; - + iqinfo.phase = static_cast(_phase*32768.0); iqinfo.gain = static_cast(_gain*32768.0); - + fcdAppSetParam(FCD_CMD_APP_SET_IQ_CORR, iqinfo.auc, 4); } diff --git a/gr-fcd/lib/fcd_source_c_impl.h b/gr-fcd/lib/fcd_source_c_impl.h index d082ecc1e..d4ac40417 100644 --- a/gr-fcd/lib/fcd_source_c_impl.h +++ b/gr-fcd/lib/fcd_source_c_impl.h @@ -1,17 +1,17 @@ /* -*- c++ -*- */ /* * Copyright 2011-2012 Free Software Foundation, Inc. - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -36,12 +36,12 @@ public: void set_freq_corr(int ppm); void set_dc_corr(double _dci, double _dcq); void set_iq_corr(double _gain, double _phase); - + private: fcd_source_c_impl(const std::string device_name = ""); friend FCD_API fcd_source_c_sptr fcd_make_source_c(const std::string device_name); - + audio_source::sptr fcd; /*!< The audio input source */ int d_freq_corr; /*!< The frequency correction in ppm */ int d_freq_req; /*!< The latest requested frequency in Hz */ diff --git a/gr-fcd/lib/hid/hid-libusb.c b/gr-fcd/lib/hid/hid-libusb.c index 7069f50d0..82cbc9151 100644 --- a/gr-fcd/lib/hid/hid-libusb.c +++ b/gr-fcd/lib/hid/hid-libusb.c @@ -10,7 +10,7 @@ Libusb Version - 8/13/2010 Copyright 2009, All Rights Reserved. - + At the discretion of the user of this library, this software may be licensed under the terms of the GNU Public License v3, a BSD-Style license, or the @@ -77,23 +77,23 @@ struct input_report { struct hid_device_ { /* Handle to the actual device. */ libusb_device_handle *device_handle; - + /* Endpoint information */ int input_endpoint; int output_endpoint; int input_ep_max_packet_size; - /* The interface number of the HID */ + /* The interface number of the HID */ int interface; - + /* Indexes of Strings */ int manufacturer_index; int product_index; int serial_index; - + /* Whether blocking reads are used */ int blocking; /* boolean */ - + /* Read thread objects */ pthread_t thread; pthread_mutex_t mutex; /* Protects input_reports */ @@ -126,11 +126,11 @@ static hid_device *new_hid_device(void) dev->shutdown_thread = 0; dev->transfer = NULL; dev->input_reports = NULL; - + pthread_mutex_init(&dev->mutex, NULL); pthread_cond_init(&dev->condition, NULL); pthread_barrier_init(&dev->barrier, NULL, 2); - + return dev; } @@ -191,13 +191,13 @@ static int get_usage(uint8_t *report_descriptor, size_t size, int size_code; int data_len, key_size; int usage_found = 0, usage_page_found = 0; - + while (i < size) { int key = report_descriptor[i]; int key_cmd = key & 0xfc; //printf("key: %02hhx\n", key); - + if ((key & 0xf0) == 0xf0) { /* This is a Long Item. The next byte contains the length of the data section (value) for this key. @@ -232,7 +232,7 @@ static int get_usage(uint8_t *report_descriptor, size_t size, }; key_size = 1; } - + if (key_cmd == 0x4) { *usage_page = get_bytes(report_descriptor, size, data_len, i); usage_page_found = 1; @@ -246,11 +246,11 @@ static int get_usage(uint8_t *report_descriptor, size_t size, if (usage_page_found && usage_found) return 0; /* success */ - + /* Skip over this key and it's associated data */ i += data_len + key_size; } - + return -1; /* failure */ } #endif // INVASIVE_GET_USAGE @@ -262,7 +262,7 @@ static uint16_t get_first_language(libusb_device_handle *dev) { uint16_t buf[32]; int len; - + /* Get the string from libusb. */ len = libusb_get_string_descriptor(dev, 0x0, /* String ID */ @@ -271,7 +271,7 @@ static uint16_t get_first_language(libusb_device_handle *dev) sizeof(buf)); if (len < 4) return 0x0; - + return buf[1]; // First two bytes are len and descriptor type. } @@ -280,7 +280,7 @@ static int is_language_supported(libusb_device_handle *dev, uint16_t lang) uint16_t buf[32]; int len; int i; - + /* Get the string from libusb. */ len = libusb_get_string_descriptor(dev, 0x0, /* String ID */ @@ -289,8 +289,8 @@ static int is_language_supported(libusb_device_handle *dev, uint16_t lang) sizeof(buf)); if (len < 4) return 0x0; - - + + len /= 2; /* language IDs are two-bytes each. */ /* Start at index 1 because there are two bytes of protocol data. */ for (i = 1; i < len; i++) { @@ -325,7 +325,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx) lang = get_usb_code_for_current_locale(); if (!is_language_supported(dev, lang)) lang = get_first_language(dev); - + /* Get the string from libusb. */ len = libusb_get_string_descriptor(dev, idx, @@ -334,17 +334,17 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx) sizeof(buf)); if (len < 0) return NULL; - + buf[sizeof(buf)-1] = '\0'; - + if (len+1 < sizeof(buf)) buf[len+1] = '\0'; - + /* Initialize iconv. */ ic = iconv_open("UTF-32", "UTF-16"); if (ic == (iconv_t)-1) return NULL; - + /* Convert to UTF-32 (wchar_t on glibc systems). Skip the first character (2-bytes). */ inptr = buf+2; @@ -359,13 +359,13 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx) wbuf[sizeof(wbuf)/sizeof(wbuf[0])-1] = 0x00000000; if (outbytes >= sizeof(wbuf[0])) *((wchar_t*)outptr) = 0x00000000; - + /* Allocate and copy the string. */ str = wcsdup(wbuf+1); err: iconv_close(ic); - + return str; } @@ -377,7 +377,7 @@ static char *make_path(libusb_device *dev, int interface_number) libusb_get_device_address(dev), interface_number); str[sizeof(str)-1] = '\0'; - + return strdup(str); } @@ -410,12 +410,12 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, libusb_device_handle *handle; ssize_t num_devs; int i = 0; - + struct hid_device_info *root = NULL; // return object struct hid_device_info *cur_dev = NULL; - + setlocale(LC_ALL,""); - + if (!initialized) hid_init(); @@ -431,7 +431,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, int res = libusb_get_device_descriptor(dev, &desc); unsigned short dev_vid = desc.idVendor; unsigned short dev_pid = desc.idProduct; - + /* HID's are defined at the interface level. */ if (desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE) continue; @@ -462,11 +462,11 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, root = tmp; } cur_dev = tmp; - + /* Fill out the record */ cur_dev->next = NULL; cur_dev->path = make_path(dev, interface_num); - + res = libusb_open(dev, &handle); if (res >= 0) { @@ -501,7 +501,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, between interfaces. */ int detached = 0; unsigned char data[256]; - + /* Usage Page and Usage */ res = libusb_kernel_driver_active(handle, interface_num); if (res == 1) { @@ -550,7 +550,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, /* Release Number */ cur_dev->release_number = desc.bcdDevice; - + /* Interface Number */ cur_dev->interface_number = interface_num; } @@ -585,7 +585,7 @@ hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, wchar struct hid_device_info *devs, *cur_dev; const char *path_to_open = NULL; hid_device *handle = NULL; - + devs = hid_enumerate(vendor_id, product_id); cur_dev = devs; while (cur_dev) { @@ -611,14 +611,14 @@ hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, wchar } hid_free_enumeration(devs); - + return handle; } static void read_callback(struct libusb_transfer *transfer) { hid_device *dev = transfer->user_data; - + if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { struct input_report *rpt = malloc(sizeof(*rpt)); @@ -644,13 +644,13 @@ static void read_callback(struct libusb_transfer *transfer) num_queued++; } cur->next = rpt; - + /* Pop one off if we've reached 30 in the queue. This way we don't grow forever if the user never reads anything from the device. */ if (num_queued > 30) { return_data(dev, NULL, 0); - } + } } pthread_mutex_unlock(&dev->mutex); } @@ -668,7 +668,7 @@ static void read_callback(struct libusb_transfer *transfer) else { LOG("Unknown transfer code: %d\n", transfer->status); } - + /* Re-submit the transfer object. */ libusb_submit_transfer(transfer); } @@ -691,14 +691,14 @@ static void *read_thread(void *param) read_callback, dev, 5000/*timeout*/); - + /* Make the first submission. Further submissions are made from inside read_callback() */ libusb_submit_transfer(dev->transfer); // Notify the main thread that the read thread is up and running. pthread_barrier_wait(&dev->barrier); - + /* Handle all the events. */ while (!dev->shutdown_thread) { int res; @@ -708,14 +708,14 @@ static void *read_thread(void *param) break; } } - + /* Cancel any transfer that may be pending. This call will fail if no transfers are pending, but that's OK. */ if (libusb_cancel_transfer(dev->transfer) == 0) { /* The transfer was cancelled, so wait for its completion. */ libusb_handle_events(NULL); } - + /* Now that the read thread is stopping, Wake any threads which are waiting on data (in hid_read_timeout()). Do this under a mutex to make sure that a thread which is about to go to sleep waiting on @@ -732,7 +732,7 @@ static void *read_thread(void *param) cleaned up after the call to pthread_join() (in hid_close()), but since hid_close() calls libusb_cancel_transfer(), on these objects, they can not be cleaned up here. */ - + return NULL; } @@ -749,9 +749,9 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) int res; int d = 0; int good_open = 0; - + setlocale(LC_ALL,""); - + if (!initialized) hid_init(); @@ -782,7 +782,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) break; } good_open = 1; - + /* Detach the kernel driver, but only if the device is managed by the kernel */ if (libusb_kernel_driver_active(dev->device_handle, intf_desc->bInterfaceNumber) == 1) { @@ -795,7 +795,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) break; } } - + res = libusb_claim_interface(dev->device_handle, intf_desc->bInterfaceNumber); if (res < 0) { LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res); @@ -812,7 +812,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) /* Store off the interface number */ dev->interface = intf_desc->bInterfaceNumber; - + /* Find the INPUT and OUTPUT endpoints. An OUTPUT endpoint is not required. */ for (i = 0; i < intf_desc->bNumEndpoints; i++) { @@ -824,10 +824,10 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) int is_interrupt = (ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_INTERRUPT; - int is_output = + int is_output = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT; - int is_input = + int is_input = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN; @@ -844,12 +844,12 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) dev->output_endpoint = ep->bEndpointAddress; } } - + pthread_create(&dev->thread, NULL, read_thread, dev); - + // Wait here for the read thread to be initialized. pthread_barrier_wait(&dev->barrier); - + } free(dev_path); } @@ -860,7 +860,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) } libusb_free_device_list(devs, 1); - + // If we have a good handle, return it. if (good_open) { return dev; @@ -895,13 +895,13 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t dev->interface, (unsigned char *)data, length, 1000/*timeout millis*/); - + if (res < 0) return -1; - + if (skipped_report_id) length++; - + return length; } else { @@ -912,13 +912,13 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t (unsigned char*)data, length, &actual_length, 1000); - + if (res < 0) return -1; - + if (skipped_report_id) actual_length++; - + return actual_length; } } @@ -966,14 +966,14 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t bytes_read = return_data(dev, data, length); goto ret; } - + if (dev->shutdown_thread) { /* This means the device has been disconnected. An error code of -1 should be returned. */ bytes_read = -1; goto ret; } - + if (milliseconds == -1) { /* Blocking */ while (!dev->input_reports && !dev->shutdown_thread) { @@ -994,7 +994,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t ts.tv_sec++; ts.tv_nsec -= 1000000000L; } - + while (!dev->input_reports && !dev->shutdown_thread) { res = pthread_cond_timedwait(&dev->condition, &dev->mutex, &ts); if (res == 0) { @@ -1002,7 +1002,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t bytes_read = return_data(dev, data, length); break; } - + /* If we're here, there was a spurious wake up or the read thread was shutdown. Run the loop again (ie: don't break). */ @@ -1039,7 +1039,7 @@ int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length) int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock) { dev->blocking = !nonblock; - + return 0; } @@ -1063,14 +1063,14 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char dev->interface, (unsigned char *)data, length, 1000/*timeout millis*/); - + if (res < 0) return -1; - + /* Account for the report ID */ if (skipped_report_id) length++; - + return length; } @@ -1094,13 +1094,13 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, dev->interface, (unsigned char *)data, length, 1000/*timeout millis*/); - + if (res < 0) return -1; if (skipped_report_id) res++; - + return res; } @@ -1109,31 +1109,31 @@ void HID_API_EXPORT hid_close(hid_device *dev) { if (!dev) return; - + /* Cause read_thread() to stop. */ dev->shutdown_thread = 1; libusb_cancel_transfer(dev->transfer); /* Wait for read_thread() to end. */ pthread_join(dev->thread, NULL); - + /* Clean up the Transfer objects allocated in read_thread(). */ free(dev->transfer->buffer); libusb_free_transfer(dev->transfer); - + /* release the interface */ libusb_release_interface(dev->device_handle, dev->interface); - + /* Close the handle */ libusb_close(dev->device_handle); - + /* Clear out the queue of received reports. */ pthread_mutex_lock(&dev->mutex); while (dev->input_reports) { return_data(dev, NULL, 0); } pthread_mutex_unlock(&dev->mutex); - + free_hid_device(dev); } @@ -1316,7 +1316,7 @@ static struct lang_map_entry lang_map[] = { LANG("Xhosa", "xh", 0x0434), LANG("Yiddish", "yi", 0x043D), LANG("Zulu", "zu", 0x0435), - LANG(NULL, NULL, 0x0), + LANG(NULL, NULL, 0x0), }; uint16_t get_usb_code_for_current_locale(void) @@ -1324,16 +1324,16 @@ uint16_t get_usb_code_for_current_locale(void) char *locale; char search_string[64]; char *ptr; - + /* Get the current locale. */ locale = setlocale(0, NULL); if (!locale) return 0x0; - + /* Make a copy of the current locale string. */ strncpy(search_string, locale, sizeof(search_string)); search_string[sizeof(search_string)-1] = '\0'; - + /* Chop off the encoding part, and make it lower case. */ ptr = search_string; while (*ptr) { @@ -1350,10 +1350,10 @@ uint16_t get_usb_code_for_current_locale(void) while (lang->string_code) { if (!strcmp(lang->string_code, search_string)) { return lang->usb_code; - } + } lang++; } - + /* There was no match. Find with just the language only. */ /* Chop off the variant. Chop it off at the '_'. */ ptr = search_string; @@ -1365,18 +1365,18 @@ uint16_t get_usb_code_for_current_locale(void) } ptr++; } - + #if 0 // TODO: Do we need this? /* Find the entry which matches the string code of our language. */ lang = lang_map; while (lang->string_code) { if (!strcmp(lang->string_code, search_string)) { return lang->usb_code; - } + } lang++; } #endif - + /* Found nothing. */ return 0x0; } diff --git a/gr-fcd/lib/hid/hidapi.h b/gr-fcd/lib/hid/hidapi.h index 31b1cf206..8e55c8474 100644 --- a/gr-fcd/lib/hid/hidapi.h +++ b/gr-fcd/lib/hid/hidapi.h @@ -87,7 +87,7 @@ extern "C" { needed. This function should be called at the beginning of execution however, if there is a chance of HIDAPI handles being opened by different threads simultaneously. - + @ingroup API @returns diff --git a/gr-fcd/lib/hid/hidmac.c b/gr-fcd/lib/hid/hidmac.c index 276541be1..d8c69a8e5 100644 --- a/gr-fcd/lib/hid/hidmac.c +++ b/gr-fcd/lib/hid/hidmac.c @@ -1,14 +1,14 @@ /******************************************************* HIDAPI - Multi-Platform library for communication with HID devices. - + Alan Ott Signal 11 Software 2010-07-03 Copyright 2010, All Rights Reserved. - + At the discretion of the user of this library, this software may be licensed under the terms of the GNU Public License v3, a BSD-Style license, or the @@ -51,7 +51,7 @@ static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrie errno = EINVAL; return -1; } - + if(pthread_mutex_init(&barrier->mutex, 0) < 0) { return -1; } @@ -118,7 +118,7 @@ struct hid_device_ { pthread_barrier_t barrier; /* Ensures correct startup sequence */ pthread_barrier_t shutdown_barrier; /* Ensures correct shutdown sequence */ int shutdown_thread; - + hid_device *next; }; @@ -148,7 +148,7 @@ static hid_device *new_hid_device(void) pthread_cond_init(&dev->condition, NULL); pthread_barrier_init(&dev->barrier, NULL, 2); pthread_barrier_init(&dev->shutdown_barrier, NULL, 2); - + /* Add the new record to the device_list. */ pthread_mutex_lock(&device_list_mutex); if (!device_list) @@ -164,7 +164,7 @@ static hid_device *new_hid_device(void) } } pthread_mutex_unlock(&device_list_mutex); - + return dev; } @@ -172,7 +172,7 @@ static void free_hid_device(hid_device *dev) { if (!dev) return; - + /* Delete any input reports still left over. */ struct input_report *rpt = dev->input_reports; while (rpt) { @@ -209,7 +209,7 @@ static void free_hid_device(hid_device *dev) d->next = d->next->next; break; } - + d = d->next; } } @@ -234,7 +234,7 @@ static int32_t get_int_property(IOHIDDeviceRef device, CFStringRef key) { CFTypeRef ref; int32_t value; - + ref = IOHIDDeviceGetProperty(device, key); if (ref) { if (CFGetTypeID(ref) == CFNumberGetTypeID()) { @@ -285,7 +285,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t } else return 0; - + } static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, char *buf, size_t len) @@ -312,7 +312,7 @@ static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, cha } else return 0; - + } @@ -354,7 +354,7 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len) res = get_string_property_utf8( device, CFSTR(kIOHIDTransportKey), transport, sizeof(transport)); - + if (!res) return -1; @@ -363,8 +363,8 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len) res = snprintf(buf, len, "%s_%04hx_%04hx_%p", transport, vid, pid, device); - - + + buf[len-1] = '\0'; return res+1; } @@ -372,7 +372,7 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len) static int init_hid_manager(void) { IOReturn res; - + /* Initialize all the HID Manager Objects */ hid_mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); IOHIDManagerSetDeviceMatching(hid_mgr, NULL); @@ -400,7 +400,7 @@ int HID_API_EXPORT hid_exit(void) CFRelease(hid_mgr); hid_mgr = NULL; } - + return 0; } @@ -410,21 +410,21 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, struct hid_device_info *cur_dev = NULL; CFIndex num_devices; int i; - + setlocale(LC_ALL,""); /* Set up the HID Manager if it hasn't been done */ hid_init(); - + /* Get a list of the Devices */ CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); - /* Convert the list into a C array so we can iterate easily. */ + /* Convert the list into a C array so we can iterate easily. */ num_devices = CFSetGetCount(device_set); IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef)); CFSetGetValues(device_set, (const void **) device_array); - /* Iterate over each device, making an entry for it. */ + /* Iterate over each device, making an entry for it. */ for (i = 0; i < num_devices; i++) { unsigned short dev_vid; unsigned short dev_pid; @@ -474,7 +474,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, cur_dev->manufacturer_string = dup_wcs(buf); get_product_string(dev, buf, BUF_LEN); cur_dev->product_string = dup_wcs(buf); - + /* VID/PID */ cur_dev->vendor_id = dev_vid; cur_dev->product_id = dev_pid; @@ -486,10 +486,10 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, cur_dev->interface_number = -1; } } - + free(device_array); CFRelease(device_set); - + return root; } @@ -514,7 +514,7 @@ hid_device * HID_API_EXPORT hid_open(unsigned short vendor_id, unsigned short pr struct hid_device_info *devs, *cur_dev; const char *path_to_open = NULL; hid_device * handle = NULL; - + devs = hid_enumerate(vendor_id, product_id); cur_dev = devs; while (cur_dev) { @@ -540,7 +540,7 @@ hid_device * HID_API_EXPORT hid_open(unsigned short vendor_id, unsigned short pr } hid_free_enumeration(devs); - + return handle; } @@ -555,7 +555,7 @@ static void hid_device_removal_callback(void *context, IOReturn result, d->disconnected = 1; CFRunLoopStop(d->run_loop); } - + d = d->next; } pthread_mutex_unlock(&device_list_mutex); @@ -580,7 +580,7 @@ static void hid_report_callback(void *context, IOReturn result, void *sender, /* Lock this section */ pthread_mutex_lock(&dev->mutex); - + /* Attach the new report object to the end of the list. */ if (dev->input_reports == NULL) { /* The list is empty. Put it at the root. */ @@ -623,7 +623,7 @@ static void perform_signal_callback(void *context) static void *read_thread(void *param) { hid_device *dev = param; - + /* Move the device's run loop to this thread. */ IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetCurrent(), dev->run_loop_mode); @@ -636,7 +636,7 @@ static void *read_thread(void *param) ctx.perform = &perform_signal_callback; dev->source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0/*order*/, &ctx); CFRunLoopAddSource(CFRunLoopGetCurrent(), dev->source, dev->run_loop_mode); - + /* Store off the Run Loop so it can be stopped from hid_close() and on device disconnection. */ dev->run_loop = CFRunLoopGetCurrent(); @@ -682,7 +682,7 @@ static void *read_thread(void *param) if (!dev->disconnected) { IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone); } - + /* Wait here until hid_close() is called and makes it past the call to CFRunLoopWakeUp(). This thread still needs to be valid when that function is called on the other thread. */ @@ -696,22 +696,22 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) int i; hid_device *dev = NULL; CFIndex num_devices; - + dev = new_hid_device(); /* Set up the HID Manager if it hasn't been done */ hid_init(); CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); - + num_devices = CFSetGetCount(device_set); IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef)); - CFSetGetValues(device_set, (const void **) device_array); + CFSetGetValues(device_set, (const void **) device_array); for (i = 0; i < num_devices; i++) { char cbuf[BUF_LEN]; size_t len; IOHIDDeviceRef os_dev = device_array[i]; - + len = make_path(os_dev, cbuf, sizeof(cbuf)); if (!strcmp(cbuf, path)) { // Matched Paths. Open this Device. @@ -722,29 +722,29 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) free(device_array); CFRelease(device_set); dev->device_handle = os_dev; - + /* Create the buffers for receiving data */ dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev); dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t)); - + /* Create the Run Loop Mode for this device. printing the reference seems to work. */ sprintf(str, "HIDAPI_%p", os_dev); - dev->run_loop_mode = + dev->run_loop_mode = CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII); - + /* Attach the device to a Run Loop */ IOHIDDeviceRegisterInputReportCallback( os_dev, dev->input_report_buf, dev->max_input_report_len, &hid_report_callback, dev); IOHIDManagerRegisterDeviceRemovalCallback(hid_mgr, hid_device_removal_callback, NULL); - + /* Start the read thread */ pthread_create(&dev->thread, NULL, read_thread, dev); /* Wait here for the read thread to be initialized. */ pthread_barrier_wait(&dev->barrier); - + return dev; } else { @@ -782,20 +782,20 @@ static int set_report(hid_device *dev, IOHIDReportType type, const unsigned char data_to_send = data; length_to_send = length; } - + if (!dev->disconnected) { res = IOHIDDeviceSetReport(dev->device_handle, type, data[0], /* Report ID*/ data_to_send, length_to_send); - + if (res == kIOReturnSuccess) { return length; } else return -1; } - + return -1; } @@ -830,11 +830,11 @@ static int cond_wait(const hid_device *dev, pthread_cond_t *cond, pthread_mutex_ data in the queue before returning, and if not, go back to sleep. See the pthread_cond_timedwait() man page for details. */ - + if (dev->shutdown_thread || dev->disconnected) return -1; } - + return 0; } @@ -850,11 +850,11 @@ static int cond_timedwait(const hid_device *dev, pthread_cond_t *cond, pthread_m data in the queue before returning, and if not, go back to sleep. See the pthread_cond_timedwait() man page for details. */ - + if (dev->shutdown_thread || dev->disconnected) return -1; } - + return 0; } @@ -865,7 +865,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t /* Lock the access to the report list. */ pthread_mutex_lock(&dev->mutex); - + /* There's an input report queued up. Return it. */ if (dev->input_reports) { /* Return the first one */ @@ -878,7 +878,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t bytes_read = -1; goto ret; } - + if (dev->shutdown_thread) { /* This means the device has been closed (or there has been an error. An error code of -1 should @@ -888,7 +888,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t } /* There is no data. Go to sleep and wait for data. */ - + if (milliseconds == -1) { /* Blocking */ int res; @@ -913,7 +913,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t ts.tv_sec++; ts.tv_nsec -= 1000000000L; } - + res = cond_timedwait(dev, &dev->condition, &dev->mutex, &ts); if (res == 0) bytes_read = return_data(dev, data, length); @@ -942,7 +942,7 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock) { /* All Nonblocking operation is handled by the library. */ dev->blocking = !nonblock; - + return 0; } @@ -985,14 +985,14 @@ void HID_API_EXPORT hid_close(hid_device *dev) IOHIDDeviceUnscheduleFromRunLoop(dev->device_handle, dev->run_loop, dev->run_loop_mode); IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetMain(), kCFRunLoopDefaultMode); } - + /* Cause read_thread() to stop. */ dev->shutdown_thread = 1; - + /* Wake up the run thread's event loop so that the thread can exit. */ CFRunLoopSourceSignal(dev->source); CFRunLoopWakeUp(dev->run_loop); - + /* Notify the read thread that it can shut down now. */ pthread_barrier_wait(&dev->shutdown_barrier); @@ -1005,7 +1005,7 @@ void HID_API_EXPORT hid_close(hid_device *dev) if (!dev->disconnected) { IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone); } - + /* Clear out the queue of received reports. */ pthread_mutex_lock(&dev->mutex); while (dev->input_reports) { @@ -1085,19 +1085,19 @@ int main(void) { IOHIDManagerRef mgr; int i; - + mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); IOHIDManagerSetDeviceMatching(mgr, NULL); IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone); - + CFSetRef device_set = IOHIDManagerCopyDevices(mgr); - + CFIndex num_devices = CFSetGetCount(device_set); IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef)); CFSetGetValues(device_set, (const void **) device_array); - + setlocale(LC_ALL, ""); - + for (i = 0; i < num_devices; i++) { IOHIDDeviceRef dev = device_array[i]; printf("Device: %p\n", dev); @@ -1107,16 +1107,16 @@ int main(void) char cbuf[256]; get_serial_number(dev, serial, 256); - + printf(" Serial: %ls\n", serial); printf(" Loc: %ld\n", get_location_id(dev)); get_transport(dev, buf, 256); printf(" Trans: %ls\n", buf); make_path(dev, cbuf, 256); printf(" Path: %s\n", cbuf); - + } - + return 0; } #endif diff --git a/gr-fcd/lib/hid/hidwin.c b/gr-fcd/lib/hid/hidwin.c index 26d870fd8..5d34aadf4 100644 --- a/gr-fcd/lib/hid/hidwin.c +++ b/gr-fcd/lib/hid/hidwin.c @@ -8,7 +8,7 @@ 8/22/2009 Copyright 2009, All Rights Reserved. - + At the discretion of the user of this library, this software may be licensed under the terms of the GNU Public License v3, a BSD-Style license, or the @@ -162,7 +162,7 @@ static void register_error(hid_device *device, const char *op) MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&msg, 0/*sz*/, NULL); - + // Get rid of the CR and LF that FormatMessage() sticks at the // end of the message. Thanks Microsoft! ptr = msg; @@ -174,7 +174,7 @@ static void register_error(hid_device *device, const char *op) ptr++; } - // Store the message off in the Device entry so that + // Store the message off in the Device entry so that // the hid_error() function can pick it up. LocalFree(device->last_error_str); device->last_error_str = msg; @@ -284,9 +284,9 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor // Get information for all the devices belonging to the HID class. device_info_set = SetupDiGetClassDevsA(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - + // Iterate over each device in the HID class, looking for the right one. - + for (;;) { HANDLE write_handle = INVALID_HANDLE_VALUE; DWORD required_size = 0; @@ -297,7 +297,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor &InterfaceClassGuid, device_index, &device_interface_data); - + if (!res) { // A return of FALSE from this function means that // there are no more devices. @@ -344,7 +344,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor // Unable to open the device. //register_error(dev, "CreateFile"); goto cont_close; - } + } // Get the Vendor ID and Product ID for this device. @@ -354,7 +354,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor // Check the VID/PID to see if we should add this // device to the enumeration list. - if ((vendor_id == 0x0 && product_id == 0x0) || + if ((vendor_id == 0x0 && product_id == 0x0) || (attrib.VendorID == vendor_id && attrib.ProductID == product_id)) { #define WSTR_LEN 512 @@ -388,7 +388,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor HidD_FreePreparsedData(pp_data); } - + /* Fill out the record */ cur_dev->next = NULL; str = device_interface_detail_data->DevicePath; @@ -488,7 +488,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi struct hid_device_info *devs, *cur_dev; const char *path_to_open = NULL; hid_device *handle = NULL; - + devs = hid_enumerate(vendor_id, product_id); cur_dev = devs; while (cur_dev) { @@ -514,7 +514,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi } hid_free_enumeration(devs); - + return handle; } @@ -550,7 +550,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) } nt_res = HidP_GetCaps(pp_data, &caps); if (nt_res != HIDP_STATUS_SUCCESS) { - register_error(dev, "HidP_GetCaps"); + register_error(dev, "HidP_GetCaps"); goto err_pp_data; } dev->input_report_length = caps.InputReportByteLength; @@ -562,7 +562,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) err_pp_data: HidD_FreePreparsedData(pp_data); -err: +err: CloseHandle(dev->device_handle); free(dev); return NULL; @@ -577,7 +577,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char * memset(&ol, 0, sizeof(ol)); res = WriteFile(dev->device_handle, data, length, NULL, &ol); - + if (!res) { if (GetLastError() != ERROR_IO_PENDING) { // WriteFile() failed. Return error. @@ -612,7 +612,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char dev->read_pending = TRUE; ResetEvent(ev); res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol); - + if (!res) { if (GetLastError() != ERROR_IO_PENDING) { // ReadFile() has failed. @@ -638,7 +638,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char // we are in non-blocking mode. Get the number of bytes read. The actual // data has been copied to the data[] array which was passed to ReadFile(). res = GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/); - + // Set pending back to false, even if GetOverlappedResult() returned error. dev->read_pending = FALSE; @@ -656,13 +656,13 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char memcpy(data, dev->read_buf, length); } } - + end_of_function: if (!res) { register_error(dev, "GetOverlappedResult"); return -1; } - + return bytes_read; } @@ -805,7 +805,7 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) //#define PICPGM //#define S11 #define P32 -#ifdef S11 +#ifdef S11 unsigned short VendorID = 0xa0a0; unsigned short ProductID = 0x0001; #endif @@ -835,7 +835,7 @@ int __cdecl main(int argc, char* argv[]) memset(buf,0x00,sizeof(buf)); buf[0] = 0; buf[1] = 0x81; - + // Open the device. int handle = open(VendorID, ProductID, L"12345"); diff --git a/gr-fcd/python/CMakeLists.txt b/gr-fcd/python/CMakeLists.txt index 1c5dde35f..55233d256 100644 --- a/gr-fcd/python/CMakeLists.txt +++ b/gr-fcd/python/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2012 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gr-fcd/python/__init__.py b/gr-fcd/python/__init__.py index 9e573450f..daf9c890d 100644 --- a/gr-fcd/python/__init__.py +++ b/gr-fcd/python/__init__.py @@ -1,23 +1,23 @@ # # Copyright 2011 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -# +# ''' This is the gr-fcd package. This package provides a GNU Radio diff --git a/gr-fcd/python/qa_fcd.py b/gr-fcd/python/qa_fcd.py index f2546ce92..0993cab42 100755 --- a/gr-fcd/python/qa_fcd.py +++ b/gr-fcd/python/qa_fcd.py @@ -1,24 +1,24 @@ #!/usr/bin/env python # # Copyright 2012 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. -# +# # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -# +# from gnuradio import gr, gr_unittest import fcd_swig @@ -34,6 +34,6 @@ class test_fcd(gr_unittest.TestCase): def test_000_nop (self): """Just see if we can import the module...""" pass - + if __name__ == '__main__': gr_unittest.run(test_fcd, "test_fcd.xml") diff --git a/gr-fcd/swig/fcd_swig.i b/gr-fcd/swig/fcd_swig.i index d75e57b85..f4ad1b320 100644 --- a/gr-fcd/swig/fcd_swig.i +++ b/gr-fcd/swig/fcd_swig.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2012 Free Software Foundation, Inc. - * + * * This file is part of GNU Radio - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, -- cgit