Skip to content

Commit c32a8c0

Browse files
committed
Only re-evaluate if a claim has changed
1 parent 952ff86 commit c32a8c0

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

src/evse_man.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,19 @@ EvseManager::Claim::Claim() :
109109
{
110110
}
111111

112-
void EvseManager::Claim::claim(EvseClient client, int priority, EvseProperties &target)
112+
bool EvseManager::Claim::claim(EvseClient client, int priority, EvseProperties &target)
113113
{
114-
_client = client;
115-
_priority = priority;
116-
_properties = target;
114+
if(_client != client ||
115+
_priority != priority ||
116+
_properties != target)
117+
{
118+
_client = client;
119+
_priority = priority;
120+
_properties = target;
121+
return true;
122+
}
123+
124+
return false;
117125
}
118126

119127
void EvseManager::Claim::release()
@@ -385,7 +393,7 @@ bool EvseManager::claim(EvseClient client, int priority, EvseProperties &target)
385393
{
386394
Claim *slot = NULL;
387395

388-
DBUGF("New claim from 0x%08x, priority %d, %s", client, priority, target.getState().toString());
396+
DBUGF("Claim from 0x%08x, priority %d, %s", client, priority, target.getState().toString());
389397

390398
for (size_t i = 0; i < EVSE_MANAGER_MAX_CLIENT_CLAIMS; i++)
391399
{
@@ -400,10 +408,13 @@ bool EvseManager::claim(EvseClient client, int priority, EvseProperties &target)
400408

401409
if(slot)
402410
{
403-
DBUGF("Found slot, waking task");
404-
slot->claim(client, priority, target);
405-
_evaluateClaims = true;
406-
MicroTask.wakeTask(this);
411+
DBUGF("Found slot");
412+
if(slot->claim(client, priority, target))
413+
{
414+
DBUGF("Claim added/updated, waking task");
415+
_evaluateClaims = true;
416+
MicroTask.wakeTask(this);
417+
}
407418
return true;
408419
}
409420

src/evse_man.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ class EvseProperties : virtual public JsonSerialize<512>
162162
return *this;
163163
}
164164

165+
bool equals(EvseProperties &rhs) {
166+
return this->_state == rhs._state &&
167+
this->_charge_current == rhs._charge_current &&
168+
this->_max_current == rhs._max_current &&
169+
this->_energy_limit == rhs._energy_limit &&
170+
this->_time_limit == rhs._time_limit &&
171+
this->_auto_release == rhs._auto_release;
172+
173+
}
174+
bool equals(EvseState &rhs) {
175+
return this->_state == rhs;
176+
}
177+
178+
bool operator == (EvseProperties &rhs) {
179+
return this->equals(rhs);
180+
}
181+
bool operator == (EvseState &rhs) {
182+
return this->equals(rhs);
183+
}
184+
185+
bool operator != (EvseProperties &rhs) {
186+
return !equals(rhs);
187+
}
188+
bool operator != (EvseState &rhs) {
189+
return !equals(rhs);
190+
}
191+
192+
165193
using JsonSerialize::deserialize;
166194
virtual bool deserialize(JsonObject &obj);
167195
using JsonSerialize::serialize;
@@ -181,7 +209,7 @@ class EvseManager : public MicroTasks::Task
181209
public:
182210
Claim();
183211

184-
void claim(EvseClient client, int priority, EvseProperties &target);
212+
bool claim(EvseClient client, int priority, EvseProperties &target);
185213
void release();
186214

187215
bool isValid() {

0 commit comments

Comments
 (0)