Advertisement
Zy0d0x

Untitled

Sep 20th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. /**
  2. * Hacked-together cm108-ptt library. Nearly 100% copied from Hamlib.
  3. * Do-not-trust and will-do-evil-things generally apply.
  4. *
  5. * Have fun with it :D
  6. */
  7.  
  8. /*
  9. * Hamlib Interface - CM108 HID communication low-level support
  10. * Copyright (c) 2000-2012 by Stephane Fillod
  11. * Copyright (c) 2011 by Andrew Errington
  12. * CM108 detection code Copyright (c) Thomas Sailer used with permission
  13. *
  14. * This library is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU Library General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Library General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Library General Public
  25. * License along with this library; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. */
  29.  
  30. /**
  31. * \addtogroup rig_internal
  32. * @{
  33. */
  34.  
  35. /**
  36. * \brief CM108 GPIO
  37. * \file cm108.c
  38. */
  39. #include <stdlib.h>
  40. #include <stdio.h> /* Standard input/output definitions */
  41. #include <string.h> /* String function definitions */
  42. #include <unistd.h> /* UNIX standard function definitions */
  43. #include <fcntl.h> /* File control definitions */
  44. #include <errno.h> /* Error number definitions */
  45. #include <sys/time.h>
  46. #include <sys/types.h>
  47. #include <unistd.h>
  48. #include <sys/ioctl.h>
  49. #include <libudev.h>
  50. #include <sys/param.h>
  51.  
  52. #include <linux/hidraw.h>
  53. #include "cm108.h"
  54.  
  55.  
  56. /**
  57. * Find the matching hidraw device for the given USB_VID and USB_PID.
  58. * Returns the path of the found hidraw device or a null pointer if none was found.
  59. */
  60. const char *cm108_find_device()
  61. {
  62. struct udev *udev;
  63. struct udev_enumerate *enumerate;
  64. struct udev_list_entry *devices, *dev_list_entry;
  65. struct udev_device *dev;
  66. const char *found_path;
  67.  
  68. udev = udev_new();
  69. if(!udev) {
  70. printf("Can't create udev\n");
  71. exit(2);
  72. }
  73.  
  74. enumerate = udev_enumerate_new(udev);
  75. udev_enumerate_add_match_subsystem(enumerate, "hidraw");
  76. udev_enumerate_scan_devices(enumerate);
  77.  
  78. devices = udev_enumerate_get_list_entry(enumerate);
  79.  
  80. udev_list_entry_foreach(dev_list_entry, devices) {
  81. const char *path, *hidraw;
  82.  
  83. path = udev_list_entry_get_name(dev_list_entry);
  84. dev = udev_device_new_from_syspath(udev, path);
  85.  
  86. hidraw = udev_device_get_devnode(dev);
  87.  
  88.  
  89. if((strcmp(udev_device_get_sysattr_value(dev, "idVendor"), CM108_VID) == 0)
  90. && (strcmp(udev_device_get_sysattr_value(dev, "idProduct"), CM108_PID) == 0)) {
  91. found_path = hidraw;
  92. goto clean;
  93. }
  94. }
  95.  
  96. clean:
  97. udev_enumerate_unref(enumerate);
  98. udev_unref(udev);
  99.  
  100. return found_path;
  101. }
  102.  
  103.  
  104.  
  105.  
  106. /**
  107. * \brief Open CM108 HID port (/dev/hidrawX)
  108. * \param port
  109. * \return file descriptor
  110. */
  111.  
  112. int cm108_open(const char* path)
  113. {
  114. int fd;
  115.  
  116. fd = open(path, O_RDWR);
  117.  
  118. if (fd < 0) {
  119. return -1;
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement