|
4 | 4 | import java.net.URLEncoder; |
5 | 5 | import java.nio.charset.StandardCharsets; |
6 | 6 | import java.util.HashMap; |
| 7 | +import java.util.Objects; |
7 | 8 | import java.util.stream.Collectors; |
8 | 9 | import net.heberling.ismart.asn1.v2_1.entity.OTA_RVMVehicleStatusResp25857; |
9 | 10 | import net.heberling.ismart.asn1.v3_0.entity.OTA_ChrgMangDataResp; |
@@ -32,15 +33,30 @@ public static String updateAbrp( |
32 | 33 | HashMap<String, Object> map = new HashMap<>(); |
33 | 34 | // utc [s]: Current UTC timestamp (epoch) in seconds (note, not milliseconds!) |
34 | 35 | map.put("utc", vehicleStatus.getGpsPosition().getTimestamp4Short().getSeconds()); |
35 | | - // soc [SoC %]: State of Charge of the vehicle (what's displayed on the dashboard of |
36 | | - // the vehicle is preferred) |
37 | | - map.put("soc", chargeStatus.getBmsPackSOCDsp() / 10.d); |
38 | | - // power [kW]: Instantaneous power output/input to the vehicle. Power output is |
39 | | - // positive, power input is negative (charging) |
40 | | - double current = chargeStatus.getBmsPackCrnt() * 0.05d - 1000.0d; |
41 | | - double voltage = (double) chargeStatus.getBmsPackVol() * 0.25d; |
42 | | - double power = current * voltage / 1000d; |
43 | | - map.put("power", power); |
| 36 | + |
| 37 | + if (Objects.nonNull(chargeStatus)) { |
| 38 | + // soc [SoC %]: State of Charge of the vehicle (what's displayed on the dashboard of |
| 39 | + // the vehicle is preferred) |
| 40 | + map.put("soc", chargeStatus.getBmsPackSOCDsp() / 10.d); |
| 41 | + // power [kW]: Instantaneous power output/input to the vehicle. Power output is |
| 42 | + // positive, power input is negative (charging) |
| 43 | + |
| 44 | + // TODO: batt_temp [°C]: Battery temperature |
| 45 | + |
| 46 | + double voltage = (double) chargeStatus.getBmsPackVol() * 0.25d; |
| 47 | + // voltage [V]: Battery pack voltage |
| 48 | + map.put("voltage", voltage); |
| 49 | + |
| 50 | + double current = chargeStatus.getBmsPackCrnt() * 0.05d - 1000.0d; |
| 51 | + // current [A]: Battery pack current (similar to power: output is |
| 52 | + // positive, input (charging) is negative.) |
| 53 | + map.put("current", current); |
| 54 | + |
| 55 | + double power = current * voltage / 1000d; |
| 56 | + map.put("power", power); |
| 57 | + } else { |
| 58 | + map.put("soc", vehicleStatus.getBasicVehicleStatus().getExtendedData1()); |
| 59 | + } |
44 | 60 | // speed [km/h]: Vehicle speed |
45 | 61 | map.put("speed", vehicleStatus.getGpsPosition().getWayPoint().getSpeed() / 10.d); |
46 | 62 | // lat [°]: Current vehicle latitude |
@@ -80,12 +96,6 @@ public static String updateAbrp( |
80 | 96 | if (vehicleStatus.getBasicVehicleStatus().getExteriorTemperature() != -128) { |
81 | 97 | map.put("ext_temp", vehicleStatus.getBasicVehicleStatus().getExteriorTemperature()); |
82 | 98 | } |
83 | | - // TODO: batt_temp [°C]: Battery temperature |
84 | | - // voltage [V]: Battery pack voltage |
85 | | - map.put("voltage", voltage); |
86 | | - // current [A]: Battery pack current (similar to power: output is |
87 | | - // positive, input (charging) is negative.) |
88 | | - map.put("current", current); |
89 | 99 | // odometer [km]: Current odometer reading in km. |
90 | 100 | if (vehicleStatus.getBasicVehicleStatus().getMileage() > 0) { |
91 | 101 | map.put("odometer", vehicleStatus.getBasicVehicleStatus().getMileage() / 10.d); |
|
0 commit comments