Skip to content

Commit

Permalink
Reorganize includes
Browse files Browse the repository at this point in the history
  • Loading branch information
FredM67 committed May 1, 2023
1 parent 5975daf commit 52f7f98
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 149 deletions.
3 changes: 3 additions & 0 deletions Mk2_3phase_RFdatalog_temp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "debug.h"
#include "types.h"

#include "utils_relay.h"
#include "utils_temp.h"

//--------------------------------------------------------------------------------------------------
// constants which must be set individually for each system
//
Expand Down
147 changes: 0 additions & 147 deletions Mk2_3phase_RFdatalog_temp/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,150 +67,6 @@ 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;

/**
* @brief Construct a new relay Config object
*
* @param _surplusThreshold Surplus threshold to turn relay ON
* @param _importThreshold Import threshold to turn relay OFF
*/
constexpr relayConfig(int16_t _surplusThreshold, int16_t _importThreshold)
: surplusThreshold(abs(_surplusThreshold)), importThreshold(abs(_importThreshold))
{
}

/**
* @brief Construct a new relay Config object
*
* @param _surplusThreshold Surplus threshold to turn relay ON
* @param _importThreshold Import threshold to turn relay OFF
* @param _minON Minimum duration to leave relay ON
* @param _minOFF Minimum duration in minutes to l
*/
constexpr relayConfig(int16_t _surplusThreshold, int16_t _importThreshold, uint16_t _minON, uint16_t _minOFF)
: surplusThreshold(abs(_surplusThreshold)), importThreshold(abs(_importThreshold)), minON(_minON * 60), minOFF(_minOFF * 60)
{
}

/**
* @brief Get the surplus threshold which will turns ON the relay
*
* @return constexpr auto
*/
constexpr auto get_surplusThreshold() const
{
return surplusThreshold;
}

/**
* @brief Get the import threshold which will turns OFF the relay
*
* @return constexpr auto
*/
constexpr auto get_importThreshold() const
{
return importThreshold;
}

/**
* @brief Get the minimum ON-time
*
* @return constexpr auto
*/
constexpr auto get_minON() const
{
return minON;
}

/**
* @brief Get the minimum OFF-time
*
* @return constexpr auto
*/
constexpr auto get_minOFF() const
{
return minOFF;
}

/**
* @brief Increment the duration of the current state
*
*/
void inc_duration()
{
++duration;
}

/**
* @brief Proceed with the relay
*
* @param currentAvgPower Current sliding average power
*/
void proceed_relay(int16_t currentAvgPower)
{
if (currentAvgPower > surplusThreshold)
{
try_turnON();
}
else if (-currentAvgPower > importThreshold)
{
try_turnOFF();
}
}

private:
/**
* @brief Turn ON the relay if the 'time' condition is met
*
*/
void try_turnON()
{
if (relayState)
{
return;
}
if (duration > minOFF)
{
relayState = true;
duration = 0;
}
}

/**
* @brief Turn OFF the relay if the 'time' condition is met
*
*/
void try_turnOFF()
{
if (!relayState)
{
return;
}
if (duration > minON)
{
relayState = false;
duration = 0;
}
}

private:
int16_t surplusThreshold{ 1000 }; /**< Surplus threshold to turn relay ON */
int16_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 */

uint16_t duration{ 0 }; /**< Duration of the current state */
bool relayState{ false }; /**< State of the relay */
};

/** @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.
Expand Down Expand Up @@ -248,9 +104,6 @@ class pairForceLoad
uint16_t uiDuration{ UINT16_MAX }; /**< the duration for overriding the load in hours or minutes */
};

using ScratchPad = uint8_t[9];
using DeviceAddress = uint8_t[8];

/**
* @brief Helper function to retrieve the dimension of a C-array
*
Expand Down
144 changes: 144 additions & 0 deletions Mk2_3phase_RFdatalog_temp/utils_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,148 @@

#include "types.h"

/**
* @brief Config parameters for relay diversion
*
*/
class relayConfig
{
public:
constexpr relayConfig() = default;

/**
* @brief Construct a new relay Config object
*
* @param _surplusThreshold Surplus threshold to turn relay ON
* @param _importThreshold Import threshold to turn relay OFF
*/
constexpr relayConfig(int16_t _surplusThreshold, int16_t _importThreshold)
: surplusThreshold(abs(_surplusThreshold)), importThreshold(abs(_importThreshold))
{
}

/**
* @brief Construct a new relay Config object
*
* @param _surplusThreshold Surplus threshold to turn relay ON
* @param _importThreshold Import threshold to turn relay OFF
* @param _minON Minimum duration to leave relay ON
* @param _minOFF Minimum duration in minutes to l
*/
constexpr relayConfig(int16_t _surplusThreshold, int16_t _importThreshold, uint16_t _minON, uint16_t _minOFF)
: surplusThreshold(abs(_surplusThreshold)), importThreshold(abs(_importThreshold)), minON(_minON * 60), minOFF(_minOFF * 60)
{
}

/**
* @brief Get the surplus threshold which will turns ON the relay
*
* @return constexpr auto
*/
constexpr auto get_surplusThreshold() const
{
return surplusThreshold;
}

/**
* @brief Get the import threshold which will turns OFF the relay
*
* @return constexpr auto
*/
constexpr auto get_importThreshold() const
{
return importThreshold;
}

/**
* @brief Get the minimum ON-time
*
* @return constexpr auto
*/
constexpr auto get_minON() const
{
return minON;
}

/**
* @brief Get the minimum OFF-time
*
* @return constexpr auto
*/
constexpr auto get_minOFF() const
{
return minOFF;
}

/**
* @brief Increment the duration of the current state
*
*/
void inc_duration()
{
++duration;
}

/**
* @brief Proceed with the relay
*
* @param currentAvgPower Current sliding average power
*/
void proceed_relay(int16_t currentAvgPower)
{
if (currentAvgPower > surplusThreshold)
{
try_turnON();
}
else if (-currentAvgPower > importThreshold)
{
try_turnOFF();
}
}

private:
/**
* @brief Turn ON the relay if the 'time' condition is met
*
*/
void try_turnON()
{
if (relayState)
{
return;
}
if (duration > minOFF)
{
relayState = true;
duration = 0;
}
}

/**
* @brief Turn OFF the relay if the 'time' condition is met
*
*/
void try_turnOFF()
{
if (!relayState)
{
return;
}
if (duration > minON)
{
relayState = false;
duration = 0;
}
}

private:
int16_t surplusThreshold{ 1000 }; /**< Surplus threshold to turn relay ON */
int16_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 */

uint16_t duration{ 0 }; /**< Duration of the current state */
bool relayState{ false }; /**< State of the relay */
};

#endif // _UTILS_RELAY_H
5 changes: 3 additions & 2 deletions Mk2_3phase_RFdatalog_temp/utils_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

#include "config.h"
#include "constants.h"
#include "dualtariff.h"
#include "processing.h"

using ScratchPad = uint8_t[9];
using DeviceAddress = uint8_t[8];

inline int16_t readTemperature(const DeviceAddress &deviceAddress);
inline void requestTemperatures();
Expand Down

0 comments on commit 52f7f98

Please sign in to comment.