Доработка индикатора уровня сигнала
This commit is contained in:
@@ -33,9 +33,9 @@ func (a *API) HandleHealth(w http.ResponseWriter, r *http.Request) {
|
|||||||
latest, ok := a.buf.GetLatest()
|
latest, ok := a.buf.GetLatest()
|
||||||
idle := time.Since(a.buf.LastWriteTime())
|
idle := time.Since(a.buf.LastWriteTime())
|
||||||
|
|
||||||
status := "ok"
|
status := "На связи"
|
||||||
if idle > 15*time.Second {
|
if idle > 15*time.Second {
|
||||||
status = "degraded"
|
status = "Нет связи"
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, map[string]any{
|
writeJSON(w, map[string]any{
|
||||||
|
|||||||
@@ -246,10 +246,9 @@ h1 {
|
|||||||
transition: background-color 0.3s, border-color 0.3s;
|
transition: background-color 0.3s, border-color 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sig-bar-1 { height: 25%; }
|
.sig-bar-1 { height: 33%; }
|
||||||
.sig-bar-2 { height: 50%; }
|
.sig-bar-2 { height: 66%; }
|
||||||
.sig-bar-3 { height: 75%; }
|
.sig-bar-3 { height: 100%; }
|
||||||
.sig-bar-4 { height: 100%; }
|
|
||||||
|
|
||||||
/* Активные — зелёная заливка */
|
/* Активные — зелёная заливка */
|
||||||
.sig-bar.active-1,
|
.sig-bar.active-1,
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
<div class="sig-bar sig-bar-1"></div>
|
<div class="sig-bar sig-bar-1"></div>
|
||||||
<div class="sig-bar sig-bar-2"></div>
|
<div class="sig-bar sig-bar-2"></div>
|
||||||
<div class="sig-bar sig-bar-3"></div>
|
<div class="sig-bar sig-bar-3"></div>
|
||||||
<div class="sig-bar sig-bar-4"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -16,27 +16,22 @@ function setBar(id, value) {
|
|||||||
document.getElementById(id).style.width = value + "%";
|
document.getElementById(id).style.width = value + "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== SIGNAL ICON =====
|
// ===== SIGNAL ICON (0-3 уровня) =====
|
||||||
function setSignal(percent) {
|
function setSignal(level) {
|
||||||
const bars = document.querySelectorAll(".sig-bar");
|
const bars = document.querySelectorAll(".sig-bar");
|
||||||
bars.forEach(b => {
|
bars.forEach(b => {
|
||||||
b.classList.remove("active-1", "active-2", "active-3", "active-4");
|
b.classList.remove("active-1", "active-2", "active-3", "active-4");
|
||||||
b.classList.add("dim");
|
b.classList.add("dim");
|
||||||
});
|
});
|
||||||
|
|
||||||
if (percent > 75) {
|
if (level >= 3) {
|
||||||
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
||||||
bars[1].classList.add("active-2"); bars[1].classList.remove("dim");
|
bars[1].classList.add("active-2"); bars[1].classList.remove("dim");
|
||||||
bars[2].classList.add("active-3"); bars[2].classList.remove("dim");
|
bars[2].classList.add("active-3"); bars[2].classList.remove("dim");
|
||||||
bars[3].classList.add("active-4"); bars[3].classList.remove("dim");
|
} else if (level >= 2) {
|
||||||
} else if (percent > 50) {
|
|
||||||
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
||||||
bars[1].classList.add("active-2"); bars[1].classList.remove("dim");
|
bars[1].classList.add("active-2"); bars[1].classList.remove("dim");
|
||||||
bars[2].classList.add("active-3"); bars[2].classList.remove("dim");
|
} else if (level >= 1) {
|
||||||
} else if (percent > 25) {
|
|
||||||
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
|
||||||
bars[1].classList.add("active-2"); bars[1].classList.remove("dim");
|
|
||||||
} else if (percent > 0) {
|
|
||||||
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
bars[0].classList.add("active-1"); bars[0].classList.remove("dim");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +73,7 @@ async function update() {
|
|||||||
const uptime = Math.round(h.uptime_sec || 0);
|
const uptime = Math.round(h.uptime_sec || 0);
|
||||||
|
|
||||||
document.getElementById("meta").textContent =
|
document.getElementById("meta").textContent =
|
||||||
"аптайм: " + uptime + "s | буфер: " + filled;
|
"работа: " + uptime + "s | буфер: " + filled;
|
||||||
|
|
||||||
// ===== HISTORY =====
|
// ===== HISTORY =====
|
||||||
const arr = Array.isArray(hist.bytes) ? hist.bytes : [];
|
const arr = Array.isArray(hist.bytes) ? hist.bytes : [];
|
||||||
@@ -90,21 +85,23 @@ async function update() {
|
|||||||
" = значение: " + (Number(b) & 0xFF)
|
" = значение: " + (Number(b) & 0xFF)
|
||||||
).join("<br>");
|
).join("<br>");
|
||||||
|
|
||||||
// ===== FILTER (последние 9 значений) =====
|
// ===== ПОСЛЕДНЕЕ ЗНАЧЕНИЕ (без фильтра) =====
|
||||||
const last = arr.slice(-9).map(v => Number(v) & 0xFF);
|
const raw = arr.length > 0 ? (arr[arr.length - 1] & 0xFF) : 0;
|
||||||
|
|
||||||
const filtered = median(last);
|
// ===== ПАРСИНГ БИТ =====
|
||||||
|
const barValue = raw & 0x3F; // биты 0-5 (0-63)
|
||||||
|
const signalLevel = (raw >> 6) & 0x3; // биты 6-7 (0-3)
|
||||||
|
|
||||||
// ===== NORMALIZE =====
|
// ===== PROGRESS BAR (0-63 -> 0-100%) =====
|
||||||
const percent = (filtered / 255) * 100;
|
const percent = (barValue / 63) * 100;
|
||||||
|
|
||||||
// ===== SMOOTH =====
|
|
||||||
const smooth = smoothBar(percent);
|
const smooth = smoothBar(percent);
|
||||||
|
|
||||||
// ===== ONLY CHANNEL 1 =====
|
|
||||||
setBar("bar1", smooth);
|
setBar("bar1", smooth);
|
||||||
document.getElementById("last-byte").textContent = filtered;
|
|
||||||
setSignal(smooth);
|
// ===== SIGNAL ICON =====
|
||||||
|
setSignal(signalLevel, raw);
|
||||||
|
|
||||||
|
// ===== LAST BYTE =====
|
||||||
|
document.getElementById("last-byte").textContent = barValue;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("UPDATE ERROR:", e);
|
console.error("UPDATE ERROR:", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user