Commit 1e5d42689d4a70fba997e2efb4a028a6ddceb311

Authored by jason
1 parent 7ccb8cd1

feat:gps

HDFwear.xcodeproj/project.pbxproj
... ... @@ -285,6 +285,7 @@
285 285 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; };
286 286 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; };
287 287 847AF36E2B4CF35F00E3456E /* NewSleepModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */; };
  288 + 84DA399D2B4D3A5B008D34A9 /* NewGpsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */; };
288 289 B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; };
289 290 B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; };
290 291 B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; };
... ... @@ -664,6 +665,7 @@
664 665 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSleepModel.swift; sourceTree = "<group>"; };
665 666 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = "<group>"; };
666 667 847D2DE42B3D575F001BA7EF /* 20240110ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20240110ReadMe.md; sourceTree = "<group>"; };
  668 + 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGpsModel.swift; sourceTree = "<group>"; };
667 669 B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; };
668 670 B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = "<group>"; };
669 671 B212F2012A14CE0900781D59 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchSetting.strings"; sourceTree = "<group>"; };
... ... @@ -1279,6 +1281,7 @@
1279 1281 847482752B03793C0004F0C2 /* NewWeatherModel.swift */,
1280 1282 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */,
1281 1283 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */,
  1284 + 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */,
1282 1285 );
1283 1286 path = Model;
1284 1287 sourceTree = "<group>";
... ... @@ -1747,6 +1750,7 @@
1747 1750 6CEA284627EB033E006A44AB /* MedalCell.swift in Sources */,
1748 1751 6CEA284A27EB0A82006A44AB /* MedalHeaderView.swift in Sources */,
1749 1752 6CFEEBA62772BED300621863 /* CameraViewController.swift in Sources */,
  1753 + 84DA399D2B4D3A5B008D34A9 /* NewGpsModel.swift in Sources */,
1750 1754 6C6DF2D3274F386600EF6B8D /* BloodPressureVC.swift in Sources */,
1751 1755 6C6505C72798FB030043DB7A /* LTTableView.swift in Sources */,
1752 1756 6C2EE97B277FFC6B0051413A /* HealthDataCell.swift in Sources */,
... ...
HDFwear/20240110ReadMe.md
... ... @@ -100,3 +100,8 @@ BluetoothManager+Function
100 100 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 6, 1, 140, 110]
101 101 接收: [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]
102 102 接收: [237, 126, 0, 1, 128, 25, 0, 1, 0, 1, 255, 79, 201]
  103 +
  104 +gps数据
  105 + func parseGpsData(_ content: [UInt8])
  106 + 接收: [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]
  107 + 接收: [237, 126, 0, 1, 128, 37, 0, 1, 0, 1, 255, 107, 166]
... ...
HDFwear/Home/Model/HealthModel.swift
... ... @@ -646,7 +646,6 @@ class TemperatureModel: Object {
646 646 }
647 647  
648 648 //MARK: - 压力
649   -//jtd!
650 649 class StressModel: Object {
651 650 @Persisted var value: Int = -1
652 651 @Persisted var date: Date? = nil
... ...
HDFwear/Home/Model/NewGpsModel.swift
... ... @@ -6,3 +6,69 @@
6 6 //
7 7  
8 8 import Foundation
  9 +import UIKit
  10 +import HandyJSON
  11 +import SwiftDate
  12 +
  13 +class NewGpsModel: NSObject {
  14 + required override init() { }
  15 + struct LocationPoint {
  16 + var longitudeValue: UInt32
  17 + var longitudeScale: UInt32
  18 + var latitudeValue: UInt32
  19 + var latitudeScale: UInt32
  20 +
  21 + var longitude: Double {
  22 + return convert(value: longitudeValue, scale: longitudeScale)
  23 + }
  24 +
  25 + var latitude: Double {
  26 + return convert(value: latitudeValue, scale: latitudeScale)
  27 + }
  28 +
  29 + private func convert(value: UInt32, scale: UInt32) -> Double {
  30 + if scale == 0 {
  31 + return 0
  32 + }
  33 + let degrees = Double(value) / (Double(scale) * 100)
  34 + let minutes = Double(value) / Double(scale) - degrees * 100
  35 + return degrees + (minutes * 1000000 / (60 * Double(scale))) / 1000000.0
  36 + }
  37 + }
  38 +
  39 + var exerciseType: Int = 0
  40 + var startTime: Date?
  41 + var locationCount: Int = 0
  42 + var locations: [LocationPoint] = []
  43 +
  44 + init(exerciseType: Int, startTime: Date? = nil, locationCount: Int, locations: [LocationPoint]) {
  45 + self.exerciseType = exerciseType
  46 + self.startTime = startTime
  47 + self.locationCount = locationCount
  48 + self.locations = locations
  49 + }
  50 +
  51 + class func toGpsModel(_ data: [UInt8]) -> NewGpsModel {
  52 + let gpsModel = NewGpsModel()
  53 + guard data.count >= 9 else {
  54 + return gpsModel // 数据长度不够
  55 + }
  56 + gpsModel.exerciseType = Int(data[0])
  57 + let combinedUInt32 = data[1..<5].reduce(0) { ($0 << 8) + UInt32($1) }
  58 + gpsModel.startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32))
  59 + gpsModel.locationCount = Int(data[5..<9].reduce(0) { ($0 << 8) + UInt32($1) })
  60 + var arr = [LocationPoint]()
  61 + // 将数组分成16个一组
  62 + for index in stride(from: 9, to: data.count, by: 16) {
  63 + let longitudeValue = data[index + 0..<index + 4].reduce(0) { ($0 << 8) + UInt32($1) }
  64 + let longitudeScale = data[index + 4..<index + 8].reduce(0) { ($0 << 8) + UInt32($1) }
  65 + let latitudeValue = data[index + 8..<index + 12].reduce(0) { ($0 << 8) + UInt32($1) }
  66 + let latitudeScale = data[index + 12..<index + 16].reduce(0) { ($0 << 8) + UInt32($1) }
  67 +
  68 + let point = LocationPoint(longitudeValue: longitudeValue, longitudeScale: longitudeScale, latitudeValue: latitudeValue, latitudeScale: latitudeScale)
  69 + arr.append(point)
  70 + }
  71 + gpsModel.locations = arr
  72 + return gpsModel
  73 + }
  74 +}
