//
//  WSBKBlueToothSDK.h
//  WSBKLiquidCheck
//
//  Created by vispek on 2022/4/12.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger,  WSBKBlueToothSDKCommandType) {
    /// 电量
    WSBKBlueToothSDKBatteryCommandType,
    /// 光谱
    WSBKBlueToothSDKSpectralCommandType,
    /// 温度
    WSBKBlueToothSDKTemperatureCommandType,
    /// 硬件版本
    WSBKBlueToothSDKDeviceVersionCommandType,
    /// 设备编码
    WSBKBlueToothSDKDeviceSNCommandType
 };



@protocol WSBKBlueToothSDKDelegate <NSObject>

@optional
/**
   系统蓝牙被关闭、提示用户去开启蓝牙
 */
- (void)systemBluetoothClose;
/**
  系统蓝牙已开启、开始扫描周边的蓝牙设备
 */
- (void)sysytemBluetoothOpen;


/**
 扫描到的设备回调
 
 @param peripheralInfoArr 扫描到的蓝牙设备数组
 */
- (void)getScanResultPeripherals:(NSArray *)peripheralInfoArr;


/**
 连接成功
 */
- (void)connectSuccess;


/**
 连接失败
 */
- (void)connectFailed;


/**
 当前断开的设备
 
 @param peripheral 断开的peripheral信息
 */
- (void)disconnectPeripheral:(CBPeripheral *)peripheral;


@end


@interface WSBKBlueToothSDK : NSObject

/** WSBKBlueToothSDK 的单例 */
+ (instancetype)shared;

@property (nonatomic, weak) id<WSBKBlueToothSDKDelegate> delegate;

/**
 连接所选中的蓝牙外设
 @param peripheral 所选择蓝牙外设的perioheral
 */
- (void)connectPeripheral:(CBPeripheral *)peripheral;


/**
 获取当前连接成功的peripherals数组
 
 @return 返回当前所连接成功peripherals数组
 */
- (NSArray *)findConnectedPeripherals;


/// 获取当前连接的peripheral
/// @param peripheralName peripheralName
- (CBPeripheral *)findConnectedPeripheral:(NSString *)peripheralName;


/**
 获取设备的服务跟特征值
 当已连接成功时调用有效
 */
- (void)searchServerAndCharacteristicUUID;

/**
 断开当前连接的所有蓝牙设备
 */
- (void)disconnectAllPeripherals;

/**
 断开所选择的蓝牙设备
 
 @param peripheral 所选择蓝牙外设的perioheral
 */
- (void)disconnectLastPeripheral:(CBPeripheral *)peripheral;

/**
 开始扫描周边蓝牙设备
 */
- (void)startScanPeripheral;

/**
停止扫描
 */
- (void)stopScanPeripheral;



/// 发送指令获取蓝牙设备返回数据
/// @param commandType 指令类型
/// @param successBlock 获取数据成功回调
/// @param failedBlock 获取数据失败回调
- (void)sendCommandType:(WSBKBlueToothSDKCommandType)commandType getDeviceData:(void (^)(NSString *response, NSString *response2))successBlock failed:(void (^)(NSString *failed))failedBlock;


/**
 添加断开自动重连的外设
 */
- (void)AutoReconnect:(CBPeripheral *)peripheral;

/**
 删除断开自动重连的外设
 */
- (void)AutoReconnectCancel:(CBPeripheral *)peripheral;



/**
 根据外设UUID对应的string获取已配对的外设
 
 UUIDString   peripheral.identifier.UUIDString

 通过方法获取外设后可以直接连接外设，跳过扫描过程
 */
- (CBPeripheral *)retrievePeripheralWithUUIDString:(NSString *)UUIDString;

@end

NS_ASSUME_NONNULL_END
