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.
167 lines
4.3 KiB
167 lines
4.3 KiB
// |
|
// Bluetooth.h |
|
// BluetoothDemo |
|
// |
|
// Created by mac on 17/3/9. |
|
// Copyright © 2017年 . All rights reserved. |
|
// |
|
|
|
#import <Foundation/Foundation.h> |
|
#import <CoreBluetooth/CoreBluetooth.h> |
|
#import "BluetoothDelegate.h" |
|
#import "BluetoothDataSource.h" |
|
#import "BLEConst.h" |
|
#import "BlueToothItem.h" |
|
#import "BluetoothTool.h" |
|
#import "BlueToothEume.h" |
|
#import <JL_BLEKit/JL_BLEKit.h> |
|
|
|
/** 连接成功通知 */ |
|
#define BluetoothNotificationAtConnectSuccess @"BluetoothNotificationAtConnectSuccess" |
|
/** 连接DFU成功通知 */ |
|
#define BluetoothNotificationAtDFUConnectSuccess @"BluetoothNotificationAtDFUConnectSuccess" |
|
/** 连接失败通知 */ |
|
#define BluetoothNotificationAtConnectFail @"BluetoothNotificationAtConnectFail" |
|
/** 断开连接通知 */ |
|
#define BluetoothNotificationAtDisconnect @"BluetoothNotificationAtDisconnect" |
|
/** 重连通知 */ |
|
#define BluetoothNotificationAtReconnect @"BluetoothNotificationAtReconnect" |
|
/** 蓝牙开关关闭 */ |
|
#define BluetoothNotificationAtPowerOff @"BluetoothNotificationAtPowerOff" |
|
|
|
|
|
#pragma mark - BLE状态通知 |
|
extern NSString *kFLT_BLE_FOUND; //发现设备 |
|
extern NSString *kFLT_BLE_PAIRED; //已配对 |
|
extern NSString *kFLT_BLE_CONNECTED; //已连接 |
|
extern NSString *kFLT_BLE_DISCONNECTED; //断开连接 |
|
|
|
@protocol JL_SDKOtaDelegate <NSObject> |
|
|
|
@required |
|
/** |
|
* ota升级过程状态回调 |
|
*/ |
|
- (void)otaProgressWithOtaResult:(JL_OTAResult)result withProgress:(float)progress; |
|
|
|
@end |
|
|
|
|
|
@interface Bluetooth : NSObject <BluetoothDelegate, BluetoothDelegate> |
|
|
|
/** 连接状态 */ |
|
@property (nonatomic, assign) BOOL isConnected; |
|
|
|
/** 写的特征值 */ |
|
@property (nullable, nonatomic, strong) CBCharacteristic *writecharacteristic; |
|
|
|
/** 中心管理者 */ |
|
@property (nullable, nonatomic, strong) CBCentralManager *cMgr; |
|
|
|
/** 蓝牙状态 */ |
|
@property (nonatomic, assign) CBManagerState state; |
|
|
|
/** UUID数组 */ |
|
@property (nullable, nonatomic, strong) NSArray *services; |
|
|
|
/** 指令序号 */ |
|
@property (nonatomic, assign) NSInteger bleRequestSid; |
|
/** 是否正在执行 */ |
|
@property (nonatomic, assign) BOOL executing; |
|
/** 当前设备是否已配对 */ |
|
@property (nonatomic, assign) BOOL isPair; |
|
/** 蓝牙代理 */ |
|
@property (nullable, nonatomic, weak) id<BluetoothDelegate> delegate; |
|
/** 成功失败代理 */ |
|
@property (nullable, nonatomic, weak) id<BluetoothDataSource> dataSource; |
|
/** 蓝牙指令队列 */ |
|
@property (nonatomic, strong) NSMutableArray * bluetoothItems; |
|
/// 当前连接外设 |
|
@property (nonatomic, strong) BLEModel * currenModel; |
|
/// 延时重连时间(默认0 仅执行一次延时,随后置零) |
|
@property (nonatomic, assign) NSInteger reconnectTime; |
|
|
|
/// 是否是主动断开连接 |
|
@property (nonatomic ,assign) BOOL isIndependentOff; |
|
|
|
@property(strong,nonatomic)JL_Assist * _Nullable mAssist; |
|
|
|
|
|
@property (weak, nonatomic) id<JL_SDKOtaDelegate> jl_delegate; |
|
|
|
/** FRQ OTA写特征值 */ |
|
@property (nullable, nonatomic, strong) CBCharacteristic *frqOTAwritecharacteristic; |
|
|
|
|
|
|
|
@property (strong, nonatomic) NSString *__nullable lastBleMacAddress; // 上一次连接的蓝牙地址 |
|
|
|
//单例模式 |
|
+ (nullable instancetype)shareInstance; |
|
|
|
/** |
|
扫描外设Peripherals |
|
|
|
@param serviceUUIDs 过滤的服务UUID |
|
@param isDFU 是否DFU升级使用 |
|
*/ |
|
- (void)scanForPeripheralsWithdiscoverServices:(nullable NSArray<CBUUID *> *)serviceUUIDs |
|
IsDFU:(BOOL)isDFU; |
|
|
|
/** |
|
停止扫描 |
|
*/ |
|
- (void)cancelScan; |
|
|
|
/** |
|
连接设备 |
|
|
|
@param bleModel ble模型 |
|
*/ |
|
- (void)connectedWithBleModel:(nullable BLEModel *)bleModel; |
|
|
|
/// 断开当前连接的设备 |
|
/// @param isUnbind 是否解绑 |
|
- (void)disConnectedCurrenDevice:(BOOL)isUnbind; |
|
|
|
/** |
|
蓝牙设备重连 |
|
|
|
@param isStart 开启停止 |
|
*/ |
|
- (void)startAndStopReconnect:(BOOL)isStart; |
|
|
|
/** |
|
写入数据 |
|
|
|
@param bleItem 蓝牙命令模型 |
|
*/ |
|
- (void)writeWithBleItem:(nullable BlueToothItem *)bleItem; |
|
|
|
/// 清空指令队列 |
|
- (void)removeCmdItem; |
|
|
|
///** |
|
// 同步手机状态到设备 |
|
// |
|
// @param state 0:后台 1:前台 |
|
// */ |
|
//- (void)syncPhoneState:(BOOL)state; |
|
|
|
/** |
|
固件升级成功后重置代理 |
|
*/ |
|
- (void)firmwareCompleteResetDelegate; |
|
|
|
/// 杰里打开表盘文件 |
|
- (void)openDialFile; |
|
|
|
- (void)otaFuncWithFilePaths:(NSString *_Nonnull)otaFilePath; |
|
|
|
|
|
- (void)otaTimeCheck; |
|
|
|
- (void)otaTimeClose; |
|
|
|
- (void)downloadZipUrl:(NSString *_Nonnull)url updatePath:(NSString *_Nonnull)path; |
|
@end
|
|
|