From: liangzhenying <867174124@qq.com> Date: Thu, 26 Dec 2024 03:52:30 +0000 (+0800) Subject: 字节sdk鉴权调试 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=3641dbb9064b3389a3622cce566924ea430c93dd;p=mirrors%2FMouseSdk-MacOS.git 字节sdk鉴权调试 --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj index cf220de..c9429ee 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj +++ b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj @@ -433,6 +433,10 @@ 3FCF53502D1A5C97007EC52F /* LogManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FCF534D2D1A5C97007EC52F /* LogManager.h */; }; 3FCF53512D1A5C97007EC52F /* LogManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FCF534D2D1A5C97007EC52F /* LogManager.h */; }; 3FCF53522D1A5C97007EC52F /* LogManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FCF534E2D1A5C97007EC52F /* LogManager.m */; }; + 3FCF53552D1A8DBA007EC52F /* AiMouseSdk1.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FCF53542D1A8DBA007EC52F /* AiMouseSdk1.m */; }; + 3FCF53562D1A8DBA007EC52F /* AiMouseSdk1.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FCF53532D1A8DBA007EC52F /* AiMouseSdk1.h */; }; + 3FCF53572D1A8DBA007EC52F /* AiMouseSdk1.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FCF53532D1A8DBA007EC52F /* AiMouseSdk1.h */; }; + 3FCF53582D1A8DBA007EC52F /* AiMouseSdk1.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FCF53542D1A8DBA007EC52F /* AiMouseSdk1.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -657,9 +661,11 @@ 18EF7AF62C7603E800AC5223 /* TlwConnectManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TlwConnectManager.h; sourceTree = ""; }; 18FCA3952C7F2AD100C44A37 /* AiMouseAuth.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiMouseAuth.h; sourceTree = ""; }; 18FCA3962C7F2AD100C44A37 /* AiMouseAuth.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiMouseAuth.m; sourceTree = ""; }; - 3FCF534C2D1A4E38007EC52F /* libAiMouseSdk copy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libAiMouseSdk copy.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 3FCF534C2D1A4E38007EC52F /* libAiMouseSdk copy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libAiMouseSdk copy.a"; path = "/Users/yaozuopan/Documents/code/MouseSdk-MacOS/MouseSdk/AiMouseSdk/build/Debug/libAiMouseSdk copy.a"; sourceTree = ""; }; 3FCF534D2D1A5C97007EC52F /* LogManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogManager.h; sourceTree = ""; }; 3FCF534E2D1A5C97007EC52F /* LogManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LogManager.m; sourceTree = ""; }; + 3FCF53532D1A8DBA007EC52F /* AiMouseSdk1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiMouseSdk1.h; sourceTree = ""; }; + 3FCF53542D1A8DBA007EC52F /* AiMouseSdk1.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AiMouseSdk1.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -721,7 +727,6 @@ 180E7AA82BD7BB12008558E8 /* AiMouseSdk */, 180E7AA72BD7BB12008558E8 /* Products */, 180E7D092BD8FEB2008558E8 /* Frameworks */, - 3FCF534C2D1A4E38007EC52F /* libAiMouseSdk copy.a */, ); sourceTree = ""; }; @@ -740,6 +745,8 @@ 180E7BF62BD8FC4E008558E8 /* ffmpeg */, 180E7AA92BD7BB12008558E8 /* AiMouseSdk.h */, 180E7AAB2BD7BB12008558E8 /* AiMouseSdk.m */, + 3FCF53532D1A8DBA007EC52F /* AiMouseSdk1.h */, + 3FCF53542D1A8DBA007EC52F /* AiMouseSdk1.m */, 180E7B472BD7BD7F008558E8 /* AiAuthManager.h */, 180E7B522BD7BD82008558E8 /* AiAuthManager.m */, 188814BB2C85BB76009299A9 /* AiBkzhAuthManager.h */, @@ -1284,6 +1291,7 @@ 180E7CA22BD8FC4E008558E8 /* frame.h in Headers */, 180E7CB32BD8FC4E008558E8 /* sha512.h in Headers */, 180E7C952BD8FC4E008558E8 /* samplefmt.h in Headers */, + 3FCF53562D1A8DBA007EC52F /* AiMouseSdk1.h in Headers */, 180E7C8E2BD8FC4E008558E8 /* fifo.h in Headers */, 180E7CC72BD8FC4E008558E8 /* cpu.h in Headers */, 180E7CF22BD8FC4F008558E8 /* d3d11va.h in Headers */, @@ -1378,6 +1386,7 @@ 18862B512C806BD900D3564D /* rational.h in Headers */, 18862B522C806BD900D3564D /* TlwTools.h in Headers */, 18862B532C806BD900D3564D /* codec_id.h in Headers */, + 3FCF53572D1A8DBA007EC52F /* AiMouseSdk1.h in Headers */, 18862B542C806BD900D3564D /* avconfig.h in Headers */, 18862B552C806BD900D3564D /* avassert.h in Headers */, 18862B562C806BD900D3564D /* channel_layout.h in Headers */, @@ -1572,6 +1581,7 @@ 18EF7AFC2C7603E800AC5223 /* TlwConnectManager.m in Sources */, 181CE5C22C6EED9900EF8D07 /* AiAliAuthManager.m in Sources */, 18D57A032C917385003D5714 /* NMouseSdk.m in Sources */, + 3FCF53552D1A8DBA007EC52F /* AiMouseSdk1.m in Sources */, 184A710D2BDA4C050025A332 /* AFSecurityPolicy.m in Sources */, 18862A272C8064E300D3564D /* DeviceManger.m in Sources */, 180E7B552BD7BD83008558E8 /* AiAudioDecoder.m in Sources */, @@ -1596,6 +1606,7 @@ 18862BB42C806BD900D3564D /* AiSender.m in Sources */, 18862BB52C806BD900D3564D /* AiTrippleModel.m in Sources */, 18862BB62C806BD900D3564D /* AiMouseSdk.m in Sources */, + 3FCF53582D1A8DBA007EC52F /* AiMouseSdk1.m in Sources */, 188814912C85766B009299A9 /* AiDeviceAuthManager.m in Sources */, 18862BB82C806BD900D3564D /* AFHTTPSessionManager.m in Sources */, 18862BB92C806BD900D3564D /* AiMouseTools.m in Sources */, diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index 6349347..27157b9 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ AiMouseSdk copy.xcscheme_^#shared#^_ orderHint - 3 + 4 AiMouseSdk.xcscheme_^#shared#^_ diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h index 2a000a4..2351512 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic,strong)void (^outputLogBlock)(NSString *log); @property (nonatomic,strong)void (^timeOutBlock)(void); --(void)receiveData:(NSData *)data; +-(BOOL)receiveData:(NSData *)data; /// 获取版本 - (void)getVersion:(void (^)(NSString *version,NSError *error))finished; diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m index 6327f55..2cce84d 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m @@ -56,9 +56,9 @@ @implementation AiDeviceInfoManager --(void)receiveData:(NSData *)data{ +-(BOOL)receiveData:(NSData *)data{ if(![self.sender isAnswer:data]){ - return; + return false; } AiSender *sender = self.sender; @@ -89,7 +89,7 @@ } } //鼠标移动数据,不处理 - return; + return true; } // [self showLog:[NSString stringWithFormat:@"总data = %@",[AiMouseTools dataToHexString:data]]]; @@ -101,6 +101,7 @@ else{ [self getCmdCallBack:dict]; } + return true; } - (void)setCmdCallBack:(NSDictionary *)dict sender:(AiSender *)sender{ @@ -275,6 +276,10 @@ self.deviceInfo.type = 0; self.deviceInfoBlock = complete; [self sendDeviceInfoCmd:@{kCmd_Key:@"get_battery_power"}]; + +// [self sendDeviceInfoCmd:@{@"cmd":@"set_config", +// @"set_VMouse_MAC":@"C0:31:00:00:A5:83" +// }]; } diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h index fad4a25..896e6a8 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h @@ -7,6 +7,13 @@ #import +@interface ByteDanceInfo : NSObject +@property (nonatomic, strong) NSString *expireTime; +@property (nonatomic, strong) NSString *token; +@property (nonatomic, strong) NSString *host; +@property (nonatomic, strong) NSString *urlParams; +@end + @interface AiMouseDeviceInfo : NSObject @property (nonatomic, assign) int type;/// 产品类型,0鼠标,1键盘 @@ -17,6 +24,7 @@ @property (nonatomic, strong) NSString *brand;/// 品牌名称 @property (nonatomic, strong) NSString *sn;/// 设备序列号 @property (nonatomic, strong) NSString *mac;///设备MAC地址 +@property (nonatomic, strong) ByteDanceInfo *byteAuthInfo;///字节鉴权信息,只有字节sdk该字段才会有值 @end typedef NS_ENUM(NSInteger,AiMouseErrorCode) { @@ -162,4 +170,7 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) { /// 关闭录音 /// - finished: 执行结果回调 - (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished; + + +- (void)sendToBle:(NSData *)data; @end diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index e3c303e..fb64d88 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -18,6 +18,11 @@ #import "AiMouseConfig.h" #import "AiRecordManager.h" +#import "ByteDanceSdk.h" +#import "DeviceManger.h" + +@implementation ByteDanceInfo +@end @interface AiMouseDeviceInfo() @property (nonatomic, strong) NSString *productKey;/// 品牌key @@ -26,13 +31,14 @@ @end @implementation AiMouseDeviceInfo -(NSString *)description{ - NSString *info = [NSString stringWithFormat:@"\n type = %d \n battery_power = %@\n CPI = %@\n CPI_list = %@\n version = %@\n brand = %@\n sn = %@\n mac = %@\n productKey = %@\n secretKey = %@\n deviceSecret = %@ ",self.type,self.battery_power,self.CPI,self.CPI_list,self.version,self.brand,self.sn,self.mac,self.productKey,self.secretKey,self.deviceSecret]; + NSString *info = [NSString stringWithFormat:@"\n type = %d \n battery_power = %@\n CPI = %@\n CPI_list = %@\n version = %@\n brand = %@\n sn = %@\n mac = %@\n productKey = %@\n secretKey = %@\n deviceSecret = %@ \n\n host = %@ \n token = %@ \n urlParams = %@ \n expireTime = %@ ",self.type,self.battery_power,self.CPI,self.CPI_list,self.version,self.brand,self.sn,self.mac,self.productKey,self.secretKey,self.deviceSecret,self.byteAuthInfo.host,self.byteAuthInfo.token,self.byteAuthInfo.urlParams,self.byteAuthInfo.expireTime]; return info; } @end @interface AiMouse() +@property (nonatomic, strong) ByteDanceSdk *byteSdk; @property (nonatomic, strong) AiAudioManager *audioManager; @property (nonatomic, strong) AiRecordManager *recordManager; @property (nonatomic, strong) void (^authBlock)(AiMouseAuthState state); @@ -55,6 +61,12 @@ if (self = [super init]) { _connectType = AiMouseConnectType_bluetooth; [self.recordManager checkPermissions]; + + if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) { + self.byteSdk = [ByteDanceSdk shared]; + [self.byteSdk initSdk]; + } + } return self; } @@ -122,7 +134,15 @@ [self.recordManager checkPermissions]; } if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:self.connected]; - [self checkAuthState]; + + if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) { + [self.byteSdk startAuth:^(ByteDanceInfo *info) { + if(self.delegate) [self.delegate aiMouseAuthenticationResult:AiMouseAuthState_Success]; + }]; + } + else{ + if(self.delegate) [self.delegate aiMouseAuthenticationResult:AiMouseAuthState_Success]; + } } else{ if (self.connected) { @@ -134,7 +154,7 @@ } - (void)sendAiDataToSdk:(NSData *)data{ -// [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; + [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; if(self.connectType == AiMouseConnectType_hid){ // 0AFFFF12BC32 @@ -179,26 +199,33 @@ if (data.length == 0 || (data.length == 6 && [[AiMouseTools dataToHexString:data] hasSuffix:@"f77f"])) { [self showLog:[NSString stringWithFormat:@"[receive][info] %@",data]]; [self showLog:@"收到异常数据!!!"]; -// [self switchConnect:self.connectType isConnected:false]; return; } [self showLog:[NSString stringWithFormat:@"[receive][info][json] %@",[AiMouseTools dataToHexString:data]]]; [self showLog:[NSString stringWithFormat:@"[receive][info][byte] %@",[AiMouseTools dataToUtf8String:data]]]; - if (self.connected == false) { - if([AiMouseTools dataToHexString:data].length < 10){ -// [self switchConnect:AiMouseConnectType_hid isConnected:false ]; - if (self.delegate && [self.delegate respondsToSelector:@selector(aiMouseHidDataError)]) [self.delegate aiMouseHidDataError]; - return; + + + if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) { + if([self.deviceInfoManager receiveData:data]){ + } + else{ + [self.byteSdk sendToSdk:data]; + } + } + else{ + [self.deviceInfoManager receiveData:data]; } - [self.deviceInfoManager receiveData:data]; } - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{ __weak typeof(self) ws = self; [self.deviceInfoManager getDeviceInfo:^(AiMouseDeviceInfo * _Nonnull deviceInfo, NSError * _Nonnull error) { + if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) { + deviceInfo.byteAuthInfo = ws.byteSdk.info; + } complete(deviceInfo,error); if (error != nil) { [ws switchConnect:ws.connectType isConnected:false]; @@ -303,9 +330,6 @@ } } -- (void)checkAuthState{ - if(self.delegate) [self.delegate aiMouseAuthenticationResult:AiMouseAuthState_Success]; -} #pragma mark - deviceInfo - (void)startRecord{ // [self showLog:@"开始录音"]; @@ -322,5 +346,12 @@ // [self showLog:@"结束录音"]; } + +- (void)sendToBle:(NSData *)data{ + [self showLog:[NSString stringWithFormat:@"[send][info][byte] %@",[AiMouseTools dataToHexString:data]]]; + if (self.delegate) { + [self.delegate aiMouseSendDeviceInfoData:data]; + }; +} @end diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk1.h b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk1.h new file mode 100644 index 0000000..cfe7538 --- /dev/null +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk1.h @@ -0,0 +1,165 @@ +//// +//// AiMouseSdk.h +//// AiMouseSdk +//// +//// Created by incar on 2024/4/23. +//// +// +//#import +// +//@interface AiMouseDeviceInfo : NSObject +//@property (nonatomic, assign) int type;/// 产品类型,0鼠标,1键盘 +// +//@property (nonatomic, strong) NSString *battery_power;/// 电池百分百电量,0-100 +//@property (nonatomic, strong) NSString *CPI;/// CPI值 +//@property (nonatomic, strong) NSString *CPI_list;/// 可设置的CPI参数列表 +//@property (nonatomic, strong) NSString *version;///软件版本 +//@property (nonatomic, strong) NSString *brand;/// 品牌名称 +//@property (nonatomic, strong) NSString *sn;/// 设备序列号 +//@property (nonatomic, strong) NSString *mac;///设备MAC地址 +//@end +// +//typedef NS_ENUM(NSInteger,AiMouseErrorCode) { +// AiMouseErrorCode_timeOut = 1001,///请求超时 +// AiMouseErrorCode_busy = 1002,/// 繁忙,有命令未执行完 +// AiMouseErrorCode_unknown = 1003,/// 未知错误 +//}; +// +//typedef NS_ENUM(NSInteger,AiMouseConnectType) { +// AiMouseConnectType_bluetooth = 0,///蓝牙 +// AiMouseConnectType_hid = 1,///hid +//}; +// +//typedef NS_ENUM(NSInteger,AiMouseAuthState) { +// AiMouseAuthState_Unknow = 0,///未知 +// AiMouseAuthState_Success,///鉴权成功 +// AiMouseAuthState_Failure///鉴权失败 +//}; +// +//@protocol AiMouseDelegate +// +///// 设备连接状态 +///// - Parameter connected: 是否连接 +//- (void)aiMouseConnectStateDidChange:(BOOL)connected; +// +///// 鉴权结果返回 +///// - Parameter authState: 鉴权状态 +//- (void)aiMouseAuthenticationResult:(AiMouseAuthState)authState; +// +///// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 +///// - Parameter data: 数据 +//- (void)aiMouseSendDeviceInfoData:(NSData *)data; +// +///// 鼠标按键指令回调 +///// - Parameter data: 数据。 +///// 前 第一次单击31(开始录音), 第二次单击32(结束录音) , 按下21(开始录音)抬起22(结束录音) +///// 中 单击42, 按下25(开始录音)抬起26(结束录音) +///// 后 单击43,按下27(开始录音)抬起28(结束录音) +///// 其他未定义 +//- (void)aiMouseSendCmdData:(NSData *)data; +// +///// 录音回调 +///// - Parameter data: pcm格式语音数据 +//- (void)aiMouseSendRecordData:(NSData *)data; +// +///// hid数据异常,需要重新开启监听usb设备 +//- (void)aiMouseHidDataError; +// +///// 输出sdk日志 +///// - Parameter log: 日志 +//- (void)aiMouseAddLog:(NSString *)log; +// +//@end +// +//@interface AiMouse : NSObject +//@property (nonatomic, weak) id delegate;/// 代理 +//@property (nonatomic, readonly) AiMouseConnectType connectType;//连接类型 +//@property (nonatomic, assign) BOOL connected;//是否已连接 +// +///// 单利 +//+(AiMouse *)shared; +// +// +///// 断开连接 +//- (void)didDisconnect; +// +///// 切换连接类型 +///// - Parameter type: 连接类型 +//- (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted; +// +///// 传输业务数据给sdk +///// - Parameter data:ai特征传过来的数据 +//- (void)sendAiDataToSdk:(NSData *)data; +// +///// 传输设备信息数据给sdk +///// - Parameter data:设备信息特征传过来的数据 +//- (void)sendDeviceDataToSdk:(NSData *)data; +// +///// 获取设备信息 +///// - Parameter completation: 如果获取成功,则deviceInfo有值,否则为nil +//- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete; +// +///// 获取信号强度 +///// - Parameter completation: 信号强度回调,如果获取成功,则value有值,否则为nil +//- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete; +// +///// 设置品牌名称 +///// - Parameters: +///// - value: 品牌名称 +///// - finished: 设置结果回调 +//- (void)setBrand:(NSString *)brand completation:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 设置CPI +///// - Parameters: +///// - value: AiMouseDeviceInfo 中可以设置的值CPI_list +///// - finished: 设置结果回调 +//- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 设置录音模式 +///// - Parameters: +///// - value: 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音 +///// - finished: 设置结果回调 +//- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 设置长按滚轮弹出的网页地址 +///// - Parameters: +///// - url: 最大长度:49字节 +///// - finished: 设置结果回调 +//- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 设置长按滚轮弹出网页开关 +///// - Parameters: +///// - state: 0关闭,1打开 +///// - finished: 设置结果回调 +//- (void)setUrlState:(int)state completation:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 设置鼠标连接模式 +///// - Parameters: +///// - mode: 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式 +///// - finished: 设置结果回调 +//- (void)setMouseMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 获取录音模式 +///// - Parameter complete: mode 0:常规模式,按按键打开关闭录音 1:命令模式,发命令打开关闭录音 。error为nil才代表获取成功 +//- (void)getRecordMode:(void (^)(int mode,NSError *error))complete; +// +///// 获取长按滚轮弹出的网页地址 +///// - Parameter complete: url地址 。error为nil才代表获取成功 +//- (void)getUrl:(void (^)(NSString *url,NSError *error))complete; +// +///// 获取长按滚轮弹出的网页地址开关状态 +///// - Parameter complete: state 0关闭,1打开。 error为nil才代表获取成功 +//- (void)getUrlState:(void (^)(int state,NSError *error))complete; +// +///// 获取鼠标连接模式 +///// - Parameter complete: mode 0:2.4G模式,1:蓝牙1模式,2:蓝牙2模式 。error为nil才代表获取成功 +//- (void)getMouseModel:(void (^)(int mode,NSError *error))complete; +// +///// 打开录音 +///// - finished: 执行结果回调 +//- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished; +// +///// 关闭录音 +///// - finished: 执行结果回调 +//- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished; +//@end diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk1.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk1.m new file mode 100644 index 0000000..b61e522 --- /dev/null +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk1.m @@ -0,0 +1,326 @@ +//// +//// AiMouseSdk.m +//// AiMouseSdk +//// +//// Created by incar on 2024/4/23. +//// +// +//#import "AiMouseSdk.h" +// +//#import "AiAuthManager.h" +//#import "AiAliAuthManager.h" +//#import "AiBkzhAuthManager.h" +// +//#import "AiDeviceInfoManager.h" +//#import "AiAudioManager.h" +//#import "AiMouseTools.h" +//#import "AiMouseTools2.h" +//#import "AiMouseConfig.h" +//#import "AiRecordManager.h" +// +// +//@interface AiMouseDeviceInfo() +//@property (nonatomic, strong) NSString *productKey;/// 品牌key +//@property (nonatomic, strong) NSString *secretKey;/// 品牌Secret +//@property (nonatomic, strong) NSString *deviceSecret;///设备Secret +//@end +//@implementation AiMouseDeviceInfo +//-(NSString *)description{ +// NSString *info = [NSString stringWithFormat:@"\n type = %d \n battery_power = %@\n CPI = %@\n CPI_list = %@\n version = %@\n brand = %@\n sn = %@\n mac = %@\n productKey = %@\n secretKey = %@\n deviceSecret = %@ ",self.type,self.battery_power,self.CPI,self.CPI_list,self.version,self.brand,self.sn,self.mac,self.productKey,self.secretKey,self.deviceSecret]; +// return info; +//} +//@end +// +//@interface AiMouse() +// +//@property (nonatomic, strong) AiAudioManager *audioManager; +//@property (nonatomic, strong) AiRecordManager *recordManager; +//@property (nonatomic, strong) void (^authBlock)(AiMouseAuthState state); +//@property (nonatomic, strong) AiDeviceInfoManager *deviceInfoManager; +//@property (nonatomic, strong) NSString *updateDeviceSecret;//更新的deviceSecret +// +//@end +// +//@implementation AiMouse +//+(AiMouse *)shared{ +// static AiMouse *manager = nil; +// static dispatch_once_t oncePredicate; +// dispatch_once(&oncePredicate, ^{ +// manager = [[AiMouse alloc]init]; +// }); +// return manager; +//} +// +//-(instancetype)init{ +// if (self = [super init]) { +// _connectType = AiMouseConnectType_bluetooth; +// [self.recordManager checkPermissions]; +// } +// return self; +//} +// +// +//-(AiDeviceInfoManager *)deviceInfoManager{ +// if (!_deviceInfoManager) { +// _deviceInfoManager = [[AiDeviceInfoManager alloc] init]; +// __weak typeof(self) ws = self; +// _deviceInfoManager.sendToBleBlock = ^(NSData * _Nonnull data) { +// if (ws.delegate) { +// [ws showLog:[NSString stringWithFormat:@"[send][info][json] %@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]]]; +// [ws showLog:[NSString stringWithFormat:@"[send][info][byte] %@",[AiMouseTools dataToHexString:data]]]; +// [ws.delegate aiMouseSendDeviceInfoData:data]; +// } +// }; +// _deviceInfoManager.outputLogBlock = ^(NSString * _Nonnull log) { +// [ws showLog:log]; +// }; +// _deviceInfoManager.timeOutBlock = ^{ +// [ws switchConnect:ws.connectType isConnected:false]; +// }; +// } +// return _deviceInfoManager;; +//} +// +//-(AiAudioManager *)audioManager{ +// if (!_audioManager) { +// _audioManager = [[AiAudioManager alloc] init]; +// __weak typeof(self) ws = self; +// _audioManager.decodeCallBack = ^(NSData * _Nonnull data) { +// [ws sendRecordData:data]; +// }; +// _audioManager.outputLog = ^(NSString * _Nonnull log) { +// [ws showLog:log]; +// }; +// } +// return _audioManager; +//} +// +//- (AiRecordManager *)recordManager{ +// if (!_recordManager) { +// _recordManager = [[AiRecordManager alloc] init]; +// __weak typeof(self) ws = self; +// _recordManager.didRecordData = ^(NSData * _Nonnull data) { +// [ws sendRecordData:data]; +// }; +// } +// return _recordManager; +//} +// +//#pragma mark - pub Api +//- (void)didDisconnect{ +// [self stopRecord:true]; +// // [self.connectManager disConnected]; +// +//} +//- (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted{ +// if(isConneted ){ +// _connected = true; +// _connectType = type; +// [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"]; +// +// if (type == AiMouseConnectType_hid ) { +// [self.recordManager checkPermissions]; +// } +// if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:self.connected]; +// [self checkAuthState]; +// } +// else{ +// if (self.connected) { +// [self stopRecord:true]; +// _connected = false; +// if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:self.connected]; +// } +// } +//} +// +//- (void)sendAiDataToSdk:(NSData *)data{ +// // [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]]; +// +// if(self.connectType == AiMouseConnectType_hid){ +// // 0AFFFF12BC32 +// if(data.length == 6){ +// NSData *subData = [data subdataWithRange:NSMakeRange(5, 1)]; +// [self sendCmdData:subData]; +// uint8 cmd; +// [subData getBytes:&cmd length:1]; +// // [self showLog:[NSString stringWithFormat:@"cmd = %X",cmdInt]]; +// if(cmd == 0x31 || cmd == 0x21 || cmd == 0x25 ||cmd == 0x27){ +// self.recordManager.startCmd = subData; +// [self startRecord]; +// } +// else if(cmd == 0x32 || cmd == 0x22 || cmd == 0x26 ||cmd == 0x28){ +// [self stopRecord:false]; +// } +// } +// else{ +// [self showLog:@"未实现指令"]; +// } +// } +// else if (self.connectType == AiMouseConnectType_bluetooth){ +// if(data.length == 16){ +// //0A65004E003200010101C0C10000A5A5 +// NSData *cmd = [data subdataWithRange:NSMakeRange(5, 1)]; +// [self sendCmdData:cmd]; +// return; +// } +// NSString *cmd = [[AiMouseTools dataToHexString:data] lowercaseString]; +// if([cmd hasPrefix:@"9c31"]){ +// //声音 +// [self.audioManager receiveData:data]; +// } +// else{ +// [self showLog:@"未实现指令"]; +// } +// } +//} +// +//#pragma mark - deviceInfoManager +//-(void)sendDeviceDataToSdk:(NSData *)data{ +// if (data.length == 0 || (data.length == 6 && [[AiMouseTools dataToHexString:data] hasSuffix:@"f77f"])) { +// [self showLog:[NSString stringWithFormat:@"[receive][info] %@",data]]; +// [self showLog:@"收到异常数据!!!"]; +// // [self switchConnect:self.connectType isConnected:false]; +// return; +// } +// [self showLog:[NSString stringWithFormat:@"[receive][info][json] %@",[AiMouseTools dataToHexString:data]]]; +// [self showLog:[NSString stringWithFormat:@"[receive][info][byte] %@",[AiMouseTools dataToUtf8String:data]]]; +// if (self.connected == false) { +// if([AiMouseTools dataToHexString:data].length < 10){ +// // [self switchConnect:AiMouseConnectType_hid isConnected:false ]; +// if (self.delegate && [self.delegate respondsToSelector:@selector(aiMouseHidDataError)]) [self.delegate aiMouseHidDataError]; +// return; +// } +// } +// +// [self.deviceInfoManager receiveData:data]; +//} +// +//- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{ +// +// __weak typeof(self) ws = self; +// [self.deviceInfoManager getDeviceInfo:^(AiMouseDeviceInfo * _Nonnull deviceInfo, NSError * _Nonnull error) { +// complete(deviceInfo,error); +// if (error != nil) { +// [ws switchConnect:ws.connectType isConnected:false]; +// } +// }]; +// +//} +//- (void)getRSSI:(void (^)(NSString *value,NSError *error))complete{ +// [self.deviceInfoManager getRSSI:complete]; +//} +//- (void)setBrand:(NSString *)brand completation:(void (^)(BOOL isSuccess,NSError *error))finished{ +// [self.deviceInfoManager setBrand:brand completation:finished]; +//} +//- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished{ +// [self.deviceInfoManager setCPI:value completation:finished]; +//} +///// 设置录音模式 +//- (void)setRecordMode:(int)mode completation:(void (^)(BOOL isSuccess,NSError *error))finished{ +// [self.deviceInfoManager setRecordMode:mode completation:finished]; +//} +///// 设置长按滚轮弹出的网页地址 +//- (void)setUrl:(NSString *)url completation:(void (^)(BOOL isSuccess,NSError *error))finished{ +// [self.deviceInfoManager setUrl:url completation:finished]; +//} +///// 设置长按滚轮弹出网页开关 +//- (void)setUrlState:(int)state completation:(void (^)(BOOL, NSError *))finished{ +// [self.deviceInfoManager setUrlState:state completation:finished]; +//} +///// 设置鼠标连接模式 +//- (void)setMouseMode:(int)mode completation:(void (^)(BOOL, NSError *))finished{ +// [self.deviceInfoManager setMouseMode: mode completation:finished]; +//} +///// 获取录音模式 +//- (void)getRecordMode:(void (^)(int mode,NSError *error))complete{ +// [self.deviceInfoManager getRecordMode:complete]; +//} +///// 获取长按滚轮弹出的网页地址 +//- (void)getUrl:(void (^)(NSString *url,NSError *error))complete{ +// [self.deviceInfoManager getUrl:complete]; +//} +///// 获取长按滚轮弹出的网页地址开关状态 +//- (void)getUrlState:(void (^)(int state,NSError *error))complete{ +// [self.deviceInfoManager getUrlState:complete]; +//} +///// 获取鼠标连接模式 +//- (void)getMouseModel:(void (^)(int mode,NSError *error))complete{ +// [self.deviceInfoManager getMouseModel:complete]; +//} +///// 开始录音 +//- (void)openRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ +// __weak typeof(self) ws = self; +// [self.deviceInfoManager openRecord:^(BOOL isSuccess, NSError * _Nonnull error) { +// finished(isSuccess,error); +// if (isSuccess) { +// uint8 value = 0x31; +// NSData *cmd = [NSData dataWithBytes:&value length:1]; +// [ws sendCmdData:cmd]; +// +// if(self.connectType == AiMouseConnectType_hid){ +// [ws startRecord]; +// } +// } +// }]; +//} +///// 结束录音 +//- (void)closeRecord:(void (^)(BOOL isSuccess,NSError *error))finished{ +// __weak typeof(self) ws = self; +// [self.deviceInfoManager closeRecord:^(BOOL isSuccess, NSError * _Nonnull error) { +// finished(isSuccess,error); +// +// if (isSuccess) { +// uint8 value = 0x32; +// NSData *cmd = [NSData dataWithBytes:&value length:1]; +// [ws sendCmdData:cmd]; +// +// if(self.connectType == AiMouseConnectType_hid){ +// [ws stopRecord:false]; +// } +// } +// }]; +//} +//#pragma mark - other +//- (void)sendRecordData:(NSData *)data{ +// // [self showLog:[NSString stringWithFormat:@"[audio] %@",data]]; +// if (self.delegate) [self.delegate aiMouseSendRecordData:data]; +//} +//- (void)sendCmdData:(NSData *)data{ +// [self showLog:[NSString stringWithFormat:@"[send] %@",data]]; +// if (self.delegate) [self.delegate aiMouseSendCmdData:data]; +//} +// +//- (void)authResult:(BOOL)isSuccess{ +// [self.deviceInfoManager setAuthStateToDevice:isSuccess]; +// +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// if(self.authBlock) self.authBlock(isSuccess); +// }); +//} +//- (void)showLog:(NSString *)log{ +// if (self.delegate && [self.delegate respondsToSelector:@selector(aiMouseAddLog:)]) { +// [self.delegate aiMouseAddLog:[NSString stringWithFormat:@"[frk]%@",log]]; +// } +//} +// +//- (void)checkAuthState{ +// if(self.delegate) [self.delegate aiMouseAuthenticationResult:AiMouseAuthState_Success]; +//} +//#pragma mark - deviceInfo +//- (void)startRecord{ +// // [self showLog:@"开始录音"]; +// [self.recordManager start]; +//} +// +//- (void)stopRecord:(BOOL)sendCmd{ +// if (self.recordManager.recording ) { +// [self.recordManager stop]; +// } +// if (sendCmd) { +// [self sendCmdData:self.recordManager.stopCmd]; +// } +// // [self showLog:@"结束录音"]; +//} +// +//@end +// diff --git a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h index a06ccc9..3f1f2ff 100644 --- a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h +++ b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h @@ -6,13 +6,22 @@ // #import +#import "AiMouseSdk.h" + -NS_ASSUME_NONNULL_BEGIN @interface ByteDanceSdk : NSObject +@property (nonatomic, strong) void (^sendToBleCallback)(NSData *data);/// 发送给蓝牙设备 +@property (nonatomic, strong) void (^byteDanceAuthInfoCallback)(ByteDanceInfo *data); +@property (nonatomic,strong) ByteDanceInfo *info; +(ByteDanceSdk *)shared; +- (void)initSdk; + +- (void)startAuth:(void (^)(ByteDanceInfo *info))complete; + +- (void)sendToSdk:(NSData *)data; + @end -NS_ASSUME_NONNULL_END diff --git a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m index 059156d..34b33bf 100644 --- a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m +++ b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m @@ -9,6 +9,7 @@ #import "stb_app.h" #import "AiMouseTools.h" #import "LogManager.h" +#import "AiMouseSdk.h" //appID:tis_test // //token:x3hWlrnUZXG2mlIlmvQ35gUUSTkmOa0m @@ -21,21 +22,14 @@ @implementation ByteDanceSdk -//+(ByteDanceSdk *)shared{ -// static ByteDanceSdk *manager = nil; -// static dispatch_once_t oncePredicate; -// dispatch_once(&oncePredicate, ^{ -// manager = [[ByteDanceSdk alloc]init]; ++(ByteDanceSdk *)shared{ + static ByteDanceSdk *manager = nil; + static dispatch_once_t oncePredicate; + dispatch_once(&oncePredicate, ^{ + manager = [[ByteDanceSdk alloc]init]; // [manager initSdk]; -// }); -// return manager; -//} - --(instancetype)init{ - if (self = [super init]) { - [self initSdk]; - } - return self; + }); + return manager; } - (void)initSdk{ @@ -48,45 +42,170 @@ } -- (void)startAuth{ +- (void)startAuth:(void (^)(ByteDanceInfo *info))complete{ + self.byteDanceAuthInfoCallback = complete; + self.info = [[ByteDanceInfo alloc] init]; stb_app_start_identify(); +// [self sendCmdToBle:@{@"cmd":@"set_config", +// @"set_VMouse_MAC":@"C0:34:56:78:AB:6D" +// }]; +} + +- (void)sendToSdk:(NSData *)data{ + stb_app_recv_data_from_device(data.bytes, data.length); +} + +- (void)checkAuthSuccess{ + if (self.info.urlParams && self.info.expireTime && self.info.token && self.info.host) { + if(self.byteDanceAuthInfoCallback)self.byteDanceAuthInfoCallback(self.info); + } +} +- (void)sendCmdToBle:(NSDictionary *)dict{ + NSData *data = [AiMouseTools dictionaryToData:dict]; + NSString *str = [AiMouseTools dataToUtf8String:data]; + NSArray *list = [self splitCMD:str]; + // [self showLog:[NSString stringWithFormat:@"send %@",str]]; + if(list.count > 1){ + { + //开始标志 + NSString *cmd = @"-$$\0"; + [self sendToBle:cmd]; + } + //指令 + for (NSInteger i = 0; i < list.count; i++) { + NSString *cmd = [NSString stringWithFormat:@"%@\0",list[i]]; + [self sendToBle:cmd]; + } + { + //结束标志 + NSString *cmd = @"$$-\0"; + [self sendToBle:cmd]; + } + } + else{ + NSString *cmd = [NSString stringWithFormat:@"-$$%@$$-\n",str]; + [self sendToBle:cmd]; + } +} +- (void)sendToBle:(NSString *)cmd{ + NSData *data = [cmd dataUsingEncoding:NSUTF8StringEncoding]; + [[AiMouse shared] sendToBle:data]; +} +//切割 +- (NSArray *)splitCMD:(NSString *)cmd{ + NSMutableArray *list = [[NSMutableArray alloc] init]; + NSString *str = cmd; + NSInteger len = 30; + while (str.length > 0) { + if (str.length > len) { + NSString *sub = [str substringToIndex:len]; + [list addObject:sub]; + str = [str substringFromIndex:len]; + } + else{ + [list addObject:str]; + break; + } + } + return list; } #pragma mark - ByteDance void STB_STDCALL cus_printf_str(char* str) { - NSString *logStr = [NSString stringWithFormat:@"%s", str]; - [[LogManager shared] addLog:logStr]; - return; + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *logStr = [NSString stringWithFormat:@"%s", str]; + [[LogManager shared] addLog:logStr]; + }); + + } static void cust_event_callback_func(uint32_t type,uint8_t *report, uint32_t data_len){ - NSData *data = [[NSData alloc] initWithBytes:report length:data_len]; - [[LogManager shared] addLog:[NSString stringWithFormat:@"type = ,data = %@,data_len = %d",type,data,data_len]]; + dispatch_async(dispatch_get_main_queue(), ^{ + switch (type) { + case STB_DYNREG_SUCCESS: + [[LogManager shared] addLog:@"STB_DYNREG_SUCCESS"]; + break; + case STB_DYNREG_FAIL: + [[LogManager shared] addLog:@"STB_DYNREG_FAIL"]; + break; + case STB_MQTT_CONNECT_SUCCESS: + [[LogManager shared] addLog:@"STB_MQTT_CONNECT_SUCCESS"]; + stb_app_get_token_async(); + break; + case STB_MQTT_CONNECT_FAIL: + [[LogManager shared] addLog:@"STB_MQTT_CONNECT_FAIL"]; + break; + case STB_MQTT_CONNECT_OFFLINE: + [[LogManager shared] addLog:@"STB_MQTT_CONNECT_OFFLINE"]; + break; + case STB_MQTT_CONNECT_ONLINE: + [[LogManager shared] addLog:@"STB_MQTT_CONNECT_ONLINE"]; + + break; + case STB_DM_DATA_ARRIVED_TOKEN: + { + //token + NSData *data = [[NSData alloc] initWithBytes:report length:data_len]; + [ByteDanceSdk shared].info.token = [AiMouseTools dataToUtf8String:data]; + [[LogManager shared] addLog:[NSString stringWithFormat:@"STB_DM_DATA_ARRIVED_TOKEN = %@",[ByteDanceSdk shared].info.token]]; + [[ByteDanceSdk shared] checkAuthSuccess]; + break; + } + case STB_DM_DATA_ARRIVED_TOKEN_TIMEOUT: + //token timeout + { + NSData *data = [[NSData alloc] initWithBytes:report length:data_len]; + [ByteDanceSdk shared].info.expireTime = [AiMouseTools dataToUtf8String:data]; +// [[LogManager shared] addLog:[NSString stringWithFormat:@"STB_DM_DATA_ARRIVED_TOKEN_TIMEOUT = %@",[ByteDanceSdk shared].info.expireTime]]; + [[ByteDanceSdk shared] checkAuthSuccess]; + break; + } + case STB_DM_DATA_ARRIVED_HOST: + { + //host + NSData *data = [[NSData alloc] initWithBytes:report length:data_len]; + [ByteDanceSdk shared].info.host = [AiMouseTools dataToUtf8String:data]; + [[LogManager shared] addLog:[NSString stringWithFormat:@"STB_DM_DATA_ARRIVED_HOST = %@",[ByteDanceSdk shared].info.host]]; + [[ByteDanceSdk shared] checkAuthSuccess]; + break; + } + case STB_DM_DATA_ARRIVED_PARAMS_SIGN: + { + //params + NSData *data = [[NSData alloc] initWithBytes:report length:data_len]; + [ByteDanceSdk shared].info.urlParams = [AiMouseTools dataToUtf8String:data]; + [[LogManager shared] addLog:[NSString stringWithFormat:@"STB_DM_DATA_ARRIVED_PARAMS_SIGN = %@",[ByteDanceSdk shared].info.urlParams]]; + [[ByteDanceSdk shared] checkAuthSuccess]; + break; + } + + default: + [[LogManager shared] addLog:@"UNKNOWN_MSG"]; + break; + } + + NSData *data = [[NSData alloc] initWithBytes:report length:data_len]; + [[LogManager shared] addLog:[NSString stringWithFormat:@"event_callback type = %u,data = %@",type,[AiMouseTools dataToHexString:data]]]; + [[LogManager shared] addLog:[NSString stringWithFormat:@"str = %@",[AiMouseTools dataToUtf8String:data]]]; + }); } int32_t STB_STDCALL cus_hal_send_data2device(uint8_t* data, uint32_t len) { - NSData *sendData = [[NSData alloc] initWithBytes:data length:len]; - [[LogManager shared] addLog:[NSString stringWithFormat:@"sendData = %@",[AiMouseTools dataToHexString_placeholder:sendData]]]; -// std::ostringstream oss; -// // 把数据转换成十六进制字符串 -// IBuffer buffer; -// for (uint32_t i = 0; i < len; ++i) -// { -// oss << std::hex << std::setw(2) << std::setfill('0') << static_cast(data[i]) << " "; -// } -// // 转换为字符串并使用 OutputDebugString 输出 -// std::string hexData = oss.str(); -// OutputDebugString(L"[STBAPP] send data 2 device:\n"); -// OutputDebugStringA(hexData.c_str()); -// DataWriter writer; -// for (uint32_t i = 0; i < len; ++i) -// { -// writer.WriteByte(data[i]); -// } -// writer.WriteByte('\n'); -// buffer = writer.DetachBuffer(); -// CusWriteCharacteristic.WriteValueAsync(buffer); + +// dispatch_async(dispatch_get_main_queue(), ^{ + NSData *cmdData = [[NSData alloc] initWithBytes:data length:len]; + [[LogManager shared] addLog:[NSString stringWithFormat:@"send_data2device = %@",[AiMouseTools dataToHexString_placeholder:cmdData]]]; + NSMutableData *fullData = [[NSMutableData alloc] init]; + + uint8_t head[] = { 0x2d, 0x24, 0x24}; + uint8_t tail[] = {0x24, 0x24,0x2d}; + [fullData appendBytes:&head length:3]; + [fullData appendData:cmdData]; + [fullData appendBytes:&tail length:3]; + [[AiMouse shared] sendToBle:fullData]; +// }); return 0; } diff --git a/MouseSdk/AiMouseSdk/Manager/BleManager.m b/MouseSdk/AiMouseSdk/Manager/BleManager.m index 40e8ddc..1b4f1dd 100644 --- a/MouseSdk/AiMouseSdk/Manager/BleManager.m +++ b/MouseSdk/AiMouseSdk/Manager/BleManager.m @@ -111,19 +111,17 @@ if ([characteristic.UUID.UUIDString isEqualToString:kFrkVoiceUUID]) { //语音特征 [peripheral setNotifyValue:YES forCharacteristic:characteristic]; + } + else if ([characteristic.UUID.UUIDString isEqualToString:kFrkDeviceInfoUUID]) { + //通知设备信息特征 + [peripheral setNotifyValue:YES forCharacteristic:characteristic]; + self.deviceInfoCha = characteristic; self.productType = AiMouseProductType_frk; - dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC); dispatch_after(delayTime, dispatch_get_main_queue(), ^{ [self showLog:[NSString stringWithFormat:@"连接成功 = %@",peripheral.name]]; self.connectStateCallBack(self.curentPeripheral.name,true); }); - - } - else if ([characteristic.UUID.UUIDString isEqualToString:kFrkDeviceInfoUUID]) { - //通知设备信息特征 - [peripheral setNotifyValue:YES forCharacteristic:characteristic]; - self.deviceInfoCha = characteristic; } } @@ -131,19 +129,17 @@ if ([characteristic.UUID.UUIDString isEqualToString:kTlwVoiceUUID]) { //语音特征 [peripheral setNotifyValue:YES forCharacteristic:characteristic]; + } + else if ([characteristic.UUID.UUIDString isEqualToString:kTlwNotifyDeviceInfoUUID]) { + //通知设备信息特征 + [peripheral setNotifyValue:YES forCharacteristic:characteristic]; self.productType = AiMouseProductType_tlw; - // 使用dispatch_after来延迟执行任务 dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC); dispatch_after(delayTime, dispatch_get_main_queue(), ^{ [self showLog:[NSString stringWithFormat:@"连接成功 = %@",peripheral.name]]; self.connectStateCallBack(self.curentPeripheral.name,true); }); - - } - else if ([characteristic.UUID.UUIDString isEqualToString:kTlwNotifyDeviceInfoUUID]) { - //通知设备信息特征 - [peripheral setNotifyValue:YES forCharacteristic:characteristic]; } else if ([characteristic.UUID.UUIDString isEqualToString:kTlwSetDeviceInfoUUID]) { //设备信息特征 @@ -220,6 +216,7 @@ [self.curentPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithResponse]; } else{ +// NSLog(@"Characteristic = %@",self.deviceInfoCha); [self.curentPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse]; } } diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.h b/MouseSdk/AiMouseSdk/Manager/DeviceManger.h index ea26770..aa2de3a 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.h +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.h @@ -19,6 +19,7 @@ typedef NS_ENUM(NSInteger,AiMouseProductType) { NS_ASSUME_NONNULL_BEGIN @interface DeviceManger : NSObject +@property (nonatomic, readonly) int appType;//1威鼠不鉴权;2威鼠字节鉴权;3千寻不鉴权;4千寻字节鉴权 @property (nonatomic, readonly)BOOL isConneted;//是否连接 @property (nonatomic, readonly) AiMouseConnectType connectType;//连接类型 @@ -38,6 +39,10 @@ NS_ASSUME_NONNULL_BEGIN ///单例 +(DeviceManger *)shared; +/// 初始化sdk +/// - Parameter appType: app类型 1威鼠不鉴权;2威鼠字节鉴权;3千寻不鉴权;4千寻字节鉴权 +- (void)initSdk:(int)appType; + ///当前设置的连接类型:@"0"表示蓝牙;@"1"表示USB; - (NSString *)getCurrentConnectType; diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m index c570ca9..729411f 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m @@ -46,16 +46,28 @@ - (instancetype)init{ self = [super init]; if (self) { - NSString *version = @"MouseSdk_v2024120303"; - NSLog(@"[AiMouseSdk] %@",version); - [self showLog:version];; - [self setupSDK]; - [self setupBle]; - [self setupHid]; - [self setupTimer]; +// NSString *version = @"MouseSdk_v2024120303"; +// NSLog(@"[AiMouseSdk] %@",version); +// [self showLog:version];; +// [self setupSDK]; +// [self setupBle]; +// [self setupHid]; +// [self setupTimer]; } return self; } +- (void)initSdk:(int)appType{ + _appType = appType; + + NSString *version = @"MouseSdk_v2024122601"; + NSLog(@"[AiMouseSdk] %@",version); + NSLog(@"[AiMouseSdk] %d",appType); + [self showLog:version]; + [self setupSDK]; + [self setupBle]; + [self setupHid]; + [self setupTimer]; +} #pragma mark ------ 设备初始化 - (void)setupSDK{ self.kbSdk = [[KeyboardSdk alloc] init]; @@ -223,6 +235,7 @@ } return false; } + - (NSString *)getCurrentConnectType { if (self.productType == AiMouseProductType_keyboard) { if (self.kbSdk.connectType == AiMouseConnectType_bluetooth) { diff --git a/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m index a3a4144..76d5ec4 100644 --- a/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m +++ b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m @@ -7,6 +7,8 @@ #import "NMouseSdk.h" #import "TlwTools.h" +#import "DeviceManger.h" + @interface NMouseSdk() @property (nonatomic,strong)void (^getDeviceInfoCallBack)(AiMouseDeviceInfo *deviceInfo,NSError *error); @@ -16,7 +18,6 @@ @property (nonatomic,assign)BOOL didReceiveData; @property (nonatomic,assign)NSInteger dongleTimes; - @property (nonatomic,strong)AiMouseDeviceInfo *deviceInfo; @end @@ -55,9 +56,16 @@ _connected = false; } -//北科专属 - (void)sendDeviceDataToSdk:(NSData *)data{ - + if([DeviceManger shared].appType == 1 || [DeviceManger shared].appType == 2){ + [self beiKeyReceive:data]; + } + else{ + [self qianxunReceive:data]; + } +} + +- (void)beiKeyReceive:(NSData *)data{ NSString *text = [TlwTools dataToHexString:data]; // 鼠标 0x020001f0ff0000 @@ -97,41 +105,43 @@ } } + + //千寻 -//- (void)sendDeviceDataToSdk:(NSData *)data{ -// NSString *text = [TlwTools dataToHexString:data]; -// -//// 鼠标 0x020001f0ff0000 -//// sn1 0xb52c00bba30d5540 -//// sn2 0xb52c01bba30d5540 -//// 62DF3D553297 -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// if ([text hasPrefix:@"B52C00"]) { -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// if (self.getSn1CallBack) { -// self.getSn1CallBack([text substringWithRange:NSMakeRange(6, 8)], nil); -// } -// } -// else if ([text hasPrefix:@"B52C01"]) { -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// if (self.getSn2CallBack) { -// self.getSn2CallBack([text substringWithRange:NSMakeRange(6, 4)], nil); -// } -// } -// else if([text hasPrefix:@"B5200443"]){ -// uint8_t cmd = 0x42; -// NSMutableData *mData = [NSMutableData data]; -// [mData appendBytes:&cmd length:1]; -// [self.delegate nMouseSendCmdData:mData]; -// } -// else if([text hasPrefix:@"B5200057"]){ -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// uint8_t cmd = 0x42; -// NSMutableData *mData = [NSMutableData data]; -// [mData appendBytes:&cmd length:1]; -// [self.delegate nMouseSendCmdData:mData]; -// } -//} +- (void)qianxunReceive:(NSData *)data{ + NSString *text = [TlwTools dataToHexString:data]; + +// 鼠标 0x020001f0ff0000 +// sn1 0xb52c00bba30d5540 +// sn2 0xb52c01bba30d5540 +// 62DF3D553297 + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if ([text hasPrefix:@"B52C00"]) { + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if (self.getSn1CallBack) { + self.getSn1CallBack([text substringWithRange:NSMakeRange(6, 8)], nil); + } + } + else if ([text hasPrefix:@"B52C01"]) { + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if (self.getSn2CallBack) { + self.getSn2CallBack([text substringWithRange:NSMakeRange(6, 4)], nil); + } + } + else if([text hasPrefix:@"B5200443"]){ + uint8_t cmd = 0x42; + NSMutableData *mData = [NSMutableData data]; + [mData appendBytes:&cmd length:1]; + [self.delegate nMouseSendCmdData:mData]; + } + else if([text hasPrefix:@"B5200057"]){ + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + uint8_t cmd = 0x42; + NSMutableData *mData = [NSMutableData data]; + [mData appendBytes:&cmd length:1]; + [self.delegate nMouseSendCmdData:mData]; + } +} - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{ [NSObject cancelPreviousPerformRequestsWithTarget:self]; self.getDeviceInfoCallBack = finished; diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index 4b64755..85216d9 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..6f99efd --- /dev/null +++ b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/MouseSdk/MouseSdk/ViewController.m b/MouseSdk/MouseSdk/ViewController.m index 5c68a7b..2ea1600 100644 --- a/MouseSdk/MouseSdk/ViewController.m +++ b/MouseSdk/MouseSdk/ViewController.m @@ -30,7 +30,7 @@ } - (void)loadView{ - self.view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; + self.view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 500, 800)]; } - (void)setupUI{ @@ -80,7 +80,7 @@ [self.view addSubview:label]; } { - NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(180, self.view.bounds.size.height - 360, 400, 200)]; + NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(180, self.view.bounds.size.height - 560, 400, 400)]; label.editable = NO; label.bordered = NO; label.stringValue = @""; @@ -104,6 +104,7 @@ - (void)setupDeviceManger{ // [AiHidManager shared]; DeviceManger *manager = [DeviceManger shared]; + [manager initSdk:2]; __weak typeof(self) ws = self; manager.aiMouseAddLogCallBack = ^(NSString * _Nonnull log) { NSLog(@"%@",log); diff --git a/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index d2ea65a..c230d1a 100644 --- a/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ Masonry.xcscheme_^#shared#^_ orderHint - 4 + 2 Pods-MouseSdk.xcscheme_^#shared#^_ orderHint - 2 + 3