import {Description} from '@nodedc/ui-react'; import {useEffect,useRef,useState} from 'react'; import {Button,LoadingRegion,ResourceList,ResourceRow,SettingsCard,StatusBadge,FeatureSettingsWindow} from '@nodedc/ui-react'; import type {SensorDetailProps} from '../../../../packages/sensor-ui/src/extensions'; import {perform} from '../../../../packages/sensor-ui/src/contracts'; import {vescLabel,vescStatus,type VescTelemetry} from './model'; import {SensorGeneralSettings} from '../../../../packages/sensor-ui/src/SensorGeneralSettings'; import {VescBackups} from './VescBackups'; import {VescMotor} from './VescMotor'; import {VescHall} from './VescHall'; import {VescCalibration} from './VescCalibration'; import {VescConfiguration} from './VescConfiguration'; import {VescDiagnostics,VescConnections} from './VescDiagnostics'; import './vesc.css'; import {VescTools,VescTerminal} from './VescTools'; import {VescFirmware} from './VescFirmware'; import {VescLink} from './VescLink'; import {VescPackages} from './VescPackages'; import {VescSampleData} from './VescSampleData'; import {VescCodeTools} from './VescCodeTools'; import {VescBms} from './VescBms'; import {VescTrends} from './VescTrends'; import {VescLogAnalysis} from './VescLogAnalysis'; const fields=[['input_voltage_v','Напряжение питания','В'],['input_current_a','Ток питания','А'], ['motor_current_a','Ток мотора','А'],['erpm','Электрические обороты','ERPM'],['duty','Заполнение PWM',''], ['mos_temperature_c','Температура контроллера','°C'],['motor_temperature_c','Температура мотора','°C'], ['fault_code','Код ошибки',''],['can_id','CAN ID',''],['timeout','Тайм-аут управления',''], ['kill_switch','Вход аварийного останова','']] as const; export function VescDetail(props:SensorDetailProps){ const {device,transport,enabled,back,refresh,failure}=props; const status=vescStatus(device);const label=vescLabel(device,enabled); const [telemetry,setTelemetry]=useState(status.telemetry); const [pending,setPending]=useState(null); const [saved,setSaved]=useState(null); const [section,setSection]=useState('general'); const [motorBusy,setMotorBusy]=useState(false); const [hallBusy,setHallBusy]=useState(false); const [calibrationBusy,setCalibrationBusy]=useState(false); const [configBusy,setConfigBusy]=useState(false); const [diagnosticBusy,setDiagnosticBusy]=useState(false); const [linkBusy,setLinkBusy]=useState(false); const [generalBusy,setGeneralBusy]=useState(false); const poweredBusy=generalBusy||motorBusy||hallBusy||calibrationBusy||linkBusy||configBusy||diagnosticBusy; const running=useRef(false);const mounted=useRef(true); const available=enabled&&device.online&&device.verified&&status.readable; useEffect(()=>{mounted.current=true;return()=>{mounted.current=false;};},[]); async function read(action:'vesc.telemetry.read'|'vesc.config.backup'){ if(running.current||poweredBusy||!available)return; running.current=true;setPending(action);failure(null); try{ const result=await perform>(transport,device,action); if(!mounted.current)return; if(action==='vesc.telemetry.read')setTelemetry(result as unknown as VescTelemetry); else { setSaved(String(result.observed_at)); } await refresh(); }catch(error){if(mounted.current)failure(error);} finally{running.current=false;if(mounted.current)setPending(null);} } const backupAt=saved??status.backup?.observed_at; const busy=poweredBusy||pending!==null; const sections=[ {id:'general',label:'Общие данные',group:'Устройство'}, {id:'overview',label:'Контроллер и прошивка',group:'Устройство'}, {id:'diagnostics',label:'Текущие показания',group:'Устройство'}, {id:'trends',label:'Графики и CSV',group:'Устройство'}, {id:'hardware',label:'USB и журнал ошибок',group:'Устройство'}, {id:'connections',label:'CAN и приёмник',group:'Устройство'}, {id:'samples',label:'Sample Data',group:'Диагностика'}, {id:'motor-parameters',label:'Мотор',group:'Параметры VESC Tool'}, {id:'application-parameters',label:'Входы и приложения',group:'Параметры VESC Tool'}, {id:'calibration',label:'Калибровка FOC',group:'Настройка мотора'}, {id:'hall',label:'Датчики Холла',group:'Настройка мотора'}, {id:'rotation',label:'Проверка вращения',group:'Настройка мотора'}, {id:'configuration',label:'Резервные копии',group:'Конфигурации'}, {id:'firmware',label:'Прошивка и загрузчик',group:'Конфигурации'}, {id:'bms',label:'Аккумулятор BMS',group:'Инструменты'}, {id:'peripherals',label:'Входы и IMU',group:'Инструменты'}, {id:'log-analysis',label:'Анализ журналов и FFT',group:'Инструменты'}, {id:'terminal',label:'Терминал диагностики',group:'Инструменты'}, {id:'packages',label:'Расширения',group:'Программирование'}, {id:'lisp',label:'LispBM',group:'Программирование'}, {id:'qml',label:'QML-интерфейс',group:'Программирование'}, ].map(item=>({...item,disabled:busy&&item.id!==section})); return {if(!busy)setSection(value);}} onClose={()=>{if(!busy)back();}} headerActions={{label.label}}>
{!enabled||!device.online?Нет свежей связи с контроллером. Показаны последние полученные сведения.:status.message?{status.message}:null} {section==='general'&&} {section==='samples'&&} {section==='log-analysis'&&} {section==='packages'&&} {section==='bms'&&} {section==='peripherals'&&} {section==='terminal'&&} {section==='firmware'&&} {section==='hardware'&&}
; }