Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrunot committed Apr 25, 2024
1 parent 5165e3a commit 2c6e3c0
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 25 deletions.
7 changes: 4 additions & 3 deletions include/Mrfc522Driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Arduino.h"
#include <memory>
#include <array>

#include "FabUser.hpp"
#include "MFRC522Debug.h"
Expand All @@ -24,9 +25,9 @@ namespace fablabbg
public:
struct UidDriver
{
byte size; // Number of bytes in the UID. 4, 7 or 10.
byte uidByte[10];
byte sak; // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
byte size; // Number of bytes in the UID. 4, 7 or 10.
std::array<byte, 10> uidByte{0}; // The UID (Unique Identifier) of the PICC.
byte sak; // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
};

Mrfc522Driver();
Expand Down
2 changes: 1 addition & 1 deletion include/RFIDWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace fablabbg
RFIDWrapper &operator=(const RFIDWrapper &x) = delete; // copy assignment
RFIDWrapper(RFIDWrapper &&) = delete; // move constructor
RFIDWrapper &operator=(RFIDWrapper &&) = delete; // move assignment
~RFIDWrapper() = default; // Default destructor
~RFIDWrapper() override{}; // Default destructor
};
} // namespace fablabbg

Expand Down
3 changes: 0 additions & 3 deletions include/Tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ namespace fablabbg::Tasks
class Scheduler
{
public:
Scheduler() : tasks{} {};
~Scheduler() = default;

auto addTask(Task &task) -> void;
auto removeTask(const Task &task) -> void;

Expand Down
4 changes: 2 additions & 2 deletions include/WhiteList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace fablabbg
namespace conf::cards
{
static constexpr auto LEN = 10U; /* Number of whitelisted cards */
}
} // namespace conf::cards

using WhiteListEntry = std::tuple<card::uid_t, FabUser::UserLevel, std::string_view>;
using WhiteList = std::array<WhiteListEntry, conf::cards::LEN>;
Expand Down Expand Up @@ -47,6 +47,6 @@ namespace fablabbg

return sorted1 == sorted2;
}
}
} // namespace fablabbg

#endif // WHITELIST_HPP
15 changes: 14 additions & 1 deletion include/card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace fablabbg::card
{
using uid_t = u_int64_t;
static constexpr uid_t INVALID = 0ULL;

/// @brief Returns a string representation of the UID
/// @param uid number to convert
/// @return an hex string representation of the UID (e.g. "123456ADCD")
Expand Down Expand Up @@ -42,6 +42,19 @@ namespace fablabbg::card
return result;
}

/// @brief Converts a UID from an array of bytes to a number
/// @param uid array of bytes
/// @return the UID as a number
[[nodiscard]] constexpr inline auto to_array(const uid_t uid) -> std::array<uint8_t, conf::rfid_tags::UID_BYTE_LEN>
{
std::array<uint8_t, conf::rfid_tags::UID_BYTE_LEN> retVal{0};
for (auto i = (conf::rfid_tags::UID_BYTE_LEN - 1); i >= 0; i--)
{
retVal[i] = (uid >> (i * 8)) & 0xFF;
}
return retVal;
}

inline void print(uint64_t uid)
{
ESP_LOGI(TAG, "Card UID = %s", card::uid_str(uid).c_str());
Expand Down
8 changes: 5 additions & 3 deletions include/mock/MockMrfc522.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define MOCK_MOCKMRFC522_HPP_

#include "Arduino.h"

#include <array>
#include <memory>
#include <optional>

Expand All @@ -22,9 +24,9 @@ namespace fablabbg
public:
struct UidDriver
{
byte size; // Number of bytes in the UID. 4, 7 or 10.
byte uidByte[10];
byte sak; // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
byte size{4}; // Number of bytes in the UID. 4, 7 or 10.
std::array<byte, 10> uidByte{0};
byte sak{0}; // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
};

constexpr MockMrfc522(){};
Expand Down
6 changes: 3 additions & 3 deletions src/Mrfc522Driver.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Arduino.h"
#include <algorithm>
#include <memory>

#include "MFRC522DriverPinSimple.h"
Expand Down Expand Up @@ -57,11 +58,10 @@ namespace fablabbg

bool Mrfc522Driver::PCD_PerformSelfTest() { return mfrc522->PCD_PerformSelfTest(); }

Mrfc522Driver::UidDriver Mrfc522Driver::getDriverUid() const
auto Mrfc522Driver::getDriverUid() const -> UidDriver
{
UidDriver retVal{};
memset(&retVal, 0, sizeof(retVal));
memcpy(retVal.uidByte, mfrc522->uid.uidByte, sizeof(retVal.uidByte));
std::copy(mfrc522->uid.uidByte, mfrc522->uid.uidByte + 10, retVal.uidByte.begin());
retVal.size = mfrc522->uid.size;
retVal.sak = mfrc522->uid.sak;
return retVal;
Expand Down
9 changes: 4 additions & 5 deletions src/RFIDWrapper.tpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <memory>

#include "Logging.hpp"
Expand Down Expand Up @@ -94,11 +95,9 @@ namespace fablabbg
{
std::array<uint8_t, conf::rfid_tags::UID_BYTE_LEN> arr{0};
auto const &uid = driver->getDriverUid();
memcpy(arr.data(), uid.uidByte, std::min(conf::rfid_tags::UID_BYTE_LEN, uid.size));

auto c = card::from_array(arr);

return c;
size_t size = std::min(uid.size, conf::rfid_tags::UID_BYTE_LEN);
std::copy(uid.uidByte.cbegin(), uid.uidByte.cbegin() + size, arr.begin());
return card::from_array(arr);
}

/// @brief Initializes RFID chip including self test
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace fablabbg::Tasks
auto Scheduler::execute() const -> void
{
// Tasks shall be run in order of expiration (the most expired task shall run first)
std::vector<decltype(tasks)::const_iterator> iters{0};
std::vector<decltype(tasks)::const_iterator> iters;
for (auto it = tasks.begin(); it != tasks.end(); ++it)
{
iters.push_back(it); // Vector of iterators
Expand Down
8 changes: 5 additions & 3 deletions src/mock/MockMrfc522.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include "mock/MockMrfc522.hpp"

#include <algorithm>

namespace fablabbg
{
auto MockMrfc522::getDriverUid() const -> MockMrfc522::UidDriver
{
UidDriver retVal{};
memset(&retVal, 0, sizeof(retVal));
if (getSimulatedUid().has_value())
if (auto sim = getSimulatedUid(); sim.has_value())
{
memcpy(retVal.uidByte, &uid.value(), sizeof(uid.value()));
retVal.size = sizeof(uid.value());
auto uid = card::to_array(sim.value());
std::copy(uid.begin(), uid.end(), retVal.uidByte.begin());
retVal.sak = 1;
}
return retVal;
Expand Down

0 comments on commit 2c6e3c0

Please sign in to comment.