BabyBluetoothSwift.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // BabyBluetoothSwift.h
  3. // Shourigf
  4. //
  5. // Created by liaolj on 16/8/11.
  6. // Copyright © 2016年 Shourigf. All rights reserved.
  7. //
  8. /**
  9. 1. 加一个通知,成功返回数据
  10. */
  11. #import <Foundation/Foundation.h>
  12. #import <BabyBluetooth/BabyBluetooth.h>
  13. //搜索结果的通知
  14. #define kBabyBluetoothNotificationScanResult @"KKWBlueToothServiceNotify.ScanResult"
  15. //接收到数据的通知
  16. #define kBabyBluetoothNotificationUartDataRecieve @"KKWBlueToothServiceNotify.UartDataRecieve"
  17. //服务状态的通知
  18. #define kBabyBluetoothNotificationServiceStatus @"KKWBlueToothServiceNotify.ServiceStatus"
  19. //查找设备ID的通知
  20. #define kBabyBluetoothNotificationDeviceIDFound @"KKWBlueToothServiceNotify.DeviceIDFound"
  21. //通知 已经断开设备
  22. #define kBabyBluetoothNotificationDeviceWasDisconect @"kBabyBluetoothNotificationDeviceWasDisconect"
  23. typedef enum BabyBluetoothStatus: NSInteger {
  24. BabyBluetooth_ReadyToSendCMDStatus,//准备发送CMDStatus
  25. BabyBluetooth_ConnectedStatus,//蓝牙连接
  26. BabyBluetooth_DisConnectedStatus,//蓝牙丢失连接
  27. } BabyBluetoothStatus;
  28. @interface BabyBluetoothSwift : NSObject
  29. //单例
  30. + (instancetype)shareInstance;
  31. //搜索设备
  32. -(void)scanForPeripherals;
  33. //判断是否存在设备
  34. -(BOOL)peripheralExitsAtPeripheralName:(NSString *)peripheralName;
  35. //停止搜索
  36. -(void)cancelScan;
  37. //连接设备
  38. -(void)connectPeripheralWithName:(NSString *)name;
  39. //连接设备 带返回
  40. -(void)connectPeripheralWithName:(NSString *)name connectCompletionHandler:(void(^)(CBPeripheral *,BOOL))connectCompletionHandler;
  41. //连接设备 带返回
  42. -(void)connectPeripheralWithName:(NSString *)name connectCompletionHandler:(void(^)(CBPeripheral *,BOOL))connectCompletionHandler startWriteDataCallback:(void(^)(void))startWriteDataCallback;
  43. //重新连接
  44. -(void)reconnectPeripheralWithName:(NSString *)name;
  45. //断开链接设备
  46. -(void)disconnectPeripheralWithName:(NSString *)name;
  47. //-(void) writeData:(NSData *) data;
  48. -(void) writeData1:(NSMutableArray *)type;
  49. //写入
  50. -(void) writeData:(NSString *)type withData:(NSData *) data;
  51. //断开所有链接
  52. -(void)cancelAllPeripheralsConnection;
  53. -(void)writeData:(NSString *)dataStr completionHandler:(void (^)(NSString * ))completionHandler;
  54. -(void)writeData2222:(NSArray *)dataArr completionHandler:(void (^)(NSDictionary * ))completionHandler;
  55. //循环写入
  56. -(void)loopWriteDataWite:(NSArray *)dataArr type:(NSString *)type completionHandler:(void (^)(NSDictionary *))completionHandler;
  57. /**
  58. 写入上传信息
  59. @param timerout 超时时间
  60. @return 是否成功
  61. */
  62. -(BOOL) WaitPostMessage:(int) timerout;
  63. //上传接收到的数据
  64. -(BOOL) PostRecvMessage;
  65. //清除接收到的数据
  66. -(void) ClearRecvFifo;
  67. //是否可以写
  68. -(BOOL)canWrite;
  69. //外设数组
  70. @property (strong, nonatomic) NSMutableArray *peripherals;
  71. //当前外设
  72. @property (nonatomic,strong)CBPeripheral *currPeripheral;
  73. //@property (strong, nonatomic) NSNumber* mDeviceID;
  74. /**
  75. 收到的数据回调
  76. */
  77. @property(nonatomic, copy) void (^testBlock)(NSMutableDictionary *testData);
  78. @property(nonatomic, copy) void (^testBlock2)(NSMutableDictionary *testData);
  79. @property(nonatomic, copy) void (^updateNameBlock)(NSMutableDictionary *testData);
  80. @property(nonatomic, copy) void (^clearHistoryDataBlock)(NSMutableDictionary *testData);
  81. @property(nonatomic, copy) void (^resetBlock)(NSMutableDictionary *testData);
  82. @property (nonatomic,copy) void (^sucessBlock)(BOOL isSuccess);
  83. @property (nonatomic,copy) void (^centralBlock)(CBCentralManager *central);
  84. //搜索到的服务 DiscoverServices
  85. @property (nonatomic,copy) void (^DiscoverServicesBlock)(NSString *uuid);
  86. //设置密码
  87. -(void)writePasswordData:(NSString *) data;
  88. //复位、
  89. -(void)writeRestoreSystemData:(NSString *)data;
  90. //写固件更新
  91. -(void)updateFirmwareData:(NSString *)data;
  92. @end