|
@@ -9,7 +9,6 @@
|
|
|
#import "BTDataProcess.h"
|
|
|
#import "IOSPlatformSDK.h"
|
|
|
#include "Game.h"
|
|
|
-#import "MainShoesAnalysis.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>
|
|
@@ -81,12 +80,6 @@ static BTDataProcess* instance = nil;
|
|
|
|
|
|
//默认游戏模式关
|
|
|
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";
|
|
@@ -122,15 +115,24 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
//监听通知开始游戏
|
|
|
-(void)gameStartInitData{
|
|
|
|
|
|
-// NSLog(@"通知开始游戏 --> BTDataProcess");
|
|
|
+ NSLog(@"通知开始游戏 --> BTDataProcess");
|
|
|
self.gameModel = YES;
|
|
|
//反馈->蓝牙sdk
|
|
|
// [self.game start];
|
|
|
|
|
|
+ //读写到特征后 添加测试弹窗
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [self inittestLabel];
|
|
|
+ });
|
|
|
+
|
|
|
+// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
+// [self inittestLabel];
|
|
|
+// });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//监听通知结束游戏
|
|
|
--(void)gameEndInitData:(NSNotification*)notification{
|
|
|
+-(void)gameEndInitData{
|
|
|
|
|
|
// NSLog(@"通知结束游戏 --> BTDataProcess");
|
|
|
self.gameModel = NO;
|
|
@@ -449,14 +451,9 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
self.initial_down_count = 0;
|
|
|
self.initial_jump_count = 0;
|
|
|
-
|
|
|
- //读写到特征后 添加测试弹窗
|
|
|
- [self inittestLabel];
|
|
|
-
|
|
|
- }else if (deviceType ==DEVICETYPE_VICE){
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//开启游戏模式&查询设备信息 初始化步数数据
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
|
|
|
[self timingDataTransmission:@"dispatch_after"];
|
|
@@ -763,8 +760,13 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
}
|
|
|
|
|
|
/********************调试窗数据 *****************/
|
|
|
- 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脚步: %@ %@ \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];
|
|
|
+ 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];
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
|
|
@@ -982,16 +984,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
#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];
|
|
|
}
|
|
@@ -1004,37 +997,38 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
[self.clearnButton removeFromSuperview];
|
|
|
}
|
|
|
|
|
|
- self.testLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, [UIScreen mainScreen].bounds.size.width-100, 160)];
|
|
|
- self.testLabel.textColor = [UIColor redColor];
|
|
|
- self.testLabel.font = [UIFont boldSystemFontOfSize:18];
|
|
|
- self.testLabel.backgroundColor = [UIColor clearColor];
|
|
|
- self.testLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
- self.testLabel.numberOfLines = 0;
|
|
|
-
|
|
|
self.uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
- self.uploadButton.frame = CGRectMake(SCREEN_WIDTH/2-100-10, SCREEN_HEIGHT-40-10, 100, 40);
|
|
|
+ self.uploadButton.frame = CGRectMake(SCREEN_WIDTH/2-SCALEoefficient(75)-10, SCREEN_HEIGHT-40-10, SCALEoefficient(75), SCALEoefficient(30));
|
|
|
self.uploadButton.backgroundColor = [UIColor redColor];
|
|
|
[self.uploadButton.titleLabel setTextColor:[UIColor redColor]];
|
|
|
- [self.uploadButton setFont: [UIFont boldSystemFontOfSize:20]];
|
|
|
+ [self.uploadButton setFont: [UIFont boldSystemFontOfSize:SCALEoefficient(15)]];
|
|
|
[self.uploadButton setTitle:@"上传" forState:UIControlStateNormal];
|
|
|
[self.uploadButton addTarget:self action:@selector(uploadpPlistFile) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
self.clearnButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
- self.clearnButton.frame = CGRectMake(SCREEN_WIDTH/2+10, SCREEN_HEIGHT-40-10, 100, 40);
|
|
|
+ self.clearnButton.frame = CGRectMake(SCREEN_WIDTH/2+10, SCREEN_HEIGHT-40-10, SCALEoefficient(75), SCALEoefficient(30));
|
|
|
self.clearnButton.backgroundColor = [UIColor redColor];
|
|
|
[self.clearnButton.titleLabel setTextColor:[UIColor redColor]];
|
|
|
- [self.clearnButton setFont: [UIFont boldSystemFontOfSize:20]];
|
|
|
+ [self.clearnButton setFont: [UIFont boldSystemFontOfSize:SCALEoefficient(15)]];
|
|
|
[self.clearnButton setTitle:@"清理缓存" forState:UIControlStateNormal];
|
|
|
[self.clearnButton addTarget:self action:@selector(clearCacheWithFilePath) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
- [rootVC.view addSubview:self.testLabel];
|
|
|
- [rootVC.view addSubview:self.uploadButton];
|
|
|
- [rootVC.view addSubview:self.clearnButton];
|
|
|
-
|
|
|
+ self.testLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCALEoefficient(20), 0, [UIScreen mainScreen].bounds.size.width-100, SCALEoefficient(160))];
|
|
|
+ self.testLabel.textColor = [UIColor redColor];
|
|
|
+ self.testLabel.font = [UIFont boldSystemFontOfSize:SCALEoefficient(14)];
|
|
|
+ self.testLabel.backgroundColor = [UIColor clearColor];
|
|
|
+ self.testLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
+ self.testLabel.numberOfLines = 0;
|
|
|
+
|
|
|
+ if ([UIApplication sharedApplication].keyWindow != nil){
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:self.uploadButton];
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:self.clearnButton];
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:self.testLabel];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
#pragma mark ===============================================>> 存储和上传数据
|
|
|
-
|
|
|
- (void)clearCacheWithFilePath{
|
|
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
@@ -1075,12 +1069,12 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
|
|
|
}else{
|
|
|
|
|
|
-// NSLog(@"-------文件存在,追加文件----------");
|
|
|
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
|
|
|
+// NSLog(@"-------文件存在,追加文件----------");
|
|
|
+ NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
|
|
|
[fileHandle seekToEndOfFile]; //将节点跳到文件的末尾
|
|
|
NSData* stringData = [self.tempStepString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
[fileHandle writeData:stringData]; //追加写入数据
|
|
|
- [fileHandle closeFile];
|
|
|
+ [fileHandle closeFile];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1112,7 +1106,7 @@ void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
|
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_run_%@.txt",[self getNowTimeTimestamp]] mimeType:@"text/plain"];
|
|
|
+ [formData appendPartWithFileData:upData name:@"file" fileName:[NSString stringWithFormat:@"ios_%@_%@.txt",Game_Type,[self getNowTimeTimestamp]] mimeType:@"text/plain"];
|
|
|
|
|
|
}progress:^(NSProgress * _Nonnull uploadProgress){
|
|
|
NSLog(@"上传进度 = %@",uploadProgress);
|