Skip to content

Commit 5494bc0

Browse files
committed
added battery heater
1 parent 231ca3c commit 5494bc0

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

ASN.1 schema/v3_0/ApplicationData.asn1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ OTA_ChrgMangDataResp ::= SEQUENCE
6767
chargeStatus RvsChargingStatus(1),
6868
bmsAdpPubChrgSttnDspCmd INTEGER(0..255)
6969
}
70+
OTA_ChrgHeatReq ::= SEQUENCE
71+
{
72+
ptcHeatReq INTEGER(0..255)
73+
}
74+
OTA_ChrgHeatResp ::= SEQUENCE
75+
{
76+
ptcHeatReqDspCmd INTEGER(0..255),
77+
ptcHeatResp INTEGER(0..255),
78+
rvcReqSts OCTET STRING(SIZE(1))
79+
}
7080
RvsChargingStatus ::= SEQUENCE
7181
{
7282
realtimePower INTEGER(0..65535),

saic-java-mqtt-gateway/src/main/java/net/heberling/ismart/mqtt/MqttGatewayTopics.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MqttGatewayTopics {
2222
public static final String DRIVETRAIN_CHARGING_TYPE = DRIVETRAIN + "/chargingType";
2323
public static final String DRIVETRAIN_CURRENT = DRIVETRAIN + "/current";
2424
public static final String DRIVETRAIN_HV_BATTERY_ACTIVE = DRIVETRAIN + "/hvBatteryActive";
25+
public static final String DRIVETRAIN_HV_BATTERY_HEATING = DRIVETRAIN + "/hvBatteryHeating";
2526
public static final String DRIVETRAIN_MILEAGE = DRIVETRAIN + "/mileage";
2627
public static final String DRIVETRAIN_POWER = DRIVETRAIN + "/power";
2728
public static final String DRIVETRAIN_RANGE = DRIVETRAIN + "/range";

saic-java-mqtt-gateway/src/main/java/net/heberling/ismart/mqtt/VehicleHandler.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import net.heberling.ismart.asn1.v3_0.Message;
2727
import net.heberling.ismart.asn1.v3_0.entity.OTA_ChrgCtrlReq;
2828
import 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;
2931
import net.heberling.ismart.asn1.v3_0.entity.OTA_ChrgMangDataResp;
3032
import org.bn.coders.IASN1PreparedElement;
3133
import 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":

saic-java-mqtt-gateway/src/main/java/net/heberling/ismart/mqtt/VehicleState.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ public void handleChargeStatusMessage(
426426
msg.setRetained(true);
427427
client.publish(mqttVINPrefix + "/" + DRIVETRAIN_VOLTAGE, msg);
428428

429+
boolean batteryHeating =
430+
chargingStatusResponseMessage.getApplicationData().getBmsPTCHeatReqDspCmd() == 1;
431+
msg = new MqttMessage((String.valueOf(batteryHeating)).getBytes(StandardCharsets.UTF_8));
432+
msg.setQos(0);
433+
msg.setRetained(true);
434+
client.publish(mqttVINPrefix + "/" + DRIVETRAIN_HV_BATTERY_HEATING, msg);
435+
429436
double power = current * voltage / 1000d;
430437
msg = new MqttMessage((String.valueOf(power)).getBytes(StandardCharsets.UTF_8));
431438
msg.setQos(0);

0 commit comments

Comments
 (0)