Skip to content

Commit e9d2b56

Browse files
committed
config: add support for specifying ev_connector_types
1 parent 05a74f6 commit e9d2b56

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

contrib/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,12 @@
9898
# Path to script executed when Android Auto session starts/stops and EV battery data is needed
9999
# Argument "start" or "stop" is appended automatically when invoked
100100
ev_battery_logger = ""
101+
102+
# List of EV connector types supported by your car.
103+
# Possible values (separate multiple with a comma ','):
104+
# EV_CONNECTOR_TYPE_J1772, EV_CONNECTOR_TYPE_MENNEKES, EV_CONNECTOR_TYPE_CHADEMO,
105+
# EV_CONNECTOR_TYPE_COMBO_1, EV_CONNECTOR_TYPE_COMBO_2, EV_CONNECTOR_TYPE_TESLA_SUPERCHARGER,
106+
# EV_CONNECTOR_TYPE_GBT
107+
#
108+
# If left empty, the default is EV_CONNECTOR_TYPE_MENNEKES.
109+
ev_connector_types = ""

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub struct AppConfig {
141141
pub ev: bool,
142142
#[serde(default, deserialize_with = "empty_string_as_none")]
143143
pub ev_battery_logger: Option<PathBuf>,
144+
#[serde(default, deserialize_with = "empty_string_as_none")]
145+
pub ev_connector_types: Option<String>,
144146

145147
#[serde(skip)]
146148
pub restart_requested: bool,
@@ -178,6 +180,7 @@ impl Default for AppConfig {
178180
ev: false,
179181
ev_battery_logger: None,
180182
restart_requested: false,
183+
ev_connector_types: None,
181184
}
182185
}
183186
}
@@ -273,6 +276,9 @@ impl AppConfig {
273276
if let Some(path) = &self.ev_battery_logger {
274277
doc["ev_battery_logger"] = value(path.display().to_string());
275278
}
279+
if let Some(ev_connector_types) = &self.ev_connector_types {
280+
doc["ev_connector_types"] = value(ev_connector_types);
281+
}
276282

277283
let _ = remount_root(false);
278284
info!(

src/mitm.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::mitm::AudioStreamType::*;
2424
use crate::mitm::SensorMessageId::*;
2525
use crate::mitm::SensorType::*;
2626
use protobuf::text_format::print_to_string_pretty;
27-
use protobuf::{Enum, Message, MessageDyn};
27+
use protobuf::{Enum, EnumOrUnknown, Message, MessageDyn};
2828
use protos::ControlMessageType::{self, *};
2929

3030
use crate::config::AppConfig;
@@ -272,6 +272,7 @@ pub async fn pkt_modify_hook(
272272
ctx: &mut ModifyContext,
273273
sensor_channel: Arc<tokio::sync::Mutex<Option<u8>>>,
274274
ev_battery_logger: Option<PathBuf>,
275+
connector_types: Option<String>,
275276
) -> Result<bool> {
276277
// if for some reason we have too small packet, bail out
277278
if pkt.payload.len() < 2 {
@@ -466,12 +467,20 @@ pub async fn pkt_modify_hook(
466467
.supported_fuel_types = vec![FuelType::FUEL_TYPE_ELECTRIC.into()];
467468

468469
// supported connector types
469-
// FIXME: make this connectors configurable via config
470+
let connectors: Vec<EnumOrUnknown<EvConnectorType>> = match connector_types {
471+
Some(types) => types
472+
.split(',')
473+
.filter_map(|s| EvConnectorType::from_str(s.trim()))
474+
.map(EnumOrUnknown::new)
475+
.collect(),
476+
None => {
477+
vec![EvConnectorType::EV_CONNECTOR_TYPE_MENNEKES.into()]
478+
}
479+
};
470480
svc.sensor_source_service
471481
.as_mut()
472482
.unwrap()
473-
.supported_ev_connector_types =
474-
vec![EvConnectorType::EV_CONNECTOR_TYPE_MENNEKES.into()];
483+
.supported_ev_connector_types = connectors;
475484
}
476485
}
477486

@@ -797,6 +806,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
797806
&mut ctx,
798807
sensor_channel.clone(),
799808
config.ev_battery_logger.clone(),
809+
config.ev_connector_types.clone(),
800810
)
801811
.await?;
802812
let _ = pkt_debug(
@@ -842,6 +852,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
842852
&mut ctx,
843853
sensor_channel.clone(),
844854
config.ev_battery_logger.clone(),
855+
config.ev_connector_types.clone(),
845856
)
846857
.await?;
847858
let _ = pkt_debug(

static/index.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ <h3>🛸 aa-proxy-rs</h3>
4242
<small
4343
>Log file path, by default it is saved to <code>/var/log</code> in
4444
<code>tmpfs</code>/memory. If you want, you can change it e.g. to
45-
<code>/data/aa-proxy-rs.log</code> and it will be saved to SD
46-
card (appended, not replaced).</small
45+
<code>/data/aa-proxy-rs.log</code> and it will be saved to SD card
46+
(appended, not replaced).</small
4747
>
4848
</td>
4949
</tr>
@@ -294,6 +294,21 @@ <h3>🛸 aa-proxy-rs</h3>
294294
>
295295
</td>
296296
</tr>
297+
<tr>
298+
<td><label for="ev_connector_types">ev_connector_types</label></td>
299+
<td>
300+
<input type="text" id="ev_connector_types" /><br /><small>
301+
List of EV connector types supported by your car. Possible values
302+
(separate multiple with a comma ','):<br />
303+
EV_CONNECTOR_TYPE_J1772, EV_CONNECTOR_TYPE_MENNEKES,
304+
EV_CONNECTOR_TYPE_CHADEMO, EV_CONNECTOR_TYPE_COMBO_1,
305+
EV_CONNECTOR_TYPE_COMBO_2, EV_CONNECTOR_TYPE_TESLA_SUPERCHARGER,
306+
EV_CONNECTOR_TYPE_GBT<br />
307+
308+
If left empty, the default is EV_CONNECTOR_TYPE_MENNEKES.
309+
</small>
310+
</td>
311+
</tr>
297312
</table>
298313
</form>
299314

@@ -384,6 +399,7 @@ <h3>🛸 aa-proxy-rs</h3>
384399
"dhu",
385400
"ev",
386401
"ev_battery_logger",
402+
"ev_connector_types",
387403
];
388404
ids.forEach((id) => (config[id] = getValue(id)));
389405
await fetch("/config", {

0 commit comments

Comments
 (0)