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 -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){