-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmp2diag-tmp.mjs
More file actions
20 lines (20 loc) · 1.39 KB
/
Copy pathmp2diag-tmp.mjs
File metadata and controls
20 lines (20 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import WebSocket from 'ws';
const H='192.168.86.111:48000', CH=process.env.CH||'10C', sid='D'+Date.now();
const w=new WebSocket(`ws://${H}/ws/user-spectrum?client=${sid}&user_session_id=${sid}`);
let picked=false,b=null,last=null,lbl='';
w.on('open',()=>setTimeout(()=>w.send(JSON.stringify({type:'dab',on:1,channel:CH})),2000));
w.on('message',m=>{const t=m.toString(); if(t[0]!=='{'||!t.includes('"type":"dab"'))return;
let j; try{j=JSON.parse(t);}catch(e){return;} last=j;
if(!picked&&j.services&&j.services.length){picked=true;
const d=j.services.find(x=>x.codec==='MP2'); lbl=d.label;
w.send(JSON.stringify({type:'dab_service',sid:d.sid}));
setTimeout(()=>{b=JSON.parse(JSON.stringify(last));},12000);}});
setTimeout(()=>{ if(!b){console.log('no baseline');process.exit(1);}
const d=k=>Number(last[k]||0)-Number(b[k]||0); const i=d('mp2In');
console.log(`${CH} ${lbl} ${last.bitrate}k over 60s: ${i} frames`);
console.log(` bad ${d('mp2Bad')} = ${(100*d('mp2Bad')/i).toFixed(2)}%`);
console.log(` ★ noSync ${d('mp2NoSync')} <- not a frame at all: FRAMING, ours`);
console.log(` ★ tooLong ${d('mp2TooLong')} <- valid header, more bytes claimed than arrived (LSF)`);
console.log(` ★ crcBad ${d('mp2CrcBad')} <- real frame, damaged bits: RF`);
console.log(` lsfOrphans ${d('lsfOrphans')} erased ${d('erased')} fib ${last.fibRate}`);
process.exit(0);},74000);