CEC-4702 can net rem diag cmd (#415)
* CEC-4702 support for 'can_network' remote diagnostic command. allow to send diag request to dev T.Rexes (0.0.0). * remove logs * CEC-4702 'can_network' and 'remote_ignition' remote commands * sms * small fix * remove console.log(). * split components * change order
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
import { Button, FormControl, InputLabel, Select } from "@material-ui/core";
|
import { Button, FormControl, InputLabel, Select, Grid, Switch } from "@material-ui/core";
|
||||||
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";
|
||||||
|
import smsAPI from "../../../services/smsAPI";
|
||||||
import cmp from "semver-compare";
|
import cmp from "semver-compare";
|
||||||
|
|
||||||
|
|
||||||
@@ -11,18 +12,26 @@ import {
|
|||||||
useVehicleContext
|
useVehicleContext
|
||||||
} from "../../Contexts/VehicleContext";
|
} from "../../Contexts/VehicleContext";
|
||||||
|
|
||||||
const commands = ["Reset"]
|
const commands = [
|
||||||
|
{ displayname: "Reset", val: "remote_reset" },
|
||||||
|
{ displayname: "Set CAN Network State", val: "can_network" },
|
||||||
|
{ displayname: "Set Remote Ignition", val: "remote_ignition" },
|
||||||
|
{ displayname: "Send Wake Up SMS", val: "sms" },
|
||||||
|
]
|
||||||
|
|
||||||
const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
||||||
|
|
||||||
const { getState, sendDiagnosticCommand, getECUs } = useVehicleContext();
|
const { vehicle, getVehicle, getState, sendDiagnosticCommand, getECUs } = useVehicleContext();
|
||||||
|
|
||||||
const [carState, setCarState] = useState(null);
|
const [carState, setCarState] = useState(null);
|
||||||
const [ecus, setEcus] = useState([]);
|
const [ecus, setEcus] = useState([]);
|
||||||
const { setMessage } = useStatusContext();
|
const { setMessage } = useStatusContext();
|
||||||
|
|
||||||
const [currentCommand, setCurrentCommand] = useState(commands[0].toLowerCase());
|
const [currentCommand, setCurrentCommand] = useState(commands[0].val);
|
||||||
const [currentECU, setCurrentECU] = useState("");
|
const [currentECU, setCurrentECU] = useState("");
|
||||||
|
const [canNetState, setCanNetState] = useState(false);
|
||||||
|
const [ignitionState, setIgnitionState] = useState(false);
|
||||||
|
const [seconds, setSeconds] = useState(180);
|
||||||
|
|
||||||
const changeCommandHandler = (e) => {
|
const changeCommandHandler = (e) => {
|
||||||
setCurrentCommand(e.target.value);
|
setCurrentCommand(e.target.value);
|
||||||
@@ -48,6 +57,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
result.data.push({ ecu: "TBOX" })
|
result.data.push({ ecu: "TBOX" })
|
||||||
setCurrentECU(result.data[0].ecu)
|
setCurrentECU(result.data[0].ecu)
|
||||||
setEcus(result.data)
|
setEcus(result.data)
|
||||||
|
await getVehicle(vin, token);
|
||||||
})();
|
})();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [vin]);
|
}, [vin]);
|
||||||
@@ -71,12 +81,28 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
|
|
||||||
const TREX_MIN_VER = "1.1.141";
|
const TREX_MIN_VER = "1.1.141";
|
||||||
const isRemoteResetSupported = () => {
|
const isRemoteResetSupported = () => {
|
||||||
return !carState?.trex_version ? true : cmp(carState.trex_version, TREX_MIN_VER) >= 0 || carState.trex_version.includes("dev");
|
return !carState?.trex_version ? true
|
||||||
|
: cmp(carState.trex_version, TREX_MIN_VER) >= 0
|
||||||
|
|| carState.trex_version.includes("dev")
|
||||||
|
|| carState.trex_version.includes("0.0.0");
|
||||||
};
|
};
|
||||||
|
|
||||||
const clickHandler = async (_) => {
|
const clickHandler = async (_) => {
|
||||||
try {
|
try {
|
||||||
|
if (currentCommand === "remote_reset") {
|
||||||
await sendDiagnosticCommand([vin], { command: currentCommand, ecu_name: currentECU }, token);
|
await sendDiagnosticCommand([vin], { command: currentCommand, ecu_name: currentECU }, token);
|
||||||
|
}
|
||||||
|
else if (currentCommand === "can_network") {
|
||||||
|
await sendDiagnosticCommand([vin], { command: currentCommand, can_net_action: canNetState ? "on" : "off", timeout: seconds }, token);
|
||||||
|
} else if (currentCommand === "remote_ignition") {
|
||||||
|
await sendDiagnosticCommand([vin], { command: currentCommand, ignition_action: ignitionState ? "on" : "off", timeout: seconds }, token);
|
||||||
|
} else if (currentCommand === "sms") {
|
||||||
|
const res = await smsAPI.send({ ICCID: vehicle.iccid, await: true, messageText: "remote_diagnostic" })
|
||||||
|
if (res.error) {
|
||||||
|
setMessage(`Failed to wake up the car: ${res.error}`)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
setMessage(`Sent diagnostic command to ${vin}`);
|
setMessage(`Sent diagnostic command to ${vin}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setMessage(error.message);
|
setMessage(error.message);
|
||||||
@@ -86,7 +112,75 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={clsx(classes.paper, classes.tableSize)}>
|
<div className={clsx(classes.paper, classes.tableSize)}>
|
||||||
|
{
|
||||||
|
currentCommand === "remote_reset"
|
||||||
|
?
|
||||||
|
<ResetCommand classes={classes} ecus={ecus} currentECU={currentECU} setCurrentECU={setCurrentECU} />
|
||||||
|
: currentCommand === "can_network"
|
||||||
|
?
|
||||||
|
<CanNetCommand canNetState={canNetState} setCanNetState={setCanNetState} seconds={seconds} setSeconds={setSeconds} />
|
||||||
|
: currentCommand === "remote_ignition"
|
||||||
|
?
|
||||||
|
<RemoteIgnitionCommand ignitionState={ignitionState} setIgnitionState={setIgnitionState} seconds={seconds} setSeconds={setSeconds} />
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
|
<p></p>
|
||||||
|
|
||||||
|
<FormControl
|
||||||
|
className={classes.formControl}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<InputLabel htmlFor="send-command" className={classes.whiteBackground}>
|
||||||
|
Diagnostic Command
|
||||||
|
</InputLabel>
|
||||||
|
<Select
|
||||||
|
native
|
||||||
|
variant="outlined"
|
||||||
|
inputProps={{
|
||||||
|
name: "send-command",
|
||||||
|
id: "send-command",
|
||||||
|
}}
|
||||||
|
onChange={changeCommandHandler}
|
||||||
|
>
|
||||||
|
{commands.map((command, index) => (
|
||||||
|
<option key={index} value={command.val}>
|
||||||
|
{command.displayname}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
aria-label="send command"
|
||||||
|
fullWidth
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
className={classes.submit}
|
||||||
|
onClick={clickHandler}
|
||||||
|
disabled={(!isOnline() || !isRemoteResetSupported()) && currentCommand !== "sms"}
|
||||||
|
>
|
||||||
|
Send
|
||||||
|
</Button>
|
||||||
|
<div>
|
||||||
|
<b>
|
||||||
|
{isOnline() ? "ONLINE" : "OFFLINE"}
|
||||||
|
</b>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<b>
|
||||||
|
{!isRemoteResetSupported() ? `Remote Reset supported from ${TREX_MIN_VER}, current version ${carState.trex_version}` : ""}
|
||||||
|
</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ResetCommand = ({ classes, ecus, currentECU, setCurrentECU }) => {
|
||||||
|
return (
|
||||||
<FormControl
|
<FormControl
|
||||||
className={classes.formControl}
|
className={classes.formControl}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -110,59 +204,73 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
<p></p>
|
const CanNetCommand = ({ canNetState, setCanNetState, seconds, setSeconds }) => {
|
||||||
|
return (
|
||||||
<FormControl
|
<div>
|
||||||
className={classes.formControl}
|
<Grid component="label" container alignItems="center" spacing={1}>
|
||||||
variant="outlined"
|
<Grid item>Off</Grid>
|
||||||
size="small"
|
<Grid item>
|
||||||
>
|
<Switch checked={canNetState} onChange={(event) => {
|
||||||
<InputLabel htmlFor="send-command" className={classes.whiteBackground}>
|
setCanNetState(event.target.checked)
|
||||||
Diagnostic Command
|
}} />
|
||||||
</InputLabel>
|
</Grid>
|
||||||
<Select
|
<Grid item>On</Grid>
|
||||||
native
|
</Grid>
|
||||||
variant="outlined"
|
{
|
||||||
inputProps={{
|
canNetState ?
|
||||||
name: "send-command",
|
<label>
|
||||||
id: "send-command",
|
Enter amount of seconds:
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={seconds}
|
||||||
|
min={0} // Minimum value
|
||||||
|
step={10} // Increment/decrement step
|
||||||
|
onChange={(event) => {
|
||||||
|
const value = event.target.value;
|
||||||
|
setSeconds(parseInt(value));
|
||||||
}}
|
}}
|
||||||
onChange={changeCommandHandler}
|
/>
|
||||||
>
|
</label>
|
||||||
{commands.map((command, index) => (
|
: null
|
||||||
<option key={index} value={command.toLowerCase()}>
|
}
|
||||||
{command}
|
</div>
|
||||||
</option>
|
)
|
||||||
))}
|
}
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<Button
|
const RemoteIgnitionCommand = ({ ignitionState, setIgnitionState, setSeconds, seconds }) => {
|
||||||
type="submit"
|
return (
|
||||||
aria-label="send command"
|
|
||||||
fullWidth
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
className={classes.submit}
|
|
||||||
onClick={clickHandler}
|
|
||||||
disabled={!isOnline() || !isRemoteResetSupported()}
|
|
||||||
>
|
|
||||||
Send
|
|
||||||
</Button>
|
|
||||||
<div>
|
<div>
|
||||||
<b>
|
<Grid component="label" container alignItems="center" spacing={1}>
|
||||||
{isOnline() ? "ONLINE" : "OFFLINE"}
|
<Grid item>Off</Grid>
|
||||||
</b>
|
<Grid item>
|
||||||
|
<Switch checked={ignitionState} onChange={(event) => {
|
||||||
|
setIgnitionState(event.target.checked)
|
||||||
|
}} />
|
||||||
|
</Grid>
|
||||||
|
<Grid item>On</Grid>
|
||||||
|
</Grid>
|
||||||
|
{
|
||||||
|
ignitionState ?
|
||||||
|
<label>
|
||||||
|
Enter amount of seconds:
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={seconds}
|
||||||
|
min={0} // Minimum value
|
||||||
|
step={10} // Increment/decrement step
|
||||||
|
onChange={(event) => {
|
||||||
|
const value = event.target.value;
|
||||||
|
setSeconds(parseInt(value));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
: null
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
)
|
||||||
<b>
|
}
|
||||||
{!isRemoteResetSupported() ? `Remote Reset supported from ${TREX_MIN_VER}, current version ${carState.trex_version}` : ""}
|
|
||||||
</b>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div >
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SendDiagnosticCommand;
|
export default SendDiagnosticCommand;
|
||||||
|
|||||||
Reference in New Issue
Block a user