BleConstants

BLE Constants for AC Device Communication.

These UUIDs and constants match the AC firmware protocol exactly.

Properties

Link copied to clipboard
const val CONNECT_TIMEOUT_MS: Long = 10000

Connect timeout (milliseconds)

Link copied to clipboard
const val DATA_ACK_TIMEOUT_MS: Long = 15000

Timeout for data ACK (milliseconds)

Link copied to clipboard

Known AC device name patterns for scanning

Link copied to clipboard
const val FRAG_HEADER_SIZE: Int = 5

Fragmentation header size: segCount:2B BEmtu:2B BE = 5 bytes

Link copied to clipboard
const val HEADER_ACK_TIMEOUT_MS: Long = 5000

Timeout for header ACK (milliseconds)

Link copied to clipboard
const val HEADER_MARKER: Byte = 99

Header marker byte (0x63 = 'c') - indicates a fragmentation header

Link copied to clipboard
const val IDCP_HEADER_SIZE: Int = 5

IDCP header size for AC → Mobile chunks: "mpc"(3) + seq(2) = 5 bytes

Link copied to clipboard
const val LAYER1_HEADER_SIZE: Int = 22

Layer 1 header size (plaintext): magic(3) + encrypt(1) + msgType(2) + size(4) + sessionId(8) + startTime(4) = 22 bytes

Link copied to clipboard

Layer 1 magic bytes: "?##"

Link copied to clipboard
const val MAX_HEADER_RETRIES: Int = 3

Maximum retry count for header ACK

Link copied to clipboard
const val MTU_SIZE: Int = 512

MTU size to request (512 bytes allows larger BLE packets)

Link copied to clipboard
const val RECV_TIMEOUT_MS: Long = 120000

Timeout for receiving complete message (milliseconds)

Link copied to clipboard
const val RX_UUID: String

RX characteristic - Read data FROM the AC device (notifications)

Link copied to clipboard
const val SCAN_TIMEOUT_MS: Long = 30000

Scan timeout (milliseconds)

Link copied to clipboard
const val SEGMENT_SIZE: Int

Segment size for data fragmentation (488 bytes per segment)

Link copied to clipboard
const val SERVICE_UUID: String

Main UART service UUID for AC device communication

Link copied to clipboard
const val TX_UUID: String

TX characteristic - Write data TO the AC device

Functions

Link copied to clipboard
fun buildFragmentationHeader(segmentCount: Int, mtuSize: Int = MTU_SIZE): ByteArray

Build fragmentation header: segCount:2B BEmtu:2B BE

Link copied to clipboard

Calculate the optimal segment size based on the negotiated MTU.

Link copied to clipboard

Check if response is a data ACK ("yes\0" without IDCP prefix).

Link copied to clipboard

Check if response is a data NACK ("no\0" without IDCP prefix).

Link copied to clipboard

Check if a BLE notification is a final confirmation ("yes" or "no"). Format: "mpc"(3) + seq(2) + "yes\0"(4) or "no\0"(3)

Link copied to clipboard

Check if a final confirmation is "yes" (ACK) vs "no" (NACK).

Link copied to clipboard

Check if a BLE notification is a header ACK. Format: "mpc"(3) + seq(2) + "headrcv\0"(8) = 13 bytes

Link copied to clipboard

Check if a packet contains Layer 1 data (has IDCP header + "?##" magic).

Link copied to clipboard

Parse fragmentation header from received data.

Link copied to clipboard

Parse sequence number from an IDCP-prefixed notification ("mpc" + seq:2B BE + ...).