Blame view

HDFwear/3rd/RTKOTASDK/RTKLEFoundation.framework/Headers/RTKLEPeripheral.h 5.51 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  //
  //  RTKLEPeripheral.h
  //  RTKLEFoundation
  //
  //  Created by jerome_gu on 2019/1/7.
  //  Copyright © 2019 Realtek. All rights reserved.
  //
  
  #import <Foundation/Foundation.h>
  #import <CoreBluetooth/CoreBluetooth.h>
  
  #ifdef RTK_SDK_IS_STATIC_LIBRARY
  #import "RTKLEGeneralDefines.h"
  #import "RTKPeripheralCharacteristicOperation.h"
  #else
  #import <RTKLEFoundation/RTKLEGeneralDefines.h>
  #import <RTKLEFoundation/RTKPeripheralCharacteristicOperation.h>
  #endif
  
  
  typedef NS_ENUM(NSUInteger, RTKLEPeripheralValidState) {
      RTKLEPeripheralValidStateUnknown,
      RTKLEPeripheralValidStateEvaluating,
      RTKLEPeripheralValidStateInvalid,
      RTKLEPeripheralValidStateValid,
  };
  
  
  NS_ASSUME_NONNULL_BEGIN
  
  @class RTKLEProfile;
  @class RTKLEPeripheral;
  
  /**
   * Methods that a RTKLEPeripheralDelegate implement to receive notification of Name and RSSI changes.
   */
  @protocol RTKLEPeripheralDelegate <NSObject>
  @optional
  /**
   * Invoked when peripheral name updated.
   */
  - (void)RTKPeripheralDidUpdateName:(RTKLEPeripheral *)peripheral;
  
  /**
   * Invoked when peripheral RSSI updated.
   */
  - (void)RTKPeripheralDidUpdateRSSI:(RTKLEPeripheral *)peripheral;
  
  @end
  
  
  /*!
   *  @class RTKLEPeripheral
   *  Realtek wrapper of CBPeripheral.
   *
   *  @discussion The CBPeer class is an abstract base class that defines common behavior for objects representing Realtek remote devices. Use this class for Realtek SDK context. Do not confuse with CBPeripheral.
   */
  @interface RTKLEPeripheral : NSObject <CBPeripheralDelegate> {
      @protected
      RTKLEPeripheralValidState _validState;
      CBPeripheral *_CBPeripheral;
  }
  
  /**
   * CoreBluetooth Peripheral instance related.
   */
  @property (readonly, nonnull) CBPeripheral *CBPeripheral;
  
  /**
   * Peripheral name. Identical to CBPeripheral.name
   */
  @property (readonly, nullable) NSString *name;
  
  /**
   * Designated initializer
   * @param peripheral The underlying CBPeripheral.
   */
  - (instancetype)initWithCBPeripheral:(CBPeripheral *)peripheral profile:(RTKLEProfile *)profile;
  
  
  @property (weak, nonatomic, nullable) id<RTKLEPeripheralDelegate> delegate;
  
  /**
   * The peripheral advertisement data. Retrived when scan.
   */
  @property (readonly, nullable) NSDictionary<NSString *, id> *advertisement;
  
  /**
   * The last peripheral RSSI.
   * @discussion When RSSI monitoring is on going, this value is updated periodically.
   */
  @property (readonly) NSInteger RSSI;
  
  /**
   * Start monitor RSSI.
   */
  - (void)startMonitorRSSI;
  
  /**
   * Stop monitor RSSI.
   */
  - (void)stopMonitorRSSI;
  
  /**
   * The profile which this peripheral belong to.
   */
  @property (nonatomic, weak, readonly) RTKLEProfile *profile;
  
  @end
  
  
  @interface RTKLEPeripheral(Validation)
  
  /**
   * Indicate whether the peripheral conform Profile Service Spec. i.e have specified service & characterisitc.
   */
  @property (readonly) RTKLEPeripheralValidState validState;
  
  /**
   * The interval as a hint when wait for validate completion.
   * Default to 5 secound. The actual timeout interval may not be same with the passed value.
   */
  @property (nonatomic) NSTimeInterval validateTimeoutInterval;
  
  - (void)validateConformanceWithCompletion:(RTKLECompletionBlock)handler;
  
  @end
  
  
  @interface RTKLEPeripheral(Open)
  
  /**
   * Whether peripheral is ready for operation.
   */
  @property (readonly) BOOL isOpen;
  
  - (void)openWithCompletion:(RTKLECompletionBlock)handler;
  - (void)closeWithCompletion:(RTKLECompletionBlock)handler;
  
  @end
  
  
  
  
  
  
  @interface RTKLEPeripheral(Private)
  - (void)_setScanAdvertisementData:(NSDictionary<NSString *, id> *)data;
  - (void)_setScanRSSI:(NSInteger)rssi;
  @end
  
  
  /**
   * Interface related to ATT Discovery
   */
  @interface RTKLEPeripheral(Discovery)
  
  /**
   * Asynchronously discover Attribute(Service & Characteristics)
   * @param dict NSDictionary containing Service UUIDs and Characteristic UUIDs to discover. Example: @{@"000002FD-3C17-D293-8E48-14FE2E4DA212": @[@"FFE0", @"FFE1"]}
   * @param handler Invoked when all Service and Characteristics specified in dict discovered, or timeout error (5s).
   */
  - (void)discoverCharacteristicsWithIDDictionary:(NSDictionary *)dict completionHandler:(void(^)(BOOL, NSError *_Nullable))handler;
  
  - (void)discoverService:(NSString *)serviceID containingCharacteristics:(nullable NSArray <NSString*>*)characteristicIDs completionHandler:(void(^)(BOOL, NSError *_Nullable))handler;
  
  - (void)discoverService:(NSString *)serviceID containingCharacteristics:(nullable NSArray <NSString*>*)characteristicIDs timeout:(NSTimeInterval)timeout completionHandler:(void(^)(BOOL, NSError *_Nullable))handler;
  
  - (void)_clearDiscoveryCache;
  
  
  - (nullable CBService *)serviceWithID:(NSString *)serviceID;
  
  /**
   * Return the Characteristic already discovered.
   */
  - (nullable CBCharacteristic *)characteristicOfID:(NSString *)charID inService:(NSString *)serviceID;
  
  
  
  - (void)handleConnectionEvent;
  
  - (void)handleDisconnectionEventWithError:(nullable NSError *)err;
  
  @end
  
  
  #pragma mark - Deprecated
  
  /**
   * Add or remove Characteristic value event dispatch destination.
   */
  @interface RTKLEPeripheral(CharacteristicReadWrite)
  /* 注册Characteristic读和写的事件通知 */
  - (void)registerCharacteristicReader:(id <RTKPeripheralCharacteristicRead>)reader;
  - (void)unregisterCharacteristicReader:(id <RTKPeripheralCharacteristicRead>)reader;
  - (void)registerCharacteristicWriter:(id <RTKPeripheralCharacteristicWrite>)writer;
  - (void)unregisterCharacteristicWriter:(id <RTKPeripheralCharacteristicWrite>)writer;
  
  @end
  
  @interface RTKLEPeripheral (CBPeripheralDelegate)
  
  - (void)addCBPeripheralDelegate:(id <CBPeripheralDelegate>)delegate;
  - (void)removeCBPeripheralDelegate:(id <CBPeripheralDelegate>)delegate;
  
  @end
  
  
  NS_ASSUME_NONNULL_END