#ifndef PROTOCOL_H #define PROTOCOL_H #include #include // Protocol Constants #define PROTOCOL_SOF 0xAA #define PACKET_TYPE_AUDIO 0x02 #define PACKET_LEN_V1 0x08 // Payload length (excluding SOF, TYPE, LEN, CRC) #define PACKET_TOTAL_SIZE 12 // CRC8-ATM Constants #define CRC8_POLY 0x07 #define CRC8_INIT 0x00 /** * @brief Calculates CRC-8/ATM over the data buffer. * Polynomial: x^8 + x^2 + x + 1 (0x07) * Init: 0x00, RefIn: false, RefOut: false, XorOut: 0x00 * @param data Pointer to data buffer * @param len Length of data * @return Calculated CRC8 */ uint8_t crc8_atm(const uint8_t *data, size_t len); /** * @brief Encodes the audio metric packet into the wire format. * @param buf Output buffer (must be at least 12 bytes) * @param timestamp_ms Timestamp in milliseconds * @param rms_dbfs RMS value in dBFS (float) * @param freq_hz Peak frequency in Hz (float) */ void protocol_pack_v1( uint8_t *buf, uint32_t timestamp_ms, float rms_dbfs, float freq_hz); #endif // PROTOCOL_H