@@ -288,6 +288,46 @@ bool MeteringServiceEvse::existsMeasurand(const char *measurand, size_t len) {
288288 return false ;
289289}
290290
291+ namespace MicroOcpp {
292+ namespace Ocpp201 {
293+
294+ bool validateSelectString (const char *csl, void *userPtr) {
295+ auto mService = static_cast <MeteringService*>(userPtr);
296+
297+ bool isValid = true ;
298+ const char *l = csl; // the beginning of an entry of the comma-separated list
299+ const char *r = l; // one place after the last character of the entry beginning with l
300+ while (*l) {
301+ if (*l == ' ,' ) {
302+ l++;
303+ continue ;
304+ }
305+ r = l + 1 ;
306+ while (*r != ' \0 ' && *r != ' ,' ) {
307+ r++;
308+ }
309+ bool found = false ;
310+ for (size_t evseId = 0 ; evseId < MO_NUM_EVSEID && mService ->getEvse (evseId); evseId++) {
311+ if (mService ->getEvse (evseId)->existsMeasurand (l, (size_t ) (r - l))) {
312+ found = true ;
313+ break ;
314+ }
315+ }
316+ if (!found) {
317+ isValid = false ;
318+ MO_DBG_WARN (" could not find metering device for %.*s" , (int ) (r - l), l);
319+ break ;
320+ }
321+ l = r;
322+ }
323+ return isValid;
324+ }
325+
326+ } // namespace Ocpp201
327+ } // namespace MicroOcpp
328+
329+ using namespace MicroOcpp ::Ocpp201;
330+
291331MeteringService::MeteringService (Model& model, size_t numEvses) {
292332
293333 auto varService = model.getVariableService ();
@@ -298,40 +338,10 @@ MeteringService::MeteringService(Model& model, size_t numEvses) {
298338 varService->declareVariable <const char *>(" SampledDataCtrlr" , " TxEndedMeasurands" , " " );
299339 varService->declareVariable <const char *>(" AlignedDataCtrlr" , " AlignedDataMeasurands" , " " );
300340
301- std::function<bool (const char *)> validateSelectString = [this ] (const char *csl) {
302- bool isValid = true ;
303- const char *l = csl; // the beginning of an entry of the comma-separated list
304- const char *r = l; // one place after the last character of the entry beginning with l
305- while (*l) {
306- if (*l == ' ,' ) {
307- l++;
308- continue ;
309- }
310- r = l + 1 ;
311- while (*r != ' \0 ' && *r != ' ,' ) {
312- r++;
313- }
314- bool found = false ;
315- for (size_t evseId = 0 ; evseId < MO_NUM_EVSEID && evses[evseId]; evseId++) {
316- if (evses[evseId]->existsMeasurand (l, (size_t ) (r - l))) {
317- found = true ;
318- break ;
319- }
320- }
321- if (!found) {
322- isValid = false ;
323- MO_DBG_WARN (" could not find metering device for %.*s" , (int ) (r - l), l);
324- break ;
325- }
326- l = r;
327- }
328- return isValid;
329- };
330-
331- varService->registerValidator <const char *>(" SampledDataCtrlr" , " TxStartedMeasurands" , validateSelectString);
332- varService->registerValidator <const char *>(" SampledDataCtrlr" , " TxUpdatedMeasurands" , validateSelectString);
333- varService->registerValidator <const char *>(" SampledDataCtrlr" , " TxEndedMeasurands" , validateSelectString);
334- varService->registerValidator <const char *>(" AlignedDataCtrlr" , " AlignedDataMeasurands" , validateSelectString);
341+ varService->registerValidator <const char *>(" SampledDataCtrlr" , " TxStartedMeasurands" , validateSelectString, this );
342+ varService->registerValidator <const char *>(" SampledDataCtrlr" , " TxUpdatedMeasurands" , validateSelectString, this );
343+ varService->registerValidator <const char *>(" SampledDataCtrlr" , " TxEndedMeasurands" , validateSelectString, this );
344+ varService->registerValidator <const char *>(" AlignedDataCtrlr" , " AlignedDataMeasurands" , validateSelectString, this );
335345
336346 for (size_t evseId = 0 ; evseId < std::min (numEvses, (size_t )MO_NUM_EVSEID ); evseId++) {
337347 evses[evseId] = new MeteringServiceEvse (model, evseId);
0 commit comments