Skip to content

Commit

Permalink
Merge branch 'main' into idf5-arduino3
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrunot committed Jul 2, 2024
2 parents 48ec065 + 4db597d commit ce556fd
Show file tree
Hide file tree
Showing 36 changed files with 199 additions and 300 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ EXCLUDE_PATTERNS = */.git*
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories use the pattern */test/*

EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = std::*

# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
Expand Down
208 changes: 66 additions & 142 deletions conf/conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,241 +11,165 @@ namespace fabomatic
{
using namespace std::chrono_literals;

/// @brief Machine-related default settings
namespace conf::default_config
{
/**
* Name of the default server for Backend. Will be resolved through mDNS
*/
static constexpr std::string_view mqtt_server{"fabpi2.local"};

/**
* In case Shelly is used, name of the topic on MQTT Broker
*/
static constexpr std::string_view mqtt_switch_topic{""};

/**
* What value shall be written on the topic to switch on the Shelly device
*/
static constexpr std::string_view mqtt_switch_on_message{"on"};

/**
* What value shall be written on the topic to switch off the Shelly device
*/
static constexpr std::string_view mqtt_switch_off_message{"off"};

/**
* Default MachineID for backend. Can be overriden through WiFi Portal config
*/
/// @brief Default MachineID for backend. Can be overriden through WiFi Portal config
static constexpr MachineID machine_id{1};

/**
* Default machine name for LCD. Will be overriden with Backend config data
*/
/// @brief Default machine name for LCD. Will be overriden with Backend config data
static constexpr std::string_view machine_name{"MACHINE1"};

/**
* Default machine type. No impact on code
*/
/// @brief Default machine type. No impact on code
static constexpr MachineType machine_type{MachineType::Printer3D};

/**
* Default hostname for the ESP32 board, Machine ID will be added to the hostname in order to form unique hostnames
*/
/// @brief Default hostname for the ESP32 board, Machine ID will be added to the hostname in order to form unique hostnames
static constexpr std::string_view hostname{"BOARD"};

} // namespace conf::default_config

/**
* Configuration for RFID related settings
*/
/// @brief RFID-related settings
namespace conf::rfid_tags
{
/* Number of bytes in RFID cards UID, may depend on specific RFID chip */
/// @brief Number of bytes in RFID cards UID, may depend on specific RFID chip
static constexpr uint8_t UID_BYTE_LEN{4};
/* Number of cached UID, persisted in flash */
/// @brief Number of cached UID, persisted in flash
static constexpr uint8_t CACHE_LEN{10};

} // namespace conf::rfid_tags

/**
* Configuration for LCD pannel
*/
/// @brief Configuration for LCD pannel
namespace conf::lcd
{
/**
* Number of rows for LCD display
*/
/// @brief Number of rows for LCD display
static constexpr uint8_t ROWS{2};
/**
* Number of cols for LCD display
*/

/// @brief Number of cols for LCD display
static constexpr uint8_t COLS{16};
/**
* How much time shall we wait for a short message on LCD for user
*/

/// @brief How much time shall we wait for a short message on LCD for user
static constexpr auto SHORT_MESSAGE_DELAY{1s};

} // namespace conf::lcd

/**
* Configuration for connected machine
*/
/// @brief Configuration for connected machine
namespace conf::machine
{
/**
* User will be log out after this delay. If 0h, no auto-logout. This may be overriden by backend data
*/
/// @brief User will be log out after this delay. If 0h, no auto-logout. This may be overriden by backend data
static constexpr auto DEFAULT_AUTO_LOGOFF_DELAY{12h};

/**
* Idle time before poweroff. If 0min, machine will stay on.
*/
/// @brief Idle time before poweroff. If 0min, machine will stay on.
static constexpr auto DEFAULT_GRACE_PERIOD{90s};

/**
* Beeps will be heard every 30s when the machine is in grace period
*/
/// @brief Beeps will be heard every 30s when the machine is in grace period
static constexpr auto DELAY_BETWEEN_BEEPS{30s};

/**
* If true, machine needing maintenance will be blocked for normal users
*/
/// @brief If true, machine needing maintenance will be blocked for normal users
static constexpr bool MAINTENANCE_BLOCK{true};

/**
* Minimum time to confirm by long tap maintenance
*/
/// @brief Minimum time to confirm by long tap maintenance
static constexpr auto LONG_TAP_DURATION{10s};

} // namespace conf::machine

