Skip to content

Commit 514d25a

Browse files
committed
Updated samples.
1 parent 31ca3d7 commit 514d25a

File tree

4 files changed

+313
-18
lines changed

4 files changed

+313
-18
lines changed

ocpp-v1_6-example/src/main/core_features/JSONClientSample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorR
122122
return null; // returning null means unsupported feature
123123
}
124124
});
125-
client = new JSONClient(core);
126-
client.connect("ws://hostname:8887");
125+
client = new JSONClient(core, "chargeboxIdentity");
126+
client.connect("ws://hostname:8887", null);
127127
}
128128

129129
public void sendBootNotification() throws Exception {

ocpp-v1_6-example/src/main/core_features/JSONServerSample.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
package eu.chargetime.ocpp.test;
1+
package core_features;
22

33
import eu.chargetime.ocpp.JSONServer;
44
import eu.chargetime.ocpp.ServerEvents;
55
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
66
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
7-
import eu.chargetime.ocpp.model.Confirmation;
8-
import eu.chargetime.ocpp.model.Request;
97
import eu.chargetime.ocpp.model.core.*;
108

11-
import java.util.Calendar;
9+
import java.util.UUID;
1210

1311
/*
1412
ChargeTime.eu - Java-OCA-OCPP
@@ -39,16 +37,17 @@ of this software and associated documentation files (the "Software"), to deal
3937
public class JSONServerSample
4038
{
4139
private JSONServer server;
40+
private ServerCoreProfile core;
4241

4342
public void started() throws Exception
4443
{
4544
if (server != null)
4645
return;
4746

4847
// The core profile is mandatory
49-
ServerCoreProfile core = new ServerCoreProfile(new ServerCoreEventHandler() {
48+
core = new ServerCoreProfile(new ServerCoreEventHandler() {
5049
@Override
51-
public AuthorizeConfirmation handleAuthorizeRequest(int sessionIndex, AuthorizeRequest request) {
50+
public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
5251

5352
System.out.println(request);
5453
// ... handle event
@@ -57,7 +56,7 @@ public AuthorizeConfirmation handleAuthorizeRequest(int sessionIndex, AuthorizeR
5756
}
5857

5958
@Override
60-
public BootNotificationConfirmation handleBootNotificationRequest(int sessionIndex, BootNotificationRequest request) {
59+
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
6160

6261
System.out.println(request);
6362
// ... handle event
@@ -66,7 +65,7 @@ public BootNotificationConfirmation handleBootNotificationRequest(int sessionInd
6665
}
6766

6867
@Override
69-
public DataTransferConfirmation handleDataTransferRequest(int sessionIndex, DataTransferRequest request) {
68+
public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
7069

7170
System.out.println(request);
7271
// ... handle event
@@ -75,7 +74,7 @@ public DataTransferConfirmation handleDataTransferRequest(int sessionIndex, Data
7574
}
7675

7776
@Override
78-
public HeartbeatConfirmation handleHeartbeatRequest(int sessionIndex, HeartbeatRequest request) {
77+
public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
7978

8079
System.out.println(request);
8180
// ... handle event
@@ -84,7 +83,7 @@ public HeartbeatConfirmation handleHeartbeatRequest(int sessionIndex, HeartbeatR
8483
}
8584

8685
@Override
87-
public MeterValuesConfirmation handleMeterValuesRequest(int sessionIndex, MeterValuesRequest request) {
86+
public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
8887

8988
System.out.println(request);
9089
// ... handle event
@@ -93,7 +92,7 @@ public MeterValuesConfirmation handleMeterValuesRequest(int sessionIndex, MeterV
9392
}
9493

9594
@Override
96-
public StartTransactionConfirmation handleStartTransactionRequest(int sessionIndex, StartTransactionRequest request) {
95+
public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
9796

9897
System.out.println(request);
9998
// ... handle event
@@ -102,7 +101,7 @@ public StartTransactionConfirmation handleStartTransactionRequest(int sessionInd
102101
}
103102

104103
@Override
105-
public StatusNotificationConfirmation handleStatusNotificationRequest(int sessionIndex, StatusNotificationRequest request) {
104+
public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
106105

107106
System.out.println(request);
108107
// ... handle event
@@ -111,7 +110,7 @@ public StatusNotificationConfirmation handleStatusNotificationRequest(int sessio
111110
}
112111

113112
@Override
114-
public StopTransactionConfirmation handleStopTransactionRequest(int sessionIndex, StopTransactionRequest request) {
113+
public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
115114

116115
System.out.println(request);
117116
// ... handle event
@@ -124,14 +123,14 @@ public StopTransactionConfirmation handleStopTransactionRequest(int sessionIndex
124123
server.open("localhost", 8887, new ServerEvents() {
125124

126125
@Override
127-
public void newSession(int sessionIndex) {
126+
public void newSession(UUID sessionIndex, String identifier) {
128127

129128
// sessionIndex is used to send messages.
130-
System.out.println("New session " + sessionIndex);
129+
System.out.println("New session " + sessionIndex + ": " + identifier);
131130
}
132131

133132
@Override
134-
public void lostSession(int sessionIndex) {
133+
public void lostSession(UUID sessionIndex) {
135134

136135
System.out.println("Session " + sessionIndex + " lost connection");
137136
}
@@ -143,6 +142,7 @@ public void sendClearCacheRequest() throws Exception {
143142
// Use the feature profile to help create event
144143
ClearCacheRequest request = core.createClearCacheRequest();
145144

145+
UUID sessionIndex = null;
146146
// Server returns a promise which will be filled once it receives a confirmation.
147147
// Select the distination client with the sessionIndex integer.
148148
server.send(sessionIndex, request).whenComplete((confirmation, throwable) -> System.out.println(confirmation));
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package core_features;
2+
3+
import eu.chargetime.ocpp.Client;
4+
import eu.chargetime.ocpp.SOAPClient;
5+
import eu.chargetime.ocpp.feature.profile.ClientCoreEventHandler;
6+
import eu.chargetime.ocpp.feature.profile.ClientCoreProfile;
7+
import eu.chargetime.ocpp.model.Request;
8+
import eu.chargetime.ocpp.model.core.*;
9+
10+
import java.net.URL;
11+
12+
/*
13+
* ChargeTime.eu - Java-OCA-OCPP
14+
* Copyright (C) 2015-2016 Thomas Volden <[email protected]>
15+
*
16+
* MIT License
17+
*
18+
* Copyright (c) 2016 Thomas Volden
19+
*
20+
* Permission is hereby granted, free of charge, to any person obtaining a copy
21+
* of this software and associated documentation files (the "Software"), to deal
22+
* in the Software without restriction, including without limitation the rights
23+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24+
* copies of the Software, and to permit persons to whom the Software is
25+
* furnished to do so, subject to the following conditions:
26+
*
27+
* The above copyright notice and this permission notice shall be included in all
28+
* copies or substantial portions of the Software.
29+
*
30+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
* SOFTWARE.
37+
*/
38+
public class SOAPClientSample {
39+
private Client client;
40+
private ClientCoreProfile core;
41+
42+
public void connect() throws Exception {
43+
44+
// The core profile is mandatory
45+
core = new ClientCoreProfile(new ClientCoreEventHandler() {
46+
@Override
47+
public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest(ChangeAvailabilityRequest request) {
48+
49+
System.out.println(request);
50+
// ... handle event
51+
52+
return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted);
53+
}
54+
55+
@Override
56+
public GetConfigurationConfirmation handleGetConfigurationRequest(GetConfigurationRequest request) {
57+
58+
System.out.println(request);
59+
// ... handle event
60+
61+
return null; // returning null means unsupported feature
62+
}
63+
64+
@Override
65+
public ChangeConfigurationConfirmation handleChangeConfigurationRequest(ChangeConfigurationRequest request) {
66+
67+
System.out.println(request);
68+
// ... handle event
69+
70+
return null; // returning null means unsupported feature
71+
}
72+
73+
@Override
74+
public ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request) {
75+
76+
System.out.println(request);
77+
// ... handle event
78+
79+
return null; // returning null means unsupported feature
80+
}
81+
82+
@Override
83+
public DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request) {
84+
85+
System.out.println(request);
86+
// ... handle event
87+
88+
return null; // returning null means unsupported feature
89+
}
90+
91+
@Override
92+
public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request) {
93+
94+
System.out.println(request);
95+
// ... handle event
96+
97+
return null; // returning null means unsupported feature
98+
}
99+
100+
@Override
101+
public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request) {
102+
103+
System.out.println(request);
104+
// ... handle event
105+
106+
return null; // returning null means unsupported feature
107+
}
108+
109+
@Override
110+
public ResetConfirmation handleResetRequest(ResetRequest request) {
111+
112+
System.out.println(request);
113+
// ... handle event
114+
115+
return null; // returning null means unsupported feature
116+
}
117+
118+
@Override
119+
public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request) {
120+
121+
System.out.println(request);
122+
// ... handle event
123+
124+
return null; // returning null means unsupported feature
125+
}
126+
});
127+
client = new SOAPClient("chargeboxIdentity", new URL("http://localhost:8889"), core);
128+
client.connect("ws://hostname:8887", null);
129+
}
130+
131+
public void sendBootNotification() throws Exception {
132+
133+
// Use the feature profile to help create event
134+
Request request = core.createBootNotificationRequest("some vendor", "some model");
135+
136+
// Client returns a promise which will be filled once it receives a confirmation.
137+
client.send(request).whenComplete((s, ex) -> System.out.println(s));
138+
}
139+
140+
public void disconnect() {
141+
client.disconnect();
142+
}
143+
144+
}

0 commit comments

Comments
 (0)