Skip to content

Commit 5a79981

Browse files
committed
added battery heater
1 parent 2be8ba5 commit 5a79981

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
@@ -23,6 +23,8 @@
2323
import net.heberling.ismart.asn1.v3_0.Message;
2424
import net.heberling.ismart.asn1.v3_0.entity.OTA_ChrgCtrlReq;
2525
import 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;
2628
import net.heberling.ismart.asn1.v3_0.entity.OTA_ChrgMangDataResp;
2729
import org.bn.coders.IASN1PreparedElement;
2830
import 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":

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)