Skip to content

Commit

Permalink
Merge pull request #857 from frogonwheels/add-metric-obd2ecu-on
Browse files Browse the repository at this point in the history
Add metric+events for obd2ecu on/off
  • Loading branch information
dexterbg committed Mar 14, 2023
2 parents d1994ca + 6fe39bf commit 324acc1
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/source/userguide/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ network.wifi.sta.bad WIFI client has bad signal level
network.wifi.sta.good WIFI client has good signal level
network.wifi.up WIFI network is up
notify.<type>.<subtype> An info / alert / error notification is sent
obd2ecu.start Called after the OBD2ECU process is started.
obd2ecu.stop Called before the OBD2ECU process is stopped.
retools.cleared.all RE frame log has been cleared
retools.cleared.changed RE frame change flags cleared
retools.cleared.discovered RE frame discovery flags cleared
Expand Down
1 change: 1 addition & 0 deletions docs/source/userguide/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ m.net.sq -79dBm …signal qual
m.net.type wifi …and type (none/modem/wifi)
m.net.wifi.network WLAN-214677 Current Wifi network SSID
m.net.wifi.sq -79.1dBm …and signal quality
m.obdc2ecu.on no Is the OBD2ECU process currently on.
m.serial Reserved for module serial no.
m.tasks 20 Task count (use ``module tasks`` to list)
m.time.utc 1572590910Sec UTC time in seconds
Expand Down
8 changes: 7 additions & 1 deletion vehicle/OVMS.V3/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ Open Vehicle Monitor System v3 - Change log
New metrics:
xrt.b.energy.avail -- Current battery energy available [kWh] (aged)
xrt.b.energy.full -- Maximum battery energy capacity [kWh] (aged, needs full charge)
- Add button on web file editor to reload ECU (when ECU is enabled).
- Add button on web file editor to reload obd2ECU (when obd2ECU is enabled).
- Vehicle: add support for a geofence for valet mode similar to parking/flatbed warnings.
New Configs:
[vehicle] valet.alarmdistance -- How far away from the original position before raising an alert (in metres)
[vehicle] valet.alarminterval -- How often the alarm can be raised in minumtes
- Add metric and events related to obd2ecu process:
New metric:
m.obdc2ecu.on -- Is the OBD2ECU process currently on.
New events:
obd2ecu.start -- Called after the OBD2ECU process is started.
obd2ecu.stop -- Called before the OBD2ECU process is stopped.

2022-09-01 MWJ 3.3.003 OTA release
- Toyota RAV4 EV: Initial support added. Only the Tesla bus is decoded and just listening so far.
Expand Down
14 changes: 14 additions & 0 deletions vehicle/OVMS.V3/components/obd2ecu/src/obd2ecu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ obd2ecu::obd2ecu(const char* name, canbus* can)
xTaskCreatePinnedToCore(OBD2ECU_task, "OVMS OBDII ECU", 6144, (void*)this, 5, &m_task, CORE(1));

MyCan.RegisterListener(m_rxqueue);
NotifyStartup();
}

obd2ecu::~obd2ecu()
{
NotifyShutdown();
m_can->SetPowerMode(Off);
MyCan.DeregisterListener(m_rxqueue);

Expand All @@ -186,6 +188,18 @@ obd2ecu::~obd2ecu()
ClearMap();
}

void obd2ecu::NotifyStartup()
{
StandardMetrics.ms_m_obd2ecu_on->SetValue(true);
MyEvents.SignalEvent("obd2ecu.start", NULL);
}

void obd2ecu::NotifyShutdown()
{
StandardMetrics.ms_m_obd2ecu_on->SetValue(false);
MyEvents.SignalEvent("obd2ecu.stop", NULL);
}

