Commit | Line | Data |
---|---|---|
fd22859b SK |
1 | #! /usr/bin/awk -f |
2 | ||
75b23ff8 SK |
3 | BEGIN { |
4 | OFS = msg_fs ? msg_fs : "|" | |
5 | Kfs = key_fs ? key_fs : ":" | |
6 | } | |
7 | ||
fd22859b SK |
8 | /^Controller / { |
9 | controller = $2 | |
10 | controllers[++ctrl_count] = controller | |
11 | } | |
12 | ||
13 | /^\t[A-Z][A-Za-z]+:/ { | |
14 | key = $1 | |
15 | sub(":$", "", key) | |
7af746e8 | 16 | sub("^\t" $1 " *", "") |
fd22859b SK |
17 | val = $0 |
18 | data[controller, key] = val | |
19 | } | |
20 | ||
21 | END { | |
22 | # Using the 1st seen controller. Should we select specific instead? | |
23 | power_status = data[controllers[1], "Powered"] | |
24 | if (ctrl_count > 0) { | |
25 | if (power_status == "no") { | |
26 | show = "off" | |
27 | } else if (power_status == "yes") { | |
28 | show = "on" | |
29 | } else { | |
30 | print_error("Unexpected bluetooth power status: " power_status) | |
31 | show = "ERROR" | |
32 | } | |
33 | } else { | |
cdbd6083 | 34 | show = "n/a" |
fd22859b | 35 | } |
75b23ff8 | 36 | print("power_status", show) |
fd22859b SK |
37 | } |
38 | ||
39 | function print_error(msg) { | |
40 | print(msg) > "/dev/stderr" | |
41 | } |