diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index 3131d03..029cf31 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -285,6 +285,7 @@ 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; }; 847AF36E2B4CF35F00E3456E /* NewSleepModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */; }; + 84DA399D2B4D3A5B008D34A9 /* NewGpsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */; }; B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; }; B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; }; B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; }; @@ -664,6 +665,7 @@ 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSleepModel.swift; sourceTree = ""; }; 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = ""; }; 847D2DE42B3D575F001BA7EF /* 20240110ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20240110ReadMe.md; sourceTree = ""; }; + 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGpsModel.swift; sourceTree = ""; }; B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = ""; }; B212F2012A14CE0900781D59 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchSetting.strings"; sourceTree = ""; }; @@ -1279,6 +1281,7 @@ 847482752B03793C0004F0C2 /* NewWeatherModel.swift */, 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */, 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */, + 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */, ); path = Model; sourceTree = ""; @@ -1747,6 +1750,7 @@ 6CEA284627EB033E006A44AB /* MedalCell.swift in Sources */, 6CEA284A27EB0A82006A44AB /* MedalHeaderView.swift in Sources */, 6CFEEBA62772BED300621863 /* CameraViewController.swift in Sources */, + 84DA399D2B4D3A5B008D34A9 /* NewGpsModel.swift in Sources */, 6C6DF2D3274F386600EF6B8D /* BloodPressureVC.swift in Sources */, 6C6505C72798FB030043DB7A /* LTTableView.swift in Sources */, 6C2EE97B277FFC6B0051413A /* HealthDataCell.swift in Sources */, diff --git a/HDFwear/20240110ReadMe.md b/HDFwear/20240110ReadMe.md index 7a6119f..aa96dae 100644 --- a/HDFwear/20240110ReadMe.md +++ b/HDFwear/20240110ReadMe.md @@ -100,3 +100,8 @@ BluetoothManager+Function 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 6, 1, 140, 110] 接收: [237, 126, 0, 1, 128, 25, 0, 0, 0, 77, 3, 7, 9, 101, 120, 119, 200, 0, 0, 14, 16, 10, 101, 120, 133, 216, 0, 0, 14, 16, 8, 101, 120, 147, 232, 0, 0, 14, 16, 7, 101, 120, 161, 248, 0, 0, 14, 16, 9, 101, 120, 176, 8, 0, 0, 14, 16, 10, 101, 120, 190, 24, 0, 0, 14, 16, 9, 101, 120, 204, 40, 0, 0, 14, 16, 101, 121, 46, 152, 101, 121, 60, 168, 0, 0, 14, 16, 224, 73] 接收: [237, 126, 0, 1, 128, 25, 0, 1, 0, 1, 255, 79, 201] + +gps数据 + func parseGpsData(_ content: [UInt8]) + 接收: [237, 126, 0, 1, 128, 37, 0, 1, 0, 169, 1, 101, 133, 64, 133, 0, 0, 0, 20, 13, 84, 138, 254, 0, 1, 134, 160, 67, 167, 168, 250, 0, 1, 134, 160, 13, 84, 142, 230, 0, 1, 134, 160, 67, 167, 172, 226, 0, 1, 134, 160, 13, 84, 146, 206, 0, 1, 134, 160, 67, 167, 176, 202, 0, 1, 134, 160, 13, 84, 142, 230, 0, 1, 134, 160, 67, 167, 172, 226, 0, 1, 134, 160, 13, 84, 138, 254, 0, 1, 134, 160, 67, 167, 168, 250, 0, 1, 134, 160, 13, 84, 135, 22, 0, 1, 134, 160, 67, 167, 161, 42, 0, 1, 134, 160, 13, 84, 131, 46, 0, 1, 134, 160, 67, 167, 157, 66, 0, 1, 134, 160, 13, 84, 123, 94, 0, 1, 134, 160, 67, 167, 153, 90, 0, 1, 134, 160, 13, 84, 119, 118, 0, 1, 134, 160, 67, 167, 149, 114, 0, 1, 134, 160, 13, 84, 115, 142, 0, 1, 134, 160, 67, 167, 141, 162, 0, 1, 134, 160, 68, 78] + 接收: [237, 126, 0, 1, 128, 37, 0, 1, 0, 1, 255, 107, 166] diff --git a/HDFwear/Home/Model/HealthModel.swift b/HDFwear/Home/Model/HealthModel.swift index e084f16..dd5919a 100644 --- a/HDFwear/Home/Model/HealthModel.swift +++ b/HDFwear/Home/Model/HealthModel.swift @@ -646,7 +646,6 @@ class TemperatureModel: Object { } //MARK: - 压力 -//jtd! class StressModel: Object { @Persisted var value: Int = -1 @Persisted var date: Date? = nil diff --git a/HDFwear/Home/Model/NewGpsModel.swift b/HDFwear/Home/Model/NewGpsModel.swift index 18ef96f..e97f24b 100644 --- a/HDFwear/Home/Model/NewGpsModel.swift +++ b/HDFwear/Home/Model/NewGpsModel.swift @@ -6,3 +6,69 @@ // import Foundation +import UIKit +import HandyJSON +import SwiftDate + +class NewGpsModel: NSObject { + required override init() { } + struct LocationPoint { + var longitudeValue: UInt32 + var longitudeScale: UInt32 + var latitudeValue: UInt32 + var latitudeScale: UInt32 + + var longitude: Double { + return convert(value: longitudeValue, scale: longitudeScale) + } + + var latitude: Double { + return convert(value: latitudeValue, scale: latitudeScale) + } + + private func convert(value: UInt32, scale: UInt32) -> Double { + if scale == 0 { + return 0 + } + let degrees = Double(value) / (Double(scale) * 100) + let minutes = Double(value) / Double(scale) - degrees * 100 + return degrees + (minutes * 1000000 / (60 * Double(scale))) / 1000000.0 + } + } + + var exerciseType: Int = 0 + var startTime: Date? + var locationCount: Int = 0 + var locations: [LocationPoint] = [] + + init(exerciseType: Int, startTime: Date? = nil, locationCount: Int, locations: [LocationPoint]) { + self.exerciseType = exerciseType + self.startTime = startTime + self.locationCount = locationCount + self.locations = locations + } + + class func toGpsModel(_ data: [UInt8]) -> NewGpsModel { + let gpsModel = NewGpsModel() + guard data.count >= 9 else { + return gpsModel // 数据长度不够 + } + gpsModel.exerciseType = Int(data[0]) + let combinedUInt32 = data[1..<5].reduce(0) { ($0 << 8) + UInt32($1) } + gpsModel.startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32)) + gpsModel.locationCount = Int(data[5..<9].reduce(0) { ($0 << 8) + UInt32($1) }) + var arr = [LocationPoint]() + // 将数组分成16个一组 + for index in stride(from: 9, to: data.count, by: 16) { + let longitudeValue = data[index + 0.. ())? = nil) { - newGetData(type: .gps, option: option, completion: completion) + func newGetGpsData(option: SyncOption = .now, closure: GpsClosure? = nil) { + let data = BleMessage.shared.getSyncCmd(.gps, option) + newStartSyncHealthData(closure: closure, data: data, synType: .gps) } //MARK: - old code @@ -327,6 +327,12 @@ extension BluetoothManager { mettClosure?([], -1002) mettClosure = nil } + case is GpsClosure: + if gpsClosure == nil { + gpsClosure = closure as? GpsClosure + gpsClosure?(nil, -1002) + gpsClosure = nil + } default: break } @@ -505,14 +511,14 @@ extension BluetoothManager { delegate.didReceiveCameraCommand(status: stauts) } case 0x8025://手表户外运动定位轨迹 - print("运动轨迹") + print("gps轨迹") let content = parseContentFromBytes(bytes) if (content.count == 1 && content.first == 0xff) { for delegate in syncDelegateList { delegate.didReceiveFinishCommand(0x8025) } }else { - // parseStepData(content) + parseGpsData(content) } default: break @@ -688,15 +694,13 @@ extension BluetoothManager { } // GPS数据 - func parseGPSData (_ content: [UInt8]) { - //jtd! parse gps data -// guard content.count > 0 else { -// print("无有效的信息") -// heartRateClosure?([], nil) -// return -// } -// let hrArray = HeartRateModel.toHeartRateArray(content) -// HeartRateModel.addArray(hrArray)// 加入数据库 -// heartRateClosure?(hrArray, nil) + func parseGpsData(_ content: [UInt8]) { + guard content.count > 0 else { + print("无有效的信息") + gpsClosure?(nil, nil) + return + } + let gpsModel = NewGpsModel.toGpsModel(content) + gpsClosure?(gpsModel, nil) } } diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index ac22b7f..d739dc7 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -93,6 +93,8 @@ class BluetoothManager: NSObject { var pressureClosure: PressureClosure? typealias MettClosure = (_ mettArray: [MettModel], _ error: Int?) -> Void var mettClosure: MettClosure? + typealias GpsClosure = (_ gps: NewGpsModel?, _ error: Int?) -> Void + var gpsClosure: GpsClosure? typealias DialProgressClosure = (_ progress: Int) -> Void var dialProgressClosure: DialProgressClosure? @@ -1306,6 +1308,8 @@ class BluetoothManager: NSObject { pressureClosure = closure as? PressureClosure case is MettClosure: mettClosure = closure as? MettClosure + case is GpsClosure: + gpsClosure = closure as? GpsClosure default: break }