xref: /openbmc/openbmc/meta-facebook/meta-ventura/recipes-phosphor/gpio/phosphor-gpio-monitor/frontled (revision f2e5579708b9efb2b033a08802dfbfdad32fb5e1)
162841f52SJason Hsu#!/bin/bash
262841f52SJason Hsu
3*f2e55797SEldin Leesource=$1
4213745a5SEldin Leeinit=$2
57f8df995SYang Chenpower_state=$3
6213745a5SEldin Lee
7213745a5SEldin Leeget_leakport() {
8*f2e55797SEldin Lee   if [[ $1 =~ ^PWRGD_TRAY_LEAK_PORT([0-9]+)_N$ ]]; then
9*f2e55797SEldin Lee      echo "leakport${BASH_REMATCH[1]}"
10213745a5SEldin Lee   fi
11213745a5SEldin Lee}
12*f2e55797SEldin Lee
13*f2e55797SEldin Leeleakport=$(get_leakport "$source")
147f8df995SYang Chenportnum=${leakport#leakport}
1562841f52SJason Hsu
167f8df995SYang Chenleak_state=$(busctl get-property xyz.openbmc_project.leakdetector "/xyz/openbmc_project/state/leak/detector/LeakPort${portnum}_Big" xyz.openbmc_project.State.Leak.Detector State | awk -F'.' '{print $NF}' | tr -d '"')
1762841f52SJason Hsu
187f8df995SYang Chenif [ "$power_state" == "assert" ]; then
197f8df995SYang Chen   # If power is asserted and leak state is Normal, turn on blue LED and turn off amber LED
207f8df995SYang Chen   # Else do nothing control by the leak detector leakage service
21213745a5SEldin Lee   if [ "$leak_state" == "Normal" ] || [ "$init" == "true" ]; then
227f8df995SYang Chen      busctl set-property "xyz.openbmc_project.LED.GroupManager" "/xyz/openbmc_project/led/groups/${leakport}_amber" "xyz.openbmc_project.Led.Group" "Asserted" "b" "false"
237f8df995SYang Chen      busctl set-property "xyz.openbmc_project.LED.GroupManager" "/xyz/openbmc_project/led/groups/${leakport}_blue" "xyz.openbmc_project.Led.Group" "Asserted" "b" "true"
2462841f52SJason Hsu   fi
257f8df995SYang Chenelif [ "$power_state" == "deassert" ]; then
267f8df995SYang Chen   busctl set-property "xyz.openbmc_project.LED.GroupManager" "/xyz/openbmc_project/led/groups/${leakport}_blue" "xyz.openbmc_project.Led.Group" "Asserted" "b" "false"
2762841f52SJason Hsufi
287f8df995SYang Chen
297f8df995SYang Chenexit 0
30