// ------------------------------------------------ --------------------------------
// Project constants that describe the specifics of the CONFIGURATION TN
// ------------------------------------------------ --------------------------------
#ifndef Constant_h
#define Constant_h
#include " Config.h " // Catch the configuration right away
#include " Util.h "

// OPTIONS FOR COMPILING THE PROJECT --------------------------------------------- ----------
#define VERSION " 1.070 " // Firmware version
#define VER_SAVE 141      // Version of the format of the stored data in I2C memory
#ifndef UART_SPEED
#define UART_SPEED 115200 // Debug port speed
#endif
#ifdef DEBUG_NATIVE_USB // Where to output debugging
#define SerialDbg SerialUSB
#else
#define SerialDbg Serial
#endif
// #define LOG // Sends a web server log to the serial port (requests are logged)
#define FAST_LIB                     // use the dopped ezernet library Usually used
#define TIME_ZONE 3                  // DEFAULT time zone correction
#define NTP_SERVER " time.nist.gov " // NTP server for synchronizing time by DEFAULT (preparing to disable the bourgeois Internet - "ntp2.stratum2.ru")
#define NTP_SERVER_LEN 60            // maximum length of the NTP server address
#define NTP_PORT 123
#define NTP_LOCAL_PORT 8888         // local port that will be listened for UDP packets of the NTP server
#define NTP_REPEAT 3                // Number of attempts of NTP server requests
#define NTP_REPEAT_TIME 1000        // (ms) Time between retries of ntp packets
#define PING_SERVER " 192.168.0.1 " // ping server by DEFAULT
#define WDT_TIME 10                 // Watchdog period of the second timer but no more than 16 seconds !!! IF set to 0 then Watchdog will be disabled !!!
#ifndef INDEX_FILE
#define INDEX_FILE " index.html " // default start file for a large face
#endif
#define INDEX_MOB_FILE INDEX_FILE   // default start file for the mobile face
#define MOB_PATH " / mob / "        // Path to the mobile face
#define HEADER_BIN " HP-SAVE-DATA " // The title (beginning) of the file when saving the settings. Required to search for data in the data buffer when recovering from a file
#define MAX_LEN_PM 250              // maximum length of a string parameter in a request (boiler schedule 175 bytes) profile description encoding 40 letters one letter 6 bytes (double encoding)
#ifndef CHART_POINT                 // You can define your own special chart size in your config
#define CHART_POINT 300             // Maximum number of graph points, one dot is 2 bytes * number of graphs // 300 - works
#endif
#ifndef ADC_PRESCAL
#define ADC_PRESCAL 2 // ADCClock = MCK / ((PRESCAL + 1) * 2)
#endif

// NETWORK SETTINGS ---------------------------------------------- ----------------
// By default and in demo mode (valid there and there)
// In operating mode, the settings are taken from EEPROM, if it was not possible to read, then the default settings apply
byte defaultMAC[] = {0xDE, 0xA1, 0x1E, 0x01, 0x02, 0x03}; // do not change
const uint16_t defaultPort = 80;

// Byte bit macros, used for flags
#define GETBIT (b, f)((b & (1 << (f))) ? true : false) // get the bit status
#define SETBIT1 (b, f)(b | = (1 << (f)))               // set the bit to 1
#define SETBIT0 (b, f)(b & = ~(1 << (f)))              // set the bit to 0

// ------------------- SPI ---------------------------- ------
// memory card
#define SD_REPEAT 3 // Number of attempts to read the card, open files, if it fails, switch to work without a card

// W5200 chip (more precisely, any chip used)
#ifndef W5200_THREAD
#define W5200_THREAD 3 // The number of threads for the w5200 network chip is valid for 1-4 threads, most likely 4 is not enough space in the RAM
#endif
#define W5200_NUM_PING 4     // The number of ping attempts before determining the loss of communication
#define W5200_TIME_PING 1000 // ms Time between ping attempts (if not luck)
#define W5200_MAX_LEN 2048   // = W5100.SSIZE // Maximum buffer length, determined by W5200 no more than 2048 bytes
#define W5200_NUM_LINK 2     // The number of attempts to reset the w5500 chip and check for a connection (cable stuck) is used to initialize the chip
#define W5200_TIME_LINK 4000 // Maximum time to wait for a connection to be established (raising Link) a plugged in cable is used to initialize the chip (ms)
#define W5200_TIME_WAIT 3000 // Mutex capture timeout (thread switching) ms
// #define W5200_STACK_SIZE 230 renamed and moved to config // Stack size (words !!! - 4 bytes) before trimming stacks was 340 - works
#define W5200_SPI_SPEED SPI_RATE          // THIS DIVIDER (SPI_RATE is defined in w5100.h) !!! SPI frequency w5200 = 84 / W5200_SPI_SPEED i.e. 2-42MHz 3-28MHz 4-21MHz 6-14MHz Range 2-6
#define W5200_SOCK_SYS (MAX_SOCK_NUM - 1) // The system socket number that is not used in the web server, this is the last socket, DO NOT CHANGE
#define W5200_RTR (2 * 0x07D0)            // timeout time in 100 μs intervals (default 200ms (100us X 2000 (0x07D0))) is relevant for the commands CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP
#define W5200_RCR (0x04)                  // number of retransmissions (default 0x08 times))
#define MAIN_WEB_TASK 0                   // which stream of the web server is the main one (the stream in which MQTT and notifications are sent), usually 0

// ------------------- SERIAL ---------------------------- ----
// Nextion display
// #define NEXTION_DEBUG // Display information in the debug port from the display
#define NEXTION_PORT Serial1    // Hardware port where the display is attached
#define NEXTION_PORT_SPEED 9600 // Port speed, baud
#define NEXTION_UPDATE 5000     // Time for updating information on the Nextion display (ms)
#define NEXTION_BOOT_TIME 300   // Time to load the display, if the display is not found during reset, increase (ms)
#define NEXTION_READ 50         // Nextion display polling time (ms) parsing the input queue

// Configure Modbus for inverter and SDM counter
#ifndef MODBUS_PORT_NUM
#define MODBUS_PORT_NUM Serial2       // Hardware port where Modbus is attached
#define MODBUS_PORT_SPEED 9600        // Port speed where the frequency counter and counter are attached
#define MODBUS_PORT_CONFIG SERIAL_8N1 // Port configuration where the frequency counter and counter are attached
#define MODBUS_TIME_WAIT 2000         // Mutex capture timeout for modbus ms
#ifndef MODBUS_TIME_TRANSMISION
#define MODBUS_TIME_TRANSMISION 4 // The pause (msec) between the request and the response for modbass was 4
#endif
#endif
// #define MODBUS_FREERTOS // Set the lib to multitask must be defined in the lib.
#if RADIO_SENSORS_PORT == 2
#define RADIO_SENSORS_SERIAL Serial2 // Hardware port
#elif RADIO_SENSORS_PORT == 3
#define RADIO_SENSORS_SERIAL Serial3 // Hardware port
#endif
#define RADIO_LOST_TIMEOUT 30 * 60 * 1000 // after how many to assume that the connection is lost with the sensor, ms

// Global parameters of the inverter inverter on modbas depend on the compressor !!!!!!!!!
#define FC_MODBUS_ADR 1         // Address of the frequency converter on the bus must not match SMD_MODBUS_ADR
#define FC_TIME_READ (8 * 1000) // Inverter polling time in Moscow time (it was 6)
#define FC_NUM_READ 4           // The number of attempts to read the inverter (in a row) by modbass before it stopped the VT in error
#define FC_DELAY_REPEAT 40      // ms The time between REPEAT read attempts was 100
#define FC_DELAY_READ 5         // ms The time between consecutive requests was 20
#define FC_WRITE_READ 10        // ms Time between sequential recording

// Global counter variables SDM120 on modbas
// communication settings with the counter by default (out of the box, see instructions) is required for programming it to work
#define DEFAULT_SDM_SPEED 2400   // Baud rate for default counter
#define DEFAULT_SDM_MODBUS_ADR 1 // The address of the counter on the bus must not coincide with FC_MODBUS_ADR when programming the inverter OFF (address 1)
// Required communication settings (after programming)
#define SDM_SPEED 2      // counter speed in constants 0 = 2400 bps. 1 = 4800 bps. 2 = 9600 bps 5 = 1200 bps Baud rates must match, see MODBUS_PORT_SPEED
#define SDM_MODBUS_ADR 2 // The counter address on the bus must not match FC_MODBUS_ADR
#ifndef SDM_READ_PERIOD
#define SDM_READ_PERIOD (10 * 1000) // Counter polling time in Moscow time
#endif
#define SDM_NUM_READ 3       // The number of attempts to read the counter (in a row) by modbass before it is turned off (no error is generated)
#define SDM_DELAY_REPEAD 100 // ms The time between REPEAT read attempts was 40 (less does not make sense - the counter may not be in time)
// #define SDM_BLOCK // Block the counter reading when the connection is lost, otherwise attempts will be made to restore the connection periodically

// ------------------- TIME & DELAY -------------------------- --------
// Times and delays
#define cDELAY_DS1820 750 // ms. DS1820 read delay (conversion time)
#ifndef TIME_READ_SENSOR
#define TIME_READ_SENSOR 4000 // ms. Sensor Polling Period
#endif
#define TIME_WEB_SERVER 2                // ms. Web servera survey period was 5
#define TIME_CONTROL (10 * 1000)         // ms. Heat pump control period (hysteresis control cycle)
#define TIME_EEV (1 * 1000)              // ms. VUpdateEEV task period in transient VT states
#define TIME_EEV_BEFORE_PID (4 * 1000)   // ms.
#define TIME_COMMAND 500                 // ms. Period of analysis of VT control commands (rather a pause before processing a command)
#define TIME_I2C_UPDATE (60 * 60) * 1000 // ms. Time for updating the internal clock according to I2C hours (if of course it is necessary)
#define TIME_MESSAGE_TEMP 300            // 1/10 seconds, Checking boundary temperatures for notifications
#define TIME_LED_OK 1500                 // LED blinking period at OK (ms)
#define TIME_LED_ERR 200                 // The blinking period of the LED on error (ms).
#define TIME_BEEP_ERR 1000               // Period of the sound signal upon error, ms
#define cDELAY_START_MESSAGE 60          // Delay (sec) after starting to send messages
#define UPDATE_HP_WAIT_PERIOD 5000       // Period of vUpdate call while waiting or error, ms
#define NO_POWER_ON_DELAY_CNT 10         // Delay on after power on, * TIME_READ_SENSOR

// ------------------- I2C ---------------------------- ------
// i2c devices I2C_EEPROM_64KB and I2C_FRAM_MEMORY The size and type of memory are defined in config.h since he often changes
#define I2C_SPEED twiClock400kHz // I2C bus frequency
#define I2C_NUM_INIT 3           // Number of bus initialization attempts
#define I2C_TIME_WAIT 2000       // I2C bus mutex capture timeout ms
#define I2C_ADR_RTC 0x68         // rtc chip address on the I2C bus
#define I2C_ADR_DS2482 0x18      // OneWire chip address on I2C bus 3-wire
#define I2C_ADR_DS2482_2 0x19    // OneWire chip address on the 2nd I2C bus
#define I2C_ADR_DS2482_3 0x1A    // OneWire chip address on the 3rd I2C bus
#define I2C_ADR_DS2482_4 0x1B    // OneWire chip address on the 4th I2C bus

