11package de .rwth .idsg .steve .ocpp .converter ;
22
3+ import ocpp .cs ._2012 ._06 .AuthorizationStatus ;
34import ocpp .cs ._2012 ._06 .AuthorizeResponse ;
45import ocpp .cs ._2012 ._06 .BootNotificationResponse ;
56import ocpp .cs ._2012 ._06 .DataTransferResponse ;
7+ import ocpp .cs ._2012 ._06 .DataTransferStatus ;
68import ocpp .cs ._2012 ._06 .DiagnosticsStatusNotificationResponse ;
79import ocpp .cs ._2012 ._06 .FirmwareStatusNotificationResponse ;
810import ocpp .cs ._2012 ._06 .HeartbeatResponse ;
11+ import ocpp .cs ._2012 ._06 .IdTagInfo ;
912import ocpp .cs ._2012 ._06 .MeterValuesResponse ;
13+ import ocpp .cs ._2012 ._06 .RegistrationStatus ;
1014import ocpp .cs ._2012 ._06 .StartTransactionResponse ;
1115import ocpp .cs ._2012 ._06 .StatusNotificationResponse ;
1216import ocpp .cs ._2012 ._06 .StopTransactionResponse ;
1317import ocpp .cs ._2015 ._10 .AuthorizeRequest ;
1418import ocpp .cs ._2015 ._10 .BootNotificationRequest ;
19+ import ocpp .cs ._2015 ._10 .ChargePointErrorCode ;
20+ import ocpp .cs ._2015 ._10 .ChargePointStatus ;
1521import ocpp .cs ._2015 ._10 .DataTransferRequest ;
22+ import ocpp .cs ._2015 ._10 .DiagnosticsStatus ;
1623import ocpp .cs ._2015 ._10 .DiagnosticsStatusNotificationRequest ;
24+ import ocpp .cs ._2015 ._10 .FirmwareStatus ;
1725import ocpp .cs ._2015 ._10 .FirmwareStatusNotificationRequest ;
1826import ocpp .cs ._2015 ._10 .HeartbeatRequest ;
27+ import ocpp .cs ._2015 ._10 .Location ;
28+ import ocpp .cs ._2015 ._10 .Measurand ;
29+ import ocpp .cs ._2015 ._10 .MeterValue ;
1930import ocpp .cs ._2015 ._10 .MeterValuesRequest ;
31+ import ocpp .cs ._2015 ._10 .ReadingContext ;
32+ import ocpp .cs ._2015 ._10 .SampledValue ;
2033import ocpp .cs ._2015 ._10 .StartTransactionRequest ;
2134import ocpp .cs ._2015 ._10 .StatusNotificationRequest ;
2235import ocpp .cs ._2015 ._10 .StopTransactionRequest ;
36+ import ocpp .cs ._2015 ._10 .UnitOfMeasure ;
37+ import ocpp .cs ._2015 ._10 .ValueFormat ;
38+
39+ import java .util .List ;
40+ import java .util .stream .Collectors ;
2341
2442/**
2543 * @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
@@ -34,54 +52,116 @@ public enum Server15to16Impl implements Server15to16 {
3452
3553 @ Override
3654 public BootNotificationRequest convertRequest (ocpp .cs ._2012 ._06 .BootNotificationRequest request ) {
37- return null ;
55+ return new BootNotificationRequest ()
56+ .withChargePointVendor (request .getChargePointVendor ())
57+ .withChargePointModel (request .getChargePointModel ())
58+ .withChargePointSerialNumber (request .getChargePointSerialNumber ())
59+ .withChargeBoxSerialNumber (request .getChargeBoxSerialNumber ())
60+ .withFirmwareVersion (request .getFirmwareVersion ())
61+ .withIccid (request .getIccid ())
62+ .withImsi (request .getImsi ())
63+ .withMeterType (request .getMeterType ())
64+ .withMeterSerialNumber (request .getMeterSerialNumber ());
3865 }
3966
4067 @ Override
41- public FirmwareStatusNotificationRequest convertRequest (
42- ocpp . cs . _2012 . _06 . FirmwareStatusNotificationRequest request ) {
43- return null ;
68+ public FirmwareStatusNotificationRequest convertRequest (ocpp . cs . _2012 . _06 . FirmwareStatusNotificationRequest request ) {
69+ return new FirmwareStatusNotificationRequest ()
70+ . withStatus ( FirmwareStatus . fromValue ( request . getStatus (). value ())) ;
4471 }
4572
4673 @ Override
4774 public StatusNotificationRequest convertRequest (ocpp .cs ._2012 ._06 .StatusNotificationRequest request ) {
48- return null ;
49- }
75+ ChargePointStatus status = ChargePointStatus .fromValue (request .getStatus ().value ());
5076
51- @ Override
52- public MeterValuesRequest convertRequest (ocpp .cs ._2012 ._06 .MeterValuesRequest request ) {
53- return null ;
77+ ChargePointErrorCode errorCode16 ;
78+ ocpp .cs ._2012 ._06 .ChargePointErrorCode errorCode15 = request .getErrorCode ();
79+
80+
81+ // Mapping required: Enum values in both directions don't necessarily match.
82+ // TODO: Make sure that no information is lost (by e.g. creating InsertConnectorStatusParams earlier in the pipeline)
83+ if (errorCode15 .equals (ocpp .cs ._2012 ._06 .ChargePointErrorCode .MODE_3_ERROR )) {
84+ errorCode16 = ChargePointErrorCode .OTHER_ERROR ;
85+ } else {
86+ errorCode16 = ChargePointErrorCode .fromValue (request .getErrorCode ().value ());
87+ }
88+
89+ return new StatusNotificationRequest ()
90+ .withConnectorId (request .getConnectorId ())
91+ .withStatus (status )
92+ .withErrorCode (errorCode16 );
5493 }
5594
5695 @ Override
57- public DiagnosticsStatusNotificationRequest convertRequest (
58- ocpp .cs ._2012 ._06 .DiagnosticsStatusNotificationRequest request ) {
59- return null ;
96+ public MeterValuesRequest convertRequest (ocpp .cs ._2012 ._06 .MeterValuesRequest request ) {
97+ //nested lists, therefore not that readable
98+ List <MeterValue > values16 = request .getValues ()
99+ .stream ()
100+ .map (e -> new MeterValue ()
101+ .withTimestamp (e .getTimestamp ())
102+ .withSampledValue (e .getValue ().stream ()
103+ .map (f -> new SampledValue ()
104+ .withContext (ReadingContext .fromValue (f .getContext ().value ()))
105+ .withFormat (ValueFormat .fromValue (f .getFormat ().value ()))
106+ .withLocation (Location .fromValue (f .getLocation ().value ()))
107+ .withMeasurand (Measurand .fromValue (f .getMeasurand ().value ()))
108+ .withUnit (UnitOfMeasure .fromValue (f .getUnit ().value ()))
109+ .withValue (f .getValue ())
110+ )
111+ .collect (Collectors .toList ())
112+ )
113+ )
114+ .collect (Collectors .toList ());
115+
116+ return new MeterValuesRequest ()
117+ .withTransactionId (request .getTransactionId ())
118+ .withConnectorId (request .getConnectorId ())
119+ .withMeterValue (values16 );
120+ }
121+
122+ @ Override
123+ public DiagnosticsStatusNotificationRequest convertRequest (ocpp .cs ._2012 ._06 .DiagnosticsStatusNotificationRequest request ) {
124+ DiagnosticsStatus status = DiagnosticsStatus .fromValue (request .getStatus ().value ());
125+ return new DiagnosticsStatusNotificationRequest ()
126+ .withStatus (status );
60127 }
61128
62129 @ Override
63130 public StartTransactionRequest convertRequest (ocpp .cs ._2012 ._06 .StartTransactionRequest request ) {
64- return null ;
131+ return new StartTransactionRequest ()
132+ .withConnectorId (request .getConnectorId ())
133+ .withIdTag (request .getIdTag ())
134+ .withMeterStart (request .getMeterStart ())
135+ .withTimestamp (request .getTimestamp ());
65136 }
66137
67138 @ Override
68139 public StopTransactionRequest convertRequest (ocpp .cs ._2012 ._06 .StopTransactionRequest request ) {
69- return null ;
140+ return new StopTransactionRequest ()
141+ .withIdTag (request .getIdTag ())
142+ // .withReason(Reason.OTHER) // Reason was introduced with 1.6 and is optional (no mapping needed)
143+ .withMeterStop (request .getMeterStop ())
144+ .withTimestamp (request .getTimestamp ())
145+ .withTransactionId (request .getTransactionId ());
70146 }
71147
72148 @ Override
73149 public HeartbeatRequest convertRequest (ocpp .cs ._2012 ._06 .HeartbeatRequest request ) {
74- return null ;
150+ return new HeartbeatRequest () ;
75151 }
76152
77153 @ Override
78154 public AuthorizeRequest convertRequest (ocpp .cs ._2012 ._06 .AuthorizeRequest request ) {
79- return null ;
155+ return new AuthorizeRequest ()
156+ .withIdTag (request .getIdTag ());
80157 }
81158
82159 @ Override
83160 public DataTransferRequest convertRequest (ocpp .cs ._2012 ._06 .DataTransferRequest request ) {
84- return null ;
161+ return new DataTransferRequest ()
162+ .withVendorId (request .getVendorId ())
163+ .withMessageId (request .getMessageId ())
164+ .withData (request .getData ());
85165 }
86166
87167 // -------------------------------------------------------------------------
@@ -90,53 +170,74 @@ public DataTransferRequest convertRequest(ocpp.cs._2012._06.DataTransferRequest
90170
91171 @ Override
92172 public BootNotificationResponse convertResponse (ocpp .cs ._2015 ._10 .BootNotificationResponse response ) {
93- return null ;
173+ return new BootNotificationResponse ()
174+ .withCurrentTime (response .getCurrentTime ())
175+ .withHeartbeatInterval (response .getInterval ())
176+ .withStatus (RegistrationStatus .fromValue (response .getStatus ().value ()));
94177 }
95178
96179 @ Override
97180 public FirmwareStatusNotificationResponse convertResponse (
98181 ocpp .cs ._2015 ._10 .FirmwareStatusNotificationResponse response ) {
99- return null ;
182+ return new FirmwareStatusNotificationResponse () ;
100183 }
101184
102185 @ Override
103186 public StatusNotificationResponse convertResponse (ocpp .cs ._2015 ._10 .StatusNotificationResponse response ) {
104- return null ;
187+ return new StatusNotificationResponse () ;
105188 }
106189
107190 @ Override
108191 public MeterValuesResponse convertResponse (ocpp .cs ._2015 ._10 .MeterValuesResponse response ) {
109- return null ;
192+ return new MeterValuesResponse () ;
110193 }
111194
112195 @ Override
113- public DiagnosticsStatusNotificationResponse convertResponse (
114- ocpp .cs ._2015 ._10 .DiagnosticsStatusNotificationResponse response ) {
115- return null ;
196+ public DiagnosticsStatusNotificationResponse convertResponse (ocpp .cs ._2015 ._10 .DiagnosticsStatusNotificationResponse response ) {
197+ return new DiagnosticsStatusNotificationResponse ();
116198 }
117199
118200 @ Override
119201 public StartTransactionResponse convertResponse (ocpp .cs ._2015 ._10 .StartTransactionResponse response ) {
120- return null ;
202+ return new StartTransactionResponse ()
203+ .withIdTagInfo (convertIdTagInfo16to15 (response .getIdTagInfo ()))
204+ .withTransactionId (response .getTransactionId ());
121205 }
122206
123207 @ Override
124208 public StopTransactionResponse convertResponse (ocpp .cs ._2015 ._10 .StopTransactionResponse response ) {
125- return null ;
209+ return new StopTransactionResponse ()
210+ .withIdTagInfo (convertIdTagInfo16to15 (response .getIdTagInfo ()));
126211 }
127212
128213 @ Override
129214 public HeartbeatResponse convertResponse (ocpp .cs ._2015 ._10 .HeartbeatResponse response ) {
130- return null ;
215+ return new HeartbeatResponse ()
216+ .withCurrentTime (response .getCurrentTime ());
131217 }
132218
133219 @ Override
134220 public AuthorizeResponse convertResponse (ocpp .cs ._2015 ._10 .AuthorizeResponse response ) {
135- return null ;
221+ return new AuthorizeResponse ()
222+ .withIdTagInfo (convertIdTagInfo16to15 (response .getIdTagInfo ()));
136223 }
137224
138225 @ Override
139226 public DataTransferResponse convertResponse (ocpp .cs ._2015 ._10 .DataTransferResponse response ) {
140- return null ;
227+ return new DataTransferResponse ()
228+ .withStatus (DataTransferStatus .fromValue (response .getStatus ().value ()))
229+ .withData (response .getData ());
141230 }
231+
232+ // -------------------------------------------------------------------------
233+ // Helpers
234+ // -------------------------------------------------------------------------
235+
236+ private static IdTagInfo convertIdTagInfo16to15 (ocpp .cs ._2015 ._10 .IdTagInfo info16 ) {
237+ return new IdTagInfo ()
238+ .withExpiryDate (info16 .getExpiryDate ())
239+ .withParentIdTag (info16 .getParentIdTag ())
240+ .withStatus (AuthorizationStatus .fromValue (info16 .getStatus ().value ()));
241+ }
242+
142243}
0 commit comments