Skip to content

Commit

Permalink
Upgrade to Arduino 3.0.2 + IDF v5.1.4 via Tasmota esp32 platform (#31)
Browse files Browse the repository at this point in the history
* Arduino 3.0, IDF 5.1 changes

* Updated to Arduino-3.0.0-rc3

* Removed constexpr due to linker warnings

* Fixed compiler warning on format string

* Updated watchdog to IDF v5.1 API

* Logging : now working with Arduino 3.0

* Tests: fixed logging

* Watchdog: fixed failed initialization

* Esp32: compatibility with IDF 5.1

* Reduced warnings/errors

* Added colored output

* Update test_mqtt.cpp

* Updated workflows to run if needed

* Update sizes.yml

* Github actions: added sizes

* Updating to latest IDF 5.1.14+Arduino 3.0.0

* Generate unique firmware artifact names

* Warnings due to IDF 5.x redefining types from IDF 4.x

* Fixing regression

* Update build.yml

* Update build.yml

* Espressif: bugfix MAC address

* compilation error

* Added PIOENV as build info

* Bugfix #32 + Buzzer class and tests

* removed conf::machine::BEEP_PERIOD

* Wrapped ESP.reset() inside esp32 namespace

* LCD: Removed Warning if text is too long

* Update Tasks.hpp

* Tasks: simplify sorting

* Lang: #ifdef instead of #if

* MQTT: streaming Arduino String can be done without cstr()

* Lcd: removed BaseLCDWrapper, as mockup is not needed

* Tests: fix after LCDWrapper refactor

* Update conf.hpp

* Upgrade to released espressif platform from Jason2866

see https://github.com/Jason2866/platform-espressif32/releases/tag/2024.07.20

* Upgrade to Tasmota Espressif32 platform based on Arduino 3.0.2

* MQTT: bugfix only first IP char is sent in aliveMessage

* Tasks: using std::chrono ::steady_clock::time_point instead of millis
  • Loading branch information
PBrunot committed Jul 14, 2024
1 parent 0da0118 commit 5095622
Show file tree
Hide file tree
Showing 28 changed files with 430 additions and 210 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ jobs:
run: cp conf/secrets.hpp.example conf/secrets.hpp
- name: Build PlatformIO Project ${{ matrix.variant }}
run: pio run --environment ${{ matrix.variant }}
- name: Set sha_short variable
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Upload firmware image for ${{ matrix.variant }}
uses: actions/upload-artifact@v4
with:
name: Firmware files for ${{ matrix.variant }}
name: FW-${{ matrix.variant }}-${{ steps.vars.outputs.sha_short }}
path: |
.pio/build/${{ matrix.variant }}/firmware.bin
.pio/build/${{ matrix.variant }}/firmware_metrics.txt
Expand Down
102 changes: 102 additions & 0 deletions .github/workflows/tags_sizes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Compare firmware sizes (tag)

on:
workflow_dispatch:
push:
tags:
- '*' # Trigger on all tags

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
size_report:
runs-on: ubuntu-latest
strategy:
matrix:
variant:
- hardware-rev0-it_IT
- esp32-devboard
steps:
- name: Check out the code
uses: actions/checkout@v4
with:
fetch-depth: 50

- name: Install PlatformIO Core
uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install --upgrade platformio

- name: Use secrets.hpp.example as base for the build
run: cp conf/secrets.hpp.example conf/secrets.hpp

- name: Build PlatformIO Project (current version)
run: pio run --environment ${{ matrix.variant }}

- name: Copy latest MAP file
run: cp .pio/build/${{ matrix.variant }}/firmware.map ../firmware.map.latest

- name: Find previous tag
id: prev_tag
run: |
tags=$(git tag --sort=-creatordate)
for tag in $tags; do
if [ "$tag" != "${GITHUB_REF#refs/tags/}" ]; then
echo "previous_tag=$tag" >> $GITHUB_ENV
break
fi
done
- name: Check out previous tag
run: git checkout ${{ env.previous_tag }}

- name: Use secrets.hpp.example as base for the build
run: cp conf/secrets.hpp.example conf/secrets.hpp

- name: Build PlatformIO Project (previous version)
run: pio run --environment ${{ matrix.variant }}

- name: Copy previous MAP file
run: cp .pio/build/${{ matrix.variant }}/firmware.map ../firmware.map.previous

- name: Compare MAP files
run: python -m esp_idf_size --format=text --diff=../firmware.map.previous ../firmware.map.latest -o size_report.txt

- name: Detailed report
run: python -m esp_idf_size --archives --format=text --diff=../firmware.map.previous ../firmware.map.latest -o size_report_details.txt

- name: Upload size report
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.variant }}_size_report
path: |
size_report.txt
size_report_details.txt
retention-days: 90

