Program Listing for File desfire_pcd.hpp

Return to documentation for file (libspookyaction/include/pn532/desfire_pcd.hpp)

//
// Created by Pietro Saccardi on 04/01/2021.
//

#ifndef PN532_DESFIRE_PCD_HPP
#define PN532_DESFIRE_PCD_HPP

#include <desfire/pcd.hpp>
#include <pn532/controller.hpp>

namespace pn532 {
    class desfire_pcd final : public desfire::pcd {
        std::shared_ptr<controller> _pcd;
        std::uint8_t _target;
        pn532::result<rf_status> _last_result;

        [[nodiscard]] inline controller &ctrl();

    public:
        inline desfire_pcd(std::shared_ptr<controller> controller, std::uint8_t target_logical_index);

        [[nodiscard]] inline std::uint8_t target_logical_index() const;
        [[nodiscard]] inline controller &tag_reader();
        [[nodiscard]] inline controller const &tag_reader() const;

        [[nodiscard]] inline pn532::result<rf_status> last_result() const;

        std::optional<bin_data> communicate(bin_data const &data) override;
    };
}// namespace pn532

namespace pn532 {
    desfire_pcd::desfire_pcd(std::shared_ptr<controller> controller, std::uint8_t target_logical_index)
        : _pcd{std::move(controller)}, _target{target_logical_index}, _last_result{rf_status{false, false, internal_error_code::none}} {
    }

    controller &desfire_pcd::ctrl() { return *_pcd; }

    std::uint8_t desfire_pcd::target_logical_index() const {
        return _target;
    }

    pn532::result<rf_status> desfire_pcd::last_result() const {
        return _last_result;
    }

    controller &desfire_pcd::tag_reader() {
        return *_pcd;
    }
    controller const &desfire_pcd::tag_reader() const {
        return *_pcd;
    }

}// namespace pn532

#endif//PN532_DESFIRE_PCD_HPP