-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Nasar165/start-transaction
start charging implemented
- Loading branch information
Showing
14 changed files
with
257 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type button = { | ||
text: string; | ||
disabled: boolean; | ||
onClick: () => void; | ||
}; | ||
|
||
export default function Button({ text, disabled, onClick }: button) { | ||
const disable = disabled ? 'bg-gray-400' : ''; | ||
return ( | ||
<button | ||
className={`${disable} border border-blue-600 rounded-md px-4 py-2 my-4`} | ||
onClick={() => onClick()} | ||
disabled={disabled} | ||
> | ||
{text} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { SyntheticEvent, useState } from 'react'; | ||
import { SendStartTransaction } from '../service/ocpp/charging/start.transaction'; | ||
import Input from './input'; | ||
import Button from './button'; | ||
import { IWriter } from '../service/websocket/websocket.model'; | ||
import { StatusNotification } from '../service/ocpp/command/status-notification/status.notification'; | ||
|
||
type transaction = { | ||
writer: IWriter; | ||
connectorId: number; | ||
state: StatusNotification; | ||
}; | ||
|
||
export default function Transaction({ | ||
writer, | ||
connectorId, | ||
state, | ||
}: transaction): React.JSX.Element { | ||
const [idTag, setIdTag] = useState('cli013322'); | ||
const onChange = (ev: SyntheticEvent<HTMLInputElement>) => { | ||
setIdTag(ev.currentTarget.value); | ||
}; | ||
|
||
const notConnected = () => { | ||
if (writer == null) { | ||
alert('Please connect to CSMS'); | ||
} | ||
}; | ||
|
||
const onStart = () => { | ||
if (writer == null) { | ||
notConnected(); | ||
return; | ||
} | ||
|
||
if ( | ||
state == StatusNotification.AVAILABLE || | ||
state == StatusNotification.PREPARING | ||
) { | ||
if (idTag.trim() == '') return; | ||
SendStartTransaction(writer, connectorId, idTag); | ||
return; | ||
} | ||
|
||
alert( | ||
'Please make sure that the charger is in Available or preparing state' | ||
); | ||
}; | ||
|
||
const onStop = () => { | ||
if (writer == null) { | ||
notConnected(); | ||
return; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='border border-black p-2 my-2 rounded-md'> | ||
<Input | ||
title='Client id tag' | ||
name='idTag' | ||
placeholder='enter ID tag to submit with start transaction' | ||
value={idTag} | ||
onChange={onChange} | ||
disabled={false} | ||
/> | ||
<div className='grid gap-2 grid-cols-2'> | ||
<Button | ||
onClick={onStart} | ||
text='Start Transaction' | ||
disabled={state == StatusNotification.CHARGING} | ||
/> | ||
<Button | ||
onClick={onStop} | ||
text='Stop Transaction' | ||
disabled={state != StatusNotification.CHARGING} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Min } from 'class-validator'; | ||
|
||
enum AuthorizationStatus { | ||
ACCEPTED = 'Accepted', | ||
BLOCKED = 'Blocked', | ||
EXPIRED = 'Expired', | ||
INVALID = 'Invalid', | ||
CONCURRENT_TX = 'ConcurrentTx', | ||
} | ||
|
||
interface IIdTagInfo { | ||
expiryDate: Date; | ||
parentIdTag: string; | ||
status: string; | ||
} | ||
|
||
interface IStartTransactionRes { | ||
idTagInfo: IIdTagInfo; | ||
transactionId: number; | ||
} | ||
|
||
interface IStartTransaction { | ||
connectorId: number; | ||
idTag: string; | ||
meterStart: number; | ||
timestamp: Date; | ||
} | ||
|
||
interface IChargingSession { | ||
idTag: string; | ||
transactionId: number; | ||
connectorId: number; | ||
} | ||
|
||
class StartTransactionsRes implements IStartTransactionRes { | ||
idTagInfo: IIdTagInfo = { | ||
expiryDate: new Date(), | ||
status: AuthorizationStatus.BLOCKED, | ||
parentIdTag: '', | ||
}; | ||
|
||
@Min(0) | ||
transactionId: number = 0; | ||
} | ||
|
||
export type { | ||
IIdTagInfo, | ||
IStartTransaction, | ||
IStartTransactionRes, | ||
IChargingSession, | ||
}; | ||
export { AuthorizationStatus, StartTransactionsRes }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Validate from '@/app/helper/validation.helper'; | ||
import { IWriter } from '../../websocket/websocket.model'; | ||
import { Action, CreateRequestFrame, GetRequestFrame } from '../ocpp.action'; | ||
import { CreateError, ErrorCode } from '../ocpp.error'; | ||
import { IResponse } from '../ocpp.frame'; | ||
import { ChangeState } from '../ocpp.handler'; | ||
import { CreateTransaction } from '../transaction/transaction.handler'; | ||
import { | ||
AuthorizationStatus, | ||
IChargingSession, | ||
IStartTransaction, | ||
StartTransactionsRes, | ||
} from './start.transaction.model'; | ||
import { StatusNotification } from '../command/status-notification/status.notification'; | ||
|
||
let session: IChargingSession; | ||
|
||
function SendStartTransaction( | ||
w: IWriter, | ||
connectorId: number, | ||
idTag: string | ||
): void { | ||
const transaction: IStartTransaction = { | ||
connectorId, | ||
idTag, | ||
meterStart: 0, | ||
timestamp: new Date(), | ||
}; | ||
|
||
const frame = CreateRequestFrame(Action.START_TRANSACTION, transaction); | ||
w.Write(frame); | ||
CreateTransaction(GetRequestFrame(frame), StartTransaction); | ||
session = { connectorId, idTag, transactionId: -1 }; | ||
} | ||
|
||
function StartTransaction( | ||
w: IWriter, | ||
frame: IResponse, | ||
changeState: ChangeState | ||
): IChargingSession | undefined { | ||
const [result, validation] = Validate<StartTransactionsRes>( | ||
StartTransactionsRes, | ||
frame.payload | ||
); | ||
|
||
if (validation.length > 0) { | ||
w.Write(CreateError(ErrorCode.PropertyConstraintViolation, validation)); | ||
return; | ||
} | ||
|
||
if (result.idTagInfo.status != AuthorizationStatus.ACCEPTED) { | ||
return; | ||
} | ||
|
||
changeState(StatusNotification.CHARGING); | ||
session.transactionId = result.transactionId; | ||
return session; | ||
} | ||
|
||
export { SendStartTransaction, StartTransaction }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters