Merge branch 'develop' into release/0.9.0

This commit is contained in:
jwu-fisker
2023-07-06 17:14:03 -07:00
2 changed files with 55 additions and 23 deletions

View File

@@ -32,7 +32,7 @@ const tableColumns = [
label: "ID", label: "ID",
}, },
{ {
id: "update_package_id", id: "update_manifest_id",
label: "Name", label: "Name",
}, },
{ {

View File

@@ -1,7 +1,6 @@
import clsx from "clsx"; import clsx from "clsx";
import { Button, FormControl, InputLabel, Select, FormControlLabel, FormGroup } from "@material-ui/core"; import { Button, FormControl, InputLabel, Select } from "@material-ui/core";
import Checkbox from '@mui/material/Checkbox';
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useStatusContext } from "../../Contexts/StatusContext"; import { useStatusContext } from "../../Contexts/StatusContext";
import { logger } from "../../../services/monitoring"; import { logger } from "../../../services/monitoring";
@@ -13,17 +12,17 @@ import {
} from "../../Contexts/VehicleContext"; } from "../../Contexts/VehicleContext";
const commands = ["Reset"] const commands = ["Reset"]
const ecus = ["TBOX"]
const SendDiagnosticCommand = ({ vin, token, classes }) => { const SendDiagnosticCommand = ({ vin, token, classes }) => {
const { getState, sendDiagnosticCommand } = useVehicleContext(); const { getState, sendDiagnosticCommand, getECUs } = useVehicleContext();
const [carState, setCarState] = useState(null); const [carState, setCarState] = useState(null);
const [ecus, setEcus] = useState([]);
const { setMessage } = useStatusContext(); const { setMessage } = useStatusContext();
const [currentCommand, setCurrentCommand] = useState(commands[0].toLowerCase()); const [currentCommand, setCurrentCommand] = useState(commands[0].toLowerCase());
const [currentECUs] = useState([ecus[0]]); const [currentECU, setCurrentECU] = useState("");
const changeCommandHandler = (e) => { const changeCommandHandler = (e) => {
setCurrentCommand(e.target.value); setCurrentCommand(e.target.value);
@@ -39,6 +38,19 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [vin]); }, [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 () => { const getCarState = async () => {
try { try {
const result = await getState(token, vin); const result = await getState(token, vin);
@@ -52,15 +64,18 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
const isOnline = () => { const isOnline = () => {
return carState && carState?.online; 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 TREX_MIN_VER = "1.1.141";
const isTBOXResetSupported = () => { const isRemoteResetSupported = () => {
return !carState?.trex_version ? true : cmp(carState.trex_version, TREX_MIN_VER) === 1; return !carState?.trex_version ? true : cmp(carState.trex_version, TREX_MIN_VER) >= 0;
}; };
const clickHandler = async (_) => { const clickHandler = async (_) => {
try { 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}`); setMessage(`Sent diagnostic command to ${vin}`);
} catch (error) { } catch (error) {
setMessage(error.message); setMessage(error.message);
@@ -70,6 +85,33 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
return ( return (
<div className={clsx(classes.paper, classes.tableSize)}> <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 <FormControl
className={classes.formControl} className={classes.formControl}
variant="outlined" variant="outlined"
@@ -94,17 +136,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
))} ))}
</Select> </Select>
</FormControl> </FormControl>
<FormGroup>
{
ecus.map((ecu, idx) => {
return <FormControlLabel
control={<Checkbox key={idx} />}
label={ecu}
value={ecu}
checked={true} />
})
}
</FormGroup>
<Button <Button
type="submit" type="submit"
aria-label="send command" aria-label="send command"
@@ -113,7 +145,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
color="primary" color="primary"
className={classes.submit} className={classes.submit}
onClick={clickHandler} onClick={clickHandler}
disabled={!isOnline() || !isTBOXResetSupported()} disabled={!isOnline() || !isRemoteResetSupported()}
> >
Send Send
</Button> </Button>
@@ -124,7 +156,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
</div> </div>
<div> <div>
<b> <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> </b>
</div> </div>