X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=x2%2Fsrc%2Fawk%2Fexe%2Fparse_bluetoothctl_show.awk;fp=x2%2Fsrc%2Fawk%2Fexe%2Fparse_bluetoothctl_show.awk;h=3a02897199aeb59c80cb8f9305f15d6ca87964f9;hb=499c58a269a00e031302938b5a8f006f23aae451;hp=0000000000000000000000000000000000000000;hpb=4c703fadbdc17d1753d16841582636598f862416;p=khatus.git diff --git a/x2/src/awk/exe/parse_bluetoothctl_show.awk b/x2/src/awk/exe/parse_bluetoothctl_show.awk new file mode 100644 index 0000000..3a02897 --- /dev/null +++ b/x2/src/awk/exe/parse_bluetoothctl_show.awk @@ -0,0 +1,34 @@ +/^Controller / { + controller = $2 + controllers[++ctrl_count] = controller +} + +/^\t[A-Z][A-Za-z]+:/ { + key = $1 + sub(":$", "", key) + sub("^\t" $1 " *", "") + val = $0 + data[controller, key] = val +} + +END { + # Using the 1st seen controller. Should we select specific instead? + power_status = data[controllers[1], "Powered"] + if (ctrl_count > 0) { + if (power_status == "no") { + show = "off" + } else if (power_status == "yes") { + show = "on" + } else { + print_error("Unexpected bluetooth power status: " power_status) + show = "ERROR" + } + } else { + show = "n/a" + } + print("power_status", show) +} + +function print_error(msg) { + print(msg) > "/dev/stderr" +}