BTDataAnalysis.mm 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // BTDataAnalysis.m
  3. // Unity-iPhone
  4. //
  5. // Created by duowan123 on 2022/1/26.
  6. //
  7. #import "BTDataAnalysis.h"
  8. #import "IOSPlatformSDK.h"
  9. @implementation BTDataAnalysis
  10. #pragma mark ===============================================>> 校验 & 报文数据解析
  11. -(void)analysisCharacteristic:(NSData*)characteristic peripheral:(CBPeripheral*)peripheral{
  12. //// NSLog(@"接收到的数据data = %@",characteristic);
  13. // int frameHead = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(0, 1)]];//帧头数据aa
  14. // int messageLength = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(1, 1)]];//报文长度
  15. // int messageLengthNegation = ~messageLength;//报文长度取反
  16. // int dataType = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(3, 1)]];//cmd类型
  17. //
  18. // if (dataType == 4){//获取主动推过来的数据
  19. // //右脚坐标数据
  20. // int right_X = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(4, 4)];
  21. // int right_Y = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(8, 4)];
  22. // int right_Z = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(12, 4)];
  23. // int right_pos[3] = {right_X,right_Y,right_Z};
  24. // //左脚坐标数据
  25. // int left_X = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(16, 4)];
  26. // int left_Y = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(20, 4)];
  27. // int left_Z = [AlgorithmTool dataToSwapBigIntToHost:characteristic andRange:NSMakeRange(24, 4)];
  28. // int left_pos[3] = {left_X,left_Y,left_Z};
  29. // //右脚姿势数据
  30. // short righrPosture_X = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(28, 2)];
  31. // short righrPosture_Y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(30, 2)];
  32. // short righrPosture_Z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(32, 2)];
  33. // int right_att[3] = {righrPosture_X,righrPosture_Y,righrPosture_Z};
  34. // //左脚姿势数据
  35. // short leftPosture_X = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(34, 2)];
  36. // short leftPosture_Y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(36, 2)];
  37. // short leftPosture_Z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(38, 2)];
  38. // int left_att[3] = {leftPosture_X,leftPosture_Y,leftPosture_Z};
  39. // //右脚三维数据
  40. // short righrAcc_x = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(40, 2)];
  41. // short righrAcc_Y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(42, 2)];
  42. // short righrAcc_z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(44, 2)];
  43. // int righr_acc[3] = {righrAcc_x,righrAcc_Y,righrAcc_z};
  44. // //左脚三维数据
  45. // short leftAcc_x = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(46, 2)];
  46. // short leftAcc_y = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(48, 2)];
  47. // short leftAcc_z = [AlgorithmTool dataToSwapBigShortToHost:characteristic andRange:NSMakeRange(50, 2)];
  48. // int left_acc[3] = {leftAcc_x,leftAcc_y,leftAcc_z};
  49. // //左脚、右脚、蹲 、跳四个动作信息数据
  50. // int actionInformation = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(52, 1)]];;//0c 16进制字符串
  51. // int girlShoes = actionInformation & 16;
  52. // if (girlShoes!=0){
  53. // girlShoes=1;
  54. // }else{
  55. // girlShoes=0;
  56. // }
  57. // int rightZupt = actionInformation & 8;
  58. // if (rightZupt!=0){
  59. // rightZupt=1;
  60. // }else{
  61. // rightZupt=0;
  62. // }
  63. // int leftZupt = actionInformation & 4;
  64. // if (leftZupt!=0){
  65. // leftZupt=1;
  66. // }else{
  67. // leftZupt=0;
  68. // }
  69. // int down = actionInformation & 2;
  70. // if (down!=0){
  71. // down=1;
  72. // }else{
  73. // down=0;
  74. // }
  75. // int jump = actionInformation & 1;
  76. // if (jump!=0){
  77. // jump=1;
  78. // }else{
  79. // jump=0;
  80. // }
  81. //
  82. // int rssi = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(53, 1)]];//rssi 信号强度
  83. // int ts = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(54, 1)]];;//ts 时间戳
  84. // int right_press = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(55, 2)]];//3 29新增 右鞋压力
  85. // int left_press = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(57, 2)]];//3 29新增 左鞋压力
  86. // int frameCheck = [AlgorithmTool dataToChar:[characteristic subdataWithRange:NSMakeRange(59, 1)]];//校验位
  87. //
  88. // if (deviceType==DEVICETYPE_MAIN){//主设备
  89. // // NSLog(@"主设备 接收到 鞋子动作数据 data = %@",characteristic);
  90. // //调取鞋子SDK
  91. // // [self shoseSDKRight_pos:right_pos Right_att:right_att Right_acc:righr_acc 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];
  92. //
  93. // }else if (deviceType==DEVICETYPE_VICE){//副设备动作数据
  94. // //调取鞋子SDK
  95. // // [self viceShoseSDKRight_pos:right_pos Right_att:right_att Right_acc:righr_acc 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];
  96. // }
  97. //
  98. // }else if (dataType == -95 && characteristic.length == 26){//获取的是查询的数据 char-->int a1 = -95
  99. //A1+1 >> 1: 设备数据(左鞋,右鞋) aa 14 eb a1 01 64 00 1a 0000981d 64 00 17 00000000 f9
  100. // NSLog(@"主设备 读取特征的报文 硬件信息 %ld dataType = -95 %@ %ld",(long)deviceType,characteristic,characteristic.length);
  101. int leftElectricity = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(5, 1)]];
  102. int rightElectricity = [AlgorithmTool dataToInt:[characteristic subdataWithRange:NSMakeRange(15, 1)]];//龙哥新协议
  103. if (peripheral==LEManager.peripheral && LEManager.peripheral!=nil){//主设备
  104. // NSLog(@"主设备 接收到 鞋子硬件数据: %@ 电量 %d %d %@ %@",characteristic,leftElectricity,rightElectricity,LEManager.peripheral.name,LEManager.peripheral.identifier.UUIDString);
  105. //主 设备定时器 60秒调一次 /******************ios call unity*****************/
  106. [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_MAIN
  107. name:LEManager.peripheral.name
  108. address:LEManager.peripheral.identifier.UUIDString
  109. status:CONNECT_ED
  110. electricity:leftElectricity<=rightElectricity?leftElectricity:rightElectricity];
  111. }else if (peripheral==LEManager.vicePeripheral && LEManager.vicePeripheral!=nil){//副设备
  112. // NSLog(@"副设备 接收到 鞋子硬件数据: %@ 电量 %d %d",characteristic,leftElectricity,rightElectricity);
  113. //副 设备定时器 60秒调一次 /******************ios call unity*****************/
  114. [[IOSPlatformSDK sharedInstance] bridgingDeviceAction:DEVICETYPE_VICE
  115. name:LEManager.vicePeripheral.name
  116. address:LEManager.vicePeripheral.identifier.UUIDString
  117. status:CONNECT_ED
  118. electricity:leftElectricity<=rightElectricity?leftElectricity:rightElectricity];
  119. }
  120. // }
  121. }
  122. @end