/// @brief Debug settings
namespace conf::debug
{
/**
* True to add logs to serial output
*/
/// @brief True to add logs to serial output
static constexpr bool ENABLE_LOGS{true};
/**
* True to add many logs regarding tasks scheduling and statistics
*/

/// @brief True to add many logs regarding tasks scheduling and statistics
static constexpr bool ENABLE_TASK_LOGS{false};
/**
* Serial speed in bauds
*/

/// @brief Serial speed in bauds
static constexpr unsigned long SERIAL_SPEED_BDS{115200};
/**
* True to force portal startup. May be useful to override saved configuration
*/

/// @brief True to force portal startup. May be useful to override saved configuration
static constexpr bool FORCE_PORTAL{false};
/**
* True to force EEPROM settings to defaults, regardless of actual values.
*/

/// @brief True to force EEPROM settings to defaults, regardless of actual values.
static constexpr bool LOAD_EEPROM_DEFAULTS{false};
/**
* True if important MQTT messages should be saved when network is down and replayed.
*/

/// @brief True if important MQTT messages should be saved when network is down and replayed.
static constexpr bool ENABLE_BUFFERING{true};

} // namespace conf::debug

/**
* Configuration for buzzer
*/
/// @brief Configuration for buzzer
namespace conf::buzzer
{
/**
* Single beep duration, typical value 200ms. Set to 0 to disable beeps.
*/
/// @brief Single beep duration, typical value 200ms. Set to 0 to disable beeps.
static constexpr auto STANDARD_BEEP_DURATION{250ms};
/**
* Number of beeps every time the function is called
*/

/// @brief Number of beeps every time the function is called
static constexpr auto NB_BEEPS{3};

} // namespace conf::buzzer

/**
* Configuration related to tasks scheduling
*/
/// @brief Configuration related to tasks scheduling
namespace conf::tasks
{
/**
* Task period to check for RFID badge (should be fast: 150ms)
*/
/// @brief Task period to check for RFID badge (should be fast: 150ms)
static constexpr auto RFID_CHECK_PERIOD{150ms};

/**
* Performs RFID self check and reset chip if necessary (default: 60s)
*/
/// @brief Performs RFID self check and reset chip if necessary (default: 60s)
static constexpr auto RFID_SELFTEST_PERIOD{60s};

/**
* Query the MQTT broker for machine state at given period (default: 30s)
*/
/// @brief Query the MQTT broker for machine state at given period (default: 30s)
static constexpr auto MQTT_REFRESH_PERIOD{30s};

/**
* Timeout for hardware watchdog, set to 0s to disable (default: 60s)
*/
/// @brief Timeout for hardware watchdog, set to 0s to disable (default: 60s)
static constexpr auto WATCHDOG_TIMEOUT{60s};

/**
* Period of the watchdog signaling task (default 1s)
*/
/// @brief Period of the watchdog signaling task (default 1s)
static constexpr auto WATCHDOG_PERIOD{1s};

/**
* Timeout for portal configuration (default: 5min)
*/
/// @brief Timeout for portal configuration (default: 5min)
static constexpr auto PORTAL_CONFIG_TIMEOUT{5min};

/**
* Board announcement on the MQTT server (default: 2min)
*/
/// @brief Board announcement on the MQTT server (default: 2min)
static constexpr auto MQTT_ALIVE_PERIOD{2min};

} // namespace conf::tasks

