From 90f874b599c006e68145160f30fc663075ec36ca Mon Sep 17 00:00:00 2001 From: Daniel Mohns Date: Wed, 20 Dec 2023 11:45:54 +0100 Subject: [PATCH] Revert "Factory setting mode (#140)" (#146) This reverts commit 36472224bf68d7266c0a5ee52bdc03a524dc1279. --- firmware/src/keypad.hpp | 172 ++++-------------------------- firmware/src/mem_operation.hpp | 2 - firmware/src/opaygo_token.hpp | 2 + firmware/src/token_management.hpp | 3 - 4 files changed, 22 insertions(+), 157 deletions(-) diff --git a/firmware/src/keypad.hpp b/firmware/src/keypad.hpp index 8aa36e6..6a3a08b 100644 --- a/firmware/src/keypad.hpp +++ b/firmware/src/keypad.hpp @@ -10,8 +10,6 @@ // OpenSmartMeter libraries #include "led_buzzer.hpp" -#include "time_management.hpp" -#include "token_management.hpp" #define STAR_KEY -1 #define HASH_KEY -2 @@ -31,146 +29,6 @@ byte colPins[COLS] = {PA7, PA6, PA5, PC13}; Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); -void FactorySetting() { - lcd.clear(); - lcd.setCursor(0, 0); - data_count = 0; - lcd_count = 8; - dt = 0; - switch (setting_mode) { - case 1: - lcd.println( - "001:Reinitialisation 011:Configuration 021:Change password"); - setting_mode = 2; - break; - - case 2: // Reinitialize values - if (sts_data == "001") { - fault = 0; - billing = 0.0; - true_power = 0.0; - ENERGY = 0.0; - freq = 0.0; - curr = 0.0; - powerFactor = 0.0; - mains_input_value = 0.0; - - InvalidTokenCount = 0; - TokenCount = 1; - UsedTokens = 0; - PAYGEnabled = true; - ActiveUntil = 0; - TokenEntryLockedUntil = 0; - nbDisconnections = 0; - StoreActivationVariables(); - - topup = 0.0; - topupnew = 0; - - warntime = 0; - warn_now = 0; - - timeInitializationRtc = 0; - hours = 0; - minutes = 0; - seconds = 0; - rtcday = 0; - nw_month_cnt = 0; - rtcmonth = 0; - rtcnewmonth = 0; - billing_date = 0; - - thingsboard_check = 0; - - lastmonth_KWH = 0.0; - initializeTime(); - - lcdtime_now = 0; - prev_lcdtime = 0; - cnt = 0; - lcd_count = 0; - data_count = 0; - dt = 0; - parameters = 0; - token_used = 0; - - sts_eeprom_fetched = 0; - token_eeprom_location = 20; - eeprom_location_cnt = 40; - - sts_value = 0; - sts_mode = 0; - - lcd.println("Values reinitialize"); - delay(2000); - lcd.clear(); - lcd.setCursor(0, 0); - setting_mode = 0; - } - - if (sts_data == "011") { // Configure mode - lcd.println("112:STS 122:Energy-based 132:Timed-based"); - setting_mode = 3; - } - - if (sts_data == "021") { // Change Password - lcd.println("Old password: "); - setting_mode = 4; - } - break; - - case 3: - if (sts_data == "112") { - Mode_select = 1; // For STS Mode (Energy-based) - lcd.println("configured to STS Mode"); - delay(2000); - lcd.clear(); - lcd.setCursor(0, 0); - } - - if (sts_data == "122") { - Mode_select = 2; // For OpenPaygo Energy-based - lcd.println("configured to OPaygo Energy-based Mode"); - delay(2000); - lcd.clear(); - lcd.setCursor(0, 0); - } - - if (sts_data == "132") { - Mode_select = 3; // For OpenPaygo Time-based - lcd.println("configured to OPaygo Time-based Mode"); - delay(2000); - lcd.clear(); - lcd.setCursor(0, 0); - } - setting_mode = 0; - break; - - case 4: // Enter new password - if (sts_data == password) { - lcd.println("New password: "); - setting_mode = 5; - } - break; - - case 5: // confirm new password - new_password = sts_data; - lcd.println("confirm new password: "); - setting_mode = 6; - break; - - case 6: // Password Changed - if (sts_data == new_password) { - password = new_password; - lcd.println("password changed "); - delay(2000); - lcd.clear(); - lcd.setCursor(0, 0); - setting_mode = 0; - } - break; - } -} // For STS void STS_keypad() { @@ -186,11 +44,9 @@ void STS_keypad() { lcd.setCursor(0, 0); sts_mode = 1; if (customKeypad.getState() == HOLD) { - lcd.println("Enter Password to start factory setting: "); - setting_mode = 1; + lcd.println("Password: "); } else { lcd.print("TOKEN: "); - setting_mode = 0; } } @@ -240,13 +96,25 @@ void STS_keypad() { } } - if (data_count < 19 && data_count >= 3) { - if (setting_mode == 1) { - if (sts_data == password) { - FactorySetting(); - } - } else if (setting_mode > 1) { - FactorySetting(); + if (data_count < 19 && data_count > 3) { + if (sts_data == password) { + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("MODE: "); + data_count = 0; + lcd_count = 8; + dt = 0; + } + if (sts_data == "112") { + Mode_select = 1; // For STS Mode (Energy-based) + } + + if (sts_data == "122") { + Mode_select = 2; // For OpenPaygo Energy-based + } + + if (sts_data == "132") { + Mode_select = 3; // For OpenPaygo Time-based } } } diff --git a/firmware/src/mem_operation.hpp b/firmware/src/mem_operation.hpp index 815364d..cb9378d 100644 --- a/firmware/src/mem_operation.hpp +++ b/firmware/src/mem_operation.hpp @@ -29,8 +29,6 @@ uint32_t ActiveUntil = 0; uint32_t TokenEntryLockedUntil = 0; uint8_t nbDisconnections = 0; -int InvalidTokenCount = 0; - void LoadActivationVariables() { TokenCount = mem.readInt(TokenCount_eeprom_location); // We load TokenCount (& diff --git a/firmware/src/opaygo_token.hpp b/firmware/src/opaygo_token.hpp index 5777ad4..3ab7e72 100644 --- a/firmware/src/opaygo_token.hpp +++ b/firmware/src/opaygo_token.hpp @@ -25,6 +25,8 @@ extern "C" { # define TOKEN_LENGTH 9 #endif +int InvalidTokenCount = 0; + bool TokenEntryAllowed() { if (TokenEntryLockedUntil > GetTimeInSeconds()) { return false; diff --git a/firmware/src/token_management.hpp b/firmware/src/token_management.hpp index b7563df..2bb7c0b 100644 --- a/firmware/src/token_management.hpp +++ b/firmware/src/token_management.hpp @@ -19,7 +19,6 @@ byte dt = 0; byte parameters = 0; byte token_used = 0; String password = "1234"; -String new_password = "1234"; // for meter unsigned long sts_eeprom_fetched = 0; @@ -29,8 +28,6 @@ unsigned long eeprom_location_cnt = 40; unsigned long sts_value = 0; unsigned long sts_mode = 0; unsigned long Mode_select = 0; -unsigned long setting_mode = - 0; // when the value is 1 we are in Factory Setting Mode void check_tokenused() { token_eeprom_location = mem.readLong(eeprom_location_cnt);