Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental : Arduino 3.0.2 + IDF v5.1.4.240629 platform #31

Merged
merged 48 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7f6b6f2
Arduino 3.0, IDF 5.1 changes
PBrunot May 24, 2024
a33ea4f
Updated to Arduino-3.0.0-rc3
PBrunot May 26, 2024
2896f8f
Removed constexpr due to linker warnings
PBrunot May 26, 2024
abbf12c
Fixed compiler warning on format string
PBrunot May 26, 2024
6aa3d7a
Updated watchdog to IDF v5.1 API
PBrunot May 26, 2024
733965e
Merge branch 'main' into idf5-arduino3
PBrunot May 26, 2024
aba97a3
Logging : now working with Arduino 3.0
PBrunot May 26, 2024
88be290
Tests: fixed logging
PBrunot May 26, 2024
f3e3c64
Watchdog: fixed failed initialization
PBrunot May 26, 2024
6c5603d
Merge branch 'main' into idf5-arduino3
PBrunot May 27, 2024
b08af85
Esp32: compatibility with IDF 5.1
PBrunot May 27, 2024
96bc3bd
Reduced warnings/errors
PBrunot May 27, 2024
ea7c8de
Added colored output
PBrunot May 27, 2024
b17b3d0
Update test_mqtt.cpp
PBrunot May 27, 2024
58738d7
Updated workflows to run if needed
PBrunot May 27, 2024
9b41266
Update sizes.yml
PBrunot May 27, 2024
1e112f9
Github actions: added sizes
PBrunot May 27, 2024
9b6eb45
Merge branch 'main' into idf5-arduino3
PBrunot May 30, 2024
515e2ed
Updating to latest IDF 5.1.14+Arduino 3.0.0
PBrunot May 30, 2024
7706b2d
Generate unique firmware artifact names
PBrunot May 30, 2024
ecf66b0
Warnings due to IDF 5.x redefining types from IDF 4.x
PBrunot May 30, 2024
2ab3aa3
Fixing regression
PBrunot May 30, 2024
205f64e
Update build.yml
PBrunot May 30, 2024
e724ef9
Update build.yml
PBrunot May 30, 2024
e0819b6
Espressif: bugfix MAC address
PBrunot Jun 1, 2024
c68bc45
compilation error
PBrunot Jun 1, 2024
584f6fa
Added PIOENV as build info
PBrunot Jun 1, 2024
519ca19
Bugfix #32 + Buzzer class and tests
PBrunot Jun 2, 2024
4393e5a
removed conf::machine::BEEP_PERIOD
PBrunot Jun 16, 2024
9b55185
Wrapped ESP.reset() inside esp32 namespace
PBrunot Jun 16, 2024
35c46af
LCD: Removed Warning if text is too long
PBrunot Jun 16, 2024
afae531
Merge branch 'main' into idf5-arduino3
PBrunot Jun 16, 2024
910b8e3
Update Tasks.hpp
PBrunot Jun 16, 2024
0d76230
Tasks: simplify sorting
PBrunot Jun 28, 2024
cd89efd
Lang: #ifdef instead of #if
PBrunot Jun 30, 2024
3a2e22c
MQTT: streaming Arduino String can be done without cstr()
PBrunot Jun 30, 2024
03e70ad
Merge branch 'main' into idf5-arduino3
PBrunot Jul 1, 2024
1a3dd45
Lcd: removed BaseLCDWrapper, as mockup is not needed
PBrunot Jul 1, 2024
8d47707
Tests: fix after LCDWrapper refactor
PBrunot Jul 1, 2024
f088769
Merge branch 'main' into idf5-arduino3
PBrunot Jul 1, 2024
621d84d
Update conf.hpp
PBrunot Jul 1, 2024
48ec065
Merge branch 'idf5-arduino3' of https://github.com/fablab-bergamo/fab…
PBrunot Jul 1, 2024
ce556fd
Merge branch 'main' into idf5-arduino3
PBrunot Jul 2, 2024
990f347
Upgrade to released espressif platform from Jason2866
PBrunot Jul 3, 2024
dbe00f5
Upgrade to Tasmota Espressif32 platform based on Arduino 3.0.2
PBrunot Jul 9, 2024
e8a2f51
MQTT: bugfix only first IP char is sent in aliveMessage
PBrunot Jul 9, 2024
dbfe19b
Merge branch 'main' into idf5-arduino3
PBrunot Jul 14, 2024
1301339
Tasks: using std::chrono ::steady_clock::time_point instead of millis
PBrunot Jul 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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