// ------------------------------------------------ -------------------------------------------------- ------------------------
#ifdef I2C_EEPROM_64KB
// Start addresses ---------------------------------------------- -------
// MEMORY CARD in i2c chip with a capacity of 64 kbytes
// 0x0000 - I2C_COUNT_EEPROM storage of counters, maximum size 0x79 (127) bytes. 52 bytes are currently in use
// 0x0080 - I2C_SETTING_EEPROM storage of VT settings maximum size 0x980 (2432) bytes. Currently using 1095 bytes
// 0x0A00 - I2C_PROFILE_EEPROM storage of profiles, the maximum size is 0x1000 (4096) bytes. Number of profiles 10 pcs. Profile size now 301 bytes (3010)
// 0x1A00 - I2C_SCHEDULER_EEPROM for storing schedules, maximum 0x5FE (1534) bytes (now 377 bytes)
// 0x1FFE - I2C_JOURNAL_EEPROM log storage log size area must be a multiple of W5200_MAX_LEN
#define I2C_PROFIL_NUM 10                                        // Maximum number of profiles to be stored
#define I2C_COUNT_EEPROM 0x0000                                  // Address inside the eeprom chip from where the counters are written from the beginning of the chip 0
#define I2C_SETTING_EEPROM 0x0080                                // Address inside the eeprom chip from where the VT settings are written and before it the counters are written
#define I2C_PROFILE_EEPROM 0x0A00                                // Address inside the eeprom chip from where profiles are (address of the first profile)
#define I2C_SCHEDULER_EEPROM 0x1A00                              // Address inside the eeprom chip for Schedules
#define MAX_CALENDARS 9                                          // maximum 9
#define TIMETABLES_MAXSIZE 500                                   // bytes
#define DAILY_SWITCH_MAX 10                                      // Maximum number of entries for daily turning on devices (DailySwitch). MAX = 10
#define I2C_JOURNAL_EEPROM 0x1FFE                                // The address from which the log starts in the i2c memory, in the end there is a sign of formatting the log. Log Length JOURNAL_LEN
#define I2C_JOURNAL_START (I2C_JOURNAL_EEPROM + 2)               // Address from which DATA starts the log in i2c memory ATTENTION - 2 bytes is a sign of log formatting
#The define I2C_JOURNAL_EEPROM_NEXT(I2C_MEMORY_TOTAL * 1024 / 8) // Address after the log size = EEPROM
// Journal
#define JOURNAL_LEN ((I2C_JOURNAL_EEPROM_NEXT - I2C_JOURNAL_START) / W5200_MAX_LEN * W5200_MAX_LEN) // Journal size - rounding an integer number of pages W5200_MAX_LEN
#define I2C_JOURNAL_HEAD (0x01)                                                                     // Sign of the head of the journal
#define I2C_JOURNAL_TAIL (0x02)                                                                     // Log Tail Sign
#define I2C_JOURNAL_FORMAT (0xff)                                                                   // The character that fills the log when formatting
#define I2C_JOURNAL_READY (0x55aa)                                                                  // A sign of creating a journal - if it is not at I2C_JOURNAL_START-2 then you need to format the journal (initialization)
#else                                                                                               // 4KB eeprom
// 0x0000 - I2C_COUNT_EEPROM storage of counters, maximum size 0x79 (127) bytes. 52 bytes are currently in use
// 0x0080 - I2C_SETTING_EEPROM storage of VT settings maximum size 0x580 (1408) bytes.
// 0x0600 - I2C_PROFILE_EEPROM storage of profiles, the maximum size is 0x860 (2144) bytes.
// 0x0E60 - I2C_SCHEDULER_EEPROM storing schedules, maximum 0x1A0 (416) bytes
#define I2C_PROFIL_NUM 6                                                                            // Maximum number of profiles to be stored
#define I2C_COUNT_EEPROM 0x00                                                                       // Address inside the eeprom chip from where the counters are written from the beginning of the chip 0
#define I2C_SETTING_EEPROM 0x080                                                                    // Address inside the eeprom chip from where the VT settings are written and before it the counters are written
#define I2C_PROFILE_EEPROM 0x600                                                                    // Address inside the eeprom chip from where profiles are (address of the first profile)
#define I2C_SCHEDULER_EEPROM 0xE60                                                                  // Address inside the eeprom chip for Schedules
#define MAX_CALENDARS 4                                                                             // maximum 9
#define TIMETABLES_MAXSIZE 214                                                                      // bytes
#define DAILY_SWITCH_MAX 5                                                                          // Maximum number of daily device enable entries (DailySwitch)
#define JOURNAL_LEN (2 * W5200_MAX_LEN)                                                             // The size of the system log MUST BE a multiple of W5200_MAX_LEN, Increase accurately, may not have enough memory - hangs when loading
#endif
// Type of save record, 16bit
#define SAVE_TYPE_END 0
#define SAVE_TYPE_sTemp -1
#define SAVE_TYPE_sADC -2
#define SAVE_TYPE_sInput -3
#define SAVE_TYPE_sFrequency -4
#define SAVE_TYPE_sIP -5
#define SAVE_TYPE_dEEV -6
#define SAVE_TYPE_dSDM -7
#define SAVE_TYPE_clMQTT -8
#define SAVE_TYPE_PwrCorr -9
#define SAVE_TYPE_LIMIT -100

// ------------------- EEV ---------------------------- ------
// Constants of the phases of the movement of the electric propulsion, three options (do not change the constants of options!)
#define PHASE_4 0  // 4 phases, step
#define PHASE_8 1  // 8 phases, step
#define PHASE_8s 2 // 8 phases, half-step main option (pav2000)

#ifndef DEFAULT_RULE_EEV
#define DEFAULT_RULE_EEV 0   // Default formula
#define DEFAULT_FREON_TYPE 0 // Default Front Type
#define DEFAULT_OVERHEAT 400 // Overheating by default (hundredths of a degree)
#endif
#define EEV_MAX_INT_PID 1 // Maximum contribution of the integral component in steps

#define EEV_START_POS_LOW_TEMP 1000  // Lower limit temperature for setting the position at start, in hundred
#define EEV_START_POS_HIGH_TEMP 4500 // Upper limit temperature for setting position at start, in hundred
#define EEV_STAT_ARRAY_SIZE 4
#ifndef EEV_SET_ZERO_OVERRIDE
#define EEV_SET_ZERO_OVERRIDE 40 // Add to full close when zeroing , steps
#endif
#ifndef EEV_OVERHEAT2_CRITICAL
#define EEV_OVERHEAT2_CRITICAL 30 // Critical value of superheat 2, hundredths of a degree
#endif

// ----------------------- EVI ------------------------ ------
#define EVI_TEMP_CON 4000 // Condenser temperature to enable EVI
#define EVI_TEMP_EVA 300  // Evaporator temperature to enable EVI

// ------------------- GENERAL SETTINGS --------------------------- -------
#define TEMP_WEATHER 0                      // Temperature at which the target flow temperature for heating is set (weather dependence)
#define MIN_WEATHER (7 * 100)               // Minimum feed temperature for weather dependence
#define MAX_WEATHER (50 * 100)              // Maximum flow temperature during weather dependence
#define HYSTERESIS_RHEAD 20                 // Hysteresis of the additional heating ten (subtracted from the target) in hundredths of a degree
#define HYSTERESIS_RBOILER 30               // Hysteresis of the operation of the additional DHW heating ten (subtracted from the target) in hundredths of a degree
#define HYSTERESIS_BoilerTogetherHeatSt 500 // Hysteresis of co-heating the boiler with heating in hundredths of a degree
#define HYSTERESIS_BoilerTogetherHeatEn 200 // Hysteresis of co-heating the boiler with heating in hundredths of a degree
#define HYSTERESIS_BoilerAddHeat 300        // Hysteresis of boiler heating to a preheat temperature, in hundredths of a degree
#define HYSTERESIS_HeatFloor 30             // Hysteresis for separate control of the underfloor heating relay
#define SALLMONELA_DAY 3                    // Day when the water disinfection algorithm is activated (Monday 1 Sunday 7)
#define SALLMONELA_HOUR 1                   // Hour when the water disinfection algorithm is turned on (should be 0 minutes)
#define SALLMONELA_TEMP (70 * 100)          // Temperature that is maintained for disinfection (hundredths of a degree)
#define SALLMONELA_TIME (240 * 60)          // Maximum cycle time (sec), so that the cycle does not last indefinitely if it is not possible to achieve SALLMONELA_TEMP
// #define SALLMONELA_HARD // If defined, then maintaining the temperature SALLMONELA_TEMP works until the end of the SALLMONELA_TIME time, if it is NOT DEFINED then shutting down immediately after reaching SALLMONELA_TEMP but the cycle does not exceed SALLMONELA_TIME
// #define NIGHT_START_HOUR 23 // Beginning of the night tariff
// #define NIGHT_END_HOUR 7 // End of exact tariff
// Heat dissipation during DHW heating
#ifndef BOILER_TEMP_FEED_RESET
#define BOILER_TEMP_FEED_RESET 100 // How much does the supply temperature exceed the target during DHW heating, at which the heat is released into the heating system
#endif
#ifndef BOILER_TEMP_COMP_RESET
#define BOILER_TEMP_COMP_RESET 500 // How much is the discharge temperature (TCOMP) lower than the maximum when heating the DHW, during which the heat is released into the heating system
#endif
// ------------------- SENSOR TEMP --------------------------- -------
#ifndef T_NUMSAMLES
#define T_NUMSAMLES 1        // Number of values ​​for averaging temperature readings
#define GAP_TEMP_VAL 300     // Permissible difference (in hundredths of C) of readings between two readings (anti-interference) - no error occurs when overshot, but data is skipped.
#define GAP_NUMBER 3         // The maximum number of consecutive readings exceeding GAP_TEMP_VAL, after which these readings are issued as valid
#define GAP_TEMP_VAL_CRC 200 // Sensors with a flag ignore CRC. The permissible difference (in hundredths of C) of the readings between two readings (anti-interference) - no error occurs when overshot, but data is skipped.
#define GAP_NUMBER_CRC 5     // Sensors with a flag ignore CRC. The maximum number of consecutive readings exceeding GAP_TEMP_VAL, after which these readings are issued as valid
#endif
#define MAX_TEMP_ERR 700     // Maximum systematic error of the temperature sensor (hundredths of a degree)
#define NUM_READ_TEMP_ERR 10 // The number of errors in a row reading the temperature sensor after which it is considered that the sensor is not working
#define RES_ONEWIRE_ERR 3    // Number of attempts to reset the temperature sensors before generating a bus error

#define BASE_TIME_READ 10 // 20 // Frequency sensors - time (sec) at which the number of pulses is measured, at the end there is a conversion to frequency

#define UPDATE_IP 120 // Time since the last packet was received from the remote sensor (in seconds) after which it is considered that the sensor is inactive and is not used in calculations

// ------------------- MQTT ---------------------------- ------
#define MQTT_REPEAT        // Try to reconnect to the server
#define MQTT_NUM_ERR_OFF 8 // The number of sending errors in a row at which the MQTT sending service is disabled (the flag is reset)

#define DEFAULT_PORT_MQTT 1883                   // Default MQTT server port address
#define DEFAULT_TIME_MQTT (3 * 60)               // period of sending to the server in seconds. 10 ... 60,000
#define DEFAULT_ADR_MQTT " mqtt.thingspeak.com " // Default MQTT server address
#define DEFAULT_ADR_NARMON " narodmon.ru "       // Address of the popular monitoring server
#define TIME_NARMON (5 * 60)                     // (sec) Do not set the period of sending to the national monitoring (constant) for less than 5 minutes

// ------------------- HEAP ---------------------------- ------
#define PASS_LEN 10          // Maximum password length for entering the controller
#define NAME_USER " user "   // username
#define NAME_ADMIN " admin " // admin name
// #define FILE_STATISTIC "statistic.csv" // name of the statistics file for the CURRENT period

#define HOUR_SIGNAL_LIFE 12 // Hour when a life signal is generated

#define ATOF_ERROR -9876543.00 // Error code converting a string to float
#define K_VCC_POWER 338.2      // conversion factor of the ADC to volts for power control (metering of the support) (UT71E results of spare parts 284.02 ТН 338.2)
#define HEAT_CAPACITY 4174     // heat capacity of the liquid in the contour by default at 30 degrees [Cp, J / (kg · deg)]

