From: Siraaj Khandkar Date: Thu, 14 Feb 2019 20:31:40 +0000 (-0500) Subject: Break up into procedures X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=1fd28945d92907f2c228e3a39ae7f7c649cce6b0;p=khatus.git Break up into procedures --- diff --git a/x4/sanity_check b/x4/sanity_check index 036d4b9..7ed1ca0 100755 --- a/x4/sanity_check +++ b/x4/sanity_check @@ -6,7 +6,7 @@ set -e dir="${prefix}/${host}" -kill_all() { +sensors_kill_all() { for pid_file in $(find $dir -type f -name pid) do kill -9 $(cat $pid_file) || true @@ -15,7 +15,13 @@ kill_all() { pkill khatus_x4 } -read_sensor() { +sensors_fork_all() { + ./bin/khatus_x4_sensor_datetime & + ./bin/khatus_x4_sensor_mpd & + ./bin/khatus_x4_sensor_energy & +} + +sensor_read_one() { if test -f "$1" then cat "$1" @@ -24,18 +30,22 @@ read_sensor() { fi } -kill_all - -./bin/khatus_x4_sensor_datetime & -./bin/khatus_x4_sensor_mpd & -./bin/khatus_x4_sensor_energy & - -while : -do - battery_state="$(read_sensor ${dir}/khatus_x4_sensor_energy/out/battery_state)" - battery_percentage="$(read_sensor ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" - datetime="$(read_sensor ${dir}/khatus_x4_sensor_datetime/out/datetime)" - mpd="$(read_sensor ${dir}/khatus_x4_sensor_mpd/out/status)" - echo "E[${battery_state} ${battery_percentage}] [${mpd}] ${datetime}" - sleep 1 -done +sensors_read_all() { + while : + do + battery_state="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_state)" + battery_percentage="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" + datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" + mpd="$(sensor_read_one ${dir}/khatus_x4_sensor_mpd/out/status)" + echo "E[${battery_state} ${battery_percentage}] [${mpd}] ${datetime}" + sleep 1 + done +} + +main() { + sensors_kill_all + sensors_fork_all + sensors_read_all +} + +main