2626import net .heberling .ismart .asn1 .v3_0 .Message ;
2727import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgCtrlReq ;
2828import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgCtrlStsResp ;
29+ import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgHeatReq ;
30+ import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgHeatResp ;
2931import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgMangDataResp ;
3032import org .bn .coders .IASN1PreparedElement ;
3133import org .eclipse .paho .client .mqttv3 .IMqttClient ;
@@ -419,6 +421,72 @@ private void sendCharging(boolean state)
419421 SaicMqttGateway .anonymized (otaRvcStatus25857MessageCoder , sendCommandReqestMessage )));
420422 }
421423
424+ private void sendChargeHeating (boolean state )
425+ throws URISyntaxException ,
426+ ExecutionException ,
427+ InterruptedException ,
428+ TimeoutException ,
429+ MqttException ,
430+ IOException {
431+ net .heberling .ismart .asn1 .v3_0 .MessageCoder <OTA_ChrgHeatReq > otaRvcReqMessageCoder =
432+ new net .heberling .ismart .asn1 .v3_0 .MessageCoder <>(OTA_ChrgHeatReq .class );
433+
434+ // we send a command end expect the car to wake up
435+ vehicleState .notifyCarActivityTime (ZonedDateTime .now (), false );
436+
437+ OTA_ChrgHeatReq req = new OTA_ChrgHeatReq ();
438+ req .setPtcHeatReq (state ? 1 : 2 );
439+
440+ Message <OTA_ChrgHeatReq > sendCommandRequest =
441+ otaRvcReqMessageCoder .initializeMessage (uid , token , vinInfo .getVin (), "516" , 768 , 9 , req );
442+
443+ String sendCommandRequestMessage = otaRvcReqMessageCoder .encodeRequest (sendCommandRequest );
444+
445+ String sendCommandResponseMessage =
446+ Client .sendRequest (saicUri .resolve ("/TAP.Web/ota.mpv30" ), sendCommandRequestMessage );
447+
448+ final net .heberling .ismart .asn1 .v3_0 .MessageCoder <OTA_ChrgHeatResp >
449+ otaRvcStatus25857MessageCoder =
450+ new net .heberling .ismart .asn1 .v3_0 .MessageCoder <>(OTA_ChrgHeatResp .class );
451+ net .heberling .ismart .asn1 .v3_0 .Message <OTA_ChrgHeatResp > sendCommandReqestMessage =
452+ otaRvcStatus25857MessageCoder .decodeResponse (sendCommandResponseMessage );
453+
454+ // ... use that to request the data again, until we have it
455+ // TODO: check for real errors (result!=0 and/or errorMessagePresent)
456+ while (sendCommandReqestMessage .getApplicationData () == null ) {
457+ if (sendCommandReqestMessage .getBody ().isErrorMessagePresent ()) {
458+ if (sendCommandReqestMessage .getBody ().getResult () == 2 ) {
459+ // TODO:
460+ // getBridgeHandler().relogin();
461+ }
462+ throw new TimeoutException (
463+ new String (sendCommandReqestMessage .getBody ().getErrorMessage ()));
464+ }
465+ SaicMqttGateway .fillReserved (sendCommandRequest .getReserved ());
466+
467+ if (sendCommandReqestMessage .getBody ().getResult () == 0 ) {
468+ // we get an eventId back...
469+ sendCommandRequest .getBody ().setEventID (sendCommandReqestMessage .getBody ().getEventID ());
470+ } else {
471+ // try a fresh eventId
472+ sendCommandRequest .getBody ().setEventID (0 );
473+ }
474+
475+ sendCommandRequestMessage = otaRvcReqMessageCoder .encodeRequest (sendCommandRequest );
476+
477+ sendCommandResponseMessage =
478+ Client .sendRequest (saicUri .resolve ("/TAP.Web/ota.mpv30" ), sendCommandRequestMessage );
479+
480+ sendCommandReqestMessage =
481+ otaRvcStatus25857MessageCoder .decodeResponse (sendCommandResponseMessage );
482+ }
483+
484+ LOGGER .debug (
485+ "Got SendCommand Response message: {}" ,
486+ SaicMqttGateway .toJSON (
487+ SaicMqttGateway .anonymized (otaRvcStatus25857MessageCoder , sendCommandReqestMessage )));
488+ }
489+
422490 public void handleMQTTCommand (String topic , MqttMessage message ) throws MqttException {
423491 try {
424492 if (message .isRetained ()) {
@@ -437,6 +505,18 @@ public void handleMQTTCommand(String topic, MqttMessage message) throws MqttExce
437505 throw new MqttGatewayException ("Unsupported payload " + message );
438506 }
439507 break ;
508+ case DRIVETRAIN_HV_BATTERY_HEATING :
509+ switch (message .toString ().toLowerCase ()) {
510+ case "true" :
511+ sendChargeHeating (true );
512+ break ;
513+ case "false" :
514+ sendChargeHeating (false );
515+ break ;
516+ default :
517+ throw new MqttGatewayException ("Unsupported payload " + message );
518+ }
519+ break ;
440520 case DRIVETRAIN_CHARGING :
441521 switch (message .toString ().toLowerCase ()) {
442522 case "true" :
0 commit comments