Skip to content

Commit 7240097

Browse files
committed
added battery heater
1 parent f36ae48 commit 7240097

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;
@@ -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":

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
@@ -425,6 +425,13 @@ public void handleChargeStatusMessage(
425425
msg.setRetained(true);
426426
client.publish(mqttVINPrefix + "/" + DRIVETRAIN_VOLTAGE, msg);
427427

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

0 commit comments

Comments
 (0)