1
0

diag.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. #
  3. # Copyright © 2017 OpenWrt.org
  4. #
  5. . /lib/functions.sh
  6. . /lib/functions/leds.sh
  7. . /usr/share/libubox/jshn.sh
  8. preinit_match_diag_led() {
  9. local CFG keys key cfg name sysfs default
  10. CFG=/etc/board.json
  11. if [ ! -s $CFG ]; then
  12. CFG=/tmp/board.json
  13. [ -s /tmp/sysinfo/model ] || return
  14. /bin/board_detect $CFG || return
  15. fi
  16. json_init
  17. json_load "$(cat $CFG)"
  18. json_get_keys keys led
  19. json_select led
  20. for key in $keys; do
  21. json_select "$key"
  22. json_get_vars name sysfs default
  23. if [ "$name" = "DIAG" -a "$default" = "1" ]; then
  24. status_led="$sysfs"
  25. return
  26. fi
  27. json_select ..
  28. done
  29. }
  30. match_diag_led() {
  31. local name
  32. local default
  33. local sysfs
  34. config_get name "$1" name
  35. config_get default "$1" default
  36. config_get sysfs "$1" sysfs
  37. if [ "$name" = "DIAG" -a "$default" = "1" ]; then
  38. status_led="$sysfs"
  39. fi
  40. }
  41. get_status_led() {
  42. if [ -s /etc/config/system ]; then
  43. config_load system
  44. config_foreach match_diag_led led
  45. else
  46. preinit_match_diag_led
  47. fi
  48. }
  49. set_state() {
  50. get_status_led
  51. case "$1" in
  52. preinit)
  53. status_led_blink_preinit
  54. ;;
  55. failsafe)
  56. status_led_blink_failsafe
  57. ;;
  58. preinit_regular)
  59. status_led_blink_preinit_regular
  60. ;;
  61. done)
  62. status_led_on
  63. ;;
  64. esac
  65. }