feat(sfm): the page's Call Home tab by serial -- state and audited On / Off (phase 4)
device_routing.js (Node-tested): call_home_state / call_home_on / call_home_off
routes (serial required); controlsFor gains callHomeChange (by serial, a
confirmed Series 3 or 4) and callHomeRead now covers a Series 4 by serial;
serialPanes gains callHomeForm / callHomeBox; callHomeRows renders the switch
(On / Off / 'Unknown (byte 5 = 0xNN)'), dial string and series;
changeErrorText takes the whole label ('Start monitoring', 'Enable call-home').
sfm_webapp.js: by serial the Call Home tab hides the legacy multi-field form
(Series 3 by host only) and shows the unit's switch with On / Off. Each asks
confirm(), sends one audited change, reports it with changeSummary /
changeErrorText, then re-reads quietly so the change's own result stays on
screen. A different unit's switch is never left showing. The new buttons are
wired with addEventListener, not onclick= (no inline JS).
Checked in jsdom against the real page: placeholder, read, Off (confirm, the
disable route, 'confirmed -- enabled -> disabled'), a serial edit clearing it,
legacy mode unchanged, no script errors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
06fa56db09
commit
84c142f36c
4 files changed
+151
-23
No files matched your search
+12
-1
@@ -1141,6 +1141,16 @@
|
||||
═══════════════════════════════════════════════════════════════════ -->
|
||||
<div id="tab-call-home" class="tab-pane">
|
||||
|
||||
<div id="ch-serial" style="display:none; margin-bottom:12px">
|
||||
<div class="cfg-section-title">On the unit (by serial)</div>
|
||||
<div class="dev-table" id="ch-state"></div>
|
||||
<div class="cfg-actions" style="margin-top:8px">
|
||||
<button class="btn btn-success" id="ch-on-btn" disabled>Call-home On</button>
|
||||
<button class="btn btn-ghost" id="ch-off-btn" disabled>Call-home Off</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ch-legacy">
|
||||
<div class="cfg-grid">
|
||||
|
||||
<!-- Enable / dial -->
|
||||
@@ -1243,11 +1253,12 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cfg-actions">
|
||||
<button class="btn btn-ghost" id="ch-read-btn" onclick="readCallHome()" disabled>Read from Device</button>
|
||||
<button class="btn btn-success" id="ch-write-btn" onclick="writeCallHome()" disabled>Write to Device</button>
|
||||
<button class="btn btn-ghost" onclick="clearCallHomeForm()">Clear Form</button>
|
||||
<button class="btn btn-ghost" id="ch-clear-btn" onclick="clearCallHomeForm()">Clear Form</button>
|
||||
<span id="ch-status"></span>
|
||||
<span id="ch-series-note" style="color:var(--text-dim)"></span>
|
||||
</div>
|
||||
|
||||
@@ -44,6 +44,9 @@ const DEVICE_ROUTES = {
|
||||
slow_drip: ['POST', '/device/stop_monitoring_slow_drip', false],
|
||||
call_home_read: ['GET', '/device/call_home', false],
|
||||
call_home_write: ['POST', '/device/call_home', false],
|
||||
call_home_state: ['GET', '/device/call_home/state', true],
|
||||
call_home_on: ['POST', '/device/call_home/enable', true],
|
||||
call_home_off: ['POST', '/device/call_home/disable', true],
|
||||
config_write: ['POST', '/device/config', false],
|
||||
event_waveform: ['GET', '/device/event/{index}/waveform', false],
|
||||
event_file: ['GET', '/device/event/{index}/blastware_file', false],
|
||||
@@ -82,10 +85,13 @@ function controlsFor(unit) {
|
||||
startStop: serialMode && (series === 3 || series === 4),
|
||||
hangup: series === 4,
|
||||
diagnostics: series === 3,
|
||||
callHomeRead: series === 3,
|
||||
// by host, the legacy read is Series 3's; by serial, both series (phase 4)
|
||||
callHomeRead: series === 3 || (serialMode && series === 4),
|
||||
callHomeChange: serialMode && (series === 3 || series === 4),
|
||||
configWrite: false,
|
||||
callHomeWrite: false,
|
||||
reasons: { configWrite: 'Coming in phase 5 (#46)', callHomeWrite: 'Coming in phase 4' },
|
||||
reasons: { configWrite: 'Coming in phase 5 (#46)',
|
||||
callHomeWrite: 'By serial: use Call-home On / Off (audited). Other call-home fields wait for the THOR round.' },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -178,18 +184,28 @@ function deviceErrorText(status, body, unit, statusText) {
|
||||
return status === 504 && !(body || {}).sent && unit && unit.host ? `${text} — ${NO_REPLY_HINT}` : text;
|
||||
}
|
||||
|
||||
// A start/stop that went out (or may have) is not "failed": its body carries
|
||||
// `sent` (ChangeUnconfirmed, bench finding #10), and its message says what the
|
||||
// unit did and names the audit record.
|
||||
function changeErrorText(verb, status, body, unit, statusText) {
|
||||
if ((body || {}).sent) return `${verb} monitoring not confirmed: ${errorDetail(body, statusText)}`;
|
||||
return `${verb} monitoring failed: ${deviceErrorText(status, body, unit, statusText)}`;
|
||||
// A change that went out (or may have) is not "failed": its body carries `sent`
|
||||
// (ChangeUnconfirmed, bench finding #10), and its message says what the unit
|
||||
// did and names the audit record. `label` is the whole name: "Start monitoring",
|
||||
// "Enable call-home".
|
||||
function changeErrorText(label, status, body, unit, statusText) {
|
||||
if ((body || {}).sent) return `${label} not confirmed: ${errorDetail(body, statusText)}`;
|
||||
return `${label} failed: ${deviceErrorText(status, body, unit, statusText)}`;
|
||||
}
|
||||
|
||||
// By serial, settings are read-only until phase 5: no empty legacy edit form or
|
||||
// legacy tables, and the settings box shows from the start (#6, #12).
|
||||
function serialPanes(bySerial, settingsRead) {
|
||||
return { configForm: !bySerial, settingsBox: bySerial, settingsPlaceholder: bySerial && !settingsRead,
|
||||
legacyDeviceTables: !bySerial };
|
||||
legacyDeviceTables: !bySerial, callHomeForm: !bySerial, callHomeBox: bySerial };
|
||||
}
|
||||
|
||||
// A unit's call-home switch, read by serial (phase 4). `enabled` null is an
|
||||
// enable byte never measured -- shown with the byte, never as On or Off.
|
||||
function callHomeRows(state) {
|
||||
const s = state || {};
|
||||
const sw = s.enabled === true ? 'On' : s.enabled === false ? 'Off'
|
||||
: `Unknown (byte 5 = ${(s.detail || {}).byte5 ?? '?'})`;
|
||||
return [['Call-home', sw], ['Dial string', s.dial_string || '—'], ['Series', s.series]];
|
||||
}
|
||||
/* </device-routing> */
|
||||
@@ -96,11 +96,71 @@ function applyControls() {
|
||||
hw.disabled = !c.callHomeWrite; hw.title = c.reasons.callHomeWrite;
|
||||
const chr = document.getElementById('ch-read-btn');
|
||||
chr.disabled = !c.callHomeRead;
|
||||
const s4 = series === 4 ? 'Not yet available for Series 4' : '';
|
||||
const s4 = series === 4 && !c.callHomeRead ? "Series 4: type the unit's serial to read its call-home" : '';
|
||||
chr.title = s4;
|
||||
document.getElementById('ch-series-note').textContent = s4;
|
||||
for (const id of ['ch-on-btn', 'ch-off-btn']) {
|
||||
document.getElementById(id).disabled = !c.callHomeChange || changeInFlight;
|
||||
}
|
||||
setMonitorButtons();
|
||||
applyConfigPanes();
|
||||
applyCallHomePanes();
|
||||
}
|
||||
|
||||
// The Call Home tab by serial (phase 4): the unit's switch and audited On / Off;
|
||||
// the legacy multi-field form is Series 3 by host only.
|
||||
let callHomeShownFor = null;
|
||||
function applyCallHomePanes() {
|
||||
const serial = normSerial(currentUnit().serial);
|
||||
const p = serialPanes(Boolean(serial), false);
|
||||
document.getElementById('ch-legacy').style.display = p.callHomeForm ? '' : 'none';
|
||||
document.getElementById('ch-serial').style.display = p.callHomeBox ? 'block' : 'none';
|
||||
document.getElementById('ch-write-btn').hidden = !p.callHomeForm;
|
||||
document.getElementById('ch-clear-btn').hidden = !p.callHomeForm;
|
||||
if (p.callHomeBox && callHomeShownFor !== serial) {
|
||||
callHomeShownFor = null;
|
||||
renderTextTable('ch-state', [['Call-home', 'Not read yet — press Read from Device']]);
|
||||
}
|
||||
}
|
||||
|
||||
// `quiet`: the re-read after a change -- the change's own result stays on screen.
|
||||
async function readCallHomeBySerial({ quiet = false } = {}) {
|
||||
const btn = document.getElementById('ch-read-btn');
|
||||
btn.disabled = true;
|
||||
if (!quiet) setChStatus('Reading call-home from the unit…');
|
||||
try {
|
||||
const st = await deviceFetch('call_home_state');
|
||||
renderTextTable('ch-state', callHomeRows(st));
|
||||
callHomeShownFor = normSerial(st.serial);
|
||||
if (!quiet) setChStatus(`Call-home read from ${st.serial}.`, 'ok');
|
||||
} catch (e) {
|
||||
if (!quiet) setChStatus(`Read failed: ${e.message}`, 'error');
|
||||
else renderTextTable('ch-state', [['Call-home', `Re-read failed: ${e.message}`]]);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// One audited send, never retried; the body says what the unit did.
|
||||
async function changeCallHome(on) {
|
||||
const serial = normSerial(currentUnit().serial);
|
||||
const label = on ? 'Enable call-home' : 'Disable call-home';
|
||||
if (!confirm(`Turn call-home ${on ? 'ON' : 'OFF'} on ${serial}?`)) return;
|
||||
changeInFlight = true; applyControls();
|
||||
setChStatus(`${label}…`);
|
||||
try {
|
||||
const r = await deviceRequest(on ? 'call_home_on' : 'call_home_off');
|
||||
const body = await r.json().catch(() => ({}));
|
||||
setChStatus(body.outcome ? changeSummary(body)
|
||||
: changeErrorText(label, r.status, body, currentUnit(), r.statusText),
|
||||
r.ok ? 'ok' : 'error');
|
||||
} catch (e) {
|
||||
// No reply is not "nothing sent": the request may have reached the unit.
|
||||
setChStatus(`${label}: no reply from SFM (${e.message}) — it may have been sent; `
|
||||
+ `check the unit's state and GET /db/device_commands`, 'error');
|
||||
}
|
||||
changeInFlight = false; applyControls();
|
||||
await readCallHomeBySerial({ quiet: true });
|
||||
}
|
||||
|
||||
// The Config tab by serial (#6): settings are read-only until phase 5, so the
|
||||
@@ -444,7 +504,7 @@ async function changeMonitoring(action) {
|
||||
if (body.outcome) {
|
||||
setStatus(changeSummary(body), r.ok ? 'ok' : 'error');
|
||||
} else {
|
||||
setStatus(changeErrorText(verb, r.status, body, currentUnit(), r.statusText), 'error');
|
||||
setStatus(changeErrorText(`${verb} monitoring`, r.status, body, currentUnit(), r.statusText), 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
// No reply is not "nothing sent": the request may have reached the unit.
|
||||
@@ -862,6 +922,7 @@ function clearCallHomeForm() {
|
||||
|
||||
async function readCallHome() {
|
||||
if (!devHost()) { setChStatus('Not connected.', 'error'); return; }
|
||||
if (serialMode()) { await readCallHomeBySerial(); return; }
|
||||
setChStatus('Reading call home config from device…');
|
||||
document.getElementById('ch-read-btn').disabled = true;
|
||||
try {
|
||||
@@ -2275,6 +2336,9 @@ document.getElementById('api-base').value = window.location.origin;
|
||||
for (const id of ['dev-serial', 'dev-host', 'dev-port']) {
|
||||
document.getElementById(id).addEventListener('input', () => { unitConfirmed = null; applyControls(); });
|
||||
}
|
||||
// New controls are wired here, not with onclick= in the HTML (no inline JS).
|
||||
document.getElementById('ch-on-btn').addEventListener('click', () => changeCallHome(true));
|
||||
document.getElementById('ch-off-btn').addEventListener('click', () => changeCallHome(false));
|
||||
applyControls();
|
||||
|
||||
// Reflect any persisted mic-unit preference in the header pill on load
|
||||
|
||||
Reference in new issue
Block a user