Skip to content

Commit

Permalink
changed bootlock handling
Browse files Browse the repository at this point in the history
added isBootLocked() using ECVF_BOOT_LOCK  vflag
  • Loading branch information
KipK committed May 11, 2023
1 parent 2b7cba6 commit e27c9a3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/evse_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ void EvseManager::setSleepForDisable(bool sleepForDisable)
}
}

void EvseManager::unlock() {
_monitor.unlock();
}

unsigned long EvseManager::loop(MicroTasks::WakeReason reason)
{
DBUG("EVSE manager woke: ");
Expand Down
6 changes: 6 additions & 0 deletions src/evse_man.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ class EvseManager : public MicroTasks::Task
bool isVehicleConnected() {
return _monitor.isVehicleConnected();
}
bool isBootLocked() {
return _monitor.isBootLocked();
}
bool isError() {
return _monitor.isError();
}
Expand Down Expand Up @@ -482,6 +485,9 @@ class EvseManager : public MicroTasks::Task
}
void setSleepForDisable(bool sleepForDisable);

// unlock openevse fw compiled with BOOTLOCK
void unlock();

// Temp until everything uses EvseManager
RapiSender &getSender() {
return _sender;
Expand Down
37 changes: 15 additions & 22 deletions src/evse_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,27 +253,6 @@ void EvseMonitor::evseBoot(const char *firmware)
_openevse.heartbeatEnable(EVSE_HEATBEAT_INTERVAL, EVSE_HEARTBEAT_CURRENT, [this](int ret, int interval, int current, int triggered) {
_heartbeat = RAPI_RESPONSE_OK == ret;
});

// ESP32_WiFi handle OpenEvse state, so let first put it to disabled before unlocking
if (config_pause_uses_disabled()) {
disable();
}
else {
sleep();
}

// Unlock OpenEVSE if compiled with BOOTLOCK
_openevse.clearBootLock([this](int ret)
{
if(RAPI_RESPONSE_OK == ret)
{
DBUGF("Unlocked OpenEVSE");
}
else {
DBUGF("Unlock OpenEVSE failed");
}

});
}

void EvseMonitor::updateEvseState(uint8_t evse_state, uint8_t pilot_state, uint32_t vflags)
Expand Down Expand Up @@ -368,7 +347,7 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)
if (isCharging()){
verifyPilot();
}

_count ++;

return EVSE_MONITOR_POLL_TIME;
Expand Down Expand Up @@ -431,6 +410,20 @@ EvseMonitor::ServiceLevel EvseMonitor::getActualServiceLevel()
ServiceLevel::L1;
}

void EvseMonitor::unlock() {
// Unlock OpenEVSE if compiled with BOOTLOCK
_openevse.clearBootLock([this](int ret)
{
if(RAPI_RESPONSE_OK == ret)
{
DBUGF("Unlocked OpenEVSE");
}
else {
DBUGF("Unlock OpenEVSE failed");
}

});
}
void EvseMonitor::enable()
{
OpenEVSE.enable([this](int ret)
Expand Down
8 changes: 7 additions & 1 deletion src/evse_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class EvseMonitor : public MicroTasks::Task
bool isVehicleConnected() {
return OPENEVSE_VFLAG_EV_CONNECTED == (getFlags() & OPENEVSE_VFLAG_EV_CONNECTED);
}
bool isBootLocked() {
return OPENEVSE_VFLAG_BOOT_LOCK == (getFlags() & OPENEVSE_VFLAG_BOOT_LOCK);
}
};

class DataReady : public MicroTasks::Event
Expand Down Expand Up @@ -188,7 +191,7 @@ class EvseMonitor : public MicroTasks::Task
~EvseMonitor();

bool begin(RapiSender &sender);

void unlock();
void enable();
void sleep();
void disable();
Expand Down Expand Up @@ -232,6 +235,9 @@ class EvseMonitor : public MicroTasks::Task
bool isVehicleConnected() {
return _state.isVehicleConnected();
}
bool isBootLocked() {
return _state.isBootLocked();
}
double getAmps() {
return _amp;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ loop() {

import_timers(&scheduler);
}
// unlock openevse fw compiled with BOOTLOCK
if (evse.isBootLocked()) {
evse.unlock();
DBUGLN("Unlocked BOOTLOCK");
}

// -------------------------------------------------------------------
// Do these things once every 2s
Expand Down

0 comments on commit e27c9a3

Please sign in to comment.