From: liangzhenying <867174124@qq.com>
Date: Mon, 1 Apr 2024 09:56:47 +0000 (+0800)
Subject: USB鉴权通讯调试
X-Git-Tag: é¿éé´æ~4
X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=f8b45e53f8c63faf4280ab797b708f749b1a05d8;p=mirrors%2FMouseSdk-MacOS.git
USB鉴权通讯调试
---
diff --git "a/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md" "b/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md"
index ca77af9..f70e522 100644
--- "a/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md"
+++ "b/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md"
@@ -9,6 +9,7 @@
| 1.0.0 | åå§çæ¬ | æ¢æ¯è¥ | 2024-03-8 |
| 1.0.1 | é¼ æ æé®æä»¤ä¿®æ¹ | æ¢æ¯è¥ | 2024-03-18 |
| 1.0.2 | é´ææµç¨ä¿®æ¹ï¼åªæé´ææåäºï¼SDKç¸å
³åè½æå¯ä»¥ä½¿ç¨ | æ¢æ¯è¥ | 2024-03-19 |
+| 1.0.3 | æ¯æUSBé讯 | æ¢æ¯è¥ | 2024-04-01 |
@@ -22,19 +23,30 @@
## ç¸å
³æéé
ç½®
-å 为sdkç¨å°èçæéï¼æä»¥éè¦å¨info.plistè¿è¡ç¸å
³é
ç½®
+å 为sdkç¨å°èçæéãç½ç»ãè¯é³çåè½ï¼info.pliståæ²çéè¦è¿è¡ç¸å
³æé设置
```xml
NSBluetoothAlwaysUsageDescription
-Appéè¦æ¨çåæ,æè½è®¿é®èç
-```
+è¦æå¼èçæè½ä½¿ç¨AIåè½å¦
+
+Privacy - Microphone Usage Description
+è¦æå¼éº¦å
飿è½ä½¿ç¨AIåè½å¦
+```
+
## SDKç¸å
³æ¥å£
```objective-c
+/// åå©
++(AiMouse *)shared;
+
+/// åæ¢è¿æ¥ç±»å
+/// - Parameter type: è¿æ¥ç±»å
+- (void)switchConnect:(AiMouseConnectType)type;
+
/// å¼å§é´æ
/// - Parameter finished: é´æç»æåè°
- (void)startAuthentication:(void (^)(AiMouseAuthState state))finished;
@@ -77,9 +89,9 @@
/// é¼ æ æé®æä»¤åè°
/// - Parameter data: æ°æ®ã
-/// M é® çæ0x42ï¼é¿ææä¸ï¼å¼å§å½é³ï¼0x25ï¼ é¿ææ¬èµ·(ç»æå½é³) 0x26;
-/// AIé® çæ0x43 ï¼é¿ææä¸ï¼å¼å§å½é³ï¼0x27ï¼ é¿ææ¬èµ·(ç»æå½é³) 0x28;
-/// è¯é³é® æä¸ï¼å¼å§å½é³ï¼ 0x31ï¼å¼¹èµ·ï¼ç»æå½é³ï¼0x32ï¼
+/// å ç¬¬ä¸æ¬¡åå»31(å¼å§å½é³ï¼ï¼ ç¬¬äºæ¬¡åå»32(ç»æå½é³) ï¼ æä¸21ï¼å¼å§å½é³ï¼æ¬èµ·22(ç»æå½é³)
+/// ä¸ åå»42ï¼ æä¸25ï¼å¼å§å½é³ï¼æ¬èµ·26(ç»æå½é³)
+/// å åå»43ï¼æä¸27ï¼å¼å§å½é³ï¼æ¬èµ·28(ç»æå½é³)
/// å
¶ä»æªå®ä¹
- (void)aiMouseSendCmdData:(NSData *)data;
@@ -88,177 +100,541 @@
- (void)aiMouseSendRecordData:(NSData *)data;
```
-## 示ä¾
-
-- èçæå¡ç¹å¾
-
- ```objective-c
- // æå¡id
- #define kServiceUUID @"FFF1"
- //aiç¹å¾
- #define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8"
- //é´æç¹å¾
- #define kAuthUUID @"0783B73E-8535-B5A0-7140-A304D2194CB7"
- //设å¤ä¿¡æ¯ç¹å¾
- #define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6"
- ```
-
-
-
-
-
-1. 设置代ç
-
- ```objective-c
- [AiMouse shared].delegate = self;
- ```
-
-2. æ¥æ¾å¯¹åºç¹å¾ï¼è®¢é
-
- ```
- // åç°ç¹å¾
- - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
- for (CBCharacteristic *characteristic in service.characteristics){
- if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {
- //é´æç¹å¾
- self.authCha = characteristic;
- [peripheral setNotifyValue:YES forCharacteristic:characteristic];
- //æ¾å°é´æç¹å¾åï¼ä¸å®è¦è°ç¨é´ææ¥å£å¼å§é´æãåªæé´æéè¿äºï¼sdkç¸å
³åè½æå¯ä»¥ä½¿ç¨
- [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {
- [self showLog:[NSString stringWithFormat:@"é´æç»æ = %@",@(state)]];
- if(self.authCallBack){
- self.authCallBack(state == AiMouseAuthState_Success);
- }
- }];
- }
- else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {
- //AIç¹å¾
- self.aiCha = characteristic;
- [peripheral setNotifyValue:YES forCharacteristic:characteristic];
- }
- else if ([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]) {
- //设å¤ä¿¡æ¯ç¹å¾
- self.deviceInfoCha = characteristic;
- [peripheral setNotifyValue:YES forCharacteristic:characteristic];
- }
- }
- }
- ```
-
-
-
-3. æ¶å°è®¾å¤ä¼ è¾è¿æ¥çæ°æ®ï¼ä¼ ç»sdkå¤ç
-
- ```objective-c
- //æ¶å°èçæ°æ®
- - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
- NSData *data = characteristic.value;
- [self showLog:[NSString stringWithFormat:@"[receive] %@",[AiMouseTools dataToHexString:data]]];
- if([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]){
- //é´ææ°æ®
- [[AiMouse shared] sendAuthDataToSdk:data];
- }
- else if([characteristic.UUID.UUIDString isEqualToString:kAiUUID]){
- //AIæ°æ®
- [[AiMouse shared] sendAiDataToSdk:data];
- }
- else if([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]){
- //设å¤ä¿¡æ¯æ°æ®
- [[AiMouse shared] sendDeviceDataToSdk:data];
- }
- }
-
- ```
-
- sdk代çåè°
-
- ```objective-c
- /// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
- /// - Parameter data: æ°æ®
- - (void)aiMouseSendAuthData:(NSData *)data{
- [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
- [self.connectPeripheral writeValue:data forCharacteristic:self.authCha type:CBCharacteristicWriteWithoutResponse];
- }
-
-
- /// 设å¤ä¿¡æ¯æ°æ®åè°ï¼éè¦å°æ¤æ°æ®éè¿è®¾å¤ä¿¡æ¯ç¹å¾è½¬åç»èç设å¤
- /// - Parameter data: æ°æ®
- -(void)aiMouseSendDeviceInfoData:(NSData *)data{
- [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
- [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse];
- }
-
- /// é¼ æ æé®æä»¤åè°
- /// - Parameter data: æ°æ®ã
- /// M é® çæ0x42ï¼é¿ææä¸ï¼å¼å§å½é³ï¼0x25ï¼ é¿ææ¬èµ·(ç»æå½é³) 0x26;
- /// AIé® çæ0x43 ï¼é¿ææä¸ï¼å¼å§å½é³ï¼0x27ï¼ é¿ææ¬èµ·(ç»æå½é³) 0x28;
- /// è¯é³é® æä¸ï¼å¼å§å½é³ï¼ 0x31ï¼å¼¹èµ·ï¼ç»æå½é³ï¼0x32ï¼
- /// å
¶ä»æªå®ä¹
- - (void)aiMouseSendCmdData:(NSData *)data{
- uint8 cmd;
- [data getBytes:&cmd length:1];
- if(cmd == 0x25){
- [self showLog:@"Mé®å¼å§å½é³"];
- self.recordData = [[NSMutableData alloc] init];
- }
- else if(cmd == 0x26){
- [self showLog:@"Mé®ç»æå½é³"];
- [self finishRecored:self.recordData];
- }
- else if(cmd == 0x27){
- [self showLog:@"AIé®å¼å§å½é³"];
- self.recordData = [[NSMutableData alloc] init];
- }
- else if(cmd == 0x28){
- [self showLog:@"AIé®ç»æå½é³"];
- [self finishRecored:self.recordData];
- }
- else if(cmd == 0x31){
- [self showLog:@"è¯é³é®å¼å§å½é³"];
- self.recordData = [[NSMutableData alloc] init];
- }
- else if(cmd == 0x32){
- [self showLog:@"è¯é³é®ç»æå½é³"];
- [self finishRecored:self.recordData];
- }
- else{
- [self showLog:@"æªå®ä¹æä»¤ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼"];
- }
- }
- /// å½é³åè°
- /// - Parameter data: pcmæ ¼å¼è¯é³æ°æ®
- - (void)aiMouseSendRecordData:(NSData *)data{
- [self.recordData appendData:data];
- }
- ```
-
- è·å设å¤ä¿¡æ¯
-
-- è·å设å¤ä¿¡æ¯
-
- ```
- [[AiMouse shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {
-
- }];
- ```
-
-
-
-- 设置PCI
-
- ```
- [[AiMouse shared] setCPI:1000 completation:^(BOOL isSuccess, NSError *error) {
-
- }];
- ```
-
-
+
+
+## èç示ä¾
+
+```objective-c
+ //
+// BleManager.m
+// AliIotSdkDemo
+//
+// Created by incar on 2024/1/30.
+//
+
+#import "BleManager.h"
+#import
+#import "Config.h"
+
+// æå¡id
+#define kServiceUUID @"FFF1"
+//aiç¹å¾
+#define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8"
+//é´æç¹å¾
+#define kAuthUUID @"0783B73E-8535-B5A0-7140-A304D2194CB7"
+//设å¤ä¿¡æ¯ç¹å¾
+#define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6"
+
+@interface BleManager ()
+@property(nonatomic, strong) CBCentralManager *centralManager;///èç管ç
+@property(nonatomic, strong) CBPeripheral *connectPeripheral;//è¿æ¥ç设å¤
+@property(nonatomic, strong) CBCharacteristic *authCha;//é´æç¹å¾
+@property(nonatomic, strong) CBCharacteristic *aiCha;//aiç¹å¾
+@property(nonatomic, strong) CBCharacteristic *deviceInfoCha;//设å¤ä¿¡æ¯ç¹å¾
+@property (nonatomic,strong) NSMutableData *recordData;//å½é³çæ°æ®
+@end
+
+@implementation BleManager
++(BleManager *)shared{
+ static BleManager *manager = nil;
+ static dispatch_once_t oncePredicate;
+ dispatch_once(&oncePredicate, ^{
+ manager = [[BleManager alloc]init];
+ });
+ return manager;
+}
+
+- (instancetype)init{
+ self = [super init];
+ if (self) {
+ self.centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
+ }
+ return self;
+}
+
+#pragma mark - CBCentralManagerDelegate
+- (void)centralManagerDidUpdateState:(nonnull CBCentralManager *)central {
+ [self showLog:[NSString stringWithFormat:@"èçç¶æ = %@",@(central.state)]];
+ switch (central.state) {
+ case CBManagerStateUnknown:
+
+ break;
+ case CBManagerStateResetting:
+
+ break;
+ case CBManagerStateUnsupported:
+
+ break;
+ case CBManagerStateUnauthorized:
+
+ break;
+ case CBManagerStatePoweredOff:
+
+ break;
+ case CBManagerStatePoweredOn:
+ [self autoConnectDevice];
+ break;
+ }
+}
+
+- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
+// [self showLog:[NSString stringWithFormat:@"æ«æå°è®¾å¤ = %@, data = %@",peripheral,advertisementData]];
+ if(self.discoverDevice){
+ self.discoverDevice(peripheral);
+ }
+}
+
+- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
+ [self showLog:[NSString stringWithFormat:@"è¿æ¥æå name = %@",peripheral.name]];
+ if(self.didConnectDevice){
+ self.didConnectDevice(peripheral);
+ }
+ peripheral.delegate = self;
+ [peripheral discoverServices:nil];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:kDidConnectBleNotification object:nil];
+}
+-(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
+ [self showLog:[NSString stringWithFormat:@"æå¼è¿æ¥ããã%@",error.description]];
+ [[NSNotificationCenter defaultCenter] postNotificationName:kDidDisconnectBleNotification object:nil];
+ if(self.didDisConnectDevice){
+ self.didDisConnectDevice(peripheral);
+ }
+ [self autoConnectDevice];
+}
+- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error{
+ [self showLog:[NSString stringWithFormat:@"è¿æ¥å¤±è´¥ããã%@",error.description]];
+}
+#pragma mark - CBPeripheralDelegate
+//åç°æå¡
+- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
+ for (CBService *service in peripheral.services){
+ [peripheral discoverCharacteristics:nil forService:service];
+ }
+}
+
+// åç°ç¹å¾
+- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
+ for (CBCharacteristic *characteristic in service.characteristics){
+ if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {
+ //é´æç¹å¾
+ self.authCha = characteristic;
+ [peripheral setNotifyValue:YES forCharacteristic:characteristic];
+ //忢代ç
+ [AiMouse shared].delegate = self;
+ //忢å½åè¿æ¥ç±»å
+ [[AiMouse shared] switchConnect:AiMouseConnectType_bluetooth];
+ //æ¾å°é´æç¹å¾åï¼ä¸å®è¦è°ç¨é´ææ¥å£å¼å§é´æãåªæé´æéè¿äºï¼sdkç¸å
³åè½æå¯ä»¥ä½¿ç¨
+ [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {
+ [self showLog:[NSString stringWithFormat:@"é´æç»æ = %@",@(state)]];
+ if(self.authCallBack){
+ self.authCallBack(state == AiMouseAuthState_Success);
+ }
+ }];
+ }
+ else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {
+ //AIç¹å¾
+ self.aiCha = characteristic;
+ [peripheral setNotifyValue:YES forCharacteristic:characteristic];
+ }
+ else if ([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]) {
+ //设å¤ä¿¡æ¯ç¹å¾
+ self.deviceInfoCha = characteristic;
+ [peripheral setNotifyValue:YES forCharacteristic:characteristic];
+ }
+ }
+}
+//æ¶å°èçæ°æ®
+- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
+ NSData *data = characteristic.value;
+ [self showLog:[NSString stringWithFormat:@"[receive] %@",[AiMouseTools dataToHexString:data]]];
+ if([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]){
+ //é´ææ°æ®
+ [[AiMouse shared] sendAuthDataToSdk:data];
+ }
+ else if([characteristic.UUID.UUIDString isEqualToString:kAiUUID]){
+ //AIæ°æ®
+ [[AiMouse shared] sendAiDataToSdk:data];
+ }
+ else if([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]){
+ //设å¤ä¿¡æ¯æ°æ®
+ [[AiMouse shared] sendDeviceDataToSdk:data];
+ }
+}
+
+#pragma mark - AiDelegate
+/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
+/// - Parameter data: æ°æ®
+- (void)aiMouseSendAuthData:(NSData *)data{
+ [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
+ [self.connectPeripheral writeValue:data forCharacteristic:self.authCha type:CBCharacteristicWriteWithoutResponse];
+}
+
+
+/// 设å¤ä¿¡æ¯æ°æ®åè°ï¼éè¦å°æ¤æ°æ®éè¿è®¾å¤ä¿¡æ¯ç¹å¾è½¬åç»èç设å¤
+/// - Parameter data: æ°æ®
+-(void)aiMouseSendDeviceInfoData:(NSData *)data{
+ [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
+ [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse];
+}
+
+/// é¼ æ æé®æä»¤åè°
+/// - Parameter data: æ°æ®ã
+/// å ç¬¬ä¸æ¬¡åå»31(å¼å§å½é³ï¼ï¼ ç¬¬äºæ¬¡åå»32(ç»æå½é³) ï¼ æä¸21ï¼å¼å§å½é³ï¼æ¬èµ·22(ç»æå½é³)
+/// ä¸ åå»42ï¼ æä¸25ï¼å¼å§å½é³ï¼æ¬èµ·26(ç»æå½é³)
+/// å åå»43ï¼æä¸27ï¼å¼å§å½é³ï¼æ¬èµ·28(ç»æå½é³)
+/// å
¶ä»æªå®ä¹
+- (void)aiMouseSendCmdData:(NSData *)data{
+ uint8 cmd;
+ [data getBytes:&cmd length:1];
+ [self showLog:[NSString stringWithFormat:@"æ¶å°æä»¤ = %X",cmd]];
+
+ if(cmd == 0x31 || cmd == 0x21 || cmd == 0x25 ||cmd == 0x27){
+ [self showLog:@"å¼å§å½é³"];
+ self.recordData = [[NSMutableData alloc] init];
+ }
+ else if(cmd == 0x32 || cmd == 0x22 || cmd == 0x26 ||cmd == 0x28){
+ [self showLog:@"ç»æå½é³"];
+ [self finishRecored:self.recordData];
+ }
+}
+
+/// å½é³åè°
+/// - Parameter data: pcmæ ¼å¼è¯é³æ°æ®
+- (void)aiMouseSendRecordData:(NSData *)data{
+ [self.recordData appendData:data];
+}
+
+#pragma mark - public
+/// è¿æ¥è®¾å¤
+- (void)startScanDevice{
+ [self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : [NSNumber numberWithBool:NO]}];
+}
+
+/// æ«æè®¾å¤
+- (void)stopScanDevice{
+ [self.centralManager stopScan];
+}
+
+/// è¿æ¥è®¾å¤
+- (void)connectPeripheral:(CBPeripheral *)peripheral{
+ self.connectPeripheral = peripheral;
+ [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey : [NSNumber numberWithBool:YES]}];
+}
+
+/// è·å设å¤ä¿¡æ¯
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{
+ [[AiMouse shared] getDeviceInfo:completation];
+}
+#pragma mark - other
+//èªå¨è¿æ¥ï¼è·åå·²é
对çèç,å第ä¸ä¸ªè¿æ¥
+- (void)autoConnectDevice{
+ //妿æ¯å·²è¿æ¥æè
æ£å¨è¿æ¥ï¼åä¸åéè¿
+ if (self.connectPeripheral && (self.connectPeripheral.state == CBPeripheralStateConnected || self.connectPeripheral.state == CBPeripheralStateConnecting)) {
+ return;
+ }
+ NSArray *devices = [self.centralManager retrieveConnectedPeripheralsWithServices:@[[CBUUID UUIDWithString:kServiceUUID]]];
+ if (devices.count > 0) {
+ CBPeripheral *peripheral = devices[0];
+ [self showLog:[NSString stringWithFormat:@"å¹é
è¿ç设å¤%@",peripheral.name]];
+ [self connectPeripheral:peripheral];
+ }
+ // 10sèªå¨éè¿
+ [self performSelector:@selector(autoConnectDevice) withObject:nil afterDelay:10];
+}
+- (void)showLog:(NSString *)log{
+ NSLog(@"%@",log);
+}
+
+//å°å½é³æ°æ®ä¿å
+- (void)finishRecored:(NSData *)data{
+ NSString *doc = NSTemporaryDirectory();
+ NSString *fullPath = [NSString stringWithFormat:@"%@1.pcm",doc];
+ NSError *err;
+ [data writeToFile:fullPath options:NSDataWritingAtomic error:&err];
+ if (err) {
+ [self showLog:[NSString stringWithFormat:@"å½é³ä¿å失败 %@",err.description]];
+ }
+ else{
+ [self showLog:[NSString stringWithFormat:@"å½é³ä¿åæå path = %@",fullPath]];
+ }
+}
+@end
+
+```
+
+
+
+## USB示ä¾
+
+â
+
+```objective-c
+//
+// HidManager.m
+// MouseSdk
+//
+// Created by incar on 2024/3/26.
+//
+
+#import "HidManager.h"
+#include
+#include
+#import
+#import "Config.h"
+
+//ä¾åºåid
+const long vendorID = 0x248a;
+//产åid
+const long productID = 0xca08;
+
+@interface HidManager ()
+
+@property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管ç
+@property(nonatomic, assign) IOHIDDeviceRef authCha;//é´æéé
+@property(nonatomic, assign) IOHIDDeviceRef aiCha;//aiéé
+@property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设å¤ä¿¡æ¯éé
+@property (nonatomic,strong) NSMutableData *recordData;//å½é³çæ°æ®
+@end
+
+@implementation HidManager
++(HidManager *)shared{
+ static HidManager *manager = nil;
+ static dispatch_once_t oncePredicate;
+ dispatch_once(&oncePredicate, ^{
+ manager = [[HidManager alloc]init];
+ });
+ return manager;
+}
+
+- (instancetype)init{
+ self = [super init];
+ if (self) {
+ [self initHid];
+ [self open];
+ }
+ return self;
+}
+
+- (void)initHid{
+
+}
+
+- (void)open{
+ self.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
+ IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
+ IOReturn ret = IOHIDManagerOpen(self.hidManager, 0L);
+ if (ret != kIOReturnSuccess) {
+ NSLog(@"æå¼è®¾å¤å¤±è´¥!");
+ }else{
+ NSLog(@"æå¼è®¾å¤æå!");
+ }
+ //设置å¹é
设å¤
+ NSMutableDictionary* dict= [NSMutableDictionary dictionary];
+ [dict setValue:[NSNumber numberWithLong:productID] forKey:[NSString stringWithCString:kIOHIDProductIDKey encoding:NSUTF8StringEncoding]];
+ [dict setValue:[NSNumber numberWithLong:vendorID] forKey:[NSString stringWithCString:kIOHIDVendorIDKey encoding:NSUTF8StringEncoding]];
+ IOHIDManagerSetDeviceMatching(self.hidManager, (__bridge CFMutableDictionaryRef)dict);
+ //设置å¹é
å°è®¾å¤åè°
+ IOHIDManagerRegisterDeviceMatchingCallback(self.hidManager, &hidAppearDevice, NULL);
+ //设置移é¤è®¾å¤åè°
+ IOHIDManagerRegisterDeviceRemovalCallback(self.hidManager, &hidDisAppearDevice, NULL);
+}
+
+- (void)close{
+ IOReturn ret = IOHIDManagerClose(self.hidManager, 0);
+ if (ret != kIOReturnSuccess) {
+ NSLog(@"å
³é设å¤å¤±è´¥!");
+ }else{
+ NSLog(@"å
³éè®¾å¤æå!");
+ }
+}
+
+#pragma mark - Hid CallBack
+/// å¹é
å°è®¾å¤åè°
+static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
+ uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));
+ uint32_t pid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey));
+ uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey));
+ uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey));
+ NSLog(@"vid = %u, pid = %u, PrimaryUsagePage = %u, PrimaryUsage = %u,",vid,pid,PrimaryUsagePage,PrimaryUsage);
+ NSLog(@"åç°è®¾å¤ %@\n ",inIOHIDDeviceRef);
+
+ // PrimaryUsagePage=1 PrimaryUsage=0,设å¤ä¿¡æ¯
+ // PrimaryUsagePage=1 PrimaryUsage=6,é´æ
+ // PrimaryUsagePage=65283 PrimaryUsage=0ï¼ai
+ if(PrimaryUsagePage == 1 && PrimaryUsage == 0){
+ //设å¤ä¿¡æ¯
+ [HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
+ //é´æ
+ [HidManager shared].authCha = inIOHIDDeviceRef;
+ //å¼å§é´æ
+ [[HidManager shared] startAuthentication];
+ }
+ else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){
+ //ai
+ [HidManager shared].aiCha = inIOHIDDeviceRef;
+ }
+ //æ³¨åæ¶æ¯åè°
+ unsigned char InputBuffer[128];
+ IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);
+}
+
+/// 设å¤ç§»é¤åè°
+static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
+ NSLog(@"æåºè®¾å¤ %@ ",inIOHIDDeviceRef);
+ uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey));
+ uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey));
+
+ if(PrimaryUsagePage == 1 && PrimaryUsage == 0){
+ [HidManager shared].connectStateCallBack(false);
+ }
+}
+
+static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){
+
+ [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] å¤çå %@",[AiMouseTools dataToHexString:[[NSData alloc] initWithBytes:report length:reportLength]]]];
+
+ NSInteger len = get_data_len(report, reportLength);
+ NSData *data = [[NSData alloc] initWithBytes:report length:len];
+ [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] å¤çå %@",[AiMouseTools dataToHexString:data]]];
+
+ uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey));
+ uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey));
+
+ if(PrimaryUsagePage == 1 && PrimaryUsage == 0){
+ [[HidManager shared] showLog:@"deviceæ°æ®"];
+ [[AiMouse shared] sendDeviceDataToSdk:data];
+ }
+ else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){
+ [[HidManager shared] showLog:@"AIæ°æ®"];
+ [[AiMouse shared] sendAiDataToSdk:data];
+ }
+}
+#pragma mark - AiDelegate
+/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
+/// - Parameter data: æ°æ®
+- (void)aiMouseSendAuthData:(NSData *)data{
+ [self sendData:data toDevice:self.authCha];
+}
+
+/// 设å¤ä¿¡æ¯æ°æ®åè°ï¼éè¦å°æ¤æ°æ®éè¿è®¾å¤ä¿¡æ¯ç¹å¾è½¬åç»èç设å¤
+/// - Parameter data: æ°æ®
+-(void)aiMouseSendDeviceInfoData:(NSData *)data{
+ [self sendData:data toDevice:self.deviceInfoCha];
+}
+
+/// é¼ æ æé®æä»¤åè°
+/// - Parameter data: æ°æ®ã
+/// å ç¬¬ä¸æ¬¡åå»31(å¼å§å½é³ï¼ï¼ ç¬¬äºæ¬¡åå»32(ç»æå½é³) ï¼ æä¸21ï¼å¼å§å½é³ï¼æ¬èµ·22(ç»æå½é³)
+/// ä¸ åå»42ï¼ æä¸25ï¼å¼å§å½é³ï¼æ¬èµ·26(ç»æå½é³)
+/// å åå»43ï¼æä¸27ï¼å¼å§å½é³ï¼æ¬èµ·28(ç»æå½é³)
+/// å
¶ä»æªå®ä¹
+- (void)aiMouseSendCmdData:(NSData *)data{
+ uint8 cmd;
+ [data getBytes:&cmd length:1];
+ [self showLog:[NSString stringWithFormat:@"æ¶å°æä»¤ = %X",cmd]];
+
+ if(cmd == 0x31 || cmd == 0x21 || cmd == 0x25 ||cmd == 0x27){
+ [self showLog:@"å¼å§å½é³"];
+ self.recordData = [[NSMutableData alloc] init];
+ }
+ else if(cmd == 0x32 || cmd == 0x22 || cmd == 0x26 ||cmd == 0x28){
+ [self showLog:@"ç»æå½é³"];
+ [self finishRecored:self.recordData];
+ }
+}
+/// å½é³åè°
+/// - Parameter data: pcmæ ¼å¼è¯é³æ°æ®
+- (void)aiMouseSendRecordData:(NSData *)data{
+ [self.recordData appendData:data];
+}
+
+#pragma mark - public
+-(void)startAuthentication{
+ //è¿ä¸è®¾å¤
+ [HidManager shared].connectStateCallBack(true);
+ //设置代ç
+ [AiMouse shared].delegate = self;
+ //忢å½åè¿æ¥ç±»å
+ [[AiMouse shared] switchConnect:AiMouseConnectType_hid];
+ //æ¾å°é´æç¹å¾åï¼ä¸å®è¦è°ç¨é´ææ¥å£å¼å§é´æãåªæé´æéè¿äºï¼sdkç¸å
³åè½æå¯ä»¥ä½¿ç¨
+ [self showLog:@"å¼å§é´æ"];
+ [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {
+ [self showLog:[NSString stringWithFormat:@"é´æç»æ = %@",@(state)]];
+ if(self.authCallBack){
+ self.authCallBack(state == AiMouseAuthState_Success);
+ }
+ }];
+}
+/// è·å设å¤ä¿¡æ¯
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{
+ [[AiMouse shared] getDeviceInfo:completation];
+}
+
+/// åéæ°æ®ç»è®¾å¤
+-(void)sendData:(NSData *)data toDevice:(IOHIDDeviceRef)device{
+ if(device == nil){
+ [self showLog:@"请å
è¿ä¸è®¾å¤"];
+ return;
+ }
+ [self showLog:[NSString stringWithFormat:@"å¼å§åé[send] %@\n%@",[AiMouseTools dataToHexString:data],[AiMouseTools dataToUtf8String:data]]];
+
+ IOReturn ret = IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 0, data.bytes, data.length);
+ if (ret != kIOReturnSuccess) {
+ [self showLog:[NSString stringWithFormat:@"åé失败! code = %d",ret]];
+ }else{
+ [self showLog:@"åéæå!"];
+ }
+}
+//å°å½é³æ°æ®ä¿å
+- (void)finishRecored:(NSData *)data{
+ NSString *doc = NSTemporaryDirectory();
+ NSString *fullPath = [NSString stringWithFormat:@"%@1.pcm",doc];
+ NSError *err;
+ [data writeToFile:fullPath options:NSDataWritingAtomic error:&err];
+ if (err) {
+ [self showLog:[NSString stringWithFormat:@"å½é³ä¿å失败 %@",err.description]];
+ }
+ else{
+ [self showLog:[NSString stringWithFormat:@"å½é³ä¿åæå path = %@",fullPath]];
+ }
+}
+- (void)showLog:(NSString *)log{
+ NSLog(@"%@",log);
+}
+
+/// å®é
å°æ°æ®é¿åº¦
+static inline int get_data_len(uint8_t *buf, u_long len) {
+ if (len <= 0 ) return 0;
+ int url_len = 0;
+ while (buf[url_len] != 0x00) url_len++;
+ return url_len;
+}
+
+/// è·å对åºå±æ§å¼
+static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStringRef inKey) {
+ uint32_t outValue = 0;
+ if (inIOHIDDeviceRef != NULL) {
+ CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, inKey);
+ if (tCFTypeRef != NULL && (CFNumberGetTypeID() == CFGetTypeID(tCFTypeRef)) ) {
+ Boolean result = CFNumberGetValue((CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, &outValue);
+ if (!result) {
+ NSLog(@"get %@ failed.", inKey);
+ }
+ }
+ }
+ return outValue;
+}
+@end
+
+```
## 注æäºé¡¹
-- é´ææ°æ®ä½¿ç¨çæ¯é´æç¹å¾ï¼èµ°é´ææ¥å£ï¼è®¾å¤ä¿¡æ¯æ°æ®ä½¿ç¨çæ¯è®¾å¤ä¿¡æ¯ç¹å¾ï¼èµ°è®¾å¤ä¿¡æ¯æ¥å£ï¼AIæ°æ®ä½¿ç¨çæ¯AIç¹å¾ï¼èµ°AIæ¥å£ã
-- åªæé´ææåäºä»¥åï¼AIç¸å
³åè½æå¯ç¨ãauthStateé´æç¶æ,é»è®¤æ¯Unknowãæä»¥å¿
é¡»å¨è¿ä¸èçè®¾å¤æ¾å°é´æç¹å¾åï¼éè¦ä¸»å¨è°ç¨startAuthenticationæ¹æ³å»é´æãï¼åªæé´ææåï¼AIé®ï¼è¯é³é®ãM鮿å¯ç¨ï¼
+- é´ææ°æ®ä½¿ç¨çæ¯é´æï¼èµ°é´ææ¥å£ï¼è®¾å¤ä¿¡æ¯æ°æ®ä½¿ç¨çæ¯è®¾å¤ä¿¡æ¯ééï¼èµ°è®¾å¤ä¿¡æ¯æ¥å£ï¼AIæ°æ®ä½¿ç¨çæ¯AIééï¼èµ°AIæ¥å£ã
+- åªæé´ææåäºä»¥åï¼AIç¸å
³åè½æå¯ç¨ãauthStateé´æç¶æ,é»è®¤æ¯Unknowãæä»¥å¿
é¡»å¨è¿ä¸èçè®¾å¤æ¾å°é´æç¹å¾åï¼éè¦ä¸»å¨è°ç¨startAuthenticationæ¹æ³å»é´æãï¼åªæé´ææåï¼AIåè½æå¯ç¨ï¼
- SDKåªå°è£
äºèçç¸å
³æ°æ®å¤çï¼APPèªå·±ç»´æ¤èç设å¤çæ«æè¿æ¥ãèç设å¤ä¸æ®µæ¶é´æ²¡æä»»ä½æä½çè¯ï¼ä¼èªå¨æå¼è¿æ¥ãAPPå¯ä»¥å¨æ£æµå°æå¼åéè¿ã
+- å½åæ¢èçæè
USBï¼éè¦è°ç¨switchConnectåæ¢è¿æ¥ç±»åã
diff --git a/MouseSdk/AiMouseSdk/AiAuthManager.m b/MouseSdk/AiMouseSdk/AiAuthManager.m
index 64b4276..0a9b99a 100644
--- a/MouseSdk/AiMouseSdk/AiAuthManager.m
+++ b/MouseSdk/AiMouseSdk/AiAuthManager.m
@@ -24,7 +24,7 @@
_bizbusManager.bleSendDataDelegate = self;
_bizbusManager.appVersion = @"--";
_bizbus_connect_queue = dispatch_queue_create("bizbus_connect_queue", DISPATCH_QUEUE_SERIAL);
- [self enableBizbusLog:true];
+ [self enableBizbusLog:false];
}
return self;
}
diff --git a/MouseSdk/AiMouseSdk/AiFrameManager.m b/MouseSdk/AiMouseSdk/AiFrameManager.m
index 056c7f8..db7dd64 100644
--- a/MouseSdk/AiMouseSdk/AiFrameManager.m
+++ b/MouseSdk/AiMouseSdk/AiFrameManager.m
@@ -7,6 +7,7 @@
#import "AiFrameManager.h"
#import "AiMouseTools.h"
+#import "AiMouseConfig.h"
@interface AiFrameManager()
@property (nonatomic,strong)NSMutableData *recvData;
@@ -14,14 +15,15 @@
@implementation AiFrameManager
- (void)didReceiveFrameData:(NSData *)data{
- NSString *str = [AiMouseTools dataToUtf8String:data];
- if ([str isEqualTo:@"-$$"]) {
+ NSString *str = [[AiMouseTools dataToHexString:data] uppercaseString];
+ [self showLog:[NSString stringWithFormat:@"åæ®µ = %@ å
容 = %@",str,[AiMouseTools dataToUtf8String:data]]];
+ if ([str hasPrefix:@"2D242400"]) {
//å¼å§
self.recvData = [[NSMutableData alloc] init];
}
- else if([str isEqualTo:@"$$-\n"]){
+ else if([str hasSuffix:@"24242D0A00"]){
NSString *str1 = [AiMouseTools dataToHexString:self.recvData];
- NSLog(@"æ¶å°å®æ´æ°æ® = %@",str1);
+ [self showLog:[NSString stringWithFormat:@"宿´æ°æ® = %@",str1]];
//ç»æ
if(self.didReceiveFullData){
self.didReceiveFullData(self.recvData);
@@ -29,27 +31,39 @@
}
else{
//æ°æ®
- [self.recvData appendData:data];
+ NSData *subData;
+ if([str hasSuffix:@"00"]){
+ subData = [data subdataWithRange:NSMakeRange(0, data.length - 1)];
+ }
+ else{
+ subData = data;
+ }
+ [self showLog:[NSString stringWithFormat:@"æ¼æ¥æ°æ® = %@",[AiMouseTools dataToHexString:subData]]];
+ [self.recvData appendData:subData];
}
}
- (void)didReceiveHidAuthData:(NSData *)data{
- NSString *str = [AiMouseTools dataToHexString:data];
- NSLog(@"æ¶å°æ°æ® = %@",str);
+ NSString *str = [[AiMouseTools dataToHexString:data] uppercaseString];
+ [self showLog:[NSString stringWithFormat:@"åæ®µ = %@ å
容 = %@",str,[AiMouseTools dataToUtf8String:data]]];
if ([str hasPrefix:@"2D2424"]) {
+ self.recvData = [[NSMutableData alloc] init];
//å¼å§
- NSData *subData = [data subdataWithRange:NSMakeRange(3, data.length - 4)];
- NSString *str1 = [AiMouseTools dataToHexString:subData];
- NSLog(@"宿¶æ°æ® = %@",str1);
- self.recvData = [[NSMutableData alloc] initWithData:subData];
+ NSData *subData = [data subdataWithRange:NSMakeRange(3, data.length - 3)];
+ if(subData.length > 0){
+ [self showLog:[NSString stringWithFormat:@"æ¼æ¥æ°æ® = %@",[AiMouseTools dataToHexString:subData]]];
+ [self.recvData appendData:subData];
+ }
+
}
else if([str hasSuffix:@"24242D0A"]){
- NSData *subData = [data subdataWithRange:NSMakeRange(0, data.length - 5)];
- NSString *str1 = [AiMouseTools dataToHexString:subData];
- NSLog(@"宿¶æ°æ® = %@",str1);
- [self.recvData appendData:subData];
- NSString *all = [AiMouseTools dataToUtf8String:self.recvData];
- NSLog(@"宿´æ°æ® %@\n %@",[AiMouseTools dataToHexString:self.recvData],all);
+ NSData *subData = [data subdataWithRange:NSMakeRange(0, data.length - 4)];
+ if(subData.length > 0){
+ [self showLog:[NSString stringWithFormat:@"æ¼æ¥æ°æ® = %@",[AiMouseTools dataToHexString:subData]]];
+ [self.recvData appendData:subData];
+ }
+ NSString *str1 = [AiMouseTools dataToHexString:self.recvData];
+ [self showLog:[NSString stringWithFormat:@"宿´æ°æ® = %@",str1]];
//ç»æ
if(self.didReceiveFullData){
self.didReceiveFullData(self.recvData);
@@ -57,10 +71,19 @@
}
else{
//æ°æ®
- NSData *subData = [data subdataWithRange:NSMakeRange(0, data.length - 1)];
- NSString *str1 = [AiMouseTools dataToHexString:subData];
- NSLog(@"宿¶æ°æ® = %@",str1);
- [self.recvData appendData:data];
+ NSData *subData;
+ if([str hasSuffix:@"00"]){
+ subData = [data subdataWithRange:NSMakeRange(0, data.length - 1)];
+ }
+ else{
+ subData = data;
+ }
+ [self showLog:[NSString stringWithFormat:@"æ¼æ¥æ°æ® = %@",[AiMouseTools dataToHexString:subData]]];
+ [self.recvData appendData:subData];
}
}
+
+- (void)showLog:(NSString *)log{
+ NSLog(@"%@",log);
+}
@end
diff --git a/MouseSdk/AiMouseSdk/AiMouse.h b/MouseSdk/AiMouseSdk/AiMouse.h
index a5e4b9b..c8f174b 100644
--- a/MouseSdk/AiMouseSdk/AiMouse.h
+++ b/MouseSdk/AiMouseSdk/AiMouse.h
@@ -47,7 +47,7 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) {
@property (nonatomic, readonly) NSString *version;/// çæ¬å·
@property (nonatomic, weak) id delegate;/// 代ç
@property (nonatomic, readonly) AiMouseConnectType connectType;//è¿æ¥ç±»å
-@property (nonatomic, readonly) AiMouseAuthState authState;/// é´æç¶æ,é»è®¤æ¯Unknowãæä»¥å¿
é¡»å¨è¿ä¸èçè®¾å¤æ¾å°é´æç¹å¾åï¼éè¦ä¸»å¨è°ç¨startAuthenticationæ¹æ³å»é´æãï¼åªæé´ææåï¼AIé®ï¼è¯é³é®ãM鮿å¯ç¨ï¼
+@property (nonatomic, readonly) AiMouseAuthState authState;/// é´æç¶æ,é»è®¤æ¯Unknowãæä»¥å¿
é¡»å¨è¿ä¸èçè®¾å¤æ¾å°é´æç¹å¾åï¼éè¦ä¸»å¨è°ç¨startAuthenticationæ¹æ³å»é´æãï¼åªæé´ææåï¼AIåè½æå¯ç¨ï¼
/// åå©
+(AiMouse *)shared;
diff --git a/MouseSdk/AiMouseSdk/AiMouse.m b/MouseSdk/AiMouseSdk/AiMouse.m
index 9a3f06b..0a98cb6 100644
--- a/MouseSdk/AiMouseSdk/AiMouse.m
+++ b/MouseSdk/AiMouseSdk/AiMouse.m
@@ -47,7 +47,7 @@
}
-(NSString *)version{
- return @"1.0.3";
+ return @"1.0.4";
}
-(AiFrameManager *)frameManager{
if (!_frameManager) {
@@ -279,8 +279,13 @@
}
}
- (void)sendDeviceInfoData:(NSData *)data{
+ NSString *str = [AiMouseTools dataToUtf8String:data];
+ NSMutableString *str1 = [NSMutableString stringWithString:str];
+ NSString *sendStr = [NSString stringWithFormat:@"-$$%@$$-\n",str1];
+ NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding];
+ [self showLog:[NSString stringWithFormat:@"åéç设å¤ä¿¡æ¯æ°æ® = %@",sendStr]];
if (self.delegate) {
- [self.delegate aiMouseSendDeviceInfoData:data];
+ [self.delegate aiMouseSendDeviceInfoData:sendData];
}
}
diff --git a/MouseSdk/AiMouseSdk/AiRecordManager.m b/MouseSdk/AiMouseSdk/AiRecordManager.m
index 5a6b216..b0c9e5f 100644
--- a/MouseSdk/AiMouseSdk/AiRecordManager.m
+++ b/MouseSdk/AiMouseSdk/AiRecordManager.m
@@ -127,7 +127,7 @@
}
- (void)openSettings{
- NSURL *url = [NSURL URLWithString:@""];
+// NSURL *url = [NSURL URLWithString:@""];
}
- (void)showLog:(NSString *)log{
diff --git a/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Mqtt/IotMqtt/IotMqttManager_C.swift b/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Mqtt/IotMqtt/IotMqttManager_C.swift
index ad8f245..d652003 100755
--- a/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Mqtt/IotMqtt/IotMqttManager_C.swift
+++ b/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Mqtt/IotMqtt/IotMqttManager_C.swift
@@ -161,6 +161,7 @@ class IotMqttManager_C: NSObject, SdkMqttService_C {
}
let legacyConfig = IotMqttLegacyConfig_C.init(productKey: config.productKey, deviceName: config.deviceName, password: config.password, timestamp: config.timestamp)
+// print("å¼å§è¯·æ±: clientId =\(legacyConfig.clientId) userName = \(legacyConfig.username) passWord = \(legacyConfig.password) url = \(config.server) port = \(config.port)")
let initSdk:() -> () = { [self] in
let result = mqttShared.mqttLegacyInit(legacyConfig.clientId, userName: legacyConfig.username, passWord: legacyConfig.password, hostUrl: config.server, port: config.port)
diff --git a/MouseSdk/MouseSdk.xcodeproj/project.pbxproj b/MouseSdk/MouseSdk.xcodeproj/project.pbxproj
index 2dc25fc..05904bf 100644
--- a/MouseSdk/MouseSdk.xcodeproj/project.pbxproj
+++ b/MouseSdk/MouseSdk.xcodeproj/project.pbxproj
@@ -273,6 +273,7 @@
18BF1E892B8362D300B8D90F /* AiMouseSdk.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiMouseSdk.h; sourceTree = ""; };
18BF8F4C2BA9A7A4008F6933 /* AiMouseDeviceInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiMouseDeviceInfo.h; sourceTree = ""; };
18BF8F4D2BA9A7A4008F6933 /* AiMouseDeviceInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiMouseDeviceInfo.m; sourceTree = ""; };
+ 18C31D6F2BBAA6CC0089D656 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; };
18CB080B2BA401D0005F5854 /* liblzma.5.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = liblzma.5.tbd; path = usr/lib/liblzma.5.tbd; sourceTree = SDKROOT; };
18CB08102BA40282005F5854 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = version.h; sourceTree = ""; };
18CB08112BA40282005F5854 /* buffersrc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = buffersrc.h; sourceTree = ""; };
@@ -511,6 +512,7 @@
18BF1DCC2B81AB7C00B8D90F /* MouseSdk */ = {
isa = PBXGroup;
children = (
+ 18C31D6F2BBAA6CC0089D656 /* Info.plist */,
18BF1E202B83066200B8D90F /* BleManager.h */,
18BF1E212B83066200B8D90F /* BleManager.m */,
1867E5A72BB2706F008FC5FB /* HidManager.h */,
@@ -1390,10 +1392,11 @@
"$(PROJECT_DIR)/framework",
);
GENERATE_INFOPLIST_FILE = YES;
- INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "è¦æå¼èçæè½ç»§ç»ä½¿ç¨APPå¦";
+ INFOPLIST_FILE = MouseSdk/Info.plist;
+ INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "è¦æå¼èçæè½ä½¿ç¨AIåè½å¦";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
- INFOPLIST_KEY_NSMicrophoneUsageDescription = "è¦æå¼éº¦å
飿è½ç»§ç»ä½¿ç¨APPå¦";
+ INFOPLIST_KEY_NSMicrophoneUsageDescription = "è¦æå¼éº¦å
飿è½ä½¿ç¨AIåè½å¦";
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
@@ -1427,10 +1430,11 @@
"$(PROJECT_DIR)/framework",
);
GENERATE_INFOPLIST_FILE = YES;
- INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "è¦æå¼èçæè½ç»§ç»ä½¿ç¨APPå¦";
+ INFOPLIST_FILE = MouseSdk/Info.plist;
+ INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "è¦æå¼èçæè½ä½¿ç¨AIåè½å¦";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
- INFOPLIST_KEY_NSMicrophoneUsageDescription = "è¦æå¼éº¦å
飿è½ç»§ç»ä½¿ç¨APPå¦";
+ INFOPLIST_KEY_NSMicrophoneUsageDescription = "è¦æå¼éº¦å
飿è½ä½¿ç¨AIåè½å¦";
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
index 1b585d5..ae341d2 100644
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index 8cf9284..b9bdb28 100644
--- a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -32,5 +32,68 @@
stopOnStyle = "0">
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MouseSdk/MouseSdk/HidManager.h b/MouseSdk/MouseSdk/HidManager.h
index c1e4e62..147e693 100644
--- a/MouseSdk/MouseSdk/HidManager.h
+++ b/MouseSdk/MouseSdk/HidManager.h
@@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation;
+/// é´æ
-(void)startAuthentication;
@end
diff --git a/MouseSdk/MouseSdk/HidManager.m b/MouseSdk/MouseSdk/HidManager.m
index 838d5d1..c164014 100644
--- a/MouseSdk/MouseSdk/HidManager.m
+++ b/MouseSdk/MouseSdk/HidManager.m
@@ -8,16 +8,20 @@
#import "HidManager.h"
#include
#include
-
#import
#import "Config.h"
+//ä¾åºåid
+const long vendorID = 0x248a;
+//产åid
+const long productID = 0xca08;
+
@interface HidManager ()
@property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管ç
-@property(nonatomic, assign) IOHIDDeviceRef authCha;//é´æç¹å¾
-@property(nonatomic, assign) IOHIDDeviceRef aiCha;//aiç¹å¾
-@property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设å¤ä¿¡æ¯ç¹å¾
+@property(nonatomic, assign) IOHIDDeviceRef authCha;//é´æéé
+@property(nonatomic, assign) IOHIDDeviceRef aiCha;//aiéé
+@property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设å¤ä¿¡æ¯éé
@property (nonatomic,strong) NSMutableData *recordData;//å½é³çæ°æ®
@end
@@ -53,15 +57,14 @@
}else{
NSLog(@"æå¼è®¾å¤æå!");
}
-
- const long vendorID = 0x248a;
- const long productID = 0xca08;
+ //设置å¹é
设å¤
NSMutableDictionary* dict= [NSMutableDictionary dictionary];
[dict setValue:[NSNumber numberWithLong:productID] forKey:[NSString stringWithCString:kIOHIDProductIDKey encoding:NSUTF8StringEncoding]];
[dict setValue:[NSNumber numberWithLong:vendorID] forKey:[NSString stringWithCString:kIOHIDVendorIDKey encoding:NSUTF8StringEncoding]];
IOHIDManagerSetDeviceMatching(self.hidManager, (__bridge CFMutableDictionaryRef)dict);
-
+ //设置å¹é
å°è®¾å¤åè°
IOHIDManagerRegisterDeviceMatchingCallback(self.hidManager, &hidAppearDevice, NULL);
+ //设置移é¤è®¾å¤åè°
IOHIDManagerRegisterDeviceRemovalCallback(self.hidManager, &hidDisAppearDevice, NULL);
}
@@ -75,6 +78,7 @@
}
#pragma mark - Hid CallBack
+/// å¹é
å°è®¾å¤åè°
static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));
uint32_t pid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey));
@@ -91,22 +95,19 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH
[HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
//é´æ
[HidManager shared].authCha = inIOHIDDeviceRef;
+ //å¼å§é´æ
[[HidManager shared] startAuthentication];
}
- else if(PrimaryUsagePage == 1 && PrimaryUsage == 6){
-// //é´æ
-// [HidManager shared].authCha = inIOHIDDeviceRef;
-// [[HidManager shared] startAuthentication];
- }
else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){
//ai
[HidManager shared].aiCha = inIOHIDDeviceRef;
}
-
+ //æ³¨åæ¶æ¯åè°
unsigned char InputBuffer[128];
IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);
}
+/// 设å¤ç§»é¤åè°
static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {
NSLog(@"æåºè®¾å¤ %@ ",inIOHIDDeviceRef);
uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey));
@@ -118,9 +119,12 @@ static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,
}
static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){
+
+ [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] å¤çå %@",[AiMouseTools dataToHexString:[[NSData alloc] initWithBytes:report length:reportLength]]]];
+
NSInteger len = get_data_len(report, reportLength);
NSData *data = [[NSData alloc] initWithBytes:report length:len];
- [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] = %@",[AiMouseTools dataToHexString:data]]];
+ [[HidManager shared] showLog:[NSString stringWithFormat:@"[receive] å¤çå %@",[AiMouseTools dataToHexString:data]]];
uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey));
uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey));
@@ -134,21 +138,6 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
[[AiMouse shared] sendAiDataToSdk:data];
}
}
-
-static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStringRef inKey) {
- uint32_t outValue = 0;
- if (inIOHIDDeviceRef != NULL) {
- CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, inKey);
- if (tCFTypeRef != NULL && (CFNumberGetTypeID() == CFGetTypeID(tCFTypeRef)) ) {
- Boolean result = CFNumberGetValue((CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, &outValue);
- if (!result) {
- NSLog(@"get %@ failed.", inKey);
- }
- }
- }
-
- return outValue;
-}
#pragma mark - AiDelegate
/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
/// - Parameter data: æ°æ®
@@ -156,7 +145,6 @@ static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStr
[self sendData:data toDevice:self.authCha];
}
-
/// 设å¤ä¿¡æ¯æ°æ®åè°ï¼éè¦å°æ¤æ°æ®éè¿è®¾å¤ä¿¡æ¯ç¹å¾è½¬åç»èç设å¤
/// - Parameter data: æ°æ®
-(void)aiMouseSendDeviceInfoData:(NSData *)data{
@@ -191,7 +179,9 @@ static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStr
#pragma mark - public
-(void)startAuthentication{
+ //è¿ä¸è®¾å¤
[HidManager shared].connectStateCallBack(true);
+ //设置代ç
[AiMouse shared].delegate = self;
//忢å½åè¿æ¥ç±»å
[[AiMouse shared] switchConnect:AiMouseConnectType_hid];
@@ -209,6 +199,7 @@ static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStr
[[AiMouse shared] getDeviceInfo:completation];
}
+/// åéæ°æ®ç»è®¾å¤
-(void)sendData:(NSData *)data toDevice:(IOHIDDeviceRef)device{
if(device == nil){
[self showLog:@"请å
è¿ä¸è®¾å¤"];
@@ -240,6 +231,7 @@ static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStr
NSLog(@"%@",log);
}
+/// å®é
å°æ°æ®é¿åº¦
static inline int get_data_len(uint8_t *buf, u_long len) {
if (len <= 0 ) return 0;
int url_len = 0;
@@ -247,4 +239,18 @@ static inline int get_data_len(uint8_t *buf, u_long len) {
return url_len;
}
+/// è·å对åºå±æ§å¼
+static uint32_t IOHIDDevGetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStringRef inKey) {
+ uint32_t outValue = 0;
+ if (inIOHIDDeviceRef != NULL) {
+ CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, inKey);
+ if (tCFTypeRef != NULL && (CFNumberGetTypeID() == CFGetTypeID(tCFTypeRef)) ) {
+ Boolean result = CFNumberGetValue((CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, &outValue);
+ if (!result) {
+ NSLog(@"get %@ failed.", inKey);
+ }
+ }
+ }
+ return outValue;
+}
@end
diff --git a/MouseSdk/MouseSdk/Info.plist b/MouseSdk/MouseSdk/Info.plist
new file mode 100644
index 0000000..0c67376
--- /dev/null
+++ b/MouseSdk/MouseSdk/Info.plist
@@ -0,0 +1,5 @@
+
+
+
+
+