You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.7 KiB

import Foundation
import CoreBluetooth
/**
* BLE服务常量
*/
class BleConst {
// ================== 协议相关UUID ==================
/** 主服务UUID - 文档中定义为0000ABC0-0000-1111-2222-123456789ABC */
static let PRIMARY_SERVICE_UUID = CBUUID(string: "0000abc0-0000-1111-2222-123456789abc")
/** 音频服务UUID - 文档中定义为00001801-0000-1000-8000-00805f9b34fb */
static let AUDIO_SERVICE_UUID = CBUUID(string: "0000ae00-0000-1000-8000-00805f9b34fb")
/** 接收音频特征UUID - 文档中定义为0000ABC1-0000-1111-2222-123456789ABC */
static let RECEIVE_AUDIO_CHAR_UUID = CBUUID(string: "0000ae02-0000-1000-8000-00805f9b34fb")
/** 写入特征UUID - 文档中定义为0000ABC1-0000-1111-2222-123456789ABC */
static let WRITE_CHAR_UUID = CBUUID(string: "0000abc1-0000-1111-2222-123456789abc")
/** 通知特征UUID - 文档中定义为0000ABC2-0000-1111-2222-123456789ABC */
static let NOTIFY_CHAR_UUID = CBUUID(string: "0000abc2-0000-1111-2222-123456789abc")
/** 客户端特征配置描述符UUID */
static let CLIENT_CHAR_CONFIG_UUID = CBUUID(string: "00002902-0000-1000-8000-00805f9b34fb")
/** BLE扫描Action */
static let ACTION_SCAN_RESULT = "com.yunqiinnovation.ble_service.ACTION_BLE_SCAN"
// ================== 连接状态 ==================
static let STATE_DISCONNECTED = 0
static let STATE_CONNECTING = 1
static let STATE_CONNECTED = 2
static let STATE_DISCONNECTING = 3
static let STATE_ERROR = 4
// ================== 广播厂商信息 ==================
/** 厂商ID - 文档中定义为0xABEF */
static let MANUFACTURER_ID: UInt16 = 0xABEF
/** 客户ID - 文档中定义为0xA001 */
static let CUSTOMER_ID: UInt16 = 0xA001
/** 产品ID - 文档中定义为0xA001 */
static let PRODUCT_ID: UInt16 = 0xA001
/** 蓝牙状态-未连接 */
static let BT_STATE_DISCONNECTED: UInt8 = 0x00
/** 蓝牙状态-已连接 */
static let BT_STATE_CONNECTED: UInt8 = 0x0C
// ================== 协议格式 ==================
/** APP请求帧头 */
static let APP_REQUEST_HEADER: UInt8 = 0xAA
/** 设备响应帧头 */
static let DEVICE_RESPONSE_HEADER: UInt8 = 0xBB
/** 设备主动上报帧头 */
static let DEVICE_NOTIFY_HEADER: UInt8 = 0xCC
// ================== 协议指令 (CMD) ==================
/** 获取耳机版本号 */
static let CMD_GET_VERSION: UInt8 = 0x01
/** 获取耳机产品ID */
static let CMD_GET_PRODUCT_ID: UInt8 = 0x02
/** 获取耳机颜色ID */
static let CMD_GET_COLOR_ID: UInt8 = 0x03
/** 获取耳机电量ID */
static let CMD_GET_BATTERY_INFO: UInt8 = 0x04
/** APP控制编解码指令 */
static let CMD_CONTROL_CODEC: UInt8 = 0x05
/** 音量增大 */
static let CMD_VOLUME_UP: UInt8 = 0x06
/** 音量减小 */
static let CMD_VOLUME_DOWN: UInt8 = 0x07
/** A2DP播放 */
static let CMD_PLAY_A2DP: UInt8 = 0x08
/** 唤醒指令 */
static let CMD_WAKE_UP: UInt8 = 0x11
// ================== 编解码控制值 ==================
/** 关闭编解码指令 */
static let CODEC_CONTROL_CLOSE: UInt8 = 0x00
/** 音乐或者通话远端声音 */
static let CODEC_CONTROL_DECODE_ON: UInt8 = 0xA1
/** mic和dac(音乐或者通话远端)声音 */
static let CODEC_CONTROL_A2DP_PLAY: UInt8 = 0xA2
/** 打开编码指令 */
static let CODEC_CONTROL_ENCODE_ON: UInt8 = 0xB1
/** 左声道 */
static let AUDIO_CHANNEL_LEFT: UInt8 = 0x01
/** 右声道 */
static let AUDIO_CHANNEL_RIGHT: UInt8 = 0x02
/** 立体声 */
static let AUDIO_CHANNEL_STEREO: UInt8 = 0x03
}