Blame view

Twear/3rd/Mediatek/MTKBleManager.h 6.32 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
  //
  //  MTKBleManager.h
  //  BleProfile
  //
  //  Created by ken on 14-7-6.
  //  Copyright (c) 2014 MTK. All rights reserved.
  //
  
  #import <Foundation/Foundation.h>
  #import <CoreBluetooth/CoreBluetooth.h>
  #include <unistd.h>
  #import "MTKBleProximityService.h"
  #import "AlertService.h"
  //#import "HealthKitSerivce.h"
  #import "GATTLinker.h"
  #import "BLEClientProfile.h"
  
  /* Charactistic UUID */
  extern NSString *const kAlertLevelCharacteristicUUIDStringNew;
  extern NSString *const kTxPowerLevelCharacteristicUUIDString;
  
  extern NSString *const kEnterBackgroundNotification;
  extern NSString *const kEnterForegroundNotification;
  extern NSString *const kFinishLaunchNotification;
  //For application be forced killed
  extern NSString *const kKillApplicationNotification;
  
  extern NSString *const UserDefaultKey_disconnecManually;
  extern NSString *const UserDefaultKey_savedIdentify;
  extern NSString *const UserDefaultKey_killedForcely;
  
  /*UI Protocols */
  @protocol BleDiscoveryDelegate <NSObject>
  
  - (void) discoveryDidRefresh: (CBPeripheral *)peripheral;
  - (void) discoveryStatePoweredOff;
  
  @end
  
  @protocol BleConnectDlegate <NSObject>
  
  - (void) connectDidRefresh:(int)connectionState deviceName:(CBPeripheral*)peripheral;
  - (void) disconnectDidRefresh: (int)connectionState devicename: (CBPeripheral *)peripheral;
  - (void) retrieveDidRefresh: (NSArray *)peripherals;
  
  @end
  
  @protocol BleScanningStateChangeDelegate <NSObject>
  
  - (void) scanStateChange:(int)state;
  
  @end
  
  @protocol BluetoothAdapterStateChangeDelegate <NSObject>
  
  -(void)onBluetoothStateChange:(int)state;
  
  @end
  
  @protocol ClientProfileDelegate <NSObject>
  
  - (void)onCentralManagerStateChange: (int)state;
  - (void)onConnected: (CBPeripheral *)peripheral;
  - (void)onDisconnected;
  - (void)onServiceDiscovered: (CBPeripheral *)periphearl error: (NSError *)error;
  - (void)onCharacteristicDiscovered: (CBPeripheral *)peripheral forService: (CBService *)service error: (NSError *)err;
  - (void)onUpdateValueForCharacteristic: (CBPeripheral *)peripheral forCharacteristic: (CBCharacteristic *)characteristic error: (NSError *)err;
  - (void)onCharacteristicWrite;
  - (void)onReadRssi: (CBPeripheral *)peripheral rssiValue: (int)rssi error: (NSError *)err;
  
  @end
  
  /******************** scaning state **********************/
  const static int SCANNING_STATE_ON = 1;
  const static int SCANNING_STATE_OFF = 0;
  /**********************************************************/
  
  /******************** conntion state **********************/
  const static int CONNECT_SUCCESS = 1;
  const static int CONNECT_FAILED = 2;
  const static int DISCONNECT_SUCCESS = 3;
  const static int DISCONNECT_FAILED = 4;
  
  const static int CONNECTION_STATE_CONNECTED = 2;
  const static int CONNECTION_STATE_CONNECTING = 1;
  const static int CONNECTION_STATE_DISCONNECTING = 3;
  const static int CONNECTION_STATE_DISCONNECTED = 0;
  /**********************************************************/
  
  @interface MTKBleManager: NSObject
  
  + (id) sharedInstance;
  
  @property (nonatomic) int scanningState;
  
  - (void)registerDiscoveryDelgegate: (id<BleDiscoveryDelegate>)discoveryDelegate;
  - (void)registerConnectDelgegate: (id<BleConnectDlegate>)connectDelegate;
  - (void)registerProximityDelgegate: (id<ProximityAlarmProtocol>)proximityDelegate __attribute__((deprecated("use method registerProximityDelgegate: in MTKBleProximityService instead")));
  - (void)registerScanningStateChangeDelegate:(id<BleScanningStateChangeDelegate>)scanStateChangeDelegate;
  - (void)registerBluetoothStateChangeDelegate:(id<BluetoothAdapterStateChangeDelegate>)bluetoothStateChangeDelegate;
  //- (void)registerCalibrateDelegate:(id<CalibrateProtocol>)calibrateDelegate;
  
  /* Action */
  - (void)startScanning;
  - (void)stopScanning;
  - (void)forgetPeripheral;
  
  - (int)getCurrentConnectState;
  
  - (void)connectPeripheral: (CBPeripheral *)peripheral;
  - (void)disconnectPeripheral: (CBPeripheral *)peripheral;//phase out
  - (void)disconnectPeripheral;
  
  - (void)unRegisterDiscoveryDelgegate: (id<BleDiscoveryDelegate>)discoveryDelegate;
  - (void)unRegisterConnectDelgegate: (id<BleConnectDlegate>)connectDelegate;
  - (void)unRegisterProximityDelgegate: (id<ProximityAlarmProtocol>)proximityDelegate __attribute__((deprecated("use method unRegisterProximityDelgegate: in MTKBleProximityService instead")));
  - (void)unRegisterScanningStateChangeDelegate:(id<BleScanningStateChangeDelegate>)scanStateChangeDelegate;
  - (void)unRegisterBluetoothStateChangeDelegate:(id<BluetoothAdapterStateChangeDelegate>)bluetoothStateChangeDelegate;
  //- (void)unRegisterCalibrateDelegate:(id<CalibrateProtocol>)calibrateDelegate;
  
  
  //pxp related
  - (void)updatePxpSetting: (NSString *)peripheralIdentify
              alertEnabler: (int)alertEnabler
                     range: (int)rangeAlertEnabler
                 rangeType: (int)rangeType
             alertDistance: (int)distance
    disconnectAlertEnabler: (int)disconnectAlertEnabler __attribute__((deprecated("use method updatePxpSetting: in MTKBleProximityService instead")));
  
  - (int)queryDistance: (CBPeripheral *) peripheral __attribute__((deprecated("use method queryDistance: in MTKBleProximityService instead")));
  - (BOOL)getIsNotifyRemote: (CBPeripheral *)peripheral __attribute__((deprecated("use method getIsNotifyRemote: in MTKBleProximityService instead")));
  - (void)setAlertThreshold: (int)near midThreshold: (int)middle farThreshold: (int)far __attribute__((deprecated("use method updateAlertThreshhold: in MTKBleProximityService instead")));
  -(BOOL)findTarget:(int) level __attribute__((deprecated("use method findTarget: in FmpGattClient instead")));
  
  -(int)getScanningState;
  
  /**
   use this method to set the DOGP max write GATT length to avoid loss package
   */
  -(BOOL)setDogpMaxWriteLength:(int)length;
  
  /* Behave properly when heading into and out of the background */
  - (void)enteredBackground;
  - (void)enteredForeground;
  - (void)terminateApplication;
  
  /*Access to the devices */
  @property (retain, nonatomic) NSMutableArray *foundPeripherals;
  @property (retain, nonatomic) NSMutableArray *connectPeripherals;
  @property (retain, nonatomic) NSMutableArray *connectedService;
  @property (retain, nonatomic, strong) CBPeripheral *peripheral;
  @property (retain, nonatomic, strong) CBPeripheral *tempPeripheral;
  
  /**
   *    register clien UUID for searching service
   *
   *    @param clientUUID the UUID published by remote server
   */
  - (void)registerClientProfile: (NSString *)clientServiceUUIDStr ClientProfileDelegate: (id<ClientProfileDelegate>)clientProfileDelegate;
  
  @end