diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index a5f98ed..48399a1 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -281,6 +281,7 @@ 6CFEEBC22773354500621863 /* HRReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC12773354500621863 /* HRReferenceVC.swift */; }; 6CFEEBC42773355700621863 /* SleepReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */; }; 844959782B48EF900029E2E0 /* BluetoothManager+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844959772B48EF900029E2E0 /* BluetoothManager+Deprecated.swift */; }; + 845ADEA12B551C8E00C3AD73 /* NewStepModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845ADEA02B551C8E00C3AD73 /* NewStepModel.swift */; }; 8473FB622B4BF1A200409148 /* TaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8473FB612B4BF1A200409148 /* TaskManager.swift */; }; 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; }; @@ -660,6 +661,7 @@ 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepReferenceVC.swift; sourceTree = ""; }; 844959772B48EF900029E2E0 /* BluetoothManager+Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BluetoothManager+Deprecated.swift"; sourceTree = ""; }; 845ADE9F2B5507FA00C3AD73 /* 20240126ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20240126ReadMe.md; sourceTree = ""; }; + 845ADEA02B551C8E00C3AD73 /* NewStepModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewStepModel.swift; sourceTree = ""; }; 8473FB612B4BF1A200409148 /* TaskManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskManager.swift; sourceTree = ""; }; 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = ""; }; 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewBeiDouContactModel.swift; sourceTree = ""; }; @@ -1284,6 +1286,7 @@ 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */, 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */, 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */, + 845ADEA02B551C8E00C3AD73 /* NewStepModel.swift */, ); path = Model; sourceTree = ""; @@ -1569,6 +1572,7 @@ 6C2081F0277F00A600F6D4B9 /* HomePageSortVC.swift in Sources */, 6C5A978B27CC711A00221361 /* MettViewController.swift in Sources */, 6C5A978927CC710B00221361 /* PressureViewController.swift in Sources */, + 845ADEA12B551C8E00C3AD73 /* NewStepModel.swift in Sources */, 6C5CD63627785971003747E1 /* WeChatSportVC.swift in Sources */, 6CA4F8EB27DC71F300B8E726 /* DailSyncSubVC.swift in Sources */, 6C41D0BF275F5DAD00747BE4 /* LoaderLineFadeAnimation.swift in Sources */, diff --git a/HDFwear/20240126ReadMe.md b/HDFwear/20240126ReadMe.md index 585df65..957f0e3 100644 --- a/HDFwear/20240126ReadMe.md +++ b/HDFwear/20240126ReadMe.md @@ -38,4 +38,41 @@ BluetoothManager+Function 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 25, 101, 156, 112, 96, 98, 101, 156, 119, 104, 120, 101, 156, 126, 112, 101, 101, 156, 133, 120, 60, 101, 156, 140, 128, 70, 213, 123] 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 25, 101, 156, 112, 96, 98, 101, 156, 119, 104, 120, 101, 156, 126, 112, 101, 101, 156, 133, 120, 60, 101, 156, 140, 128, 70, 213, 123] 接收: [237, 126, 0, 1, 128, 22, 0, 2, 0, 1, 255, 17, 22] + +拉取压力数据 + func getPressureData(option: SyncOption = .now, closure: PressureClosure? = nil) + 当前 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 5, 1, 217, 61] + 接收: [237, 126, 0, 1, 128, 32, 0, 1, 0, 25, 101, 157, 222, 0, 98, 101, 157, 229, 8, 20, 101, 157, 236, 16, 30, 101, 157, 243, 24, 85, 101, 157, 250, 32, 66, 155, 155] + 接收: [237, 126, 0, 1, 128, 32, 0, 1, 0, 1, 255, 40, 167] + 历史 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 5, 2, 233, 94] + 接收: [237, 126, 0, 1, 128, 32, 0, 2, 0, 25, 101, 156, 140, 128, 98, 101, 156, 147, 136, 10, 101, 156, 154, 144, 50, 101, 156, 161, 152, 70, 101, 156, 168, 160, 100, 207, 63] + 接收: [237, 126, 0, 1, 128, 32, 0, 2, 0, 25, 101, 156, 140, 128, 98, 101, 156, 147, 136, 10, 101, 156, 154, 144, 50, 101, 156, 161, 152, 70, 101, 156, 168, 160, 100, 207, 63] + 接收: [237, 126, 0, 1, 128, 32, 0, 2, 0, 25, 101, 157, 222, 0, 98, 101, 157, 229, 8, 20, 101, 157, 236, 16, 30, 101, 157, 243, 24, 85, 101, 157, 250, 32, 66, 246, 39] + 接收: [237, 126, 0, 1, 128, 32, 0, 2, 0, 25, 101, 156, 140, 128, 98, 101, 156, 147, 136, 10, 101, 156, 154, 144, 50, 101, 156, 161, 152, 70, 101, 156, 168, 160, 100, 207, 63] + 接收: [237, 126, 0, 1, 128, 32, 0, 2, 0, 25, 101, 157, 222, 0, 98, 101, 157, 229, 8, 20, 101, 157, 236, 16, 30, 101, 157, 243, 24, 85, 101, 157, 250, 32, 66, 246, 39] + 接收: [237, 126, 0, 1, 128, 32, 0, 2, 0, 1, 255, 179, 123] + +拉取步数卡路里距离数据 + func getStepData(option: SyncOption = .now, closure: StepClosure? = nil) + 当前 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 8, 1, 175, 97] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 156, 28, 0, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 0, 101, 156, 42, 16, 0, 0, 0, 0, 0, 0, 7, 208, 0, 0, 0, 0, 101, 156, 56, 32, 0, 0, 0, 0, 0, 0, 11, 184, 0, 0, 0, 0, 101, 156, 70, 48, 0, 0, 0, 0, 0, 0, 15, 160, 0, 0, 0, 0, 101, 156, 84, 64, 0, 0, 0, 0, 0, 0, 19, 136, 0, 0, 0, 0, 101, 156, 84, 64, 0, 0, 0, 0, 0, 0, 23, 112, 0, 0, 0, 0, 101, 156, 112, 96, 0, 0, 0, 0, 0, 0, 27, 88, 0, 0, 0, 0, 101, 156, 126, 112, 0, 0, 3, 232, 0, 0, 31, 64, 0, 0, 1, 244, 101, 156, 140, 128, 0, 0, 7, 208, 0, 0, 35, 40, 0, 0, 3, 232, 101, 156, 154, 144, 0, 0, 11, 184, 0, 0, 39, 16, 0, 0, 5, 220, 27, 211] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 156, 168, 160, 0, 0, 15, 160, 0, 0, 42, 248, 0, 0, 7, 208, 101, 156, 182, 176, 0, 0, 19, 136, 0, 0, 46, 224, 0, 0, 9, 196, 101, 156, 196, 192, 0, 0, 23, 112, 0, 0, 50, 200, 0, 0, 11, 184, 101, 156, 210, 208, 0, 0, 27, 88, 0, 0, 54, 176, 0, 0, 13, 172, 101, 156, 224, 224, 0, 0, 27, 88, 0, 0, 58, 152, 0, 0, 13, 172, 101, 156, 238, 240, 0, 0, 31, 64, 0, 0, 62, 128, 0, 0, 15, 160, 101, 156, 253, 0, 0, 0, 35, 40, 0, 0, 62, 128, 0, 0, 17, 148, 101, 157, 11, 16, 0, 0, 39, 16, 0, 0, 66, 104, 0, 0, 19, 136, 101, 157, 25, 32, 0, 0, 39, 16, 0, 0, 70, 80, 0, 0, 19, 136, 101, 157, 39, 48, 0, 0, 42, 248, 0, 0, 74, 56, 0, 0, 21, 124, 85, 61] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 64, 101, 157, 53, 64, 0, 0, 46, 224, 0, 0, 78, 32, 0, 0, 23, 112, 101, 157, 67, 80, 0, 0, 46, 224, 0, 0, 82, 8, 0, 0, 23, 112, 101, 157, 81, 96, 0, 0, 46, 224, 0, 0, 85, 240, 0, 0, 23, 112, 101, 157, 95, 112, 0, 0, 46, 224, 0, 0, 89, 216, 0, 0, 23, 112, 37, 209] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 1, 255, 85, 77] + 历史 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 8, 2, 159, 2] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 154, 202, 128, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 0, 101, 154, 216, 144, 0, 0, 0, 0, 0, 0, 7, 208, 0, 0, 0, 0, 101, 154, 230, 160, 0, 0, 0, 0, 0, 0, 11, 184, 0, 0, 0, 0, 101, 154, 244, 176, 0, 0, 0, 0, 0, 0, 15, 160, 0, 0, 0, 0, 101, 155, 2, 192, 0, 0, 0, 0, 0, 0, 19, 136, 0, 0, 0, 0, 101, 155, 2, 192, 0, 0, 0, 0, 0, 0, 23, 112, 0, 0, 0, 0, 101, 155, 30, 224, 0, 0, 0, 0, 0, 0, 27, 88, 0, 0, 0, 0, 101, 155, 44, 240, 0, 0, 3, 232, 0, 0, 31, 64, 0, 0, 1, 244, 101, 155, 59, 0, 0, 0, 7, 208, 0, 0, 35, 40, 0, 0, 3, 232, 101, 155, 73, 16, 0, 0, 11, 184, 0, 0, 39, 16, 0, 0, 5, 220, 234, 162] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 155, 87, 32, 0, 0, 15, 160, 0, 0, 42, 248, 0, 0, 7, 208, 101, 155, 101, 48, 0, 0, 19, 136, 0, 0, 46, 224, 0, 0, 9, 196, 101, 155, 115, 64, 0, 0, 23, 112, 0, 0, 50, 200, 0, 0, 11, 184, 101, 155, 129, 80, 0, 0, 27, 88, 0, 0, 54, 176, 0, 0, 13, 172, 101, 155, 143, 96, 0, 0, 27, 88, 0, 0, 58, 152, 0, 0, 13, 172, 101, 155, 157, 112, 0, 0, 31, 64, 0, 0, 62, 128, 0, 0, 15, 160, 101, 155, 171, 128, 0, 0, 35, 40, 0, 0, 62, 128, 0, 0, 17, 148, 101, 155, 185, 144, 0, 0, 39, 16, 0, 0, 66, 104, 0, 0, 19, 136, 101, 155, 199, 160, 0, 0, 39, 16, 0, 0, 70, 80, 0, 0, 19, 136, 101, 155, 213, 176, 0, 0, 42, 248, 0, 0, 74, 56, 0, 0, 21, 124, 6, 69] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 64, 101, 155, 227, 192, 0, 0, 46, 224, 0, 0, 78, 32, 0, 0, 23, 112, 101, 155, 241, 208, 0, 0, 46, 224, 0, 0, 82, 8, 0, 0, 23, 112, 101, 155, 255, 224, 0, 0, 46, 224, 0, 0, 85, 240, 0, 0, 23, 112, 101, 156, 13, 240, 0, 0, 46, 224, 0, 0, 89, 216, 0, 0, 23, 112, 166, 117] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 154, 202, 128, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 0, 101, 154, 216, 144, 0, 0, 0, 0, 0, 0, 7, 208, 0, 0, 0, 0, 101, 154, 230, 160, 0, 0, 0, 0, 0, 0, 11, 184, 0, 0, 0, 0, 101, 154, 244, 176, 0, 0, 0, 0, 0, 0, 15, 160, 0, 0, 0, 0, 101, 155, 2, 192, 0, 0, 0, 0, 0, 0, 19, 136, 0, 0, 0, 0, 101, 155, 2, 192, 0, 0, 0, 0, 0, 0, 23, 112, 0, 0, 0, 0, 101, 155, 30, 224, 0, 0, 0, 0, 0, 0, 27, 88, 0, 0, 0, 0, 101, 155, 44, 240, 0, 0, 3, 232, 0, 0, 31, 64, 0, 0, 1, 244, 101, 155, 59, 0, 0, 0, 7, 208, 0, 0, 35, 40, 0, 0, 3, 232, 101, 155, 73, 16, 0, 0, 11, 184, 0, 0, 39, 16, 0, 0, 5, 220, 234, 162] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 155, 87, 32, 0, 0, 15, 160, 0, 0, 42, 248, 0, 0, 7, 208, 101, 155, 101, 48, 0, 0, 19, 136, 0, 0, 46, 224, 0, 0, 9, 196, 101, 155, 115, 64, 0, 0, 23, 112, 0, 0, 50, 200, 0, 0, 11, 184, 101, 155, 129, 80, 0, 0, 27, 88, 0, 0, 54, 176, 0, 0, 13, 172, 101, 155, 143, 96, 0, 0, 27, 88, 0, 0, 58, 152, 0, 0, 13, 172, 101, 155, 157, 112, 0, 0, 31, 64, 0, 0, 62, 128, 0, 0, 15, 160, 101, 155, 171, 128, 0, 0, 35, 40, 0, 0, 62, 128, 0, 0, 17, 148, 101, 155, 185, 144, 0, 0, 39, 16, 0, 0, 66, 104, 0, 0, 19, 136, 101, 155, 199, 160, 0, 0, 39, 16, 0, 0, 70, 80, 0, 0, 19, 136, 101, 155, 213, 176, 0, 0, 42, 248, 0, 0, 74, 56, 0, 0, 21, 124, 6, 69] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 64, 101, 155, 227, 192, 0, 0, 46, 224, 0, 0, 78, 32, 0, 0, 23, 112, 101, 155, 241, 208, 0, 0, 46, 224, 0, 0, 82, 8, 0, 0, 23, 112, 101, 155, 255, 224, 0, 0, 46, 224, 0, 0, 85, 240, 0, 0, 23, 112, 101, 156, 13, 240, 0, 0, 46, 224, 0, 0, 89, 216, 0, 0, 23, 112, 166, 117] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 154, 202, 128, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 0, 101, 154, 216, 144, 0, 0, 0, 0, 0, 0, 7, 208, 0, 0, 0, 0, 101, 154, 230, 160, 0, 0, 0, 0, 0, 0, 11, 184, 0, 0, 0, 0, 101, 154, 244, 176, 0, 0, 0, 0, 0, 0, 15, 160, 0, 0, 0, 0, 101, 155, 2, 192, 0, 0, 0, 0, 0, 0, 19, 136, 0, 0, 0, 0, 101, 155, 2, 192, 0, 0, 0, 0, 0, 0, 23, 112, 0, 0, 0, 0, 101, 155, 30, 224, 0, 0, 0, 0, 0, 0, 27, 88, 0, 0, 0, 0, 101, 155, 44, 240, 0, 0, 3, 232, 0, 0, 31, 64, 0, 0, 1, 244, 101, 155, 59, 0, 0, 0, 7, 208, 0, 0, 35, 40, 0, 0, 3, 232, 101, 155, 73, 16, 0, 0, 11, 184, 0, 0, 39, 16, 0, 0, 5, 220, 234, 162] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 160, 101, 155, 87, 32, 0, 0, 15, 160, 0, 0, 42, 248, 0, 0, 7, 208, 101, 155, 101, 48, 0, 0, 19, 136, 0, 0, 46, 224, 0, 0, 9, 196, 101, 155, 115, 64, 0, 0, 23, 112, 0, 0, 50, 200, 0, 0, 11, 184, 101, 155, 129, 80, 0, 0, 27, 88, 0, 0, 54, 176, 0, 0, 13, 172, 101, 155, 143, 96, 0, 0, 27, 88, 0, 0, 58, 152, 0, 0, 13, 172, 101, 155, 157, 112, 0, 0, 31, 64, 0, 0, 62, 128, 0, 0, 15, 160, 101, 155, 171, 128, 0, 0, 35, 40, 0, 0, 62, 128, 0, 0, 17, 148, 101, 155, 185, 144, 0, 0, 39, 16, 0, 0, 66, 104, 0, 0, 19, 136, 101, 155, 199, 160, 0, 0, 39, 16, 0, 0, 70, 80, 0, 0, 19, 136, 101, 155, 213, 176, 0, 0, 42, 248, 0, 0, 74, 56, 0, 0, 21, 124, 6, 69] + 接收: [237, 126, 0, 1, 128, 9, 0, 1, 0, 64, 101, 155, 227, 192, 0, 0, 46, 224, 0, 0, 78, 32, 0, 0, 23, 112, 101, 155, 241, 208, 0, 0, 46, 224, 0, 0, 82, 8, 0, 0, 23, 112, 101, 155, 255, 224, 0, 0, 46, 224, 0, 0, 85, 240, 0, 0, 23, 112, 101, 156, 13, 240, 0, 0, 46, 224, 0, 0, 89, 216, 0, 0, 23, 112, 166, 117] + 接收: [237, 126, 0, 1, 128, 9, 0, 2, 0, 1, 255, 206, 145] + 接受数据类 diff --git a/HDFwear/Home/HomeViewController.swift b/HDFwear/Home/HomeViewController.swift index 2691771..ea11590 100644 --- a/HDFwear/Home/HomeViewController.swift +++ b/HDFwear/Home/HomeViewController.swift @@ -718,12 +718,12 @@ extension HomeViewController: XMLParserDelegate { } print("\(queryArray)---同步步数---\(day)") if queryArray.contains("Step"), let index = queryArray.firstIndex(of: "Step") { - BluetoothManager.shared.getStepHistoryData() {[weak self] stepArray, error in + BluetoothManager.shared.getStepData() {[weak self] stepArray, error in self?.queryArray.remove(at: index) if error == nil { - StepModel.addArray(stepArray) - NotificationCenter.default.post(name: NSNotification.Name("UpdateStepData"), object: nil)//计步页面同步过程中拖动闪退的问题 +// StepModel.addArray(stepArray) +// NotificationCenter.default.post(name: NSNotification.Name("UpdateStepData"), object: nil)//计步页面同步过程中拖动闪退的问题 } self?.syncBloodOxygen(day) } @@ -783,7 +783,7 @@ extension HomeViewController: XMLParserDelegate { func syncPressure(_ day: SyncDay) { print("\(queryArray)---同步压力---\(day)") if queryArray.contains("Pressure"), let index = queryArray.firstIndex(of: "Pressure") { - BluetoothManager.shared.getPressureHistoryData() {[weak self] pressureArray, error in + BluetoothManager.shared.getPressureData() {[weak self] pressureArray, error in self?.queryArray.remove(at: index) if error == nil { PressureModel.addArray(pressureArray) diff --git a/HDFwear/Home/Model/NewStepModel.swift b/HDFwear/Home/Model/NewStepModel.swift new file mode 100644 index 0000000..7c59d84 --- /dev/null +++ b/HDFwear/Home/Model/NewStepModel.swift @@ -0,0 +1,61 @@ +// +// NewStepModel.swift +// HDFwear +// +// Created by admin on 2024/1/15. +// + +import Foundation +import UIKit +import HandyJSON +import SwiftDate + +class NewStepModel: NSObject { + required override init() { } + + var date: Date? = nil + var timeInterval: TimeInterval = 0 + var stepValue: UInt32 = 0 + var calorie: UInt32 = 0 + var distance: UInt32 = 0 + + override var description: String { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + dateFormatter.timeZone = TimeZone.current + + var desc = "NewStepModel\n" + desc += "Date: \(dateFormatter.string(from: date ?? Date()))\n" + desc += "TimeInterval: \(timeInterval)\n" + desc += "Step Value: \(stepValue)\n" + desc += "Calorie: \(calorie)\n" + desc += "Distance: \(distance)\n" + return desc + } + + class func toStepArray(_ bytes: [UInt8]) -> [NewStepModel] { + var sArray: [NewStepModel] = [] + // 将数组分成16个一组 + let groupedArray = stride(from: 0, to: bytes.count, by: 16).map { Array(bytes[$0.. NewStepModel { + let s = NewStepModel() + guard data.count >= 16 else { + return s + } + + let hexValue = data[0..<4].reduce(0) { ($0 << 8) + UInt32($1) } + s.timeInterval = TimeInterval(hexValue) + s.date = Date(timeIntervalSince1970: TimeInterval(hexValue)) + s.stepValue = data[4..<8].reduce(0) { ($0 << 8) + UInt32($1) } + s.calorie = data[8..<12].reduce(0) { ($0 << 8) + UInt32($1) } + s.distance = data[12..<16].reduce(0) { ($0 << 8) + UInt32($1) } + return s; + } +} diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index f66e993..deb29a1 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -506,13 +506,23 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } - let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) {[weak self] action in - BluetoothManager.shared.getStepHistoryData() { sArray, error in + let archiveAction15a = UIAlertAction(title: "getStepData now", style: .default) {[weak self] action in + BluetoothManager.shared.getStepData(option: .now) { sArray, error in if error != nil { - print("getStepHistoryData" + (error?.description ?? "")) + print("getStepData" + (error?.description ?? "")) }else { self?.showDetailAlert(msg: sArray.description) - print("getStepHistoryData success") + print("getStepData success") + } + } + } + let archiveAction15b = UIAlertAction(title: "getStepData history", style: .default) {[weak self] action in + BluetoothManager.shared.getStepData(option: .history) { sArray, error in + if error != nil { + print("getStepData" + (error?.description ?? "")) + }else { + self?.showDetailAlert(msg: sArray.description) + print("getStepData success") } } } @@ -528,13 +538,23 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } - let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) {[weak self] action in - BluetoothManager.shared.getPressureHistoryData() { pArray, error in + let archiveAction17a = UIAlertAction(title: "getPressureData now", style: .default) {[weak self] action in + BluetoothManager.shared.getPressureData(option: .now) { pArray, error in + if error != nil { + print("getPressureData" + (error?.description ?? "")) + }else { + self?.showDetailAlert(msg: pArray.description) + print("getPressureData success") + } + } + } + let archiveAction17b = UIAlertAction(title: "getPressureData history", style: .default) {[weak self] action in + BluetoothManager.shared.getPressureData(option: .history) { pArray, error in if error != nil { - print("getPressureHistoryData" + (error?.description ?? "")) + print("getPressureData" + (error?.description ?? "")) }else { self?.showDetailAlert(msg: pArray.description) - print("getPressureHistoryData success") + print("getPressureData success") } } } @@ -567,9 +587,11 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction10b) alert.addAction(archiveAction14a) alert.addAction(archiveAction14b) - alert.addAction(archiveAction15) + alert.addAction(archiveAction15a) + alert.addAction(archiveAction15b) alert.addAction(archiveAction16) - alert.addAction(archiveAction17) + alert.addAction(archiveAction17a) + alert.addAction(archiveAction17b) alert.addAction(archiveAction22) alert.addAction(archiveAction101) diff --git a/HDFwear/ReadMe.txt b/HDFwear/ReadMe.txt index 3e06593..0962f74 100644 --- a/HDFwear/ReadMe.txt +++ b/HDFwear/ReadMe.txt @@ -39,18 +39,10 @@ BluetoothManager+Function func newSetNotDisturb(remind: RemindModel, weekflag:[WeekFlag], isRepeat:Bool, completion: @escaping(_ error: Int?) -> ()) 发送: [237, 126, 0, 1, 0, 39, 0, 1, 0, 7, 0, 1, 33, 22, 0, 22, 0, 159, 5] -22. 拉取计步数据 - func getStepHistoryData(closure: StepClosure? = nil) - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 3, 160, 143] - 23. 拉取训练数据 func getTrainHistoryData(closure: TrainClosure? = nil) 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 7, 224, 11] -24. 拉取压力数据 - func getPressureHistoryData(closure: PressureClosure? = nil) - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 1, 5, 192, 73] - 接受数据类 1. 通用返回数据 private func parseDefaultResponseData(_ bytes: [UInt8]) @@ -62,9 +54,6 @@ BluetoothManager+Function 5. 体温数据 func parseTemperaturData (_ content: [UInt8]) -7. 计步数据 - func parseStepData (_ content: [UInt8]) - 8. 睡眠数据 func parseSleepData (_ content: [UInt8]) diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index 3f3a2c9..6f7a7b2 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -168,12 +168,12 @@ enum SyncType: UInt8 { case all = 0x00 case heartRate = 0x01 case bloodOxygen = 0x02 - case step = 0x03 +// case step = 0x03 case temperature = 0x04 case pressure = 0x05 case sleep = 0x06 case train = 0x07 -// case 0x08 + case step = 0x08 case battery = 0x09 case gps = 0x0A case other = 0xff diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index 6183cf2..b4abe13 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -257,8 +257,8 @@ extension BluetoothManager { newStartSyncHealthData(closure: closure, data: data, synType: .heartRate) } - // 拉取计步数据 - func getStepHistoryData(option: SyncOption = .now, closure: StepClosure? = nil) { + // 拉取步数数据 + func getStepData(option: SyncOption = .now, closure: StepClosure? = nil) { let data = BleMessage.shared.getSyncCmd(.step, option) newStartSyncHealthData(closure: closure, data: data, synType: .step) } @@ -270,7 +270,7 @@ extension BluetoothManager { } // 拉取压力数据 - func getPressureHistoryData(option: SyncOption = .now, closure: PressureClosure? = nil) { + func getPressureData(option: SyncOption = .now, closure: PressureClosure? = nil) { let data = BleMessage.shared.getSyncCmd(.pressure, option) newStartSyncHealthData(closure: closure, data: data, synType: .pressure) } @@ -429,8 +429,8 @@ extension BluetoothManager { print("设备信息查询应答") let content = parseContentFromBytes(bytes) parseDeviceInfoData(content) - case 0x8009:// 实时步数、卡路里、距离自动上报 - print("实时步数、卡路里、距离自动上报") + case 0x8009:// 步数、卡路里、距离自动上报 + print("步数、卡路里、距离自动上报") let content = parseContentFromBytes(bytes) if (content.count == 1 && content.first == 0xff) { for delegate in syncDelegateList { @@ -498,8 +498,8 @@ extension BluetoothManager { }else { parseSleepData(content) } - case 0x8020:// 历史压力数据上报 - print("历史压力数据上报") + case 0x8020:// 压力数据上报 + print("压力数据上报") let content = parseContentFromBytes(bytes) if (content.count == 1 && content.first == 0xff) { for delegate in syncDelegateList { @@ -508,16 +508,16 @@ extension BluetoothManager { }else { parsePressureData(content) } - case 0x8021:// 分时段计步数据上报 - print("分时段计步数据上报") - let content = parseContentFromBytes(bytes) - if (content.count == 1 && content.first == 0xff) { - for delegate in syncDelegateList { - delegate.didReceiveFinishCommand(0x8021) - } - }else { - parseStepData(content) - } +// case 0x8021:// 分时段计步数据上报 +// print("分时段计步数据上报") +// let content = parseContentFromBytes(bytes) +// if (content.count == 1 && content.first == 0xff) { +// for delegate in syncDelegateList { +// delegate.didReceiveFinishCommand(0x8021) +// } +// }else { +// parseStepData(content) +// } case 0x8022:// 遥控拍照 print("遥控拍照") let stauts = bytes[10] @@ -670,6 +670,7 @@ extension BluetoothManager { } // 计步数据 + // not used now func parseStepData (_ content: [UInt8]) { guard content.count > 0 else { print("无有效的信息") @@ -678,7 +679,7 @@ extension BluetoothManager { } let array = StepModel.toStepArray(content) StepModel.addArray(array)// 加入数据库 - stepClosure?(array, nil) +// stepClosure?(array, nil) } // 睡眠数据 @@ -692,19 +693,19 @@ extension BluetoothManager { sleepClosure?(model, nil) } - // 实时步数,卡路里,距离数据 + // 步数,卡路里,距离数据 func parseStepCalorieDistanceData (_ content: [UInt8]) { - guard content.count == 16 else { + guard content.count >= 16 else { print("无有效的信息") stepClosure?([], nil) return } - let step = StepModel.toStepModel(content) - step.realTimeAdd()// 加入数据库 + let steps = NewStepModel.toStepArray(content) +// step.realTimeAdd()// 加入数据库 for delegate in syncDelegateList { delegate.didReceiveStep() } - stepClosure?([step], nil) + stepClosure?(steps, nil) } // GPS数据 diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index 1ca6c86..65bc7e5 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -85,7 +85,7 @@ class BluetoothManager: NSObject { var bloodOxygenClosure: BloodOxygenClosure? typealias SleepClosure = (_ sleepModel: NewSleepModel?, _ error: Int?) -> Void var sleepClosure: SleepClosure? - typealias StepClosure = (_ stepArray: [StepModel], _ error: Int?) -> Void + typealias StepClosure = (_ stepArray: [NewStepModel], _ error: Int?) -> Void var stepClosure: StepClosure? typealias TrainClosure = (_ trainArray: TrainModel?, _ error: Int?) -> Void var trainClosure: TrainClosure?