X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_controller;h=c67e640245d436770b1a6bb02a333af4c81d4879;hb=b4612a8afc54fdba4622309e085f6cbff80d44ee;hp=d9218ceac999313e83e559362b42dcc9cd02c10d;hpb=f03e88c6896157abd5517394024162aedebff829;p=khatus.git diff --git a/bin/khatus_controller b/bin/khatus_controller index d9218ce..c67e640 100755 --- a/bin/khatus_controller +++ b/bin/khatus_controller @@ -1,130 +1,173 @@ #! /usr/bin/awk -f -{ debug("LINE", $0) } +/^OK/ { debug("OK line", $0) } -/^in:ENERGY battery/\ +/^ERROR/ { + debug("ERROR line", $0) + shift() + msg_head = $1 + shift() + msg_body = $0 + alert_trigger_hi(msg_head, "KhatusSensorError", msg_body) +} + +/^OK in:ENERGY battery/\ { debug("ENERGY battery", $0) - sub("%$", "", $4) + sub("%$", "", $5) db["energy_state_prev"] = db["energy_state_curr"] - db["energy_state_curr"] = $3 - db["energy_percentage"] = ensure_numeric($4) + db["energy_state_curr"] = $4 + db["energy_percentage"] = ensure_numeric($5) alert_check_energy_battery() } -/^in:ENERGY line_power/\ +/^OK in:ENERGY line_power/\ { debug("ENERGY line_power", $0) db["energy_line_power_prev"] = db["energy_line_power_curr"] - db["energy_line_power_curr"] = $3 + db["energy_line_power_curr"] = $4 alert_check_energy_line_power() } -/^in:MEMORY/\ +/^OK in:MEMORY/\ { + shift() shift() db["memory_total"] = $1 db["memory_used"] = $2 } -/^in:FAN +status:/\ +/^OK in:FAN +status:/\ { + shift() shift() db["fan_status"] = $2 } -/^in:FAN +speed:/\ +/^OK in:FAN +speed:/\ { + shift() shift() db["fan_speed"] = $2 } -/^in:FAN +level:/\ +/^OK in:FAN +level:/\ { + shift() shift() db["fan_level"] = $2 } -/^in:TEMPERATURE/\ +/^OK in:TEMPERATURE/\ { + shift() shift() db["temperature"] = $1 } -/^in:LOAD_AVG/\ +/^OK in:LOAD_AVG/\ { + shift() shift() set_load_avg() } -/^in:DISK_IO/\ +/^OK in:DISK_IO/\ { + shift() shift() set_disk_io() } -/^in:DISK_SPACE/\ +/^OK in:DISK_SPACE/\ { + shift() shift() db["disk_space_used"] = $0 } -/^in:NET_ADDR_IO/\ +/^OK in:NET_ADDR_IO/\ { + shift() shift() set_net_addr_io() } -/^in:NET_WIFI_STATUS/\ +/^OK in:NET_WIFI_STATUS/\ { shift() - db["net_wifi_status"] = $0 + shift() + set_net_wifi_status() } -/^in:BLUETOOTH_POWER/\ +/^OK in:BLUETOOTH_POWER/\ { + shift() shift() db["bluetooth_power"] = $0 } -/^in:SCREEN_BRIGHTNESS/\ +/^OK in:SCREEN_BRIGHTNESS/\ { + shift() shift() set_screen_brightness() } -/^in:VOLUME/\ +/^OK in:VOLUME/\ { shift() - db["volume"] = $0 + set_volume() } -/^in:MPD_SONG OK +MPD/ { delete db_mpd_song; next } -/^in:MPD_SONG OK$/ { set_mpd_playing() ; next } -/^in:MPD_SONG / { set_mpd_song() ; next } +/^OK in:MPD_SONG OK +MPD/ { delete db_mpd_song; next } +/^OK in:MPD_SONG OK$/ { set_mpd_playing() ; next } +/^OK in:MPD_SONG / { set_mpd_song() ; next } -/^in:MPD_STATE /\ +/^OK in:MPD_STATE /\ { + shift() shift() db["mpd_status_state"] = $1 db["mpd_status_time"] = $2 db["mpd_status_percent"] = $3 } -/^in:WEATHER/\ +/^OK in:WEATHER/\ { + shift() shift() db["weather_temperature"] = $0 } -/^in:DATE_TIME/\ +/^OK in:DATE_TIME/\ { + shift() shift() db["datetime"] = $0 output_msg_status_bar(make_status_bar()) } +function set_volume( mute, left, right) { + # 0 RUNNING no 75% 75% + #msg_head = $1 + #sink = $2 + #state = $3 + mute = $4 + left = $5 + right = $6 + + if (mute == "no") { + db["volume"] = sprintf("%s %s", left, right) + } else if (mute == "yes") { + db["volume"] = "X" + } else { + error("set_volume", "Unexpected value for 'mute' field: " mute) + } +} + function set_mpd_song( key, val) { + shift() key = $2 shift() shift() @@ -170,7 +213,7 @@ function alert_check_mpd( curr, prev, name, body) { " - " db_mpd_song["Album:"] \ " - " db_mpd_song["Title:"] } - alert_trigger_low("alert_check_mpd", "NowPlaying", body) + alert_trigger_low("alert_check_mpd", "MpdNowPlaying", body) } } @@ -295,6 +338,12 @@ function set_disk_io( curr_w, curr_r, prev_w, prev_r) { db["disk_io_diff_r"] = curr_r - prev_r } +function set_net_wifi_status( interface) { + interface = $1 + shift() + db["net_wifi_status", interface] = $0 +} + function set_net_addr_io( \ interface, address, io_curr_w, io_curr_r, io_prev_w, io_prev_r\ ) { @@ -432,7 +481,7 @@ function make_status_net( \ io_stat = "--" } if (interface ~ "^w") { - label = label ":" db["net_wifi_status"] + label = label ":" db["net_wifi_status", interface] } if (++count_printed > 1) { sep = " " @@ -494,6 +543,13 @@ function debug(location, msg, values, sep, vals, key, payload) { } } +function error(location, msg) { + # TODO: Reconsider classifying internal errors as alerts + # Maybe better to keep the error class distinct and provide a + # an optional transformation from error to alert + alert_trigger_hi(location, "KhatusControllerError", msg) +} + function ensure_numeric(n) { return n + 0 }