leon 2 роки тому
батько
коміт
1faa2f0251
39 змінених файлів з 2994 додано та 1978 видалено
  1. BIN
      .DS_Store
  2. BIN
      IMAGES/.DS_Store
  3. 612 559
      IOSToUnitySDK.xcodeproj/project.pbxproj
  4. BIN
      IOSToUnitySDK.xcworkspace/xcuserdata/duowan123.xcuserdatad/UserInterfaceState.xcuserstate
  5. BIN
      SDK/.DS_Store
  6. 15 32
      SDK/BLE/BTDataProcess.h
  7. 237 610
      SDK/BLE/BTDataProcess.mm
  8. 29 0
      SDK/BLE/BTDataSend.h
  9. 163 0
      SDK/BLE/BTDataSend.m
  10. 35 0
      SDK/BLE/DebugView.h
  11. 235 0
      SDK/BLE/DebugView.m
  12. 4 0
      SDK/BLE/LEONBLManager.h
  13. 16 0
      SDK/BLE/LEONBLManager.m
  14. 51 0
      SDK/BLE/MainShoesAnalysis.h
  15. 551 0
      SDK/BLE/MainShoesAnalysis.mm
  16. 16 0
      SDK/BLE/ViceShoesAnalysis.h
  17. 12 0
      SDK/BLE/ViceShoesAnalysis.m
  18. BIN
      SDK/HTTP/.DS_Store
  19. 16 6
      SDK/HTTP/HTTPDataProcession.h
  20. 12 6
      SDK/HTTP/HTTPDataProcession.m
  21. 141 218
      SDK/IOSPlatformSDK.mm
  22. 1 1
      SDK/PrefixHeader.h
  23. BIN
      SDK/ThirdClass/.DS_Store
  24. 156 156
      SDK/Tool/GameObjc.h
  25. 367 367
      SDK/Tool/GameObjc.mm
  26. 6 1
      SDK/Tool/MYFactoryManager.h
  27. 0 1
      SDK/Tool/MYFactoryManager.m
  28. 0 1
      SDK/UI/AnimationVIew/AnimationView.m
  29. 1 1
      SDK/UI/SearchDeviceViewController.m
  30. BIN
      SDK/resources /.DS_Store
  31. 123 0
      SDK/shoes_sdk/BigFoot.cpp
  32. 39 0
      SDK/shoes_sdk/BigFoot.h
  33. 6 1
      SDK/shoes_sdk/FootStep.cpp
  34. 4 1
      SDK/shoes_sdk/FootStep.h
  35. 118 9
      SDK/shoes_sdk/Game.cpp
  36. 23 0
      SDK/shoes_sdk/Game.h
  37. 0 2
      SDK/shoes_sdk/InertialTrajProcess.cpp
  38. 3 5
      SDK/shoes_sdk/RunGame.cpp
  39. 2 1
      SDK/shoes_sdk/pub.h

BIN
IMAGES/.DS_Store


Різницю між файлами не показано, бо вона завелика
+ 612 - 559
IOSToUnitySDK.xcodeproj/project.pbxproj


BIN
IOSToUnitySDK.xcworkspace/xcuserdata/duowan123.xcuserdatad/UserInterfaceState.xcuserstate



+ 15 - 32
SDK/BLE/BTDataProcess.h

@@ -6,10 +6,8 @@
 //
 
 #import <UIKit/UIKit.h>
-#import <CoreBluetooth/CoreBluetooth.h>
 #import "MYFactoryManager.h"
 #import "LEONBLManager.h"
-#import "CBPeripheral+ADName.h"
 
 //游戏类型
 typedef NS_ENUM(int, GAME_TYPE){
@@ -19,24 +17,6 @@ typedef NS_ENUM(int, GAME_TYPE){
     GAME_TYPE_SDAER, //
 };
 
-//动作数据
-typedef NS_ENUM(NSInteger, GAME_MOTION){
-    MOTION_STOP =0,
-    MOTION_RUN,// 跑
-    MOTION_JUMP, // 跳
-    MOTION_DOWN, // 蹲
-    MOTION_LEFT, // 滑左
-    MOTION_RIGHT, // 滑右
-    MOTION_FRONT, // 滑前
-    MOTION_BACK, // 滑后
-    MOTION_LEFT_UP, // 点击-左上
-    MOTION_LEFT_DOWN, // 点击-左下
-    MOTION_RIGHT_UP, // 点击-右上
-    MOTION_RIGHT_DOWN, // 点击-右下
-    MOTION_STEP, // 点击-原地踩
-    NUMBERS_OF_MOTION
-};
-
 //蓝牙状态
 typedef NS_ENUM(NSInteger, BLETOOTH_STUTAS){
     CONNECT_DIS =0, // 未链接
@@ -47,35 +27,38 @@ typedef NS_ENUM(NSInteger, BLETOOTH_STUTAS){
 
 @interface BTDataProcess : UIViewController
     
-//app 跳转传过来的mac 实际是蓝牙设备的identity
+//趣动跳转过来携带的mac 实际是蓝牙设备的identity
 @property(copy,nonatomic)NSString * macAddress;
 //弹窗 unity主动选择链接 主0 副1 设备
 @property(assign,nonatomic)DEVICE_TYPE deviceType;
 //游戏种类 1是跳舞 3是跑酷 2是赛达尔传说 4是demo->dance
-@property(assign,nonatomic)GAME_TYPE game_id;
+@property(assign,nonatomic)GAME_TYPE game_type;
+
 //蓝牙设备数据源回调给popSeaechView
 @property(copy,nonatomic)void (^deviceArrBLock)(NSMutableArray*arr);
-//主设备跳起 下蹲 步数 的总数
-@property(assign,nonatomic)int jump_count;
-@property(assign,nonatomic)int crouch_count;
-@property(assign,nonatomic)int step_count;
-//步数回调缓存
-@property(copy,nonatomic)void (^allMotionCountBLock)(int jump_count,int crouch_count,int step_count);//蓝牙设备数据源
 //脚步交互数据
-@property(copy,nonatomic)void (^getInteractionBlock)(int interaction);//蓝牙设备数据源
+@property(copy,nonatomic)void (^getInteractionBlock)(int interaction);
 
-@property(assign,nonatomic)int isBackGround;//程序在前台还是后台
+//程序在前台还是后台
+@property(assign,nonatomic)int isBackGround;
 
 //单例->初始化蓝牙
 +(instancetype)sharedInstance;
+
 //初始化中心管理
 -(void)initCBCentralManager;
 //app跳转直接连 或 tableview 选中
 -(void)connectPeripheral:(CBPeripheral*)peripheral;
 //unity或者趣动请求 外部断开蓝牙链接
 -(void)disConnedctBle;
-//
--(void)applicationWillEnterForeground;
+
+
+//监听通知开始游戏
+-(void)gameStartInitData;
+//监听通知结束游戏
+-(void)gameEndInitData;
+//监听通知震动
+-(void)vibrationAction:(int)type duration:(int)duration;
 
 @end
 

+ 237 - 610
SDK/BLE/BTDataProcess.mm

@@ -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
 
 

+ 29 - 0
SDK/BLE/BTDataSend.h

@@ -0,0 +1,29 @@
+//
+//  BTDataSend.h
+//  Unity-iPhone
+//
+//  Created by duowan123 on 2021/12/21.
+//
+
+#import <Foundation/Foundation.h>
+#import "MYFactoryManager.h"
+
+#define BTDataSendInstance [BTDataSend sharedInstance]
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface BTDataSend : NSObject
+
++(instancetype)sharedInstance;
+
+//查询设备信息
+- (void)queryDevideInfo;
+//打开游戏模式
+- (void)startGameModel;
+//设置震动
+- (void)vibration:(DEVICE_TYPE)deviceType duration:(int)duration;
+//开启/关闭 激光模式
+- (void)laser:(int)state;
+@end
+
+NS_ASSUME_NONNULL_END

+ 163 - 0
SDK/BLE/BTDataSend.m

@@ -0,0 +1,163 @@
+//
+//  BTDataSend.m
+//  Unity-iPhone
+//
+//  Created by duowan123 on 2021/12/21.
+//
+
+#import "BTDataSend.h"
+
+@implementation BTDataSend
+
+//单例静态
+static BTDataSend* 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];
+    });
+    return instance;
+}
+
+#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];
+    }
+    
+}
+
+//开启/关闭 激光模式
+- (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];
+    }
+    
+}
+
+@end

+ 35 - 0
SDK/BLE/DebugView.h

@@ -0,0 +1,35 @@
+//
+//  DebugView.h
+//  Unity-iPhone
+//
+//  Created by duowan123 on 2021/12/22.
+//
+
+#import <UIKit/UIKit.h>
+#import "MYFactoryManager.h"
+
+#define DebugViewInstance [DebugView sharedInstance]
+#define Game_Type @"run"
+#define JBSDKLog @"runLog.txt"
+
+@interface DebugView : UIView
+/*****测试*******/
+@property (nonatomic,strong)UILabel * testLabel;//调试框
+@property (nonatomic,strong)UIButton * uploadButton;//上传
+@property (nonatomic,strong)UIButton * clearnButton;//上传
+
+//当前的时间戳+丢包
+@property (nonatomic,strong)NSString * tempStepString;//剑波要的字符串数据 缓存plist
+@property(nonatomic,assign) NSNumber *RSSI;//威严要的测试数据
+@property(nonatomic,assign) int currentTS;//颖嘉要的测试数据
+
++(instancetype)sharedInstance;
+
+#pragma mark ===============================================>> DEBUG
+-(void)inittestLabel;
+
+//数据写入沙河
+-(void)writeFileToplist;
+    
+@end
+

+ 235 - 0
SDK/BLE/DebugView.m

