|
@@ -6,7 +6,15 @@
|
|
|
#import "BTDataProcess.h"
|
|
|
#import "IOSPlatformSDK.h"
|
|
|
#include "Game.h"
|
|
|
-#import "MotionCountObj.h"
|
|
|
+
|
|
|
+#import "MYFactoryManager.h"
|
|
|
+
|
|
|
+#import "LEONBLManager.h"
|
|
|
+
|
|
|
+#import "ShoesInfo.h"
|
|
|
+#import "GameInfo.h"
|
|
|
+#import "DebugTool.h"
|
|
|
+#import "CacheTool.h"
|
|
|
|
|
|
//#define NSLog(format, ...) printf("TIME:%s FILE:%s(%d行) FUNCTION:%s %s\n",__TIME__, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
|
|
|
@interface BTDataProcess ()
|
|
@@ -26,15 +34,16 @@ Game *viceDeviceGame;
|
|
|
|
|
|
//定时查询设备状态
|
|
|
@property(nonatomic,weak)NSTimer * timer;
|
|
|
-
|
|
|
-@property(nonatomic,strong)MotionCountObj * motionCountObj;
|
|
|
+//鞋子信息
|
|
|
+@property(nonatomic,strong)ShoesInfo * shoes_info;
|
|
|
+//当局游戏信息
|
|
|
+@property(nonatomic,strong)GameInfo * game_info;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation BTDataProcess
|
|
|
|
|
|
-#pragma mark ===============================================>> 静态的初始化方法 init的时候(建立蓝牙中心管理类,设置代理)
|
|
|
-//单例静态
|
|
|
+#pragma mark ===============================================>> 单例
|
|
|
static BTDataProcess* instance = nil;
|
|
|
+(instancetype)sharedInstance{
|
|
|
return [[self alloc] init];
|
|
@@ -56,127 +65,17 @@ static BTDataProcess* instance = nil;
|
|
|
return instance;
|
|
|
}
|
|
|
|
|
|
-#pragma mark ===============================================>> public method
|
|
|
--(void)startWithUrl:(NSURL*)url{//
|
|
|
-
|
|
|
- if (url==nil){
|
|
|
- return;
|
|
|
- }
|
|
|
- NSString * urlString = [url absoluteString];
|
|
|
- NSArray * stringArr = [urlString componentsSeparatedByString:@"//"];
|
|
|
- if (stringArr == nil || stringArr.count<2){
|
|
|
- return;
|
|
|
- }
|
|
|
- NSString * arr2 = stringArr[1];
|
|
|
- NSString* finsalString = [arr2 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
- NSDictionary * urlDict = [AlgorithmTool dictionaryWithJsonString:finsalString];
|
|
|
- NSLog(@"Schemes_Url转码的dict ========= %@",urlDict);
|
|
|
- //缓存用户信息数据
|
|
|
- [IOS_NSUSERDEFAULT setObject:urlDict forKey:IOSSDK_USERINFO];
|
|
|
- [IOS_NSUSERDEFAULT synchronize];
|
|
|
-
|
|
|
- if ([urlDict isKindOfClass:[NSNull class]] || urlDict == nil || [urlDict isEqual:[NSNull null]]){
|
|
|
- [PopupView showCusHUDA:@"获取用户信息失败,请从趣动启动"];
|
|
|
- return;
|
|
|
- }
|
|
|
- //主副设备:deviceType 游戏种类:game_type mac地址:macAddress
|
|
|
- self.game_info.deviceType = DEVICETYPE_MAIN;
|
|
|
- NSString * game_type = [MYFactoryManager getGameType];
|
|
|
- self.game_info.game_type = (GAME_TYPE)[game_type intValue];
|
|
|
- self.shoes_info.macAddress = [MYFactoryManager getGameMac];
|
|
|
- //链接蓝牙
|
|
|
- [self initCBCentralManager];
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//unity call instance弹出蓝牙搜索框
|
|
|
--(void)searchBLEAction:(int)type{
|
|
|
-
|
|
|
- /***************************初始化蓝牙数据处理工具***************************/
|
|
|
- //主副设备:deviceType 游戏种类:game_type mac地址:macAddress
|
|
|
- self.game_info.deviceType = (DEVICE_TYPE)type;
|
|
|
- NSString * game_type = [MYFactoryManager getGameType];
|
|
|
- self.game_info.game_type = (GAME_TYPE)[game_type intValue];
|
|
|
- self.shoes_info.macAddress = @"";
|
|
|
- //初始化蓝牙CBCentralManager
|
|
|
- [self initCBCentralManager];
|
|
|
-
|
|
|
- /***************************搜索蓝牙外设弹窗***************************/
|
|
|
- self.searchDeviceVC = [SearchDeviceViewController new];
|
|
|
- UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
|
|
|
- UIViewController *parent = rootVC;
|
|
|
- while ((parent = rootVC.presentedViewController) != nil ){
|
|
|
- rootVC = parent;
|
|
|
- }
|
|
|
- while ([rootVC isKindOfClass:[UINavigationController class]]){
|
|
|
- rootVC = [(UINavigationController *)rootVC topViewController];
|
|
|
- }
|
|
|
- [rootVC addChildViewController:self.searchDeviceVC];
|
|
|
- [rootVC.view addSubview:self.searchDeviceVC.view];
|
|
|
- //点击searchVC的tableViewCell链接选中的蓝牙
|
|
|
- __weak __typeof(self)weakself = self;
|
|
|
- self.searchDeviceVC.connectDeviceBlock = ^(CBPeripheral * peripheral){
|
|
|
- weakself.game_info.deviceType = (DEVICE_TYPE)type;
|
|
|
- weakself.shoes_info.macAddress = peripheral.identifier.UUIDString;
|
|
|
- [weakself connectPeripheral:peripheral];
|
|
|
- };
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//每重新开始一局游戏
|
|
|
--(void)gameStartInitData{
|
|
|
-
|
|
|
- //当局游戏时间
|
|
|
- self.game_info.firstTime = [NSDate date];
|
|
|
-
|
|
|
- self.motionCountObj = [MotionCountObj new];
|
|
|
- if (game){
|
|
|
- self.motionCountObj.step = game->getMotionCount(STEP_COUNT);
|
|
|
- self.motionCountObj.jump = game->getMotionCount(JUMP_COUNT);
|
|
|
- self.motionCountObj.crouch = game->getMotionCount(DOWN_COUNT);
|
|
|
- self.motionCountObj.tick = game->getMotionCount(KICK_COUNT);
|
|
|
- self.motionCountObj.paper = game->getMotionCount(PAPER_COUNT);
|
|
|
- self.motionCountObj.scissors = game->getMotionCount(SCISSORS_COUNT);
|
|
|
- self.motionCountObj.rock = game->getMotionCount(ROCK_COUNT);
|
|
|
- NSLog(@"self.motionCountObj = %d %d %d %d %d %d %d",self.motionCountObj.step,self.motionCountObj.jump,self.motionCountObj.crouch,self.motionCountObj.tick,self.motionCountObj.paper,self.motionCountObj.scissors,self.motionCountObj.rock);
|
|
|
- }
|
|
|
-
|
|
|
- //游戏模式 ==>> 回调剑波sdk数据
|
|
|
- self.shoes_info.gameModel = YES;
|
|
|
- //读写到特征后 添加测试弹窗
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [DebugViewInstance inittestLabel];
|
|
|
- });
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//每结束一局游戏
|
|
|
--(void)gameEndInitData{
|
|
|
-// self.shoes_info.gameModel = NO;
|
|
|
- //jb
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
- [DebugViewInstance uploadpPlistFile];
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-//监听通知震动
|
|
|
--(void)vibrationAction:(int)type duration:(int)duration{
|
|
|
- [BTDataSendInstance vibration:(DEVICE_TYPE)type duration:duration];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark ============================>> private
|
|
|
+#pragma mark ===============================================>> private
|
|
|
-(void)initData{
|
|
|
|
|
|
self.shoes_info = [ShoesInfo new];
|
|
|
self.shoes_info.gameModel = NO; //默认游戏模式关
|
|
|
+ self.shoes_info.timestamp = [AlgorithmTool returnTimestamp];//跳转游戏时候的时间戳
|
|
|
|
|
|
self.game_info = [GameInfo new];
|
|
|
self.game_info.isBackGround = NO; //后台模式
|
|
|
-
|
|
|
- //固定一个时间戳
|
|
|
- NSString * timestamp = [AlgorithmTool returnTimestamp];
|
|
|
- [IOS_NSUSERDEFAULT setObject:timestamp forKey:IOSSDK_TIMESTAMP];
|
|
|
- [IOS_NSUSERDEFAULT synchronize];
|
|
|
+// NSLog(@"self.game_info = %d %d %d %d %d %d %d",self.game_info.step,self.game_info.jump,self.game_info.crouch,self.game_info.tick,self.game_info.paper,self.game_info.scissors,self.game_info.rock);
|
|
|
+
|
|
|
|
|
|
//监听 趣动 app group 消息 ==>> 好友邀请信息
|
|
|
CFStringRef invite = (__bridge CFStringRef)@"INVITE_NOTIFICATION";
|
|
@@ -218,6 +117,12 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
[instance disConnedctBle];
|
|
|
}
|
|
|
|
|
|
+//趣动 ==>> 断开蓝牙
|
|
|
+-(void)disConnedctBle{
|
|
|
+ NSLog(@"趣动 call 断开蓝牙");
|
|
|
+ [LEManager cancelPeripheralConnection];
|
|
|
+}
|
|
|
+//趣动 ==>> 通知邀请好友
|
|
|
void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
|
|
|
|
|
|
//group.com.Oujia.AppAndGame 沙河数据
|
|
@@ -247,12 +152,87 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
}
|
|
|
|
|
|
-//趣动 ==>> 断开蓝牙
|
|
|
--(void)disConnedctBle{
|
|
|
- NSLog(@"趣动 call 断开蓝牙");
|
|
|
- [LEManager cancelPeripheralConnection];
|
|
|
+#pragma mark ===============================================>> public method
|
|
|
+-(void)startWithUrl:(NSURL*)url{//
|
|
|
+
|
|
|
+ if (url==nil){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSString * urlString = [url absoluteString];
|
|
|
+ NSArray * stringArr = [urlString componentsSeparatedByString:@"//"];
|
|
|
+ if (stringArr == nil || stringArr.count<2){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ NSString * arr2 = stringArr[1];
|
|
|
+ NSString* finsalString = [arr2 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+ NSDictionary * urlDict = [AlgorithmTool dictionaryWithJsonString:finsalString];
|
|
|
+ NSLog(@"Schemes_Url转码的dict ========= %@",urlDict);
|
|
|
+ //缓存用户信息数据
|
|
|
+ [IOS_NSUSERDEFAULT setObject:urlDict forKey:IOSSDK_USERINFO];
|
|
|
+ [IOS_NSUSERDEFAULT synchronize];
|
|
|
+
|
|
|
+ //主副设备:deviceType 游戏种类:game_type mac地址:macAddress
|
|
|
+ self.game_info.deviceType = DEVICETYPE_MAIN;
|
|
|
+ self.game_info.game_type = (GAME_TYPE)[[MYFactoryManager getGameType] intValue];
|
|
|
+ self.shoes_info.macAddress = [MYFactoryManager getGameMac];
|
|
|
+
|
|
|
+ //链接蓝牙
|
|
|
+ [self initCBCentralManager];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//unity call instance弹出蓝牙搜索框
|
|
|
+-(void)searchBLEAction:(int)type{
|
|
|
+
|
|
|
+ //初始化蓝牙CBCentralManager
|
|
|
+ [self initCBCentralManager];
|
|
|
+
|
|
|
+ //搜索蓝牙外设弹窗
|
|
|
+ self.searchDeviceVC = [SearchDeviceViewController new];
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:self.searchDeviceVC.view];
|
|
|
+
|
|
|
+ //点击searchVC的tableViewCell链接选中的蓝牙
|
|
|
+ __weak __typeof(self)weakself = self;
|
|
|
+ self.searchDeviceVC.connectDeviceBlock = ^(CBPeripheral * peripheral){
|
|
|
+ //主副设备:deviceType 游戏种类:game_type mac地址:macAddress
|
|
|
+ weakself.game_info.game_type = (GAME_TYPE)[[MYFactoryManager getGameType] intValue];
|
|
|
+ weakself.game_info.deviceType = (DEVICE_TYPE)type;
|
|
|
+ weakself.shoes_info.macAddress = peripheral.identifier.UUIDString;
|
|
|
+ [weakself connectPeripheral:peripheral];
|
|
|
+ };
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+//每重新开始一局游戏
|
|
|
+-(void)gameStartInitData{
|
|
|
+
|
|
|
+ //当局游戏时间
|
|
|
+ self.game_info.firstTime = [NSDate date];
|
|
|
+
|
|
|
+ //游戏模式 ==>> 回调剑波sdk数据
|
|
|
+ self.shoes_info.gameModel = YES;
|
|
|
+ //读写到特征后 添加测试弹窗
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [DebugViewInstance inittestLabel];
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//每结束一局游戏
|
|
|
+-(void)gameEndInitData{
|
|
|
+// self.shoes_info.gameModel = NO;
|
|
|
+ //jb
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
+ [DebugViewInstance uploadpPlistFile];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+//监听通知震动
|
|
|
+-(void)vibrationAction:(int)type duration:(int)duration{
|
|
|
+ [BTDataSendInstance vibration:(DEVICE_TYPE)type duration:duration];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
#pragma mark ===============================================>> leon Ble manager
|
|
|
//测试自己封装的蓝牙类
|
|
|
-(void)initCBCentralManager{
|
|
@@ -327,11 +307,9 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
// NSLog(@"主设备扫描发现有效的蓝牙设备 =============== %@ identifier == %@",peripheral.name,peripheral.identifier.UUIDString);
|
|
|
|
|
|
if (self.deviceArray.count == 0){//数据源为0
|
|
|
-
|
|
|
[self.deviceArray addObject:peripheral];
|
|
|
//判断扫描到外设之后是否要链接蓝牙
|
|
|
[self ifAppJumpWithIdentifier:peripheral];
|
|
|
-
|
|
|
}else{
|
|
|
|
|
|
BOOL isExist = NO;
|
|
@@ -342,14 +320,13 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
[self.deviceArray replaceObjectAtIndex:i withObject:peripheral];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (!isExist){
|
|
|
[self.self.deviceArray addObject:peripheral];
|
|
|
//判断扫描到外设之后是否要链接蓝牙
|
|
|
[self ifAppJumpWithIdentifier:peripheral];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//数据回调给 搜索蓝牙弹窗
|
|
|
self.searchDeviceVC.deviceArray = self.deviceArray;
|
|
|
[self.searchDeviceVC reloadData];
|
|
@@ -399,12 +376,44 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
//链接主副设备 + 绑定特征
|
|
|
-(void)connectBLEManagerData:(CBPeripheral*)peripheral deviceType:(DEVICE_TYPE)deviceType{
|
|
|
-
|
|
|
+
|
|
|
+ //链接蓝牙 此时 LEManager.peripheral || LEManager.vicePeripheral 还未init
|
|
|
+ [LEManager connectPeripheral:peripheral options:nil];
|
|
|
//链接动画
|
|
|
[[AnimationView shanreAnimationView] addAnimation];
|
|
|
|
|
|
- //链接蓝牙 此时 LEManager.peripheral || LEManager.vicePeripheral 还未init
|
|
|
- [LEManager connectPeripheral:peripheral options:nil];
|
|
|
+ //蓝牙连接成功
|
|
|
+ LEManager.successfulBlock = ^(CBPeripheral * _Nonnull peripheral){
|
|
|
+ NSLog(@"蓝牙链接成功");
|
|
|
+ };
|
|
|
+
|
|
|
+ //蓝牙连接失败
|
|
|
+ LEManager.connectFailureBlock = ^(NSError * _Nonnull error){
|
|
|
+ NSLog(@"蓝牙链接失败");
|
|
|
+ };
|
|
|
+
|
|
|
+ //蓝牙连接丢失
|
|
|
+ LEManager.disConnectBlock = ^(CBPeripheral * _Nonnull peripheral, NSError * _Nonnull error){
|
|
|
+ NSLog(@"蓝牙链接丢失");
|
|
|
+ if (LEManager.peripheral!=nil&&peripheral == LEManager.peripheral){
|
|
|
+ [self.sdk bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
+ name:LEManager.peripheral.name
|
|
|
+ address:LEManager.peripheral.identifier.UUIDString
|
|
|
+ status:CONNECT_LOST
|
|
|
+ electricity:0];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (LEManager.vicePeripheral!=nil&&peripheral == LEManager.vicePeripheral){
|
|
|
+ [self.sdk bridgingDeviceAction:DEVICETYPE_VICE
|
|
|
+ name:LEManager.vicePeripheral.name
|
|
|
+ address:LEManager.vicePeripheral.identifier.UUIDString
|
|
|
+ status:CONNECT_LOST
|
|
|
+ electricity:0];
|
|
|
+ }
|
|
|
+ //断线重连
|
|
|
+ [self initCBCentralManager];
|
|
|
+ };
|
|
|
+
|
|
|
//发现服务和特征
|
|
|
LEManager.discoverCharacteristicsBlock = ^(CBPeripheral * _Nonnull peripheral, CBService * _Nonnull service, NSArray * _Nonnull characteristics, NSError * _Nonnull error){
|
|
|
|
|
@@ -460,7 +469,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
int dataType = [AlgorithmTool dataToChar:[characteristic.value subdataWithRange:NSMakeRange(3, 1)]];//cmd类型
|
|
|
// NSLog(@"读取特征的报文 游戏数据 %ld dataType = %d %@",(long)type,dataType,characteristic.value);
|
|
|
- if (dataType == 4){//获取主动推过来的数据
|
|
|
+ if (dataType == 4){//鞋子游戏数据
|
|
|
|
|
|
//数据丢给算法计算轨迹
|
|
|
if (type == DEVICETYPE_MAIN&&LEManager.main_read == 0){
|
|
@@ -468,18 +477,23 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
LEManager.main_read = 1;
|
|
|
[self shoseSDK:characteristic.value];
|
|
|
}else if (type == DEVICETYPE_VICE&&LEManager.vice_read == 0){
|
|
|
- NSLog(@"LEManager.vice_read = %d",LEManager.main_read);
|
|
|
+// NSLog(@"LEManager.vice_read = %d",LEManager.main_read);
|
|
|
LEManager.vice_read = 1;
|
|
|
[self viceShoseSDK:characteristic.value];
|
|
|
}
|
|
|
|
|
|
- }else if(dataType == -95){//读取基本信息
|
|
|
+ }else if(dataType == -95){//鞋子状态信息
|
|
|
+
|
|
|
+ //隐藏加载框
|
|
|
+ [[AnimationView shanreAnimationView] stopAnimation];
|
|
|
+
|
|
|
//嵌入式原始数据解析 --->> 回调蓝牙状态/电量给unity
|
|
|
BTDataAnalysis * anly = [BTDataAnalysis new];
|
|
|
[anly analysisCharacteristic:characteristic.value deviceType:type];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -495,46 +509,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
// NSLog(@"self.RSSI = %@",self.RSSI);
|
|
|
};
|
|
|
|
|
|
- //蓝牙连接成功
|
|
|
- LEManager.successfulBlock = ^(CBPeripheral * _Nonnull peripheral){
|
|
|
- NSLog(@"蓝牙链接成功");
|
|
|
- [[AnimationView shanreAnimationView] stopAnimation];
|
|
|
- };
|
|
|
|
|
|
- //蓝牙连接失败
|
|
|
- LEManager.connectFailureBlock = ^(NSError * _Nonnull error){
|
|
|
- NSLog(@"蓝牙链接失败");
|
|
|
- };
|
|
|
-
|
|
|
- //蓝牙连接丢失
|
|
|
- LEManager.disConnectBlock = ^(CBPeripheral * _Nonnull peripheral, NSError * _Nonnull error){
|
|
|
-
|
|
|
- if (LEManager.peripheral!=nil&&peripheral == LEManager.peripheral){
|
|
|
-
|
|
|
- [self.sdk bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
- name:LEManager.peripheral.name
|
|
|
- address:LEManager.peripheral.identifier.UUIDString
|
|
|
- status:CONNECT_LOST
|
|
|
- electricity:0];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (LEManager.vicePeripheral!=nil&&peripheral == LEManager.vicePeripheral){
|
|
|
-
|
|
|
- [self.sdk bridgingDeviceAction:DEVICETYPE_VICE
|
|
|
- name:LEManager.vicePeripheral.name
|
|
|
- address:LEManager.vicePeripheral.identifier.UUIDString
|
|
|
- status:CONNECT_LOST
|
|
|
- electricity:0];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- NSLog(@"蓝牙链接丢失");
|
|
|
- //断线重连
|
|
|
- [self initCBCentralManager];
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
}
|
|
|
|
|
|
#pragma mark ===============================================>> 读取特征后 鞋子打开游戏模式 & 激光开关 &查询鞋子蓝牙状态 & 主设备初始化缓存游戏步数
|
|
@@ -550,7 +525,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
[self.timer invalidate];
|
|
|
self.timer = nil;
|
|
|
}
|
|
|
- self.timer = [NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(timingDataTransmission:) userInfo:nil repeats:YES];
|
|
|
+ self.timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timingDataTransmission:) userInfo:nil repeats:YES];
|
|
|
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
|
|
|
|
|
|
}
|
|
@@ -577,66 +552,67 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
Byte * buff = (Byte*)[validData bytes];
|
|
|
game->GameProcessBuf(buff, (int)validData.length);
|
|
|
|
|
|
+ /********************剑波 & 威严 要的图表数据 *****************/
|
|
|
+ NSString * message = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
|
|
|
+ [DebugTool debugMessage:message shoesInfo:self.shoes_info];
|
|
|
+
|
|
|
+ /******************左右脚动作数据处理 + 回调*****************/
|
|
|
int length = 4;
|
|
|
int result[length];
|
|
|
game->getGameResult(result);
|
|
|
// NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
|
|
|
-
|
|
|
- /******************左右脚动作数据处理 + 回调*****************/
|
|
|
int motionLeft = result[0];//左脚的动作
|
|
|
int motionRight = result[1];//右脚的动作
|
|
|
int motionJump = result[2];//jump
|
|
|
int motionDown = result[3];//down
|
|
|
|
|
|
-// //无效动作
|
|
|
-// if (motionLeft==-1 && motionRight == -1&& motionJump == -1&& motionDown == -1){
|
|
|
-// return;
|
|
|
-// }else{
|
|
|
+ //无效动作
|
|
|
+ if (motionLeft==-1 && motionRight == -1&& motionJump == -1&& motionDown == -1){
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
|
|
|
//跳跃和蹲下的动作 双脚是同步的
|
|
|
if (motionJump == MOTION_JUMP){
|
|
|
motionLeft = motionJump;
|
|
|
motionRight = motionJump;
|
|
|
- NSLog(@" 主设备 ================================== 跳起来 ");
|
|
|
+// NSLog(@" 主设备 ================================== 跳起来 ");
|
|
|
}
|
|
|
|
|
|
if (motionDown == MOTION_DOWN){
|
|
|
motionLeft = motionDown;
|
|
|
motionRight = motionDown;
|
|
|
- NSLog(@" 主设备 =================================== 蹲下去 ");
|
|
|
+// NSLog(@" 主设备 =================================== 蹲下去 ");
|
|
|
}
|
|
|
|
|
|
- /******************步频数据处理 + 回调*****************/
|
|
|
+ /******************当局鞋子子动作状态数据 缓存*****************/
|
|
|
self.shoes_info.leftStepStatus = game->getStepStatus(LEFT_FOOT);
|
|
|
self.shoes_info.leftStepFreq = game->getStepFreq(LEFT_FOOT);
|
|
|
self.shoes_info.leftStepCount = game->getStepCount(LEFT_FOOT);
|
|
|
self.shoes_info.rightStepStatus = game->getStepStatus(RIGHT_FOOT);
|
|
|
self.shoes_info.rightStepFreq = game->getStepFreq(RIGHT_FOOT);
|
|
|
self.shoes_info.rightStepCount = game->getStepCount(RIGHT_FOOT);
|
|
|
+ [self cacheAllMotionCount];
|
|
|
|
|
|
- /******************玩家当前朝向 用户赛车*****************/
|
|
|
- // int attLength = 3;
|
|
|
- // int left[attLength];
|
|
|
- // int right[attLength];
|
|
|
- // game->getFootAtt(left, right);
|
|
|
- // self.nativeAttX = left[0];
|
|
|
- // NSLog(@"self.nativeAttX = %d",self.nativeAttX);
|
|
|
-
|
|
|
- //跑酷需要回调步频
|
|
|
- if (self.game_info.game_type == GAME_TYPE_RUN){
|
|
|
- [self.sdk bridgingStepAction:DEVICETYPE_MAIN leftStatus:self.shoes_info.leftStepStatus rightStatus:self.shoes_info.rightStepStatus leftFrag:self.shoes_info.leftStepFreq rightFrag:self.shoes_info.rightStepFreq];
|
|
|
- }
|
|
|
- //左右脚动作
|
|
|
- [self.sdk bridgingMotionAction:DEVICETYPE_MAIN left:motionLeft right:motionRight];
|
|
|
-
|
|
|
- //当局运动数据缓存
|
|
|
- [self cacheAllMotionCount:self.shoes_info.leftStepCount+self.shoes_info.rightStepCount];
|
|
|
-
|
|
|
- //测试数据
|
|
|
- [self tempTest:self.shoes_info.rightStepFreq leftStepFreq:self.shoes_info.leftStepFreq];
|
|
|
+ /******************鞋子动作状态数据 实时回调*****************/
|
|
|
+ //左右脚动作
|
|
|
+ [self.sdk bridgingMotionAction:DEVICETYPE_MAIN left:motionLeft right:motionRight];
|
|
|
|
|
|
-// }
|
|
|
+ //只有 跑酷 需要回调步频
|
|
|
+ if (self.game_info.game_type == GAME_TYPE_RUN){
|
|
|
+ [self.sdk bridgingStepAction:DEVICETYPE_MAIN leftStatus:self.shoes_info.leftStepStatus rightStatus:self.shoes_info.rightStepStatus leftFrag:self.shoes_info.leftStepFreq rightFrag:self.shoes_info.rightStepFreq];
|
|
|
+ }
|
|
|
|
|
|
+// //只有 赛车游戏 需要回调当前朝向
|
|
|
+// if (self.game_info.game_type == GAME_TYPE_CYCLE){
|
|
|
+// int attLength = 3;
|
|
|
+// int left[attLength];
|
|
|
+// int right[attLength];
|
|
|
+// game->getFootAtt(left, right);
|
|
|
+// self.nativeAttX = left[0];
|
|
|
+// NSLog(@"self.nativeAttX = %d",self.nativeAttX);
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}else{//当前是交互模式
|
|
|
|
|
@@ -651,73 +627,11 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
// }else{
|
|
|
// // NSLog(@"BTDataProcess 无效交互动作 ===>> %@",@"原地");
|
|
|
// }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-//算法需要的测试数据
|
|
|
--(void)tempTest:(int)rightStepFreq leftStepFreq:(int)leftStepFreq{
|
|
|
-
|
|
|
- /********************剑波 & 威严 要的图表数据 *****************/
|
|
|
- NSString * aString = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
|
|
|
-// NSLog(@"aString == %@",aString);
|
|
|
- if (aString.length <1){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //上传即使动作数据
|
|
|
- [[SocketRocketUtility sharedInstance] sendData:nil withRequestURI:aString];
|
|
|
- if (DebugViewInstance.RSSI==nil){
|
|
|
- DebugViewInstance.RSSI = 0;
|
|
|
- }
|
|
|
- aString = [NSString stringWithFormat:@"%@,%@",aString,DebugViewInstance.RSSI];
|
|
|
- DebugViewInstance.tempStepString = [NSString stringWithFormat:@"%@\n",aString];
|
|
|
- if (DebugViewInstance.tempStepString!=nil && DebugViewInstance.tempStepString.length>1){
|
|
|
- [DebugViewInstance writeFileToplist];
|
|
|
- }
|
|
|
-
|
|
|
- /********************调试窗数据 *****************/
|
|
|
- NSArray *aArray = [aString componentsSeparatedByString:@","];
|
|
|
- if (aArray == nil || [aArray isKindOfClass:[NSNull class]] || aArray.count<30){
|
|
|
- return;
|
|
|
- }
|
|
|
-// NSLog(@"aArray == %@",aArray);
|
|
|
-// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if (DebugViewInstance.testLabel!=nil){
|
|
|
- DebugViewInstance.testLabel.text = [NSString stringWithFormat:@"right:[%@,%@,%@] [%@,%@,%@] [%@,%@,%@] [%@,%@,%@] \nleft:[%@,%@,%@] [%@,%@,%@] [%@,%@,%@] [%@,%@,%@] \nrssi:[%@ %@] ts:%@ \n脚步:[%@ %@] \n步频:[%d %d] ",aArray[0],aArray[1],aArray[2],aArray[3],aArray[4],aArray[5],aArray[6],aArray[7],aArray[8],aArray[9],aArray[10],aArray[11],aArray[12],aArray[13],aArray[14],aArray[15],aArray[16],aArray[17],aArray[18],aArray[19],aArray[20],aArray[21],aArray[22],aArray[23],DebugViewInstance.RSSI,aArray[26],aArray[27],aArray[28],aArray[29],rightStepFreq,leftStepFreq];
|
|
|
- }
|
|
|
-// });
|
|
|
-
|
|
|
- /********************颖嘉+的ts丢包数据 *****************/
|
|
|
- NSString * tsString = aArray[27];
|
|
|
-// NSLog(@"剑波 getGameDataStr 时间戳 ==============>> %@\n",tsString);
|
|
|
- int tsInt = [tsString intValue];
|
|
|
- int total;
|
|
|
- if (DebugViewInstance.currentTS != 1000){//颖嘉初始值未知 ios初始值==1000
|
|
|
- //1....255
|
|
|
- if (tsInt > DebugViewInstance.currentTS){
|
|
|
- total = tsInt - DebugViewInstance.currentTS - 1;
|
|
|
- }
|
|
|
- //255...1
|
|
|
- if (tsInt < DebugViewInstance.currentTS){
|
|
|
- if (tsInt ==0){
|
|
|
- total = (255-DebugViewInstance.currentTS) + tsInt + 1 - 1;
|
|
|
- }else{
|
|
|
- total = (255-DebugViewInstance.currentTS) + tsInt - 1;
|
|
|
- }
|
|
|
- }
|
|
|
- if (total > 10){
|
|
|
- NSLog(@"getGameDataStr 丢包 ================================>> %d",total);
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
|
|
- [PopupView showCusHUDA:[NSString stringWithFormat:@"丢包数: %d",total]];
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-// NSLog(@"tsInt = %d currentTS = %d total = %d",tsInt,self.currentTS,total);
|
|
|
- DebugViewInstance.currentTS = tsInt;
|
|
|
-
|
|
|
-}
|
|
|
|
|
|
#pragma mark ===============================================>>副设备 报文数据解析后 -- 调用蓝牙鞋子SDK装换数据 -- ios call unity 更新游戏动作
|
|
|
-(void)viceShoseSDK:(NSData*)characteristic{
|
|
@@ -750,6 +664,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if (motionLeft==-1 && motionRight == -1&& ivce_motionJump == -1&& ivce_motionDown == -1){//无效动作
|
|
|
return;
|
|
|
}else{
|
|
|
+
|
|
|
//跳跃和蹲下的动作 双脚是同步的
|
|
|
if (ivce_motionJump == MOTION_JUMP){
|
|
|
motionLeft = ivce_motionJump;
|
|
@@ -769,7 +684,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
//ios call unity
|
|
|
[self.sdk bridgingMotionAction:DEVICETYPE_VICE left:motionLeft right:motionRight];//副设备左右脚动作
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -782,16 +697,17 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
#pragma mark ===============================================>>玩游戏过程中缓存 动作数据 和时间戳 数据存入plist
|
|
|
--(void)cacheAllMotionCount:(int)totalStep{
|
|
|
+-(void)cacheAllMotionCount{
|
|
|
|
|
|
//总数
|
|
|
- int total_step_count = game->getMotionCount(STEP_COUNT) - self.motionCountObj.step;
|
|
|
- int total_jump_count = game->getMotionCount(JUMP_COUNT) - self.motionCountObj.jump;
|
|
|
- int total_crouch_count = game->getMotionCount(DOWN_COUNT) - self.motionCountObj.crouch;
|
|
|
- int total_tick_count = game->getMotionCount(KICK_COUNT) - self.motionCountObj.tick;
|
|
|
- int total_paper_count = game->getMotionCount(PAPER_COUNT) - self.motionCountObj.paper;
|
|
|
- int total_scissors_count = game->getMotionCount(SCISSORS_COUNT) - self.motionCountObj.scissors;
|
|
|
- int total_rock_count = game->getMotionCount(ROCK_COUNT) - self.motionCountObj.rock;
|
|
|
+ int total_step_count = game->getMotionCount(STEP_COUNT) - self.game_info.step;
|
|
|
+ int total_jump_count = game->getMotionCount(JUMP_COUNT) - self.game_info.jump;
|
|
|
+ int total_crouch_count = game->getMotionCount(DOWN_COUNT) - self.game_info.crouch;
|
|
|
+ int total_tick_count = game->getMotionCount(KICK_COUNT) - self.game_info.tick;
|
|
|
+ int total_paper_count = game->getMotionCount(PAPER_COUNT) - self.game_info.paper;
|
|
|
+ int total_scissors_count = game->getMotionCount(SCISSORS_COUNT) - self.game_info.scissors;
|
|
|
+ int total_rock_count = game->getMotionCount(ROCK_COUNT) - self.game_info.rock;
|
|
|
+// int total_trample_count = game->getMotionCount(ROCK_COUNT) - self.game_info.trample;
|
|
|
|
|
|
//缓存pilst文件
|
|
|
NSMutableDictionary * motionCountObj = [NSMutableDictionary new];
|
|
@@ -806,9 +722,12 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
NSMutableDictionary * movements = [NSMutableDictionary new];
|
|
|
[movements setObject:motionCountObj forKey:@"movements"];
|
|
|
- NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:self.game_info.firstTime];//游戏总共经历的时长 秒数
|
|
|
+ //游戏总共经历的时长(秒数)
|
|
|
+ NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:self.game_info.firstTime];
|
|
|
[movements setObject:[NSNumber numberWithInt:durationTime] forKey:@"duration"];
|
|
|
-
|
|
|
+ //时间戳
|
|
|
+ [movements setObject: self.shoes_info.timestamp forKey:@"play_group"];
|
|
|
+
|
|
|
NSDictionary * dict = [NSDictionary dictionaryWithDictionary:movements];
|
|
|
|
|
|
//归档缓存
|