void obd2ecu::SetPowerMode(PowerMode powermode)
{
m_powermode = powermode;
Expand Down
3 changes: 3 additions & 0 deletions vehicle/OVMS.V3/components/obd2ecu/src/obd2ecu.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class obd2ecu : public pcp, public InternalRamAllocated
uint32_t m_supported_21_40; // bitmap of PIDs configured 0x21 through 0x40

public:
void NotifyStartup();
void NotifyShutdown();

void IncomingFrame(CAN_frame_t* p_frame);
void LoadMap();
void ClearMap();
Expand Down
13 changes: 13 additions & 0 deletions vehicle/OVMS.V3/components/vehicle/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,13 @@ OvmsVehicle::OvmsVehicle()
CONFIG_OVMS_VEHICLE_RXTASK_STACK, (void*)this, 10, &m_rxtask, CORE(1));

MyEvents.RegisterEvent(TAG, "ticker.1", std::bind(&OvmsVehicle::VehicleTicker1, this, _1, _2));

MyEvents.RegisterEvent(TAG, "config.changed", std::bind(&OvmsVehicle::VehicleConfigChanged, this, _1, _2));
MyEvents.RegisterEvent(TAG, "config.mounted", std::bind(&OvmsVehicle::VehicleConfigChanged, this, _1, _2));
VehicleConfigChanged("config.mounted", NULL);

MyMetrics.RegisterListener(TAG, "*", std::bind(&OvmsVehicle::MetricModified, this, _1));

}

OvmsVehicle::~OvmsVehicle()
Expand Down Expand Up @@ -1744,6 +1746,17 @@ void OvmsVehicle::MetricModified(OvmsMetric* metric)
{
CalculateRangeSpeed();
}
else if (metric == StdMetrics.ms_m_obd2ecu_on)
{
if ( StdMetrics.ms_m_obd2ecu_on->AsBool() )
{
NotifiedOBD2ECUStart();
}
else
{
NotifiedOBD2ECUStop();
}
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions vehicle/OVMS.V3/components/vehicle/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class OvmsVehicle : public InternalRamAllocated
virtual void NotifiedVehicleChargeType(const std::string& state) {}
virtual void NotifiedVehicleGenState(const std::string& state) {}
virtual void NotifiedVehicleGenType(const std::string& state) {}
virtual void NotifiedOBD2ECUStart() {}
virtual void NotifiedOBD2ECUStop() {}

protected:
uint32_t m_valet_last_alarm;
Expand Down
1 change: 1 addition & 0 deletions vehicle/OVMS.V3/main/metrics_standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ MetricsStandard::MetricsStandard()
ms_m_egpio_output = new OvmsMetricBitset<10,0>(MS_M_EGPIO_OUTPUT, SM_STALE_MAX);
ms_m_egpio_monitor = new OvmsMetricBitset<10,0>(MS_M_EGPIO_MONITOR, SM_STALE_MAX);
#endif //CONFIG_OVMS_COMP_MAX7317
ms_m_obd2ecu_on = new OvmsMetricBool(MS_M_OBD2ECU_ON, SM_STALE_MID);

ms_s_v2_connected = new OvmsMetricBool(MS_S_V2_CONNECTED);
ms_s_v2_peers = new OvmsMetricInt(MS_S_V2_PEERS);
Expand Down
2 changes: 2 additions & 0 deletions vehicle/OVMS.V3/main/metrics_standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define MS_M_EGPIO_MONITOR "m.egpio.monitor"
#define MS_M_EGPIO_OUTPUT "m.egpio.output"
#endif //CONFIG_OVMS_COMP_MAX7317
#define MS_M_OBD2ECU_ON "m.obdc2ecu.on"

#define MS_S_V2_CONNECTED "s.v2.connected"
#define MS_S_V2_PEERS "s.v2.peers"
Expand Down Expand Up @@ -302,6 +303,7 @@ class MetricsStandard
OvmsMetricBitset<10,0>* ms_m_egpio_output; // EGPIO (MAX7317) output port state
OvmsMetricBitset<10,0>* ms_m_egpio_monitor; // EGPIO (MAX7317) input monitoring state
#endif //CONFIG_OVMS_COMP_MAX7317
OvmsMetricBool* ms_m_obd2ecu_on; // OBD2ECU process is on.

OvmsMetricBool* ms_s_v2_connected; // True = V2 server connected [1]
OvmsMetricInt* ms_s_v2_peers; // V2 clients connected [1]
Expand Down

0 comments on commit 324acc1

Please sign in to comment.