- name: Comment size changes on release/tag page
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const report = fs.readFileSync('size_report.txt', 'utf8');
const previousTag = process.env.previous_tag;
if (report) {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.ref.substring(10)
});
const truncatedReport = report.length > 63*1024 ? report.substring(0, 63*1024) + '... (truncated)' : report;
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
body: release.data.body + '\n\n## Firmware size changes for ${{ matrix.variant }}\n\nCommit CURRENT ' + context.sha + ' vs REFERENCE ' + previousTag + '\n```\n' + truncatedReport + '\n```'
});
}
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- test_logic
- test_savedconfig
- test_tasks
- test_chrono
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ log.txt
rfid-arduino.code-workspace
secrets.hpp
tools/__pycache__/
build/
managed_components/
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@
"set": "cpp",
"future": "cpp",
"variant": "cpp",
"any": "cpp"
"any": "cpp",
"bit": "cpp",
"compare": "cpp",
"concepts": "cpp",
"netfwd": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"stop_token": "cpp"
},
"cmake.sourceDirectory": "D:/GitHub/rfid-arduino/.pio/libdeps/desktop/ArduinoJson",
"cmake.configureOnOpen": false,
Expand Down
9 changes: 5 additions & 4 deletions include/AuthProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <string_view>
#include <tuple>
#include <optional>

#include "FabUser.hpp"
#include "secrets.hpp"
Expand All @@ -20,10 +21,10 @@ namespace fabomatic
WhiteList whitelist;
mutable CachedCards cache;
mutable size_t cache_idx{0};
[[nodiscard]] auto uidInWhitelist(card::uid_t uid) const -> std::optional<WhiteListEntry>;
[[nodiscard]] auto uidInCache(card::uid_t uid) const -> std::optional<CachedCard>;
[[nodiscard]] auto searchCache(card::uid_t candidate_uid) const -> std::optional<CachedCard>;
auto updateCache(card::uid_t candidate_uid, FabUser::UserLevel level) const -> void;
[[nodiscard]] constexpr auto uidInWhitelist(card::uid_t uid) const -> std::optional<WhiteListEntry>;
[[nodiscard]] constexpr auto uidInCache(card::uid_t uid) const -> std::optional<CachedCard>;
[[nodiscard]] constexpr auto searchCache(card::uid_t candidate_uid) const -> std::optional<CachedCard>;
constexpr auto updateCache(card::uid_t candidate_uid, FabUser::UserLevel level) const -> void;

public:
AuthProvider() = delete;
Expand Down
3 changes: 2 additions & 1 deletion include/CachedCards.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CACHEDCARDS_HPP

#include <array>
#include <optional>

#include "FabUser.hpp"
#include "conf.hpp"
Expand Down Expand Up @@ -32,7 +33,7 @@ namespace fabomatic
return {cards[i], levels[i]};
}

