-
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 #30 from Nasar165/meter-value
Meter value
- Loading branch information
Showing
6 changed files
with
112 additions
and
7 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,59 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import Select, { ReturnValue } from './select'; | ||
import { meterValueList } from './transaction'; | ||
import { StatusNotification } from '../service/ocpp/command/status-notification/status.notification'; | ||
import Button from './button'; | ||
import { SendMeterValue } from '../service/ocpp/command/meter-value/meter.value'; | ||
import { IWriter } from '../service/websocket/websocket.model'; | ||
|
||
const DEFAULT_INTERVAL = 20000; | ||
|
||
type meterValue = { | ||
w: IWriter; | ||
connectorId: number; | ||
state: StatusNotification; | ||
}; | ||
|
||
export default function MeterValue({ | ||
w, | ||
connectorId, | ||
state, | ||
}: meterValue): React.JSX.Element { | ||
const [meter, setMeter] = useState<Array<number>>([250]); | ||
const meterValue = { name: meter.toString(), value: meter[0] }; | ||
|
||
const onSelectChange = (item: ReturnValue) => { | ||
meter[0] = item as number; | ||
setMeter([...meter]); | ||
}; | ||
|
||
const onClick = () => { | ||
SendMeterValue(w, connectorId, meter[0]); | ||
}; | ||
|
||
useEffect(() => { | ||
console.info('start interval'); | ||
const id = setInterval(onClick, DEFAULT_INTERVAL - 19000); | ||
return () => { | ||
console.info('clean up interval'); | ||
clearInterval(id); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div className='border border-black p-2 my-2 rounded-md'> | ||
<p className='my-2'>Meter value</p> | ||
<p className='text-xs'>Notes: Meter Values are sent every 20 seconds</p> | ||
<Select | ||
items={meterValueList} | ||
onChange={onSelectChange} | ||
defaultItem={meterValue} | ||
/> | ||
<Button | ||
onClick={onClick} | ||
text='Send Meter Values' | ||
disabled={state != StatusNotification.CHARGING} | ||
/> | ||
</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
File renamed without changes.
Empty file.
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,32 @@ | ||
import { IWriter } from '../../../websocket/websocket.model'; | ||
import { Action, CreateRequestFrame, GetRequestFrame } from '../../ocpp.action'; | ||
import { CreateTransaction } from '../../transaction/transaction.handler'; | ||
import { GetSession } from '../charging/start.transaction'; | ||
|
||
function SendMeterValue(w: IWriter, connectorId: number, value: number): void { | ||
const session = GetSession(); | ||
const payload: any = { | ||
connectorId, | ||
meterValue: [ | ||
{ | ||
context: 'Sample.Periodic', | ||
value: value, | ||
unit: 'W', | ||
measurand: 'Power.Active.Import', | ||
}, | ||
], | ||
}; | ||
|
||
if (session != null && session.transactionId != 0) | ||
payload['transactionId'] = session.transactionId; | ||
|
||
const frame = CreateRequestFrame(Action.METER_VALUES, payload); | ||
CreateTransaction(GetRequestFrame(frame), MeterValue); | ||
w.Write(frame); | ||
} | ||
|
||
function MeterValue(): void { | ||
console.log('meter value accepted by CSMS'); | ||
} | ||
|
||
export { SendMeterValue, MeterValue }; |