Program Listing for File p2p.hpp
↰ Return to documentation for file (libspookyaction/include/pn532/p2p.hpp
)
//
// Created by spak on 1/20/23.
//
#ifndef PN532_P2P_HPP
#define PN532_P2P_HPP
#include <pn532/controller.hpp>
namespace pn532::p2p {
using ms = std::chrono::milliseconds;
struct initiator {
[[nodiscard]] virtual result<mlab::bin_data> communicate(mlab::bin_data const &data, ms timeout) = 0;
virtual ~initiator() = default;
};
struct target {
[[nodiscard]] virtual result<mlab::bin_data> receive(ms timeout) = 0;
virtual result<> send(mlab::bin_data const &data, ms timeout) = 0;
virtual ~target() = default;
};
class pn532_initiator : public initiator {
controller *_controller = nullptr;
std::uint8_t _idx{};
public:
pn532_initiator() = default;
pn532_initiator(controller &controller, std::uint8_t logical_index);
pn532_initiator(pn532_initiator const &) = delete;
pn532_initiator &operator=(pn532_initiator const &) = delete;
pn532_initiator(pn532_initiator &&) noexcept = default;
pn532_initiator &operator=(pn532_initiator &&) noexcept = default;
[[nodiscard]] result<mlab::bin_data> communicate(mlab::bin_data const &data, ms timeout) override;
};
class pn532_target : public target {
controller *_controller = nullptr;
public:
pn532_target() = default;
explicit pn532_target(controller &controller);
pn532_target(pn532_target const &) = delete;
pn532_target &operator=(pn532_target const &) = delete;
pn532_target(pn532_target &&) noexcept = default;
pn532_target &operator=(pn532_target &&) noexcept = default;
[[nodiscard]] result<pn532::activation_as_target> init_as_dep_target(std::array<std::uint8_t, 5> nfcid_data, ms timeout = 5s);
[[nodiscard]] result<mlab::bin_data> receive(ms timeout) override;
result<> send(mlab::bin_data const &data, ms timeout) override;
};
}// namespace pn532::p2p
#endif//PN532_P2P_HPP