diff --git a/src/components/Controls/SendDiagnosticCommand/index.jsx b/src/components/Controls/SendDiagnosticCommand/index.jsx index 117583d..00d6cc2 100644 --- a/src/components/Controls/SendDiagnosticCommand/index.jsx +++ b/src/components/Controls/SendDiagnosticCommand/index.jsx @@ -1,7 +1,6 @@ import clsx from "clsx"; -import { Button, FormControl, InputLabel, Select, FormControlLabel, FormGroup } from "@material-ui/core"; -import Checkbox from '@mui/material/Checkbox'; +import { Button, FormControl, InputLabel, Select } from "@material-ui/core"; import React, { useEffect, useState } from "react"; import { useStatusContext } from "../../Contexts/StatusContext"; import { logger } from "../../../services/monitoring"; @@ -13,17 +12,17 @@ import { } from "../../Contexts/VehicleContext"; const commands = ["Reset"] -const ecus = ["TBOX"] const SendDiagnosticCommand = ({ vin, token, classes }) => { - const { getState, sendDiagnosticCommand } = useVehicleContext(); + const { getState, sendDiagnosticCommand, getECUs } = useVehicleContext(); const [carState, setCarState] = useState(null); + const [ecus, setEcus] = useState([]); const { setMessage } = useStatusContext(); const [currentCommand, setCurrentCommand] = useState(commands[0].toLowerCase()); - const [currentECUs] = useState([ecus[0]]); + const [currentECU, setCurrentECU] = useState(""); const changeCommandHandler = (e) => { setCurrentCommand(e.target.value); @@ -39,6 +38,19 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [vin]); + //Get ECUs + useEffect(() => { + (async () => { + if (!vin) return; + const result = await getECUs({ vin }, token) + sortECUs(result.data) + result.data.push({ ecu: "TBOX" }) + setCurrentECU(result.data[0].ecu) + setEcus(result.data) + })(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [vin]); + const getCarState = async () => { try { const result = await getState(token, vin); @@ -52,15 +64,18 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => { const isOnline = () => { return carState && carState?.online; }; + const sortECUs = (ecus) => { + return ecus.sort((a, b) => { return a.ecu < b.ecu ? -1 : a.ecu > b.ecu ? 1 : 0 }) + } - const TREX_MIN_VER = "1.1.108"; - const isTBOXResetSupported = () => { - return !carState?.trex_version ? true : cmp(carState.trex_version, TREX_MIN_VER) === 1; + const TREX_MIN_VER = "1.1.141"; + const isRemoteResetSupported = () => { + return !carState?.trex_version ? true : cmp(carState.trex_version, TREX_MIN_VER) >= 0; }; const clickHandler = async (_) => { try { - await sendDiagnosticCommand([vin], { body: { command: currentCommand, ecus: currentECUs } }, token); + await sendDiagnosticCommand([vin], { command: currentCommand, ecu_name: currentECU }, token); setMessage(`Sent diagnostic command to ${vin}`); } catch (error) { setMessage(error.message); @@ -70,6 +85,33 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => { return (