You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2019 OpenWrt.org
  3. START=90
  4. USE_PROCD=1
  5. NAME=mbusd
  6. mbusd_instance() {
  7. [ "$2" = 0 ] || {
  8. echo "Validation failed"
  9. return 1
  10. }
  11. [ "$enabled" -gt 0 ] || return 1
  12. [ "$parity" = 0 ] && parity=n || parity=y
  13. [ "$rts" = 0 ] && rts=
  14. procd_open_instance mbusd-$port
  15. procd_set_param command /usr/bin/mbusd \
  16. -d \
  17. -L - \
  18. -P $port \
  19. -v $loglevel \
  20. ${max_connections:+-C $max_connections} \
  21. ${timeout:+-T $timeout} \
  22. -p $device \
  23. -s $speed \
  24. -m ${databits}${parity}${stopbits} \
  25. ${rts:+-t} \
  26. ${rtu_retries:+-N $rtu_retries} \
  27. ${rtu_wait:+-W $rtu_wait}
  28. procd_set_param stdout 1
  29. procd_set_param stderr 1
  30. procd_set_param respawn
  31. procd_close_instance
  32. }
  33. validate_section_mbusd() {
  34. uci_load_validate mbusd mbusd "$1" "$2" \
  35. 'enabled:bool:1' \
  36. 'port:port:502' \
  37. 'loglevel:uinteger:2' \
  38. 'max_connections:uinteger' \
  39. 'timeout:uinteger' \
  40. 'device:string' \
  41. 'speed:uinteger' \
  42. 'databits:uinteger' \
  43. 'parity:bool' \
  44. 'stopbits:uinteger' \
  45. 'rts:bool:0' \
  46. 'rtu_retries:uinteger' \
  47. 'rtu_wait:uinteger'
  48. }
  49. start_service() {
  50. config_load "$NAME"
  51. config_foreach validate_section_mbusd mbusd mbusd_instance
  52. }
  53. service_triggers() {
  54. procd_add_reload_trigger "$NAME"
  55. procd_add_validation validate_section_mbusd
  56. }