@@ -73,11 +73,13 @@ MeterValuesManager::MeterValuesManager(ocpp::config::IOcppConfig& ocp
7373
7474 // Register configuration change handler
7575 config_manager.registerConfigChangedListener (" ClockAlignedDataInterval" , *this );
76+ config_manager.registerConfigChangedListener (" MeterValueSampleInterval" , *this );
7677
7778 // Start clock aligned and sample timers
7879 configureClockAlignedTimer ();
79- for (const Connector* connector : m_connectors.getConnectors ())
80+ for (Connector* connector : m_connectors.getConnectors ())
8081 {
82+ connector->meter_values_timer .setCallback (std::bind (&MeterValuesManager::processSampled, this , connector->id ));
8183 if (connector->transaction_id != 0 )
8284 {
8385 startSampledMeterValues (connector->id );
@@ -131,7 +133,6 @@ void MeterValuesManager::startSampledMeterValues(unsigned int connector_id)
131133 if (connector)
132134 {
133135 // Start meter value timer for the connector
134- connector->meter_values_timer .setCallback (std::bind (&MeterValuesManager::processSampled, this , connector_id));
135136 connector->meter_values_timer .start (interval);
136137 }
137138 }
@@ -235,23 +236,74 @@ bool MeterValuesManager::onTriggerMessage(ocpp::types::MessageTriggerEnumType
235236/* * @copydoc void IConfigChangedListener::configurationValueChanged(const std::string&) */
236237void MeterValuesManager::configurationValueChanged (const std::string& key)
237238{
238- // No need to check key, only ClockAlignedDataInterval is monitored
239- (void )key;
240-
241- // Check new value
242- std::chrono::seconds interval = m_ocpp_config.clockAlignedDataInterval ();
243- if (interval == std::chrono::seconds (0 ))
239+ if (key == " metervaluesampleinterval" )
240+ {
241+ // Check new value
242+ std::chrono::seconds interval = m_ocpp_config.meterValueSampleInterval ();
243+ for (Connector* connector : m_connectors.getConnectors ())
244+ {
245+ if (interval == std::chrono::seconds (0 ))
246+ {
247+ // Disable meter values
248+ connector->meter_values_timer .stop ();
249+ LOG_INFO << " Meter values disabled on connector " << connector->id ;
250+ }
251+ else if (connector->status == ocpp::types::ChargePointStatus::Charging)
252+ {
253+ configureMeterValueSampleTimer (connector->id , interval);
254+ }
255+ }
256+ }else if (key == " clockaligneddatainterval" )
244257 {
245- // Disable clock aligned values
246- m_clock_aligned_timer.stop ();
258+ // Check new value
259+ std::chrono::seconds interval = m_ocpp_config.clockAlignedDataInterval ();
260+ if (interval == std::chrono::seconds (0 ))
261+ {
262+ // Disable clock aligned values
263+ m_clock_aligned_timer.stop ();
247264
248- LOG_INFO << " Clock aligned meter values disabled" ;
265+ LOG_INFO << " Clock aligned meter values disabled" ;
266+ }
267+ else
268+ {
269+ // Reconfigure clock aligned timer
270+ configureClockAlignedTimer ();
271+ }
249272 }
250- else
273+ }
274+
275+ /* * @brief Configure meter value sample timer */
276+ void MeterValuesManager::configureMeterValueSampleTimer (const unsigned int connector_id, const std::chrono::seconds interval)
277+ {
278+ Connector* connector = m_connectors.getConnector (connector_id);
279+
280+ if (!connector) {
281+ return ;
282+ }
283+
284+ // Reconfigure meter value timer
285+ // Stop timer
286+ connector->meter_values_timer .stop ();
287+
288+ LOG_INFO << " Configure meter values on connector " << connector->id << " : interval in seconds = " << interval.count ();
289+
290+ // Compute next due date
291+ time_t now = std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ());
292+ struct tm aligned_time_tm;
293+ #ifdef _MSC_VER
294+ localtime_s (&aligned_time_tm, &now);
295+ #else // _MSC_VER
296+ localtime_r (&now, &aligned_time_tm);
297+ #endif // _MSC_VER
298+ aligned_time_tm.tm_min = 0 ;
299+ aligned_time_tm.tm_sec = 0 ;
300+ time_t aligned_time = std::mktime (&aligned_time_tm);
301+ while (aligned_time <= now)
251302 {
252- // Reconfigure clock aligned timer
253- configureClockAlignedTimer ();
303+ aligned_time += interval.count ();
254304 }
305+ std::chrono::seconds next_due_interval = std::chrono::seconds (aligned_time - now);
306+ connector->meter_values_timer .start (std::chrono::milliseconds (next_due_interval));
255307}
256308
257309/* * @brief Configure clock-aligned timer */
0 commit comments