From 4d122fc3109dc9308111bec0dd20e5b3742b2d13 Mon Sep 17 00:00:00 2001 From: alberto Date: Wed, 14 Oct 2026 20:16:14 +0200 Subject: [PATCH] Treat empty modem status after restart as idle --- bpq.mjs | 2 +- test.mjs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bpq.mjs b/bpq.mjs index 005c7d8..07b7e0a 100644 --- a/bpq.mjs +++ b/bpq.mjs @@ -4,4 +4,4 @@ export function parseMessages(html){const result=[];const regex=/([\s\S]*?)<\/tr>/gi)].flatMap(m=>{const cells=[...m[1].matchAll(/]*>([\s\S]*?)<\/td>/gi)].map(c=>plain(c[1]));if(cells.length<12)return [];return [{port:cells[0].replace('>',''),active:cells[0].startsWith('>'),call:cells[1],quality:Number(cells[2]),nodes:Number(cells[3]),frames:Number(cells[4]),retries:Number(cells[5]),heard:cells[9],queued:Number(cells[10])}];});} export function parseMessage(html){const m=html.match(/]*>([\s\S]*?)<\/textarea>/i);if(!m)return null;const text=decode(m[1]).replace(/\r\n|\r/g,'\n');const header={},first=text.indexOf('\n\n');for(const l of text.slice(0,first).split('\n')){const sep=l.indexOf(':');if(sep>0)header[l.slice(0,sep)]=l.slice(sep+1).trim();}return {from:header.From||'',to:header.To||'',subject:header.Title||'',date:header['Date/Time']||'',bid:header.Bid||'',type:header['Type/Status']?.[0]||'',text:first>=0?text.slice(first+2):text};} export function bpqTimestamp(value,reference=new Date()) {const m=String(value||'').match(/^(\d{1,2})-([A-Za-z]{3})\s+(\d{2}):(\d{2})Z$/);if(!m)return null;const month=['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'].indexOf(m[2].toLowerCase());if(month<0||Number(m[1])>31||Number(m[3])>23||Number(m[4])>59)return null;let year=reference.getUTCFullYear();let date=new Date(Date.UTC(year,month,Number(m[1]),Number(m[3]),Number(m[4])));if(date.getTime()>reference.getTime()+86400000)date=new Date(Date.UTC(--year,month,Number(m[1]),Number(m[3]),Number(m[4])));if(date.getUTCMonth()!==month||date.getUTCDate()!==Number(m[1]))return null;return date.toISOString();} -export function parseRadio(html){const t=plain(html);return {connected:/Connected to .*?(?:TNC|Modem)|Comms State Connected/i.test(t),state:t.match(/TNC State (.*?)(?: Mode| Channel| Traffic|$)/)?.[1]||'Free',busy:t.includes('Channel State Busy'),mode:t.match(/Mode (\S+)/)?.[1]||'',snr:t.match(/S\/N ([\d,.-]+)/)?.[1]||'—',sent:Number(t.match(/Traffic Sent (\d+)/)?.[1]||0),received:Number(t.match(/RXed (\d+)/)?.[1]||0),frequency:t.match(/\b(\d+\.\d+)\s+(?:USB|LSB|FM|DIG|DATA)\b/)?.[1]||'—',scanning:/\b\d+\.\d+\s+(?:USB|LSB|FM|DIG|DATA)\s+S\b/.test(t)};} +export function parseRadio(html){const t=plain(html);return {connected:/Connected to .*?(?:TNC|Modem)|Comms State Connected/i.test(t),state:t.match(/TNC State\s+(.*?)(?=Mode\b|Channel\b|Traffic\b|$)/)?.[1]?.trim()||'Free',busy:t.includes('Channel State Busy'),mode:t.match(/Mode (\S+)/)?.[1]||'',snr:t.match(/S\/N ([\d,.-]+)/)?.[1]||'—',sent:Number(t.match(/Traffic Sent (\d+)/)?.[1]||0),received:Number(t.match(/RXed (\d+)/)?.[1]||0),frequency:t.match(/\b(\d+\.\d+)\s+(?:USB|LSB|FM|DIG|DATA)\b/)?.[1]||'—',scanning:/\b\d+\.\d+\s+(?:USB|LSB|FM|DIG|DATA)\s+S\b/.test(t)};} diff --git a/test.mjs b/test.mjs index d4b85b7..6a17a1b 100644 --- a/test.mjs +++ b/test.mjs @@ -63,3 +63,5 @@ test('generic PACTOR station runs without VARA, chat, monitor or BBS',async()=>{ test('generic own-call handling accepts SSIDs without station constants',()=>{assert.equal(mailFolder({from:'N9DEMO-11',status:'N'},'N9DEMO'),'queue');assert.equal(mailFolder({from:'N9DEMO@winlink.org',status:'F'},'N9DEMO'),'sent');assert.equal(mailFolder({from:'N1OTHER',status:'N'},'N9DEMO'),'inbox');}); test('configuration detects a Telnet-only node without inventing a modem',async()=>{const {parseConfig}=await import('./config.mjs');const c=parseConfig('NODECALL=N8TEST-7\nPORT\nDRIVER=Telnet.dll\nPORTNUM=2\nHTTPPORT=8088\nTCPPORT=9000\nENDPORT');assert.equal(c.httpPort,8088);assert.equal(c.telnetPort,9000);assert.deepEqual(c.radioPorts,[]);assert.equal(c.call,'N8TEST');}); + +test('empty modem state after restart remains idle',()=>{assert.equal(parseRadio('Comms State Connected to VARA TNC TNC State Mode Channel State Clear').state,'Free');});