-
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 #28 from Nasar165/remote-start
Remote start
- Loading branch information
Showing
10 changed files
with
144 additions
and
27 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
File renamed without changes.
14 changes: 7 additions & 7 deletions
14
...ervice/ocpp/charging/start.transaction.ts → ...cpp/command/charging/start.transaction.ts
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.
10 changes: 5 additions & 5 deletions
10
...service/ocpp/charging/stop.transaction.ts → ...ocpp/command/charging/stop.transaction.ts
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
29 changes: 29 additions & 0 deletions
29
app/service/ocpp/command/remote/remote.start.transaction.model.ts
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,29 @@ | ||
import { IsOptional, IsString, Min, Max } from 'class-validator'; | ||
|
||
enum Status { | ||
ACCEPTED = 'Accepted', | ||
REJECTED = 'Rejected', | ||
} | ||
|
||
interface IRemoteStartTransactionRes { | ||
status: Status; | ||
} | ||
|
||
interface IRemoteStartTransaction { | ||
connectorId: number; | ||
idTag: string; | ||
} | ||
|
||
class RemoteStartTransaction implements IRemoteStartTransaction { | ||
@Min(0) | ||
@Max(1) | ||
@IsOptional() | ||
connectorId: number = 0; | ||
@IsString() | ||
idTag: string = ''; | ||
@IsOptional() | ||
chargingProfile: unknown; | ||
} | ||
|
||
export type { IRemoteStartTransactionRes, IRemoteStartTransaction }; | ||
export { RemoteStartTransaction, Status }; |
51 changes: 51 additions & 0 deletions
51
app/service/ocpp/command/remote/remote.start.transaction.ts
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,51 @@ | ||
import { IWriter } from '@/app/service/websocket/websocket.model'; | ||
import { IRequest } from '../../ocpp.frame'; | ||
import { StatusNotification } from '../status-notification/status.notification'; | ||
import { CreateResponseFrame } from '../../ocpp.action'; | ||
import { | ||
IRemoteStartTransaction, | ||
IRemoteStartTransactionRes, | ||
RemoteStartTransaction, | ||
Status, | ||
} from './remote.start.transaction.model'; | ||
import { SendStartTransaction } from '../charging/start.transaction'; | ||
import Validate from '@/app/helper/validation.helper'; | ||
import { CreateError, ErrorCode } from '../../ocpp.error'; | ||
|
||
export function RemoteStartTransactionReq( | ||
w: IWriter, | ||
frame: IRequest, | ||
state: StatusNotification | ||
): void { | ||
console.log(state); | ||
|
||
let status: IRemoteStartTransactionRes = { status: Status.REJECTED }; | ||
if ( | ||
state == StatusNotification.AVAILABLE || | ||
state == StatusNotification.PREPARING || | ||
state == StatusNotification.FINISHING | ||
) { | ||
const [result, validation] = Validate<IRemoteStartTransaction>( | ||
RemoteStartTransaction, | ||
frame.payload | ||
); | ||
|
||
if (validation.length > 0) { | ||
w.Write(CreateError(ErrorCode.PropertyConstraintViolation, validation)); | ||
return; | ||
} | ||
|
||
if (result.connectorId == 0) { | ||
result.connectorId = 1; | ||
} | ||
|
||
status.status = Status.ACCEPTED; | ||
SendStartTransaction(w, result.connectorId, result.idTag); | ||
} | ||
|
||
const response = CreateResponseFrame<IRemoteStartTransactionRes>( | ||
frame.uuid, | ||
status | ||
); | ||
w.Write(response); | ||
} |
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,23 @@ | ||
import { IWriter } from '../websocket/websocket.model'; | ||
import { RemoteStartTransactionReq } from './command/remote/remote.start.transaction'; | ||
import { StatusNotification } from './command/status-notification/status.notification'; | ||
import { Action } from './ocpp.action'; | ||
import { ErrorCode } from './ocpp.error'; | ||
import { IRequest } from './ocpp.frame'; | ||
|
||
type ActionItem = { | ||
name: string; | ||
handel: (w: IWriter, frame: IRequest, state: StatusNotification) => void; | ||
}; | ||
|
||
const List: Array<ActionItem> = [ | ||
{ name: Action.REMOTE_START_TRANSACTION, handel: RemoteStartTransactionReq }, | ||
]; | ||
|
||
function FindAction(action: string): ActionItem { | ||
const handler = List.find((a) => a.name == action); | ||
if (handler == null) throw new Error(ErrorCode.NotImplemented); | ||
return handler; | ||
} | ||
|
||
export { FindAction }; |
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