1+ /*
2+ * SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
3+ * Copyright (C) 2013-2025 SteVe Community Team
4+ * All Rights Reserved.
5+ *
6+ * This program is free software: you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation, either version 3 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18+ */
119package de .rwth .idsg .steve ;
220
321import de .rwth .idsg .steve .ocpp .OcppVersion ;
1129import ocpp .cs ._2010 ._08 .MeterValuesRequest ;
1230import ocpp .cs ._2010 ._08 .StatusNotificationRequest ;
1331import ocpp .cs ._2010 ._08 .StopTransactionRequest ;
14- import ocpp .cs ._2010 ._08 .SampledValue ;
1532
1633import java .time .OffsetDateTime ;
1734import java .time .temporal .ChronoUnit ;
18- import java .util .Collections ;
1935
2036import static org .assertj .core .api .Assertions .assertThat ;
2137import static org .assertj .core .api .Assertions .byLessThan ;
@@ -25,16 +41,19 @@ public class Ocpp12JsonClient implements OcppTestClient {
2541 private final OcppJsonChargePoint client ;
2642
2743 public Ocpp12JsonClient (String chargeBoxId , String path ) {
28- this .client = new OcppJsonChargePoint (new JsonObjectMapper (), OcppVersion .V_12 , chargeBoxId , path );
44+ this .client =
45+ new OcppJsonChargePoint (JsonObjectMapper .createObjectMapper (), OcppVersion .V_12 , chargeBoxId , path );
2946 this .client .start ();
3047 }
3148
3249 @ Override
3350 public void bootNotification (String vendor , String model ) {
51+ var req = new BootNotificationRequest ();
52+ req .setChargePointVendor (vendor );
53+ req .setChargePointModel (model );
54+
3455 client .prepare (
35- new BootNotificationRequest ()
36- .withChargePointVendor (vendor )
37- .withChargePointModel (model ),
56+ req ,
3857 ocpp .cs ._2010 ._08 .BootNotificationResponse .class ,
3958 response -> assertThat (response .getStatus ()).isEqualTo (ocpp .cs ._2010 ._08 .RegistrationStatus .ACCEPTED ),
4059 error -> {
@@ -50,11 +69,13 @@ public void startTransaction(int connectorId, String idTag, int meterStart, Offs
5069
5170 @ Override
5271 public void stopTransaction (int transactionId , int meterStop , OffsetDateTime timestamp ) {
72+ var req = new StopTransactionRequest ();
73+ req .setTransactionId (transactionId );
74+ req .setTimestamp (timestamp );
75+ req .setMeterStop (meterStop );
76+
5377 client .prepare (
54- new StopTransactionRequest ()
55- .withTransactionId (transactionId )
56- .withTimestamp (timestamp )
57- .withMeterStop (meterStop ),
78+ req ,
5879 ocpp .cs ._2010 ._08 .StopTransactionResponse .class ,
5980 response -> assertThat (response ).isNotNull (),
6081 error -> {
@@ -65,13 +86,16 @@ public void stopTransaction(int transactionId, int meterStop, OffsetDateTime tim
6586
6687 @ Override
6788 public void meterValues (int connectorId , int transactionId , OffsetDateTime timestamp , String value ) {
68- var meterValue = new MeterValue ()
69- .withTimestamp (timestamp )
70- .withSampledValue (Collections .singletonList (new SampledValue ().withValue (value )));
71- var meterValuesRequest = new MeterValuesRequest ()
72- .withConnectorId (connectorId )
73- .withTransactionId (transactionId )
74- .withMeterValue (Collections .singletonList (meterValue ));
89+ var meterValue = new MeterValue ();
90+ meterValue .setTimestamp (timestamp );
91+ meterValue .setValue (Integer .parseInt (value ));
92+
93+ var meterValuesRequest = new MeterValuesRequest ();
94+ meterValuesRequest .setConnectorId (connectorId );
95+ // OCPP 1.2 does not support transactionId in MeterValues
96+ // req.setTransactionId(transactionId);
97+ meterValuesRequest .getValues ().add (meterValue );
98+
7599 client .prepare (
76100 meterValuesRequest ,
77101 ocpp .cs ._2010 ._08 .MeterValuesResponse .class ,
@@ -89,7 +113,8 @@ public void heartbeat() {
89113 ocpp .cs ._2010 ._08 .HeartbeatResponse .class ,
90114 response -> {
91115 assertThat (response ).isNotNull ();
92- assertThat (response .getCurrentTime ()).isCloseTo (OffsetDateTime .now (), byLessThan (1 , ChronoUnit .SECONDS ));
116+ assertThat (response .getCurrentTime ())
117+ .isCloseTo (OffsetDateTime .now (), byLessThan (1 , ChronoUnit .SECONDS ));
93118 },
94119 error -> {
95120 throw new RuntimeException (error .toString ());
@@ -99,11 +124,13 @@ public void heartbeat() {
99124
100125 @ Override
101126 public void statusNotification (int connectorId , String status , String errorCode , OffsetDateTime timestamp ) {
102- var statusNotificationRequest = new StatusNotificationRequest ()
103- .withConnectorId (connectorId )
104- .withStatus (ChargePointStatus .fromValue (status ))
105- .withErrorCode (ChargePointErrorCode .fromValue (errorCode ))
106- .withTimestamp (timestamp );
127+ var statusNotificationRequest = new StatusNotificationRequest ();
128+ statusNotificationRequest .setConnectorId (connectorId );
129+ statusNotificationRequest .setStatus (ChargePointStatus .fromValue (status ));
130+ statusNotificationRequest .setErrorCode (ChargePointErrorCode .fromValue (errorCode ));
131+ // OCPP 1.2 does not support timestamp in StatusNotification
132+ // statusNotificationRequest.setTimestamp(timestamp);
133+
107134 client .prepare (
108135 statusNotificationRequest ,
109136 ocpp .cs ._2010 ._08 .StatusNotificationResponse .class ,
0 commit comments