From 00ba307b4d3b4f1e25ae9edca95ed14f362517e9 Mon Sep 17 00:00:00 2001 From: lincomatic Date: Mon, 6 Feb 2023 21:45:14 -0800 Subject: [PATCH] added BOOTLOCK --- firmware/open_evse/CHANGELOG | 3 +++ firmware/open_evse/J1772EvseController.cpp | 6 +++++- firmware/open_evse/J1772EvseController.h | 15 +++++++++++++-- firmware/open_evse/main.cpp | 16 +++++++++++++--- firmware/open_evse/open_evse.h | 3 +++ firmware/open_evse/rapi_proc.cpp | 15 ++++++++++++++- firmware/open_evse/rapi_proc.h | 6 +++++- platformio.ini | 3 ++- 8 files changed, 58 insertions(+), 9 deletions(-) diff --git a/firmware/open_evse/CHANGELOG b/firmware/open_evse/CHANGELOG index 2121a713..49fb6809 100644 --- a/firmware/open_evse/CHANGELOG +++ b/firmware/open_evse/CHANGELOG @@ -1,5 +1,8 @@ Change Log +20230206 SCL +- added BOOTLOCK - when defined, EVSE locked until receives $SB + 20220408 V8.2.1 SCL - fix bug: SaveSettings() should save GetMaxCurrentCapacity() instead of GetCurrentCapacity(), in case called during throttling diff --git a/firmware/open_evse/J1772EvseController.cpp b/firmware/open_evse/J1772EvseController.cpp index 7b27b48c..1a2ce4ac 100644 --- a/firmware/open_evse/J1772EvseController.cpp +++ b/firmware/open_evse/J1772EvseController.cpp @@ -1,7 +1,7 @@ /* * This file is part of Open EVSE. * - * Copyright (c) 2011-2021 Sam C. Lin + * Copyright (c) 2011-2023 Sam C. Lin * * Open EVSE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1079,6 +1079,10 @@ void J1772EVSEController::Init() m_wVFlags = ECVF_DEFAULT; +#ifdef BOOTLOCK + m_wVFlags |= ECVF_BOOT_LOCK; +#endif + m_MaxHwCurrentCapacity = eeprom_read_byte((uint8_t*)EOFS_MAX_HW_CURRENT_CAPACITY); if (!m_MaxHwCurrentCapacity || (m_MaxHwCurrentCapacity == (uint8_t)0xff)) { m_MaxHwCurrentCapacity = MAX_CURRENT_CAPACITY_L2; diff --git a/firmware/open_evse/J1772EvseController.h b/firmware/open_evse/J1772EvseController.h index 03f542ca..a35cb354 100644 --- a/firmware/open_evse/J1772EvseController.h +++ b/firmware/open_evse/J1772EvseController.h @@ -2,7 +2,7 @@ /* * This file is part of Open EVSE. * - * Copyright (c) 2011-2021 Sam C. Lin + * Copyright (c) 2011-2023 Sam C. Lin * * Open EVSE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -102,7 +102,7 @@ typedef uint8_t (*EvseStateTransitionReqFunc)(uint8_t prevPilotState,uint8_t cur #define ECVF_UI_IN_MENU 0x0800 // onboard UI currently in a menu #define ECVF_TIMER_ON 0x1000 // delay timer enabled #define ECVF_CHARGE_LIMIT 0x2000 -// reserved #define ECVF_BOOT_LOCK 0x4000 // locked at boot +#define ECVF_BOOT_LOCK 0x4000 // locked at boot #define ECVF_MENNEKES_MANUAL 0x8000 // Mennekes lock manual mode #if defined(AUTH_LOCK) && (AUTH_LOCK != 0) #define ECVF_DEFAULT ECVF_AUTH_LOCKED|ECVF_SESSION_ENDED @@ -389,6 +389,17 @@ class J1772EVSEController { uint8_t ReadACPins(); #endif // ADVPWR + void ClearBootLock() { + clrVFlags(ECVF_BOOT_LOCK); + } + uint8_t IsBootLocked() { +#ifdef BOOTLOCK + return vFlagIsSet(ECVF_BOOT_LOCK) ? 1 : 0; +#else + return 0; +#endif + } + void HardFault(int8_t recoverable); void SetLimitSleep(int8_t tf) { diff --git a/firmware/open_evse/main.cpp b/firmware/open_evse/main.cpp index 27e47cfe..cb7b37e9 100644 --- a/firmware/open_evse/main.cpp +++ b/firmware/open_evse/main.cpp @@ -2,7 +2,7 @@ /* * Open EVSE Firmware * - * Copyright (c) 2011-2021 Sam C. Lin + * Copyright (c) 2011-2023 Sam C. Lin * Copyright (c) 2011-2014 Chris Howell * timer code Copyright (c) 2013 Kevin L * portions Copyright (c) 2014-2015 Nick Sayer @@ -2486,12 +2486,22 @@ void setup() g_EvseController.SetStateTransitionReqFunc(&StateTransitionReqFunc); #endif //PP_AUTO_AMPACITY - EvseReset(); - #ifdef TEMPERATURE_MONITORING g_TempMonitor.Init(); #endif + EvseReset(); + +#ifdef BOOTLOCK +#ifdef LCD16X2 + g_OBD.LcdMsg_P(PSTR("Waiting for"),PSTR("Initialization..")); +#endif // LCD16X2 + while (g_EvseController.IsBootLocked()) { + ProcessInputs(); + } +#endif // BOOTLOCK + + WDT_ENABLE(); } // setup() diff --git a/firmware/open_evse/open_evse.h b/firmware/open_evse/open_evse.h index 53cdb7ef..24b5b389 100644 --- a/firmware/open_evse/open_evse.h +++ b/firmware/open_evse/open_evse.h @@ -69,6 +69,9 @@ typedef unsigned long time_t; // auto detect L1/L2 #define AUTOSVCLEVEL +// on boot, EVSE locked until receives $SB +//#define BOOTLOCK + // show disabled tests before POST #define SHOW_DISABLED_TESTS diff --git a/firmware/open_evse/rapi_proc.cpp b/firmware/open_evse/rapi_proc.cpp index d274cce8..6bf97325 100644 --- a/firmware/open_evse/rapi_proc.cpp +++ b/firmware/open_evse/rapi_proc.cpp @@ -2,7 +2,7 @@ /* * Open EVSE Firmware * - * Copyright (c) 2013-2021 Sam C. Lin + * Copyright (c) 2013-2023 Sam C. Lin * * This file is part of Open EVSE. @@ -445,6 +445,19 @@ int EvseRapiProcessor::processCmd() } break; #endif // AMMETER +#ifdef BOOTLOCK + case 'B': + if (g_EvseController.InFaultState()) { + strcpy(buffer,"1"); + } + else { + g_EvseController.ClearBootLock(); + strcpy(buffer,"0"); + } + bufCnt=1; + rc = 0; + break; +#endif // BOOTLOCK case 'C': // current capacity if ((tokenCnt == 2) || (tokenCnt == 3)) { u2.u8 = dtou32(tokens[1]); diff --git a/firmware/open_evse/rapi_proc.h b/firmware/open_evse/rapi_proc.h index 6a21df5c..9e8b6a25 100644 --- a/firmware/open_evse/rapi_proc.h +++ b/firmware/open_evse/rapi_proc.h @@ -2,7 +2,7 @@ /* * Open EVSE Firmware * - * Copyright (c) 2013-2021 Sam C. Lin + * Copyright (c) 2013-2023 Sam C. Lin * * This file is part of Open EVSE. @@ -172,6 +172,10 @@ S5 A|M|0|1 - Mennekes lock setting 1 = lock (valid only in manual mode) n.b. requires MENNEKES_LOCK. manual mode is volatile - always boots in automatic mode SA currentscalefactor currentoffset - set ammeter settings +SB - clear boot lock + when BOOTLOCK is defined, EVSE won't allow charging after boot up until SB is received + response: $OK 0 = unlock success + $OK 1 = unlock fail - EVSE currently in fault state SC amps [V|M]- set current capacity response: if amps < minimum current capacity, will set to minimum and return $NK ampsset diff --git a/platformio.ini b/platformio.ini index e058214d..0357f15a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,9 +24,10 @@ upload_flags = -F -e #platform = atmelavr@1.4.1 # Arduino 1.6.23 platform = atmelavr@1.15.0 -src_build_flags = +build_src_flags = -DOEV6 -DRELAY_PWM +# -DBOOTLOCK # -DENABLE_CGMI -DAUTOSVCLEVEL -DSHOW_DISABLED_TESTS