auto find_uid(const card::uid_t &search_uid) const -> const std::optional<CachedCard>
constexpr auto find_uid(const card::uid_t &search_uid) const -> const std::optional<CachedCard>
{
if (search_uid == card::INVALID)
{
Expand Down
7 changes: 6 additions & 1 deletion include/Logging.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef LOGGING_HPP_
#define LOGGING_HPP_

#include "esp_log.h"
#ifndef LOG_LOCAL_LEVEL
#define LOG_LOCAL_LEVEL 5
#endif

#undef TAG
[[maybe_unused]] static const char *const TAG = "FAB-O-MATIC"; // Required for ESP32 Logging

#include "esp_log.h"

#endif // LOGGING_HPP_
5 changes: 3 additions & 2 deletions include/Machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <array>
#include <chrono>
#include <cstdint>
#include <optional>

namespace fabomatic
{
Expand Down Expand Up @@ -106,8 +107,8 @@ namespace fabomatic
bool active{false};
FabUser current_user{};

std::optional<std::chrono::time_point<std::chrono::system_clock>> usage_start_timestamp{std::nullopt}; // When did the machine start?
std::optional<std::chrono::time_point<std::chrono::system_clock>> logoff_timestamp{std::nullopt}; // When did the last user log off?
std::optional<std::chrono::steady_clock::time_point> usage_start_timestamp{std::nullopt}; // When did the machine start?
std::optional<std::chrono::steady_clock::time_point> logoff_timestamp{std::nullopt}; // When did the last user log off?
PowerState power_state{PowerState::PoweredOff};

/// @brief If true, machine needs maintenance
Expand Down
37 changes: 23 additions & 14 deletions include/Tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@

#include <chrono>
#include <functional>
#include "Arduino.h"
#include <list>

/// @brief This namespace contains the classes that implement a cooperative task scheduler
namespace fabomatic::Tasks
{
using milliseconds = std::chrono::milliseconds;
using time_point_sc = std::chrono::time_point<std::chrono::system_clock>;
using namespace std::chrono_literals;

[[nodiscard]] inline auto arduinoNow() -> const std::chrono::steady_clock::time_point
{
return std::chrono::steady_clock::now();
}

class Scheduler;

/// @brief A task class which represents a function to be called at requested intervals
Expand Down Expand Up @@ -63,7 +69,7 @@ namespace fabomatic::Tasks
[[nodiscard]] auto isActive() const -> bool;

/// @brief Current period of the task
[[nodiscard]] auto getPeriod() const -> milliseconds;
[[nodiscard]] auto getPeriod() const -> const milliseconds;

/// @brief Function to be called when task is run
/// @return Callback function
Expand All @@ -74,28 +80,30 @@ namespace fabomatic::Tasks

/// @brief Get the initial delay before the task is run at given period
/// @return Delay in milliseconds
[[nodiscard]] auto getDelay() const -> milliseconds;
[[nodiscard]] auto getDelay() const -> const milliseconds;

/// @brief Get the average tardiness, i.e. the average period between scheduled start and actual start of execution.
[[nodiscard]] auto getAvgTardiness() const -> milliseconds;
[[nodiscard]] auto getAvgTardiness() const -> const milliseconds;

/// @brief Gets the number of times the task has been run.
[[nodiscard]] auto getRunCounter() const -> unsigned long;

/// @brief Gets the total execution time of the task. Useful to spot slowest tasks
[[nodiscard]] auto getTotalRuntime() const -> milliseconds;
[[nodiscard]] auto getTotalRuntime() const -> const milliseconds;

/// @brief When shall the task be run again
/// @return time_point of the next run or time_point::max() if the task will not run.
[[nodiscard]] auto getNextRun() const -> time_point_sc;
[[nodiscard]] auto getNextRun() const -> const std::chrono::steady_clock::time_point;

[[nodiscard]] auto toString() const -> const std::string;

private:
bool active;
const std::string id;
milliseconds period;
milliseconds delay;
time_point_sc last_run;
time_point_sc next_run;
std::chrono::steady_clock::time_point last_run;
std::chrono::steady_clock::time_point next_run;
milliseconds average_tardiness;
milliseconds total_runtime;
std::function<void()> callback;
Expand All @@ -106,24 +114,25 @@ namespace fabomatic::Tasks
class Scheduler
{
public:
auto addTask(Task &task) -> void;
auto removeTask(const Task &task) -> void;
constexpr Scheduler(){};
auto addTask(Task *task) -> void;
auto removeTask(const Task *task) -> void;

/// @brief Execute all tasks that are ready to run
/// @details Tasks will be ordered by next_run time ascending, then run sequentially
auto execute() const -> void;
auto execute() -> void;

/// @brief Recompute all the next run times for all the tasks
auto updateSchedules() const -> void;

/// @brief Gets the number of tasks in the scheduler
[[nodiscard]] auto taskCount() const -> size_t;

/// @brief Get a vector of references to the tasks
[[nodiscard]] auto getTasks() const -> const std::vector<std::reference_wrapper<Task>>;
/// @brief Get a copy vector of task pointers
[[nodiscard]] auto getTasks() const -> const std::vector<Task *>;

private:
std::vector<std::reference_wrapper<Task>> tasks; // Vector containing references to the tasks, not the tasks themselves
std::vector<Task *> tasks;

auto printStats() const -> void;
};
Expand Down
1 change: 1 addition & 0 deletions include/card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "conf.hpp"

#include "Logging.hpp"
#include <esp_mac.h>

namespace fabomatic::card
{
Expand Down
2 changes: 1 addition & 1 deletion include/mock/MockMrfc522.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace fabomatic
{
private:
std::optional<card::uid_t> uid{std::nullopt};
std::optional<std::chrono::time_point<std::chrono::system_clock>> stop_uid_simulate_time{std::nullopt};
std::optional<std::chrono::steady_clock::time_point> stop_uid_simulate_time{std::nullopt};
std::optional<card::uid_t> getSimulatedUid() const;

public:
Expand Down
Loading

0 comments on commit 5095622

Please sign in to comment.