1.ãIOSãBLE-èç空ä¸å级(OAD)
2.iOS èç
3.ios开发如何获取iPhone经典蓝牙的牙源牙a源码mac地址
ãIOSãBLE-èç空ä¸å级(OAD)
èç为CC ioså级èçåºä»¶;
1.头æ件
å级è¦ç¨å°çID
2.è·åèçå表,éæ©éè¦å级çèç
3.è·åææçç¹å¾å¼,æ¾å°æ们éè¦çéé,设置ééç模å¼ä¸ºçæµééåå
ä¼ è¿å»æéçåæ°
4.æå®èçç代çå代çæ¹æ³
5.éæ©è¦å级çæ件(è¿éæ¯æ¬å°)
6.å¼å§è¿è¡èçå级:
(1)åéä¸ä¸ªåèæ°æ®æ¥è·åèç设å¤çå½å设å¤ä¿¡æ¯
(2)å¨ä»£çå¤æ¥æ¶è¿åæ°æ®
(3)å¤çæ¥æ¶çæ°æ®,å¦æçæ¬ä¸ç¸å,å°±ææ¬å°æ件çåºä»¶ä¿¡æ¯éè¿ éé1 åéè¿å»;
åºä»¶ä¿¡æ¯å å«çä¿¡æ¯æï¼åºä»¶çæ¬ãåºä»¶é¿åº¦ãåºä»¶ç±»å
(4)å¨ä»£çå¤æ¥æ¶è¿åæ°æ®(å¦ææåä¼éè¿ éé2 è¿åæ°æ®)
(5)å¤çæ°æ®,å¼å§åéæ¬å°æ件;æ¶å°çæ°æ®æ¯éè¦åéæ°æ®çåºå·(-FFFF,é«ä½å¨å;,,...FF,,...)
æ¤æ¶æ两ç§æ¹æ³:
第ä¸ç§æ¯æ¯æ¬¡é½éè¿æ¥æ¶å°çåºå·æ¥åéæ°æ®,å°±ä¸éè¦æ¹åèççåéåæ¥æ¶æ¨¡å¼;
第äºç§æ¯ç´æ¥æç §ä¸å®çé´éå»åéæ°æ®;åªè¦å硬件è§å®å¥½æ¶é´å°±å¯ä»¥åºæ¬ä¿è¯æå;
ç±äºç¬¬ä¸ç§æ¹æ³çé度å¾æ ¢,æ以æéæ©ç第äºç§æ¹å¼;
(6)设置å®æ¶å¨,é´éæ¶é´ms;ç±äºæ¯ç´æ¥åéä¸éè¦è¿åæ以éæ© CBCharacteristicWriteWithoutResponse çæ¹å¼;
(7)ä¼ è¾ç»æå,硬件设å¤ä¼èªå¯,èçä¼æå¼;
demo没æ´ç è§è°
/huasali/blueToothDemo
iOS èç
1. iOSä¸å¼åèç常ç¨çç³»ç»åºæ¯<CoreBluetooth/CoreBluetooth.h>ã
2.èçå¤è®¾å¿ é为4.0å以ä¸(2.0éè¦MFI认è¯)ï¼å¦åæ æ³è¿è¡å¼åï¼èç4.0设æ½ç±äºä½èçµï¼æ以ä¹å«åBLEã
3. CoreBluetoothæ¡æ¶çæ ¸å¿å ¶å®æ¯ä¿©ä¸è¥¿
3.1 Peripheral
3.2 Central
4. æå¡åç¹å¾(service characteristic)ï¼ç®èè¨ä¹ï¼å¤é¨èçä¸å®æè¥å¹²ä¸ªæå¡serviceï¼æå¡ä½ è½äºè§£ä¸ºèçææ¥æçå¯ä»¥åï¼ï¼èæ¯ä¸ªæå¡serviceä¸æ¥æè¥å¹²ä¸ªç¹å¾characteristicï¼ç¹å¾ä½ è½äºè§£ä¸ºè§£éè¿ä¸ªæå¡çå±æ§ï¼ã
5. Descriptorï¼å½¢å®¹ï¼ä½¿ç¨æ¥å½¢å®¹characteristicåéçå±æ§ãä¾å¦ï¼ä¸ä¸ªdescriptorè½è§å®ä¸ä¸ªå¯è¯»ç形容ï¼æè è ä¸ä¸ªcharacteristicåéå¯æ¥åçèå´ï¼æè è ä¸ä¸ªcharacteristicåéç¹å®çåä½ã
3.1 å建ä¸ä¸ªCBCentralManagerå®ä¾æ¥è¿è¡èç管çï¼
3.2 æç´¢æ«æå¤å´è®¾å¤ï¼
3.3 è¿æ¥å¤å´è®¾å¤ï¼
3.4 è·å¾å¤å´è®¾å¤çæå¡ï¼
3.5 è·å¾æå¡çç¹å¾ï¼
3.6 ä»å¤å´è®¾å¤è¯»åæ°æ®ï¼
3.7 ç»å¤å´è®¾å¤åéï¼åå ¥ï¼æ°æ®ã
4.1 åå§å
dispatch_queue_t centralQueue = dispatch_queue_create(âcentralQueue",DISPATCH_QUEUE_SERIAL);
NSDictionary *dic = @{ CBCentralManagerOptionRestoreIdentifierKey : restoreIdentifier};
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:centralQueue options:dic];
CBCentralManagerOptionRestoreIdentifierKey对åºçæ¯ä¸ä¸ªå¯ä¸æ è¯çå符串ï¼ç¨äºèçè¿ç¨è¢«æææ¢å¤è¿æ¥æ¶ä½¿ç¨
4.2 æ«æ
/
**æ«æ设å¤
*/
- ( void )scanForDevices:(NSError**)error
{
if (CBCentralManagerStatePoweredOn == self .centralManager.state) {
//ååå·²è¿æ¥çservice设å¤
NSArray* retrievedPeripherals = [ self .centralManagerretrieveConnectedPeripheralsWithServices:@[ self .serviceUUID]];
for (CBPeripheral* peripheral in retrievedPeripherals){
//NSLog(@"retrieved peripheral:%@", peripheral);
[ self .delegateclient: self didDiscoverDevice:peripheral.identifier];
}
//å¯å¨æ«æ
if ( self .advertisementUUID) {
[ self .centralManager scanForPeripheralsWithServices:@[ self .advertisementUUID ] options:@{ CBCentralManagerScanOptionAllowDuplicatesKey:@YES }];
} else {
[ self .centralManager scanForPeripheralsWithServices: nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey:@YES }];
// [self.centralManager scanForPeripheralsWithServices:nil options:nil];
}
} else {
if (error != NULL ) {
*error = [NSErrorerrorWithDomain:HCErrorDomaincode:(SRVClientErrorUnknown+ self .centralManager.state)userInfo: nil ];
NSLog(@"[NSError errorWithDomain:HCErrorDomain code:(SRVClientErrorUnknown + self.centralManager.state) userInfo:nil];");
}
}
}
4.3 åç°å¤å´è®¾å¤
- ( void )centralManager:(CBCentralManager*)centraldidDiscoverPeripheral:(CBPeripheral*)peripheraladvertisementData:(NSDictionary*)advertisementDataRSSI:(NSNumber*)RSSI {
NSString*peripheralName = peripheral.name;
if (peripheralName == nil || peripheralName.length==0) {
return ;
}
if ([peripheralNameisEqualToString:SRV_CLIENT_DEV_NAME] || [peripheralNameisEqualToString:SRV_CLIENT_DFU_NAME]) {
}
}
4.4 è¿æ¥å¤å´è®¾å¤
//èçè¿æ¥æååè°
- ( void )centralManager:(CBCentralManager*)centraldidConnectPeripheral:(CBPeripheral*)peripheral {
[ self .centralManager stopScan];
peripheral.delegate= self ;
self .commandNo=0;
NSLog(@"[D] CentralManager Discover services.");
NSLog(@"%@", self .peripheral);
self .peripheral.delegate= self ;
[ self .peripheral discoverServices:@[ self .serviceUUID]];
NSLog(@"%@", self .serviceUUID);
//å®æ¶è·åRSSI
if ( self .needReadRSSI) {
[ self readPeripheralRSSI];
if (! self .rssiTimer) {
self .rssiTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target: self
selector: @selector (readPeripheralRSSI)
userInfo: nil
repeats: YES ];
}
}
}
#pragma mark è¿æ¥å¤è®¾ââ失败
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
NSLog(@"%@", error);
}
#pragma mark åæ¶ä¸å¤è®¾çè¿æ¥åè°
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
NSLog(@"%@", peripheral);
}
4.5 è·å¾å¤å´è®¾å¤çæå¡
//åç°æå¡çåè°
- ( void )peripheral:(CBPeripheral*)peripheraldidDiscoverServices:(NSError*)error
{
NSLog(@"%@---didDiscoverServices",peripheral);
if (error){
NSLog(@"[E] peripheral didDiscoverServices error: %@", error.localizedDescription);
[ self cancelConnection];
return ;
}
for (CBService* service in peripheral.services){
NSLog(@"[D] Discover characteristics. For service = %@", service);
[peripheraldiscoverCharacteristics: nil forService:service];
}
}
//åç°ç¹å¾çåè°
- ( void )peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if (error){
NSLog(@"[E] peripheral didDiscoverCharacteristicsForService error: %@", error.localizedDescription);
[ self cancelConnection];
return ;
}
NSLog(@"[D] peripheral DiscoverCharacteristics = %@", service.characteristics);
//订é ç¹å¾
for (CBCharacteristic*characteristic in service.characteristics){
if (characteristic.properties & (CBCharacteristicPropertyNotify|CBCharacteristicPropertyIndicate)){
if (!characteristic.isNotifying) {
if ([ self .ignoreCharacteristicUUIDscontainsObject:characteristic.UUID]) {
continue ;
}
NSLog(@"[D] Enable notify value. For characteristic = %@", characteristic);
//d订é ç¹æ§å½æ°æ®é¢ç¹æ¹åæ¶ç¨ setNotifyValue ä¸é¢ç¹æ¶ç¨readValueForCharacteristic
[peripheralsetNotifyValue: YES forCharacteristic:characteristic];
}
}
}
}
// 订é åçcallback
- ( void )peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
if (error){
NSLog(@"[E] peripheral didUpdateNotificationStateForCharacteristic error: %@", error.localizedDescription);
[ self cancelConnection];
return ;
}
if ([ self isAllCharacteristicNotificationEnabled]){
NSLog(@"订é æå");
//authorizeRequest ææ认è¯
[ self .delegate clientDidPrepareForOperation: self ];
}
// [self.delegate clientDidPrepareForOperation:self];
}
4.6 ä»å¤å´è®¾å¤è¯»åæ°æ®
// peripheral主å¨åæ°æ®ï¼å æ¬åå½ä»¤å主å¨è¿åçç¶æ 读æ°æ®çåè°
- ( void )peripheral:(CBPeripheral*)peripheraldidUpdateValueForCharacteristic:(CBCharacteristic*)characteristicerror:(NSError*)error
{
if (error) {
NSLog(@"[E] peripheral didUpdateValueForCharacteristic error: %@ %@", error.localizedDescription,characteristic);
[ self cancelConnection];
[ self cleanupOperationUnexpectedly];
return ;
}
NSLog(@"%@",peripheral);
NSLog(@"%@",characteristic);
[ self .delegate client: self didUpdateValueForCharacteristic:characteristic.UUID value:characteristic.value];
if ([characteristic.UUIDisEqual: self .ctrlptUUID]) {
if (CTRLPTProgressWaitResp == self .ctrlptProgress) {
}
}
}
4.7 ç»å¤å´è®¾å¤åéï¼åå ¥ï¼æ°æ®
- ( BOOL )performOperationSegment:(CBCharacteristic*)characteristic
{
BOOL isLastSegment;
uint8_tsegment[];
uint_tindex =0;
uint_tsegLength;
NSIntegerforwardLength = self .forwardFlow.length;
if ((forwardLength - self .forwardOffset) > (- index)) {
isLastSegment = NO ;
segLength = (- index);
} else {
isLastSegment = YES ;
segLength = (forwardLength - self .forwardOffset);
}
memcpy(&segment[index], & self .forwardFlow.bytes[ self .forwardOffset], segLength);
self .forwardOffset+= segLength;
index += segLength;
NSData*writeData = [NSDatadataWithBytes:segmentlength:index];
NSLog(@"[D] Write value = %@. For characteristic = %@", writeData, characteristic);
[ self .peripheral writeValue:writeData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];//对äºææ§ç±»èçï¼æ°æ®åå ¥è¦æ±é常快ï¼å ¶ä¸writeWithSponceåå ¥æ¶èçæ¶é´æ¯writeWithoutSponceç2.3åï¼å æ¤å°½éæ¹åæwriteWithoutSponceæ¥æååå ¥éç
return isLastSegment;
}
//æ¯å¦åå ¥æåçåè°
- ( void )peripheral:(CBPeripheral*)peripheraldidWriteValueForCharacteristic:(CBCharacteristic*)characteristicerror:(NSError*)error
{
if (error) {
NSLog(@"[E] peripheral didWriteValueForCharacteristic error: %@", error);
[ self cancelConnection];
[ self cleanupOperationUnexpectedly];
return ;
}
NSLog(@"åå ¥æå----%@",characteristic);
if ([characteristic.UUIDisEqual: self .ctrlptUUID]) {
if (CTRLPTProgressWritting == self .ctrlptProgress) {
if ([ self performOperationSegment:characteristic]) {
self .ctrlptProgress = CTRLPTProgressWaitResp;
self .backwardFlow.length=0;
self .backwardOffset=0;
}
}
}
}
4.8 å¦ä½è§£æèçæ°æ®
//å¤ææ¯å¦ç¬¬ä¸ä¸ªå ï¼è¥æ¯ï¼ååºå é¿åº¦
if (0== self .backwardOffset&& length >=2) {
uint_tcommandLength;
[characteristicDatagetBytes:&commandLengthlength: sizeof (commandLength)];
offset += sizeof (commandLength);
self .backwardLength= commandLength;
[ self .backwardFlowappendData:[characteristicDatasubdataWithRange:NSMakeRange(offset, length - offset)]];
} else {
[ self .backwardFlowappendData:characteristicData];
}
ios开发如何获取iPhone经典蓝牙的mac地址
1:把它加到蓝牙的广播包里,但是码下登录框源码这样的话对硬件来说负担很大 而且芯片会不稳定
2:有的设备可以通过 “A”这个服务来发现特征,再来读取 “2A”这个特征值,载蓝qq壁纸ps源码可以获得Mac地址(如果你的牙源牙a源码php 组卷源码蓝牙设备不支持这样获取,你可以跟硬件工程师沟通,来获得Mac地址,码下telnet的源码分析添加一个获取地址命令或者增加一个含地址的载蓝c 用easyx源码特征值都可以很容易的获取)