OpenBlink Bluetooth Communication Specification

May 19, 2025 ยท View on GitHub

Overview

This document describes the Bluetooth Low Energy (BLE) communication specification for the OpenBlink system. It includes service and characteristic UUIDs, protocol details, data structures, and communication flow.

Service and Characteristics

  • Service UUID: 227da52c-e13a-412b-befb-ba2256bb7fbe
  • Description: Primary service for OpenBlink device communication

Characteristics

CharacteristicUUIDPropertiesDescription
Programad9fdd56-1135-4a84-923c-ce5a244385e7Write, Write Without ResponseUsed for bytecode transfer and execution
Consolea015b3de-185a-4252-aa04-7a87d38ce148NotifyUsed for debug output and notifications
Statusca141151-3113-448b-b21a-6a6203d253ffReadProvides device status information

Protocol

  • Version: 0x01
  • Description: Protocol for transferring and executing bytecode on the OpenBlink device

Command Types

CommandCodeDescription
Data'D'Transfers a chunk of bytecode
Program'P'Executes the transferred bytecode
Reset'R'Resets the device
Reload'L'Reloads the bytecode

Data Structures

  • Size: 2 bytes
  • Description: Common header for all Blink protocol commands
FieldTypeSizeDescription
versionuint8_t1 byteBlink protocol version (0x01)
commanduint8_t1 byteCommand type ('D', 'P', 'R', or 'L')
  • Size: 6 bytes + data
  • Description: Structure for data chunk transfers
FieldTypeSizeDescription
headerBLINK_CHUNK_HEADER2 bytesCommon header
offsetuint16_t2 bytesOffset in bytecode buffer
sizeuint16_t2 bytesSize of data chunk
datauint8_t[]VariableActual bytecode data
  • Size: 8 bytes
  • Description: Structure for program execution command
FieldTypeSizeDescription
headerBLINK_CHUNK_HEADER2 bytesCommon header
lengthuint16_t2 bytesTotal bytecode length
crcuint16_t2 bytesCRC16 checksum
slotuint8_t1 byteTarget slot for bytecode
reserveduint8_t1 byteReserved for future use

Communication Flow

Bytecode Transfer and Execution

Client                                      OpenBlink Device
  |                                               |
  |--- Discover OpenBlink Service --------------->|
  |<-- Service and Characteristics Found ---------|
  |                                               |
  |--- Write Data Chunk 1 to Program Char ------->|
  |--- Write Data Chunk 2 to Program Char ------->|
  |--- Write Data Chunk n to Program Char ------->|
  |                                               |
  |--- Write Program Command to Program Char ---->|
  |                   (CRC check)                 |
  |                                               |
  |--- Write Reset/Reload Command --------------->|
  |                                               |

BLE Events

EventDescription
BLE_EVENT_INITIALIZEDBLE stack has been initialized
BLE_EVENT_CONNECTEDBLE connection established
BLE_EVENT_DISCONNECTEDBLE connection terminated
BLE_EVENT_RECEIVEDData received over BLE
BLE_EVENT_SENTData sent over BLE
BLE_EVENT_BLINKBlink bytecode received
BLE_EVENT_STATUSStatus information requested
BLE_EVENT_REBOOTReboot request received
BLE_EVENT_RELOADReload request received

Error Handling

Error Notifications

Errors during bytecode transfer or execution are reported through notifications on the Console characteristic. The notification contains an error message string.

Common Errors

ErrorDescription
"ERROR: Blink version mismatch"Protocol version is not supported
"ERROR: Blink data size error"Data chunk size does not match expected size
"ERROR: Size exceeds buffer limits"Bytecode size exceeds maximum allowed size
"ERROR: CRC mismatch"CRC checksum verification failed
"ERROR: Blink program error"Error during bytecode execution
"ERROR: Blink unknown type"Unknown command type received

Implementation Notes

Maximum Bytecode Size

The maximum bytecode size is defined by BLINK_MAX_BYTECODE_SIZE in the implementation.

CRC Calculation

CRC16 checksum is calculated using the crc16_reflect function with the following parameters:

  • Initial value: 0xFFFF
  • Polynomial: 0xd175 (provides Hamming Distance 4 protection for data lengths up to 32751 bits)
  • Input: bytecode buffer
  • Length: bytecode length

Reference: https://users.ece.cmu.edu/~koopman/crc/index.html