@@ -0,0 +1,235 @@
+//
+//  DebugView.m
+//  Unity-iPhone
+//
+//  Created by duowan123 on 2021/12/22.
+//
+
+#import "DebugView.h"
+
+@implementation DebugView
+#pragma mark ===============================================>> 静态的初始化方法  init的时候(建立蓝牙中心管理类,设置代理)
+//单例静态
+static DebugView* 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];
+    });
+    return instance;
+}
+
+
+#pragma mark ===============================================>> DEBUG
+-(void)inittestLabel{
+
+    if (self.testLabel!=nil){
+        [self.testLabel removeFromSuperview];
+    }
+    
+    if (self.uploadButton!=nil){
+        [self.uploadButton removeFromSuperview];
+    }
+    
+    if (self.clearnButton!=nil){
+        [self.clearnButton removeFromSuperview];
+    }
+    
+    self.uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
+    self.uploadButton.frame = CGRectMake(30, SCREEN_HEIGHT-40-10, SCALEoefficient(75), SCALEoefficient(30));
+    self.uploadButton.backgroundColor = [UIColor redColor];
+    [self.uploadButton addTarget: self action: @selector (button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
+    [self.uploadButton addTarget: self action: @selector (button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
+    [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(30+SCALEoefficient(75)+20, SCREEN_HEIGHT-40-10, SCALEoefficient(75), SCALEoefficient(30));
+    self.clearnButton.backgroundColor = [UIColor redColor];
+//    [self.clearnButton addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
+//    [self.clearnButton addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
+    [self.clearnButton setFont: [UIFont boldSystemFontOfSize:SCALEoefficient(15)]];
+    [self.clearnButton setTitle:@"清理缓存" forState:UIControlStateNormal];
+    [self.clearnButton addTarget:self action:@selector(clearCacheWithFilePath) forControlEvents:UIControlEventTouchUpInside];
+    
+    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];
+    }
+
+}
+
+//  button普通状态下的背景色
+- (void )button1BackGroundNormal:(UIButton *)sender
+{
+     sender.backgroundColor = [UIColor redColor];
+}
+ 
+//  button高亮状态下的背景色
+- (void )button1BackGroundHighlighted:(UIButton *)sender
+{
+     sender.backgroundColor = [UIColor orangeColor];
+}
+
+#pragma mark ===============================================>> 存储和上传数据
+//清理缓存
+- (void)clearCacheWithFilePath{
+    
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    //获取完整路径
+    NSString *documentsDirectory = [paths objectAtIndex:0];
+    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:JBSDKLog];//这里就是你将要存储的沙盒路径(.plist文件,名字自定义)
+    NSError *error = nil;
+    //删除子文件夹
+    [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
+    if (error){
+        NSLog(@"清理缓存失败");
+        [PopupView showCusHUDA:@"清理失败"];
+    }else{
+        NSLog(@"清理缓存成功");
+        [PopupView showCusHUDA:@"清理成功"];
+    }
+    
+}
+
+//数据写入沙河
+-(void)writeFileToplist{
+    
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    //获取完整路径
+    NSString *documentsDirectory = [paths objectAtIndex:0];
+    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:JBSDKLog];//这里就是你将要存储的沙盒路径(.plist文件,名字自定义)
+
+    if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]){//plistPath这个文件\文件夹是否存在
+
+        NSLog(@"-------文件不存在,写入文件----------");
+
+               NSError *error;
+               if([self.tempStepString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error]){
+                   NSLog(@"------写入文件------success");
+               }else{
+                    NSLog(@"------写入文件------fail,error==%@",error);
+               };
+
+    }else{
+
+//     NSLog(@"-------文件存在,追加文件----------");
+       NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
+       [fileHandle seekToEndOfFile];  //将节点跳到文件的末尾
+       NSData* stringData  = [self.tempStepString dataUsingEncoding:NSUTF8StringEncoding];
+       [fileHandle writeData:stringData]; //追加写入数据
+       [fileHandle closeFile];
+
+    }
+
+}
+
+-(void)uploadpPlistFile{
+    
+    //这个方法获取出的结果是一个数组.因为有可以搜索到多个路径.
+    NSArray *array =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    //在这里,我们指定搜索的是Cache目录,所以结果只有一个,取出Cache目录
+    NSString *documentsDirectory = array[0];
+//    NSLog(@"%@",documentsDirectory);
+    //拼接文件路径
+    NSString *filePathName = [documentsDirectory stringByAppendingPathComponent:JBSDKLog];
+    //如果保存的是一个数组.那就通过数组从文件当中加载.
+    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_%@_%@.txt",Game_Type,[self getNowTimeTimestamp]] 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);
+                    if (errorObject !=nil && [errorObject isKindOfClass:[NSDictionary class]]){
+                        NSString * result = errorObject[@"result"];
+                        if ([result intValue] ==1){
+                            [PopupView showCusHUDA:@"上传成功"];
+                        }
+                        
+                    }
+
+                }
+                
+          }
+            
+    }];
+ 
+}
+
+//获取当前时间戳有两种方法(以秒为单位)
+-(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

+ 4 - 0
SDK/BLE/LEONBLManager.h

@@ -47,6 +47,9 @@ typedef void(^LEReadValueForCharacteristicBlock)(CBPeripheral *peripheral,CBChar
 /** 往特性中写入数据的回调 */
 typedef void(^LEWriteToCharacteristicBlock)(CBPeripheral *peripheral,CBCharacteristic *characteristic, NSError *error,DEVICE_TYPE type);
 
+/** RSSI*/
+typedef void(^RSSIBlock)(NSNumber *RSSI);
+
 @interface LEONBLManager : NSObject
 
 //蓝牙外设
@@ -60,6 +63,7 @@ typedef void(^LEWriteToCharacteristicBlock)(CBPeripheral *peripheral,CBCharacter
 @property(nonatomic,copy)LEDiscoverCharacteristicsBlock  discoverCharacteristicsBlock;
 @property(nonatomic,copy)LEReadValueForCharacteristicBlock  readValueForCharacteristicBlock;
 @property(nonatomic,copy)LEWriteToCharacteristicBlock  writeToCharacteristicBlock;//
+@property(nonatomic,copy)RSSIBlock rssiBlock;//
 
 @property (strong, nonatomic)CBCentralManager * centralManager;/**< 蓝牙中心管理器 */
 

+ 16 - 0
SDK/BLE/LEONBLManager.m

@@ -327,4 +327,20 @@ static LEONBLManager * instance;
 }
 
 
+/*!
+ *  @method peripheral:didReadRSSI:error:
+ *
+ *  @param peripheral    The peripheral providing this update.
+ *  @param RSSI            The current RSSI of the link.
+ *  @param error        If an error occurred, the cause of the failure.
+ *
+ *  @discussion            This method returns the result of a @link readRSSI: @/link call.
+ */
+- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(nullable NSError *)error{
+    if (_rssiBlock){
+        _rssiBlock(RSSI);
+    }
+}
+
+
 @end

+ 51 - 0
SDK/BLE/MainShoesAnalysis.h

@@ -0,0 +1,51 @@
+////
+////  MainShoesAnalysis.h
+////  Unity-iPhone
+////
+////  Created by duowan123 on 2021/12/4.
+////
+//
+//#import <Foundation/Foundation.h>
+//#import "MYFactoryManager.h"
+//
+//NS_ASSUME_NONNULL_BEGIN
+//
+//@interface MainShoesAnalysis : NSObject
+//
+//
+//+(instancetype)sharedInstance;
+//
+////弹窗 unity主动选择链接 主0 副1 设备
+//@property(assign,nonatomic)DEVICE_TYPE deviceType;
+////游戏种类 1是跳舞 3是跑酷 2是赛达尔传说 4是demo->dance
+//@property(assign,nonatomic)GAME_TYPE game_type;
+//
+////主设备跳起 下蹲 步数 的总数
+//@property(assign,nonatomic)int initial_jump_count;
+//@property(assign,nonatomic)int initial_down_count;
+////步数回调缓存
+//@property(copy,nonatomic)void (^allMotionCountBLock)(int jump_count,int crouch_count,int step_count);//蓝牙设备数据源
+////脚步交互数据
+//@property(copy,nonatomic)void (^getInteractionBlock)(int interaction);//蓝牙设备数据源
+//
+//@property(assign,nonatomic)int isBackGround;//程序在前台还是后台
+//
+//@property(nonatomic,assign)BOOL gameModel;//是否开启游戏模式
+//
+///*****测试*******/
+//@property (nonatomic,strong)UILabel * testLabel;//调试框
+//@property (nonatomic,strong)UIButton * uploadButton;//上传
+//@property (nonatomic,strong)UIButton * clearnButton;//上传
+//
+////当前的时间戳+丢包
+//@property (nonatomic,assign)int  tempTs;
+//@property (nonatomic,assign)int  loss;
+//@property (nonatomic,assign)int  totalPackages;
+//@property (nonatomic,strong)NSString * tempStepString;//剑波要的字符串数据 缓存plist
+//@property(nonatomic,assign) NSNumber *RSSI;//威严要的测试数据
+//@property(nonatomic,assign) int currentTS;//颖嘉要的测试数据
+//
+//
+//@end
+//
+//NS_ASSUME_NONNULL_END

+ 551 - 0
SDK/BLE/MainShoesAnalysis.mm

@@ -0,0 +1,551 @@
+////
+////  MainShoesAnalysis.m
+////  Unity-iPhone
+////
+////  Created by duowan123 on 2021/12/4.
+////
+//
+//#import "MainShoesAnalysis.h"
+//
+//@interface MainShoesAnalysis()
+//{
+//@private
+//Game *game;
+//}
+//
+//@end
+//
+//@implementation MainShoesAnalysis
+//
+////单例静态
+//static MainShoesAnalysis* 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];
+//    });
+//    return instance;
+//}
+//
+//#pragma mark ===============================================>> 校验 & 报文数据解析
+//-(void)verifyData:(CBCharacteristic*)characteristic deviceType:(DEVICE_TYPE)deviceType{
+//    
+//     if (characteristic.value.length>3){
+//         
+//         //带cmd位的有效数据  计算校验位
+//         if ([AlgorithmTool verificationRusult:characteristic.value]==YES){
+//             
+//             [self analysisCharacteristic:characteristic.value deviceType:deviceType];
+//                              
+//         }
+//         
+//     }else{
+//         
+//         NSLog(@"无效报文");
+//         
+//     }
+//     
+//}
+//
+//-(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;//报文长度取反
+//    int dataType = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(3, 1)]];//cmd类型
+//    
+//      if (dataType == 4){//获取主动推过来的数据
+//            //右脚坐标数据
+//           int right_X = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(4, 4)];
+//           int right_Y = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(8, 4)];
+//           int right_Z = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(12, 4)];
+//           int  right_pos[3] = {right_X,right_Y,right_Z};
+//          //左脚坐标数据
+//           int left_X = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(16, 4)];
+//           int left_Y = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(20, 4)];
+//           int left_Z = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(24, 4)];
+//           int  left_pos[3] = {left_X,left_Y,left_Z};
+//           //右脚姿势数据
+//           short righrPosture_X = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(28, 2)];
+//           short righrPosture_Y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(30, 2)];
+//           short righrPosture_Z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(32, 2)];
+//           int  right_att[3] = {righrPosture_X,righrPosture_Y,righrPosture_Z};
+//           //左脚姿势数据
+//           short leftPosture_X = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(34, 2)];
+//           short leftPosture_Y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(36, 2)];
+//           short leftPosture_Z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(38, 2)];
+//           int  left_att[3] = {leftPosture_X,leftPosture_Y,leftPosture_Z};
+//           //右脚三维数据
+//           short righrAcc_x = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(40, 2)];
+//           short righrAcc_Y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(42, 2)];
+//           short righrAcc_z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(44, 2)];
+//           int  righrAcc[3] = {righrAcc_x,righrAcc_Y,righrAcc_z};
+//           //左脚三维数据
+//           short leftAcc_x = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(46, 2)];
+//           short leftAcc_y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(48, 2)];
+//           short leftAcc_z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(50, 2)];
+//           int  left_acc[3] = {leftAcc_x,leftAcc_y,leftAcc_z};
+//           //左脚、右脚、蹲 、跳四个动作信息数据
+//           int actionInformation =  [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(52, 1)]];;//0c 16进制字符串
+//                       int girlShoes  = actionInformation & 16;
+//                       if (girlShoes!=0){
+//                           girlShoes=1;
+//                       }else{
+//                           girlShoes=0;
+//                       }
+//                       int rightZupt  = actionInformation & 8;
+//                       if (rightZupt!=0){
+//                           rightZupt=1;
+//                       }else{
+//                           rightZupt=0;
+//                       }
+//                       int leftZupt = actionInformation & 4;
+//                       if (leftZupt!=0){
+//                            leftZupt=1;
+//                        }else{
+//                            leftZupt=0;
+//                        }
+//                       int down  = actionInformation & 2;
+//                       if (down!=0){
+//                            down=1;
+//                        }else{
+//                            down=0;
+//                        }
+//                       int jump  = actionInformation & 1;
+//                       if (jump!=0){
+//                            jump=1;
+//                        }else{
+//                            jump=0;
+//                        }
+//          
+//            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)]];//校验位
+//        
+//               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 characteristic:characteristic];
+//                   
+//               }else if (deviceType==DEVICETYPE_VICE){//副设备动作数据
+//                   
+////                   NSLog(@"副设备 接收到 鞋子动作数据 data = %@",characteristic);
+//                   //调取鞋子SDK
+//  
+//                   
+//               }
+//              
+//        }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
+//                
+//                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)]];
+//                
+//                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*****************/
+//                     [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_MAIN
+//                                                 name:LEManager.peripheral.name
+//                                              address:LEManager.peripheral.identifier.UUIDString
+//                                               status:CONNECT_ED
+//                                          electricity:20];
+//             
+//                }else if (deviceType==DEVICETYPE_VICE && LEManager.vicePeripheral!=nil){//副设备
+//                    
+//                    NSLog(@"副设备 接收到 鞋子硬件数据 26 = %@  电量 %d %d",characteristic,leftElectricity,rightElectricity);
+//
+//                    //副 设备定时器 60秒调一次   /******************ios call unity*****************/
+//                     [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_VICE
+//                                                 name:LEManager.vicePeripheral.name
+//                                              address:LEManager.vicePeripheral.identifier.UUIDString
+//                                               status:CONNECT_ED
+//                                          electricity:leftElectricity<=rightElectricity?leftElectricity:rightElectricity];
+//                    
+//                }
+//             
+//           }
+//            
+//      }
+//    
+//}
+//
+//#pragma mark ===============================================>> 主设备 报文数据解析后 -- 调用蓝牙鞋子SDK装换数据 -- ios call unity 更新游戏动作
+//-(void)shoseSDKRight_pos:(int[3])right_pos
+//               Right_att:(int[3])right_att
+//               Right_acc:(int[3])right_acc
+//                 LeftPos:(int[3])left_pos
+//                Left_att:(int[3])left_att
+//                Left_acc:(int[3])left_acc
+//                      ts:(int)ts
+//               rightZupt:(int)rightZupt
+//                leftZupt:(int)leftZupt
+//                    jump:(int)jump
+//                    down:(int)down
+//                    rssi:(int)rssi
+//               girlShoes:(int)girlShoes
+//             right_press:(int)right_press
+//              left_press:(int)left_press
+//          characteristic:(NSData*)characteristic{
+//    
+//    /********************初始化 运动轨迹算法 SDK *****************/
+//    //游戏数据
+//    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];
+//    game->getGameResult(result);
+//    //   NSLog(@"result == %d %d %d %d \n",result[0],result[1],result[2],result[3]);
+//
+//    
+//    /******************步频数据处理 + 回调*****************/
+//    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];//右脚的动作
+//    int motionJump = result[2];//jump
+//    int motionDown = result[3];//down
+////    if (motionLeft==-1 && motionRight == -1&& motionJump == -1&& motionDown == -1){//无效动作
+////        return;
+////    }else{
+//        //跳跃和蹲下的动作 双脚是同步的
+//        if (motionJump == MOTION_JUMP){
+//            motionLeft = motionJump;
+//            motionRight = motionJump;
+//            NSLog(@" 主设备 ================================== 跳起来 ");
+//        }
+//    
+//        if (motionDown == MOTION_DOWN){
+//            motionLeft = motionDown;
+//            motionRight = motionDown;
+//            NSLog(@" 主设备 =================================== 蹲下去 ");
+//        }
+////    }
+//    
+//    /****************** ios call unity*****************/
+//        if (self.gameModel==YES){//当前是游戏模式
+//
+//            //跑酷需要回调步频
+//            if (self.game_type == GAME_TYPE_RUN){
+//                [[IOSPlatformSDK sharedInstance] bridgingStepAction:DEVICETYPE_MAIN leftStatus:leftStepStatus rightStatus:rightStepStatus leftFrag:leftStepFreq rightFrag:rightStepFreq];
+//            }
+//            //左右脚动作
+//            [[IOSPlatformSDK sharedInstance] bridgingMotionAction:DEVICETYPE_MAIN left:motionLeft right:motionRight];
+//
+//        }else{//当前是交互模式
+//
+//            int interaction = game->getInteractionCMD();
+////            NSLog(@"主设备 当前的脚步交互动作 ===== >> %d",interaction);
+//            [[IOSPlatformSDK sharedInstance] bridgingInteraction:DEVICETYPE_MAIN code:interaction];
+//            if (self.getInteractionBlock){
+//                self.getInteractionBlock(interaction);
+//            }
+//        }
+//    
+//    /******************数据回调缓存*****************/
+//    //标记初始值
+//    if (self.initial_jump_count==0){
+//        self.initial_jump_count = game->getGameJumpCount();
+//    }
+//    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;
+//    //数据回调缓存
+//    if (self.allMotionCountBLock){
+//        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;
+//    }
+//     aString = [NSString stringWithFormat:@"%@,%@",aString,self.RSSI];
+//    self.tempStepString = [NSString stringWithFormat:@"%@\n",aString];
+//    if (self.tempStepString!=nil && self.tempStepString.length>1){
+//        [self writeFileToplist];
+//    }
+//  
+//    /********************调试窗数据 *****************/
+//    NSArray *aArray = [self.tempStepString componentsSeparatedByString:@","];
+////    dispatch_async(dispatch_get_main_queue(), ^{
+//        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;
+//    
+//}
+//
+//
+//#pragma mark ===============================================>> DEBUG
+//-(void)inittestLabel{
+//
+//    if (self.testLabel!=nil){
+//        [self.testLabel removeFromSuperview];
+//    }
+//    
+//    if (self.uploadButton!=nil){
+//        [self.uploadButton removeFromSuperview];
+//    }
+//    
+//    if (self.clearnButton!=nil){
+//        [self.clearnButton removeFromSuperview];
+//    }
+//    
+//    self.uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
+//    self.uploadButton.frame = CGRectMake(30, SCREEN_HEIGHT-40-10, SCALEoefficient(75), SCALEoefficient(30));
+//    self.uploadButton.backgroundColor = [UIColor redColor];
+//    [self.uploadButton addTarget: self action: @selector (button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
+//    [self.uploadButton addTarget: self action: @selector (button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
+//    [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(30+SCALEoefficient(75)+20, SCREEN_HEIGHT-40-10, SCALEoefficient(75), SCALEoefficient(30));
+//    self.clearnButton.backgroundColor = [UIColor redColor];
+////    [self.clearnButton addTarget:self action:@selector(button1BackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
+////    [self.clearnButton addTarget:self action:@selector(button1BackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
+//    [self.clearnButton setFont: [UIFont boldSystemFontOfSize:SCALEoefficient(15)]];
+//    [self.clearnButton setTitle:@"清理缓存" forState:UIControlStateNormal];
+//    [self.clearnButton addTarget:self action:@selector(clearCacheWithFilePath) forControlEvents:UIControlEventTouchUpInside];
+//    
+//    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];
+//    }
+//
+//}
+//
+////  button普通状态下的背景色
+//- ( void )button1BackGroundNormal:(UIButton *)sender
+//{
+//     sender.backgroundColor = [UIColor redColor];
+//}
+// 
+////  button高亮状态下的背景色
+//- ( void )button1BackGroundHighlighted:(UIButton *)sender
+//{
+//     sender.backgroundColor = [UIColor orangeColor];
+//}
+//
+//#pragma mark ===============================================>> 存储和上传数据
+//- (void)clearCacheWithFilePath{
+//    
+//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+//    //获取完整路径
+//    NSString *documentsDirectory = [paths objectAtIndex:0];
+//    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:JBSDKLog];//这里就是你将要存储的沙盒路径(.plist文件,名字自定义)
+//    NSError *error = nil;
+//    //删除子文件夹
+//    [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
+//    if (error){
+//        NSLog(@"清理缓存失败");
+//        [PopupView showCusHUDA:@"清理失败"];
+//    }else{
+//        NSLog(@"清理缓存成功");
+//        [PopupView showCusHUDA:@"清理成功"];
+//    }
+//    
+//}
+//
+////数据写入沙河
+//-(void)writeFileToplist{
+//    
+//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+//    //获取完整路径
+//    NSString *documentsDirectory = [paths objectAtIndex:0];
+//    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:JBSDKLog];//这里就是你将要存储的沙盒路径(.plist文件,名字自定义)
+//
+//    if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]){//plistPath这个文件\文件夹是否存在
+//
+//        NSLog(@"-------文件不存在,写入文件----------");
+//
+//               NSError *error;
+//               if([self.tempStepString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error]){
+//                   NSLog(@"------写入文件------success");
+//               }else{
+//                    NSLog(@"------写入文件------fail,error==%@",error);
+//               };
+//
+//    }else{
+//
+////     NSLog(@"-------文件存在,追加文件----------");
+//       NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
+//       [fileHandle seekToEndOfFile];  //将节点跳到文件的末尾
+//       NSData* stringData  = [self.tempStepString dataUsingEncoding:NSUTF8StringEncoding];
+//       [fileHandle writeData:stringData]; //追加写入数据
+//       [fileHandle closeFile];
+//
+//    }
+//
+//}
+//
+//-(void)uploadpPlistFile{
+//    
+//    //这个方法获取出的结果是一个数组.因为有可以搜索到多个路径.
+//    NSArray *array =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+//    //在这里,我们指定搜索的是Cache目录,所以结果只有一个,取出Cache目录
+//    NSString *documentsDirectory = array[0];
+////    NSLog(@"%@",documentsDirectory);
+//    //拼接文件路径
+//    NSString *filePathName = [documentsDirectory stringByAppendingPathComponent:JBSDKLog];
+//    //如果保存的是一个数组.那就通过数组从文件当中加载.
+//    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_%@_%@.txt",Game_Type,[self getNowTimeTimestamp]] 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);
+//                    if (errorObject !=nil && [errorObject isKindOfClass:[NSDictionary class]]){
+//                        NSString * result = errorObject[@"result"];
+//                        if ([result intValue] ==1){
+//                            [PopupView showCusHUDA:@"上传成功"];
+//                        }
+//                        
+//                    }
+//
+//                }
+//                
+//          }
+//            
+//    }];
+// 
+//}
+//
+////获取当前时间戳有两种方法(以秒为单位)
+//-(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
+//

+ 16 - 0
SDK/BLE/ViceShoesAnalysis.h

@@ -0,0 +1,16 @@
+//
+//  ViceShoesAnalysis.h
+//  Unity-iPhone
+//
+//  Created by duowan123 on 2021/12/4.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ViceShoesAnalysis : NSObject
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 12 - 0
SDK/BLE/ViceShoesAnalysis.m

@@ -0,0 +1,12 @@
+//
+//  ViceShoesAnalysis.m
+//  Unity-iPhone
+//
+//  Created by duowan123 on 2021/12/4.
+//
+
+#import "ViceShoesAnalysis.h"
+
+@implementation ViceShoesAnalysis
+
+@end

BIN
SDK/HTTP/.DS_Store


+ 16 - 6
SDK/HTTP/HTTPDataProcession.h

@@ -12,14 +12,24 @@
 #define RequestSerializerType_URLEncoded @"application/x-www-form-urlencoded"
 #define RequestSerializerType_FormData @"form-data"
 
+#define CFBundleVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
+#define OS @"2"
+
 //#define BASE_URL @"http://shoes-api.hiyd.com"//正式环境
 #define BASE_URL @"http://test-shoes-api.hiyd.com"//测试环境
-#define GAME_INVITE [NSString stringWithFormat:@"%@%@",BASE_URL,@"/game/invite"]
-#define GAME_RECORD [NSString stringWithFormat:@"%@%@",BASE_URL,@"/gameRecord/addGame"]
-#define GAME_FRIENDS [NSString stringWithFormat:@"%@%@",BASE_URL,@"/forum/friends?limit=1000"]
-#define GAME_RANK [NSString stringWithFormat:@"%@%@",BASE_URL,@"/rank/game?ver=1.1.1&os=1"]
-#define GAME_START [NSString stringWithFormat:@"%@%@",BASE_URL,@"/game/start"]
-#define GAME_END [NSString stringWithFormat:@"%@%@",BASE_URL,@"/game/end"]
+//#define GAME_INVITE [NSString stringWithFormat:@"%@%@",BASE_URL,@"/game/invite"]
+//#define GAME_RECORD [NSString stringWithFormat:@"%@%@",BASE_URL,@"/gameRecord/addGame"]
+//#define GAME_FRIENDS [NSString stringWithFormat:@"%@%@",BASE_URL,@"/forum/friends"]
+//#define GAME_RANK [NSString stringWithFormat:@"%@%@",BASE_URL,@"/rank/game"]
+//#define GAME_START [NSString stringWithFormat:@"%@%@",BASE_URL,@"/game/start"]
+//#define GAME_END [NSString stringWithFormat:@"%@%@",BASE_URL,@"/game/end"]
+
+#define GAME_INVITE [NSString stringWithFormat:@"%@%@?v=%@&os=%@",BASE_URL,@"/game/invite",CFBundleVersion,OS]
+#define GAME_RECORD [NSString stringWithFormat:@"%@%@?v=%@&os=%@",BASE_URL,@"/gameRecord/addGame",CFBundleVersion,OS]
+#define GAME_FRIENDS [NSString stringWithFormat:@"%@%@?v=%@&os=%@",BASE_URL,@"/forum/friends",CFBundleVersion,OS]
+#define GAME_RANK [NSString stringWithFormat:@"%@%@?v=%@&os=%@",BASE_URL,@"/rank/game",CFBundleVersion,OS]
+#define GAME_START [NSString stringWithFormat:@"%@%@?v=%@&os=%@",BASE_URL,@"/game/start",CFBundleVersion,OS]
+#define GAME_END [NSString stringWithFormat:@"%@%@?v=%@&os=%@",BASE_URL,@"/game/end",CFBundleVersion,OS]
 
 typedef void(^SuccessBlock)(id data);
 typedef void(^FailBlock)(id errorDes);

+ 12 - 6
SDK/HTTP/HTTPDataProcession.m

@@ -145,8 +145,10 @@
 +(void)getFriendsList:(UserFriendsDataBlock)userFriendsDataBlock{
 
     NSLog(@"gameFriends token ===>> %@ ",IOSSDK_TOKEN);
+    
+    NSString *urlString =  [NSString stringWithFormat:@"%@&limit=%@&v=%@&os=%@",GAME_FRIENDS,@"1000",CFBundleVersion,OS];
 
-    [HTTPDataProcession getHTTPDataProcession:GAME_FRIENDS token:IOSSDK_TOKEN  success:^(id data){
+    [HTTPDataProcession getHTTPDataProcession:urlString token:IOSSDK_TOKEN  success:^(id data){
             // 网络访问成功
 //            NSLog(@"data=%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
             NSError * error;
@@ -212,7 +214,7 @@
 
 
 + (void)inviteFriends:(int)friendid info:(char*)info inviteDataBlock:(InviteDataBlock)inviteDataBlock{
-
+    
     NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
 
     NSString * token = [jsonDict objectForKey:@"token"];
@@ -221,7 +223,9 @@
     NSString * game_id = jsonDict[@"game_id"];
     NSLog(@"InviteFriend ===>> token:%@  friendid:%d  info:%s",token,friendid,info);
     
-    NSString *urlString = [NSString stringWithFormat:@"%@?invite_user_id=%@&invite=%@&game_id=%@",GAME_INVITE,invite_user_id,invite,game_id];
+    NSString *urlString = [NSString stringWithFormat:@"%@&invite_user_id=%@&invite=%@&game_id=%@",GAME_INVITE,invite_user_id,invite,game_id];
+    NSLog(@"InviteFriend urlString ===>> %@",urlString);
+
     [HTTPDataProcession getHTTPDataProcession:urlString token:token  success:^(id data){
         
             NSError * error;
@@ -239,7 +243,9 @@
                  }
                 
               }
+        
             }fail:^(id errorDes){
+                
     }];
     
 }
@@ -299,7 +305,7 @@
 
 //                            [gameFriends setValue:model.status forKey:@"status"];
                             NSMutableDictionary * user = [NSMutableDictionary new];
-                            [user setObject:[NSNumber numberWithInt:model.trans_id] forKey:@"id"];
+                            [user setObject:[NSNumber numberWithInt:model.user_id] forKey:@"id"];
                             [user setValue:model.user_name forKey:@"nickname"];
                             [user setObject:[NSNumber numberWithInt:model.user_gender] forKey:@"gender"];
                             [user setValue:@"" forKey:@"address"];
@@ -347,7 +353,7 @@
 */
 +(void)gameStart{
 
-    NSString *urlString = [NSString stringWithFormat:@"%@?id=%@",GAME_START,IOSSDK_GAMEID];
+    NSString *urlString = [NSString stringWithFormat:@"%@&id=%@",GAME_START,IOSSDK_GAMEID];
     [HTTPDataProcession getHTTPDataProcession:urlString token:IOSSDK_TOKEN  success:^(id data){
         
             NSError * error;
@@ -381,7 +387,7 @@
 */
 +(void)gameEnd{
     
-    NSString *urlString = [NSString stringWithFormat:@"%@?id=%@",GAME_END,IOSSDK_GAMEID];
+    NSString *urlString = [NSString stringWithFormat:@"%@&id=%@",GAME_END,IOSSDK_GAMEID];
     [HTTPDataProcession getHTTPDataProcession:urlString token:IOSSDK_TOKEN  success:^(id data){
         
             NSError * error;

+ 141 - 218
SDK/IOSPlatformSDK.mm

@@ -73,13 +73,6 @@ GetRankHandler getRankHandler;
 #pragma mark ============================>> ios call unity C语言指针声明 结束
 
 @interface IOSPlatformSDK ()
-
-//计算游戏启动时间
-@property(nonatomic,strong)NSDate * firstTime;
-
-@property(nonatomic,strong)UILabel * testLabel;
-@property(copy,nonatomic)NSString * macAddress;
-
 @end
 
 @implementation IOSPlatformSDK
@@ -102,8 +95,7 @@ static IOSPlatformSDK * instance;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
         instance = [super init];
-        [self initNotification];
-//        [self inittestLabel];
+        [self initData];
     });
     return instance;
 }
@@ -120,77 +112,34 @@ static IOSPlatformSDK * instance;
     NSString* finsalString = [arr2 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     NSDictionary * urlDict = [AlgorithmTool dictionaryWithJsonString:finsalString];
     NSLog(@"Schemes_Url转码的dict ========= %@",urlDict);
-        
-    //固定一个时间戳
-    NSString * timestamp =   [AlgorithmTool returnTimestamp];
-    [IOS_NSUSERDEFAULT setObject:timestamp forKey:IOSSDK_TIMESTAMP];
+    //缓存用户信息数据
+    [IOS_NSUSERDEFAULT setObject:urlDict forKey:IOSSDK_USERINFO];
     [IOS_NSUSERDEFAULT synchronize];
-    
+  
     if (urlDict!=nil){
-        //缓存用户信息数据
-        [IOS_NSUSERDEFAULT setObject:urlDict forKey:IOSSDK_USERINFO];
-        [IOS_NSUSERDEFAULT synchronize];
-        //主副设备:deviceType  游戏种类:game_id  mac地址:macAddress
-        BTDataProcess* bleInstance = [BTDataProcess sharedInstance];
-        bleInstance.deviceType = DEVICETYPE_MAIN;
-        NSString * game_id = urlDict[@"game_id"];
-        bleInstance.game_id = (GAME_TYPE)[game_id intValue];
+        //主副设备:deviceType  游戏种类:game_type  mac地址:macAddress
+        BTDataInstance.deviceType = DEVICETYPE_MAIN;
+        NSString * game_type = urlDict[@"game_type"];
+        BTDataInstance.game_type = (GAME_TYPE)[game_type intValue];
         if ([urlDict objectForKey:@"mac"]!=nil){
-            bleInstance.macAddress = [urlDict objectForKey:@"mac"];
-            self.macAddress = [urlDict objectForKey:@"mac"];
+            BTDataInstance.macAddress = [urlDict objectForKey:@"mac"];
         }
         //链接蓝牙
-        [bleInstance initCBCentralManager];
-        //数据存入plist
-        bleInstance.allMotionCountBLock = ^(int jump_count, int crouch_count, int step_count){
-//            NSLog(@"jump_count = %d crouch_count = %d step_count = %d ",jump_count,crouch_count,step_count);
-            [self cacheAllMotionCount:jump_count crouchCount:crouch_count stepCount:step_count];
-        };
+        [BTDataInstance initCBCentralManager];
+     
     }
-    //先打开app后已经创建了label,第二次open重新赋值
-    self.testLabel.text = [NSString stringWithFormat:@"%@ mac: %@",self.openStyle,self.macAddress];
     
 }
 
--(void)inittestLabel{
-    
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        
-        self.testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height-40,[UIScreen mainScreen].bounds.size.width, 40)];
-        self.testLabel.textColor = [UIColor redColor];
-        self.testLabel.font = [UIFont boldSystemFontOfSize:15];
-        self.testLabel.backgroundColor = [UIColor clearColor];
-        self.testLabel.textAlignment = NSTextAlignmentCenter;
-        self.testLabel.numberOfLines = 2;
-        if (self.macAddress.length>0) {
-            self.testLabel.text = [NSString stringWithFormat:@"%@ mac: %@",self.openStyle,self.macAddress];
-        }else{
-            self.testLabel.text = [NSString stringWithFormat:@"%@ mac: %@",self.openStyle,@"--"];
-        }
-
-        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:searchVC];
-        [rootVC.view addSubview:self.testLabel];
-        
-    });
-
-}
-
 #pragma mark ============================>> private 各类通知处理事件
--(void)initNotification{
+-(void)initData{
     
-    //监听各类通知action
-    [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(searchBLEAction:) name:@"searchBLEAction" object:nil];
-    //监听 app group 消息 ==>> 好友邀请信息
+    //固定一个时间戳
+    NSString * timestamp =   [AlgorithmTool returnTimestamp];
+    [IOS_NSUSERDEFAULT setObject:timestamp forKey:IOSSDK_TIMESTAMP];
+    [IOS_NSUSERDEFAULT synchronize];
+    
+    //监听 趣动 app group 消息 ==>> 好友邀请信息
     CFStringRef invite = (__bridge CFStringRef)@"INVITE_NOTIFICATION";
     CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                     NULL,
@@ -199,94 +148,95 @@ static IOSPlatformSDK * instance;
                                     NULL,
                                     CFNotificationSuspensionBehaviorDeliverImmediately);
     
+    //监听 趣动 app group 消息 ==>> 断开蓝牙
+    CFStringRef strRef = (__bridge CFStringRef)@"DISCONNECT_BLE";
+    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
+                                    NULL,
+                                    disConnectBle,
+                                    strRef,
+                                    NULL,
+                                    CFNotificationSuspensionBehaviorDeliverImmediately);
+    //监听程序 退到 后台
+    [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(enterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
+    //监听程序 返回 前台
+    [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(willEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
+
+}
+
+-(void)enterBackground{
+//    NSLog(@"leon UIApplicationDidEnterBackgroundNotification");
+    BTDataInstance.isBackGround = YES;
+}
+-(void)willEnterForeground{
+//    NSLog(@"leon UIApplicationWillEnterForegroundNotification");
+    BTDataInstance.isBackGround = NO;
+    NSLog(@"程序从后台返回 重连蓝牙 peripheral.state = %ld",LEManager.peripheral.state);
+    [BTDataInstance initCBCentralManager];
+}
+
+void disConnectBle (CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
+    [BTDataInstance disConnedctBle];
 }
 
-//趣动app:广播的通知回调
 void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
         
     //group.com.Oujia.AppAndGame 沙河数据
     NSUserDefaults* userDefault = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.Oujia.AppAndGame"];
-    //invite json字符串转字典
-    NSString * jsonString = [userDefault objectForKey:@"invite"];
-    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
-    NSDictionary *invite = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
-    NSLog(@"group通知监听好友邀请信息 invite jsonString = %@",invite);
-    if (invite!=nil){
-        //user字典转json字符串
-        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:invite options:NSJSONWritingPrettyPrinted error:nil];
-        NSString * inviteJsonString =  [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
-        const char * user =[inviteJsonString UTF8String];
-        //邀请信息
+    //趣动传过来的 invite json字符串转字典
+    NSString * string = [userDefault objectForKey:@"invite"];
+    NSData * data = [string dataUsingEncoding:NSUTF8StringEncoding];
+    NSDictionary * inviteDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
+    if (inviteDict!=nil){
+        //字典取值
+        NSDictionary * invite = [inviteDict objectForKey:@"invite"];
+        NSDictionary * user =  [invite objectForKey:@"user"];
+        //user字典 -> 字符串 -> Char
+        NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
+        NSString * userString =  [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
+        const char * userChar =[userString UTF8String];
+        //info字符串 -> Char
         NSString * infoString = invite[@"info"];
-        const char * info =[infoString UTF8String];
-        NSLog(@"unity 获取好友邀请信息 GetInviteInfo ===>> %@ %@",inviteJsonString,infoString);
-        inviteFriendHandler(0,user,info);
+        const char * infoChar =[infoString UTF8String];
+        NSLog(@"IOS_SKD 回调好友邀请信息 GetInviteInfo ===>>  %s , %s",userChar,infoChar);
+        inviteFriendHandler(0,userChar,infoChar);
     }
     
 }
 
-//通知开始游戏
--(void)gameStartInitData{
-    NSLog(@"unity call ios 通知开始游戏 --> IOSPlatformSDK");
-    if ([self existUserInfo]){
-        self.firstTime = [NSDate date];
-    }
-}
-
-//通知结束游戏
--(void)gameEndInitData:(NSNotification*)notification{
-    NSLog(@"unity call ios 通知结束游戏 --> IOSPlatformSDK");
-}
-
-//通知弹出蓝牙搜索框
--(void)searchBLEAction:(NSNotification*)notification{
+//unity call instance弹出蓝牙搜索框
+-(void)searchBLEAction:(int)type{
     
-    NSLog(@"unity call ios 通知游戏弹窗 --> IOSPlatformSDK");
-    if ([instance existUserInfo]==NO){
-        return;
-    }
     /***************************初始化蓝牙数据处理工具***************************/
-    //主副设备:deviceType  游戏种类:game_id  mac地址:macAddress
-    BTDataProcess* bleInstance = [BTDataProcess sharedInstance];
-    NSDictionary * notificationDict = notification.userInfo;
-    NSNumber * typeNumber = [notificationDict objectForKey:@"type"];
-    int type = [typeNumber intValue];
-    bleInstance.deviceType = (DEVICE_TYPE)type;
+    //主副设备:deviceType  游戏种类:game_type  mac地址:macAddress
+    BTDataInstance.deviceType = (DEVICE_TYPE)type;
     NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
-    NSString * game_id = jsonDict[@"game_id"];
-    bleInstance.game_id = (GAME_TYPE)[game_id intValue];
-    bleInstance.macAddress = @"";
+    NSString * game_type = jsonDict[@"game_type"];
+    BTDataInstance.game_type = (GAME_TYPE)[game_type intValue];
+    BTDataInstance.macAddress = @"";
     //初始化蓝牙CBCentralManager
-    [bleInstance initCBCentralManager];
-    //缓存动作数据
-    bleInstance.allMotionCountBLock = ^(int jump_count, int crouch_count, int step_count){
-//        NSLog(@"jump_count = %d crouch_count = %d step_count = %d ",jump_count,crouch_count,step_count);
-        [self cacheAllMotionCount:jump_count crouchCount:crouch_count stepCount:step_count];
-    };
+    [BTDataInstance initCBCentralManager];
 
     /***************************搜索蓝牙外设弹窗***************************/
     SearchDeviceViewController  * searchVC = [SearchDeviceViewController  new];
     [self addTOwindow:searchVC];
     //searchVC搜索蓝牙Button
     searchVC.searchDeviceTask = ^{
-        [bleInstance initCBCentralManager];
+        [BTDataInstance initCBCentralManager];
     };
     //BTDataProces搜索到的蓝牙外设-->searchVC
-    bleInstance.deviceArrBLock = ^(NSMutableArray * arr){//蓝牙数据回调 刷新popView数据
+    BTDataInstance.deviceArrBLock = ^(NSMutableArray * arr){//蓝牙数据回调 刷新popView数据
         searchVC.deviceArray = arr;
         [searchVC reloadData];
-//        [searchVC hideAnimation];
     };
     //点击searchVC的tableViewCell链接选中的蓝牙
     searchVC.connectDeviceBlock = ^(CBPeripheral * peripheral){
-        bleInstance.deviceType = (DEVICE_TYPE)type;
-//        NSLog(@"connectDeviceBlock = %@ %ld",peripheral,(long)bleInstance.deviceType);
-        [bleInstance connectPeripheral:peripheral];
-        bleInstance.macAddress = peripheral.identifier.UUIDString;
+        BTDataInstance.deviceType = (DEVICE_TYPE)type;
+        [BTDataInstance connectPeripheral:peripheral];
+        BTDataInstance.macAddress = peripheral.identifier.UUIDString;
     };
     
     //bleInstance脚步交互动作-->searchVC
-    bleInstance.getInteractionBlock = ^(int interaction){
+    BTDataInstance.getInteractionBlock = ^(int interaction){
         if (interaction!=-1){
             NSLog(@"BTDataProcess 有效交互动作 ===>> %d",interaction);
 //            [searchVC getInteraction:interaction];
@@ -296,8 +246,9 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
     };
     
 }
-//
-#pragma mark ============================>> private 全局弹窗
+
+#pragma mark ============================>> private
+//全局弹窗
 -(void)addTOwindow:(UIViewController*)searchVC{
     
     UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
@@ -313,38 +264,20 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
     
 }
 
-#pragma mark ============================>> private 缓存处理
+#pragma mark ============================>> private
 //是否已经缓存到用户信息
 -(BOOL)existUserInfo{
     
     NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
      if (jsonDict==nil){
-//         [PopupView showCusHUDA:@"获取趣动用户数据失败"];
-         return YES;
+//         [PopupView showCusHUDA:@"请从趣动App启动"];
+         return NO;
      }else{
          return YES;
      }
     
 }
 
-//玩游戏过程中缓存 动作数据 和时间戳
--(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];
-    
-}
-
 #pragma mark ============================>> ios call unity
 -(void)bridgingMotionAction:(int)cusid
                        left:(int)left
@@ -359,8 +292,9 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
               rightStatus:(int)rightStatus
                  leftFrag:(int)leftFrag
                 rightFrag:(int)rightFrag{
-    //        NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
-    stepHandler(cusid,leftStatus,rightStatus,leftFrag,rightFrag);
+    if (stepHandler != nil) {
+        stepHandler(cusid,leftStatus,rightStatus,leftFrag,rightFrag);
+    }
 }
 
 -(void)bridgingDeviceAction:(int)cusid
@@ -369,22 +303,24 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
                      status:(int)status
                 electricity:(int)electricity{
 //        NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
-    //
     const char * charName =[name UTF8String];
     const char * charAddress =[address UTF8String];
-    deviceHandler(cusid,charName,charAddress,status,electricity);
+    if (deviceHandler != nil) {
+        deviceHandler(cusid,charName,charAddress,status,electricity);
+    }
+    
 }
 
-
 -(void)bridgingInteraction:(int)cusid
                       code:(int)code{
     //传给unity ---> 旧版游戏未用到
-//    actionHandler(cusid,code);
+    if (actionHandler != nil) {
+//            actionHandler(cusid,code);
+    }
 }
 
 @end
 
-
 #pragma mark ============================>> unity call ios
 /**
  * c语言字符串指针malloc
@@ -474,16 +410,14 @@ extern "C" {void PointerGetRankHandler(GetRankHandler  handler){
  * 游戏开始
  */
 void GameStart(){
-    
    NSLog(@"Unity 请求开始游戏 GameStart ===>>");
-
    if ([instance existUserInfo]==NO){
         return;
    }
-    
-   [CUS_NOTIFICATIONCENTER postNotificationName:@"gameStartInitData" object:nil];
-   [HTTPDataProcession gameStart];
-
+    //蓝牙
+    [BTDataInstance gameStartInitData];
+    //http
+    [HTTPDataProcession gameStart];
 }
 
 /**
@@ -497,21 +431,18 @@ void GameStart(){
 void GameEnd(int level, double score, int record, int mode, int opponentId){
     
     NSLog(@"Unity 请求结束游戏 GameEnd ===>> %d %f %d %d %d",level,score,record,mode,opponentId);
-    
     if ([instance existUserInfo]==NO){
         return;
     }
     
-    [CUS_NOTIFICATIONCENTER postNotificationName:@"gameEndInitData" object:nil];
-
+    [BTDataInstance gameEndInitData];
+    //http
     [HTTPDataProcession gameEnd];
-
     //上传数据
     [HTTPDataProcession postGameRecord:level score:score record:record mode:mode opponentId:opponentId gameEndDataBlock:^(NSString *jsonString){
         NSLog(@"IOS_SKD 回调结束游戏请求 GameEnd ===> %@",jsonString);
     }];
-    
- }
+}
 
 /**
 * 搜索设备
@@ -519,10 +450,12 @@ void GameEnd(int level, double score, int record, int mode, int opponentId){
 */
 void SearchDevice(int type){
     //unity 有两个search按钮 type 0是主设备 1是副设备
-    NSDictionary * dict = @{@"type":@(type)};
-    NSLog(@"Unity 请求搜索设备 SearchDevice ===>> %@",dict);
-    [CUS_NOTIFICATIONCENTER postNotificationName:@"searchBLEAction" object:nil userInfo:dict];
-  }
+    NSLog(@"Unity 请求搜索设备 type ===>> %d",type);
+//    if ([instance existUserInfo]==NO){
+//        return;
+//    }
+    [instance searchBLEAction:type];
+}
 
 /**
 * 链接设备
@@ -530,6 +463,9 @@ void SearchDevice(int type){
 */
 void ConnectDevice(int type){
     NSLog(@"Unity 请求链接设备 ConnectDevice ===>> %d",type);
+    if ([instance existUserInfo]==NO){
+        return;
+    }
     //unity 有两个connect按钮 type 0是第一个玩家 1是第二个玩家
 }
 
@@ -539,47 +475,36 @@ void ConnectDevice(int type){
 * duration: 时长 ms [100 .. 1000]
 */
 void  Vibrate(int type,int duration){
-    //unity 有两个search按钮 type 0是主设备 1是副设备
-    NSMutableDictionary * obj = [NSMutableDictionary new];
-    [obj setObject:@(type) forKey:@"type"];
-    [obj setObject:@(duration) forKey:@"duration"];
-    NSDictionary * dict = [NSDictionary dictionaryWithDictionary:obj];
-    NSLog(@"vibrate ===>> %@",dict);
-    [CUS_NOTIFICATIONCENTER postNotificationName:@"vibrationAction" object:nil userInfo:dict];
+    if ([instance existUserInfo]==NO){
+        return;
+    }
+    [BTDataInstance vibrationAction:type duration:duration];
 }
 
 /**
 * unity获取用户好友列表 -->> ios端根据用户token值请求http好友列表 ios将列表json的数组数据传给unity
 */
 void GetUserFriends(){
-    
-    NSLog(@"Unity 请求好友列表 GetUserFriends ===>>");
-
+//    NSLog(@"Unity 请求好友列表 GetUserFriends ===>>");
     if ([instance existUserInfo]==NO){
         return;
     }
-    
     [HTTPDataProcession getFriendsList:^(int code, const char *jsonString){
         NSLog(@"IOS_SKD 回调好友列表 GetUserFriends ===> %s",jsonString);
         userFriendsHandler(code,jsonString);//异步回调
     }];
-
 }
 
 /**
 * unity获取用户信息 -->> 解析从Spotr App的传过来的RL_Seme  ios返回json数据给游戏
 */
  char *  GetUserInfoJson(){
-     
-     NSLog(@"Unity 请求用户信息 GetUserInfoJson ===>>");
-
+//     NSLog(@"Unity 请求用户信息 GetUserInfoJson ===>>");
      if ([instance existUserInfo]==NO){
          return MakeStringCopy("");
      }else{
-         
          NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
          NSDictionary * user = jsonDict[@"user"];
-         
          if (user!=nil){
              NSData *jsonData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
              NSString * userJsonString =  [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
@@ -590,6 +515,7 @@ void GetUserFriends(){
          }else{
              return MakeStringCopy("");
          }
+         
      }
      
 }
@@ -600,6 +526,9 @@ void GetUserFriends(){
 */
 void DisConnectDevice(int type){
     NSLog(@"Unity 请求断开蓝牙链接 disConnectDevice ===>>");
+    if ([instance existUserInfo]==NO){
+        return;
+    }
 }
 
 /**
@@ -607,22 +536,17 @@ void DisConnectDevice(int type){
 * friendid: 游戏好友ID
 */
 void InviteFriend(int friendid,char * info){
-    
     NSLog(@"Unity 点击邀请好友 InviteFriend ===>>");
-
     if ([instance existUserInfo]==NO){
         return;
     }
-
     [HTTPDataProcession inviteFriends:friendid info:info inviteDataBlock:^(NSString *jsonString){
-        
 //        NSLog(@"IOS_SKD 回调点击邀请好友事件 InviteFriend ===>>");
         dispatch_async(dispatch_get_main_queue(), ^{
-        [PopupView showCusHUDA:@"邀请成功"];
+        [PopupView showCusHUDA:jsonString];
         });
         
     }];
-   
 }
 
 /**
@@ -632,29 +556,24 @@ void InviteFriend(int friendid,char * info){
 void GetInviteInfo(){
     
     NSLog(@"Unity获取好友邀请信息 GetInviteInfo ===>>");
-    
-    return;
     if ([instance existUserInfo]==NO){
-        
         return;
-        
-    }else{
-        
-        NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
-        NSDictionary * invite = jsonDict[@"invite"];
-        if (invite!=nil){
-            //user字典转json字符串
-            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:invite options:NSJSONWritingPrettyPrinted error:nil];
-            NSString * inviteJsonString =  [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
-            const char * user =[inviteJsonString UTF8String];
-            //邀请信息
-            NSString * infoString = invite[@"info"];
-            const char * info =[infoString UTF8String];
-            NSLog(@"IOS_SKD 回调好友邀请信息 GetInviteInfo ===>>  %@ , %@",inviteJsonString,infoString);
-            inviteFriendHandler(0,user,info);
-        }
-        
     }
+    NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
+    NSDictionary * invite = jsonDict[@"invite"];
+    if (invite!=nil){
+        //user字典 -> 字符串 -> Char
+        NSDictionary * user =  [invite objectForKey:@"user"];
+        NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
+        NSString * userString =  [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
+        const char * userChar =[userString UTF8String];
+        //info字符串 -> Char
+        NSString * info = invite[@"info"];
+        const char * infoChar =[info UTF8String];
+        NSLog(@"IOS_SKD 回调好友邀请信息 GetInviteInfo ===>>  %s , %s",userChar,infoChar);
+        inviteFriendHandler(0,userChar,infoChar);
+    }
+    
 }
 
 /**
@@ -662,6 +581,9 @@ void GetInviteInfo(){
 */
 void ScreenProjection(){
     NSLog(@"Unity 请求投屏事件 ScreenProjection ===>>");
+    if ([instance existUserInfo]==NO){
+        return;
+    }
 }
 
 /**
@@ -670,6 +592,9 @@ void ScreenProjection(){
 */
 void ShowInviteFriend(int code, char * info){
     NSLog(@"Unity 请求打开好友列表弹窗 ShowInviteFriend ===>>");
+    if ([instance existUserInfo]==NO){
+        return;
+    }
 }
 
 /**
@@ -678,15 +603,13 @@ void ShowInviteFriend(int code, char * info){
  *ios 请求完数据后用 PointerGetRankHandler 回调数据给unity
 */
 void GetRank(int type){
-    
-    NSLog(@"Unity 获取榜单列表数据 GetRank ===>> %d",type);
+//    NSLog(@"Unity 获取榜单列表数据 GetRank ===>> %d",type);
     if ([instance existUserInfo]==NO){
         return;
     }
     [HTTPDataProcession GetRank:type rankDataBlock:^(const char *jsonString){
         NSLog(@"IOS_SKD 回调 榜单列表数据 GetRank ===>> %d %s",type,jsonString);
         getRankHandler(type,jsonString);
-        //new pop
     }];
 
 }

+ 1 - 1
SDK/PrefixHeader.h

@@ -32,7 +32,7 @@
 //#define IOS_NSUSERDEFAULT [NSUserDefaults standardUserDefaults]
 //#define CUS_NOTIFICATIONCENTER [NSNotificationCenter defaultCenter]
 //#define IOSSDK_TOKEN [[IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO] objectForKey:@"token"]
-//#define IOSSDK_GAMEID [[IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO] objectForKey:@"game_id"]
+//#define IOSSDK_GAMEID [[IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO] objectForKey:@"game_type"]
 ////#define IOSSDK_GAMEID @"3"
 ////#define IOSSDK_TOKEN @"shoes:61652aa99523f9.65681365I94"
 //

BIN
SDK/ThirdClass/.DS_Store


+ 156 - 156
SDK/Tool/GameObjc.h

@@ -1,157 +1,157 @@
-
-#import <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface GameObjc : NSObject
-+ (instancetype)new NS_UNAVAILABLE;
-- (instancetype)init NS_UNAVAILABLE;
-- (instancetype)initWithGametype:(int)gametype NS_DESIGNATED_INITIALIZER;
-
-- (void)gameProcess:(int)timeStamp
-           rightPos:(int *)rightPos
-           rightAtt:(int *)rightAtt
-           rightAcc:(int *)rightAcc
-          rightZupt:(int)rightZupt
-        right_press:(int)right_press
-            leftPos:(int *)leftPos
-            leftAtt:(int *)leftAtt
-           leftAcc:(int *)leftAcc
-           leftZupt:(int)leftZupt
-         left_press:(int)left_press
-               jump:(int)jump
-               down:(int)down
-               rssi:(int)rssi
-         girl_shoes:(int)girl_shoes;
-
-- (void)runGameProcess:(int)timeStamp
-              rightPos:(int *)rightPos
-              rightAtt:(int *)rightAtt
-              rightAcc:(int *)rightAcc
-             rightZupt:(int)rightZupt
-           right_press:(int)right_press
-               leftPos:(int *)leftPos
-               leftAtt:(int *)leftAtt
-              leftAcc:(int *)leftAcc
-              leftZupt:(int)leftZupt
-            left_press:(int)left_press
-                  jump:(int)jump
-                  down:(int)down
-            girl_shoes:(int)girl_shoes;
-
-- (void)getGameResult:(int *)matrix;
-
-- (int)getStepFreq:(int)leftOrRight;
-- (int)getStepStatus:(int)leftOrRight;
-- (int)getStepCount:(int)leftOrRight;
-
-- (float)getGamePos:(int)left_or_right index:(int)index;
-
-- (void)start;
-- (void)end;
-- (void)isBingo;
--(int)getInteractionCMD;
--(NSString*)getGameDataStr;
--(void)GameProcessBuf:(uint8_t*)buff length:(int)length;
-
-/// 向外提供,手动释放,如需要,可调用
-- (void)handRelease;
-
-@end
-
-@interface RunGameObjc : NSObject
-- (int)getResultLeftRight:(int *)pos
-                   devNum:(short)devNum;
-- (int)getResultJump:(short)jump;
-- (int)getResultDown:(short)down;
-- (void)setResultConLeft:(short)zupt;
-- (void)setResultConRight:(short)zupt;
-- (int)getResultLeft:(int *)pos girl_shoes:(int)girl_shoes;
-- (int)getResultRight:(int *)pos girl_shoes:(int)girl_shoes;
-- (void)process:(int)timeStamp
-       rightPos:(int *)rightPos
-       rightAtt:(int *)rightAtt
-       rightAcc:(int *)rightAcc
-      rightZupt:(int)rightZupt
-    right_press:(int)right_press
-        leftPos:(int *)leftPos
-        leftAtt:(int *)leftAtt
-       leftAcc:(int *)leftAcc
-       leftZupt:(int)leftZupt
-     left_press:(int)left_press
-           jump:(int)jump
-           down:(int)down
-     girl_shoes:(int)girl_shoes;
-- (void)getResult:(int *)dec;
-/// 向外提供,手动释放
-- (void)handRelease;
-@end
-
-@interface DanceGameObjc : NSObject
-//- (int)gamePositionProcess:(int *)pos
-//                   stepPos:(int *)stepPos
-//                      rssi:(int)rssi
-//               hostOrSlave:(short)hostOrSlave;
-//- (void)gameBoundary:(int *)globalPos;
-//- (int)getDirectionFloat:(float *)pos rssi:(int)rssi;
-//- (short)danceGameProcess:(int *)pos
-//                     zupt:(short)zupt
-//                     rssi:(int)rssi
-//              hostOrSlave:(short)hostOrSlave;
-- (void)process:(int *)rightPos
-       rightAtt:(int *)rightAtt
-      rightZupt:(int)rightZupt
-    right_press:(int)right_press
-        leftPos:(int *)leftPos
-        leftAtt:(int *)leftAtt
-       leftZupt:(int)leftZupt
-     left_press:(int)left_press
-           jump:(int)jump
-           down:(int)down
-           rssi:(int)rssi;
-
-- (void)getResult:(int *)matrix;
-//- (float)getRssiDistance:(int)rssi;
-//- (int)savePosAndRssi:(int *)pos
-//                 zupt:(short)zupt
-//                 rssi:(int)rssi
-//          hostOrSlave:(short)hostOrSlave;
-/// 向外提供,手动释放,如需要,可调用
-- (void)handRelease;
-@end
-
-
-@interface FootStepObjc : NSObject
-//pos开辟3个空间
-- (void)stepCal:(int)timeStamp posList:(int *)pos zupt:(int)zupt;
-- (int)getStepFreq;
-- (int)getStepStatus;
-- (int)getStepCount;
-/// 向外提供,手动释放,如需要,可调用
-- (void)handRelease;
-@end
-
-
-@interface InertialTrajProcessObjc : NSObject
-- (void)trajRotate:(int *)pos;
-//rotateMatrix只能开辟4个空间
-- (void)trajRotate:(int *)pos
-      rotateMatrix:(float *)rotateMatrix;
-- (void)resetHeading:(short)heading;
-/// 向外提供,手动释放
-- (void)handRelease;
-@end
-
-//@interface OriginTrajObj : NSObject
-//- (void)process:(int*)right_pos
-//        right_att:(int*)right_att
-//        right_zupt:(int)right_zupt
-//        left_pos:(int*)left_pos
-//        left_att:(int*)left_att
-//        left_zupt:(int) left_zupt;
-//
-//- (float)getGamePos:(int)left_or_right
-//               index:(int)index;
+//
+//#import <Foundation/Foundation.h>
+//
+//NS_ASSUME_NONNULL_BEGIN
+//
+//@interface GameObjc : NSObject
+//+ (instancetype)new NS_UNAVAILABLE;
+//- (instancetype)init NS_UNAVAILABLE;
+//- (instancetype)initWithGametype:(int)gametype NS_DESIGNATED_INITIALIZER;
+//
+//- (void)gameProcess:(int)timeStamp
+//           rightPos:(int *)rightPos
+//           rightAtt:(int *)rightAtt
+//           rightAcc:(int *)rightAcc
+//          rightZupt:(int)rightZupt
+//        right_press:(int)right_press
+//            leftPos:(int *)leftPos
+//            leftAtt:(int *)leftAtt
+//           leftAcc:(int *)leftAcc
+//           leftZupt:(int)leftZupt
+//         left_press:(int)left_press
+//               jump:(int)jump
+//               down:(int)down
+//               rssi:(int)rssi
+//         girl_shoes:(int)girl_shoes;
+//
+//- (void)runGameProcess:(int)timeStamp
+//              rightPos:(int *)rightPos
+//              rightAtt:(int *)rightAtt
+//              rightAcc:(int *)rightAcc
+//             rightZupt:(int)rightZupt
+//           right_press:(int)right_press
+//               leftPos:(int *)leftPos
+//               leftAtt:(int *)leftAtt
+//              leftAcc:(int *)leftAcc
+//              leftZupt:(int)leftZupt
+//            left_press:(int)left_press
+//                  jump:(int)jump
+//                  down:(int)down
+//            girl_shoes:(int)girl_shoes;
+//
+//- (void)getGameResult:(int *)matrix;
+//
+//- (int)getStepFreq:(int)leftOrRight;
+//- (int)getStepStatus:(int)leftOrRight;
+//- (int)getStepCount:(int)leftOrRight;
+//
+//- (float)getGamePos:(int)left_or_right index:(int)index;
+//
+//- (void)start;
+//- (void)end;
+//- (void)isBingo;
+//-(int)getInteractionCMD;
+//-(NSString*)getGameDataStr;
+//-(void)GameProcessBuf:(uint8_t*)buff length:(int)length;
+//
+///// 向外提供,手动释放,如需要,可调用
+//- (void)handRelease;
+//
+//@end
+//
+//@interface RunGameObjc : NSObject
+//- (int)getResultLeftRight:(int *)pos
+//                   devNum:(short)devNum;
+//- (int)getResultJump:(short)jump;
+//- (int)getResultDown:(short)down;
+//- (void)setResultConLeft:(short)zupt;
+//- (void)setResultConRight:(short)zupt;
+//- (int)getResultLeft:(int *)pos girl_shoes:(int)girl_shoes;
+//- (int)getResultRight:(int *)pos girl_shoes:(int)girl_shoes;
+//- (void)process:(int)timeStamp
+//       rightPos:(int *)rightPos
+//       rightAtt:(int *)rightAtt
+//       rightAcc:(int *)rightAcc
+//      rightZupt:(int)rightZupt
+//    right_press:(int)right_press
+//        leftPos:(int *)leftPos
+//        leftAtt:(int *)leftAtt
+//       leftAcc:(int *)leftAcc
+//       leftZupt:(int)leftZupt
+//     left_press:(int)left_press
+//           jump:(int)jump
+//           down:(int)down
+//     girl_shoes:(int)girl_shoes;
+//- (void)getResult:(int *)dec;
+///// 向外提供,手动释放
+//- (void)handRelease;
+//@end
+//
+//@interface DanceGameObjc : NSObject
+////- (int)gamePositionProcess:(int *)pos
+////                   stepPos:(int *)stepPos
+////                      rssi:(int)rssi
+////               hostOrSlave:(short)hostOrSlave;
+////- (void)gameBoundary:(int *)globalPos;
+////- (int)getDirectionFloat:(float *)pos rssi:(int)rssi;
+////- (short)danceGameProcess:(int *)pos
+////                     zupt:(short)zupt
+////                     rssi:(int)rssi
+////              hostOrSlave:(short)hostOrSlave;
+//- (void)process:(int *)rightPos
+//       rightAtt:(int *)rightAtt
+//      rightZupt:(int)rightZupt
+//    right_press:(int)right_press
+//        leftPos:(int *)leftPos
+//        leftAtt:(int *)leftAtt
+//       leftZupt:(int)leftZupt
+//     left_press:(int)left_press
+//           jump:(int)jump
+//           down:(int)down
+//           rssi:(int)rssi;
+//
+//- (void)getResult:(int *)matrix;
+////- (float)getRssiDistance:(int)rssi;
+////- (int)savePosAndRssi:(int *)pos
+////                 zupt:(short)zupt
+////                 rssi:(int)rssi
+////          hostOrSlave:(short)hostOrSlave;
+///// 向外提供,手动释放,如需要,可调用
+//- (void)handRelease;
+//@end
+//
+//
+//@interface FootStepObjc : NSObject
+////pos开辟3个空间
+//- (void)stepCal:(int)timeStamp posList:(int *)pos zupt:(int)zupt girl_shoes:(int)girl_shoes;
+//- (int)getStepFreq;
+//- (int)getStepStatus;
+//- (int)getStepCount;
+///// 向外提供,手动释放,如需要,可调用
+//- (void)handRelease;
+//@end
+//
+//
+//@interface InertialTrajProcessObjc : NSObject
+//- (void)trajRotate:(int *)pos;
+////rotateMatrix只能开辟4个空间
+//- (void)trajRotate:(int *)pos
+//      rotateMatrix:(float *)rotateMatrix;
+//- (void)resetHeading:(short)heading;
+///// 向外提供,手动释放
+//- (void)handRelease;
 //@end
-
-NS_ASSUME_NONNULL_END
+//
+////@interface OriginTrajObj : NSObject
+////- (void)process:(int*)right_pos
+////        right_att:(int*)right_att
+////        right_zupt:(int)right_zupt
+////        left_pos:(int*)left_pos
+////        left_att:(int*)left_att
+////        left_zupt:(int) left_zupt;
+////
+////- (float)getGamePos:(int)left_or_right
+////               index:(int)index;
+////@end
+//
+//NS_ASSUME_NONNULL_END

+ 367 - 367
SDK/Tool/GameObjc.mm

@@ -1,387 +1,387 @@
-
-#import "GameObjc.h"
-#include "Game.h"
-#include "DanceGame.h"
-#include "FootStep.h"
-#include "InertialTrajProcess.h"
-//#include "OriginTraj.h"
-//#include <math.h>
-
-#define NSLog(format, ...) printf("TIME:%s FILE:%s(%d行) FUNCTION:%s \n %s\n\n",__TIME__, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
-
-
-@interface GameObjc()
-{
-@private
-    Game *game;
-    int gametype;
-}
-@end
-
-@implementation GameObjc
-
-- (instancetype)initWithGametype:(int)gametype{
-    self = [super init];
-    if (self){
-        gametype = gametype;
-        game = new Game(gametype);
-    }
-    return self;
-}
-
-- (void)gameProcess:(int)timeStamp
-           rightPos:(int *)rightPos
-           rightAtt:(int *)rightAtt
-           rightAcc:(int *)rightAcc
-          rightZupt:(int)rightZupt
-        right_press:(int)right_press
-            leftPos:(int *)leftPos
-            leftAtt:(int *)leftAtt
-           leftAcc:(int *)leftAcc
-           leftZupt:(int)leftZupt
-         left_press:(int)left_press
-               jump:(int)jump
-               down:(int)down
-               rssi:(int)rssi
-         girl_shoes:(int)girl_shoes{
-    game->GameProcess(timeStamp, rightPos, rightAtt, rightAcc,rightZupt,right_press,leftPos, leftAtt, leftAcc,leftZupt, left_press,jump,down, rssi,girl_shoes);
-}
-
-- (void)runGameProcess:(int)timeStamp
-              rightPos:(int *)rightPos
-              rightAtt:(int *)rightAtt
-              rightAcc:(int *)rightAcc
-             rightZupt:(int)rightZupt
-           right_press:(int)right_press
-               leftPos:(int *)leftPos
-               leftAtt:(int *)leftAtt
-              leftAcc:(int *)leftAcc
-              leftZupt:(int)leftZupt
-            left_press:(int)left_press
-                  jump:(int)jump
-                  down:(int)down
-            girl_shoes:(int)girl_shoes{
-    game->RunGameProcess(rightPos, rightAtt, rightAcc,rightZupt,right_press,leftPos, leftAtt, leftAcc,leftZupt, left_press,jump,down,girl_shoes);
-    
-}
-
-- (void)getGameResult:(int *)matrix{
-    game->getGameResult(matrix);
-}
-
-- (int)getStepFreq:(int)leftOrRight{
-    return game->getStepFreq(leftOrRight);
-}
-- (int)getStepStatus:(int)leftOrRight{
-    return game->getStepStatus(leftOrRight);
-}
-- (int)getStepCount:(int)leftOrRight{
-    return game->getStepCount(leftOrRight);
-}
-
-- (float)getGamePos:(int)left_or_right index:(int)index{
-    return game->getGamePos(left_or_right, index);
-}
-
-- (void)start{
-    game->start(nil);
-}
-- (void)end{
-    game->end();
-}
-
-- (void)isBingo{
-    game->isBingo();
-}
-
--(int)getInteractionCMD{
-    return game->getInteractionCMD();
-}
-
--(NSString*)getGameDataStr{
-    
-//    NSString * string =  [NSString stringWithCString:game->getGameDataStr().c_str() encoding:[NSString defaultCStringEncoding]];
-    NSString * aString = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
-//    NSLog(@"剑波需要的数据1 %@",string);
-//    NSLog(@"剑波需要的数据2 %@",aString);
-    return aString;
-    
-}
-
--(void)GameProcessBuf:(uint8_t*)buff length:(int)length{
-    
-    game->GameProcessBuf(buff, length);
-    
-}
-
-/// 向外提供,手动释放
-- (void)handRelease{
-    delete game;
-}
-- (void)dealloc{
-    delete game;
-}
-
-@end
-
-@interface RunGameObjc ()
-{
-    @private
-    RunGame * runGame;
-}
-@end
-
-@implementation RunGameObjc
-- (instancetype)init{
-    self = [super init];
-    if (self) {
-        runGame = new RunGame();
-    }
-    return self;
-}
-- (int)getResultLeftRight:(int *)pos
-                   devNum:(short)devNum{
-    return runGame->getResultLeftRight(pos, devNum);
-}
-- (int)getResultJump:(short)jump{
-    return runGame->getResultJump(jump);
-}
-- (int)getResultDown:(short)down{
-    return runGame->getResultDown(down);
-}
-- (void)setResultConLeft:(short)zupt{
-    runGame->setResultConLeft(zupt);
-}
-- (void)setResultConRight:(short)zupt{
-     runGame->setResultConRight(zupt);
-}
-- (int)getResultLeft:(int *)pos girl_shoes:(int)girl_shoes{
-    return runGame->getResultLeft(pos,girl_shoes);
-}
-- (int)getResultRight:(int *)pos girl_shoes:(int)girl_shoes{
-    return runGame->getResultRight(pos,girl_shoes);
-}
-
-- (void)process:(int)timeStamp
-       rightPos:(int *)rightPos
-       rightAtt:(int *)rightAtt
-       rightAcc:(int *)rightAcc
-      rightZupt:(int)rightZupt
-    right_press:(int)right_press
-        leftPos:(int *)leftPos
-        leftAtt:(int *)leftAtt
-       leftAcc:(int *)leftAcc
-       leftZupt:(int)leftZupt
-     left_press:(int)left_press
-           jump:(int)jump
-           down:(int)down
-     girl_shoes:(int)girl_shoes{
-    
-    runGame->Process(rightPos, rightAtt, rightAcc,rightZupt,right_press,leftPos, leftAtt, leftAcc,leftZupt, left_press,jump,down,girl_shoes);
-    
-//    Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
-//                 int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
-//                 int jump, int down, int girl_shoes)
-    
-}
-
-- (void)getResult:(int *)dec{
-    runGame->getResult(dec);
-}
-
-/// 向外提供,手动释放
-- (void)handRelease{
-    delete runGame;
-}
-- (void)dealloc{
-    delete runGame;
-}
-@end
-
-@interface DanceGameObjc()
-{
-@private
-    DanceGame *danceGame;
-}
-@end
-
-@implementation DanceGameObjc
-- (instancetype)init{
-    self = [super init];
-    if (self) {
-        danceGame = new DanceGame();
-    }
-    return self;
-}
-
-//- (int)gamePositionProcess:(int *)pos
-//                   stepPos:(int *)stepPos
-//                      rssi:(int)rssi
-//               hostOrSlave:(short)hostOrSlave{
-//    //SInt16 ==> short*
-//    return  danceGame->game_position_process(pos, stepPos, rssi, hostOrSlave);
-//}
-
-//- (void)gameBoundary:(int *)globalPos{
-//    danceGame->game_boundary(globalPos);
-//}
-//- (int)getDirectionFloat:(float *)pos
-//                    rssi:(int)rssi{
-//    //float==>32位
-//    return  danceGame->getDirectionFloat(pos,rssi);
-//}
-//- (short)danceGameProcess:(int *)pos
-//                     zupt:(short)zupt
-//                     rssi:(int)rssi
-//              hostOrSlave:(short)hostOrSlave{
-//    return danceGame->dance_game_process(pos, zupt, rssi, hostOrSlave);
-//}
-
-- (void)process:(int *)rightPos
-       rightAtt:(int *)rightAtt
-       rightAcc:(int *)rightAcc
-      rightZupt:(int)rightZupt
-    right_press:(int)right_press
-        leftPos:(int *)leftPos
-        leftAtt:(int *)leftAtt
-       leftAcc:(int *)leftAcc
-       leftZupt:(int)leftZupt
-     left_press:(int)left_press
-           jump:(int)jump
-           down:(int)down
-           rssi:(int)rssi{
-    danceGame->Process(rightPos, rightAtt,rightAcc, rightZupt, right_press,leftPos, leftAtt,leftAtt, leftZupt, left_press,jump, down, rssi);
-}
-
-- (void)getResult:(int *)matrix{
-    danceGame->getResult(matrix);
-}
-//- (float)getRssiDistance:(int)rssi{
-//    return danceGame->getRssiDistance(rssi);
-//}
-//- (int)savePosAndRssi:(int *)pos
-//                 zupt:(short)zupt
-//                 rssi:(int)rssi
-//          hostOrSlave:(short)hostOrSlave{
-//    return danceGame->savePosAndRssi(pos, zupt, rssi, hostOrSlave);
-//}
-/// 向外提供,手动释放
-- (void)handRelease{
-    delete danceGame;
-}
-- (void)dealloc{
-    delete danceGame;
-}
-@end
-
-@interface FootStepObjc ()
-{
-@private
-    FootStep *footStep;
-}
-@end
-
-@implementation FootStepObjc
-
-- (instancetype)init{
-    self = [super init];
-    if (self) {
-        footStep = new FootStep();
-    }
-    return self;
-}
-//pos开辟3个空间
-- (void)stepCal:(int)timeStamp posList:(int *)pos zupt:(int)zupt{
-    footStep->stepCal(timeStamp, pos, zupt);
-}
-- (int)getStepFreq{
-    return footStep->getStepFreq();
-}
-- (int)getStepStatus{
-    return footStep->getStepStatus();
-}
-- (int)getStepCount{
-    return footStep->getStepCount();
-}
-- (void)dealloc{
-    delete footStep;
-}
-/// 向外提供,手动释放
-- (void)handRelease{
-    delete footStep;
-}
-
-@end
-
-@interface InertialTrajProcessObjc ()
-{
-    @private
-    InertialTrajProcess * inertialTrajProcess;
-}
-@end
-@implementation InertialTrajProcessObjc
-- (instancetype)init{
-    self = [super init];
-    if (self) {
-        inertialTrajProcess = new InertialTrajProcess();
-    }
-    return self;
-}
-- (void)trajRotate:(int *)pos{
-    inertialTrajProcess->TrajRotate(pos);
-}
-//rotateMatrix只能开辟4个空间
-- (void)trajRotate:(int *)pos
-      rotateMatrix:(float *)rotateMatrix{
-    inertialTrajProcess->TrajRotate(pos,rotateMatrix);
-}
-- (void)resetHeading:(short)heading{
-    inertialTrajProcess->ResetHeading(heading);
-}
-/// 向外提供,手动释放
-- (void)handRelease{
-    delete inertialTrajProcess;
-}
-- (void)dealloc{
-    delete inertialTrajProcess;
-}
-@end
-
-
-//@interface OriginTrajObj ()
+//
+//#import "GameObjc.h"
+//#include "Game.h"
+//#include "DanceGame.h"
+//#include "FootStep.h"
+//#include "InertialTrajProcess.h"
+////#include "OriginTraj.h"
+////#include <math.h>
+//
+//#define NSLog(format, ...) printf("TIME:%s FILE:%s(%d行) FUNCTION:%s \n %s\n\n",__TIME__, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
+//
+//
+//@interface GameObjc()
+//{
+//@private
+//    Game *game;
+//    int gametype;
+//}
+//@end
+//
+//@implementation GameObjc
+//
+//- (instancetype)initWithGametype:(int)gametype{
+//    self = [super init];
+//    if (self){
+//        gametype = gametype;
+//        game = new Game(gametype);
+//    }
+//    return self;
+//}
+//
+//- (void)gameProcess:(int)timeStamp
+//           rightPos:(int *)rightPos
+//           rightAtt:(int *)rightAtt
+//           rightAcc:(int *)rightAcc
+//          rightZupt:(int)rightZupt
+//        right_press:(int)right_press
+//            leftPos:(int *)leftPos
+//            leftAtt:(int *)leftAtt
+//           leftAcc:(int *)leftAcc
+//           leftZupt:(int)leftZupt
+//         left_press:(int)left_press
+//               jump:(int)jump
+//               down:(int)down
+//               rssi:(int)rssi
+//         girl_shoes:(int)girl_shoes{
+//    game->GameProcess(timeStamp, rightPos, rightAtt, rightAcc,rightZupt,right_press,leftPos, leftAtt, leftAcc,leftZupt, left_press,jump,down, rssi,girl_shoes);
+//}
+//
+//- (void)runGameProcess:(int)timeStamp
+//              rightPos:(int *)rightPos
+//              rightAtt:(int *)rightAtt
+//              rightAcc:(int *)rightAcc
+//             rightZupt:(int)rightZupt
+//           right_press:(int)right_press
+//               leftPos:(int *)leftPos
+//               leftAtt:(int *)leftAtt
+//              leftAcc:(int *)leftAcc
+//              leftZupt:(int)leftZupt
+//            left_press:(int)left_press
+//                  jump:(int)jump
+//                  down:(int)down
+//            girl_shoes:(int)girl_shoes{
+//    game->RunGameProcess(rightPos, rightAtt, rightAcc,rightZupt,right_press,leftPos, leftAtt, leftAcc,leftZupt, left_press,jump,down,girl_shoes);
+//
+//}
+//
+//- (void)getGameResult:(int *)matrix{
+//    game->getGameResult(matrix);
+//}
+//
+//- (int)getStepFreq:(int)leftOrRight{
+//    return game->getStepFreq(leftOrRight);
+//}
+//- (int)getStepStatus:(int)leftOrRight{
+//    return game->getStepStatus(leftOrRight);
+//}
+//- (int)getStepCount:(int)leftOrRight{
+//    return game->getStepCount(leftOrRight);
+//}
+//
+//- (float)getGamePos:(int)left_or_right index:(int)index{
+//    return game->getGamePos(left_or_right, index);
+//}
+//
+//- (void)start{
+//    game->start(nil);
+//}
+//- (void)end{
+//    game->end();
+//}
+//
+//- (void)isBingo{
+//    game->isBingo();
+//}
+//
+//-(int)getInteractionCMD{
+//    return game->getInteractionCMD();
+//}
+//
+//-(NSString*)getGameDataStr{
+//
+////    NSString * string =  [NSString stringWithCString:game->getGameDataStr().c_str() encoding:[NSString defaultCStringEncoding]];
+//    NSString * aString = [NSString stringWithUTF8String:game->getGameDataStr().c_str()];
+////    NSLog(@"剑波需要的数据1 %@",string);
+////    NSLog(@"剑波需要的数据2 %@",aString);
+//    return aString;
+//
+//}
+//
+//-(void)GameProcessBuf:(uint8_t*)buff length:(int)length{
+//
+//    game->GameProcessBuf(buff, length);
+//
+//}
+//
+///// 向外提供,手动释放
+//- (void)handRelease{
+//    delete game;
+//}
+//- (void)dealloc{
+//    delete game;
+//}
+//
+//@end
+//
+//@interface RunGameObjc ()
 //{
 //    @private
-//    OriginTraj * originTraj;
+//    RunGame * runGame;
 //}
 //@end
-//@implementation OriginTrajObj
+//
+//@implementation RunGameObjc
 //- (instancetype)init{
 //    self = [super init];
-//    if (self){
-//        originTraj = new OriginTraj();
+//    if (self) {
+//        runGame = new RunGame();
+//    }
+//    return self;
+//}
+//- (int)getResultLeftRight:(int *)pos
+//                   devNum:(short)devNum{
+//    return runGame->getResultLeftRight(pos, devNum);
+//}
+//- (int)getResultJump:(short)jump{
+//    return runGame->getResultJump(jump);
+//}
+//- (int)getResultDown:(short)down{
+//    return runGame->getResultDown(down);
+//}
+//- (void)setResultConLeft:(short)zupt{
+//    runGame->setResultConLeft(zupt);
+//}
+//- (void)setResultConRight:(short)zupt{
+//     runGame->setResultConRight(zupt);
+//}
+//- (int)getResultLeft:(int *)pos girl_shoes:(int)girl_shoes{
+//    return runGame->getResultLeft(pos,girl_shoes);
+//}
+//- (int)getResultRight:(int *)pos girl_shoes:(int)girl_shoes{
+//    return runGame->getResultRight(pos,girl_shoes);
+//}
+//
+//- (void)process:(int)timeStamp
+//       rightPos:(int *)rightPos
+//       rightAtt:(int *)rightAtt
+//       rightAcc:(int *)rightAcc
+//      rightZupt:(int)rightZupt
+//    right_press:(int)right_press
+//        leftPos:(int *)leftPos
+//        leftAtt:(int *)leftAtt
+//       leftAcc:(int *)leftAcc
+//       leftZupt:(int)leftZupt
+//     left_press:(int)left_press
+//           jump:(int)jump
+//           down:(int)down
+//     girl_shoes:(int)girl_shoes{
+//
+//    runGame->Process(rightPos, rightAtt, rightAcc,rightZupt,right_press,leftPos, leftAtt, leftAcc,leftZupt, left_press,jump,down,girl_shoes);
+//
+////    Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
+////                 int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
+////                 int jump, int down, int girl_shoes)
+//
+//}
+//
+//- (void)getResult:(int *)dec{
+//    runGame->getResult(dec);
+//}
+//
+///// 向外提供,手动释放
+//- (void)handRelease{
+//    delete runGame;
+//}
+//- (void)dealloc{
+//    delete runGame;
+//}
+//@end
+//
+//@interface DanceGameObjc()
+//{
+//@private
+//    DanceGame *danceGame;
+//}
+//@end
+//
+//@implementation DanceGameObjc
+//- (instancetype)init{
+//    self = [super init];
+//    if (self) {
+//        danceGame = new DanceGame();
 //    }
 //    return self;
 //}
 //
-//- (void)process:(int*)right_pos
-//        right_att:(int*)right_att
-//        right_zupt:(int)right_zupt
-//        left_pos:(int*)left_pos
-//        left_att:(int*)left_att
-//      left_zupt:(int) left_zupt{
-//    originTraj->Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt);
+////- (int)gamePositionProcess:(int *)pos
+////                   stepPos:(int *)stepPos
+////                      rssi:(int)rssi
+////               hostOrSlave:(short)hostOrSlave{
+////    //SInt16 ==> short*
+////    return  danceGame->game_position_process(pos, stepPos, rssi, hostOrSlave);
+////}
+//
+////- (void)gameBoundary:(int *)globalPos{
+////    danceGame->game_boundary(globalPos);
+////}
+////- (int)getDirectionFloat:(float *)pos
+////                    rssi:(int)rssi{
+////    //float==>32位
+////    return  danceGame->getDirectionFloat(pos,rssi);
+////}
+////- (short)danceGameProcess:(int *)pos
+////                     zupt:(short)zupt
+////                     rssi:(int)rssi
+////              hostOrSlave:(short)hostOrSlave{
+////    return danceGame->dance_game_process(pos, zupt, rssi, hostOrSlave);
+////}
+//
+//- (void)process:(int *)rightPos
+//       rightAtt:(int *)rightAtt
+//       rightAcc:(int *)rightAcc
+//      rightZupt:(int)rightZupt
+//    right_press:(int)right_press
+//        leftPos:(int *)leftPos
+//        leftAtt:(int *)leftAtt
+//       leftAcc:(int *)leftAcc
+//       leftZupt:(int)leftZupt
+//     left_press:(int)left_press
+//           jump:(int)jump
+//           down:(int)down
+//           rssi:(int)rssi{
+//    danceGame->Process(rightPos, rightAtt,rightAcc, rightZupt, right_press,leftPos, leftAtt,leftAtt, leftZupt, left_press,jump, down, rssi);
+//}
+//
+//- (void)getResult:(int *)matrix{
+//    danceGame->getResult(matrix);
+//}
+////- (float)getRssiDistance:(int)rssi{
+////    return danceGame->getRssiDistance(rssi);
+////}
+////- (int)savePosAndRssi:(int *)pos
+////                 zupt:(short)zupt
+////                 rssi:(int)rssi
+////          hostOrSlave:(short)hostOrSlave{
+////    return danceGame->savePosAndRssi(pos, zupt, rssi, hostOrSlave);
+////}
+///// 向外提供,手动释放
+//- (void)handRelease{
+//    delete danceGame;
+//}
+//- (void)dealloc{
+//    delete danceGame;
+//}
+//@end
+//
+//@interface FootStepObjc ()
+//{
+//@private
+//    FootStep *footStep;
 //}
+//@end
 //
-//- (float)getGamePos:(int)left_or_right
-//              index:(int)index{
-//    return originTraj->getGamePos(left_or_right, index);
+//@implementation FootStepObjc
+//
+//- (instancetype)init{
+//    self = [super init];
+//    if (self) {
+//        footStep = new FootStep();
+//    }
+//    return self;
+//}
+////pos开辟3个空间
+////- (void)stepCal:(int)timeStamp posList:(int *)pos zupt:(int)zupt girl_shoes:(int)girl_shoes{
+//    footStep->stepCal(timeStamp, pos, zupt,girl_shoes);
+//}
+//- (int)getStepFreq{
+//    return footStep->getStepFreq();
+//}
+//- (int)getStepStatus{
+//    return footStep->getStepStatus();
+//}
+//- (int)getStepCount{
+//    return footStep->getStepCount();
+//}
+//- (void)dealloc{
+//    delete footStep;
+//}
+///// 向外提供,手动释放
+//- (void)handRelease{
+//    delete footStep;
 //}
 //
+//@end
+//
+//@interface InertialTrajProcessObjc ()
+//{
+//    @private
+//    InertialTrajProcess * inertialTrajProcess;
+//}
+//@end
+//@implementation InertialTrajProcessObjc
+//- (instancetype)init{
+//    self = [super init];
+//    if (self) {
+//        inertialTrajProcess = new InertialTrajProcess();
+//    }
+//    return self;
+//}
+//- (void)trajRotate:(int *)pos{
+//    inertialTrajProcess->TrajRotate(pos);
+//}
+////rotateMatrix只能开辟4个空间
+//- (void)trajRotate:(int *)pos
+//      rotateMatrix:(float *)rotateMatrix{
+//    inertialTrajProcess->TrajRotate(pos,rotateMatrix);
+//}
+//- (void)resetHeading:(short)heading{
+//    inertialTrajProcess->ResetHeading(heading);
+//}
 ///// 向外提供,手动释放
 //- (void)handRelease{
-//    delete originTraj;
+//    delete inertialTrajProcess;
 //}
 //- (void)dealloc{
-//    delete originTraj;
+//    delete inertialTrajProcess;
 //}
 //@end
+//
+//
+////@interface OriginTrajObj ()
+////{
+////    @private
+////    OriginTraj * originTraj;
+////}
+////@end
+////@implementation OriginTrajObj
+////- (instancetype)init{
+////    self = [super init];
+////    if (self){
+////        originTraj = new OriginTraj();
+////    }
+////    return self;
+////}
+////
+////- (void)process:(int*)right_pos
+////        right_att:(int*)right_att
+////        right_zupt:(int)right_zupt
+////        left_pos:(int*)left_pos
+////        left_att:(int*)left_att
+////      left_zupt:(int) left_zupt{
+////    originTraj->Process(right_pos, right_att, right_zupt, left_pos, left_att, left_zupt);
+////}
+////
+////- (float)getGamePos:(int)left_or_right
+////              index:(int)index{
+////    return originTraj->getGamePos(left_or_right, index);
+////}
+////
+/////// 向外提供,手动释放
+////- (void)handRelease{
+////    delete originTraj;
+////}
+////- (void)dealloc{
+////    delete originTraj;
+////}
+////@end

+ 6 - 1
SDK/Tool/MYFactoryManager.h

@@ -26,6 +26,9 @@
 #define RIGHT_FOOT_OC 2
 //蓝牙框架封装
 #import "LEONBLManager.h"
+#import "BTDataSend.h"
+#import "CBPeripheral+ADName.h"
+#define BTDataInstance [BTDataProcess sharedInstance]
 #define LEManager [LEONBLManager sharedInstance]
 
 //http
@@ -39,6 +42,8 @@
 #import "AnimationView.h"
 #import "PopupView.h"
 #import "NoDeviceTip.h"
+#import <AudioToolbox/AudioToolbox.h>
+#import "DebugView.h"
 
 /*************************** 获取屏幕 宽度、高度 ***************************/
 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
@@ -65,7 +70,7 @@
 #define IOS_NSUSERDEFAULT [NSUserDefaults standardUserDefaults]
 #define CUS_NOTIFICATIONCENTER [NSNotificationCenter defaultCenter]
 #define IOSSDK_TOKEN [[IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO] objectForKey:@"token"]
-#define IOSSDK_GAMEID [[IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO] objectForKey:@"game_id"]
+#define IOSSDK_GAMEID [[IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO] objectForKey:@"game_type"]
 //#define IOSSDK_GAMEID @"3"
 //#define IOSSDK_TOKEN @"shoes:61652aa99523f9.65681365I94"
 

+ 0 - 1
SDK/Tool/MYFactoryManager.m

@@ -97,7 +97,6 @@ static MYFactoryManager * instance;
     
 }
 
-
 #pragma mark ------  发送app group通知
 + (void)postGroupCFNotificaiton:(NSString*)string{
     

+ 0 - 1
SDK/UI/AnimationVIew/AnimationView.m

@@ -217,7 +217,6 @@
     
 }
 
-
 //初始化小风扇动画
 -(void)addAnimation{
     

+ 1 - 1
SDK/UI/SearchDeviceViewController.m

@@ -116,7 +116,7 @@
     self.connectButton.backgroundColor = [UIColor colorWithRed:255/255.0 green:221/255.0 blue:0/255.0 alpha:1.0];
     self.connectButton.layer.masksToBounds = YES;
     self.connectButton.layer.cornerRadius = SCALEoefficient(20);
-    [self.connectButton setImageEdgeInsets:UIEdgeInsetsMake(0, SCALEoefficient(-15), 15, 0)];
+    [self.connectButton setImageEdgeInsets:UIEdgeInsetsMake(0, SCALEoefficient(-15), 0, 0)];
 //    self.connectButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
     
     NSArray * array = @[@"gamepop_leftarrow_notes",@"gamepop_rihgtarrow_notes",@"gamepop_close_notes",@"gamepop_determine_notes"];

BIN
SDK/resources /.DS_Store


+ 123 - 0
SDK/shoes_sdk/BigFoot.cpp

@@ -0,0 +1,123 @@
+#include "pub.h"
+
+#include "BigFoot.h"
+
+
+BigFoot::BigFoot()
+{
+	memset(result, 0, 4 * sizeof(int));
+
+	memset(left_min_acc, 0, 3 * sizeof(int));
+
+	memset(left_max_acc, 0, 3 * sizeof(int));
+
+	memset(right_min_acc, 0, 3 * sizeof(int));
+
+	memset(right_max_acc, 0, 3 * sizeof(int));
+
+	last_left_zupt = 1;
+
+	last_right_zupt = 1;
+}
+
+int BigFoot::station_acc(int* max_acc, int* min_acc)
+{
+	for (int i = 0; i < 3; i++)
+	{
+		if (max_acc[i] - min_acc[i] > 1024)
+		{
+			return 0;
+		}
+	}
+
+
+	return 1;
+}
+
+void BigFoot::getResult(int* matrix)
+{
+	memcpy(matrix, result, 4 * sizeof(int));
+}
+
+void BigFoot::Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
+	int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
+	int jump, int down, int girl_shoes)
+{
+
+
+	//需要用加速度过滤伪触地,如果期间是小于0.5g的则视为伪触地,过滤掉
+	//station_acc 判断方法
+
+	if (left_zupt && last_left_zupt == 0 && !station_acc(left_max_acc, left_min_acc))
+	//if (left_zupt && last_left_zupt == 0 )
+	{
+		result[0] = 1;
+		std::cout << "左脚踩了" << std::endl;
+	}
+	else
+	{
+		result[0] = 0;
+	}
+
+	if (right_zupt && last_right_zupt == 0 && !station_acc(right_max_acc, right_min_acc))
+	{
+		result[1] = 1;
+		std::cout << "右脚踩了" << std::endl;
+	}
+	else
+	{
+		result[1] = 0;
+	}
+	
+
+	last_left_zupt = left_zupt;
+
+	last_right_zupt = right_zupt;
+
+
+	if (left_zupt)
+	{
+		memcpy(left_min_acc, left_acc, 3 * sizeof(int));
+
+		memcpy(left_max_acc, left_acc, 3 * sizeof(int));
+	}
+	else
+	{
+		for (int i = 0; i < 3; i++)
+		{
+			if (left_min_acc[i] > left_acc[i])
+			{
+				left_min_acc[i] = left_acc[i];
+			}
+
+			if (left_max_acc[i] < left_acc[i])
+			{
+				left_max_acc[i] = left_acc[i];
+			}
+		}
+	}
+
+	if (right_zupt)
+	{
+		memcpy(right_min_acc, right_acc, 3 * sizeof(int));
+
+		memcpy(right_max_acc, right_acc, 3 * sizeof(int));
+	}
+	else
+	{
+		for (int i = 0; i < 3; i++)
+		{
+			if (right_min_acc[i] > right_acc[i])
+			{
+				right_min_acc[i] = right_acc[i];
+			}
+
+			if (right_max_acc[i] < right_acc[i])
+			{
+				right_max_acc[i] = right_acc[i];
+			}
+		}
+	}
+
+
+}

+ 39 - 0
SDK/shoes_sdk/BigFoot.h

@@ -0,0 +1,39 @@
+#pragma once
+#ifndef _BigFoot_H_
+#define _BigFoot_H_
+
+class BigFoot {
+public:
+
+	BigFoot();
+
+	void Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
+		int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
+		int jump, int down, int girl_shoes);
+
+
+	void getResult(int* dec);
+
+	int station_acc(int* max_acc, int* min_acc);
+
+
+private:
+
+	int result[4];
+
+	int left_min_acc[3];
+
+	int left_max_acc[3];
+	
+	int right_min_acc[3];
+
+	int right_max_acc[3];
+
+	int last_left_zupt;
+
+	int last_right_zupt;
+
+};
+
+
+#endif

+ 6 - 1
SDK/shoes_sdk/FootStep.cpp

@@ -28,7 +28,7 @@ FootStep::FootStep()
 	memset(last_pos, 0, 3 * sizeof(int));
 }
 
-void FootStep::stepCal(int timeStamp, int pos[3], int zupt)
+void FootStep::stepCal(int timeStamp, int pos[3], int zupt, int girl_shoes)
 {
 	//¼ÆËãÀۼƵÄʱ¼ä
 	static int stepFreqBuff[5];
@@ -77,7 +77,12 @@ void FootStep::stepCal(int timeStamp, int pos[3], int zupt)
 
 		stepFreq = 60 * 1000 / walkTime;
 
+		if (girl_shoes)
+		{
+			stepFreq *= 2;
+		}
 		
+
 		leaveFloorTime1 = localTime;
 		
 		stepTag = 0;

+ 4 - 1
SDK/shoes_sdk/FootStep.h

@@ -10,7 +10,10 @@ public:
 
 	FootStep();
 
-	void stepCal(int timeStamp, int pos[3], int zupt);
+	//void stepCal(int timeStamp, int pos[3], int zupt);
+
+	void stepCal(int timeStamp, int pos[3], int zupt, int girl_shoes);
+
 	int getStepFreq();
 	int getStepStatus();
 

+ 118 - 9
SDK/shoes_sdk/Game.cpp

@@ -21,6 +21,15 @@ Game::Game(int gametype)
 	leftRate = 0;
 	rightRate = 0;
 
+	last_down = 0;
+	last_jump = 0;
+
+	down_count = 0;
+	jump_count = 0;
+
+	down_wait = 0;
+	avoid_down_between_jump = 0;
+
 	interaction = Interaction();
 
 	InteractionCMD = -1;
@@ -57,6 +66,11 @@ Game::Game(int gametype)
 	{
 		tricycle = Tricycle();
 	}
+
+	else if (GameType == BIGFOOT)
+	{
+		bigfoot = BigFoot();
+	}
 	
 
 }
@@ -66,14 +80,85 @@ int Game::getInteractionCMD()
 	return InteractionCMD;
 }
 
+void Game::processCalorieData(int down, int jump)
+{
+
+	if (down)
+	{
+		down_wait = 20;
+	}
+
+	if (jump)
+	{
+		avoid_down_between_jump = 20;
+	}
+
+	if (avoid_down_between_jump > 0 && h_zupt == 0 && s_zupt == 0)
+	{
+		avoid_down_between_jump = 20;
+	}
+
+	if (avoid_down_between_jump > 0 && down == 1)
+	{
+		avoid_down_between_jump = 20;
+	}
+
+	if (avoid_down_between_jump > 0)
+	{
+		down_wait = 0;
+		down = 0;
+		last_down = 0;
+	}
+
+	if (down_wait > 0)
+	{
+		down = 1;
+
+		down_wait --;
+	}
+
+	if (avoid_down_between_jump)
+	{
+		avoid_down_between_jump--;
+	}
+	
+	if (down == 0 && last_down == 1)
+	{
+		down_count++;
+
+		std::cout << "蹲的次数 : " << down_count << endl;
+	}
+
+	if (last_jump == 0 && jump == 1)
+	{
+		jump_count++;
+		std::cout << "跳的次数 : " << jump_count << endl;
+
+	}
+
+	last_down = down;
+	last_jump = jump;
+}
+
+
+int Game::getGameDownCount()
+{
+	return down_count;
+}
+
+int Game::getGameJumpCount()
+{
+	return jump_count;
+}
+
 void Game::GameProcess(int timeStamp, int* right_pos, int* right_att, int *right_acc, int right_zupt, int right_press,
 	int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press, 
 	int jump, int down, int rssi, int girl_shoes)
 {
 
-	leftFootStep.stepCal(timeStamp, left_pos, left_zupt);
+	leftFootStep.stepCal(timeStamp, left_pos, left_zupt, girl_shoes);
 
-	rightFootStep.stepCal(timeStamp, right_pos, right_zupt);
+	rightFootStep.stepCal(timeStamp, right_pos, right_zupt, girl_shoes);
 	
 	
 	interaction.Process(gameTime, right_pos, right_att, right_acc, right_zupt, right_press,
@@ -81,6 +166,8 @@ void Game::GameProcess(int timeStamp, int* right_pos, int* right_att, int *right
 		jump, down, rssi);
 
 	InteractionCMD = interaction.get_motion_state();
+
+	processCalorieData(down, jump);
 	
 	
 	if (GameType == RUNGAME)
@@ -178,6 +265,16 @@ void Game::GameProcess(int timeStamp, int* right_pos, int* right_att, int *right
 		tricycle.getResult(resultMatrix);
 
 	}
+
+	else if (GameType == BIGFOOT)
+	{
+
+		bigfoot.Process(right_pos, right_att, right_acc, right_zupt, right_press,
+			left_pos, left_att, left_acc, left_zupt, left_press, jump, down, girl_shoes);
+
+		//跑酷游戏处理结果获取
+		bigfoot.getResult(resultMatrix);
+	}
 	
 	/*
 	if (foot_data_file.is_open()&& GameType == DANCEGAME)
@@ -289,8 +386,9 @@ string Game::getGameDataStr()
 
 	data_str += (to_string(left_front_mag) + "," + to_string(left_back_mag) + "," + to_string(h_zupt) + ",");
 
+	data_str += (to_string(down) + "," + to_string(jump) + "," + to_string(rssi) + "," + to_string(posTimeStamp) + ",");
 
-	data_str += (to_string(down) + "," + to_string(jump) + "," + to_string(rssi) + "," + to_string(posTimeStamp));
+	data_str += (to_string(right_step) + "," + to_string(left_step));
 
 	return data_str;
 
@@ -337,6 +435,7 @@ void Game::GameProcessBuf(uint8_t* buf, int len) {
 
 	jump = (buf[48] & 0x01) >> 0;
 
+
 	rssi = (int)buf[49];
 
 	posTimeStamp = buf[50];
@@ -350,23 +449,33 @@ void Game::GameProcessBuf(uint8_t* buf, int len) {
 
 	lastTimeStamp = posTimeStamp;
 
-	std::cout << "gameTime : " << gameTime << std::endl;
+	//std::cout << "gameTime : " << gameTime << std::endl;
 	
 	if (gameTime - last_game_time > 1)
 	{
-		std::cout << "loss package : " << gameTime - last_game_time -1 << std::endl;
+		//std::cout << "loss package : " << gameTime - last_game_time -1 << std::endl;
 		last_game_time = gameTime;
 	}
-	
+
 	last_game_time++;
 
 	right_front_mag = uint16_t(buf[51] << 8 | buf[52] << 0);
 	right_back_mag = uint16_t(buf[53] << 8 | buf[54] << 0);
 
-	left_front_mag = uint16_t(buf[51] << 8 | buf[52] << 0);
-	left_back_mag = uint16_t(buf[53] << 8 | buf[54] << 0);
+	left_front_mag = uint16_t(buf[55] << 8 | buf[56] << 0);
+	left_back_mag = uint16_t(buf[57] << 8 | buf[58] << 0);
+
+	if (len > 59)
+	{
+		right_step = uint32_t(buf[59] << 24 | buf[60] << 16 | buf[61] << 8 | buf[62] << 0);
+		left_step = uint32_t(buf[63] << 24 | buf[64] << 16 | buf[65] << 8 | buf[66] << 0);
+	}
+	else
+	{
+		right_step = 0;
+		left_step = 0;
+	}
 
-	
 	GameProcess(gameTime,
 		right_pos_data, right_att_data, right_acc_data, s_zupt, (int)right_front_mag,
 		left_pos_data, left_att_data, left_acc_data, h_zupt, (int)left_front_mag,

+ 23 - 0
SDK/shoes_sdk/Game.h

@@ -4,6 +4,7 @@
 
 #include "pub.h"
 #include "RunGame.h"
+
 #include "InertialTrajProcess.h"
 #include "DanceGame.h"
 
@@ -19,6 +20,8 @@
 
 #include "Tricycle.h"
 
+#include "BigFoot.h"
+
 #include <fstream>
 #include <time.h>
 #include <sstream>
@@ -37,6 +40,7 @@ class Game
 			void RunGameProcess(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
 				int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
 				int jump, int down, int girl_shoes);
+
 			void getGameResult(int* matrix);
 
 			string getGameDataStr();
@@ -55,6 +59,12 @@ class Game
 
 			int getInteractionCMD();
 
+			void processCalorieData(int down, int jump);
+
+			int getGameDownCount();
+
+			int getGameJumpCount();
+
 		private:
 
 			int GameType;
@@ -79,6 +89,7 @@ class Game
 
 			Tricycle tricycle;
 
+			BigFoot bigfoot;
 
 			int leftStepRate;
 			int rightStepRate;
@@ -131,6 +142,18 @@ class Game
 			uint16_t left_front_mag;
 			uint16_t left_back_mag;
 
+			uint32_t right_step;
+			uint32_t left_step;
+
+			int down_count;
+			int jump_count;
+			
+			int last_down;
+			int last_jump;
+
+			int down_wait;
+			int avoid_down_between_jump;
+
 };
 
 #endif

+ 0 - 2
SDK/shoes_sdk/InertialTrajProcess.cpp

@@ -2,7 +2,6 @@
 #include "InertialTrajProcess.h"
 #include <math.h>
 
-
 void InertialTrajProcess::TrajRotate(int *pos, float rotateMatrix[4])
 {
 	/*
@@ -43,7 +42,6 @@ void InertialTrajProcess::TrajRotate(int* pos)
 
 	posTemp[0] = cos(curheading) * float(pos_f[0]) + sin(curheading) * float(pos_f[1]);
 	posTemp[1] = -sin(curheading) * float(pos_f[0]) + cos(curheading) * float(pos_f[1]);
-
 	
 	pos[0] = (int)(posTemp[0] * 100.0f);
 	pos[1] = (int)(posTemp[1] * 100.0f);

+ 3 - 5
SDK/shoes_sdk/RunGame.cpp

@@ -28,18 +28,16 @@ void RunGame::Process(int* right_pos, int* right_att, int* right_acc, int right_
 	for (int i = 0; i < 3; i++)
 	{
 		left_pos_tmp[i] = left_pos[i] - left_last_pos[i];
+
 		right_pos_tmp[i] = right_pos[i] - right_last_pos[i];
 	}
-	/*
+
+	
 	if (left_zupt == 0)
 	{
 		std::cout << "rungame leftpos: " << left_pos_tmp[0] << " " << left_pos_tmp[1] << " " << left_pos_tmp[2] << std::endl;
 	}
 	
-	if (right_zupt == 0)
-	{
-		std::cout << "rungame rightpos:  " << right_pos_tmp[0] << " " << right_pos_tmp[1] << " " << right_pos_tmp[2] << std::endl;
-	}*/
 
 
 

+ 2 - 1
SDK/shoes_sdk/pub.h

@@ -24,6 +24,7 @@ using namespace std;
 #define MONSTER 4
 #define RUINS 5
 #define CYCLE 6
+#define BIGFOOT 7
 
 #define RSSI_LIMIT
 
@@ -33,7 +34,7 @@ using namespace std;
 
 #define PRESS_MIN 41000
 
-#define GAME_VERSION "0.3.24"
+#define GAME_VERSION "0.3.30"
 
 enum CMD_MOTION
 {

Деякі файли не було показано, через те що забагато файлів було змінено