@@ -21,7 +21,7 @@ using openxc::config::RunLevel;
2121static bool ENGINE_STARTED = false ;
2222static bool VEHICLE_IN_MOTION = false ;
2323
24- static openxc::util::time::FrequencyClock IGNITION_STATUS_TIMER = {0.5 };
24+ static openxc::util::time::FrequencyClock IGNITION_STATUS_TIMER = {0.5 , 0 , NULL };
2525
2626/* Private: A representation of an OBD-II PID.
2727 *
@@ -134,38 +134,38 @@ void openxc::diagnostics::obd2::initialize(DiagnosticsManager* manager) {
134134// seconds to start this process over again.
135135void openxc::diagnostics::obd2::loop (DiagnosticsManager* manager) {
136136 static bool pidSupportQueried = false ;
137- static bool sentFinalIgnitionCheck = false ;
137+ const int MAX_IGNITION_CHECK_COUNT = 3 ;
138+ static int ignitionCheckCount = 0 ;
138139
139140 if (!manager->initialized || manager->obd2Bus == NULL ) {
140141 return ;
141142 }
142143
143144 if (time::elapsed (&IGNITION_STATUS_TIMER, false )) {
144- if (sentFinalIgnitionCheck && getConfiguration ()->powerManagement ==
145+ if (ignitionCheckCount >= MAX_IGNITION_CHECK_COUNT &&
146+ getConfiguration ()->powerManagement ==
145147 PowerManagement::OBD2_IGNITION_CHECK) {
146148 debug (" Ceasing diagnostic requests as ignition went off" );
147149 diagnostics::reset (manager);
148150 // Don't reset diagnostics here, because if the CAN bus is still
149151 // active we want to keep querying for igntion. If we de-init
150152 // diagnosicts here we risk getting stuck awake, but not querying
151153 // for any diagnostics messages.
152- sentFinalIgnitionCheck = false ;
153- pidSupportQueried = false ;
154154 IGNITION_STATUS_TIMER.frequency = .1 ;
155- time::tick (&IGNITION_STATUS_TIMER);
155+ ignitionCheckCount = 0 ;
156+ pidSupportQueried = false ;
156157 } else {
157158 // We haven't received an ignition in 5 seconds. Either the user didn't
158159 // have either OBD-II request configured as a recurring request (which
159160 // is fine) or they did, but the car stopped responding. Kick off
160161 // another request to see which is true. It will take 5+5 seconds after
161162 // ignition off to decide we should cancel all outstanding requests.
162- IGNITION_STATUS_TIMER.frequency = .2 ;
163163 requestIgnitionStatus (manager);
164- sentFinalIgnitionCheck = true ;
164+ ++ignitionCheckCount ;
165165 }
166166 } else if (ENGINE_STARTED || VEHICLE_IN_MOTION) {
167167 IGNITION_STATUS_TIMER.frequency = .5 ;
168- sentFinalIgnitionCheck = false ;
168+ ignitionCheckCount = 0 ;
169169 getConfiguration ()->desiredRunLevel = RunLevel::ALL_IO;
170170 if (getConfiguration ()->recurringObd2Requests && !pidSupportQueried) {
171171 debug (" Ignition is on - querying for supported OBD-II PIDs" );
0 commit comments