From 9dcb9cfced12cad60a57b6da8e5ba7e42b50b6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Metrich?= <45318189+FredM67@users.noreply.github.com> Date: Mon, 1 May 2023 12:38:47 +0200 Subject: [PATCH] Add relay config class --- Mk2_3phase_RFdatalog_temp/config.h | 33 +++++++++++---------- Mk2_3phase_RFdatalog_temp/types.h | 47 ++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/Mk2_3phase_RFdatalog_temp/config.h b/Mk2_3phase_RFdatalog_temp/config.h index 1f668ebe..2d3c1493 100644 --- a/Mk2_3phase_RFdatalog_temp/config.h +++ b/Mk2_3phase_RFdatalog_temp/config.h @@ -66,23 +66,24 @@ inline constexpr bool DUAL_TARIFF{ false }; /**< set it to 'true' if th // D12 is MISO // D13 is SCK -inline constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]{ 5, 6, 7 }; /**< for 3-phase PCB, Load #1/#2/#3 (Rev 2 PCB) */ -inline uint8_t loadPrioritiesAndState[NO_OF_DUMPLOADS]{ 0, 1, 2 }; /**< load priorities and states at startup */ +inline constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]{ 5, 6, 7 }; /**< for 3-phase PCB, Load #1/#2/#3 (Rev 2 PCB) */ +inline uint8_t loadPrioritiesAndState[NO_OF_DUMPLOADS]{ 0, 1, 2 }; /**< load priorities and states at startup */ -inline constexpr uint8_t dualTariffPin{ 0xff }; /**< for 3-phase PCB, off-peak trigger */ -inline constexpr uint8_t diversionPin{ 0xff }; /**< if LOW, set diversion on standby */ -inline constexpr uint8_t rotationPin{ 0xff }; /**< if LOW, trigger a load priority rotation */ -inline constexpr uint8_t forcePin{ 0xff }; /**< for 3-phase PCB, force pin */ -inline constexpr uint8_t watchDogPin{ 0xff }; /**< watch dog LED */ +inline constexpr uint8_t relayPin{ 0xff }; /**< for 3-phase PCB, relay trigger */ +inline constexpr uint8_t dualTariffPin{ 0xff }; /**< for 3-phase PCB, off-peak trigger */ +inline constexpr uint8_t diversionPin{ 0xff }; /**< if LOW, set diversion on standby */ +inline constexpr uint8_t rotationPin{ 0xff }; /**< if LOW, trigger a load priority rotation */ +inline constexpr uint8_t forcePin{ 0xff }; /**< for 3-phase PCB, force pin */ +inline constexpr uint8_t watchDogPin{ 0xff }; /**< watch dog LED */ -inline constexpr uint8_t tempSensorPin{ 0xff }; /**< for 3-phase PCB, sensor pin */ +inline constexpr uint8_t tempSensorPin{ 0xff }; /**< for 3-phase PCB, sensor pin */ -inline constexpr uint8_t ul_OFF_PEAK_DURATION{ 8 }; /**< Duration of the off-peak period in hours */ -inline constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]{ { -3, 2 }, /**< force config for load #1 ONLY for dual tariff */ - { -3, 120 }, /**< force config for load #2 ONLY for dual tariff */ - { -180, 2 } }; /**< force config for load #3 ONLY for dual tariff */ +inline constexpr relayConfig relay_Config; /**< config for relay diversion */ -inline constexpr int16_t iTemperatureThreshold{ 100 }; /**< the temperature threshold to stop overriding in °C */ +inline constexpr uint8_t ul_OFF_PEAK_DURATION{ 8 }; /**< Duration of the off-peak period in hours */ +inline constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]{ { -3, 2 } }; /**< force config for load #1 ONLY for dual tariff */ + +inline constexpr int16_t iTemperatureThreshold{ 100 }; /**< the temperature threshold to stop overriding in °C */ inline constexpr DeviceAddress sensorAddrs[]{ { 0x28, 0xBE, 0x41, 0x6B, 0x09, 0x00, 0x00, 0xA4 }, { 0x28, 0xED, 0x5B, 0x6A, 0x09, 0x00, 0x00, 0x9D }, @@ -96,7 +97,7 @@ inline constexpr int16_t REQUIRED_EXPORT_IN_WATTS{ 20 }; /**< when set to a nega //-------------------------------------------------------------------------------------------------- // other system constants, should match most of installations -inline constexpr uint8_t SUPPLY_FREQUENCY{ 50 }; /**< number of cycles/s of the grid power supply */ +inline constexpr uint8_t SUPPLY_FREQUENCY{ 50 }; /**< number of cycles/s of the grid power supply */ inline constexpr uint8_t DATALOG_PERIOD_IN_SECONDS{ 5 }; /**< Period of datalogging in seconds */ inline constexpr uint16_t DATALOG_PERIOD_IN_MAINS_CYCLES{ DATALOG_PERIOD_IN_SECONDS * SUPPLY_FREQUENCY }; /**< Period of datalogging in cycles */ @@ -119,6 +120,6 @@ inline constexpr int nodeID{ 10 }; /**< RFM12B node ID */ inline constexpr int networkGroup{ 210 }; /**< wireless network group - needs to be same for all nodes */ inline constexpr int UNO{ 1 }; /**< for when the processor contains the UNO bootloader. */ -#endif // RF_PRESENT +#endif // RF_PRESENT -#endif // _CONFIG_H +#endif // _CONFIG_H diff --git a/Mk2_3phase_RFdatalog_temp/types.h b/Mk2_3phase_RFdatalog_temp/types.h index 3f136b79..aebedeb7 100644 --- a/Mk2_3phase_RFdatalog_temp/types.h +++ b/Mk2_3phase_RFdatalog_temp/types.h @@ -67,6 +67,49 @@ template< uint8_t N = 3, uint8_t S = 0 > class PayloadTx_struct int16_t temperature_x100[S]; /**< temperature in 100th of °C */ }; +/** + * @brief Config parameters for relay diversion + * + */ +class relayConfig +{ +public: + constexpr relayConfig() = default; + + constexpr relayConfig(uint16_t _surplusThreshold, uint16_t _importThreshold) + : surplusThreshold(_surplusThreshold), importThreshold(_importThreshold) + { + } + + constexpr relayConfig(uint16_t _surplusThreshold, uint16_t _importThreshold, uint16_t _minON, uint16_t _minOFF) + : surplusThreshold(_surplusThreshold), importThreshold(_importThreshold), minON(_minON * 60), minOFF(_minOFF * 60) + { + } + + constexpr uint16_t get_surplusThreshold() const + { + return surplusThreshold; + } + constexpr uint16_t get_importThreshold() const + { + return importThreshold; + } + constexpr uint16_t get_minON() const + { + return minON; + } + constexpr uint16_t get_minOFF() const + { + return minOFF; + } + +private: + uint16_t surplusThreshold{ 1000 }; /**< Surplus threshold to turn relay ON */ + uint16_t importThreshold{ 200 }; /**< Import threshold to turn relay OFF */ + uint16_t minON{ 5 * 60 }; /**< Minimum duration in seconds the relay is turned ON */ + uint16_t minOFF{ 5 * 60 }; /**< Minimum duration in seconds the relay is turned OFF */ +}; + /** @brief Config parameters for overriding a load * @details This class allows the user to define when and how long a load will be forced at * full power during off-peak period. @@ -122,7 +165,7 @@ struct Relay_Cfg * @tparam _Tp elements type * @tparam _Nm dimension */ -template< typename _Tp, size_t _Nm > constexpr size_t size(const _Tp (&/*__array*/)[_Nm]) noexcept +template< typename _Tp, size_t _Nm > constexpr size_t size(const _Tp (& /*__array*/)[_Nm]) noexcept { return _Nm; } @@ -132,7 +175,7 @@ template< typename _Tp, size_t _Nm > constexpr size_t size(const _Tp (&/*__array * * @tparam _Tp elements type */ -template< typename _Tp > constexpr size_t size(const _Tp (&/*__array*/)[0]) noexcept +template< typename _Tp > constexpr size_t size(const _Tp (& /*__array*/)[0]) noexcept { return 0; }