#ifndef NFC_PROTOCOL_H #define NFC_PROTOCOL_H #include // Communication protocol definitions #define MAX_NFC_DATA_SIZE 256 #define ESPNOW_CHANNEL 1 #define PAIRING_TIMEOUT_MS 30000 #define HEARTBEAT_INTERVAL_MS 1000 #define MAX_RETRY_ATTEMPTS 3 // Message types enum MessageType { MSG_PAIRING_REQUEST = 0x01, MSG_PAIRING_RESPONSE = 0x02, MSG_NFC_DATA = 0x03, MSG_HEARTBEAT = 0x04, MSG_ERROR = 0x05, MSG_ACK = 0x06 }; // NFC data structure struct NFCData { uint8_t uid[10]; // NFC UID (max 10 bytes) uint8_t uid_length; // Actual UID length uint8_t sak; // Select Acknowledge uint8_t atqa[2]; // Answer to Request Type A uint8_t raw_data[MAX_NFC_DATA_SIZE]; // Raw NFC data uint16_t data_length; // Actual data length uint32_t timestamp; // Capture timestamp uint8_t tag_type; // NFC tag type }; // Communication message structure struct CommMessage { uint8_t type; // Message type uint8_t sequence; // Sequence number uint16_t payload_size; // Payload size union { NFCData nfc_data; uint8_t raw_payload[sizeof(NFCData)]; }; uint16_t checksum; // Message integrity check }; // Device roles enum DeviceRole { ROLE_LISTENER = 1, ROLE_EMULATOR = 2 }; // Status codes enum StatusCode { STATUS_OK = 0, STATUS_ERROR = 1, STATUS_TIMEOUT = 2, STATUS_INVALID_DATA = 3, STATUS_NOT_PAIRED = 4 }; // Function prototypes uint16_t calculateChecksum(const uint8_t* data, size_t length); bool validateMessage(const CommMessage* msg); void printNFCData(const NFCData* data); #endif // NFC_PROTOCOL_H