|
@@ -6,7 +6,14 @@
|
|
|
#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 "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 ()
|
|
@@ -16,43 +23,24 @@ Game *game;
|
|
|
Game *viceDeviceGame;
|
|
|
}
|
|
|
|
|
|
-//趣动跳转过来携带的mac 实际是蓝牙设备的identity
|
|
|
-@property(copy,nonatomic)NSString * macAddress;
|
|
|
-//弹窗 unity主动选择链接 主0 副1 设备
|
|
|
-@property(assign,nonatomic)DEVICE_TYPE deviceType;
|
|
|
-//游戏种类
|
|
|
-@property(assign,nonatomic)GAME_TYPE game_type;
|
|
|
-
|
|
|
-//ios_sdk
|
|
|
-@property (nonatomic,strong)IOSPlatformSDK * sdk;
|
|
|
-
|
|
|
//蓝牙弹窗
|
|
|
@property (strong, nonatomic)SearchDeviceViewController * searchDeviceVC;
|
|
|
//蓝牙外设数据源
|
|
|
@property (strong, nonatomic)NSMutableArray * deviceArray;
|
|
|
|
|
|
-//定时请求设备状态
|
|
|
+//定时查询设备状态
|
|
|
@property(nonatomic,weak)NSTimer * timer;
|
|
|
-//程序在前台还是后台
|
|
|
-@property(assign,nonatomic)int isBackGround;
|
|
|
-//鞋子是否开启游戏模式
|
|
|
-@property(nonatomic,assign)BOOL gameModel;
|
|
|
-//当局游戏时间
|
|
|
-@property(nonatomic,strong)NSDate * firstTime;
|
|
|
-//当局游戏跳起、下蹲次数
|
|
|
-@property(assign,nonatomic)int initial_jump_count;
|
|
|
-@property(assign,nonatomic)int initial_down_count;
|
|
|
-@property(nonatomic,strong)MotionCountObj * motionCountObj;
|
|
|
-
|
|
|
-//统计参数
|
|
|
-@property(assign,nonatomic)int tempCount;
|
|
|
+
|
|
|
+//鞋子信息
|
|
|
+@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];
|
|
@@ -74,131 +62,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.deviceType = DEVICETYPE_MAIN;
|
|
|
- NSString * game_type = [MYFactoryManager getGameType];
|
|
|
- self.game_type = (GAME_TYPE)[game_type intValue];
|
|
|
- self.macAddress = [MYFactoryManager getGameMac];
|
|
|
- //链接蓝牙
|
|
|
- [self initCBCentralManager];
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//unity call instance弹出蓝牙搜索框
|
|
|
--(void)searchBLEAction:(int)type{
|
|
|
-
|
|
|
- /***************************初始化蓝牙数据处理工具***************************/
|
|
|
- //主副设备:deviceType 游戏种类:game_type mac地址:macAddress
|
|
|
- self.deviceType = (DEVICE_TYPE)type;
|
|
|
- NSString * game_type = [MYFactoryManager getGameType];
|
|
|
- self.game_type = (GAME_TYPE)[game_type intValue];
|
|
|
- self.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.deviceType = (DEVICE_TYPE)type;
|
|
|
- [weakself connectPeripheral:peripheral];
|
|
|
- weakself.macAddress = peripheral.identifier.UUIDString;
|
|
|
- };
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//每重新开始一局游戏
|
|
|
--(void)gameStartInitData{
|
|
|
-
|
|
|
- //当局游戏时间
|
|
|
- self.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.gameModel = YES;
|
|
|
- //读写到特征后 添加测试弹窗
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- [DebugViewInstance inittestLabel];
|
|
|
- });
|
|
|
-
|
|
|
- //jb
|
|
|
- [DebugViewInstance clearCacheWithFilePath];
|
|
|
-
|
|
|
-// game->start
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//每结束一局游戏
|
|
|
--(void)gameEndInitData{
|
|
|
-// self.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.isBackGround = NO;
|
|
|
- //默认游戏模式关
|
|
|
- self.gameModel = NO;
|
|
|
+ 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; //后台模式
|
|
|
+// 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);
|
|
|
|
|
|
- //固定一个时间戳
|
|
|
- NSString * timestamp = [AlgorithmTool returnTimestamp];
|
|
|
- [IOS_NSUSERDEFAULT setObject:timestamp forKey:IOSSDK_TIMESTAMP];
|
|
|
- [IOS_NSUSERDEFAULT synchronize];
|
|
|
|
|
|
//监听 趣动 app group 消息 ==>> 好友邀请信息
|
|
|
CFStringRef invite = (__bridge CFStringRef)@"INVITE_NOTIFICATION";
|
|
@@ -221,25 +95,17 @@ static BTDataProcess* instance = nil;
|
|
|
[CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(enterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
|
|
//监听程序 返回 前台
|
|
|
[CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(willEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
|
|
|
- //监听程序 被kill
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(applicationWillTerminate) name:UIApplicationWillTerminateNotification object:nil];
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
-/** 程序被杀死 */
|
|
|
--(void)applicationWillTerminate{
|
|
|
- // - 监听到 app 被杀死时候的回调....
|
|
|
- NSLog(@"监听到 app 被杀死时候的回调");
|
|
|
}
|
|
|
|
|
|
-(void)enterBackground{
|
|
|
NSLog(@"leon UIApplicationDidEnterBackgroundNotification");
|
|
|
- instance.isBackGround = YES;
|
|
|
+ self.game_info.isBackGround = YES;
|
|
|
}
|
|
|
|
|
|
-(void)willEnterForeground{
|
|
|
NSLog(@"leon UIApplicationWillEnterForegroundNotification");
|
|
|
- instance.isBackGround = NO;
|
|
|
+ self.game_info.isBackGround = NO;
|
|
|
NSLog(@"程序从后台返回 重连蓝牙 peripheral.state = %ld",LEManager.peripheral.state);
|
|
|
[self initCBCentralManager];
|
|
|
}
|
|
@@ -248,6 +114,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 沙河数据
|
|
@@ -277,20 +149,96 @@ 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];
|
|
|
+
|
|
|
+ //链接动画
|
|
|
+ [[AnimationView shanreAnimationView] addAnimation];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//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];
|
|
|
+ //链接动画
|
|
|
+ [[AnimationView shanreAnimationView] addAnimation];
|
|
|
+ };
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//每重新开始一局游戏
|
|
|
+-(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{
|
|
|
|
|
|
- //建立socket链接
|
|
|
- SocketRocketUtility * install = [SocketRocketUtility sharedInstance];
|
|
|
- [install SRWebSocketOpen];
|
|
|
-
|
|
|
if (LEManager.centralManager == nil && LEManager.peripheral == nil && LEManager.vicePeripheral == nil){
|
|
|
[LEManager initCBCentralManager];
|
|
|
NSLog(@" ====================>> 未初始化 centralManager 直接开始初始化");
|
|
@@ -316,7 +264,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
case 4:{
|
|
|
NSLog(@"当前的蓝牙状态 ===>> 蓝牙已关闭");
|
|
|
if (LEManager.peripheral!=nil){
|
|
|
- [self.sdk bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
+ [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
name:LEManager.peripheral.name
|
|
|
address:LEManager.peripheral.identifier.UUIDString
|
|
|
status:CONNECT_LOST
|
|
@@ -324,7 +272,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
if (LEManager.vicePeripheral!=nil){
|
|
|
- [self.sdk bridgingDeviceAction:DEVICETYPE_VICE
|
|
|
+ [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_VICE
|
|
|
name:LEManager.vicePeripheral.name
|
|
|
address:LEManager.vicePeripheral.identifier.UUIDString
|
|
|
status:CONNECT_LOST
|
|
@@ -341,6 +289,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ //
|
|
|
|
|
|
};
|
|
|
|
|
@@ -357,11 +306,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;
|
|
@@ -372,14 +319,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];
|
|
@@ -394,7 +340,8 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
//是否是app跳转传参 区分app跳转和弹窗搜索 type=0的时候才会执行该方法 type=0的时候才会执行该方法 当时弹框的时候type==1 不执行该方法
|
|
|
-(void)ifAppJumpWithIdentifier:(CBPeripheral*)peripheral{
|
|
|
|
|
|
- if (self.macAddress!=nil && [peripheral.identifier.UUIDString isEqualToString:self.macAddress]){//app跳转过来 主动链接蓝牙
|
|
|
+// NSLog(@"self.shoes_info.macAddress = %@ peripheral.identifier.UUIDString = %@",self.shoes_info.macAddress,peripheral.identifier.UUIDString);
|
|
|
+ if (self.shoes_info.macAddress!=nil && [peripheral.identifier.UUIDString isEqualToString:self.shoes_info.macAddress]){//app跳转过来 主动链接蓝牙
|
|
|
[self connectPeripheral:peripheral];
|
|
|
}
|
|
|
|
|
@@ -406,21 +353,26 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
if(instance!=NULL && peripheral!=NULL){
|
|
|
|
|
|
- self.sdk = [IOSPlatformSDK sharedInstance];//蓝牙数据经过sdk数据转换后 ios call unity
|
|
|
- DebugViewInstance.currentTS = 1000;
|
|
|
- NSLog(@"BTDataProcess connectPeripheral self.deviceType ==>> %ld self.game_type ==>> %d mac ==>> %@",(long)self.deviceType,self.game_type,self.macAddress);
|
|
|
+ NSLog(@"BTDataProcess connectPeripheral self.game_info.deviceType ==>> %ld self.game_info.game_type ==>> %d mac ==>> %@",(long)self.game_info.deviceType,self.game_info.game_type,self.shoes_info.macAddress);
|
|
|
+
|
|
|
+ //建立socket链接
|
|
|
+ SocketRocketUtility * install = [SocketRocketUtility sharedInstance];
|
|
|
+ [install SRWebSocketOpen];
|
|
|
+
|
|
|
+ //初始化实时时间戳
|
|
|
+ DebugViewInstance.currentTS = -1;
|
|
|
|
|
|
//初始化运轨sdk
|
|
|
- if (self.deviceType==DEVICETYPE_MAIN){
|
|
|
+ if (self.game_info.deviceType==DEVICETYPE_MAIN){
|
|
|
LEManager.peripheral = peripheral;
|
|
|
- game = new Game(self.game_type);
|
|
|
- }else if (self.deviceType == DEVICETYPE_VICE){
|
|
|
+ game = new Game(self.game_info.game_type);
|
|
|
+ }else if (self.game_info.deviceType == DEVICETYPE_VICE){
|
|
|
LEManager.vicePeripheral = peripheral;
|
|
|
- viceDeviceGame = new Game(self.game_type);
|
|
|
+ viceDeviceGame = new Game(self.game_info.game_type);
|
|
|
}
|
|
|
|
|
|
//根据ios_sdk传入deviceType 链接 主/副 设备
|
|
|
- [self connectBLEManagerData:peripheral deviceType:self.deviceType];
|
|
|
+ [self connectBLEManagerData:peripheral deviceType:self.game_info.deviceType];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -429,11 +381,42 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
//链接主副设备 + 绑定特征
|
|
|
-(void)connectBLEManagerData:(CBPeripheral*)peripheral deviceType:(DEVICE_TYPE)deviceType{
|
|
|
|
|
|
- //链接动画
|
|
|
- [[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){
|
|
|
+ [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
+ name:LEManager.peripheral.name
|
|
|
+ address:LEManager.peripheral.identifier.UUIDString
|
|
|
+ status:CONNECT_LOST
|
|
|
+ electricity:0];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (LEManager.vicePeripheral!=nil&&peripheral == LEManager.vicePeripheral){
|
|
|
+ [[IOSPlatformSDK sharedInstance] 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){
|
|
|
|
|
@@ -478,9 +461,10 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
//读取特征的报文数据
|
|
|
LEManager.readValueForCharacteristicBlock = ^(CBPeripheral * _Nonnull peripheral, CBCharacteristic * _Nonnull characteristic, NSData * _Nonnull value, NSError * _Nonnull error, DEVICE_TYPE type){
|
|
|
- if ([characteristic.UUID.UUIDString isEqualToString:@"6E400003-B5A3-F393-E0A9-E50E24DCCA9E"]){//判断是不是我们设备的特征值
|
|
|
-// NSLog(@"characteristic.UUID.UUIDString = %@",characteristic.UUID.UUIDString);
|
|
|
+ // NSLog(@"characteristic.UUID.UUIDString = %@",characteristic.UUID.UUIDString);
|
|
|
+// NSLog(@"characteristic.value = %@",characteristic.value);
|
|
|
|
|
|
+ if ([characteristic.UUID.UUIDString isEqualToString:@"6E400003-B5A3-F393-E0A9-E50E24DCCA9E"]){//判断是不是我们设备的特征值
|
|
|
//每收到数据包读取一次蓝牙RSSI 无论1秒内请求多少次rssi值,原生api每秒都最多返回一次RSSI
|
|
|
[peripheral readRSSI];
|
|
|
|
|
@@ -488,27 +472,43 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if ([AlgorithmTool verificationRusult:characteristic.value]==YES){
|
|
|
|
|
|
int dataType = [AlgorithmTool dataToChar:[characteristic.value subdataWithRange:NSMakeRange(3, 1)]];//cmd类型
|
|
|
-// NSLog(@"读取特征的报文 游戏数据 %ld dataType = %d %@",(long)type,dataType,characteristic.value);
|
|
|
- if (dataType == 4){//获取主动推过来的数据
|
|
|
+// char dataType_char = [AlgorithmTool dataToChar:[characteristic.value subdataWithRange:NSMakeRange(3, 1)]];//cmd类型
|
|
|
+
|
|
|
+ if (dataType == 4){//鞋子游戏数据
|
|
|
+
|
|
|
+ if (characteristic.value.length < 64){
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ //成功打开游戏模式 隐藏加载框
|
|
|
+ [[AnimationView shanreAnimationView] stopAnimation];
|
|
|
+
|
|
|
//数据丢给算法计算轨迹
|
|
|
if (type == DEVICETYPE_MAIN&&LEManager.main_read == 0){
|
|
|
// NSLog(@"LEManager.main_read = %d",LEManager.main_read);
|
|
|
+// NSLog(@"主设备 读取特征的报文 游戏数据 %ld dataType = %d %@",(long)type,dataType,characteristic.value);
|
|
|
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);
|
|
|
+// NSLog(@"副设备 读取特征的报文 游戏数据 %ld dataType = %d %@",(long)type,dataType,characteristic.value);
|
|
|
LEManager.vice_read = 1;
|
|
|
[self viceShoseSDK:characteristic.value];
|
|
|
}
|
|
|
|
|
|
- }else if(dataType == -95){//读取基本信息
|
|
|
+ }else if(dataType == -95){//鞋子状态信息
|
|
|
+
|
|
|
+ if (characteristic.value.length<30){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
//嵌入式原始数据解析 --->> 回调蓝牙状态/电量给unity
|
|
|
BTDataAnalysis * anly = [BTDataAnalysis new];
|
|
|
[anly analysisCharacteristic:characteristic.value deviceType:type];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -520,50 +520,11 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
//蓝牙更新RSSI
|
|
|
LEManager.rssiBlock = ^(NSNumber * _Nonnull RSSI){
|
|
|
- DebugViewInstance.RSSI = RSSI;
|
|
|
+ LEManager.RSSI = RSSI;
|
|
|
// 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 ===============================================>> 读取特征后 鞋子打开游戏模式 & 激光开关 &查询鞋子蓝牙状态 & 主设备初始化缓存游戏步数
|
|
@@ -579,7 +540,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];
|
|
|
|
|
|
}
|
|
@@ -587,7 +548,7 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
//定时发送数据
|
|
|
-(void)timingDataTransmission:(NSString*)style{
|
|
|
|
|
|
- if (self.isBackGround){//程序在后台
|
|
|
+ if (self.game_info.isBackGround){//程序在后台
|
|
|
}else{//程序在前台
|
|
|
[BTDataSendInstance startGameModel];
|
|
|
}
|
|
@@ -598,76 +559,83 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
#pragma mark ===============================================>> 主设备 报文数据解析后 -- 调用蓝牙鞋子SDK装换数据 -- ios call unity 更新游戏动作
|
|
|
-(void)shoseSDK:(NSData*)characteristic{
|
|
|
|
|
|
- if (self.gameModel==YES){//当前是游戏模式
|
|
|
+// NSLog(@"characteristic = %@",characteristic);
|
|
|
+
|
|
|
+ if (self.shoes_info.gameModel==YES){//当前是游戏模式
|
|
|
|
|
|
/********************初始化 运动轨迹算法 SDK *****************/
|
|
|
- // NSLog(@"characteristic = %@",characteristic);
|
|
|
NSData * validData= [characteristic subdataWithRange:NSMakeRange(4, characteristic.length-4)];
|
|
|
Byte * buff = (Byte*)[validData bytes];
|
|
|
game->GameProcessBuf(buff, (int)validData.length);
|
|
|
|
|
|
+ /********************剑波 & 威严 要的图表数据 *****************/
|
|
|
+ NSString * message = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
|
|
|
+ [DebugViewInstance 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(@" 主设备 =================================== 蹲下去 ");
|
|
|
}
|
|
|
- // }
|
|
|
-
|
|
|
- /******************步频数据处理 + 回调*****************/
|
|
|
- int leftStepStatus = game->getStepStatus(LEFT_FOOT);
|
|
|
- int leftStepFreq = game->getStepFreq(LEFT_FOOT);
|
|
|
- int leftStepCount = game->getStepCount(LEFT_FOOT);
|
|
|
- int rightStepStatus = game->getStepStatus(RIGHT_FOOT);
|
|
|
- int rightStepFreq = game->getStepFreq(RIGHT_FOOT);
|
|
|
- int rightStepCount = game->getStepCount(RIGHT_FOOT);
|
|
|
-
|
|
|
- /******************玩家当前朝向 用户赛车*****************/
|
|
|
- // 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_type == GAME_TYPE_RUN){
|
|
|
- [self.sdk bridgingStepAction:DEVICETYPE_MAIN leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];
|
|
|
- }
|
|
|
- //左右脚动作
|
|
|
- [self.sdk bridgingMotionAction:DEVICETYPE_MAIN left:motionLeft right:motionRight];
|
|
|
-
|
|
|
- //当局运动数据缓存
|
|
|
- [self cacheAllMotionCount:leftStepCount+rightStepCount];
|
|
|
-
|
|
|
- //测试数据
|
|
|
- [self tempTest:rightStepFreq leftStepFreq:leftStepFreq];
|
|
|
-
|
|
|
+
|
|
|
+ /******************当局鞋子子动作状态数据 缓存*****************/
|
|
|
+ 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];
|
|
|
+
|
|
|
+ /******************鞋子动作状态数据 实时回调*****************/
|
|
|
+ //左右脚动作:所有游戏都需要回调
|
|
|
+ [[IOSPlatformSDK sharedInstance] bridgingMotionAction:DEVICETYPE_MAIN left:motionLeft right:motionRight];
|
|
|
+
|
|
|
+ //步频状态:只有跑酷回调
|
|
|
+ if (self.game_info.game_type == GAME_TYPE_RUN){
|
|
|
+ [[IOSPlatformSDK sharedInstance] 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{//当前是交互模式
|
|
|
|
|
|
// int interaction = game->getInteractionCMD();
|
|
|
//// NSLog(@"主设备 当前的脚步交互动作 ===== >> %d",interaction);
|
|
|
// //游戏交互
|
|
|
-// [self.sdk bridgingInteraction:DEVICETYPE_MAIN code:interaction];
|
|
|
+// [[IOSPlatformSDK sharedInstance] bridgingInteraction:DEVICETYPE_MAIN code:interaction];
|
|
|
// //自定义弹窗界面交互
|
|
|
// if (interaction!=-1){
|
|
|
// NSLog(@"BTDataProcess 有效交互动作 ===>> %d",interaction);
|
|
@@ -679,68 +647,6 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
}
|
|
|
|
|
|
-//算法需要的测试数据
|
|
|
--(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 > 20){
|
|
|
- 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{
|
|
@@ -770,9 +676,10 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
int ivce_motionJump = result[2];//jump
|
|
|
int ivce_motionDown = result[3];//down
|
|
|
|
|
|
-// if (motionLeft==-1 && motionRight == -1&& ivce_motionJump == -1&& ivce_motionDown == -1){//无效动作
|
|
|
-// return;
|
|
|
-// }else{
|
|
|
+ if (motionLeft==-1 && motionRight == -1&& ivce_motionJump == -1&& ivce_motionDown == -1){//无效动作
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+
|
|
|
//跳跃和蹲下的动作 双脚是同步的
|
|
|
if (ivce_motionJump == MOTION_JUMP){
|
|
|
motionLeft = ivce_motionJump;
|
|
@@ -786,13 +693,13 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
//ios call unity
|
|
|
- if (self.game_type == GAME_TYPE_RUN){//跑酷才需要回调
|
|
|
- [self.sdk bridgingStepAction:DEVICETYPE_VICE leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];//副设备左右脚速度 步频
|
|
|
+ if (self.game_info.game_type == GAME_TYPE_RUN){//跑酷才需要回调
|
|
|
+ [[IOSPlatformSDK sharedInstance] bridgingStepAction:DEVICETYPE_VICE leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];//副设备左右脚速度 步频
|
|
|
}
|
|
|
//ios call unity
|
|
|
- [self.sdk bridgingMotionAction:DEVICETYPE_VICE left:motionLeft right:motionRight];//副设备左右脚动作
|
|
|
-
|
|
|
- //}
|
|
|
+ [[IOSPlatformSDK sharedInstance] bridgingMotionAction:DEVICETYPE_VICE left:motionLeft right:motionRight];//副设备左右脚动作
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -804,17 +711,18 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
return _deviceArray;;
|
|
|
}
|
|
|
|
|
|
-#pragma mark ===============================================>>玩游戏过程中缓存 动作数据 和时间戳 数据存入plist
|
|
|
--(void)cacheAllMotionCount:(int)totalStep{
|
|
|
+#pragma mark ===============================================>> 玩游戏过程中缓存 动作数据 和时间戳 数据存入plist
|
|
|
+-(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];
|
|
@@ -829,9 +737,12 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
NSMutableDictionary * movements = [NSMutableDictionary new];
|
|
|
[movements setObject:motionCountObj forKey:@"movements"];
|
|
|
- NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:self.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];
|
|
|
|
|
|
//归档缓存
|
|
@@ -841,3 +752,4 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
@end
|
|
|
+
|