/**
* Configuration regarding MQTT broker, topics
*/
/// @brief Configuration regarding MQTT broker, topics
namespace conf::mqtt
{
/**
* Initial part of the topic, machine ID will be added
*/
/// @brief Initial part of the topic, machine ID will be added
static constexpr std::string_view topic{"machine"};

/**
* Backend reply (sub-topic of the full machine topic)
*/
/// @brief Backend reply (sub-topic of the full machine topic)
static constexpr std::string_view response_topic{"/reply"};

/**
* Number of tries to get a reply from the backend
*/
/// @brief Number of tries to get a reply from the backend
static constexpr auto MAX_TRIES{2};

/**
* Timeout for a single backend reply request.
*/
/// @brief Timeout for a single backend reply request.
static constexpr auto TIMEOUT_REPLY_SERVER{2s};

/**
* MQTT port for broker
*/
/// @brief MQTT port for broker
static constexpr auto PORT_NUMBER{1883};

/// @brief Name of the default server for Backend. Will be resolved through mDNS
static constexpr std::string_view mqtt_server{"fabpi2.local"};

/// @brief In case Shelly is used, name of the topic on MQTT Broker
static constexpr std::string_view mqtt_switch_topic{""};

/// @brief What value shall be written on the topic to switch on the Shelly device
static constexpr std::string_view mqtt_switch_on_message{"on"};

/// @brief What value shall be written on the topic to switch off the Shelly device
static constexpr std::string_view mqtt_switch_off_message{"off"};
} // namespace conf::mqtt

/// @brief Other compile-time settings
namespace conf::common
{
/**
* Maximum length of saved string in WiFiManager portal.
*/
/// @brief Maximum length of saved string in WiFiManager portal.
static constexpr auto STR_MAX_LENGTH{40U};
/**
* Maximum length of saved integer in WiFiManager portal.
*/

/// @brief Maximum length of saved integer in WiFiManager portal.
static constexpr auto INT_MAX_LENGTH{5U};
}

Expand Down
27 changes: 8 additions & 19 deletions conf/secrets.hpp.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@
#include "conf.hpp"
#include "FabUser.hpp"

/**
* Whitelisted RFID cards
*/
/// @brief Whitelisted RFID cards
namespace fabomatic::secrets::cards
{
/**
* Number of whitelisted card in the array below
*/
/// @brief Number of whitelisted card in the array below
static constexpr uint8_t LEN = 10U;

using WhiteListEntry = std::tuple<card::uid_t, FabUser::UserLevel, std::string_view>;
using WhiteList = std::array<WhiteListEntry, LEN>;

/**
* Static list of whitelisted RFID cards. If the network is down, these cards will be
* authorized. If network is up, backend prevails.
*/
/// @brief Static list of whitelisted RFID cards.
/// @note If the network is down, these cards will be authorized. If network is up, backend prevails.
static constexpr WhiteList whitelist{
std::make_tuple(0xAABBCCD1, FabUser::UserLevel::FabAdmin, "ABCDEFG"),
std::make_tuple(0xAABBCCD2, FabUser::UserLevel::FabAdmin, "PIPPO"),
Expand All @@ -39,9 +33,7 @@ namespace fabomatic::secrets::cards
std::make_tuple(0xAABBCCDA, FabUser::UserLevel::FabStaff, "USER8")};
} // namespace fabomatic::secrets::cards

/**
* WiFi and MQTT credentials
*/
/// @brief WiFi and MQTT credentials
namespace fabomatic::secrets::credentials
{

Expand All @@ -53,13 +45,10 @@ namespace fabomatic::secrets::credentials
static constexpr std::string_view password = "MYPWD"; /* Default password */
#endif

/**
* Username for MQTT broker auth.
*/
/// @brief Username for MQTT broker auth.
static constexpr std::string_view mqtt_user = "user";
/**
* Username for MQTT broker auth.
*/

/// @brief Username for MQTT broker auth.
static constexpr std::string_view mqtt_password = "password";

// Checks
Expand Down
4 changes: 1 addition & 3 deletions include/AuthProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

namespace fabomatic
{
/**
* This class manages authentication of a RFID tag through cache, whitelist or network request.
*/
/// @brief This class manages authentication of a RFID tag through cache, whitelist or network request.
class AuthProvider
{
private:
Expand Down
4 changes: 1 addition & 3 deletions include/BaseRfidWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

namespace fabomatic
{
/**
* Base class for the real and mock implementation of RFID tag reader chip.
*/
/// @brief Base class for the real and mock implementation of RFID tag reader chip.
class BaseRFIDWrapper
{
public:
Expand Down
Loading

0 comments on commit ce556fd

Please sign in to comment.