diff --git a/firmware/open_evse/CHANGELOG b/firmware/open_evse/CHANGELOG index dc3deaf6..267c4544 100644 --- a/firmware/open_evse/CHANGELOG +++ b/firmware/open_evse/CHANGELOG @@ -1,5 +1,11 @@ Change Log +202012 toofishes +- various code size optimizations for a smaller binary +- recode energy meter usage calculation for better accuracy using integer math +- remove Time.h and Time.cpp libraries, not needed as we track time in other ways +- remove SERIALCLI, it hasn't been maintained in years and is replaced by RAPI + 20201001 SCL - move MV_FOR_xx from EnergyMeter.h to openevse.h, and outside of KWH_RECORDING to fix compile error when KWH_RECORDING not defined diff --git a/firmware/open_evse/open_evse.h b/firmware/open_evse/open_evse.h index edcea94e..8c2f0219 100644 --- a/firmware/open_evse/open_evse.h +++ b/firmware/open_evse/open_evse.h @@ -97,11 +97,6 @@ // enable sending of RAPI commands //#define RAPI_SENDER -// serial port command line -// For the RTC version, only CLI or LCD can be defined at one time. -// There is a directive to take care of that if you forget. -//#define SERIALCLI - // EVSE must call state transition function for permission to change states //#define STATE_TRANSITION_REQ_FUNC @@ -342,10 +337,6 @@ extern AutoCurrentCapacityController g_ACCController; #undef BTN_MENU #endif // RGBLCD || I2CLCD -#if defined(RAPI) && defined(SERIALCLI) -#error INVALID CONFIG - CANNOT DEFINE SERIALCLI AND RAPI TOGETHER SINCE THEY BOTH USE THE SERIAL PORT -#endif - #if defined(OPENEVSE_2) && !defined(ADVPWR) #error INVALID CONFIG - OPENEVSE_2 implies/requires ADVPWR #endif @@ -413,13 +404,7 @@ extern AutoCurrentCapacityController g_ACCController; #define LCD_MAX_CHARS_PER_LINE 16 - -#ifdef SERIALCLI -#define TMP_BUF_SIZE 64 -#else #define TMP_BUF_SIZE ((LCD_MAX_CHARS_PER_LINE+1)*2) -#endif // SERIALCLI - // n.b. DEFAULT_SERVICE_LEVEL is ignored if ADVPWR defined, since it's autodetected @@ -814,8 +799,6 @@ typedef union union4b { #define WDT_ENABLE() #endif // WATCHDOG -#include "serialcli.h" - // OnboardDisplay.m_bFlags #define OBDF_MONO_BACKLIGHT 0x01 #define OBDF_AMMETER_DIRTY 0x80 diff --git a/firmware/open_evse/open_evse.ino b/firmware/open_evse/open_evse.ino index 52565fb7..e09eb1ba 100644 --- a/firmware/open_evse/open_evse.ino +++ b/firmware/open_evse/open_evse.ino @@ -2404,9 +2404,6 @@ void ProcessInputs() #ifdef RAPI RapiDoCmd(); #endif -#ifdef SERIALCLI - g_CLI.getInput(); -#endif // SERIALCLI #ifdef BTN_MENU g_BtnHandler.ChkBtn(); #endif @@ -2419,11 +2416,6 @@ void ProcessInputs() void EvseReset() { Wire.begin(); - -#ifdef SERIALCLI - g_CLI.Init(); -#endif // SERIALCLI - g_OBD.Init(); #ifdef RAPI diff --git a/firmware/open_evse/serialcli.cpp b/firmware/open_evse/serialcli.cpp deleted file mode 100644 index b8cd2757..00000000 --- a/firmware/open_evse/serialcli.cpp +++ /dev/null @@ -1,377 +0,0 @@ -#include "open_evse.h" -#include "RTClib.h" - -#ifdef SERIALCLI -CLI g_CLI; - -extern RTC_DS1307 g_RTC; - -static const char s_psEnabled[] PROGMEM = "enabled"; -static const char s_psDisabled[] PROGMEM = "disabled"; - -CLI::CLI() -{ - m_CLIstrCount = 0; - m_strBuf = g_sTmp; - m_strBufLen = sizeof(g_sTmp); -} - -void CLI::info() -{ - println_P(PSTR("OpenEVSE")); // CLI print prompt when serial is ready - print_P(PSTR("Firmware - Open EVSE V")); //CLI info - println_P(VERSTR); - printlnn(); -} - -void CLI::Init() -{ - info(); - println_P(PSTR("type help for command list")); - print_P(PSTR("OpenEVSE> ")); // CLI Prompt - flush(); - -} - -uint8_t CLI::getInt() -{ - uint8_t c; - uint8_t num = 0; - - do { - c = Serial.read(); // read the byte - if ((c >= '0') && (c <= '9')) { - num = (num * 10) + c - '0'; - } - } while (c != 13); - return num; -} - -void CLI::printlnn() -{ - println(""); -} - -const char g_pson[] PROGMEM = "on"; -void CLI::getInput() -{ - int currentreading; - uint8_t amp; - if (Serial.available()) { // if byte(s) are available to be read - char inbyte = (char) Serial.read(); // read the byte - Serial.print(inbyte); - if (inbyte != 13) { // CR - if (((inbyte >= 'a') && (inbyte <= 'z')) || ((inbyte >= '0') && (inbyte <= '@') || (inbyte == ' ')) ) { //sar - allow ? - m_CLIinstr[m_CLIstrCount] = inbyte; - m_CLIstrCount++; - } - else if (m_CLIstrCount && ((inbyte == 8) || (inbyte == 127))) { - m_CLIstrCount--; - } - } - - if ((inbyte == 13) || (m_CLIstrCount == CLI_BUFLEN-1)) { // if enter was pressed or max chars reached - m_CLIinstr[m_CLIstrCount] = '\0'; - printlnn(); // print a newline - - if (strcmp_P(m_CLIinstr, PSTR("show")) == 0){ //if match SHOW - info(); - - println_P(PSTR("Settings")); - print_P(PSTR("Service level: L")); - Serial.println((int)g_EvseController.GetCurSvcLevel()); - print_P(PSTR("Current capacity (Amps): ")); - Serial.println((int)g_EvseController.GetCurrentCapacity()); - print_P(PSTR("Min Current Capacity: ")); - Serial.println(MIN_CURRENT_CAPACITY_J1772); - print_P(PSTR("Max Current Capacity: ")); - Serial.println((g_EvseController.GetCurSvcLevel() == 2) ? g_EvseController.GetMaxHwCurrentCapacity() : MAX_CURRENT_CAPACITY_L1); - print_P(PSTR("Vent Required: ")); - println_P(g_EvseController.VentReqEnabled() ? s_psEnabled : s_psDisabled); - print_P(PSTR("Diode Check: ")); - println_P(g_EvseController.DiodeCheckEnabled() ? s_psEnabled : s_psDisabled); - -#ifdef ADVPWR - print_P(PSTR("Ground Check: ")); - println_P(g_EvseController.GndChkEnabled() ? s_psEnabled : s_psDisabled); - print_P(PSTR("Stuck Relay Check: ")); - println_P(g_EvseController.StuckRelayChkEnabled() ? s_psEnabled : s_psDisabled); -#endif // ADVPWR - // Start Delay Timer feature - GoldServe -#ifdef DELAYTIMER - print_P(PSTR("Delay Timer: ")); - if (g_DelayTimer.IsTimerEnabled()){ - println_P(s_psEnabled); - } else { - println_P(s_psDisabled); - } - print_P(PSTR("Start Time: ")); - Serial.print(g_DelayTimer.GetStartTimerHour(), DEC); - print_P(PSTR(" hour ")); - Serial.print(g_DelayTimer.GetStartTimerMin(), DEC); - println_P(PSTR(" min")); - print_P(PSTR("End Time: ")); - Serial.print(g_DelayTimer.GetStopTimerHour(), DEC); - print_P(PSTR(" hour ")); - Serial.print(g_DelayTimer.GetStopTimerMin(), DEC); - println_P(PSTR(" min")); - print_P(PSTR("System Date/Time: ")); - DateTime t = g_RTC.now(); - Serial.print(t.year(), DEC); - Serial.print('/'); - Serial.print(t.month(), DEC); - Serial.print('/'); - Serial.print(t.day(), DEC); - Serial.print(' '); - Serial.print(t.hour(), DEC); - Serial.print(':'); - Serial.print(t.minute(), DEC); - Serial.print(':'); - Serial.print(t.second(), DEC); - // End Delay Timer feature - GoldServe -#endif //#ifdef DELAYTIMER - } - else if ((strcmp_P(m_CLIinstr, PSTR("help")) == 0) || (strcmp_P(m_CLIinstr, PSTR("?")) == 0)){ // string compare - println_P(PSTR("Help Commands")); - printlnn(); - println_P(PSTR("help - Display commands")); // print to the terminal - println_P(PSTR("set - Change settings")); - println_P(PSTR("show - Display settings/values")); - // Start Delay Timer feature - GoldServe -#ifdef DELAYTIMER - println_P(PSTR("dt - Date/Time commands")); - println_P(PSTR("timer - Delay timer commands")); -#endif //#ifdef DELAYTIMER - // End Delay Timer feature - GoldServe - } - else if (strcmp_P(m_CLIinstr, PSTR("set")) == 0) { // string compare - println_P(PSTR("Set Commands - Usage: set amp")); - printlnn(); - println_P(PSTR("amp - set current capacity")); - println_P(PSTR("vntreq on/off - enable/disable vent required state")); - println_P(PSTR("diochk on/off - enable/disable diode check")); - -#ifdef ADVPWR - println_P(PSTR("gndchk on/off - turn ground check on/off")); - println_P(PSTR("rlychk on/off - turn stuck relay check on/off")); -#endif // ADVPWR - println_P(PSTR("sdbg on/off - turn serial debugging on/off")); - } - else if (strncmp_P(m_CLIinstr, PSTR("set "),4) == 0) { - char *p = m_CLIinstr + 4; - if (!strncmp_P(p,PSTR("sdbg "),5)) { - p += 5; - print_P(PSTR("serial debugging ")); - if (!strcmp_P(p,g_pson)) { - g_EvseController.EnableSerDbg(1); - println_P(s_psEnabled); - } - else { - g_EvseController.EnableSerDbg(0); - println_P(s_psDisabled); - } - } - else if (!strncmp_P(p,PSTR("vntreq "),7)) { - p += 7; - print_P(PSTR("vent required ")); - if (!strcmp_P(p,g_pson)) { - g_EvseController.EnableVentReq(1); - println_P(s_psEnabled); - } - else { - g_EvseController.EnableVentReq(0); - println_P(s_psDisabled); - } - } - else if (!strncmp_P(p,PSTR("diochk "),7)) { - p += 7; - print_P(PSTR("diode check ")); - if (!strcmp_P(p,g_pson)) { - g_EvseController.EnableDiodeCheck(1); - println_P(s_psEnabled); - } - else { - g_EvseController.EnableDiodeCheck(0); - println_P(s_psDisabled); - } - } -#ifdef ADVPWR - else if (!strncmp_P(p,PSTR("gndchk "),7)) { - p += 7; - print_P(PSTR("ground check ")); - if (!strcmp_P(p,g_pson)) { - g_EvseController.EnableGndChk(1); - println_P(s_psEnabled); - } - else { - g_EvseController.EnableGndChk(0); - println_P(s_psDisabled); - } - } - else if (!strncmp_P(p,PSTR("rlychk "),7)) { - p += 7; - print_P(PSTR("stuck relay check ")); - if (!strcmp_P(p,g_pson)) { - g_EvseController.EnableStuckRelayChk(1); - println_P(s_psEnabled); - } - else { - g_EvseController.EnableStuckRelayChk(0); - println_P(s_psDisabled); - } - } -#endif // ADVPWR - else if (!strcmp_P(p,PSTR("amp"))){ // string compare - println_P(PSTR("WARNING - Do not set higher than 80% of breaker value")); - printlnn(); - print_P(PSTR("Enter amps (")); - Serial.print(MIN_CURRENT_CAPACITY_J1772); - print_P(PSTR("-")); - Serial.print((g_EvseController.GetCurSvcLevel() == 1) ? MAX_CURRENT_CAPACITY_L1 : g_EvseController.GetMaxHwCurrentCapacity()); - print_P(PSTR("): ")); - amp = getInt(); - Serial.println((int)amp); - if(g_EvseController.SetCurrentCapacity(amp,1)) { - println_P(PSTR("Invalid Setting")); - } - - print_P(PSTR("Max current: ")); // print to the terminal - Serial.print((int)g_EvseController.GetCurrentCapacity()); - print_P(PSTR("A")); - } - else { - goto unknown; - } - } - // Start Delay Timer feature - GoldServe -#ifdef DELAYTIMER - else if (strncmp_P(m_CLIinstr, PSTR("dt"), 2) == 0){ // string compare - char *p = m_CLIinstr + 3; - - if (strncmp_P(p,PSTR("set"),3) == 0) { - p += 4; - println_P(PSTR("Set Date/Time (mm/dd/yy hh:mm)")); - print_P(PSTR("Month (mm): ")); - uint8_t month = getInt(); - Serial.println(month); - print_P(PSTR("Day (dd): ")); - uint8_t day = getInt(); - Serial.println(day); - print_P(PSTR("Year (yy): ")); - uint8_t year = getInt(); - Serial.println(year); - print_P(PSTR("Hour (hh): ")); - uint8_t hour = getInt(); - Serial.println(hour); - print_P(PSTR("Minute (mm): ")); - uint8_t min = getInt(); - Serial.println(min); - - if (month + day + year + hour + min) { - g_RTC.adjust(DateTime(year, month, day, hour, min, 0)); - println_P(PSTR("Date/Time Set")); - } else { - println_P(PSTR("Date/Time NOT Set")); - } - } - else { - DateTime t = g_RTC.now(); - Serial.print(t.year(), DEC); - Serial.print('/'); - Serial.print(t.month(), DEC); - Serial.print('/'); - Serial.print(t.day(), DEC); - Serial.print(' '); - Serial.print(t.hour(), DEC); - Serial.print(':'); - Serial.print(t.minute(), DEC); - Serial.print(':'); - Serial.print(t.second(), DEC); - Serial.println(); - println_P(PSTR("Use 'dt set' to set the system date/time")); - } - - } - else if (strncmp_P(m_CLIinstr, PSTR("timer"), 5) == 0){ // string compare - char *p = m_CLIinstr + 6; - uint8_t hour, min; - - if (strncmp_P(p,PSTR("set start"),9) == 0) { - println_P(PSTR("Set Start Time (hh:mm)")); - print_P(PSTR("Hour (hh): ")); - hour = getInt(); - Serial.println(hour); - print_P(PSTR("Minute (mm): ")); - min = getInt(); - Serial.println(min); - g_DelayTimer.SetStartTimer(hour, min); - } else if (strncmp_P(p,PSTR("set stop"),8) == 0) { - println_P(PSTR("Set Stop Time (hh:mm)")); - print_P(PSTR("Hour (hh): ")); - hour = getInt(); - Serial.println(hour); - print_P(PSTR("Minute (mm): ")); - min = getInt(); - Serial.println(min); - g_DelayTimer.SetStopTimer(hour, min); - } else if (strncmp_P(p,PSTR("enable"),9) == 0) { - println_P(PSTR("Delay timer enabled, autostart disabled")); - g_DelayTimer.Enable(); - } else if (strncmp_P(p,PSTR("disable"),9) == 0) { - println_P(PSTR("Delay timer disabled, autostart enabled")); - g_DelayTimer.Disable(); - } else { - print_P(PSTR("Delay Timer: ")); - if (g_DelayTimer.IsTimerEnabled()){ - println_P(PSTR("Enabled")); - } else { - println_P(PSTR("Disabled")); - } - print_P(PSTR("Start Time: ")); - Serial.print(g_DelayTimer.GetStartTimerHour(), DEC); - print_P(PSTR(" hour ")); - Serial.print(g_DelayTimer.GetStartTimerMin(), DEC); - println_P(PSTR(" min")); - print_P(PSTR("End Time: ")); - Serial.print(g_DelayTimer.GetStopTimerHour(), DEC); - print_P(PSTR(" hour ")); - Serial.print(g_DelayTimer.GetStopTimerMin(), DEC); - println_P(PSTR(" min")); - if (!g_DelayTimer.IsTimerValid()){ - println_P(PSTR("Start and Stop times can not be the same!")); - } - println_P(PSTR("")); - println_P(PSTR("Use 'timer enable/disable' to enable/disable timer function")); - println_P(PSTR("Use 'timer set start/stop' to set timer start/stop times")); - } - } -#endif //#ifdef DELAYTIMER - // End Delay Timer feature - GoldServe - else { // if the input text doesn't match any defined above - unknown: - println_P(PSTR("Unknown Command -- type help for command list")); // echo back to the terminal - } - printlnn(); - print_P(PSTR("OpenEVSE> ")); - g_CLI.flush(); - m_CLIstrCount = 0; // get ready for new input... reset strCount - m_CLIinstr[0] = '\0'; // set to null to erase it - } - } -} - -void CLI::println_P(const char PROGMEM *s) -{ - strncpy_P(m_strBuf,s,m_strBufLen); - m_strBuf[m_strBufLen-1] = 0; - println(m_strBuf); -} - -void CLI::print_P(const char PROGMEM *s) -{ - strncpy_P(m_strBuf,s,m_strBufLen); - m_strBuf[m_strBufLen-1] = 0; - print(m_strBuf); -} - -#endif // SERIALCLI diff --git a/firmware/open_evse/serialcli.h b/firmware/open_evse/serialcli.h deleted file mode 100644 index 17be5a39..00000000 --- a/firmware/open_evse/serialcli.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#ifdef SERIALCLI -#define CLI_BUFLEN 20 -class CLI { - char m_CLIinstr[CLI_BUFLEN]; // CLI byte being read in - int m_CLIstrCount; //CLI string counter - char *m_strBuf; - int m_strBufLen; - - void info(); -public: - CLI(); - void Init(); - void println(char *s) { - Serial.println(s); - } - void println_P(const char PROGMEM *s); - void print(char *s) { - Serial.print(s); - } - void print_P(const char PROGMEM *s); - void printlnn(); - void flush() { - Serial.flush(); - } - void getInput(); - uint8_t getInt(); -}; - - - -extern CLI g_CLI; -#endif // SERIALCLI