2323import net .heberling .ismart .asn1 .v3_0 .Message ;
2424import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgCtrlReq ;
2525import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgCtrlStsResp ;
26+ import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgHeatReq ;
27+ import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgHeatResp ;
2628import net .heberling .ismart .asn1 .v3_0 .entity .OTA_ChrgMangDataResp ;
2729import org .bn .coders .IASN1PreparedElement ;
2830import org .eclipse .paho .client .mqttv3 .IMqttClient ;
@@ -431,6 +433,72 @@ private void sendCharging(boolean state)
431433 SaicMqttGateway .anonymized (otaRvcStatus25857MessageCoder , sendCommandReqestMessage )));
432434 }
433435
436+ private void sendChargeHeating (boolean state )
437+ throws URISyntaxException ,
438+ ExecutionException ,
439+ InterruptedException ,
440+ TimeoutException ,
441+ MqttException ,
442+ IOException {
443+ net .heberling .ismart .asn1 .v3_0 .MessageCoder <OTA_ChrgHeatReq > otaRvcReqMessageCoder =
444+ new net .heberling .ismart .asn1 .v3_0 .MessageCoder <>(OTA_ChrgHeatReq .class );
445+
446+ // we send a command end expect the car to wake up
447+ vehicleState .notifyCarActivityTime (OffsetDateTime .now (), false );
448+
449+ OTA_ChrgHeatReq req = new OTA_ChrgHeatReq ();
450+ req .setPtcHeatReq (state ? 1 : 2 );
451+
452+ Message <OTA_ChrgHeatReq > sendCommandRequest =
453+ otaRvcReqMessageCoder .initializeMessage (uid , token , vinInfo .getVin (), "516" , 768 , 9 , req );
454+
455+ String sendCommandRequestMessage = otaRvcReqMessageCoder .encodeRequest (sendCommandRequest );
456+
457+ String sendCommandResponseMessage =
458+ Client .sendRequest (saicUri .resolve ("/TAP.Web/ota.mpv30" ), sendCommandRequestMessage );
459+
460+ final net .heberling .ismart .asn1 .v3_0 .MessageCoder <OTA_ChrgHeatResp >
461+ otaRvcStatus25857MessageCoder =
462+ new net .heberling .ismart .asn1 .v3_0 .MessageCoder <>(OTA_ChrgHeatResp .class );
463+ net .heberling .ismart .asn1 .v3_0 .Message <OTA_ChrgHeatResp > sendCommandReqestMessage =
464+ otaRvcStatus25857MessageCoder .decodeResponse (sendCommandResponseMessage );
465+
466+ // ... use that to request the data again, until we have it
467+ // TODO: check for real errors (result!=0 and/or errorMessagePresent)
468+ while (sendCommandReqestMessage .getApplicationData () == null ) {
469+ if (sendCommandReqestMessage .getBody ().isErrorMessagePresent ()) {
470+ if (sendCommandReqestMessage .getBody ().getResult () == 2 ) {
471+ // TODO:
472+ // getBridgeHandler().relogin();
473+ }
474+ throw new TimeoutException (
475+ new String (sendCommandReqestMessage .getBody ().getErrorMessage ()));
476+ }
477+ SaicMqttGateway .fillReserved (sendCommandRequest .getReserved ());
478+
479+ if (sendCommandReqestMessage .getBody ().getResult () == 0 ) {
480+ // we get an eventId back...
481+ sendCommandRequest .getBody ().setEventID (sendCommandReqestMessage .getBody ().getEventID ());
482+ } else {
483+ // try a fresh eventId
484+ sendCommandRequest .getBody ().setEventID (0 );
485+ }
486+
487+ sendCommandRequestMessage = otaRvcReqMessageCoder .encodeRequest (sendCommandRequest );
488+
489+ sendCommandResponseMessage =
490+ Client .sendRequest (saicUri .resolve ("/TAP.Web/ota.mpv30" ), sendCommandRequestMessage );
491+
492+ sendCommandReqestMessage =
493+ otaRvcStatus25857MessageCoder .decodeResponse (sendCommandResponseMessage );
494+ }
495+
496+ LOGGER .debug (
497+ "Got SendCommand Response message: {}" ,
498+ SaicMqttGateway .toJSON (
499+ SaicMqttGateway .anonymized (otaRvcStatus25857MessageCoder , sendCommandReqestMessage )));
500+ }
501+
434502 public void handleMQTTCommand (String topic , MqttMessage message ) throws MqttException {
435503 try {
436504 if (message .isRetained ()) {
@@ -449,6 +517,18 @@ public void handleMQTTCommand(String topic, MqttMessage message) throws MqttExce
449517 throw new MqttGatewayException ("Unsupported payload " + message );
450518 }
451519 break ;
520+ case DRIVETRAIN_HV_BATTERY_HEATING :
521+ switch (message .toString ().toLowerCase ()) {
522+ case "true" :
523+ sendChargeHeating (true );
524+ break ;
525+ case "false" :
526+ sendChargeHeating (false );
527+ break ;
528+ default :
529+ throw new MqttGatewayException ("Unsupported payload " + message );
530+ }
531+ break ;
452532 case DRIVETRAIN_CHARGING :
453533 switch (message .toString ().toLowerCase ()) {
454534 case "true" :
0 commit comments