ESPHome  2024.11.2
nci_message.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/log.h"
4 #include "esphome/core/helpers.h"
5 
6 #include <vector>
7 
8 namespace esphome {
9 namespace nfc {
10 
11 class NciMessage {
12  public:
14  NciMessage(uint8_t message_type, const std::vector<uint8_t> &payload);
15  NciMessage(uint8_t message_type, uint8_t gid, uint8_t oid);
16  NciMessage(uint8_t message_type, uint8_t gid, uint8_t oid, const std::vector<uint8_t> &payload);
17  NciMessage(const std::vector<uint8_t> &raw_packet);
18 
19  std::vector<uint8_t> encode();
20  void reset();
21 
22  uint8_t get_message_type() const;
23  uint8_t get_gid() const;
24  uint8_t get_oid() const;
25  uint8_t get_payload_size(bool recompute = false);
26  uint8_t get_simple_status_response() const;
27  uint8_t get_message_byte(uint8_t offset) const;
28  std::vector<uint8_t> &get_message();
29 
30  bool has_payload() const;
31  bool message_type_is(uint8_t message_type) const;
32  bool message_length_is(uint8_t message_length, bool recompute = false);
33  bool gid_is(uint8_t gid) const;
34  bool oid_is(uint8_t oid) const;
35  bool simple_status_response_is(uint8_t response) const;
36 
37  void set_header(uint8_t message_type, uint8_t gid, uint8_t oid);
38  void set_message(uint8_t message_type, const std::vector<uint8_t> &payload);
39  void set_message(uint8_t message_type, uint8_t gid, uint8_t oid, const std::vector<uint8_t> &payload);
40  void set_message_type(uint8_t message_type);
41  void set_gid(uint8_t gid);
42  void set_oid(uint8_t oid);
43  void set_payload(const std::vector<uint8_t> &payload);
44 
45  protected:
46  std::vector<uint8_t> nci_message_{0, 0, 0}; // three bytes, MT/PBF/GID, OID, payload length/size
47 };
48 
49 } // namespace nfc
50 } // namespace esphome
uint8_t get_gid() const
Definition: nci_message.cpp:39
uint8_t get_message_type() const
Definition: nci_message.cpp:35
bool message_type_is(uint8_t message_type) const
Definition: nci_message.cpp:71
uint8_t get_message_byte(uint8_t offset) const
Definition: nci_message.cpp:60
void set_oid(uint8_t oid)
std::vector< uint8_t > & get_message()
Definition: nci_message.cpp:67
void set_header(uint8_t message_type, uint8_t gid, uint8_t oid)
bool gid_is(uint8_t gid) const
Definition: nci_message.cpp:88
void set_message_type(uint8_t message_type)
std::vector< uint8_t > nci_message_
Definition: nci_message.h:46
bool simple_status_response_is(uint8_t response) const
uint8_t get_oid() const
Definition: nci_message.cpp:41
void set_payload(const std::vector< uint8_t > &payload)
void set_message(uint8_t message_type, const std::vector< uint8_t > &payload)
bool oid_is(uint8_t oid) const
Definition: nci_message.cpp:95
uint8_t get_payload_size(bool recompute=false)
Definition: nci_message.cpp:43
void set_gid(uint8_t gid)
bool message_length_is(uint8_t message_length, bool recompute=false)
Definition: nci_message.cpp:78
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::vector< uint8_t > encode()
Definition: nci_message.cpp:27
uint8_t get_simple_status_response() const
Definition: nci_message.cpp:53