Skip to content

Commit

Permalink
support faulted
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv3 committed Jul 7, 2024
1 parent facc0b0 commit 6442e67
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
35 changes: 25 additions & 10 deletions src/components/Connector.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState, useEffect } from "react";
import { ChargePoint } from "../cp/ChargePoint.ts";
import React, {useState, useEffect} from "react";
import {ChargePoint} from "../cp/ChargePoint.ts";
import * as ocpp from "../cp/OcppTypes";

interface ConnectorProps {
id: number;
cp: ChargePoint | null;
}

const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
const Connector: React.FC<ConnectorProps> = ({id: connector_id, cp}) => {
const [cpTransactionID, setCpTransactionID] = useState<number | null>(0);
const [connectorStatus, setConnectorStatus] = useState<ocpp.OCPPStatus>(
ocpp.OCPPStatus.Unavailable
Expand All @@ -16,7 +16,7 @@ const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
ocpp.OCPPAvailability.Operative
);
const [meterValue, setMeterValue] = useState<number>(0);
const [idTag] = useState<string>(localStorage.getItem("TAG") || "DEADBEEF");
const [idTag, setIdTag] = useState<string>(localStorage.getItem("TAG") || "DEADBEEF");

useEffect(() => {
if (cp) {
Expand Down Expand Up @@ -72,7 +72,7 @@ const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
<label className="text-gray-700 text-sm font-bold mb-2">
Connector Status:{" "}
</label>
<ConnectorStatus status={connectorStatus} />
<ConnectorStatus status={connectorStatus}/>
</div>
{connectorStatus === ocpp.OCPPStatus.Charging && (
<div className="mb-6">
Expand All @@ -89,7 +89,7 @@ const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
onChange={(e) =>
setConnectorStatus(e.target.value as ocpp.OCPPStatus)
}
style={{ maxWidth: "16ch", marginRight: "1ch" }}
style={{maxWidth: "16ch", marginRight: "1ch"}}
>
{Object.keys(ocpp.OCPPStatus).map((status) =>
status === ocpp.OCPPStatus.Charging ? null : (
Expand Down Expand Up @@ -117,7 +117,7 @@ const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
>
Connector Availability:
</label>
<ConnectorAvailability availability={availability} />
<ConnectorAvailability availability={availability}/>
{/*<select
<select
id={`AVAILABILITY_CON${connector_id}`}
Expand All @@ -133,6 +133,21 @@ const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
</div>
</div>
</div>
<div className="form-group bg-gray-100 rounded p-4">
<div className="mb-1">
<label className="text-gray-700 text-sm font-bold mb-2">
RFID Tag
</label>
<input
className="shadow appearance-none border rounded w-full py-1 px-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
type="text"
value={idTag}
onChange={(e) => setIdTag(e.target.value)}
placeholder="DEADBEEF"
style={{maxWidth: "20ch"}}
/>
</div>
</div>
<button
onClick={handleStartTransaction}
className="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded mb-2 w-full
Expand Down Expand Up @@ -189,7 +204,7 @@ const Connector: React.FC<ConnectorProps> = ({ id: connector_id, cp }) => {
);
};

const ConnectorStatus: React.FC<{ status: string }> = ({ status }) => {
const ConnectorStatus: React.FC<{ status: string }> = ({status}) => {
const statusColor = (s: string) => {
switch (s) {
case ocpp.OCPPStatus.Unavailable:
Expand All @@ -211,8 +226,8 @@ const ConnectorStatus: React.FC<{ status: string }> = ({ status }) => {
};

const ConnectorAvailability: React.FC<{ availability: string }> = ({
availability,
}) => {
availability,
}) => {
const availabilityColor = (a: string) => {
switch (a) {
case ocpp.OCPPAvailability.Operative:
Expand Down
5 changes: 4 additions & 1 deletion src/cp/OCPPMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,17 @@ export class OCPPMessageHandler {
payload: StartTransactionResponse
): void {
const { transactionId, idTagInfo } = payload;
const connector = this._chargePoint.getConnector(connectorId);
if (idTagInfo.status === "Accepted") {
const connector = this._chargePoint.getConnector(connectorId);
if (connector) {
connector.transactionId = transactionId;
connector.status = OCPPStatus.Charging;
}
} else {
this._logger.log("Failed to start transaction");
if (connector) {
connector.status = OCPPStatus.Faulted;
}
}
}

Expand Down

0 comments on commit 6442e67

Please sign in to comment.