rtl_tcp.init 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2016 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. append_arg() {
  7. local cfg="$1"
  8. local var="$2"
  9. local opt="$3"
  10. local def="$4"
  11. local val
  12. config_get val "$cfg" "$var"
  13. [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
  14. }
  15. append_bool() {
  16. local cfg="$1"
  17. local var="$2"
  18. local opt="$3"
  19. local def="$4"
  20. local val
  21. config_get_bool val "$cfg" "$var" "$def"
  22. [ "$val" = 1 ] && procd_append_param command "$opt"
  23. }
  24. start_instance() {
  25. local cfg="$1"
  26. local aux
  27. config_get_bool aux "$cfg" 'disabled' '0'
  28. [ "$aux" = 1 ] && return 1
  29. procd_open_instance
  30. procd_set_param command /usr/bin/rtl_tcp
  31. append_arg "$cfg" device_index "-d"
  32. append_arg "$cfg" address "-a"
  33. append_arg "$cfg" port "-p"
  34. append_arg "$cfg" frequency "-f"
  35. append_arg "$cfg" gain "-g"
  36. append_arg "$cfg" samplerate "-s"
  37. append_arg "$cfg" buffers "-b"
  38. append_arg "$cfg" num_linked_lists "-n"
  39. append_arg "$cfg" ppm_error "-P"
  40. config_get_bool aux "$cfg" 'respawn' '0'
  41. [ "$aux" = 1 ] && procd_set_param respawn
  42. procd_close_instance
  43. }
  44. service_triggers() {
  45. procd_add_reload_trigger "rtl_tcp"
  46. }
  47. start_service() {
  48. config_load rtl_tcp
  49. config_foreach start_instance rtl_tcp
  50. }