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 ;
@@ -416,6 +418,72 @@ private void sendCharging(boolean state)
416418 SaicMqttGateway .anonymized (otaRvcStatus25857MessageCoder , sendCommandReqestMessage )));
417419 }
418420
421+ private void sendChargeHeating (boolean state )
422+ throws URISyntaxException ,
423+ ExecutionException ,
424+ InterruptedException ,
425+ TimeoutException ,
426+ MqttException ,
427+ IOException {
428+ net .heberling .ismart .asn1 .v3_0 .MessageCoder <OTA_ChrgHeatReq > otaRvcReqMessageCoder =
429+ new net .heberling .ismart .asn1 .v3_0 .MessageCoder <>(OTA_ChrgHeatReq .class );
430+
431+ // we send a command end expect the car to wake up
432+ vehicleState .notifyCarActivityTime (ZonedDateTime .now (), false );
433+
434+ OTA_ChrgHeatReq req = new OTA_ChrgHeatReq ();
435+ req .setPtcHeatReq (state ? 1 : 2 );
436+
437+ Message <OTA_ChrgHeatReq > sendCommandRequest =
438+ otaRvcReqMessageCoder .initializeMessage (uid , token , vinInfo .getVin (), "516" , 768 , 9 , req );
439+
440+ String sendCommandRequestMessage = otaRvcReqMessageCoder .encodeRequest (sendCommandRequest );
441+
442+ String sendCommandResponseMessage =
443+ Client .sendRequest (saicUri .resolve ("/TAP.Web/ota.mpv30" ), sendCommandRequestMessage );
444+
445+ final net .heberling .ismart .asn1 .v3_0 .MessageCoder <OTA_ChrgHeatResp >
446+ otaRvcStatus25857MessageCoder =
447+ new net .heberling .ismart .asn1 .v3_0 .MessageCoder <>(OTA_ChrgHeatResp .class );
448+ net .heberling .ismart .asn1 .v3_0 .Message <OTA_ChrgHeatResp > sendCommandReqestMessage =
449+ otaRvcStatus25857MessageCoder .decodeResponse (sendCommandResponseMessage );
450+
451+ // ... use that to request the data again, until we have it
452+ // TODO: check for real errors (result!=0 and/or errorMessagePresent)
453+ while (sendCommandReqestMessage .getApplicationData () == null ) {
454+ if (sendCommandReqestMessage .getBody ().isErrorMessagePresent ()) {
455+ if (sendCommandReqestMessage .getBody ().getResult () == 2 ) {
456+ // TODO:
457+ // getBridgeHandler().relogin();
458+ }
459+ throw new TimeoutException (
460+ new String (sendCommandReqestMessage .getBody ().getErrorMessage ()));
461+ }
462+ SaicMqttGateway .fillReserved (sendCommandRequest .getReserved ());
463+
464+ if (sendCommandReqestMessage .getBody ().getResult () == 0 ) {
465+ // we get an eventId back...
466+ sendCommandRequest .getBody ().setEventID (sendCommandReqestMessage .getBody ().getEventID ());
467+ } else {
468+ // try a fresh eventId
469+ sendCommandRequest .getBody ().setEventID (0 );
470+ }
471+
472+ sendCommandRequestMessage = otaRvcReqMessageCoder .encodeRequest (sendCommandRequest );
473+
474+ sendCommandResponseMessage =
475+ Client .sendRequest (saicUri .resolve ("/TAP.Web/ota.mpv30" ), sendCommandRequestMessage );
476+
477+ sendCommandReqestMessage =
478+ otaRvcStatus25857MessageCoder .decodeResponse (sendCommandResponseMessage );
479+ }
480+
481+ LOGGER .debug (
482+ "Got SendCommand Response message: {}" ,
483+ SaicMqttGateway .toJSON (
484+ SaicMqttGateway .anonymized (otaRvcStatus25857MessageCoder , sendCommandReqestMessage )));
485+ }
486+
419487 public void handleMQTTCommand (String topic , MqttMessage message ) throws MqttException {
420488 try {
421489 if (message .isRetained ()) {
@@ -434,6 +502,18 @@ public void handleMQTTCommand(String topic, MqttMessage message) throws MqttExce
434502 throw new MqttGatewayException ("Unsupported payload " + message );
435503 }
436504 break ;
505+ case DRIVETRAIN_HV_BATTERY_HEATING :
506+ switch (message .toString ().toLowerCase ()) {
507+ case "true" :
508+ sendChargeHeating (true );
509+ break ;
510+ case "false" :
511+ sendChargeHeating (false );
512+ break ;
513+ default :
514+ throw new MqttGatewayException ("Unsupported payload " + message );
515+ }
516+ break ;
437517 case DRIVETRAIN_CHARGING :
438518 switch (message .toString ().toLowerCase ()) {
439519 case "true" :
0 commit comments