|
@@ -3,32 +3,25 @@
|
|
|
// Unity-iPhone
|
|
|
//
|
|
|
// Created by leon on 2021/2/3.
|
|
|
-//
|
|
|
-
|
|
|
-
|
|
|
#import "BTDataProcess.h"
|
|
|
#import "IOSPlatformSDK.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 ()<NSURLSessionDataDelegate>
|
|
|
+#include "Game.h"
|
|
|
|
|
|
-@property (strong, nonatomic)NSMutableArray * deviceArray;/**< 蓝牙设备个数 */
|
|
|
+//#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 ()<NSURLSessionDataDelegate>
|
|
|
+{
|
|
|
+@private
|
|
|
+Game *game;
|
|
|
+Game *viceDeviceGame;
|
|
|
+}
|
|
|
+@property (strong, nonatomic)NSMutableArray * deviceArray;//蓝牙外设数据源
|
|
|
@property (nonatomic,strong)IOSPlatformSDK * sdk;//ios_sdk
|
|
|
-@property (nonatomic,strong)GameObjc * game ;//主设备蓝牙算法sdk
|
|
|
-@property (nonatomic,strong)GameObjc * viceDeviceGame ;//副设备设备蓝牙算法sdk
|
|
|
-@property(nonatomic,weak)NSTimer * timer;//定时器 定时请求主、副设备电量
|
|
|
-@property(nonatomic,assign)BOOL gameModel;//是否开启游戏模式
|
|
|
-
|
|
|
-/*****测试*******/
|
|
|
-@property (nonatomic,strong)UILabel * testLabel;//调试框
|
|
|
-//当前的时间戳+丢包
|
|
|
-@property (nonatomic,assign)int tempTs;
|
|
|
-@property (nonatomic,assign)int loss;
|
|
|
-@property (nonatomic,assign)int totalPackages;
|
|
|
-@property (nonatomic,strong)NSString * dataString;//缓存plist
|
|
|
-@property (nonatomic,strong)NSString * tempStepString;//缓存plist
|
|
|
-
|
|
|
-/*****测试*******/
|
|
|
-
|
|
|
+@property(nonatomic,weak)NSTimer * timer;//定时请求设备状态
|
|
|
+@property(nonatomic,assign)BOOL gameModel;//鞋子是否开启游戏模式
|
|
|
+@property(nonatomic,strong)NSDate * firstTime;//当局游戏时间
|
|
|
+//当局游戏跳起、下蹲次数
|
|
|
+@property(assign,nonatomic)int initial_jump_count;
|
|
|
+@property(assign,nonatomic)int initial_down_count;
|
|
|
@end
|
|
|
|
|
|
@implementation BTDataProcess
|
|
@@ -37,116 +30,57 @@
|
|
|
//单例静态
|
|
|
static BTDataProcess* instance = nil;
|
|
|
+(instancetype)sharedInstance{
|
|
|
-// NSLog(@"创建单例一次 1");
|
|
|
return [[self alloc] init];
|
|
|
}
|
|
|
-
|
|
|
+ (instancetype)allocWithZone:(struct _NSZone *)zone{
|
|
|
-// NSLog(@"创建单例一次 2");
|
|
|
static dispatch_once_t onceToken;
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
instance = [super allocWithZone:zone];
|
|
|
});
|
|
|
return instance;
|
|
|
}
|
|
|
-
|
|
|
- (instancetype)init{
|
|
|
-// NSLog(@"创建单例一次 3");
|
|
|
static dispatch_once_t onceToken;
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
instance = [super init];
|
|
|
+ //后台模式
|
|
|
self.isBackGround = NO;
|
|
|
- [self initNotification];
|
|
|
+ //默认游戏模式关
|
|
|
+ self.gameModel = NO;
|
|
|
});
|
|
|
return instance;
|
|
|
}
|
|
|
|
|
|
-#pragma mark ===============================================>> 注册通知
|
|
|
--(void)initNotification{
|
|
|
-
|
|
|
- //默认游戏模式关
|
|
|
- self.gameModel = NO;
|
|
|
- //监听unity --> 开始游戏/结束游戏/震动
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(gameStartInitData) name:@"gameStartInitData" object:nil];
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(gameEndInitData:) name:@"gameEndInitData" object:nil];
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(vibrationAction:) name:@"vibrationAction" object:nil];
|
|
|
- //监听程序从后台返回 系统方法
|
|
|
-// [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
|
|
-
|
|
|
- //监听 趣动 app group 消息
|
|
|
- CFStringRef strRef = (__bridge CFStringRef)@"DISCONNECT_BLE";
|
|
|
- CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
|
|
|
- NULL,
|
|
|
- disConnectBle,
|
|
|
- strRef,
|
|
|
- NULL,
|
|
|
- CFNotificationSuspensionBehaviorDeliverImmediately);
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//趣动APP吊起 发送通知->断开游戏的所有的蓝牙连接 (C语言函数)
|
|
|
-//C语言函数内 只能用指针instance调用实例不能用self
|
|
|
-void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
|
|
|
- [instance disConnedctBle];
|
|
|
-}
|
|
|
-
|
|
|
-//断开蓝牙
|
|
|
+#pragma mark ===============================================>> public method
|
|
|
+//趣动 ==>> 断开蓝牙
|
|
|
-(void)disConnedctBle{
|
|
|
- NSLog(@"BTDataProcess 通知断开蓝牙操作");
|
|
|
+ NSLog(@"趣动 call 断开蓝牙");
|
|
|
[LEManager cancelPeripheralConnection];
|
|
|
}
|
|
|
|
|
|
-//监听程序从后台返回
|
|
|
--(void)applicationWillEnterForeground{
|
|
|
-
|
|
|
- NSLog(@"BTDataProcess 收到程序从后台返回 peripheral.state = %ld",LEManager.peripheral.state);
|
|
|
-// if (LEManager.peripheral!=nil&&LEManager.peripheral.state!= CBPeripheralStateConnected){//蓝牙不为空 且蓝牙断开链接(有三种情况)
|
|
|
-// [self connectPeripheral:LEManager.peripheral];//蓝牙重链接
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (LEManager.vicePeripheral!=nil&&LEManager.vicePeripheral.state != CBPeripheralStateConnected){//蓝牙不为空 且蓝牙断开链接
|
|
|
-// [self connectPeripheral:LEManager.vicePeripheral];//蓝牙重链接
|
|
|
-// }
|
|
|
-
|
|
|
- [self initCBCentralManager];
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//监听通知开始游戏
|
|
|
+//每重新开始一局游戏
|
|
|
-(void)gameStartInitData{
|
|
|
-
|
|
|
-// NSLog(@"通知开始游戏 --> BTDataProcess");
|
|
|
+ //当局游戏时间
|
|
|
+ self.firstTime = [NSDate date];
|
|
|
+ //当局动作数据
|
|
|
+ self.initial_down_count = 0;
|
|
|
+ self.initial_jump_count = 0;
|
|
|
+ //游戏模式 ==>> 回调剑波sdk数据
|
|
|
self.gameModel = YES;
|
|
|
- //反馈->蓝牙sdk
|
|
|
-// [self.game start];
|
|
|
-
|
|
|
+ //读写到特征后 添加测试弹窗
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+// [DebugViewInstance inittestLabel];
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
-//监听通知结束游戏
|
|
|
--(void)gameEndInitData:(NSNotification*)notification{
|
|
|
-
|
|
|
-// NSLog(@"通知结束游戏 --> BTDataProcess");
|
|
|
+//每结束一局游戏
|
|
|
+-(void)gameEndInitData{
|
|
|
self.gameModel = NO;
|
|
|
- //反馈->蓝牙sdk
|
|
|
-// [self.game end];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//监听通知震动
|
|
|
--(void)vibrationAction:(NSNotification*)notification{
|
|
|
-
|
|
|
- //unity回调数据
|
|
|
- NSDictionary * notificationDict = notification.userInfo;
|
|
|
-// NSLog(@"弹出视图事件notificationDict == %@",notificationDict);
|
|
|
- NSNumber * typeNumber = [notificationDict objectForKey:@"type"];
|
|
|
- NSNumber * durationNumber = [notificationDict objectForKey:@"duration"];
|
|
|
- int deviceType = [typeNumber intValue];
|
|
|
- int duration = [durationNumber intValue];
|
|
|
-// NSLog(@"通知游戏震动 --> BTDataProcess %d",deviceType);
|
|
|
- [self vibration:(DEVICE_TYPE)deviceType duration:duration];
|
|
|
- //每次踩对就反馈->蓝牙sdk
|
|
|
-// [self.game isBingo];
|
|
|
-
|
|
|
+-(void)vibrationAction:(int)type duration:(int)duration{
|
|
|
+ [BTDataSendInstance vibration:(DEVICE_TYPE)type duration:duration];
|
|
|
}
|
|
|
|
|
|
#pragma mark ============================================================== leon Ble manager
|
|
@@ -198,8 +132,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
break;
|
|
|
case 5:{
|
|
|
-// NSLog(@"当前的蓝牙状态 ===>> 蓝牙已开启");//蓝牙已开启
|
|
|
- //扫描蓝牙外设
|
|
|
+ NSLog(@"当前的蓝牙状态 ===>> 蓝牙已开启");//蓝牙已开启
|
|
|
[LEManager scanForPeripheralsWithServices:nil options:nil];
|
|
|
}
|
|
|
break;
|
|
@@ -214,20 +147,15 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
LEManager.discoverPeripheralBlock = ^(CBCentralManager * _Nonnull central, CBPeripheral * _Nonnull peripheral, NSDictionary * _Nonnull advertisementData, NSNumber * _Nonnull RSSI){
|
|
|
// NSLog(@"扫描发现蓝牙设备advertisementData = %@",advertisementData);
|
|
|
NSString *advertiseName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
|
|
|
-// if ([advertiseName hasPrefix:@"SH_"]){
|
|
|
-// NSLog(@"通过 manufacturerData 扫描出来的蓝牙 ===>> %@",advertiseName);
|
|
|
-// }
|
|
|
+
|
|
|
peripheral.advertiseName = advertiseName;
|
|
|
|
|
|
if ([advertiseName hasPrefix:@"SH_"]){//SH_DANCE BLE_LOOP Shoes_4530 Shoes_2A74
|
|
|
|
|
|
// NSLog(@"主设备扫描发现有效的蓝牙设备 =============== %@ identifier == %@",peripheral.name,peripheral.identifier.UUIDString);
|
|
|
-// NSLog(@"主设备扫描发现有效的蓝牙设备 =============== %@ identifier == %@",peripheral,peripheral.identifier.UUIDString);
|
|
|
|
|
|
if (self.deviceArray.count == 0){//数据源为0
|
|
|
|
|
|
- // NSLog(@"add 扫描发现蓝牙设备 %@",peripheral.name);
|
|
|
-
|
|
|
[self.deviceArray addObject:peripheral];
|
|
|
//判断扫描到外设之后是否要链接蓝牙
|
|
|
[self ifAppJumpWithIdentifier:peripheral];
|
|
@@ -235,7 +163,6 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}else{
|
|
|
|
|
|
BOOL isExist = NO;
|
|
|
-
|
|
|
for (int i = 0; i < self.deviceArray.count; i++){
|
|
|
CBPeripheral *per = [self.deviceArray objectAtIndex:i];
|
|
|
if ([per.identifier.UUIDString isEqualToString:peripheral.identifier.UUIDString]){
|
|
@@ -279,38 +206,16 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if(instance!=NULL && peripheral!=NULL){
|
|
|
|
|
|
self.sdk = [IOSPlatformSDK sharedInstance];//蓝牙数据经过sdk数据转换后 ios call unity
|
|
|
-
|
|
|
- //app游戏列表id转为bobo sdk需要的游戏id
|
|
|
- switch (self.game_id){
|
|
|
- case 0://demo
|
|
|
- self.game_id = GAME_TYPE_DEMO;
|
|
|
- break;
|
|
|
- case 1://跳舞
|
|
|
- self.game_id = GAME_TYPE_DANCE;
|
|
|
- break;
|
|
|
- case 2://赛达尔传说
|
|
|
- self.game_id = GAME_TYPE_SDAER;
|
|
|
- break;
|
|
|
- case 3://跑酷
|
|
|
- self.game_id = GAME_TYPE_RUN;
|
|
|
- break;
|
|
|
- case 4://测试demo
|
|
|
- self.game_id = GAME_TYPE_DEMO;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ 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.deviceType ==>> %ld self.game_id ==>> %d mac ==>> %@",(long)self.deviceType,self.game_id,self.macAddress);
|
|
|
-
|
|
|
//初始化运轨sdk
|
|
|
if (self.deviceType==DEVICETYPE_MAIN){
|
|
|
LEManager.peripheral = peripheral;
|
|
|
- self.game = [[GameObjc alloc] initWithGametype:self.game_id];
|
|
|
+ game = new Game(self.game_type);
|
|
|
}else if (self.deviceType == DEVICETYPE_VICE){
|
|
|
LEManager.vicePeripheral = peripheral;
|
|
|
- self.viceDeviceGame = [[GameObjc alloc] initWithGametype:self.game_id];
|
|
|
+ viceDeviceGame = new Game(self.game_type);
|
|
|
}
|
|
|
|
|
|
//根据ios_sdk传入deviceType 链接 主/副 设备
|
|
@@ -338,7 +243,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if (cha.properties == 12){//写
|
|
|
|
|
|
LEManager.write = cha;
|
|
|
- [self initGameAction:DEVICETYPE_MAIN];
|
|
|
+ [self initGameAction:deviceType];
|
|
|
|
|
|
}else if (cha.properties == 16){//读
|
|
|
|
|
@@ -357,8 +262,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if (cha.properties == 12){//写
|
|
|
|
|
|
LEManager.viceWrite = cha;
|
|
|
-
|
|
|
- [self initGameAction:DEVICETYPE_VICE];
|
|
|
+ [self initGameAction:deviceType];
|
|
|
|
|
|
}else if (cha.properties == 16){//读
|
|
|
|
|
@@ -376,6 +280,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if ([characteristic.UUID.UUIDString isEqualToString:@"6E400003-B5A3-F393-E0A9-E50E24DCCA9E"]){//判断是不是我们设备的特征值
|
|
|
// NSLog(@"characteristic.UUID.UUIDString = %@",characteristic.UUID.UUIDString);
|
|
|
[self verifyData:characteristic deviceType:type];
|
|
|
+ [peripheral readRSSI];
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -383,67 +288,67 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
LEManager.writeToCharacteristicBlock = ^(CBPeripheral * _Nonnull peripheral,CBCharacteristic * _Nonnull characteristic, NSError * _Nonnull error, DEVICE_TYPE type){
|
|
|
};
|
|
|
|
|
|
+ //蓝牙更新RSSI
|
|
|
+ LEManager.rssiBlock = ^(NSNumber * _Nonnull RSSI){
|
|
|
+ DebugViewInstance.RSSI = RSSI;
|
|
|
+// NSLog(@"self.RSSI = %@",self.RSSI);
|
|
|
+ };
|
|
|
+
|
|
|
//蓝牙连接成功
|
|
|
LEManager.successfulBlock = ^(CBPeripheral * _Nonnull peripheral){
|
|
|
-// if (peripheral == LEManager.peripheral){
|
|
|
[[AnimationView shanreAnimationView] stopAnimation];
|
|
|
};
|
|
|
|
|
|
-// //蓝牙连接失败
|
|
|
-// LEManager.connectFailureBlock = ^(NSError * _Nonnull error){
|
|
|
-// if (peripheral == LEManager.peripheral){
|
|
|
-// [[AnimationView shanreAnimationView] addAnimation];
|
|
|
-// }
|
|
|
-// };
|
|
|
-//
|
|
|
+ //蓝牙连接失败
|
|
|
+ LEManager.connectFailureBlock = ^(NSError * _Nonnull error){
|
|
|
+ NSLog(@"蓝牙链接失败");
|
|
|
+ };
|
|
|
+
|
|
|
//蓝牙连接丢失
|
|
|
LEManager.disConnectBlock = ^(CBPeripheral * _Nonnull peripheral, NSError * _Nonnull error){
|
|
|
- if (peripheral == LEManager.peripheral){
|
|
|
- if (LEManager.peripheral!=nil){
|
|
|
-
|
|
|
- [self.sdk bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
- name:LEManager.peripheral.name
|
|
|
- address:LEManager.peripheral.identifier.UUIDString
|
|
|
- status:CONNECT_LOST
|
|
|
- electricity:0];
|
|
|
-
|
|
|
- }
|
|
|
- if (LEManager.vicePeripheral!=nil){
|
|
|
-
|
|
|
- [self.sdk bridgingDeviceAction:DEVICETYPE_VICE
|
|
|
- name:LEManager.vicePeripheral.name
|
|
|
- address:LEManager.vicePeripheral.identifier.UUIDString
|
|
|
- status:CONNECT_LOST
|
|
|
- electricity:0];
|
|
|
- }
|
|
|
+
|
|
|
+ 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 ===============================================>> 读取特征后 鞋子打开游戏模式 & 激光开关 &查询鞋子蓝牙状态 & 主设备初始化缓存游戏步数
|
|
|
-(void)initGameAction:(DEVICE_TYPE)deviceType{
|
|
|
|
|
|
- //初始化缓存动作数据
|
|
|
- if (deviceType==DEVICETYPE_MAIN){
|
|
|
- self.jump_count = 0;
|
|
|
- self.crouch_count = 0;
|
|
|
- self.step_count = 0;
|
|
|
- }else if (deviceType ==DEVICETYPE_VICE){
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
//开启游戏模式&查询设备信息 初始化步数数据
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
[self timingDataTransmission:@"dispatch_after"];
|
|
|
});
|
|
|
|
|
|
+ //定时开启游戏模式 & 查询设备信息 & 开启激光检测下蹲
|
|
|
if (self.timer!=nil){
|
|
|
[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];
|
|
|
|
|
|
}
|
|
@@ -455,14 +360,14 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
}else{//程序在前台
|
|
|
// NSLog(@"定时发送 == %@",style);
|
|
|
- [self startGameModel];
|
|
|
-// [self laser:1];
|
|
|
+ [BTDataSendInstance startGameModel];
|
|
|
}
|
|
|
|
|
|
- [self queryDevideInfo];
|
|
|
+ [BTDataSendInstance queryDevideInfo];
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
#pragma mark ===============================================>> 校验 & 报文数据解析
|
|
|
-(void)verifyData:(CBCharacteristic*)characteristic deviceType:(DEVICE_TYPE)deviceType{
|
|
|
|
|
@@ -486,7 +391,6 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
-(void)analysisCharacteristic:(NSData*)characteristic deviceType:(DEVICE_TYPE)deviceType{
|
|
|
|
|
|
// NSLog(@"接收到的数据data = %@",characteristic);
|
|
|
-
|
|
|
int frameHead = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(0, 1)]];//帧头数据aa
|
|
|
int messageLength = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(1, 1)]];//报文长度
|
|
|
int messageLengthNegation = ~messageLength;//报文长度取反
|
|
@@ -558,65 +462,36 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
int rssi = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(53, 1)]];//rssi 信号强度
|
|
|
int ts = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(54, 1)]];;//ts 时间戳
|
|
|
-
|
|
|
int right_press = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(55, 2)]];//3 29新增 右鞋压力
|
|
|
int left_press = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(57, 2)]];//3 29新增 左鞋压力
|
|
|
int frameCheck = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(59, 1)]];//校验位
|
|
|
-
|
|
|
- //开启剑波sdk数据字符串存储
|
|
|
- [self ocGetGameDataStr:characteristic];
|
|
|
-
|
|
|
+
|
|
|
if (deviceType==DEVICETYPE_MAIN){//主设备
|
|
|
-
|
|
|
// NSLog(@"主设备 接收到 鞋子动作数据 data = %@",characteristic);
|
|
|
//调取鞋子SDK
|
|
|
- [self shoseSDKRight_pos:right_pos Right_att:right_att Right_acc:righrAcc LeftPos:left_pos Left_att:left_att Left_acc:left_acc ts:ts rightZupt:rightZupt leftZupt:leftZupt jump:jump down:down rssi:rssi girlShoes:girlShoes right_press:right_press left_press:left_press];
|
|
|
+ [self shoseSDKRight_pos:right_pos Right_att:right_att Right_acc:righrAcc LeftPos:left_pos Left_att:left_att Left_acc:left_acc ts:ts rightZupt:rightZupt leftZupt:leftZupt jump:jump down:down rssi:rssi girlShoes:girlShoes right_press:right_press left_press:left_press characteristic:characteristic];
|
|
|
|
|
|
}else if (deviceType==DEVICETYPE_VICE){//副设备动作数据
|
|
|
-
|
|
|
-// NSLog(@"副设备 接收到 鞋子动作数据 data = %@",characteristic);
|
|
|
//调取鞋子SDK
|
|
|
- [self viceShoseSDKRight_pos:right_pos Right_att:right_att Right_acc:righrAcc LeftPos:left_pos Left_att:left_att Left_acc:left_acc ts:ts rightZupt:rightZupt leftZupt:leftZupt jump:jump down:down rssi:rssi girlShoes:girlShoes right_press:right_press left_press:left_press];
|
|
|
-
|
|
|
+ [self viceShoseSDKRight_pos:right_pos Right_att:right_att Right_acc:righrAcc LeftPos:left_pos Left_att:left_att Left_acc:left_acc ts:ts rightZupt:rightZupt leftZupt:leftZupt jump:jump down:down rssi:rssi girlShoes:girlShoes right_press:right_press left_press:left_press characteristic:characteristic];
|
|
|
}
|
|
|
-
|
|
|
- }else if (dataType == -95){//获取的是查询的数据 char-->int a1 = -95
|
|
|
-
|
|
|
- if (characteristic.length == 74){//A1+0 >> 0: 设备基本信息 ==>> 预留参数 趣动app用 sdk暂未调用
|
|
|
-
|
|
|
-// NSString *deviceModel = [[NSString alloc] initWithData:[characteristic subdataWithRange:NSMakeRange(5, 18)] encoding:NSUTF8StringEncoding];
|
|
|
-// NSString *softwareVer = [AlgorithmTool hexadecimalString:[characteristic subdataWithRange:NSMakeRange(69, 2)]];//0102
|
|
|
-// NSString *hardwareVer = [AlgorithmTool hexadecimalString:[characteristic subdataWithRange:NSMakeRange(71, 2)]];//0104
|
|
|
-
|
|
|
- }else if (characteristic.length == 26){//A1+1 >> 1: 设备数据(左鞋,右鞋) aa 14 eb a1 01 64 00 1a 0000981d 64 00 17 00000000 f9
|
|
|
-
|
|
|
+
|
|
|
+ }else if (dataType == -95 && characteristic.length == 26){//获取的是查询的数据 char-->int a1 = -95
|
|
|
+ //A1+1 >> 1: 设备数据(左鞋,右鞋) aa 14 eb a1 01 64 00 1a 0000981d 64 00 17 00000000 f9
|
|
|
int leftElectricity = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(5, 1)]];
|
|
|
-// int leftTempreature = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(6, 1)]];
|
|
|
-// int leftPressure = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(7, 4)]];
|
|
|
-// int leftStepCount = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(11, 4)]];
|
|
|
-// int rightElectricity = [self dataToInt:[characteristic subdataWithRange:NSMakeRange(12, 1)]];
|
|
|
int rightElectricity = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(15, 1)]];//龙哥新协议
|
|
|
-// int rightTempreature = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(16, 1)]];
|
|
|
-// int rightPressure = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(17, 4)]];
|
|
|
-// int rightStepCount = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(21, 4)]];
|
|
|
|
|
|
- [self inittestLabel];
|
|
|
-
|
|
|
- if (deviceType==DEVICETYPE_MAIN){//主设备
|
|
|
-
|
|
|
- NSLog(@"主设备 接收到 鞋子硬件数据 data 26 = %@ 电量 %d %d",characteristic,leftElectricity,rightElectricity);
|
|
|
-
|
|
|
+ if (deviceType==DEVICETYPE_MAIN && LEManager.peripheral!=nil){//主设备
|
|
|
+// NSLog(@"主设备 接收到 鞋子硬件数据 data 26 = %@ 电量 %d %d %@ %@",characteristic,leftElectricity,rightElectricity,LEManager.peripheral.name,LEManager.peripheral.identifier.UUIDString);
|
|
|
//主 设备定时器 60秒调一次 /******************ios call unity*****************/
|
|
|
[self.sdk bridgingDeviceAction:DEVICETYPE_MAIN
|
|
|
name:LEManager.peripheral.name
|
|
|
address:LEManager.peripheral.identifier.UUIDString
|
|
|
status:CONNECT_ED
|
|
|
electricity:leftElectricity<=rightElectricity?leftElectricity:rightElectricity];
|
|
|
-
|
|
|
- }else if (deviceType==DEVICETYPE_VICE){//副设备
|
|
|
-
|
|
|
- NSLog(@"副设备 接收到 鞋子硬件数据 26 = %@ 电量 %d %d",characteristic,leftElectricity,rightElectricity);
|
|
|
-
|
|
|
+
|
|
|
+ }else if (deviceType==DEVICETYPE_VICE && LEManager.vicePeripheral!=nil){//副设备
|
|
|
+// NSLog(@"副设备 接收到 鞋子硬件数据 26 = %@ 电量 %d %d",characteristic,leftElectricity,rightElectricity);
|
|
|
//副 设备定时器 60秒调一次 /******************ios call unity*****************/
|
|
|
[self.sdk bridgingDeviceAction:DEVICETYPE_VICE
|
|
|
name:LEManager.vicePeripheral.name
|
|
@@ -625,11 +500,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
electricity:leftElectricity<=rightElectricity?leftElectricity:rightElectricity];
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#pragma mark ===============================================>> 主设备 报文数据解析后 -- 调用蓝牙鞋子SDK装换数据 -- ios call unity 更新游戏动作
|
|
@@ -647,46 +518,28 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
rssi:(int)rssi
|
|
|
girlShoes:(int)girlShoes
|
|
|
right_press:(int)right_press
|
|
|
- left_press:(int)left_press{
|
|
|
+ left_press:(int)left_press
|
|
|
+ characteristic:(NSData*)characteristic{
|
|
|
|
|
|
/********************初始化 运动轨迹算法 SDK *****************/
|
|
|
- [self.game gameProcess:ts
|
|
|
- rightPos:right_pos
|
|
|
- rightAtt:right_att
|
|
|
- rightAcc:right_acc
|
|
|
- rightZupt:rightZupt
|
|
|
- right_press:right_press
|
|
|
- leftPos:left_pos
|
|
|
- leftAtt:left_att
|
|
|
- leftAcc:left_acc
|
|
|
- leftZupt:leftZupt
|
|
|
- left_press:left_press
|
|
|
- jump:jump
|
|
|
- down:down
|
|
|
- rssi:rssi
|
|
|
- girl_shoes:girlShoes];
|
|
|
+ //游戏数据
|
|
|
+ NSData * validData= [characteristic subdataWithRange:NSMakeRange(4, characteristic.length-4)];
|
|
|
+ Byte * buff = (Byte*)[validData bytes];
|
|
|
+ game->GameProcessBuf(buff, (int)validData.length);
|
|
|
+
|
|
|
int length = 4;
|
|
|
int result[length];
|
|
|
- [self.game getGameResult:result];
|
|
|
-// NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
|
|
|
-
|
|
|
+ game->getGameResult(result);
|
|
|
+ // NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
|
|
|
+
|
|
|
/******************步频数据处理 + 回调*****************/
|
|
|
- int leftStepStatus = [self.game getStepStatus:LEFT_FOOT_OC];
|
|
|
- int leftStepFreq = [self.game getStepFreq:LEFT_FOOT_OC];
|
|
|
- int leftStepCount = [self.game getStepCount:LEFT_FOOT_OC];
|
|
|
- int rightStepStatus = [self.game getStepStatus:RIGHT_FOOT_OC];
|
|
|
- int rightStepFreq = [self.game getStepFreq:RIGHT_FOOT_OC];
|
|
|
- int rightStepCount = [self.game getStepCount:RIGHT_FOOT_OC];
|
|
|
- //ios call unity
|
|
|
- if (self.game_id == GAME_TYPE_RUN){//跑酷才需要回调
|
|
|
- [self.sdk bridgingStepAction:DEVICETYPE_MAIN leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];//左右脚速度 步频
|
|
|
- }
|
|
|
- //数据回调缓存
|
|
|
- if (self.allMotionCountBLock){
|
|
|
- self.step_count = leftStepCount+rightStepCount;
|
|
|
- self.allMotionCountBLock(self.jump_count, self.crouch_count, leftStepCount+rightStepCount);
|
|
|
- }
|
|
|
-
|
|
|
+ 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 motionLeft = result[0];//左脚的动作
|
|
|
int motionRight = result[1];//右脚的动作
|
|
@@ -699,50 +552,98 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if (motionJump == MOTION_JUMP){
|
|
|
motionLeft = motionJump;
|
|
|
motionRight = motionJump;
|
|
|
- self.jump_count++;
|
|
|
NSLog(@" 主设备 ================================== 跳起来 ");
|
|
|
}
|
|
|
+
|
|
|
if (motionDown == MOTION_DOWN){
|
|
|
motionLeft = motionDown;
|
|
|
motionRight = motionDown;
|
|
|
- self.crouch_count++;
|
|
|
NSLog(@" 主设备 =================================== 蹲下去 ");
|
|
|
}
|
|
|
- //ios call unity
|
|
|
+// }
|
|
|
+
|
|
|
+ /****************** ios call unity*****************/
|
|
|
if (self.gameModel==YES){//当前是游戏模式
|
|
|
-// NSLog(@"主设备 当前是开启游戏模式 ===== >> %d",self.gameModel);
|
|
|
- [self.sdk bridgingMotionAction:DEVICETYPE_MAIN left:motionLeft right:motionRight];//左右脚动作
|
|
|
+
|
|
|
+ //跑酷需要回调步频
|
|
|
+ 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];
|
|
|
+
|
|
|
}else{//当前是交互模式
|
|
|
- int interaction = [self.game getInteractionCMD];
|
|
|
+
|
|
|
+ int interaction = game->getInteractionCMD();
|
|
|
// NSLog(@"主设备 当前的脚步交互动作 ===== >> %d",interaction);
|
|
|
-// [self.sdk bridgingInteraction:DEVICETYPE_MAIN code:interaction];
|
|
|
+ [self.sdk bridgingInteraction:DEVICETYPE_MAIN code:interaction];
|
|
|
if (self.getInteractionBlock){
|
|
|
self.getInteractionBlock(interaction);
|
|
|
}
|
|
|
}
|
|
|
-// }
|
|
|
|
|
|
- /******************测试丢包*****************/
|
|
|
- int difference = abs(ts) - abs(self.tempTs);
|
|
|
- //当前丢包数>2算作丢包
|
|
|
- if (abs(difference)>=2){
|
|
|
- self.loss = self.loss + abs(difference)-1;
|
|
|
- self.totalPackages = self.totalPackages+abs(difference);
|
|
|
-// NSLog(@"总数据包 1== >> self.totalPackages %d",self.totalPackages);
|
|
|
- }else{
|
|
|
- self.totalPackages++;
|
|
|
-// NSLog(@"总数据包 2== >> self.totalPackages %d",self.totalPackages);
|
|
|
+ /******************数据回调缓存*****************/
|
|
|
+ //标记初始值
|
|
|
+ if (self.initial_jump_count==0){
|
|
|
+ self.initial_jump_count = game->getGameJumpCount();
|
|
|
}
|
|
|
- self.tempTs = abs(ts);
|
|
|
-// NSLog(@"收到数据包 ===================>> ts: %d 当前包LOSS: %d 总包数: %d 总LOSS: %d",ts,abs(difference),self.totalPackages,self.loss);
|
|
|
-
|
|
|
- NSArray *aArray = [self.tempStepString componentsSeparatedByString:@","];
|
|
|
-
|
|
|
- self.testLabel.text = [NSString stringWithFormat:@"right:[%d,%d,%d] [%d,%d,%d] [%d,%d,%d] \nleft:[%d,%d,%d] [%d,%d,%d] [%d,%d,%d] \nZupt:[%d,%d] press:[%d,%d] \nj&d[%d %d] rssi:%d ts:%d \n脚步: %@ %@ ",right_pos[0],right_pos[1],right_pos[2],right_att[0],right_att[1],right_att[2],right_acc[0],right_acc[1],right_acc[2],left_pos[0],left_pos[1],left_pos[2],left_att[0],left_att[1],left_att[2],left_acc[0],left_acc[1],left_acc[2],rightZupt,leftZupt,right_press,left_press,jump,down,rssi,ts,aArray[aArray.count-2],aArray.lastObject];
|
|
|
+ if (self.initial_down_count==0) {
|
|
|
+ self.initial_down_count = game->getGameDownCount();
|
|
|
+ }
|
|
|
+ //总数
|
|
|
+ int total_jump_count = game->getGameJumpCount();
|
|
|
+ int total_dump_count = game->getGameDownCount();
|
|
|
+ //当局游戏次数
|
|
|
+ int current_jump_count = total_jump_count - self.initial_jump_count;
|
|
|
+ int current_dump_count = total_dump_count - self.initial_down_count;
|
|
|
+ //数据回调缓存
|
|
|
+ [self cacheAllMotionCount:current_jump_count crouchCount:current_dump_count stepCount:leftStepCount + rightStepCount];
|
|
|
|
|
|
-// 写入沙盒数据
|
|
|
-// self.dataString = [NSString stringWithFormat:@"%@\n[%d,%d,%d] [%d,%d,%d] [%d,%d,%d] [%d,%d,%d] [%d,%d,%d] [%d,%d,%d] action:[%d %d %d %d,%d] rs:%d ts:%d press:[%d,%d] 总包数: %d 总丢包: %d",self.dataString,right_pos[0],right_pos[1],right_pos[2],right_att[0],right_att[1],right_att[2],right_acc[0],right_acc[1],right_acc[2],left_pos[0],left_pos[1],left_pos[2],left_att[0],left_att[1],left_att[2],left_acc[0],left_acc[1],left_acc[2],girlShoes,rightZupt,leftZupt,jump,down,rssi,ts,right_press,left_press,self.totalPackages,self.loss];
|
|
|
-// [self writeFileToplist];
|
|
|
+ /********************剑波 & 威严 要的图表数据 *****************/
|
|
|
+ NSString * aString = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
|
|
|
+ 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 = [DebugViewInstance.tempStepString componentsSeparatedByString:@","];
|
|
|
+// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if (DebugViewInstance.testLabel!=nil){
|
|
|
+ DebugViewInstance.testLabel.text = [NSString stringWithFormat:@"right:[%d,%d,%d] [%d,%d,%d] [%d,%d,%d] \nleft:[%d,%d,%d] [%d,%d,%d] [%d,%d,%d] \nZupt:[%d,%d] press:[%d,%d] \nj&d[%d %d] rssi:[%d %@] ts:%d \n脚步: %@ %@\n步频: %d %d ",right_pos[0],right_pos[1],right_pos[2],right_att[0],right_att[1],right_att[2],right_acc[0],right_acc[1],right_acc[2],left_pos[0],left_pos[1],left_pos[2],left_att[0],left_att[1],left_att[2],left_acc[0],left_acc[1],left_acc[2],rightZupt,leftZupt,right_press,left_press,jump,down,rssi,DebugViewInstance.RSSI,ts,aArray[aArray.count-2],aArray.lastObject,leftStepFreq,rightStepFreq];
|
|
|
+ }
|
|
|
+// });
|
|
|
+
|
|
|
+ /********************颖嘉+的ts丢包数据 *****************/
|
|
|
+ NSString * tsString = aArray[aArray.count-4];
|
|
|
+ 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){
|
|
|
+ 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;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -761,193 +662,57 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
rssi:(int)rssi
|
|
|
girlShoes:(int)girlShoes
|
|
|
right_press:(int)right_press
|
|
|
- left_press:(int)left_press{
|
|
|
-
|
|
|
- /********************初始化 运动轨迹算法 SDK *****************/
|
|
|
- [self.viceDeviceGame gameProcess:ts
|
|
|
- rightPos:right_pos
|
|
|
- rightAtt:right_att
|
|
|
- rightAcc:right_acc
|
|
|
- rightZupt:rightZupt
|
|
|
- right_press:right_press
|
|
|
- leftPos:left_pos
|
|
|
- leftAtt:left_att
|
|
|
- leftAcc:left_acc
|
|
|
- leftZupt:leftZupt
|
|
|
- left_press:left_press
|
|
|
- jump:jump
|
|
|
- down:down
|
|
|
- rssi:rssi
|
|
|
- girl_shoes:girlShoes];
|
|
|
- int length = 4;
|
|
|
- int result[length];
|
|
|
- [self.viceDeviceGame getGameResult:result];
|
|
|
-// NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
|
|
|
+ left_press:(int)left_press
|
|
|
+ characteristic:(NSData*)characteristic{
|
|
|
+
|
|
|
+ /********************初始化 运动轨迹算法 SDK *****************/
|
|
|
+ //游戏数据
|
|
|
+ NSData * validData= [characteristic subdataWithRange:NSMakeRange(4, characteristic.length-4)];
|
|
|
+ Byte * buff = (Byte*)[validData bytes];
|
|
|
+ viceDeviceGame->GameProcessBuf(buff, (int)validData.length);
|
|
|
|
|
|
+ int length = 4;
|
|
|
+ int result[length];
|
|
|
+ viceDeviceGame->getGameResult(result);
|
|
|
+ // NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
|
|
|
+
|
|
|
/********************蓝牙sdk返回的鞋子 状态 步频 步数*****************/
|
|
|
- int leftStepStatus = [self.viceDeviceGame getStepStatus:LEFT_FOOT_OC];
|
|
|
- int leftStepFreq = [self.viceDeviceGame getStepFreq:LEFT_FOOT_OC];
|
|
|
-// int leftStepCount = [self.viceDeviceGame getStepCount:LEFT_FOOT_OC];
|
|
|
- int rightStepStatus = [self.viceDeviceGame getStepStatus:RIGHT_FOOT_OC];
|
|
|
- int rightStepFreq = [self.viceDeviceGame getStepFreq:RIGHT_FOOT_OC];
|
|
|
-// int rightStepCount = [self.viceDeviceGame getStepCount:RIGHT_FOOT_OC];
|
|
|
- //ios call unity
|
|
|
- //ios call unity
|
|
|
- if (self.game_id == GAME_TYPE_RUN){//跑酷才需要回调
|
|
|
- [self.sdk bridgingStepAction:DEVICETYPE_VICE leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];//副设备左右脚速度 步频
|
|
|
- }
|
|
|
+ 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);
|
|
|
|
|
|
/********************蓝牙sdk返回的鞋子 动作*****************/
|
|
|
int motionLeft = result[0];//左脚的动作
|
|
|
int motionRight = result[1];//右脚的动作
|
|
|
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;
|
|
|
motionRight = ivce_motionJump;
|
|
|
- NSLog(@"副设备 ======================================== 跳起来 jump_count = %d ",self.jump_count);
|
|
|
+ NSLog(@"副设备 ======================================== 跳起来");
|
|
|
}
|
|
|
if (ivce_motionDown == MOTION_DOWN){
|
|
|
motionLeft = ivce_motionDown;
|
|
|
motionRight = ivce_motionDown;
|
|
|
- NSLog(@"副设备 ========================================= 蹲下去 crouch_count = %d ",self.crouch_count);
|
|
|
+ NSLog(@"副设备 ========================================= 蹲下去");
|
|
|
}
|
|
|
- //ios call unity as相互NX你·
|
|
|
- [self.sdk bridgingMotionAction:DEVICETYPE_VICE left:motionLeft right:motionRight];//副设备左右脚动作
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark ===============================================>> 蓝牙发送各类数据
|
|
|
-//查询设备信息
|
|
|
-- (void)queryDevideInfo{
|
|
|
-
|
|
|
- //头帧AA + 数据长度 + 长度取反 + cmd + 数据 + 校验
|
|
|
- NSMutableData * writeData = [NSMutableData new];
|
|
|
-
|
|
|
- Byte header = 0xaa;
|
|
|
- Byte length = 0x06;//长度A1->6 A2->5 A3->7
|
|
|
- Byte lengthNegation = ~length;
|
|
|
- Byte cmd = 0xA1;
|
|
|
- Byte data = 0x1;
|
|
|
-
|
|
|
- Byte byte[] = {header,length,lengthNegation,cmd,data};
|
|
|
- writeData = [[NSMutableData alloc] initWithBytes:byte length:sizeof(byte)];
|
|
|
-// [writeData appendData:msData];
|
|
|
- Byte bcc = [AlgorithmTool byteSumBBC:writeData];
|
|
|
-
|
|
|
- [writeData appendBytes:&bcc length:sizeof(bcc)];
|
|
|
-
|
|
|
- if (LEManager.peripheral!=nil){
|
|
|
- NSLog(@"发送的报文 主设备 查询设备信息 %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.write writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_MAIN];
|
|
|
- }
|
|
|
- if (LEManager.vicePeripheral!=nil){
|
|
|
- NSLog(@"发送的报文 副设备 查询设备信息 %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.viceWrite writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_VICE];
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//打开游戏模式
|
|
|
-- (void)startGameModel{
|
|
|
-
|
|
|
- //0xaa06f9a2014c
|
|
|
-
|
|
|
- //头帧AA + 数据长度 + 长度取反 + cmd + 数据 + 校验
|
|
|
- NSMutableData * writeData = [NSMutableData new];
|
|
|
- Byte header = 0xaa;
|
|
|
- Byte length = 0x06;//长度A1->6 A2->5 A3->7
|
|
|
- Byte lengthNegation = ~length;
|
|
|
- Byte cmd = 0xA2;
|
|
|
- Byte data = 0x1;
|
|
|
- //计算校验位
|
|
|
- Byte byte[] = {header,length,lengthNegation,cmd,data};
|
|
|
- writeData = [[NSMutableData alloc] initWithBytes:byte length:sizeof(byte)];
|
|
|
- Byte bcc = [AlgorithmTool byteSumBBC:writeData];
|
|
|
- //传输数据 -->> NSData
|
|
|
- [writeData appendBytes:&bcc length:sizeof(bcc)];
|
|
|
-
|
|
|
- if (LEManager.peripheral!=nil){
|
|
|
- NSLog(@"发送的报文 主设备 开启游戏模式: %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.write writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_MAIN];
|
|
|
- }
|
|
|
-
|
|
|
- if (LEManager.vicePeripheral!=nil){
|
|
|
- NSLog(@"发送的报文 副设备 开启游戏模式: %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.viceWrite writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_VICE];
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//设置震动
|
|
|
-- (void)vibration:(DEVICE_TYPE)deviceType duration:(int)duration{
|
|
|
-
|
|
|
- //头帧AA + 数据长度 + 长度取反 + cmd + 数据 + 校验
|
|
|
- NSMutableData * writeData = [NSMutableData new];
|
|
|
- Byte header = 0xaa;
|
|
|
- Byte length = 0x07;//长度A1->6 A2->5 A3->7
|
|
|
- Byte lengthNegation = ~length;
|
|
|
- Byte cmd = 0xA4;
|
|
|
- //振动时间 2字节
|
|
|
- short ms = 400;//400毫秒
|
|
|
- Byte mslow = (Byte) (0x00FF & ms);//定义第一个byte
|
|
|
- Byte mshigh = (Byte) (0x00FF & (ms>>8));//定义第二个byte
|
|
|
- //计算校验位
|
|
|
- Byte bytes[] = {header,length,lengthNegation,cmd,mshigh,mslow};
|
|
|
- Byte bcc = [AlgorithmTool bbcByte:bytes];
|
|
|
- //传输数据 Byte -->> NSData
|
|
|
- Byte newByte[] = {header,length,lengthNegation,cmd,mshigh,mslow,bcc};
|
|
|
- writeData = [[NSMutableData alloc] initWithBytes:newByte length:sizeof(newByte)];
|
|
|
-
|
|
|
- if (deviceType==DEVICETYPE_MAIN){
|
|
|
- NSLog(@"发送的报文 主设备 设备震动 %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.write writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_MAIN];
|
|
|
- }else if (deviceType == DEVICETYPE_VICE){
|
|
|
- NSLog(@"发送的报文 副设备 设备震动 %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.viceWrite writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_VICE];
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+ //ios call unity
|
|
|
+ if (self.game_type == GAME_TYPE_RUN){//跑酷才需要回调
|
|
|
+ [self.sdk bridgingStepAction:DEVICETYPE_VICE leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];//副设备左右脚速度 步频
|
|
|
+ }
|
|
|
+ //ios call unity
|
|
|
+ [self.sdk bridgingMotionAction:DEVICETYPE_VICE left:motionLeft right:motionRight];//副设备左右脚动作
|
|
|
|
|
|
-//开启/关闭 激光模式
|
|
|
-- (void)laser:(int)state{
|
|
|
-
|
|
|
- //头帧AA + 数据长度 + 长度取反 + cmd + 数据 + 校验
|
|
|
- NSMutableData * writeData = [NSMutableData new];
|
|
|
- Byte header = 0xaa;
|
|
|
- Byte length = 0x06;//长度A1->6 A2->5 A3->7
|
|
|
- Byte lengthNegation = ~length;
|
|
|
- Byte cmd = 0xA9;
|
|
|
- //激光状态 字节
|
|
|
- Byte data;
|
|
|
- if (state ==0){
|
|
|
- data = 0x00;
|
|
|
- }else if(state==1){
|
|
|
- data = 0x01;
|
|
|
- }
|
|
|
- //计算校验位
|
|
|
- Byte bytes[] = {header,length,lengthNegation,cmd,data};
|
|
|
- Byte bcc = [AlgorithmTool bbcByte:bytes];
|
|
|
- //传输数据 Byte -->> NSData
|
|
|
- Byte newByte[] = {header,length,lengthNegation,cmd,data,bcc};
|
|
|
- writeData = [[NSMutableData alloc] initWithBytes:newByte length:sizeof(newByte)];
|
|
|
|
|
|
- if (LEManager.peripheral!=nil){
|
|
|
- NSLog(@"发送的报文 主设备 开启激光: %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.write writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_MAIN];
|
|
|
- }
|
|
|
-
|
|
|
- if (LEManager.vicePeripheral!=nil){
|
|
|
- NSLog(@"发送的报文 副设备 开启激光: %@", writeData);
|
|
|
- [LEManager writeValue:writeData forCharacteristic:LEManager.viceWrite writeType:CBCharacteristicWriteWithResponse deviceType:DEVICETYPE_VICE];
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
#pragma mark ===============================================>> 懒加载 -- 蓝牙设备数据源
|
|
@@ -958,163 +723,25 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
return _deviceArray;;
|
|
|
}
|
|
|
|
|
|
-#pragma mark ===============================================>> DEBUG
|
|
|
--(void)inittestLabel{
|
|
|
-
|
|
|
- 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];
|
|
|
- }
|
|
|
-
|
|
|
- if (self.testLabel!=nil){
|
|
|
- [self.testLabel removeFromSuperview];
|
|
|
- }
|
|
|
-
|
|
|
- self.testLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, [UIScreen mainScreen].bounds.size.width-100, 120)];
|
|
|
- self.testLabel.textColor = [UIColor redColor];
|
|
|
- self.testLabel.font = [UIFont boldSystemFontOfSize:18];
|
|
|
- self.testLabel.backgroundColor = [UIColor clearColor];
|
|
|
- self.testLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
- self.testLabel.numberOfLines = 0;
|
|
|
-
|
|
|
- UIButton * uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
- uploadButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-100, 10, 80, 40);
|
|
|
- uploadButton.backgroundColor = [UIColor redColor];
|
|
|
- [uploadButton.titleLabel setTextColor:[UIColor redColor]];
|
|
|
- [uploadButton setFont: [UIFont boldSystemFontOfSize:20]];
|
|
|
- [uploadButton setTitle:@"上传" forState:UIControlStateNormal];
|
|
|
- [uploadButton addTarget:self action:@selector(uploadpPlistFile) forControlEvents:UIControlEventTouchUpInside];
|
|
|
-
|
|
|
-// [rootVC addChildViewController:searchVC];
|
|
|
- [rootVC.view addSubview:self.testLabel];
|
|
|
- [rootVC.view addSubview:uploadButton];
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark ===============================================>> 存储和上传数据
|
|
|
-//读取剑波sdk返回字符串数据
|
|
|
--(void)ocGetGameDataStr:(NSData*)characteristic{
|
|
|
- //剑波数据测试组
|
|
|
- NSData * validData= [characteristic subdataWithRange:NSMakeRange(4, characteristic.length-4)];
|
|
|
- Byte * buff = (Byte*)[validData bytes];
|
|
|
- [self.game GameProcessBuf:buff length:(int)validData.length];
|
|
|
- self.tempStepString = [self.game getGameDataStr];
|
|
|
- if (self.dataString.length<2){
|
|
|
- self.dataString = [self.game getGameDataStr];
|
|
|
- }else{
|
|
|
- self.dataString = [NSString stringWithFormat:@"%@\n%@",self.dataString,[self.game getGameDataStr]];
|
|
|
- }
|
|
|
-// NSLog(@"剑波需要的 ===================>> %@",self.dataString);
|
|
|
- [self writeFileToplist];
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//数据写入沙河
|
|
|
--(void)writeFileToplist{
|
|
|
-
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
- //获取完整路径
|
|
|
- NSString *documentsDirectory = [paths objectAtIndex:0];
|
|
|
- NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"lossLog.txt"];//这里就是你将要存储的沙盒路径(.plist文件,名字自定义)
|
|
|
-
|
|
|
- if(![[NSFileManager defaultManager] fileExistsAtPath:plistPath]){//plistPath这个文件\文件夹是否存在
|
|
|
-
|
|
|
- NSLog(@"------1----- 写入 不 成功");
|
|
|
-
|
|
|
- [self.dataString writeToFile:plistPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
|
-
|
|
|
- }else{
|
|
|
-
|
|
|
- [self.dataString writeToFile:plistPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
|
- // NSLog(@"------2---- 写入 成功");
|
|
|
-// NSLog(@"%@",plistPath);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
--(void)uploadpPlistFile{
|
|
|
+//数据存入plist
|
|
|
+//玩游戏过程中缓存 动作数据 和时间戳
|
|
|
+-(void)cacheAllMotionCount:(int)jump_count crouchCount:(int)crouch_count stepCount:(int)step_count{
|
|
|
+
|
|
|
+ //游戏持续时间
|
|
|
+ NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:self.firstTime];//游戏总共经历的时长 秒数
|
|
|
+ //缓存pilst文件
|
|
|
+ NSMutableDictionary * bleDict = [NSMutableDictionary new];
|
|
|
+ [bleDict setObject:[NSNumber numberWithInt:durationTime] forKey:@"duration"];
|
|
|
+ [bleDict setObject:[NSNumber numberWithInt:jump_count] forKey:@"jump"];
|
|
|
+ [bleDict setObject:[NSNumber numberWithInt:crouch_count] forKey:@"crouch"];
|
|
|
+ [bleDict setObject:[NSNumber numberWithInt:step_count] forKey:@"step"];
|
|
|
+ NSDictionary * dict = [NSDictionary dictionaryWithDictionary:bleDict];
|
|
|
+ //归档缓存
|
|
|
+ [IOS_NSUSERDEFAULT setObject:dict forKey:IOSSDK_BLESDKDATA];
|
|
|
+ [IOS_NSUSERDEFAULT synchronize];
|
|
|
|
|
|
- //这个方法获取出的结果是一个数组.因为有可以搜索到多个路径.
|
|
|
- NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
- //在这里,我们指定搜索的是Cache目录,所以结果只有一个,取出Cache目录
|
|
|
- NSString *documentsDirectory = array[0];
|
|
|
-// NSLog(@"%@",documentsDirectory);
|
|
|
- //拼接文件路径
|
|
|
- NSString *filePathName = [documentsDirectory stringByAppendingPathComponent:@"lossLog.txt"];
|
|
|
- //如果保存的是一个数组.那就通过数组从文件当中加载.
|
|
|
- NSString *string = [NSString stringWithContentsOfFile:filePathName encoding:NSUTF8StringEncoding error:nil];
|
|
|
-// NSLog(@"%@",string);
|
|
|
- //4.设置请求体
|
|
|
- NSData *upData = [string dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
- //
|
|
|
- AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
|
|
- manager.requestSerializer.timeoutInterval=15;
|
|
|
- [manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
|
|
|
- manager.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
|
- manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/html",@"application/json",@"text/javascript",@"image/jpeg",@"image/png",@"application/octet-stream",@"application/x-www-form-urlencoded", nil];
|
|
|
- // NSLog(@"请求URL ===================>> %@",urlString);
|
|
|
- NSLog(@"******************* 请求头参数 = %@ ***************************",manager.requestSerializer.HTTPRequestHeaders);
|
|
|
-
|
|
|
- AFHTTPSessionManager *sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:nil];
|
|
|
- [sessionManager POST:@"http://172.16.14.127:8080/upload" parameters:nil headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData){
|
|
|
-
|
|
|
- [formData appendPartWithFileData:upData name:@"file" fileName:[NSString stringWithFormat:@"ios_paoku_%@.txt",[self getNowTimeTimestamp]] mimeType:@"text/plain"];
|
|
|
-// [formData appendPartWithFileData:upData name:@"file" fileName:[NSString stringWithFormat:@"lossLog%@.txt",@"1"] mimeType:@"text/plain"];
|
|
|
-
|
|
|
- }progress:^(NSProgress * _Nonnull uploadProgress){
|
|
|
- NSLog(@"上传进度 = %@",uploadProgress);
|
|
|
-
|
|
|
- }success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject){
|
|
|
- NSLog(@"上传成功");
|
|
|
-
|
|
|
- }failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error){
|
|
|
-
|
|
|
- for (NSString * key in error.userInfo){
|
|
|
-
|
|
|
- if ([key isEqualToString:@"com.alamofire.serialization.response.error.data"]){
|
|
|
-
|
|
|
- id errorObject = [NSJSONSerialization JSONObjectWithData:error.userInfo[key] options:1 error:nil];
|
|
|
-
|
|
|
- NSLog(@"上传失败 ===>> %@",errorObject);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-//获取当前时间戳有两种方法(以秒为单位)
|
|
|
--(NSString *)getNowTimeTimestamp{
|
|
|
-
|
|
|
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
|
|
|
-
|
|
|
- [formatter setDateStyle:NSDateFormatterMediumStyle];
|
|
|
-
|
|
|
- [formatter setTimeStyle:NSDateFormatterShortStyle];
|
|
|
-
|
|
|
- [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
|
|
|
-
|
|
|
- //设置时区,这个对于时间的处理有时很重要
|
|
|
-
|
|
|
- NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
|
|
|
-
|
|
|
- [formatter setTimeZone:timeZone];
|
|
|
-
|
|
|
- NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
|
|
|
-
|
|
|
- NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
|
|
|
-
|
|
|
- return timeSp;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
@end
|
|
|
|
|
|
|