... ...
HDFwear/Mine/MineViewController.swift
... ... @@ -503,7 +503,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
503 503 }
504 504  
505 505 let archiveAction101 = UIAlertAction(title: "newGetGpsData", style: .default) { action in
506   - BluetoothManager.shared.newGetGpsData() {error in
  506 + BluetoothManager.shared.newGetGpsData() {gpsModel, error in
507 507 if error != nil {
508 508 print("newGetGpsData" + (error?.description ?? ""))
509 509 }else {
... ...
HDFwear/Tools/Bluetooth+Types.swift
... ... @@ -22,7 +22,6 @@ struct ScanDevice {
22 22  
23 23  
24 24  
25   -//jtd! 还需要校对
26 25 public struct BLEConfig {
27 26 // 新
28 27 static let ServerUUID = "0000FFF0-0000-1000-8000-00805F9B34FB" //主服务UUID
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -224,9 +224,9 @@ extension BluetoothManager {
224 224 }
225 225  
226 226 // 拉取GPS轨迹数据
227   - //jtd! 需要使用特定的回调,这样才能够直接把数据回调出来
228   - func newGetGpsData(option: SyncOption = .now, completion: ((_ error: Int?) -> ())? = nil) {
229   - newGetData(type: .gps, option: option, completion: completion)
  227 + func newGetGpsData(option: SyncOption = .now, closure: GpsClosure? = nil) {
  228 + let data = BleMessage.shared.getSyncCmd(.gps, option)
  229 + newStartSyncHealthData(closure: closure, data: data, synType: .gps)
230 230 }
231 231  
232 232 //MARK: - old code
... ... @@ -327,6 +327,12 @@ extension BluetoothManager {
327 327 mettClosure?([], -1002)
328 328 mettClosure = nil
329 329 }
  330 + case is GpsClosure:
  331 + if gpsClosure == nil {
  332 + gpsClosure = closure as? GpsClosure
  333 + gpsClosure?(nil, -1002)
  334 + gpsClosure = nil
  335 + }
330 336 default:
331 337 break
332 338 }
... ... @@ -505,14 +511,14 @@ extension BluetoothManager {
505 511 delegate.didReceiveCameraCommand(status: stauts)
506 512 }
507 513 case 0x8025://手表户外运动定位轨迹
508   - print("运动轨迹")
  514 + print("gps轨迹")
509 515 let content = parseContentFromBytes(bytes)
510 516 if (content.count == 1 && content.first == 0xff) {
511 517 for delegate in syncDelegateList {
512 518 delegate.didReceiveFinishCommand(0x8025)
513 519 }
514 520 }else {
515   - // parseStepData(content)
  521 + parseGpsData(content)
516 522 }
517 523 default:
518 524 break
... ... @@ -688,15 +694,13 @@ extension BluetoothManager {
688 694 }
689 695  
690 696 // GPS数据
691   - func parseGPSData (_ content: [UInt8]) {
692   - //jtd! parse gps data
693   -// guard content.count > 0 else {
694   -// print("无有效的信息")
695   -// heartRateClosure?([], nil)
696   -// return
697   -// }
698   -// let hrArray = HeartRateModel.toHeartRateArray(content)
699   -// HeartRateModel.addArray(hrArray)// 加入数据库
700   -// heartRateClosure?(hrArray, nil)
  697 + func parseGpsData(_ content: [UInt8]) {
  698 + guard content.count > 0 else {
  699 + print("无有效的信息")
  700 + gpsClosure?(nil, nil)
  701 + return
  702 + }
  703 + let gpsModel = NewGpsModel.toGpsModel(content)
  704 + gpsClosure?(gpsModel, nil)
701 705 }
702 706 }
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -93,6 +93,8 @@ class BluetoothManager: NSObject {
93 93 var pressureClosure: PressureClosure?
94 94 typealias MettClosure = (_ mettArray: [MettModel], _ error: Int?) -> Void
95 95 var mettClosure: MettClosure?
  96 + typealias GpsClosure = (_ gps: NewGpsModel?, _ error: Int?) -> Void
  97 + var gpsClosure: GpsClosure?
96 98  
97 99 typealias DialProgressClosure = (_ progress: Int) -> Void
98 100 var dialProgressClosure: DialProgressClosure?
... ... @@ -1306,6 +1308,8 @@ class BluetoothManager: NSObject {
1306 1308 pressureClosure = closure as? PressureClosure
1307 1309 case is MettClosure:
1308 1310 mettClosure = closure as? MettClosure
  1311 + case is GpsClosure:
  1312 + gpsClosure = closure as? GpsClosure
1309 1313 default:
1310 1314 break
1311 1315 }
... ...