-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux_platform_packet.py
275 lines (251 loc) · 6.43 KB
/
linux_platform_packet.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import struct
NUM_CONNECTORS = 1
# charge point state
# statusnotificationstatus
# message if type
# connector state
# tag status
# configuration
# keep in sync with ChargePoint.h OcppStateStrings
charge_point_state_strings = [
"PowerOn",
"FlushPersistentMessages",
"Idle",
"Pending",
"Rejected",
"Unavailable",
"Faulted",
"SoftReset",
"HardReset"
]
# TODO: generate
status_notification_status_strings = [
"Available",
"Preparing",
"Charging",
"SuspendedEV",
"SuspendedEVSE",
"Finishing",
"Reserved",
"Unavailable",
"Faulted",
"NONE"
]
#TODO generate
message_in_flight_type_strings = [
"Authorize",
"BootNotification",
"ChangeAvailabilityResponse",
"ChangeConfigurationResponse",
"ClearCacheResponse",
"DataTransfer",
"DataTransferResponse",
"GetConfigurationResponse",
"Heartbeat",
"MeterValues",
"RemoteStartTransactionResponse",
"RemoteStopTransactionResponse",
"ResetResponse",
"StartTransaction",
"StatusNotification",
"StopTransaction",
"UnlockConnectorResponse",
"AuthorizeResponse",
"BootNotificationResponse",
"ChangeAvailability",
"ChangeConfiguration",
"ClearCache",
"GetConfiguration",
"HeartbeatResponse",
"MeterValuesResponse",
"RemoteStartTransaction",
"RemoteStopTransaction",
"Reset",
"StartTransactionResponse",
"StatusNotificationResponse",
"StopTransactionResponse",
"UnlockConnector",
"GetDiagnosticsResponse",
"DiagnosticsStatusNotification",
"FirmwareStatusNotification",
"UpdateFirmwareResponse",
"GetDiagnostics",
"DiagnosticsStatusNotificationResponse",
"FirmwareStatusNotificationResponse",
"UpdateFirmware",
"GetLocalListVersionResponse",
"SendLocalListResponse",
"GetLocalListVersion",
"SendLocalList",
"CancelReservationResponse",
"ReserveNowResponse",
"CancelReservation",
"ReserveNow",
"ClearChargingProfileResponse",
"GetCompositeScheduleResponse",
"SetChargingProfileResponse",
"ClearChargingProfile",
"GetCompositeSchedule",
"SetChargingProfile",
"TriggerMessageResponse",
"TriggerMessage"
]
# keep in sync with Connector.cpp ConnectorStateStrings
connector_state_strings = [
"IDLE",
"NO_CABLE_NO_TAG",
"NO_TAG",
"AUTH_START_NO_PLUG",
"AUTH_START_NO_CABLE",
"AUTH_START",
"NO_PLUG",
"NO_CABLE",
"TRANSACTION",
"AUTH_STOP",
"FINISHING_UNLOCKED",
"FINISHING_NO_CABLE_UNLOCKED",
"FINISHING_NO_CABLE_LOCKED",
"FINISHING_NO_SAME_TAG",
"UNAVAILABLE"
]
# TODO: generate
tag_status_strings = [
"Accepted",
"Blocked",
"Expired",
"Invalid",
"ConcurrentTx"
]
# keep in sync with Configuration config_keys
config_key_strings = [
# CORE PROFILE
#"AllowOfflineTxForUnknownId",
#"AuthorizationCacheEnabled",
"AuthorizeRemoteTxRequests",
#"BlinkRepeat",
"ClockAlignedDataInterval",
"ConnectionTimeOut",
"ConnectorPhaseRotation",
"ConnectorPhaseRotationMaxLength",
"GetConfigurationMaxKeys",
"HeartbeatInterval",
#"LightIntensity",
"LocalAuthorizeOffline",
"LocalPreAuthorize",
#"MaxEnergyOnInvalidId",
"MessageTimeout",
"MeterValuesAlignedData",
"MeterValuesAlignedDataMaxLength",
"MeterValuesSampledData",
"MeterValuesSampledDataMaxLength",
"MeterValueSampleInterval",
#"MinimumStatusDuration",
"NumberOfConnectors",
"ResetRetries",
"StopTransactionOnEVSideDisconnect",
"StopTransactionOnInvalidId",
"StopTransactionMaxMeterValues",
"StopTxnAlignedData",
"StopTxnAlignedDataMaxLength",
"StopTxnSampledData",
"StopTxnSampledDataMaxLength",
"SupportedFeatureProfiles",
#"SupportedFeatureProfilesMaxLength",
"TransactionMessageAttempts",
"TransactionMessageRetryInterval",
"UnlockConnectorOnEVSideDisconnect",
"WebSocketPingInterval",
# # LOCAL AUTH LIST MANAGEMENT PROFILE
#"LocalAuthListEnabled",
#"LocalAuthListMaxLength",
#"SendLocalListMaxLength",
# # RESERVATION PROFILE
#"ReserveConnectorZeroSupported",
# SMART CHARGING PROFILE
"ChargeProfileMaxStackLevel",
"ChargingScheduleAllowedChargingRateUnit",
"ChargingScheduleMaxPeriods",
"ConnectorSwitch3to1PhaseSupported",
"MaxChargingProfilesInstalled",
]
"""
struct PlatformResponse {
uint8_t seq_num;
char tag_id_seen[22];
uint8_t fixed_cable;
uint8_t evse_state[NUM_CONNECTORS];
uint32_t energy[NUM_CONNECTORS];
} __attribute__((__packed__));
struct ConnectorMessage {
uint8_t state;
uint8_t last_sent_status;
char tag_id[21];
char parent_tag_id[21];
uint8_t tag_status;
time_t tag_expiry_date;
uint32_t tag_deadline;
uint32_t cable_deadline;
int32_t txn_id;
uint64_t transaction_confirmed_id;
time_t transaction_start_time;
uint32_t current_allowed;
bool txn_with_invalid_id;
bool unavailable_requested;
} __attribute__((__packed__));
struct PlatformMessage {
uint8_t seq_num = 0;
char message[63] = "";
uint32_t charge_current[NUM_CONNECTORS] = {0};
uint8_t connector_locked = 0;
uint8_t charge_point_state;
uint8_t charge_point_last_sent_status;
time_t next_profile_eval;
uint8_t message_in_flight_type;
int32_t message_in_flight_id;
size_t message_in_flight_len;
uint32_t message_timeout_deadline;
uint32_t txn_msg_retry_deadline;
uint8_t queue_depths[3];
uint8_t config_key;
char config_value[500];
ConnectorMessage connector_messages[NUM_CONNECTORS];
} __attribute__((__packed__));
"""
header_format = "<B" # uint8_t seq_num = 0;
connector_format = \
"B" + \
"B" + \
"21s" + \
"21s" + \
"B" + \
"q" + \
"I" + \
"I" + \
"i" + \
"Q" + \
"q" + \
"I" + \
"?" + \
"?"
request_format = header_format + \
"63s" + \
"{num_conn}I" + \
"B" + \
"B" + \
"B" + \
"q" + \
"B" + \
"Q" + \
"Q" + \
"I" + \
"I" + \
"B" + \
"B" + \
"B" + \
"B" + \
"500s"
request_format += connector_format * NUM_CONNECTORS
request_format = request_format.format(num_conn=NUM_CONNECTORS)
response_format = header_format + "22sB{num_conn}B{num_conn}I".format(num_conn=NUM_CONNECTORS)
request_len = struct.calcsize(request_format)
response_len = struct.calcsize(response_format)