123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // BabyBluetoothSwift.h
- // Shourigf
- //
- // Created by liaolj on 16/8/11.
- // Copyright © 2016年 Shourigf. All rights reserved.
- //
- /**
- 1. 加一个通知,成功返回数据
-
- */
- #import <Foundation/Foundation.h>
- #import <BabyBluetooth/BabyBluetooth.h>
- //搜索结果的通知
- #define kBabyBluetoothNotificationScanResult @"KKWBlueToothServiceNotify.ScanResult"
- //接收到数据的通知
- #define kBabyBluetoothNotificationUartDataRecieve @"KKWBlueToothServiceNotify.UartDataRecieve"
- //服务状态的通知
- #define kBabyBluetoothNotificationServiceStatus @"KKWBlueToothServiceNotify.ServiceStatus"
- //查找设备ID的通知
- #define kBabyBluetoothNotificationDeviceIDFound @"KKWBlueToothServiceNotify.DeviceIDFound"
- //通知 已经断开设备
- #define kBabyBluetoothNotificationDeviceWasDisconect @"kBabyBluetoothNotificationDeviceWasDisconect"
- typedef enum BabyBluetoothStatus: NSInteger {
- BabyBluetooth_ReadyToSendCMDStatus,//准备发送CMDStatus
- BabyBluetooth_ConnectedStatus,//蓝牙连接
- BabyBluetooth_DisConnectedStatus,//蓝牙丢失连接
- } BabyBluetoothStatus;
- @interface BabyBluetoothSwift : NSObject
- //单例
- + (instancetype)shareInstance;
- //搜索设备
- -(void)scanForPeripherals;
- //判断是否存在设备
- -(BOOL)peripheralExitsAtPeripheralName:(NSString *)peripheralName;
- //停止搜索
- -(void)cancelScan;
- //连接设备
- -(void)connectPeripheralWithName:(NSString *)name;
- //连接设备 带返回
- -(void)connectPeripheralWithName:(NSString *)name connectCompletionHandler:(void(^)(CBPeripheral *,BOOL))connectCompletionHandler;
- //连接设备 带返回
- -(void)connectPeripheralWithName:(NSString *)name connectCompletionHandler:(void(^)(CBPeripheral *,BOOL))connectCompletionHandler startWriteDataCallback:(void(^)(void))startWriteDataCallback;
- //重新连接
- -(void)reconnectPeripheralWithName:(NSString *)name;
- //断开链接设备
- -(void)disconnectPeripheralWithName:(NSString *)name;
- //-(void) writeData:(NSData *) data;
- -(void) writeData1:(NSMutableArray *)type;
- //写入
- -(void) writeData:(NSString *)type withData:(NSData *) data;
- //断开所有链接
- -(void)cancelAllPeripheralsConnection;
- -(void)writeData:(NSString *)dataStr completionHandler:(void (^)(NSString * ))completionHandler;
- -(void)writeData2222:(NSArray *)dataArr completionHandler:(void (^)(NSDictionary * ))completionHandler;
- //循环写入
- -(void)loopWriteDataWite:(NSArray *)dataArr type:(NSString *)type completionHandler:(void (^)(NSDictionary *))completionHandler;
- /**
- 写入上传信息
-
- @param timerout 超时时间
- @return 是否成功
- */
- -(BOOL) WaitPostMessage:(int) timerout;
- //上传接收到的数据
- -(BOOL) PostRecvMessage;
- //清除接收到的数据
- -(void) ClearRecvFifo;
- //是否可以写
- -(BOOL)canWrite;
- //外设数组
- @property (strong, nonatomic) NSMutableArray *peripherals;
- //当前外设
- @property (nonatomic,strong)CBPeripheral *currPeripheral;
- //@property (strong, nonatomic) NSNumber* mDeviceID;
- /**
- 收到的数据回调
- */
- @property(nonatomic, copy) void (^testBlock)(NSMutableDictionary *testData);
- @property(nonatomic, copy) void (^testBlock2)(NSMutableDictionary *testData);
- @property(nonatomic, copy) void (^updateNameBlock)(NSMutableDictionary *testData);
- @property(nonatomic, copy) void (^clearHistoryDataBlock)(NSMutableDictionary *testData);
- @property(nonatomic, copy) void (^resetBlock)(NSMutableDictionary *testData);
- @property (nonatomic,copy) void (^sucessBlock)(BOOL isSuccess);
- @property (nonatomic,copy) void (^centralBlock)(CBCentralManager *central);
- //搜索到的服务 DiscoverServices
- @property (nonatomic,copy) void (^DiscoverServicesBlock)(NSString *uuid);
- //设置密码
- -(void)writePasswordData:(NSString *) data;
- //复位、
- -(void)writeRestoreSystemData:(NSString *)data;
- //写固件更新
- -(void)updateFirmwareData:(NSString *)data;
- @end
|