Prioritize idle packet radio preparation for forwarding and Winlink

This commit is contained in:
alberto committed 2026-10-17 09:41:54 +02:00
1 parent 9c93ec03e5
commit e536f0939c
4 files changed
+28 -2

No files matched your search

+2
View File
@@ -195,3 +195,5 @@ Tests cover protocol parsing, mail/attachments, journal, gateway validation, pro
Third-party PDF.js, font and CMap licences are retained under `public/vendor/pdfjs`; map attribution is in `public/WORLD-MAP-LICENSE.txt`.
Packet controller integrations must acknowledge a reserved slot with `pttReady: true`, after checking that their BPQ PTT backend responds. A modem TCP connection alone is insufficient. The slot status must also contain the matching request ID, frequency, VHF phase and a fresh timestamp. Manual alternate routes share the partner queue; their native HF row is reserved during use and is not counted as a second active session.
The local packet controller can use `packet-preparation.mjs` to prioritize an idle manual Packet request by advancing BPQ's native scan toward its configured packet entry. This retains the native modem interlock (for example VARA V0/LISTEN OFF), rather than directly retuning from an HF receive slot. Do not advance while attached, connecting, transmitting, or paused. Forwarding and Winlink share the same slot handshake; its measured `preparationMs` is saved with the reservation. A single radio still requires exclusive access to the selected frequency.
+8
View File
@@ -0,0 +1,8 @@
// Accelerate BPQ's native scanner rather than bypassing its V0 modem interlock.
export function canExpeditePacket({request,manualRequestId,txSuspended,ptt,connections,radioState,users,radioPorts=null,lastPtt=0,now=Date.now()}){
const attached=[...(users||'').matchAll(/(?:TNC Uplink Port|Attached to Port)\s+(\d+)\//g)].some(m=>!radioPorts||radioPorts.includes(Number(m[1])));
return Boolean(request&&request.id!==manualRequestId&&!txSuspended&&!ptt&&!connections&&now-lastPtt>=1000&&!/^(?:connecting|connected|calling|interlocked)\b/i.test(radioState||'')&&!attached);
}
export function shouldAdvancePacketScan({frequency,packetFrequencyMHz,lastFrequency,lastAdvance=0,now=Date.now()}){
return Number.isFinite(frequency)&&Number.isFinite(packetFrequencyMHz)&&Math.abs(frequency-packetFrequencyMHz)>0.0001&&(frequency!==lastFrequency||now-lastAdvance>=1500);
}
+16
View File
@@ -0,0 +1,16 @@
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {canExpeditePacket,shouldAdvancePacketScan} from './packet-preparation.mjs';
test('a manual packet request may advance the scanner from either HF band while idle',()=>{
const idle={request:{id:'new'},manualRequestId:null,ptt:false,connections:0,radioState:'Free',users:'',lastPtt:0,now:100000};
assert.equal(canExpeditePacket(idle),true);assert.equal(canExpeditePacket({...idle,radioPorts:[4,7],users:'Attached to Port 2/1'}),true);assert.equal(canExpeditePacket({...idle,radioPorts:[4,7],users:'Attached to Port 7/1'}),false);
for(const busy of [{txSuspended:true},{ptt:true},{connections:1},{radioState:'Connecting to remote'},{radioState:'Connected'},{radioState:'Interlocked'},{users:'Attached to Port 1/1'},{users:'TNC Uplink Port 3/1'},{lastPtt:99500},{manualRequestId:'new'},{request:null}])assert.equal(canExpeditePacket({...idle,...busy}),false,JSON.stringify(busy));
for(const frequency of [7.050,14.122])assert.equal(shouldAdvancePacketScan({packetFrequencyMHz:144.950,frequency,now:100000}),true);
assert.equal(shouldAdvancePacketScan({packetFrequencyMHz:144.950,frequency:144.950,now:100000}),false);
assert.equal(shouldAdvancePacketScan({packetFrequencyMHz:144.950,frequency:NaN,now:100000}),false);
});
test('native scan commands wait for a frequency change or a bounded retry interval',()=>{
assert.equal(shouldAdvancePacketScan({packetFrequencyMHz:144.950,frequency:7.050,lastFrequency:7.050,lastAdvance:10000,now:10500}),false);
assert.equal(shouldAdvancePacketScan({packetFrequencyMHz:144.950,frequency:14.122,lastFrequency:7.050,lastAdvance:10000,now:10500}),true);
assert.equal(shouldAdvancePacketScan({packetFrequencyMHz:144.950,frequency:7.050,lastFrequency:7.050,lastAdvance:10000,now:11500}),true);
});
+2 -2
View File
@@ -2,10 +2,10 @@ import {readFile,writeFile,rename} from 'node:fs/promises';
import {randomUUID} from 'node:crypto';
export async function reservePacketSlot(client,controller,frequencyMHz,port){
if(!controller)return;
const request={id:randomUUID(),frequencyMHz,expiresAt:Date.now()+90000};client.job.controller={...controller,id:request.id};await client.persist();
const began=Date.now(),request={id:randomUUID(),frequencyMHz,expiresAt:began+90000};client.job.controller={...controller,id:request.id};await client.persist();
await writeFile(controller.requestFile+'.tmp',JSON.stringify(request));await rename(controller.requestFile+'.tmp',controller.requestFile);
const deadline=Date.now()+65000;
while(Date.now()<deadline){try{const state=JSON.parse(await readFile(controller.statusFile,'utf8'));if(state.manualRequestId===request.id&&state.phase==='vhf'&&state.pttReady===true&&Math.abs(Number(state.frequency)-frequencyMHz)<0.0001&&Date.now()-Date.parse(state.at)<5000){const html=await client.fwd.bpq('/Node/Port?'+port);if(/Connected to TNC/.test(html)&&/1200bd/.test(html))return;}}catch{}await new Promise(resolve=>setTimeout(resolve,300));}
while(Date.now()<deadline){try{const state=JSON.parse(await readFile(controller.statusFile,'utf8'));if(state.manualRequestId===request.id&&state.phase==='vhf'&&state.pttReady===true&&Math.abs(Number(state.frequency)-frequencyMHz)<0.0001&&Date.now()-Date.parse(state.at)<5000){const html=await client.fwd.bpq('/Node/Port?'+port);if(/Connected to TNC/.test(html)&&/1200bd/.test(html)){client.job.controller.preparationMs=Date.now()-began;await client.persist();return;}}}catch{}await new Promise(resolve=>setTimeout(resolve,300));}
throw Error('Modem packet non pronto: nessuna chiamata avviata');
}
export async function releasePacketSlot(client){