KingsongProtocol

class KingsongProtocol(scope: CoroutineScope = CoroutineScope(Dispatchers.IO)) : EUCProtocol(source)

Improved KingSong protocol: tolerant parsing, header resync, header-aware frame reassembly using ByteByByteFrameParser, safe bounds checks, optional cell voltages parsing, and clamped command generation.

Supports frame types: 0xA9 (live telemetry), 0xB9 (distance/fan/motorTemperature), 0xBB (name/model/version), 0xB3 (serial number), 0xF5 (CPU load/PWM), 0xF6 (speed limit), 0xA4/0xB5 (alarm speeds), 0xF1/0xF2 (Smart BMS data).

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope = CoroutineScope(Dispatchers.IO))

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val dataFlow: Flow<EUCData>
Link copied to clipboard
open override val manufacturer: String

Manufacturer name (used for display and logging).

Link copied to clipboard
open override val rawFrameFlow: Flow<ByteArray>

Flow that emits every raw BLE characteristic notification received by this protocol, as a defensive copy of the original byte array. Collectors can use this to write raw logs or perform any custom processing on the unmodified BLE data.

Link copied to clipboard

Explicit command support matrix for this protocol. Commands outside this set are considered unsupported by design.

Link copied to clipboard
open override val writeFlow: Flow<ByteArray>

Flow of commands or raw bytes that the protocol needs to write to the device automatically.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open override fun createCommand(commandType: CommandType, value: Any): ByteArray

Create a command for the EUC

Link copied to clipboard
open override fun decode(data: ByteArray): EUCData?

Decode raw BLE data into EUCData

Link copied to clipboard
open override fun getBMSData(): List<BMSData>

Returns the current BMS data snapshots for all detected battery packs. Each entry represents one BMS unit (typically 1 or 2 for dual-battery wheels). Data is accumulated from frame types 0xF1/0xF2 pages 0x00 (summary), 0x01 (temperatures), and 0x02-0x06 (cell voltages).

Link copied to clipboard

Returns the candidate data characteristic UUIDs for this protocol.

Link copied to clipboard

API-level command support check (used by framework and clients).

Link copied to clipboard
open override fun getDataCharacteristicUUID(): UUID

Get the UUID for the data characteristic

Link copied to clipboard
open override fun getPollingPlan(): ProtocolPollingPlan

Optional polling/query plan consumed by BLEManager orchestration.

Link copied to clipboard
open override fun getServiceUUID(): UUID

Get the UUID for the service

Link copied to clipboard

Get the UUID for the write characteristic (if different from data characteristic)

Link copied to clipboard
open override fun isDeviceReady(data: EUCData): Boolean

Check if the device is ready for operation

Link copied to clipboard
open fun matchesDeviceName(deviceName: String): Boolean

Returns true if the given BLE device advertisement name suggests this protocol.

Link copied to clipboard
open override fun matchesQueryResponse(query: ProtocolQuerySpec, data: ByteArray): Boolean

Optional query/response matcher used by BLEManager observability and retry loop.