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.

123 lines
3.3 KiB

2 years ago
//
// FRBleAbility.h
// FRQBluetoothKit
//
// Created by chunhai xu on 2021/1/3.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
NS_ASSUME_NONNULL_BEGIN
/** 操作过程中错误码 */
typedef NS_ENUM(NSInteger, FRQErrorCode) {
///OTA升级错误
FRQErrorCode_ota = 10011,
///设备连接错误
FRQErrorCode_connect = 10022,
};
/** 蓝牙设备状态 */
typedef NS_ENUM(NSUInteger, FRQManagerState) {
///未知
FRQManagerStateUnknown = CBCentralManagerStateUnknown,
///重置
FRQManagerStateResetting = CBCentralManagerStateResetting,
///不支持
FRQManagerStateUnsupported =CBCentralManagerStateUnsupported,
///未授权
FRQManagerStateUnauthorized =CBCentralManagerStateUnauthorized,
///蓝牙关闭
FRQManagerStatePoweredOff =CBCentralManagerStatePoweredOff,
///蓝牙打开
FRQManagerStatePoweredOn =CBCentralManagerStatePoweredOn,
};
@protocol FRBleAbility <NSObject>
/**
@brief
@see FRQManagerState
*/
@property (nonatomic, assign) FRQManagerState state;
/** @brief 设置查找和连接Peripherals的规则,需要在scan之前设置
@param discoverFilter
@param connectFilter
*/
- (void)setFilterForDiscoverPeripherals:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))discoverFilter andFilterForConnectToPeripherals:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))connectFilter;
/** @brief 扫描Peripherals */
- (void)scanPeripherals;
/** @brief 停止扫描 */
- (void)cancelScan;
/** @brief 是否正在扫描中 */
- (BOOL)isScanning;
/** @brief 连接到特定的蓝牙设备
@param peripheral
*/
- (void)connectToPeripheral:(CBPeripheral *)peripheral;
/** @brief 连接设备,支持自动重连
@param peripheral
*/
- (void)autoReconnectToPeripheral:(CBPeripheral *)peripheral;
/**
@brief
@param peripheral
*/
- (void)closeAuotReconnectPeripheral:(CBPeripheral *)peripheral;
/**
@brief
@param peripheral
*/
- (void)closePeripheralConnection:(CBPeripheral *)peripheral;
/**
@brief
@param block
*/
- (void)closeAllPeripheralsConnection:(void(^)(id<FRBleAbility> ability))block;
/**
@brief peripherals
@return
*/
- (NSArray *)allConnectedPeripherals;
/**
@brief peripheral
@param peripheralName
@return
*/
- (CBPeripheral *)findConnectedPeripheralWithName:(NSString *)peripheralName;
/// OTA 升级
/**
@brief OTA升级
@param filePath app沙盒内文件路径
@param perpheral
*/
- (void)updateOTAWithFilePath:(NSString *)filePath toPeripheral:(CBPeripheral*)perpheral;
/**
@brief Data进行OTA升级
@param binData
@param perpheral
*/
- (void)updateOTAWithData:(NSData *)binData toPeripheral:(CBPeripheral*)perpheral;
/** @brief 停止升级OTA操作,如果OTA已升级完成的话无操作 */
- (void)cancelOTAUpgrade;
@end
NS_ASSUME_NONNULL_END