Files
DCCONSTRUCTIONS f32c7b400b feat(vesc): extend motor diagnostics, configuration and transport recovery
Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
2026-10-29 09:09:59 +03:00

26 lines
2.0 KiB
JavaScript

import assert from 'node:assert/strict';
import {before,after,test} from 'node:test';
import {createServer} from './support/vite-server.mjs';
let server,samples,log;
before(async()=>{server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});samples=await server.ssrLoadModule('../../plugins/vesc/frontend/src/samples.ts');log=await server.ssrLoadModule('../../plugins/vesc/frontend/src/logAnalysis.ts');});
after(async()=>{await server?.close();});
const row=i=>({index:i,i1:Math.sin(2*Math.PI*125*i/2000),i2:0,i3:0,v1:1,v2:2,v3:3,v0:4,current:0,switching_hz:20000,commutation:2,hall:3,phase_deg:180,dt_s:.0005,indexed:false,third_current_measured:false});
test('sample time uses decimated cadence and FFT resolves high frequency',()=>{
const points=samples.samplePoints(Array.from({length:1024},(_,i)=>row(i)));
assert.ok(Math.abs(points[1].at-.5)<1e-9);
const fft=log.spectrum(points,'i1',0,512);assert.ok(Math.abs(fft.peak.hz-125)<1e-8);
const csv=samples.sampleCsv([row(0),row(1)]);assert.ok(csv.startsWith('T;I1;I2;I3;'));assert.ok(csv.split('\n')[2].startsWith('0.0005;'));
assert.ok(csv.split('\n')[0].includes('Hall;Commutation;F_sw'));
});
test('malformed samples cannot become false zero traces',()=>{
for(const rows of [[{...row(0),i1:NaN}],[{...row(0),dt_s:0}],[row(1)],Array.from({length:2001},(_,i)=>row(i))])assert.throws(()=>samples.samplePoints(rows));
});
test('native Sample Data CSV imports the original asymmetric trailing delimiter',()=>{
const header='T;I1;I2;I3;V1;V2;V3;I_tot;V_zero;Phase';
const original=header+'\n0;1;2;-3;4;5;6;7;8;180;\n0.0001;2;3;-5;4;5;6;7;8;181;';
const parsed=log.parseVescLog(original);assert.equal(parsed.format,'VESC Tool · Sample Data');assert.equal(parsed.duration,.1);assert.equal(parsed.points[1].values.I3,-5);assert.equal(parsed.uuid,null);
const current=log.parseVescLog(samples.sampleCsv([row(0),row(1)]));assert.equal(current.points[1].values.Hall,3);assert.equal(current.duration,.5);
assert.throws(()=>log.parseVescLog(header+'\n0;1;2;3;4;5;6;7;8;9\n0;1;2;3;4;5;6;7;8;9'));
});