SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Classes | Macros | Functions
hid-libusb.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <fcntl.h>
#include <pthread.h>
#include <wchar.h>
#include <libusb.h>
#include "iconv.h"
#include "../fcdhid/hidapi.h"
+ Include dependency graph for hid-libusb.c:

Go to the source code of this file.

Classes

struct  input_report
 
struct  hid_device_
 
struct  lang_map_entry
 

Macros

#define _GNU_SOURCE   /* needed for wcsdup() before glibc 2.10 */
 
#define LOG(...)   do {} while (0)
 
#define DETACH_KERNEL_DRIVER
 
#define LANG(name, code, usb_code)   { name, code, usb_code }
 

Functions

uint16_t get_usb_code_for_current_locale (void)
 
int HID_API_EXPORT hid_init (void)
 Initialize the HIDAPI library. More...
 
int HID_API_EXPORT hid_exit (void)
 Finalize the HIDAPI library. More...
 
struct hid_device_info HID_API_EXPORThid_enumerate (unsigned short vendor_id, unsigned short product_id)
 Enumerate the HID Devices. More...
 
void HID_API_EXPORT hid_free_enumeration (struct hid_device_info *devs)
 Free an enumeration Linked List. More...
 
hid_devicehid_open (unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
 Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number. More...
 
hid_device *HID_API_EXPORT hid_open_path (const char *path)
 Open a HID device by its path name. More...
 
int HID_API_EXPORT hid_write (hid_device *dev, const unsigned char *data, size_t length)
 Write an Output report to a HID device. More...
 
int HID_API_EXPORT hid_read_timeout (hid_device *dev, unsigned char *data, size_t length, int milliseconds)
 Read an Input report from a HID device with timeout. More...
 
int HID_API_EXPORT hid_read (hid_device *dev, unsigned char *data, size_t length)
 Read an Input report from a HID device. More...
 
int HID_API_EXPORT hid_set_nonblocking (hid_device *dev, int nonblock)
 Set the device handle to be non-blocking. More...
 
int HID_API_EXPORT hid_send_feature_report (hid_device *dev, const unsigned char *data, size_t length)
 Send a Feature report to the device. More...
 
int HID_API_EXPORT hid_get_feature_report (hid_device *dev, unsigned char *data, size_t length)
 Get a feature report from a HID device. More...
 
void HID_API_EXPORT hid_close (hid_device *dev)
 Close a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_manufacturer_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Manufacturer String from a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_product_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Product String from a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_serial_number_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Serial Number String from a HID device. More...
 
int HID_API_EXPORT_CALL hid_get_indexed_string (hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
 Get a string from a HID device, based on its string index. More...
 
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error (hid_device *dev)
 Get a string describing the last error which occurred. More...
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* needed for wcsdup() before glibc 2.10 */

Definition at line 26 of file hid-libusb.c.

◆ DETACH_KERNEL_DRIVER

#define DETACH_KERNEL_DRIVER

Definition at line 65 of file hid-libusb.c.

◆ LANG

#define LANG (   name,
  code,
  usb_code 
)    { name, code, usb_code }

Definition at line 1233 of file hid-libusb.c.

◆ LOG

#define LOG (   ...)    do {} while (0)

Definition at line 61 of file hid-libusb.c.

Referenced by hid_read_timeout().

Function Documentation

◆ get_usb_code_for_current_locale()

uint16_t get_usb_code_for_current_locale ( void  )

Definition at line 1371 of file hid-libusb.c.

1372 {
1373  char *locale;
1374  char search_string[64];
1375  char *ptr;
1376  struct lang_map_entry *lang;
1377 
1378  /* Get the current locale. */
1379  locale = setlocale(0, NULL);
1380  if (!locale)
1381  return 0x0;
1382 
1383  /* Make a copy of the current locale string. */
1384  strncpy(search_string, locale, sizeof(search_string));
1385  search_string[sizeof(search_string)-1] = '\0';
1386 
1387  /* Chop off the encoding part, and make it lower case. */
1388  ptr = search_string;
1389  while (*ptr) {
1390  *ptr = tolower(*ptr);
1391  if (*ptr == '.') {
1392  *ptr = '\0';
1393  break;
1394  }
1395  ptr++;
1396  }
1397 
1398  /* Find the entry which matches the string code of our locale. */
1399  lang = lang_map;
1400  while (lang->string_code) {
1401  if (!strcmp(lang->string_code, search_string)) {
1402  return lang->usb_code;
1403  }
1404  lang++;
1405  }
1406 
1407  /* There was no match. Find with just the language only. */
1408  /* Chop off the variant. Chop it off at the '_'. */
1409  ptr = search_string;
1410  while (*ptr) {
1411  *ptr = tolower(*ptr);
1412  if (*ptr == '_') {
1413  *ptr = '\0';
1414  break;
1415  }
1416  ptr++;
1417  }
1418 
1419 #if 0 /* TODO: Do we need this? */
1420  /* Find the entry which matches the string code of our language. */
1421  lang = lang_map;
1422  while (lang->string_code) {
1423  if (!strcmp(lang->string_code, search_string)) {
1424  return lang->usb_code;
1425  }
1426  lang++;
1427  }
1428 #endif
1429 
1430  /* Found nothing. */
1431  return 0x0;
1432 }
Definition: hid-libusb.c:1227
const char * string_code
Definition: hid-libusb.c:1229
uint16_t usb_code
Definition: hid-libusb.c:1230