forked from Sevenstax/FreeV2G
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.py
98 lines (84 loc) · 4.34 KB
/
Application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import argparse
import json
from Evse import *
from Ev import *
if __name__ == "__main__":
WHITEBBET_DEFAULT_MAC = "00:01:01:63:77:33"
parser = argparse.ArgumentParser(description='Codico Whitebeet reference implementation.')
parser.add_argument('interface_type', type=str, choices=('eth', 'spi'), help='Type of the interface through which the Whitebeet is connected. ("eth" or "spi").')
parser.add_argument('-i', '--interface', type=str, required=True, help='This is the name of the interface where the Whitebeet is connected to (i.e. for eth "eth0" or spi "0").')
parser.add_argument('-m', '--mac', type=str, help='This is the MAC address of the ethernet interface of the Whitebeet (i.e. "{}").'.format(WHITEBBET_DEFAULT_MAC))
parser.add_argument('-r', '--role', type=str, choices=('EVSE', 'EV'), required=True, help='This is the role of the Whitebeet. "EV" for EV mode and "EVSE" for EVSE mode')
parser.add_argument('-c', '--config', type=str, help='Path to configuration file. Defaults to ./ev.json.\nA MAC present in the config file will override a MAC provided with -m argument.', nargs='?', const="./ev.json")
parser.add_argument('-p', '--portmirror', help='Enables port mirror.', action='store_true')
args = parser.parse_args()
# If no MAC address was given set it to the default MAC address of the Whitebeet
if args.interface_type == "eth" and args.mac is None:
args.mac = WHITEBBET_DEFAULT_MAC
print('Welcome to Codico Whitebeet {} reference implementation'.format(args.role))
# role is EV
if(args.role == "EV"):
mac = args.mac
config = None
# Load configuration from json
if args.config is not None:
try:
with open(args.config, 'r') as configFile:
config = json.load(configFile)
# if a MAC adress is specified in the config file use this
if 'mac' in config:
mac = config['mac']
except FileNotFoundError as err:
print("Configuration file " + str(args.config) + " not found. Use default configuration.")
with Ev(args.interface_type, args.interface, args.mac) as ev:
# apply config to ev
if config is not None:
print("EV configuration: " + str(config))
ev.load(config)
# Start the EVSE loop
ev.whitebeet.networkConfigSetPortMirrorState(args.portmirror)
ev.loop()
print("EV loop finished")
elif(args.role == 'EVSE'):
with Evse(args.interface_type, args.interface, args.mac) as evse:
# Set regulation parameters of the charger
evse.getCharger().setEvseDeltaVoltage(0.5)
evse.getCharger().setEvseDeltaCurrent(0.05)
# Set limitations of the charger
evse.getCharger().setEvseMaxVoltage(400)
evse.getCharger().setEvseMaxCurrent(100)
evse.getCharger().setEvseMaxPower(25000)
# Start the charger
evse.getCharger().start()
# Set the schedule
digest_value = range(31)
signature_value = range(63)
schedule = {
"code": 0,
"schedule_tuples": [{
'schedule_tuple_id': 1,
'schedules':[
{
"start": 0,
"interval": 1800,
"power": evse.getCharger().getEvseMaxPower()
},
{
"start": 1800,
"interval": 1800,
"power": int(evse.getCharger().getEvseMaxPower() * 0.75)
},
{
"start": 3600,
"interval": 82800,
"power": int(evse.getCharger().getEvseMaxPower() * 0.5)
}
]
}]
}
evse.setSchedule(schedule)
# Start the EVSE loop
evse.whitebeet.networkConfigSetPortMirrorState(args.portmirror)
evse.loop()
print("EVSE loop finished")
print("Goodbye!")