// ----------------------- WEB ------------------------ ----
const char WEB_HEADER_OK_CT[] = " HTTP / 1.1 200 OK \ r \ n Access-Control-Allow-Origin: * \ r \ n Content-Type: ";
const char WEB_HEADER_TEXT_ATTACH[] = " text / plain \ r \ n Content-Disposition: attachment; filename = \" ";
const char WEB_HEADER_BIN_ATTACH[] = " application / x-binary \ r \ n Content-Disposition: attachment; filename = \" ";
const char WEB_HEADER_TXT_KEEP[] = " text / html \ r \ n Connection: keep-alive ";
const char WEB_HEADER_END[] = " \ r \ n \ r \ n ";
const char *HEADER_FILE_NOT_FOUND = {" HTTP / 1.1 404 Not Found \ r \ n \ r \ n <html> \ r \ n <head> <title> 404 NOT FOUND </title> <meta charset = \" utf-8 \ " / > </ head> \ r \ n<body><h1> 404 NOT FOUND</ h1></ body> \ r \ n</ html> \ r \ n \ r \ n " };
                                         // const char * HEADER_FILE_WEB = {"HTTP / 1.1 200 OK \ r \ nContent-Type: text / html \ r \ nConnection: keep-alive \ r \ n \ r \ n"}; // CACHE DO NOT USE
                                         const char *HEADER_FILE_WEB = {" HTTP / 1.1 200 OK \ r \ n Content-Type: text / html \ r \ n Connection: keep-alive \ r \ n Cache-Control: max-age = 3600, must-revalidate \ r \ n \ r \ n "}; // CACHE USE
const char *HEADER_FILE_CSS = {" HTTP / 1.1 200 OK \ r \ n Content-Type: text / css \ r \ n Connection: keep-alive \ r \ n Cache-Control: max-age = 3600, must-revalidate \ r \ n \ r \ n "};                                           // CACHE USE
const char *HEADER_ANSWER = {" HTTP / 1.1 200 OK \ r \ n Content-Type: text / ajax \ r \ n Access-Control-Allow-Origin: * \ r \ n \ r \ n "};                                                                                           // start of the response to the request
static uint8_t fWebUploadingFilesTo = 0;                                                                                                                                                                                                // Where to load the files: 1 - SPI flash, 2 - SD card

// SOPC SAM3x Power Controller Register Constants ---------------------------------------
// SMMR register
// Kernel power control level
#define SUPC_SMMR_SMTH_1_9V (0x0u << 0)
#define SUPC_SMMR_SMTH_2_0V (0x1u << 0)
#define SUPC_SMMR_SMTH_2_1V (0x2u << 0)
#define SUPC_SMMR_SMTH_2_2V (0x3u << 0)
#define SUPC_SMMR_SMTH_2_3V (0x4u << 0)
#define SUPC_SMMR_SMTH_2_4V (0x5u << 0)
#define SUPC_SMMR_SMTH_2_5V (0x6u << 0)
#define SUPC_SMMR_SMTH_2_6V (0x7u << 0)
#define SUPC_SMMR_SMTH_2_7V (0x8u << 0)
#define SUPC_SMMR_SMTH_2_8V (0x9u << 0)
#define SUPC_SMMR_SMTH_2_9V (0xAu << 0)
#define SUPC_SMMR_SMTH_3_0V (0xBu << 0)
#define SUPC_SMMR_SMTH_3_1V (0xCu << 0)
#define SUPC_SMMR_SMTH_3_2V (0xDu << 0)
#define SUPC_SMMR_SMTH_3_3V (0xEu << 0)
#define SUPC_SMMR_SMTH_3_4V (0xFu << 0)
// Power monitoring time
#define SUPC_SMMR_SMSMPL_SMD (0x0u << 8) // not allowed
#define SUPC_SMMR_SMSMPL_CSM (0x1u << 8) // continuously
#define SUPC_SMMR_SMSMPL_32SLCK (0x2u << 8)
#define SUPC_SMMR_SMSMPL_256SLCK (0x3u << 8)
#define SUPC_SMMR_SMSMPL_2048SLCK (0x4u << 8)
#define SUPC_SMMR_SMRSTEN (0x1u << 12) / ** <\ brief(SUPC_SMMR) Supply Monitor Reset Enable * /
#define SUPC_SMMR_SMRSTEN_NOT_ENABLE (0x0u << 12) / ** <\ brief(SUPC_SMMR) the core reset signal "vddcore_nreset" is not affected when a supply monitor detection occurs.* /
#define SUPC_SMMR_SMRSTEN_ENABLE (0x1u << 12) / ** <\ brief(SUPC_SMMR) the core reset signal, vddcore_nreset is asserted when a supply monitor detection occurs.* /
#define SUPC_SMMR_SMIEN (0x1u << 13) / ** <\ brief(SUPC_SMMR) Supply Monitor Interrupt Enable * /
#define SUPC_SMMR_SMIEN_NOT_ENABLE (0x0u << 13) / ** <\ brief(SUPC_SMMR) the SUPC interrupt signal is not affected when a supply monitor detection occurs.* /
#define SUPC_SMMR_SMIEN_ENABLE (0x1u << 13) / ** <\ brief(SUPC_SMMR) the SUPC interrupt signal is asserted when a supply monitor detection occurs.* /
// MR register
#define SUPC_MR_KEY_Pos 24
#define SUPC_MR_KEY_Msk (0xffu << SUPC_MR_KEY_Pos) // Key for writing !!!
#define SUPC_MR_KEY (value)((SUPC_MR_KEY_Msk & ((value) << SUPC_MR_KEY_Pos)))
#define SUPC_MR_BODRSTEN (0x1u << 12) / ** <\ brief(SUPC_MR) Brownout Detector Reset Enable * /
#define SUPC_MR_BODRSTEN_NOT_ENABLE (0x0u << 12) / ** <\ brief(SUPC_MR) the core reset signal "vddcore_nreset" is not affected when a brownout detection occurs.* /
#define SUPC_MR_BODRSTEN_ENABLE (0x1u << 12) / ** <\ brief(SUPC_MR) the core reset signal, vddcore_nreset is asserted when a brownout detection occurs.* /
#define SUPC_MR_BODDIS (0x1u << 13) // Here it is / ** <\ brief (SUPC_MR) Brownout Detector Disable * /
#define SUPC_MR_BODDIS_ENABLE (0x0u << 13) / ** <\ brief(SUPC_MR) the core brownout detector is enabled.* /
#define SUPC_MR_BODDIS_DISABLE (0x1u << 13) / ** <\ brief(SUPC_MR) the core brownout detector is disabled.* /

#ifndef FORMAT_DATE_STR_CUSTOM
const char *FORMAT_DATE_STR = {" % 02d / % 02d / % 04d "};
#endif

// ------------------------------------------------ -------------------------------------------------- ------------------------------
// String constants reusable across all files ----------------------------------------- ---------------------------
const char *cYes = {" Yes "};
const char *cNo = {" No "};
const char *cOne = {" 1 "};
const char *cZero = {" 0 "};
const char *cOk = {" Ok "};
const char *cError = {" error "};
const char *cInvalid = {" invalid "};
const char *cStrEnd = {" \ n "};
const char *cErrorRS485 = {" % s : Read error % s , code = % d repeat ... \ n "}; // name, function, code
const char *cErrorMutex = {" Function % s : % s , mutex is buzy \ n "};           // function, mutex
const char *cAddHeat = {" + "};                                                   // Icon for heating hot water
const char http_get_str1[] = " GET ";
const char http_get_str2[] = " HTTP / 1.0 \ r \ n Host: ";
const char http_get_str3[] = " \ r \ n Accept: text / html \ r \ n \ r \ n ";
const char http_key_ok1[] = " HTTP / "; // "1.1"
const char http_key_ok2[] = " 200 OK \ r \ n ";
const uint8_t save_end_marker[1] = {0};
#define WEBDELIM " \ x7f " // ALT + 127 line separator on the web
const char SendMessageTitle[] = " Popular heat pump controller ";
const char SendSMSTitle[] = " Control ";

// Multitasking, dividing hardware resources
const char *nameFREERTOS = {" FreeRTOS "};  // Name of the source of the error (needed for passing to the function) - operating system
const char *nameHeatPump = {" Heat Pump "}; // Name of the heat pump (for the error log) Here you can change it
const char *MutexI2CBuzy = {" I2C "};
const char *MutexModbusBuzy = {" Modbus "};
const char *MutexWebThreadBuzy = {" WebThread "};
const char *MutexSPIBuzy = {" SPI "};
const char *MutexCommandBuzy = {" Command "};

// Description of the names of the ERV parameters for the get_pEEV functions set_pEEV
const char *eev_POS = {" POS "};             // Position ERV steps
const char *eev_POSp = {" POSp "};           // Position ERV%
const char *eev_POSpp = {" POSpp "};         // Position ERV steps +%
const char *eev_OVERHEAT = {" OH "};         // The current overheating of the ERV, if
const char *eev_ERROR = {" ERROR "};         // ERV error
const char *eev_MIN = {" MIN "};             // Minimum ERV
const char *eev_MAX = {" MAX "};             // Maximum ERV
const char *eev_TIME = {" TIME "};           // PID time in seconds ERV SECONDS
const char *eev_TARGET = {" TRG "};          // Overheating GOAL (hundredths of a degree)
const char *eev_tOverheatTCOMP = {" TRG2 "}; // Overheat2 target (hundredths of a degree)
const char *eev_tOverheat2_low = {" T2L "};
const char *eev_tOverheat2_low_hyst = {" T2H "};
const char *eev_tOverheatTCOMP_delta = {" TRG2D "}; // Overheat2 delta target (hundredths of a degree)
const char *eev_KP = {" KP "};                      // PID Ratio Ratio IN THOUSAND !!!
const char *eev_KI = {" KI "};                      // PID Coef integr. to configure Ki = 0 THOUSAND !!!
const char *eev_KD = {" KD "};                      // PID Coeff. Diff. IN THOUSAND !!!
const char *eev_KP2 = {" KP2 "};                    // PID Ratio Ratio IN THOUSAND !!!
const char *eev_KI2 = {" KI2 "};                    // PID Coef integr. to configure Ki = 0 THOUSAND !!!
const char *eev_KD2 = {" KD2 "};                    // PID Coeff. Diff. IN THOUSAND !!!
const char *eev_PID2_delta = {" P2D "};             // Delta for conservative PID calculations (For formula 1, this is an error in which the proportional starts to decrease)
const char *eev_PID_MAX = {" PMAX "};               // PID restriction in the steps of the EEC
const char *eev_CONST = {" CONST "};                // Overheat correction (permanent error)
const char *eev_MANUAL = {" MANUAL "};              // The number of steps to open the ERV for the rules of operation of the ERM "Manual"
const char *eev_FREON = {" FREON "};                // Freon type
const char *eev_RULE = {" RULE "};                  // The rule of the ERV
const char *eev_NAME = {" NAME "};                  // ERV name
const char *eev_NOTE = {" NOTE "};                  // ERV Description
const char *eev_REMARK = {" REMARK "};              // Description of the ERV algorithm
const char *eev_PINS = {" PINS "};                  // Listing the legs where the ERV is attached
const char *eev_cCORRECT = {" cCORRECT "};          // Flag for enabling over-correction from the temperature difference between the condenser and the evaporator
const char *eev_cDELAY = {" cDELAY "};              // Delay after compressor start, sec
const char *eev_cPERIOD = {" cPERIOD "};            // Period in ERV cycles, how much to skip
const char *eev_cDELTA = {" cD "};                  // TDIS_TCON: Discharge - condensation temperature (hundredths of a degree)
const char *eev_cDELTA_Thr = {" cDT "};             // Threshold, after exceeding which we begin to change the overheating, in hundredths of a degree
const char *eev_cOH_cDELTA_MAX = {" cDM "};         // upper limit for a proportional increase in overheating,% of OHCor_TDIS_TCON
const char *eev_cOH_MIN = {" cOH_MIN "};            // Minimum overheating (hundredths of a degree)
const char *eev_cOH_START = {" cOH_START "};        // Starting overheating (hundredths of a degree)
const char *eev_cOH_MAX = {" cOH_MAX "};            // Maximum overheating (hundredths of a degree)
const char *eev_cOH_TDELTA = {" cTDELTA "};         // Calculated Target Delta-Condensation Delta
#ifndef PID_FORMULA2
const char *eev_ERR_KP = {" ERR_KP "}; // Error (in hundredths of a degree) at which there is a decrease in the proportional component of the PID of the ERV
#endif
const char *eev_SPEED = {" SPEED "};              // The speed of the stepper motor ERV (pulses in sec.)
const char *eev_PRE_START_POS = {" PSP "};        // START-UP position ERV (THAT that at the start of the compressor during the spin)
const char *eev_START_POS = {" SP "};             // START position of ERV after compressor unwinding i.e. POSITION FROM WHICH THE WORK BEGINS passes DelayStartPos sec
const char *eev_DELAY_ON_PID = {" DOP "};         // Delay on EEV after compressor on (sec). More precisely, after reaching the working position Total time = delayOnPid + DelayStartPos
const char *eev_DELAY_START_POS = {" DSP "};      // Time after the compressor starts when the EEV reaches the start position - facilitating the start of the ERV at the beginning
const char *eev_DELAY_OFF = {" DOFF "};           // Delay closing EEV after turning off the pumps (sec). The time from the stop compressor command to closing the EEC = delayOffPump + delayOff
const char *eev_DELAY_ON = {" DON "};             // Delay between the opening (for start) of the electric propulsion and the compressor on, to equalize the pressure (sec). If the ERV shuts down when stopped
const char *eev_HOLD_MOTOR = {" HM "};            // Flag hold motor
const char *eev_PRESENT = {" PRESENT "};          // Flag of the presence of ERV in VT
const char *eev_SEEK_ZERO = {" ZERO "};           // Flag of a single search "0" ERV (only when the VT is switched on for the first time)
const char *eev_CLOSE = {" CLOSE "};              // Flag closes the ERV when the compressor is turned off
const char *eev_LIGHT_START = {" LST "};          // flag Facilitate the start of the compressor ajar ERV at the time of starting the compressor
const char *eev_START = {" START "};              // flag Always start operation of the EDS with a stratum position
const char *eev_PID_P_ON_M = {" POM "};           // PID flag proportional to dimension
const char *eev_fEEVStartPosByTemp = {" SPT "};   // flag fEEVStartPosByTemp
const char *eev_PosAtHighTemp = {" PHT "};        // PosAtHighTemp
const char *eev_fEEV_DirectAlgorithm = {" DIR "}; // flag fEEV_DirectAlgorithm
const char *eev_trend_threshold = {" TTH "};
const char *eev_trend_mul_threshold = {" TMT "};
const char *eev_DebugToLog = {" DBG "};

// Description of the MQTT parameter names for the get_paramMQTT functions set_paramMQTT
const char *mqtt_USE_TS = {" USE_TS "};                   // use flag ThingSpeak - transfer format for the client
const char *mqtt_USE_MQTT = {" USE_MQTT "};               // flag for using MQTT
const char *mqtt_BIG_MQTT = {" BIG_MQTT "};               // flag for sending ADDITIONAL data on MQTT
const char *mqtt_SDM_MQTT = {" SDM_MQTT "};               // flag of sending electric meter data to MQTT
const char *mqtt_FC_MQTT = {" FC_MQTT "};                 // flag sending inverter data to MQTT
const char *mqtt_COP_MQTT = {" COP_MQTT "};               // flag to send COP data to MQTT
const char *mqtt_TIME_MQTT = {" TIME_MQTT "};             // period of sending to the server in seconds. 10 ... 60,000
const char *mqtt_ADR_MQTT = {" ADR_MQTT "};               // server address
const char *mqtt_IP_MQTT = {" IP_MQTT "};                 // IP address of the server
const char *mqtt_PORT_MQTT = {" PORT_MQTT "};             // Server port address
const char *mqtt_LOGIN_MQTT = {" LOGIN_MQTT "};           // server login
const char *mqtt_PASSWORD_MQTT = {" PASSWORD_MQTT "};     // server password
const char *mqtt_ID_MQTT = {" ID_MQTT "};                 // Client ID on the MQTT server
                                                          // national monitoring
const char *mqtt_USE_NARMON = {" USE_NARMON "};           // flag of sending data for national monitoring
const char *mqtt_BIG_NARMON = {" BIG_NARMON "};           // flag of sending data for national monitoring, large version
const char *mqtt_ADR_NARMON = {" ADR_NARMON "};           // Address of the server of national monitoring
const char *mqtt_IP_NARMON = {" IP_NARMON "};             // IP address of the public monitoring server
const char *mqtt_PORT_NARMON = {" PORT_NARMON "};         // Port address of the public monitoring server
const char *mqtt_LOGIN_NARMON = {" LOGIN_NARMON "};       // login of the national monitoring server
const char *mqtt_PASSWORD_NARMON = {" PASSWORD_NARMON "}; // password of the public monitoring server
const char *mqtt_ID_NARMON = {" ID_NARMON "};             // Client ID on the MQTT server

// Description of the names of the parameters of the SDM counter for the functions get_paramSDM ("get_SDM"), set_paramSDM ("set_SDM")
const char *sdm_NAME = {" NAME "};         // counter name
const char *sdm_NOTE = {" NOTE "};         // Counter Description
const char *sdm_MAX_VOLTAGE = {" MAXV "};  // Maximum voltage control
const char *sdm_MIN_VOLTAGE = {" MINV "};  // Minimum voltage control
const char *sdm_MAX_POWER = {" MAXP "};    // Maximum power control
const char *sdm_VOLTAGE = {" VOLT "};      // voltage
const char *sdm_CURRENT = {" CURRENT "};   // Current
const char *sdm_REPOWER = {" REPOWER "};   // Reactive power
const char *sdm_ACPOWER = {" ACPOWER "};   // Active power
const char *sdm_POWER = {" POWER "};       // Full power
const char *sdm_POW_FACTOR = {" PF "};     // power factor
const char *sdm_PHASE = {" PHASE "};       // phase angle (degrees)
const char *sdm_FREQ = {" FREQ "};         // Frequency
const char *sdm_ACENERGY = {" ACENERGY "}; // Total active energy
const char *sdm_LINK = {" LINK "};         // Status of communication with the counter
const char *sdm_ERRORS = {" ERR "};        // Modbus read errors

// Description of profile parameter names for get_paramProfile functions set_paramProfile
const char *prof_NAME_PROFILE = {" NAME "};     // Profile name up to 10 Russian letters
const char *prof_ENABLE_PROFILE = {" ENABLE "}; // permission to use in the list
const char *prof_ID_PROFILE = {" ID "};         // profile number, numbering c 1
const char *prof_NOTE_PROFILE = {" NOTE "};     // profile description
const char *prof_DATE_PROFILE = {" DATE "};     // profile date
const char *prof_CRC16_PROFILE = {" CRC16 "};   // profile checksum
const char *prof_NUM_PROFILE = {" NUM "};       // maximum number of profiles
const char *prof_SEL_PROFILE = {" SEL "};       // list of profiles (not yet used)
const char prof_DailySwitch[] = " DS ";
const char prof_DailySwitchDevice = ' D '; // DSD
const char prof_DailySwitchOn = ' S ';     // DSS
const char prof_DailySwitchOff = ' E ';    // DSE

// Description of notification parameter names for set_messageSetting functions get_messageSetting
const char *mess_MAIL = {" MAIL "};                 // drop the notification flag to the mail
const char *mess_MAIL_AUTH = {" MAIL_AUTH "};       // flag of the need for authorization on the mail server
const char *mess_MAIL_INFO = {" MAIL_INFO "};       // flag of the need to add information about the state of the VT in the letter
const char *mess_SMS = {" SMS "};                   // throw notification flag on SMS
const char *mess_MESS_RESET = {" MESS_RESET "};     // reset flag
const char *mess_MESS_ERROR = {" MESS_ERROR "};     // error flag
const char *mess_MESS_LIFE = {" MESS_LIFE "};       // notification flag Life signal
const char *mess_MESS_TEMP = {" MESS_TEMP "};       // notification flag Reaching limit temperature
const char *mess_MESS_SD = {" MESS_SD "};           // flag flag "Problems with sd card"
const char *mess_MESS_WARNING = {" MESS_WARNING "}; // flag of the notification "Other notifications"
const char *mess_SMTP_SERVER = {" SMTP_SERVER "};   // server address
const char *mess_SMTP_IP = {" SMTP_IP "};           // IP address of the server
const char *mess_SMTP_PORT = {" SMTP_PORT "};       // Server port address
const char *mess_SMTP_LOGIN = {" SMTP_LOGIN "};     // server login if authorization is enabled
const char *mess_SMTP_PASS = {" SMTP_PASS "};       // server password if authorization is enabled
const char *mess_SMTP_MAILTO = {" SMTP_MAILTO "};   // sender address
const char *mess_SMTP_RCPTTO = {" SMTP_RCPTTO "};   // recipient address
const char *mess_SMS_SERVICE = {" SMS_list "};      // SMS sending service
const char *mess_SMS_IP = {" SMS_IP "};             // IP address of the server for sending SMS
const char *mess_SMS_PHONE = {" SMS_PHONE "};       // phone where SMS is sent
const char *mess_SMS_P1 = {" SMS_P1 "};             // first parameter to send SMS
const char *mess_SMS_P2 = {" SMS_P2 "};             // second parameter for sending SMS
const char *mess_SMS_NAMEP1 = {" SMS_NAMEP1 "};     // description of the first parameter for sending SMS
const char *mess_SMS_NAMEP2 = {" SMS_NAMEP2 "};     // description of the second parameter for sending SMS
const char *mess_MESS_TIN = {" MESS_TIN "};         // Critical temperature in the house (if less then a notification is generated)
const char *mess_MESS_TBOILER = {" MESS_TBOILER "}; // Critical boiler temperature (if less, a notification is generated)
const char *mess_MESS_TCOMP = {" MESS_TCOMP "};     // Critical compressor temperature (if more then a notification is generated)
const char *mess_MAIL_RET = {" scan_MAIL "};        // Reply to test mail
const char *mess_SMS_RET = {" scan_SMS "};          // Reply to test sms

// Description of boiler parameter names for set_Boiler get_Boiler functions
const char *boil_BOILER_ON = {" ON "};             // flag Turn on the boiler
const char *boil_SCHEDULER_ON = {" SCH_ON "};      // flag Use schedule
const char *boil_SCHEDULER_ADDHEAT = {" SCH_AH "}; // flag Use of the schedule only for the heater
const char *boil_TURBO_BOILER = {" TURBO "};       // flag TURBO DHW heating (heating = TH + TEN)
const char *boil_SALLMONELA = {" SLMN "};          // Salmonel flag once a week to warm the boiler
const char *boil_CIRCULATION = {" CIRC "};         // DHW circulation pump control flag
const char *boil_TEMP_TARGET = {" TRG "};          // Target boiler temperature
const char *boil_DTARGET = {" DTRG "};             // hysteresis of the target temperature
const char *boil_TEMP_MAX = {" MAX "};             // Maximum flow temperature
const char *boil_SCHEDULER = {" SCHEDULER "};      // Schedule
const char *boil_CIRCUL_WORK = {" CIRCW "};        // DHW pump run time seconds (fCirculation)
const char *boil_CIRCUL_PAUSE = {" CIRCP "};       // Pause in the operation of the DHW pump for a second (fCirculation)
const char *boil_RESET_HEAT = {" RESH "};          // flag Reset excess heat in CO
const char *boil_RESET_TIME = {" RESHT "};         // time for the discharge of excess heat in CO in seconds (fResetHeat)
const char *boil_BOIL_TIME = {" PT "};             // Integration time constant in seconds PID VT
const char *boil_BOIL_PRO = {" PP "};              // Proportional component of the DHW PID
const char *boil_BOIL_IN = {" PI "};               // Integral component of the PID DHW
const char *boil_BOIL_DIF = {" PD "};              // Differential component of the DHW PID
const char *boil_BOIL_TEMP = {" TEMP "};           // Target DHW PID temperature
const char *boil_ADD_HEATING = {" ADDH "};         // flag DHW heating
const char *boil_fAddHeatingForce = {" AHF "};     // flag Enable reheat if the compressor has not heated the boiler to the reheat temperature
const char *boil_TEMP_RBOILER = {" TEMPR "};       // temperature for switching on the boiler pre-heating
const char *boil_TOGETHER_HEAT = {" TGHEAT "};     // flag Warm in conjunction with heating, if the heating circuit is operating for heating
const char *boil_fBoilerPID = {" PID "};           // PID on / off
const char *boil_dAddHeat = {" dAH "};             // Hysteresis of boiler heating to the temperature of heating, in hundredths of a degree
const char *boil_HeatUrgently = {" URG "};         // Urgently need hot water

// Date Time
const char *time_TIME = {" TIME "};             // current time 12:45 without seconds
const char *time_DATE = {" DATE "};             // current date of type 12/04/2016
const char *time_NTP = {" NTP "};               // NTP server address string up to 60 characters.
const char *time_UPDATE = {" UPDATE "};         // Time synchronization with the NTP server.
const char *time_TIMEZONE = {" TIMEZONE "};     // time zone
const char *time_UPDATE_I2C = {" UPDATE_I2C "}; // Synchronize time once an hour with i2c clock

// Network
const char *net_IP = {" IP "};               // Address
const char *net_DNS = {" DNS "};             // DNS
const char *net_GATEWAY = {" GATEWAY "};     // Gateway
const char *net_SUBNET = {" SUBNET "};       // subnet mask
const char *net_DHCP = {" DHCP "};           // DHCP usage flag
const char *net_MAC = {" MAC "};             // MAC address of the chip
const char *net_RES_SOCKET = {" NSLS "};     // Reset time of hung sockets
const char *net_RES_W5200 = {" NSLR "};      // Time to regularly reset the network chip
const char *net_PASS = {" PASS "};           // Use passwords (flag)
const char *net_PASSUSER = {" PASSUSER "};   // user password
const char *net_PASSADMIN = {" PASSADMIN "}; // admin password
const char *net_SIZE_PACKET = {" SIZE "};    // packet size
const char *net_INIT_W5200 = {" INIT "};     // Minute SPI monitoring for network chip
const char *net_PORT = {" PORT "};           // Port of the web server
const char *net_NO_ACK = {" NO_ACK "};       // Do Not Expect Ack Answer
const char *net_DELAY_ACK = {" DELAY_ACK "}; // Delay before sending the next packet
const char *net_PING_ADR = {" PING "};       // ping address
const char *net_PING_TIME = {" NSLP "};      // ping time in seconds
const char *net_NO_PING = {" NO_PING "};     // prohibit the ping of the controller
const char *net_fWebLogError = {" WLOG "};   // log web request errors
const char *net_fWebFullLog = {" WFLOG "};   // display the full log

// Description of the inverter parameter names for the get_paramFC ("get_pFC") functions set_paramFC ("set_pFC")
const char *fc_ON_OFF = {" ON_OFF "};            // Flag for turning on / off (frequency control)
const char *fc_INFO = {" INFO "};                // Get information from the inverter (table !!)
const char *fc_NAME = {" NAME "};                // Inverter name
const char *fc_NOTE = {" NOTE "};                // Get a description of the frequency converter. Line 80 + 1
const char *fc_PIN = {" PIN "};                  // Get the pin number where analog FC is attached
const char *fc_PRESENT = {" PRESENT "};          // The presence of FC in the configuration.
const char *fc_STATE = {" STATE "};              // Status of the inverter (read)
const char *fc_FC = {" FC "};                    // The target frequency of the inverter is 0.01
const char *fc_cFC = {" cFC "};                  // Current inverter frequency (read)
const char *fc_cPOWER = {" cPOWER "};            // Current power (read)
const char *fc_INFO1 = {" INFO1 "};              // The first line below the inverter picture in the circuit
const char *fc_cCURRENT = {" cCURRENT "};        // Current current (read)
const char *fc_AUTO_RESET_FAULT = {" ARSTFLT "}; // Flag to automatically reset non-critical inverter error
const char *fc_LogWork = {" LOGW "};             // flag log while running
const char *fc_ANALOG = {" AN "};                // Flag of analog control
const char *fc_DAC = {" DAC "};                  // Get the current DAC value
const char *fc_LEVEL0 = {" L0 "};                // Frequency level 0 in the DAC samples
const char *fc_LEVEL100 = {" L100 "};            // Frequency level 100% in the DAC samples
const char *fc_LEVELOFF = {" LOFF "};            // Minimum power at which the chastotnik turns off (minimum power limit)
const char *fc_BLOCK = {" BLOCK "};              // flag inverter global error - inverter operation is disabled; blocking can be reset by setting 0
const char *fc_ERROR = {" ERROR "};              // Get the error code
const char *fc_UPTIME = {" UPTIME "};            // Pid controller update algorithm time (ms) The main control loop
const char *fc_PID_STOP = {" PID_STOP "};        // Percentage of the level of protection (power, current, pressure, temperature) at which the frequency increase is blocked by the pid
const char *fc_PID_FREQ_STEP = {" PID_STEP "};   // The maximum step (to increase) the frequency change with PID control of 0.01 Hz It is necessary that the ERV be in time
const char *fc_START_FREQ = {" FRQ "};           // Inverter starting frequency (cm compressor) at 0.01 Hz
const char *fc_START_FREQ_BOILER = {" FRQB "};   // Starting frequency of the inverter (cm compressor) in 0.01 GHz of hot water
const char *fc_MIN_FREQ = {" MIN "};             // Minimum inverter frequency (cm compressor) in 0.01 Hz
const char *fc_MIN_FREQ_COOL = {" MINC "};       // The minimum frequency of the inverter during cooling at 0.01 Hz
const char *fc_MIN_FREQ_BOILER = {" MINB "};     // The minimum frequency of the inverter when heating the hot water in 0.01 Hz
const char *fc_MIN_FREQ_USER = {" MINU "};       // Minimum inverter frequency MANUAL MODE (cm compressor) at 0.01 Hz
const char *fc_MAX_FREQ = {" MAX "};             // Maximum inverter frequency (cm compressor) at 0.01 Hz
const char *fc_MAX_FREQ_COOL = {" MAXC "};       // Maximum inverter frequency in cooling mode at 0.01 Hz
const char *fc_MAX_FREQ_BOILER = {" MAXB "};     // The maximum frequency of the inverter in the DHW mode at 0.01 Hz the absorption of the boiler is usually less than CO
const char *fc_MAX_FREQ_USER = {" MAXU "};       // Maximum inverter frequency MANUAL MODE (cm compressor) at 0.01 Hz
const char *fc_STEP_FREQ = {" STEP "};           // Step to decrease the inverter when reaching the maximum temperature, power and current (cm compressor) at 0.01 Hz
const char *fc_STEP_FREQ_BOILER = {" STEPB "};   // Step to decrease the inverter when reaching the maximum temperature, power and dhw current of 0.01 Hz
const char *fc_DT_COMP_TEMP = {" DTC "};         // Protection by compressor temperature - how many degrees does not reach the maximum (TCOMP) and at the same time there is a decrease in frequency
const char *fc_DT_TEMP = {" DT "};               // Exceeding the temperature from the settings (feed) at which the protection is triggered (frequency decreases) in hundredths of a degree
const char *fc_DT_TEMP_BOILER = {" DTB "};       // Exceeding the temperature from the settings (supply) at which the DHW protection in hundredths of a degree is triggered
const char *fc_MB_ERR = {" MB_ERR "};            // Modbus errors
const char *fc_FC_TIME_READ = {" TR "};          // Poll time
const char *fc_fFC_RetOil = {" FRO "};           // Flag oil return
const char *fc_FC_RETOIL_FREQ = {" FRF "};       // Frequency
const char *fc_ReturnOilPeriod = {" ROP "};      // Oil return time
const char *fc_ReturnOilPerDivHz = {" ROPH "};   // The frequency at which oil returns
const char *fc_ReturnOilEEV = {" ROE "};         // Steps of the EDS at which oil is returned

// Description of the names of the options options for the VT functions get_optionHP ("get_oHP") set_optionHP ("set_oHP")
const char *option_ADD_HEAT = {" HEAT_list "};       // use an additional heater (values ​​1 and 0)
const char *option_TEMP_RHEAT = {" TEMP_RHEAT "};    // temperature for controlling RHEAT (degrees)
const char *option_PUMP_WORK = {" PUMP_WORK "};      // condenser pump operation with compressor off seconds
const char *option_PUMP_PAUSE = {" PUMP_PAUSE "};    // pause between the operation of the condenser pump with the compressor off (seconds)
const char *option_ATTEMPT = {" ATTEMPT "};          // number of start attempts
const char *option_TIME_CHART = {" TIME_CHART "};    // statistics collection period
const char *option_BEEP = {" BEEP "};                // enable sound
const char *option_NEXTION = {" NXT "};              // use nextion display
const char *option_NEXTION_WORK = {" NXTW "};        // Turn on the display when the VT is working
const char *option_History = {" HIST "};             // write history to SD card
const char *option_SDM_LOG_ERR = {" SDM_LOGER "};    // flag write to the log irregular errors of the SDM counter
const char *option_SAVE_ON = {" SAVE_ON "};          // flag of writing in the EEPROM of switching on the VT (restoration of work after reboot)
const char *option_NEXT_SLEEP = {" NXTS "};          // Sleep Time Second NEXTION
const char *option_NEXT_DIM = {" NXTD "};            // Brightness% NEXTION
const char option_SGL1W[] = " SGL1W_ ";              // SGLOW_n, On the bus n (1-Wire, DS2482) there is only one sensor
const char *option_DELAY_ON_PUMP = {" DLONP "};      // Delay on the compressor after turning on the pumps (sec).
const char *option_DELAY_OFF_PUMP = {" DLOFP "};     // Delay for turning off the pumps after turning off the compressor (sec).
const char *option_DELAY_START_RES = {" DLSR "};     // Delay turning on the VT after a sudden reset of the controller (sec.)
const char *option_DELAY_REPEAD_START = {" DLRS "};  // Delay before switching on the VT again after an error (attempt to start) seconds
const char *option_DELAY_DEFROST_ON = {" DLDON "};   // FOR AIR THROUGH Delay after the sensor is triggered before defrosting is activated (seconds)
const char *option_DELAY_DEFROST_OFF = {" DLDOFF "}; // FOR Aerial VT Delay before turning off the defrost (seconds)
const char *option_DELAY_R4WAY = {" DLTRV "};        // Delay between switching the 4-way valve and turning on the compressor, for pressure equalization (sec). If these options are enabled (heat-cold switching)
const char *option_DELAY_BOILER_SW = {" DLBSW "};    // Pause (sec) after switching the hot water supply - equalize the temperature in the heating / hot water circuit so that the protection does not work immediately
const char *option_DELAY_BOILER_OFF = {" DLBOFF "};  // Time (sec) how much protection is blocked when switching from DHW to heating and cooling too hot after DHW
const char *option_SunTempOn = {" STO "};            // Temperature above which SK opens
const char *option_SunTempOff = {" STF "};           // Temperature below which SC closes
const char *option_SunRegGeo = {" SCG "};            // Use the solar collector to regenerate the geocontour into idle time
const char *option_SunRegGeoTemp = {" SCGT "};       // Temperature of the beginning of the regeneration of the geocontour using SC, in degrees
const char *option_SunRegGeoTempGOff = {" SCGO "};   // Temperature of the fluid at the end of the regeneration of the geocontour using SC, in degrees
const char *option_SunTDelta = {" STD "};            // Delta of temperatures for inclusion, hundredths of a degree
const char *option_SunGTDelta = {" SGD "};           // Delta temperature of the fluid to turn off, hundredths of a degree
const char *option_WebOnSPIFlash = {" WSPIF "};      // flag that the web face is on SPI Flash, otherwise on the SD card
const char *option_LogWirelessSensors = {" LOGWS "}; // Log exchange between wireless sensors
const char *option_PAUSE = {" PAUSE "};              // minimum compressor downtime
const char *option_MinCompressorOn = {" MCON "};     // Minimum compressor run time in seconds
const char *option_Charts_when_comp_on = {" CWCO "}; // Graphs in memory only during compressor operation
const char *option_fBackupPower = {" BPOW "};        // flag Use backup power from the generator (power limitation)
const char *option_maxBackupPower = {" MAXPOW "};    // Maximum power when powered by a generator

// Heating / cooling parameters
const char *hp_RULE = {" RULE "};         // operation algorithm
const char *hp_TEMP1 = {" TEMP1 "};       // target temperature in the house
const char *hp_TEMP2 = {" TEMP2 "};       // target return temperature
const char *hp_TARGET = {" TARGET "};     // what is the purpose of PID - values ​​0 (temperature in the house), 1 (return temperature).
const char *hp_DTEMP = {" DTEMP "};       // hysteresis of the target temperature
const char *hp_HP_TIME = {" HP_TIME "};   // Integration time constant in seconds PID VT
const char *hp_HP_PRO = {" HP_PRO "};     // Proportional component of PID TH
const char *hp_HP_IN = {" HP_IN "};       // Integral component of PID TH
const char *hp_HP_DIF = {" HP_DIF "};     // Differential component of PID TH
const char *hp_TEMP_IN = {" TEMP_IN "};   // feed temperature (minimum for cooling or maximum for heating)
const char *hp_TEMP_OUT = {" TEMP_OUT "}; // return temperature (maximum for cooling or minimum for heating)
const char *hp_D_TEMP = {" D_TEMP "};     // maximum temperature difference of the capacitor.
const char *hp_TEMP_PID = {" TEMP_PID "}; // Target PID temperature
const char *hp_WEATHER = {" W "};         // Use weather
const char *hp_HEAT_FLOOR = {" HFL "};    // Use underfloor heating
const char *hp_SUN = {" SUN "};           // Use the solar collector
const char *hp_K_WEATHER = {" KW "};      // Weather coefficient
const char *hp_targetPID = {" TP "};      // Target PID

// Valid for heating and domestic hot water
const char *ADD_DELTA_TEMP = {" ADT "};      // Add temperature to the unit, in degrees
const char *ADD_DELTA_HOUR = {" ADH "};      // Initial Hour of adding temperature to the installation
const char *ADD_DELTA_END_HOUR = {" ADEH "}; // End Hour of adding temperature to the installation

#ifdef SENSOR_IP                                    // remote sensor parameters get_sensorIP
const char *ip_SENSOR_TEMP = {" SENSOR_TEMP "};     // Tempeartura
const char *ip_SENSOR_NUMBER = {" SENSOR_NUMBER "}; // Number
const char *ip_RSSI = {" RSSI "};                   // signal strength
const char *ip_VCC = {" VCC "};                     // supply voltage
const char *ip_SENSOR_USE = {" SENSOR_USE "};       // Use
const char *ip_SENSOR_RULE = {" SENSOR_RULE "};     // Rule of use
const char *ip_SENSOR_IP = {" SENSOR_IP "};         // Address
const char *ip_SENSOR_COUNT = {" SENSOR_COUNT "};   // counter
const char *ip_STIME = {" STIME "};                 // time since the last sensor read
const char *ip_SENSOR = {" SENSOR "};               // -------
#endif

// Names Freon Types
const char *noteFreon[] = {" R22 ", " R410A ", " R600 ", " R134a ", " R407C ", " R12 ", " R290 ", " R404A ", " R717 "};
// The names of the rules of the work of the ERV for the web
const char noteRuleEEV[] = " TEVAOUT-T [PEVA]: 0; "
#ifdef TCOMPIN
                           " TCOMPIN-T [PEVA]: 0; "
#ifdef TEVAIN
                           " TEVAOUT-TEVAIN: 0; "
                           " TCOMPIN-TEVAIN: 0; "
                           " TABLE [EVA, CON]: 0; "
#endif
#endif
                           " MANUAL: 0; ";

// Description of the operation rules
const char *noteRemarkEEV[] = {" Overheating is equal to: temperature at the exit of the evaporator - temperature according to pressure at the exit of the evaporator. ",
#ifdef TCOMPIN
                               " Overheating is equal to: compressor inlet temperature - temperature by pressure at the outlet of the evaporator. ",
#ifdef TEVAIN
                               " Overheating is equal to: evaporator outlet temperature - evaporator inlet temperature. ",
                               " Overheating is equal to: compressor inlet temperature - evaporator inlet temperature. ",
                               " Overheating is not calculated. ERV is opened by the value of the step from the temperature table of the evaporator and condenser. ",
#endif
#endif
                               " Overheating is not calculated. Manual mode, ERV opens by a specified number of steps. "};

// warnings
#define WARNING_VALUE 1 // Attempt to set a value outside the range of the query type SET

// GPBR - eight 32x bit registers not reset at reset, volatile!
// addresses - 0x90-0xDC General Purpose Backup Register GPBR
// The System Controller embeds Eight general-purpose backup registers.
// Map of GPBR usage in NK
// GPBR-> SYS_GPBR [0] current task (shift by 8 to the left) + RTOS error numbers
// GPBR-> SYS_GPBR [1] reason for the controller reset
// GPBR-> SYS_GPBR [4] last debug point before reset, the maximum value of the debug point is 56 now (update!)
#define STORE_DEBUG_INFO (s) GPBR->SYS_GPBR[4] = s     // Saving the debug point number in the volatile memory sam3
#define WEB_STORE_DEBUG_INFO (s) GPBR->SYS_GPBR[5] = s // Saving the debug point number in the volatile memory sam3

// ------------------------------------------------ --------------------------------
// ERRORS are the same for everything - an end-to-end list
// ------------------------------------------------ --------------------------------
#define OK 0                     // No errors
#define ERR_MINTEMP -1           // Exit the lower limit of the temperature sensor
#define ERR_MAXTEMP -2           // Exit the upper limit of the temperature sensor
#define ERR_MINPRESS -3          // Exit the lower limit of the pressure sensor
#define ERR_MAXPRESS -4          // Go beyond the upper limit of the pressure sensor
#define ERR_SENSOR -5            // Sensor is not allowed in the current configuration
#define ERR_ADDRESS -6           // Temperature sensor address not set
#define ERR_DINPUT -7            // Contact sensor trips - alarm
#define ERR_MAX_EEV -8           // Going out of range (in steps) at the top
#define ERR_MIN_EEV -9           // Out of range (in steps) at the bottom
#define ERR_DEVICE -10           // The device is prohibited in the current configuration
#define ERR_ONEWIRE -11          // Reset error on the OneWire bus (open or short)
#define ERR_OVERHEAT -12         // ERV received a negative overheat
#define ERR_MEM_FREERTOS -13     // Free RTOS cannot create a task - not enough memory
#define ERR_PEVA_EEV -14         // There is no pressure sensor, and the ERV algorithm that uses it is selected
#define ERR_SAVE_EEPROM -15      // Error writing settings to eeprom I2C
#define ERR_LOAD_EEPROM -16      // Error reading settings from eeprom I2C
#define ERR_CRC16_EEPROM -17     // Checksum error for settings
#define ERR_BAD_LEN_EEPROM -18   // Data size mismatch while reading settings
#define ERR_HEADER_EEPROM -19    // Settings data not found in eeprom I2C
#define ERR_SAVE1_EEPROM -20     // Error writing status to eeprom I2C
#define ERR_LOAD1_EEPROM -21     // Error reading state from eeprom I2C
#define ERR_HEADER1_EEPROM -22   // Status data not found in eeprom I2C
#define ERR_SAVE2_EEPROM -23     // Error writing counters to eeprom I2C
#define ERR_LOAD2_EEPROM -24     // Error reading counters from eeprom I2C
#define ERR_WRONG_HARD_STATE -25 // Invalid VT state
#define ERR_DTEMP_CON -26        // The temperature difference on the condenser has been increased
#define ERR_DTEMP_EVA -27        // Excessive temperature difference on the evaporator
#define ERR_PUMP_CON -28         // There is no pump on the condenser, check the configuration
#define ERR_PUMP_EVA -29         // There is no pump on the evaporator, check the configuration
#define ERR_READ_PRESS -30       // Error reading pressure sensor (data not ready)
#define ERR_NO_COMPRESS -31      // There is no compressor, check the configuration
#define ERR_NO_WORK -32          // Everything is off and VT is on
#define ERR_COMP_ERR -33         // Attempt to turn on the compressor on error (contact the developer)
#define ERR_CONFIG -34           // Internal configuration failed (contact the developer)
#define ERR_SD_INIT -35          // Error initializing the SD card
#define ERR_SD_INDEX -36         // Index.xxx file not found on SD card
#define ERR_SD_READ -37          // Error reading file from SD card
#define ERR_TYPE_OVERHEAT -38    // The rule for calculating overheating does not match the sensors (contact the developer)
#define ERR_485_INIT -39         // Inverter on Modbus was not found (inverter operation is prohibited)
#define ERR_485_BUZY -40         // When accessing port 485, the waiting time for its release was exceeded
// Errors described in the modbus protocol
#define ERR_MODBUS_0x01 -41       // Modbus 0x01 protocol illegal function exception
#define ERR_MODBUS_0x02 -42       // Modbus 0x02 protocol illegal data address exception
#define ERR_MODBUS_0x03 -43       // Modbus 0x03 protocol illegal data value exception
#define ERR_MODBUS_0x04 -44       // Modbus 0x4 protocol slave device failure exception
#define ERR_MODBUS_0xe0 -45       // Modbus 0xe0 Master invalid response slave ID exception
#define ERR_MODBUS_0xe1 -46       // Modbus 0xe1 Master invalid response function exception
#define ERR_MODBUS_0xe2 -47       // Modbus 0xe2 Master response timed out exception
#define ERR_MODBUS_0xe3 -48       // Modbus 0xe3 Master invalid response CRC exception
#ifdef FC_VACON                   // Vocon 10 specific errors
#define ERR_MODBUS_VACON_0x05 -49 // The slave device has accepted the request and is processing it, but it takes a lot of time. This response prevents the master from generating a timeout error.
#define ERR_MODBUS_VACON_0x06 -50 // The slave is busy processing the command. The master must retry the message later when the slave is free.
#define ERR_MODBUS_VACON_0x07 -52 // The slave cannot execute the program function specified in the request.
#define ERR_MODBUS_VACON_0x08 -52 // The slave device while reading extended memory detected a parity error
#define ERR_MODBUS_VACON_0000 -53 // empty to save numbering
#define ERR_MODBUS_VACON_0001 -54 // empty to save numbering
#define ERR_MODBUS_VACON_0002 -55 // empty to save numbering
#else                             // OMRON specific errors
#define ERR_MODBUS_MX2_0x01 -49   // Omron mx2 Exception code 0x01 The specified function is not supported
#define ERR_MODBUS_MX2_0x02 -50   // Omron mx2 Exception code 0x02 The specified function was not found.
#define ERR_MODBUS_MX2_0x03 -52   // Omron mx2 Exception code 0x03 Unacceptable data format
#define ERR_MODBUS_MX2_0x05 -52   // Omron mx2 communication error over Modbus (function communication check 0x08 Omron mx2)
#define ERR_MODBUS_MX2_0x21 -53   // Omron mx2 Exception code 0x21 Data written to the storage register is outside the inverter
#define ERR_MODBUS_MX2_0x22 -54   // Omron mx2 Exception code 0x22 These functions are not available for the inverter
#define ERR_MODBUS_MX2_0x23 -55   // Omron mx2 Exception code 0x23 The register (bit) into which the value should be written is read-only
#endif
#define ERR_MODBUS_UNKNOW -56     // Modbus unknown error (protocol failure)
#define ERR_MODBUS_STATE -57      // Forbidden ( invalid ) state of the inverter
#define ERR_MODBUS_BLOCK -58      // Attempt to turn on the VT with the inverter locked
#define ERR_PID_FEED -59          // PID algorithm - reaching the maximum flow temperature (protection) The flow is the objective function, the protection is higher, and this should not be
#define ERR_OUT_OF_MEMORY -60     // Not enough memory to allocate arrays
#define ERR_SAVE_PROFILE -61      // Error writing profile in eeprom I2C
#define ERR_LOAD_PROFILE -62      // Error reading profile from eeprom I2C
#define ERR_CRC16_PROFILE -63     // Checksum error for profile
#define ERR_BAD_LEN_PROFILE -64   // Data size mismatch while reading profile
#define ERR_DS2482_NOT_FOUND -65  // DS2482 master was not found on the bus, I2C bus error is possible
#define ERR_DS2482_ONEWIRE -66    // DS2482 master cannot reset the OneWire bus PPD bit is 0
#define ERR_I2C_BUZY -67          // When accessing the I2C bus, the waiting time for its release was exceeded
#define ERR_DRV_EEV -68           // Driver L9333 ERV failed (driver protection worked)
#define ERR_HEADER2_EEPROM -69    // Counter header error in eeprom I2C
#define ERR_OPEN_I2C_JOURNAL -70  // Error opening the log in I2C memory (chip initialization)
#define ERR_READ_I2C_JOURNAL -71  // Error reading the log in I2C memory
#define ERR_WRITE_I2C_JOURNAL -72 // Error writing log in I2C memory
// #define ERR_ -73 //
#define ERR_MIN_FLOW -74       // The flow in the VET is below the set level
#define ERR_MAX_VOLTAGE -75    // Mains voltage too high (SDM120 data)
#define ERR_MAX_POWER -76      // Too much portable power (SDM120 data)
#define ERR_NO_MODBUS -77      // Modbus is required but not in the configuration
#define ERR_RESET_FC -78       // Failed to reset the inverter after an error
#define ERR_SEVA_FLOW -79      // There is no flow in the evaporator (SEVA operation)
#define ERR_COMP_NO_PUMP -80   // Attempt to turn on the compressor when the circuit pumps are not working.
#define ERR_DEFROST_R4WAY -81  // Erroneous configuration - attempt to defrost if it is not possible to switch to cooling (no R4WAY)
#define ERR_DEFROST -82        // Defrosting is required (there are conditions) during cooling
#define ERR_FC_CONF_ANALOG -83 // Error using analog control of the inverter without output
#define ERR_READ_TEMP -84      // Error reading the temperature sensor (read limit exceeded )
// #define ERR_ -85 //
#define ERR_ONEWIRE_CRC -86 // CRC error while reading OneWire
#define ERR_ONEWIRE_RW -87  // error while reading / writing OneWire
#define ERR_FC_FAULT -88    // inverter failure
#define ERR_FC_ERROR -89    // inverter control program error
#define ERR_SD_WRITE -90    // error writing to SD card
#define ERR_FC_RCOMP -91    // It is not possible to stop the inverter using RCOMP

#define ERR_ERRMAX -91 // Last error

// Description of ALL Errors description length not more than 160 bytes (limitation of the main class note_error [160 + 1])
const char *noteError[] = {" Ok ",                                                                                //   0
                           " Exit the lower limit of the temperature sensor ",                                    // -1
                           " Going beyond the upper limit of the temperature sensor ",                            // -2
                           " Going beyond the lower boundary of the pressure sensor ",                            // -3
                           " Going beyond the upper limit of the pressure sensor ",                               // -4
                           " Sensor disabled in current configuration ",                                          // -5
                           " Temperature sensor address not set ",                                                // -6
                           " Contact sensor trips - accident ",                                                   // -7
                           " ERV out of range (steps) up (ERV failure?) ",                                        // -8
                           " ERV out of range (in steps) down (ERV failure?) ",                                   // -9
                           " The device is prohibited in the current configuration ",                             // -10
                           " Reset Error on OneWire Bus (Open or Short) ",                                        // -11
                           " ERV received a negative overheating ",                                               // -12
                           " Free RTOS cannot create a task, not enough memory ",                                 // -13
                           " No pressure sensor, and ERV selected algorithm which uses it ",                      // -14 length of 132 bytes
                           " Error writing settings ",                                                            // -15
                           " Error reading settings ",                                                            // -16
                           " Checksum error for settings in I2C ",                                                // -17
                           " Data size mismatch while reading settings ",                                         // -18
                           " Settings data not found in I2C ",                                                    // -19
                           " Error writing status in I2C ",                                                       // -20
                           " Error reading state in I2C ",                                                        // -21
                           " Status data not found in I2C ",                                                      // -22
                           " Error writing counters in I2C ",                                                     // -23
                           " Error reading counters from I2C ",                                                   // -24
                           " Invalid condition of VT ",                                                           // -25
                           " Excessive temperature difference on the condenser ",                                 // -26
                           " Exceeded the temperature difference on the evaporator ",                             // -27
                           " There is no pump on the condenser, check the configuration ",                        // -28
                           " There is no pump on the evaporator, check the configuration ",                       // -29
                           " Error reading pressure sensor (data not ready) ",                                    // -30
                           " No compressor, check configuration (RCOMP and FC) ",                                 // -31
                           " There is no work for VT, check the settings of the domestic hot water and heating ", // -32
                           " Attempting to turn on the compressor in case of error (contact the developer) ",     // -33
                           " Internal configuration failed (contact the developer) ",                             // -34
                           " Error initializing the SD card ",                                                    // -35
                           " Index.xxx file not found on SD card ",                                               // -36
                           " Error reading file from SD card ",                                                   // -37
                           " The rule for calculating overheating does not match the sensors ",                   // -38
                           " Inverter on Modbus was not found (inverter operation is prohibited) ",               // -39
                           " When referring to the 485 port privysheno standby time of his release ",             // -40
                           " Modbus error 0x01 protocol illegal function exception ",                             // -41
                           " Modbus error 0x02 protocol illegal data address exception ",                         // -42
                           " Modbus error 0x03 protocol illegal data value exception ",                           // -43
                           " Modbus error 0x4 protocol slave device failure exception ",                          // -44
                           " Modbus error 0xe0 Master invalid response slave ID exception ",                      // -45
                           " Modbus error 0xe1 Master invalid response function exception ",                      // -46
                           " Modbus error 0xe2 Master response timed out exception ",                             // -47
                           " Modbus error 0xe3 Master invalid response CRC exception ",                           // -48
#ifdef FC_VACON                                                                                                   // Vocon 10 specific errors
                           "The slave device has accepted the request and is processing it (0x05) ",              // -49
                           "The slave is busy processing the command (0x06) ",                                    // -50
                           "The slave cannot execute the program function (0x07) ",                               // -51
                           "The slave detected a parity error (0x08) ",                                           // -52
                           " ",                                                                                   // -53
                           " ",                                                                                   // -54
                           " ",                                                                                   // -55
#else                                                                                                             // OMRON specific errors
                           " Exception code 0x01 The specified function is not supported ",                      // -49
                           " Exception code 0x02 The specified function was not detected ",                      // -50
                           " Exception code 0x03 Unacceptable format for the specified data ",                   // -51
                           " Omron mx2 0x05 communication error on Modbus (function communication check 0x08) ", // -52
                           " Exception code 0x21 Data written to the register is outside the inverter ",         // -53
                           " Exception code 0x22 The indicated functions are not available for the inverter ",   // -54
                           " Exception code 0x23 Register (bit), read-only ",                                    // -55
#endif
                           " Modbus unknown error (protocol failure) ",                                            // -56
                           " Forbidden (incorrect) state of the inverter ",                                        // -57
                           " Attempt to turn on the VT with a locked inverter ",                                   // -58
                           " PID algorithm - achieving the maximum flow temperature (protection) ",                // -59
                           " There is not enough memory to allocate for data (see configuration). ",               // -60
                           " Error writing profile in I2C ",                                                       // -61
                           " Error reading profile from I2C ",                                                     // -62
                           " Checksum error for profile ",                                                         // -63
                           " Data size mismatch while reading profile ",                                           // -64
                           " DS2482 master was not found on the bus, I2C bus error is possible ",                  // -65
                           " The DS2482 master cannot reset the OneWire bus PPD bit is 0 ",                        // -66
                           " When referring to the I2C bus is exceeded while waiting for her release ",            // -67
                           " L9333 ERV driver failure (driver protection worked) ",                                // -68
                           " Counter header error in I2C ",                                                        // -69
                           " Error opening the log in I2C (chip initialization) ",                                 // -70
                           " Error reading the log from I2C memory ",                                              // -71
                           " Error writing log to I2C memory ",                                                    // -72
                           " ",                                                                                    // -73
                           " The flow in the VET is below the set level (the problem is the pump, filter) ",       // -74
                           " Mains voltage too high (SDM counter data) ",                                          // -75
                           " Too much power consumption (SDM counter data) ",                                      // -76
                           " Modbus is required, but not in the configuration ",                                   // -77
                           " Failed to reset the inverter after an error ",                                        // -78
                           " There is no duct in the evaporator (SEVA operation) ",                                // -79
                           " Attempt to turn on the compressor when the circuit pump is idle ",                    // -80
                           " An attempt to defrost if it is not possible to switch to cooling (no R4WAY) ",        // -81
                           " Defrosting is required (there are conditions for temperatures) during cooling ",      // -82
                           " Error using the analog control of the inverter without the STROKE output ",           // -83
                           " Error reading temperature sensor (limit of attempts to read has been exhausted) ",    // -84
                           " ",                                                                                    // -85
                           " OneWire Read CRC Error ,															 " // -86
                           " OneWire Read / Write Error ",                                                         // -87
                           " Inverter Failure ",                                                                   // -88
                           " Inverter control program error ",                                                     // -89
                           " Error writing to the SD card ",                                                       // -90
                           " It is not possible to stop the inverter using RCOMP ",                                // -91

                           " NULL "};
// --------------------------------- LISTED TYPES ------------- --------------------------------
//   Enumerated type - download source for web muzzle
enum TYPE_SOURSE_WEB
{
    pMIN_WEB,   // It is necessary to load the minimum face
    pSD_WEB,    // You must load the face from the card
    pFLASH_WEB, // You must load the face from the flash drive
    pERR_WEB    // Internal error?
};

//   Enumerated type - Response types of POST requests
enum TYPE_RET_POST
{
    pSETTINGS_OK,  // Settings from the selected file are restored, CRC16 OK
    pSETTINGS_ERR, // Error restoring settings from a file (see log)
    pNULL,         // "" - empty string
    pLOAD_OK,      // Files uploaded, see the log for details
    pLOAD_ERR,     // Error loading file, see the log for details
    pPOST_ERR,     // Internal error of the parser of post requests
    pNO_DISK,      // No flash disk
    pSETTINGS_MEM  // Settings do not fit into the internal buffer
};

//   Enumerated type - Heat pump states
enum TYPE_STATE_HP
{
    pOFF_HP,      // 0 VT off
    pSTARTING_HP, // 1 Starts
    pSTOPING_HP,  // 2 Stops
    pWORK_HP,     // 3 Works
    pWAIT_HP,     // 4 Waiting for VT (schedule - empty space)
    pERROR_HP,    // 5 Error TN
    pERROR_CODE,  // 6 - This error should not occur!
    pEND15        // Must be the last, add BEFORE !!!
};

// Enumerated type - return point from the control algorithm (state decryption)
// Decryption of the code (example Bp12 Boiler - PID algorithm - frequency change by PID)
// The code has three fields <source> <algorithm> <algorithm_code>
// Source: B-boiler, H-heating, C-cooling
// Algorithm: h - hysteresis, p - PID
// Algorithm Code
// 1 - power off
// 2 - hysteresis inclusion
// 3 - hysteresis shutdown
// 4 - inside the hysteresis (continued: heating or cooling)
// 5 - pause inside the hysteresis
// 6 - feed frequency reset
// 7 - power frequency reset
// 8 - frequency reset by compressor temperature
// 9 - pressure frequency reset
// 10 - acceleration, pid does not work
// 11 - pid time has not come
// 12 - reached the PID, adjustable
// 13 - switching on by return; the minimum return temperature is reached
// 14 - operation of the super-boiler PID DHW (entry into the boiler)
// 15 - The boiler is heated from the pre-condenser (entry into the heating)
// 16 - frequency inverter current reset
// 17 - blocking the frequency increase by the PID when approaching the protection levels
// 18 - blocking the frequency increase by PID when approaching the protection levels
// 19 - blocking the frequency increase by the PID when approaching the current protection levels
// 20 - blocking the increase in frequency by the PID when approaching the TCOMP protection levels
// 21 - blocking the frequency increase by the PID when approaching the protection levels PRESSURE
// 22 - Turning off the heating of the boiler for switching to the HEATING mode by its heating element
// 23 - Turn off the VT mode when reaching the level of protection for the feed (reaching the border)
// 24 - Switching off the VT mode when reaching the level of protection by power (reaching the border)
// 25 - Turn off the VT mode when reaching the level of protection by compressor temperature (reaching the border)
// 26 - Switching off the VT mode when reaching the level of protection by pressure (reaching the border)
// 27 - Switching off the VT mode when reaching the current protection level (reaching the border)
// 28 - Power limitation when working from a backup power source (frequency reset)
// 29 - Turn off the VT mode when the minimum frequency is reached when working from the backup power source.

enum TYPE_RET_HP
{
    pNone,       // At the beginning
    pMinPauseOn, // Ensuring a minimum pause between inclusions
    // Boiler
    pBh1,
    pBh2,
    pBh3,
    pBh4,
    pBh5,
    pBh22,

    pBp3,
    pBp1,
    pBp2,
    pBp6,
    pBp7,
    pBp8,
    pBp9,
    pBp5,
    pBp10,
    pBp11,
    pBp12,
    pBp14,
    pBp16,

    pBp17, // pid limits
    pBp18,
    pBp19,
    pBp20,
    pBp21,
    pBp22,
    pBp23,
    pBp24,
    pBp25,
    pBp26,
    pBp27,
    pBp28,
    pBp29,

    // Heating
    pHh3,
    pHh1,
    pHh2
        pHh13,
    pHh4,

    pHp3
        pHp1
            pHp2
                pHp6,
    pHp7
        pHp8
            pHp9
                pHp5,
    pHp10
        pHp11,
    pHp12,
    pHp15,
    pHp16,

    pHp17, // pid limits
    pHp18,
    pHp19,
    pHp20
        pHp21,
    pHp23,
    pHp24,
    pHp25,
    pHp26,
    pHp27,
    pHp28
        pHp29

            // Cooling
            pCh3,
    pCh1,
    pCh2,
    pCh13,
    pCh4,

    pCp3,
    pCp1,
    pCp2,
    pCp6,
    pCp7,
    pCp8,
    pCp9,
    pCp5,
    pCp10,
    pCp11,
    pCp12,
    pCp15,
    pCp16,

    pCp17, // pid limits
    pCp18,
    pCp19,
    pCp20,
    pCp21,
    pCp23,
    pCp24,
    pCp25,
    pCp26,
    pCp27,
    pCp28,
    pCp29,

    pEND18 // Must be the last, add BEFORE !!!
};
//   To output the codes
const char *codeRet[] = {" none ", " MinPause ", " Bh1 ", " Bh2 ", " Bh3 ", " Bh4 ", " Bh5 ", " Bh22 ", " Bp3 ", " Bp1 ", " Bp2 ", " Bp6 ", "Bp7 ", " bp8", " BP9 ", " BP5 ", " BP10 ", " BP11 ", " BP12 ", " BP14 ", " BP16 ", " BP17 ", " BP18 ", " BP19 ", " BP20 ", " BP21 ", " Bp22 ", " Bp23 ", " BP24 ", " BP25 ", " BP26 ", " BP27 ", " BP28 ", " BP29 ",
                         " Hh3 ", " Hh1 ", " Hh2 ", " Hh13 ", " Hh4 ", " Hp3 ", " Hp1 ", " Hp2 ", " Hp6 ", " Hp7 ", " Hp8 ", " Hp9 ", " Hp5 ", "Hp10 ", " Hp11 ", " Hp12 ", " Hp15 ", " Hp16 ", " Hp17 ", " Hp18 ", " Hp19 ", " Hp20 ", " Hp21 ", " Hp23 ", " Hp24 ", " Hp25 ", " Hp26 ", " Hp27 ", " Hp28 ", "Hp29 ",
                         " Ch3 ", " Ch1 ", " Ch2 ", " Ch13 ", " Ch4 ", " Cp3 ", " Cp1 ", " Cp2 ", " Cp6 ", " Cp7 ", " Cp8 ", " Cp9 ", " Cp5 ", "Cp10 ", " Cp11 ", " Cp12 ", " Cp15 ", " Cp16 ", " Cp17 ", " Cp18 ", " Cp19 ", " Cp20 ", " Cp21 ", " Cp23 ", " Cp24 ", " Cp25 ", " Cp26 ", " Cp27 ", " Cp28 ", "Cp29 ", " null "};

//   Enumerated type - actions on the compressor
enum MODE_COMP
{
    pCOMP_OFF,  // compressor was turned off
    pCOMP_ON,   // compressor was turned on
    pCOMP_NONE, // compressor do nothing - do not change the status
    pEND9       // Must be the last, add BEFORE !!!
};

//   Enumerated type - what to do or what heating mode is selected (first three)
#define MODE_HP uint8_t
#define pOFF 0         // Disable
#define pHEAT 0x01     // Heating
#define pCOOL 0x02     // Cooling
#define pBOILER 0x04   // Boiler
#define pDEFROST 0x08  // Defrost the air vent
#define pCONTINUE 0x80 // flag Continuation

const char *MODE_HP_STR[] = {" Off ", " Heat ", " Cool ", " Boil ", " Defrost ", " C "};
const char MODE_HOUSE_WEBSTR[] = " Off: 0; Heating: 0; Cooling: 0; ";

//   Enumerated type - VT control commands
enum TYPE_COMMAND
{
    pEMPTY,     // 0 No teams
    pSTART,     // 1 Starting the heat pump (HANDS)
    pAUTOSTART, // 2 Starting the heat pump (automatic pRESTART pREPEAT)
    pSTOP,      // 3 Stop the heat pump
    pRESET,     // 4 Reset the controller
    pRESTART,   // 5 Starting the VT after the controller is reset (differs from pREPEAT only in delay)
    pREPEAT,    // 6 Relay restart                        (determined by the number of attempts to restart)
    pNETWORK,   // 7 reboot the network controller
    pJFORMAT,   // 8 formatting the log in I2C flash
    pSFORMAT,   // 9 formatting statistics in I2C flash
    pSAVE,      // 10 record settings of VT
    pWAIT,      // 11 switching to VT standby mode (empty schedule)
    pRESUME,    // 12 Restore from standby
    pPROG_FC,   // 13 Initial programming of the frequency converter
    pEND14      // Must be the last one, add BEFORE !!!
};

const char *hp_commands_names[] = {" EMPTY ", " START ", " AUTOSTART ", " STOP ", " RESET ", " RESTART ", " REPEAT ", " NETWORK ", " JFORMAT ", " SFORMAT ", " SAVE ", " WAIT ", " RESUME", " PROG_FC ", " UNKNOWN "};

//   Enumerated type - TYPES of notifications
enum message
{
    pMESSAGE_NONE,     // 0 No notifications
    pMESSAGE_TESTMAIL, // 1 Test mail notification +
    pMESSAGE_TESTSMS,  // 2 Test notification by SMS +
    pMESSAGE_RESET,    // 3 Notification Reset +
    pMESSAGE_ERROR,    // 4 Notification Error +
    pMESSAGE_LIFE,     // 5 Notification Life Signal +
    pMESSAGE_TEMP,     // 6 Notification Reaching limit temperature +
    pMESSAGE_SD,       // 7 Notification "Problems with sd card" +
    pMESSAGE_WARNING,  // 8 Notification "Other notifications"
    pEND10             // Must be the last, add BEFORE !!!
};

//   Enumerated type - service for sending SMS
enum SMS_SERVICE
{
    pSMS_RU,  // Service sms.ru
    pSMSC_RU, // Service smsc.ru
    pSMSC_UA, // Service smsc.ua
    pSMSCLUB  // Service smsclub.mobi
};

const char ADR_SMS_RU[] = " sms.ru ";
const char ADR_SMSC_RU[] = " smsc.ru ";
const char ADR_SMSC_UA[] = " smsc.ua ";
const char ADR_SMSCLUB[] = " gate.smsclub.mobi ";
const char SMS_SERVICE_WEB_SELECT[] = " sms.ru_b; smsc.ruogle; smsc.ua07; smsclub.mobi:07; ";

//   Enumerated type - Freon type
// enum TYPEFREON
// {
#define R22 0
#define R410A 1
#define R600A 2
#define R134A 3
#define R407C 4
#define R12 5
#define R290 6
#define R404A 7
#define R717 8 // Must be the last one, add BEFORE !!!
// };

//   Enumerated type - RED operation rule; five options are displayed depending on the availability of sensors
enum RULE_EEV
{
    TEVAOUT_PEVA,
#ifdef TCOMPIN
    TCOMPIN_PEVA,
#endif
#ifdef TEVAIN
    TEVAOUT_TEVAIN,
    TCOMPIN_TEVAIN,
    TABLE,
#endif
    MANUAL // Must be the last, add BEFORE !!!
};

//   Enumerated type - TN test mode
enum TEST_MODE
{
    NORMAL = 0,
    SAFE_TEST,
    TEST
        HARD_TEST // Must be the last, add BEFORE !!!
};

//   Enumerated type - Socket reset time
enum TIME_RES_SOCKET
{
    pNONE1,  // no reset
    p30sec,  // reset once every 30 seconds
    p300sec, // reset once every 300 seconds
    pEND4    // Must be the last, add BEFORE !!!
};

//   Enumerated type - heating algorithms
enum RULE_HP
{
    pHYSTERESIS, // hysteresis algorithm, interval mode
    pPID,        // algorithm using the PID controller
    pHYBRID,     // algorithm mixed algorithm, suggested by Ljutik
    pEND1        // Must be the last one, add BEFORE !!!
};

struct PID_STRUCT
{               // PID controller settings
    int16_t Kp; // PID Coef. proportions, in thousandths (negative)
    int16_t Ki; // PID Coef. integral, thousandths (negative)
    int16_t Kd; // PID Coef. differential, in thousandths (negative)
} __attribute __((packed));

#define trOH_default 2
#define trOH_TCOMP 3

struct PID_WORK_STRUCT
{ // PID variables of the controller
    union {
        int32_t sum;         // amount
        int16_t pre_err2[2]; // i = 0
        int8_t trend[4];     // i = trOH_ *
    };
    int16_t pre_err; // previous error for differentiation
    int32_t max;
#ifdef PID_FORMULA2
    union {
        int32_t min;
        uint8_t hyst[4]; // i = 0..1
    };
    boolean PropOnMeasure; // PID proportional to measurement, otherwise proportional to error
#else
    union {
        int16_t Kp_dmin; // The difference (in hundredths of a degree) at which there is a decrease in the proportional component of the PID ERV
        uint8_t hyst[2]; // i = 0..1
    };
#endif
};

#endif