From efc2083a6464b251499a3de93c474d933862b20d Mon Sep 17 00:00:00 2001 From: Eduard Voronkin <116690094+eduardvoronkin@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:29:36 -0700 Subject: [PATCH] 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 --- .../Controls/SendDiagnosticCommand/index.jsx | 174 ++++++++++++++---- 1 file changed, 141 insertions(+), 33 deletions(-) diff --git a/src/components/Controls/SendDiagnosticCommand/index.jsx b/src/components/Controls/SendDiagnosticCommand/index.jsx index 48f8466..3bb57d6 100644 --- a/src/components/Controls/SendDiagnosticCommand/index.jsx +++ b/src/components/Controls/SendDiagnosticCommand/index.jsx @@ -1,9 +1,10 @@ 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 { useStatusContext } from "../../Contexts/StatusContext"; import { logger } from "../../../services/monitoring"; +import smsAPI from "../../../services/smsAPI"; import cmp from "semver-compare"; @@ -11,18 +12,26 @@ import { useVehicleContext } 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 { getState, sendDiagnosticCommand, getECUs } = useVehicleContext(); + const { vehicle, getVehicle, getState, sendDiagnosticCommand, getECUs } = useVehicleContext(); const [carState, setCarState] = useState(null); const [ecus, setEcus] = useState([]); const { setMessage } = useStatusContext(); - const [currentCommand, setCurrentCommand] = useState(commands[0].toLowerCase()); + const [currentCommand, setCurrentCommand] = useState(commands[0].val); const [currentECU, setCurrentECU] = useState(""); + const [canNetState, setCanNetState] = useState(false); + const [ignitionState, setIgnitionState] = useState(false); + const [seconds, setSeconds] = useState(180); const changeCommandHandler = (e) => { setCurrentCommand(e.target.value); @@ -48,6 +57,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => { result.data.push({ ecu: "TBOX" }) setCurrentECU(result.data[0].ecu) setEcus(result.data) + await getVehicle(vin, token); })(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [vin]); @@ -71,12 +81,28 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => { const TREX_MIN_VER = "1.1.141"; 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 (_) => { try { - await sendDiagnosticCommand([vin], { command: currentCommand, ecu_name: currentECU }, token); + if (currentCommand === "remote_reset") { + 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}`); } catch (error) { setMessage(error.message); @@ -86,30 +112,18 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => { return (