CEC-5212 add 'read_ecu_versions' remote command. (#464)
* CEC-5212 add 'read_ecu_versions' remote command. * try to reduce smells. * props smells * one more smells
This commit is contained in:
@@ -6,6 +6,7 @@ import { useStatusContext } from "../../Contexts/StatusContext";
|
|||||||
import { logger } from "../../../services/monitoring";
|
import { logger } from "../../../services/monitoring";
|
||||||
import smsAPI from "../../../services/smsAPI";
|
import smsAPI from "../../../services/smsAPI";
|
||||||
import cmp from "semver-compare";
|
import cmp from "semver-compare";
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -17,6 +18,7 @@ const commands = [
|
|||||||
{ displayname: "Set CAN Network State", val: "can_network" },
|
{ displayname: "Set CAN Network State", val: "can_network" },
|
||||||
{ displayname: "Set Remote Ignition", val: "remote_ignition" },
|
{ displayname: "Set Remote Ignition", val: "remote_ignition" },
|
||||||
{ displayname: "Send Wake Up SMS", val: "sms" },
|
{ displayname: "Send Wake Up SMS", val: "sms" },
|
||||||
|
{ displayname: "Read ECU versions", val: "read_ecu_versions" },
|
||||||
]
|
]
|
||||||
|
|
||||||
const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
||||||
@@ -102,6 +104,8 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
setMessage(`Failed to wake up the car: ${res.error}`)
|
setMessage(`Failed to wake up the car: ${res.error}`)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (currentCommand === "read_ecu_versions") {
|
||||||
|
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) {
|
||||||
@@ -115,14 +119,17 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
{
|
{
|
||||||
currentCommand === "remote_reset"
|
currentCommand === "remote_reset"
|
||||||
?
|
?
|
||||||
<ResetCommand classes={classes} ecus={ecus} currentECU={currentECU} setCurrentECU={setCurrentECU} />
|
<AllECUsCommand classes={classes} ecus={ecus} currentECU={currentECU} setCurrentECU={setCurrentECU} />
|
||||||
: currentCommand === "can_network"
|
: currentCommand === "can_network"
|
||||||
?
|
?
|
||||||
<CanNetCommand canNetState={canNetState} setCanNetState={setCanNetState} seconds={seconds} setSeconds={setSeconds} />
|
<CanNetCommand canNetState={canNetState} setCanNetState={setCanNetState} seconds={seconds} setSeconds={setSeconds} />
|
||||||
: currentCommand === "remote_ignition"
|
: currentCommand === "remote_ignition"
|
||||||
?
|
?
|
||||||
<RemoteIgnitionCommand ignitionState={ignitionState} setIgnitionState={setIgnitionState} seconds={seconds} setSeconds={setSeconds} />
|
<RemoteIgnitionCommand ignitionState={ignitionState} setIgnitionState={setIgnitionState} seconds={seconds} setSeconds={setSeconds} />
|
||||||
: null
|
: currentCommand === "read_ecu_versions"
|
||||||
|
?
|
||||||
|
<AllECUsCommand classes={classes} ecus={ecus} currentECU={currentECU} setCurrentECU={setCurrentECU} />
|
||||||
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
<p></p>
|
<p></p>
|
||||||
@@ -179,7 +186,7 @@ const SendDiagnosticCommand = ({ vin, token, classes }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ResetCommand = ({ classes, ecus, currentECU, setCurrentECU }) => {
|
const AllECUsCommand = ({ classes, ecus, currentECU, setCurrentECU }) => {
|
||||||
return (
|
return (
|
||||||
<FormControl
|
<FormControl
|
||||||
className={classes.formControl}
|
className={classes.formControl}
|
||||||
@@ -206,6 +213,12 @@ const ResetCommand = ({ classes, ecus, currentECU, setCurrentECU }) => {
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
AllECUsCommand.propTypes = {
|
||||||
|
classes: PropTypes.object.isRequired,
|
||||||
|
ecus: PropTypes.array.isRequired,
|
||||||
|
currentECU: PropTypes.string.isRequired,
|
||||||
|
setCurrentECU: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
const CanNetCommand = ({ canNetState, setCanNetState, seconds, setSeconds }) => {
|
const CanNetCommand = ({ canNetState, setCanNetState, seconds, setSeconds }) => {
|
||||||
return (
|
return (
|
||||||
@@ -239,6 +252,11 @@ const CanNetCommand = ({ canNetState, setCanNetState, seconds, setSeconds }) =>
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
CanNetCommand.propTypes = {
|
||||||
|
setCanNetState: PropTypes.func.isRequired,
|
||||||
|
seconds: PropTypes.number.isRequired,
|
||||||
|
setSeconds: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
const RemoteIgnitionCommand = ({ ignitionState, setIgnitionState, setSeconds, seconds }) => {
|
const RemoteIgnitionCommand = ({ ignitionState, setIgnitionState, setSeconds, seconds }) => {
|
||||||
return (
|
return (
|
||||||
@@ -272,5 +290,11 @@ const RemoteIgnitionCommand = ({ ignitionState, setIgnitionState, setSeconds, se
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
RemoteIgnitionCommand.propTypes = {
|
||||||
|
ignitionState: PropTypes.bool.isRequired,
|
||||||
|
setIgnitionState: PropTypes.func.isRequired,
|
||||||
|
setSeconds: PropTypes.func.isRequired,
|
||||||
|
seconds: PropTypes.number.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
export default SendDiagnosticCommand;
|
export default SendDiagnosticCommand;
|
||||||
|
|||||||
Reference in New Issue
Block a user