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