Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
16 lines
2.5 KiB
TypeScript
16 lines
2.5 KiB
TypeScript
import type {LogPoint} from './logAnalysis';
|
||
export interface SampleRow {index:number;i1:number;i2:number;i3:number;v1:number;v2:number;v3:number;v0:number;current:number;switching_hz:number;commutation:number;hall:number;phase_deg:number;dt_s:number;indexed:boolean;third_current_measured:boolean}
|
||
export interface SampleState {capture_id:string;state:string;received:number;expected:number;mode:number;count:number;decimation:number;malformed:number;error?:string;rows?:SampleRow[];offset?:number;elapsed_ms:number;provenance:string}
|
||
export const sampleFields=[['i1','Ток фазы 1','А'],['i2','Ток фазы 2','А'],['i3','Ток фазы 3 (расчёт)','А'],['current','Ток мотора','А'],['v1','Напряжение фазы 1','В'],['v2','Напряжение фазы 2','В'],['v3','Напряжение фазы 3','В'],['v0','Нулевая точка','В'],['hall','Код Hall из выборки',''],['commutation','Шаг коммутации',''],['phase_deg','Угол фазы (электрический)','°'],['switching_hz','Частота выборки до делителя','Гц']] as const;
|
||
export function samplePoints(rows:SampleRow[]):LogPoint[]{
|
||
if(rows.length>2000)throw new Error('Буфер превышает 2000 отсчётов.');
|
||
let at=0;return rows.map((r,i)=>{
|
||
if(r.index!==i||!Number.isFinite(r.dt_s)||r.dt_s<=0||sampleFields.some(([key])=>!Number.isFinite(r[key])))throw new Error('Повреждён порядок или значения выборки.');
|
||
const point={at,values:Object.fromEntries(sampleFields.map(([key])=>[key,r[key]])),gap:false};at+=r.dt_s*1000;return point;
|
||
});
|
||
}
|
||
export function sampleCsv(rows:SampleRow[]){
|
||
const points=samplePoints(rows);return 'T;I1;I2;I3;V1;V2;V3;I_tot;V_zero;Phase;Hall;Commutation;F_sw\n'+rows.map((r,i)=>[points[i].at/1000,r.i1,r.i2,r.i3,r.v1,r.v2,r.v3,r.current,r.v0,r.phase_deg,r.hall,r.commutation,r.switching_hz].join(';')).join('\n');
|
||
}
|
||
export const sampleStateLabel:Record<string,string>={idle:'Захват не запускался',armed:'Ожидание выборки',stored_wait:'Ожидание события; буфер на контроллере',receiving:'Получение выборки',complete:'Все ожидаемые отсчёты получены',incomplete:'Неполная выборка',timeout:'Срок ожидания истёк',cancelled:'Захват остановлен',unverified:'Последний буфер; событие не подтверждено',expired:'Буфер истёк'};
|