summaryrefslogtreecommitdiff
path: root/ckt0.awk
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2025-12-05 19:05:36 -0800
committerwukong <wukong@longaeva>2025-12-05 19:05:36 -0800
commitdf1e57f1ac6df30174e269edbe68b5b5f7fa5c2b (patch)
tree7a1a9addcd88719f3422bdae83067156eb945614 /ckt0.awk
parente9d3488a9ef1a1b5bf8e75afc719b3cce68b9853 (diff)
added uname check in ck_boottime(); updated variable names in merge_meas();
Diffstat (limited to '')
-rw-r--r--ckt0.awk59
1 files changed, 36 insertions, 23 deletions
diff --git a/ckt0.awk b/ckt0.awk
index ebe724f..0c392a5 100644
--- a/ckt0.awk
+++ b/ckt0.awk
@@ -1,28 +1,24 @@
#!/usr/bin/env awk -f
-function log10(n) {
+function log10(n) { return log(n)/log(10.0) }
- return log(n)/log(10.0)
-}
-
-
-function merge_meas(val_est, unc_est, val_meas, unc_meas) {
+function merge_meas(est_val, est_unc, meas_val, meas_unc) {
# Kalman filtering compares variances,
- # convert uncerainties to square units
- unc_est = (0.5*unc_est)^2.0
- unc_meas = (0.5*unc_meas)^2.0
+ # convert uncertainties to square units
+ est_unc = (0.5*est_unc)^2.0
+ meas_unc = (0.5*meas_unc)^2.0
- G_K = (unc_est)/((unc_est) + (unc_meas))
- val_est = val_est + G_K*(val_meas - val_est)
- unc_est = (unc_est*unc_meas)/(unc_est + unc_meas)
+ K = (est_unc)/((est_unc) + (meas_unc))
+ est_val = est_val + K*(meas_val - est_val)
+ est_unc = (est_unc*meas_unc)/(est_unc + meas_unc)
- # convert unc_est back to original units
- unc_est = 2.0*sqrt(unc_est)
+ # convert est_unc back to original units
+ est_unc = 2.0*sqrt(est_unc)
- return sprintf(OFMT OFS OFMT ORS, val_est, unc_est)
+ return sprintf(OFMT OFS OFMT ORS, est_val, est_unc)
}
@@ -44,21 +40,41 @@ function sigfig(val, unc) {
}
+function ck_boottime() {
+
+ "uname" | getline uname
+ close("uname")
+
+ if (uname ~/OpenBSD/) {
+ "sysctl kern.boottime" | getline t0_k
+ close("sysctl kern.boottime")
+ sub("^.*=", "", t0_k)
+ split(t0_k, t0_k_arr)
+ t0_k_arr[2] = (index("JanFebMarAprMayJunJulAugSepOctNovDec", t0_k_arr[2]) + 2)/3.0
+ gsub(":", " ", t0_k_arr[4])
+ t0_k = sprintf("%04d %02d %02d %s", t0_k_arr[5], t0_k_arr[2], t0_k_arr[3], t0_k_arr[4])
+ t0_k = mktime(t0_k)
+ }
+
+ return t0_k
+
+}
+
+
# function ck_boottime() {
-#
# "sysctl kern.boottime" | getline t_kboot
# close("sysctl kern.boottime")
# sub("^.*\{", "", t_kboot)
# sub("\}.*$", "", t_kboot)
# split(t_kboot, t_kboot_arr, ",")
-#
+#
# for (i in t_kboot_arr) {
# sub("^.*= ", "", t_kboot_arr[i])
# }
-#
+#
# t_kboot = sprintf(t_kboot_arr[1] "." t_kboot_arr[2])
# return t_kboot
-#
+#
# }
@@ -141,15 +157,12 @@ BEGIN {
# check ARGV for previous estimate
if (ARGC > 0) {
- ARGV[1] ? t0_est[1] = ARGV[1] : t0_est[1] = 0.0
+ ARGV[1] ? t0_est[1] = ARGV[1] : t0_est[1] = ck_boottime()
ARGV[2] ? t0_est[2] = ARGV[2] : t0_est[2] = systime()
}
#print("t0_est = ", t0_est[1])
#print("t_boot_unc = ", t0_est[2])
- # wait (sleep) based on uncertainty
- # print(60.0/t0_est[2])
-
# check uptime, update estimate
print(ck_uptime(t0_est[1], t0_est[2]))