@end
@interface AiMouse()
-
+@property (nonatomic, strong) NSMutableData *voiceData;
@property (nonatomic, strong) ByteDanceSdk *byteSdk;
@property (nonatomic, strong) AiAudioManager *audioManager;
@property (nonatomic, strong) AiRecordManager *recordManager;
-(instancetype)init{
if (self = [super init]) {
_connectType = AiMouseConnectType_bluetooth;
+ self.voiceData = [[NSMutableData alloc] init];
[self.recordManager checkPermissions];
if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
__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 showLog:[NSString stringWithFormat:@"[send][info]%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]]];
+ [ws showLog:[NSString stringWithFormat:@"[send][info]%@",[AiMouseTools dataToHexString:data]]];
[ws.delegate aiMouseSendDeviceInfoData:data];
}
};
if (type == AiMouseConnectType_hid ) {
[self.recordManager checkPermissions];
}
- if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:self.connected];
- 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];
- }
+ __weak typeof(self) ws = self;
+ [self.deviceInfoManager getDeviceInfo:^(AiMouseDeviceInfo * _Nonnull deviceInfo, NSError * _Nonnull error) {
+ if (error != nil) {
+ [ws switchConnect:ws.connectType isConnected:false];
+ return;
+ }
+ if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+ [self.byteSdk startAuth:^(ByteDanceInfo *info) {
+ deviceInfo.byteAuthInfo = info;
+ [ws showLog:deviceInfo.description];
+ if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:self.connected];
+ if(self.delegate) [self.delegate aiMouseAuthenticationResult:AiMouseAuthState_Success];
+ }];
+ }
+ else{
+ if([ws.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [ws.delegate aiMouseConnectStateDidChange:ws.connected];
+ if(ws.delegate) [ws.delegate aiMouseAuthenticationResult:AiMouseAuthState_Success];
+ }
+ }];
}
else{
if (self.connected) {
}
}
+
#pragma mark - deviceInfoManager
-(void)sendDeviceDataToSdk:(NSData *)data{
if (data.length == 0 || (data.length == 6 && [[AiMouseTools dataToHexString:data] hasSuffix:@"f77f"])) {
[self showLog:@"收到异常数据!!!"];
return;
}
- [self showLog:[NSString stringWithFormat:@"[receive][info][json] %@",[AiMouseTools dataToHexString:data]]];
- [self showLog:[NSString stringWithFormat:@"[receive][info][byte] %@",[AiMouseTools dataToUtf8String:data]]];
+ [self showLog:[NSString stringWithFormat:@"[receive][info] %@",[AiMouseTools dataToHexString:data]]];
+ [self showLog:[NSString stringWithFormat:@"[receive][info] %@",[AiMouseTools dataToUtf8String:data]]];
if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
__weak typeof(self) ws = self;
[self.deviceInfoManager getDeviceInfo:^(AiMouseDeviceInfo * _Nonnull deviceInfo, NSError * _Nonnull error) {
- if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+ if (deviceInfo && ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4)) {
deviceInfo.byteAuthInfo = ws.byteSdk.info;
+ [ws showLog:deviceInfo.description];
}
complete(deviceInfo,error);
if (error != nil) {
#pragma mark - other
- (void)sendRecordData:(NSData *)data{
// [self showLog:[NSString stringWithFormat:@"[audio] %@",data]];
- if (self.delegate) [self.delegate aiMouseSendRecordData:data];
+ if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+ [self.voiceData appendData:data];
+ if (self.voiceData.length > 5000) {
+ if (self.delegate) [self.delegate aiMouseSendRecordData:self.voiceData];
+ self.voiceData = [[NSMutableData alloc] init];
+ }
+ }
+ else{
+ if (self.delegate) [self.delegate aiMouseSendRecordData:data];
+ }
}
- (void)sendCmdData:(NSData *)data{
[self showLog:[NSString stringWithFormat:@"[send] %@",data]];
- (void)startRecord{
// [self showLog:@"开始录音"];
[self.recordManager start];
+ self.voiceData = [[NSMutableData alloc] init];
}
- (void)stopRecord:(BOOL)sendCmd{
- (void)sendToBle:(NSData *)data{
- [self showLog:[NSString stringWithFormat:@"[send][info][byte] %@",[AiMouseTools dataToHexString:data]]];
+ [self showLog:[NSString stringWithFormat:@"[send][info] %@",[AiMouseTools dataToHexString:data]]];
if (self.delegate) {
[self.delegate aiMouseSendDeviceInfoData:data];
};
- (void)initSdk{
[[LogManager shared] addLog:@"开始初始化"];
stb_app_printf_str_register(cus_printf_str);
- NSString *appId = @"tis_test";
+// NSString *appId = @"tis_test";
+ NSString *appId = @"app_10dyx2ai21r2qkar";
int code = stb_app_init([appId UTF8String]);
stb_app_event_callback_register(cust_event_callback_func);
stb_app_send_data_to_device_register(cus_hal_send_data2device);
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{
int32_t STB_STDCALL cus_hal_send_data2device(uint8_t* data, uint32_t len)
{
-
-// dispatch_async(dispatch_get_main_queue(), ^{
+// if ([[AiMouseTools dataToHexString_placeholder:[[NSData alloc] initWithBytes:data length:len]] hasPrefix:@"07"]) {
+// NSData *data = [AiMouseTools hexStringToData:@"2D2424073137333532303432363434313624242D0A"];
+// [[AiMouse shared] sendToBle:data];
+// return 0;
+// }
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};
+ uint8_t tail[] = {0x24, 0x24,0x2d,0x0a};
[fullData appendBytes:&head length:3];
[fullData appendData:cmdData];
[fullData appendBytes:&tail length:3];
[[AiMouse shared] sendToBle:fullData];
-// });
return 0;
}