#pragma once #include #include #include #ifdef __cplusplus extern "C" { #endif #define TRIKKE_BLE_FRAGMENT_HEADER_SIZE 8 #define TRIKKE_BLE_ACK_SIZE 8 #define TRIKKE_BLE_BEGIN_SESSION_SIZE 12 // BLE data notifications carry a little-endian packet sequence, byte offset, // total TRK1 frame size, then the frame bytes at that offset. The unchanged // TRK1 CRC remains the end-to-end integrity check after reassembly. size_t trikke_ble_encode_fragment( uint8_t *output, size_t output_size, const uint8_t *packet, size_t packet_size, size_t packet_offset, size_t att_payload_capacity); // An application acknowledgement is ASCII "ACK1" followed by the exact // little-endian TRK1 packet sequence that the receiver persisted. bool trikke_ble_decode_ack( const uint8_t *ack, size_t ack_size, uint32_t *packet_sequence); // A session begin is ASCII "BGN1" followed by a receiver-generated uint64 // token. Repeating the same token is idempotent across BLE reconnects. bool trikke_ble_decode_begin_session( const uint8_t *command, size_t command_size, uint64_t *session_token); // Notification delivery is active only after both the CCCD and session // authorization are ready. Returns true when the effective state changes. bool trikke_ble_update_subscription( bool notify_enabled, bool session_connection_ready, bool *subscribed); #ifdef __cplusplus } #endif