Merge branch 'develop'
This commit is contained in:
@@ -32,7 +32,7 @@ const tableColumns = [
|
||||
label: "ID",
|
||||
},
|
||||
{
|
||||
id: "update_package_id",
|
||||
id: "update_manifest_id",
|
||||
label: "Name",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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 (
|
||||
<div className={clsx(classes.paper, classes.tableSize)}>
|
||||
|
||||
<FormControl
|
||||
className={classes.formControl}
|
||||
variant="outlined"
|
||||
size="small"
|
||||
>
|
||||
<InputLabel className={classes.whiteBackground}>
|
||||
ECU
|
||||
</InputLabel>
|
||||
<Select
|
||||
native
|
||||
variant="outlined"
|
||||
value={currentECU}
|
||||
onChange={(event) => {
|
||||
setCurrentECU(event.target.value)
|
||||
}}
|
||||
>
|
||||
{ecus.map((row, index) => (
|
||||
<option key={index} value={row.ecu}>
|
||||
{row.ecu}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
|
||||
<p></p>
|
||||
|
||||
<FormControl
|
||||
className={classes.formControl}
|
||||
variant="outlined"
|
||||
@@ -94,17 +136,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
<FormGroup>
|
||||
{
|
||||
ecus.map((ecu, idx) => {
|
||||
return <FormControlLabel
|
||||
control={<Checkbox key={idx} />}
|
||||
label={ecu}
|
||||
value={ecu}
|
||||
checked={true} />
|
||||
})
|
||||
}
|
||||
</FormGroup>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
aria-label="send command"
|
||||
@@ -113,7 +145,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
||||
color="primary"
|
||||
className={classes.submit}
|
||||
onClick={clickHandler}
|
||||
disabled={!isOnline() || !isTBOXResetSupported()}
|
||||
disabled={!isOnline() || !isRemoteResetSupported()}
|
||||
>
|
||||
Send
|
||||
</Button>
|
||||
@@ -124,7 +156,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
||||
</div>
|
||||
<div>
|
||||
<b>
|
||||
{!isTBOXResetSupported() ? `TBOX Reset supported from ${TREX_MIN_VER}, current version ${carState.trex_version}` : ""}
|
||||
{!isRemoteResetSupported() ? `Remote Reset supported from ${TREX_MIN_VER}, current version ${carState.trex_version}` : ""}
|
||||
</b>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user