单军华
2018-04-20 2197e837490f5083d18d9fdb97265d1e0f04832a
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
211
212
 
 
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "Constants.h"
#import "ResourceHandler.h"
#import "Utilities.h"
 
 
/*!
 *  @property CBDiscoveryDelegate
 *
 *  @discussion The delegate object that will receive events which use for UI updation.
 *
 */
@protocol cbDiscoveryManagerDelegate <NSObject>
 
/*!
 *  @method discoveryDidRefresh
 *
 *  @discussion            This method invoke after a new peripheral found.
 */
- (void) discoveryDidRefresh;
 
/*!
 *  @method bluetoothStateUpdatedToState:
 *
 *  @discussion     This will be invoked when the Bluetooth state changes.
 */
 
- (void) bluetoothStateUpdatedToState:(BOOL)state;
@end
 
@protocol cbCharacteristicManagerDelegate <NSObject>
 
@optional
/*!
 *  @method peripheral:didDiscoverCharacteristicsForService:error:
 *
 *  @param peripheral    The peripheral providing this information.
 *  @param service        The <code>CBService</code> object containing the characteristic(s).
 *    @param error        If an error occurred, the cause of the failure.
 *
 *  @discussion            This method returns the result of a @link discoverCharacteristics:forService: @/link call. If the characteristic(s) were read successfully,
 *                        they can be retrieved via <i>service</i>'s <code>characteristics</code> property.
 */
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error;
 
/*!
 *  @method peripheral:didUpdateValueForCharacteristic:error:
 *
 *  @param peripheral        The peripheral providing this information.
 *  @param characteristic    A <code>CBCharacteristic</code> object.
 *    @param error            If an error occurred, the cause of the failure.
 *
 *  @discussion                This method is invoked after a @link readValueForCharacteristic: @/link call, or upon receipt of a notification/indication.
 */
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error;
 
/*!
 *  @method peripheral:didWriteValueForCharacteristic:error:
 *
 *  @param peripheral        The peripheral providing this information.
 *  @param characteristic    A <code>CBCharacteristic</code> object.
 *    @param error            If an error occurred, the cause of the failure.
 *
 *  @discussion                This method returns the result of a {@link writeValue:forCharacteristic:type:} call, when the <code>CBCharacteristicWriteWithResponse</code> type is used.
 */
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error;
 
/*!
 *  @method peripheral:didUpdateNotificationStateForCharacteristic:error:
 *
 *  @param peripheral        The peripheral providing this information.
 *  @param characteristic    A <code>CBCharacteristic</code> object.
 *    @param error            If an error occurred, the cause of the failure.
 *
 *  @discussion                This method returns the result of a @link setNotifyValue:forCharacteristic: @/link call.
 */
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error;
 
/*!
 *  @method peripheral:didDiscoverDescriptorsForCharacteristic:error:
 *
 *  @param peripheral        The peripheral providing this information.
 *  @param characteristic    A <code>CBCharacteristic</code> object.
 *    @param error            If an error occurred, the cause of the failure.
 *
 *  @discussion                This method returns the result of a @link discoverDescriptorsForCharacteristic: @/link call. If the descriptors were read successfully,
 *                            they can be retrieved via <i>characteristic</i>'s <code>descriptors</code> property.
 */
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error;
 
/*!
 *  @method peripheral:didUpdateValueForDescriptor:error:
 *
 *  @param peripheral        The peripheral providing this information.
 *  @param descriptor        A <code>CBDescriptor</code> object.
 *    @param error            If an error occurred, the cause of the failure.
 *
 *  @discussion                This method returns the result of a @link readValueForDescriptor: @/link call.
 */
-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDescriptor *)descriptor error:(NSError *)error;
 
@end
 
 
@interface CBMoralManager : NSObject 
{
    
}
 
@property (strong,nonatomic)  id<cbCharacteristicManagerDelegate> cbCharacteristicDelegate;
@property (nonatomic, assign) id<cbDiscoveryManagerDelegate>           cbDiscoveryDelegate;
 
 
/*!
 *  @property myPeripheral
 *
 *  @discussion Current Connected Peripheral.
 *
 */
@property (nonatomic, retain)CBPeripheral        *myPeripheral;
 
/*!
 *  @property myService
 *
 *  @discussion  The selected Service.
 *
 */
@property (nonatomic, retain)CBService            *myService;
 
/*!
 *  @property myCharacteristic
 *
 *  @discussion  The selected Characteristic.
 *
 */
@property (nonatomic, retain)CBCharacteristic   *myCharacteristic;
 
 
/*!
 *  @property myCharacteristic2
 *
 *  @discussion Is just for USR Debug Mode.
 *
 */
@property (nonatomic,retain)CBCharacteristic *myCharacteristic2;
 
/*!
 *  @property foundPeripherals
 *
 *  @discussion  All discovered peripherals while scanning.
 *
 */
@property (retain, nonatomic) NSMutableArray    *foundPeripherals;
 
/*!
 *  @property foundServices
 *
 *  @discussion All available services of connected peripheral..
 *
 */
@property (retain, nonatomic) NSMutableArray    *foundServices;
 
/*!
 *  @property serviceUUIDDict
 *
 *  @discussion  Dictionary contains all listed Known services from pList (ServiceUUIDPlist).
 *
 */
@property (retain, nonatomic) NSMutableDictionary      *serviceUUIDDict;
 
/*!
 *  @property characteristicProperties
 *
 *  @discussion  Properties of characteristic .
 *
 */
@property (retain,nonatomic) NSMutableArray *characteristicProperties;
 
/*!
 *  @property characteristicDescriptors
 *
 *  @discussion  Descriptors of characteristic .
 *
 */
@property (retain,nonatomic) NSArray  *characteristicDescriptors;
 
/*!
 *  @property bootLoaderFilesArray
 *
 *  @discussion  Firmware files selected for device upgrade.
 *
 */
 
@property (retain, nonatomic) NSArray *bootLoaderFilesArray;
 
+ (id)sharedManager;
 
 
/*                                Actions                                        */
/****************************************************************************/
- (void) startScanning;
- (void) stopScanning;
- (void) refreshPeripherals;
 
- (void) connectPeripheral:(CBPeripheral*)peripheral CompletionBlock:(void (^)(BOOL success, NSError *error))completionHandler;
- (void) disconnectPeripheral:(CBPeripheral*)peripheral;
 
 
@end