|
@@ -9,6 +9,7 @@
|
|
|
#import "BTDataProcess.h"
|
|
|
#import "IOSPlatformSDK.h"
|
|
|
#include "Game.h"
|
|
|
+#import <AudioToolbox/AudioToolbox.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>
|
|
@@ -21,8 +22,6 @@ 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;//是否开启游戏模式
|
|
@@ -38,6 +37,8 @@ Game *viceDeviceGame;
|
|
|
@property (nonatomic,assign)int totalPackages;
|
|
|
@property (nonatomic,strong)NSString * tempStepString;//剑波要的字符串数据 缓存plist
|
|
|
@property(nonatomic,assign) NSNumber *RSSI;//威严要的测试数据
|
|
|
+@property(nonatomic,assign) int currentTS;//颖嘉要的测试数据
|
|
|
+
|
|
|
//@property(nonatomic,weak)NSTimer * rssiTimer;//记录每秒的rssi峰值
|
|
|
//@property(nonatomic,assign) NSNumber * currentPeakRSSI;//龙哥要的测试数据
|
|
|
|
|
@@ -309,6 +310,8 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ //
|
|
|
+ self.game_type = self.game_id;
|
|
|
|
|
|
//
|
|
|
NSLog(@"BTDataProcess connectPeripheral self.deviceType ==>> %ld self.game_id ==>> %d mac ==>> %@",(long)self.deviceType,self.game_id,self.macAddress);
|
|
@@ -317,11 +320,9 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
if (self.deviceType==DEVICETYPE_MAIN){
|
|
|
LEManager.peripheral = peripheral;
|
|
|
game = new Game(self.game_id);
|
|
|
-// MainShoesAnalysis * instance = [MainShoesAnalysis sharedInstance];
|
|
|
-// instance->game = new Game(self.game_id);
|
|
|
}else if (self.deviceType == DEVICETYPE_VICE){
|
|
|
LEManager.vicePeripheral = peripheral;
|
|
|
-// viceDeviceGame = [[GameObjc alloc] initWithGametype:self.game_id];
|
|
|
+ viceDeviceGame = new Game(self.game_id);
|
|
|
}
|
|
|
|
|
|
//根据ios_sdk传入deviceType 链接 主/副 设备
|
|
@@ -415,34 +416,36 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
//蓝牙连接丢失
|
|
|
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];
|
|
|
|
|
|
- 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];
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
#pragma mark ===============================================>> 读取特征后 鞋子打开游戏模式 & 激光开关 &查询鞋子蓝牙状态 & 主设备初始化缓存游戏步数
|
|
|
-(void)initGameAction:(DEVICE_TYPE)deviceType{
|
|
|
|
|
@@ -455,7 +458,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
//开启游戏模式&查询设备信息 初始化步数数据
|
|
|
- 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)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
[self timingDataTransmission:@"dispatch_after"];
|
|
|
});
|
|
|
|
|
@@ -464,7 +467,7 @@ void disConnectBle (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];
|
|
|
|
|
|
}
|
|
@@ -485,7 +488,6 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
#pragma mark ===============================================>> 校验 & 报文数据解析
|
|
|
-(void)verifyData:(CBCharacteristic*)characteristic deviceType:(DEVICE_TYPE)deviceType{
|
|
|
|
|
@@ -619,18 +621,18 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
// int rightPressure = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(17, 4)]];
|
|
|
// int rightStepCount = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(21, 4)]];
|
|
|
|
|
|
- if (deviceType==DEVICETYPE_MAIN){//主设备
|
|
|
+ if (deviceType==DEVICETYPE_MAIN && LEManager.peripheral!=nil){//主设备
|
|
|
|
|
|
- NSLog(@"主设备 接收到 鞋子硬件数据 data 26 = %@ 电量 %d %d",characteristic,leftElectricity,rightElectricity);
|
|
|
+// 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){//副设备
|
|
|
+ electricity:20];
|
|
|
+
|
|
|
+ }else if (deviceType==DEVICETYPE_VICE && LEManager.vicePeripheral!=nil){//副设备
|
|
|
|
|
|
NSLog(@"副设备 接收到 鞋子硬件数据 26 = %@ 电量 %d %d",characteristic,leftElectricity,rightElectricity);
|
|
|
|
|
@@ -748,7 +750,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
self.allMotionCountBLock(current_jump_count, current_dump_count, leftStepCount + rightStepCount);
|
|
|
}
|
|
|
|
|
|
- /********************剑波要的图表数据 *****************/
|
|
|
+ /********************剑波 & 威严 要的图表数据 *****************/
|
|
|
NSString * aString = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
|
|
|
if (self.RSSI==nil){
|
|
|
self.RSSI = 0;
|
|
@@ -760,22 +762,40 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
/********************调试窗数据 *****************/
|
|
|
+ NSArray *aArray = [self.tempStepString componentsSeparatedByString:@","];
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- NSArray *aArray = [self.tempStepString componentsSeparatedByString:@","];
|
|
|
if (self.testLabel!=nil){
|
|
|
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脚步: %@ %@\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,self.RSSI,ts,aArray[aArray.count-2],aArray.lastObject,leftStepFreq,rightStepFreq];
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
|
|
|
+ /********************颖嘉+的ts丢包数据 *****************/
|
|
|
+ NSString * tsString = aArray[aArray.count-4];
|
|
|
+ int tsInt = [tsString intValue];
|
|
|
+ int total;
|
|
|
+ //1....255
|
|
|
+ if (tsInt > self.currentTS){
|
|
|
+ total = tsInt - self.currentTS - 1;
|
|
|
+ }
|
|
|
+ //255...1
|
|
|
+ if (tsInt < self.currentTS){
|
|
|
+ if (tsInt ==0) {
|
|
|
+ total = (255-self.currentTS) + tsInt + 1 - 1;
|
|
|
+ }else{
|
|
|
+ total = (255-self.currentTS) + tsInt - 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ NSLog(@"tsInt = %d currentTS = %d total = %d",tsInt,self.currentTS,total);
|
|
|
+ if (total > 20){
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
|
|
+ [PopupView showCusHUDA:[NSString stringWithFormat:@"丢包数: %d",total]];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.currentTS = tsInt;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-////读取剑波sdk返回字符串数据
|
|
|
-//-(void)ocGetGameDataStr:(NSData*)characteristic{
|
|
|
-//
|
|
|
-//}
|
|
|
-
|
|
|
#pragma mark ===============================================>>副设备 报文数据解析后 -- 调用蓝牙鞋子SDK装换数据 -- ios call unity 更新游戏动作
|
|
|
-(void)viceShoseSDKRight_pos:(int[3])right_pos
|
|
|
Right_att:(int[3])right_att
|
|
@@ -794,7 +814,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
left_press:(int)left_press
|
|
|
characteristic:(NSData*)characteristic{
|
|
|
|
|
|
- /********************初始化 运动轨迹算法 SDK *****************/
|
|
|
+ /********************初始化 运动轨迹算法 SDK *****************/
|
|
|
//游戏数据
|
|
|
NSData * validData= [characteristic subdataWithRange:NSMakeRange(4, characteristic.length-4)];
|
|
|
Byte * buff = (Byte*)[validData bytes];
|
|
@@ -804,7 +824,6 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
int result[length];
|
|
|
viceDeviceGame->getGameResult(result);
|
|
|
// NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
|
|
|
-
|
|
|
|
|
|
/********************蓝牙sdk返回的鞋子 状态 步频 步数*****************/
|
|
|
int leftStepStatus = game->getStepStatus(LEFT_FOOT);
|
|
@@ -814,7 +833,6 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
int rightStepFreq = game->getStepFreq(RIGHT_FOOT);
|
|
|
int rightStepCount = game->getStepCount(RIGHT_FOOT);
|
|
|
|
|
|
-
|
|
|
/********************蓝牙sdk返回的鞋子 动作*****************/
|
|
|
int motionLeft = result[0];//左脚的动作
|
|
|
int motionRight = result[1];//右脚的动作
|