Commit 6a02f5338a3f0d5b85f4641d894680578e5381bc

Authored by jason
1 parent 36b76cd7

feat:beidou card

HDFwear/20240126ReadMe.md
... ... @@ -101,4 +101,10 @@ BluetoothManager+Function
101 101 接收: [237, 126, 0, 1, 128, 40, 0, 2, 0, 28, 7, 232, 1, 9, 0, 0, 0, 0, 0, 0, 10, 10, 10, 20, 30, 52, 0, 24, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 164, 33]
102 102 接收: [237, 126, 0, 1, 128, 40, 0, 2, 0, 1, 255, 190, 57]
103 103  
  104 +拉取北斗卡号数据
  105 + func newGetBeidouCardData(option: SyncOption = .now, closure: BeidouCardClosure? = nil)
  106 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 12, 1, 99, 165]
  107 + 接收: [237, 126, 0, 1, 128, 41, 0, 1, 0, 8, 49, 52, 52, 57, 51, 48, 55, 49, 16, 131]
  108 +
  109 +
104 110 接受数据类
... ...
HDFwear/Mine/MineViewController.swift
... ... @@ -611,6 +611,16 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
611 611 }
612 612 }
613 613  
  614 + let archiveAction103 = UIAlertAction(title: "newGetBeidouCardData", style: .default) {[weak self] action in
  615 + BluetoothManager.shared.newGetBeidouCardData() {card, error in
  616 + if error != nil {
  617 + print("newGetBeidouCardData" + (error?.description ?? ""))
  618 + }else {
  619 + self?.showDetailAlert(msg: card)
  620 + print("newGetBeidouCardData success")
  621 + }
  622 + }
  623 + }
614 624  
615 625 alert.addAction(archiveAction9a)
616 626 alert.addAction(archiveAction9b)
... ... @@ -628,6 +638,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
628 638 alert.addAction(archiveAction101b)
629 639 alert.addAction(archiveAction102a)
630 640 alert.addAction(archiveAction102b)
  641 + alert.addAction(archiveAction103)
631 642  
632 643 alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil))
633 644 present(alert, animated: true, completion: nil)
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -244,6 +244,12 @@ extension BluetoothManager {
244 244 newStartSyncHealthData(closure: closure, data: data, synType: .intensiveTime)
245 245 }
246 246  
  247 + // 拉取北斗卡号
  248 + func newGetBeidouCardData(option: SyncOption = .now, closure: BeidouCardClosure? = nil) {
  249 + let data = BleMessage.shared.getSyncCmd(.beidouCard, option)
  250 + newStartSyncHealthData(closure: closure, data: data, synType: .beidouCard)
  251 + }
  252 +
247 253 //MARK: - old code
248 254 // 拉取睡眠数据
249 255 func getSleepData(option: SyncOption = .now, closure: SleepClosure? = nil) {
... ... @@ -354,6 +360,12 @@ extension BluetoothManager {
354 360 intensiveTimeClosure?(nil, -1002)
355 361 intensiveTimeClosure = nil
356 362 }
  363 + case is BeidouCardClosure:
  364 + if beidouCardClosure == nil {
  365 + beidouCardClosure = closure as? BeidouCardClosure
  366 + beidouCardClosure?(nil, -1002)
  367 + beidouCardClosure = nil
  368 + }
357 369 default:
358 370 break
359 371 }
... ... @@ -556,6 +568,16 @@ extension BluetoothManager {
556 568 }else {
557 569 parseIntensiveTimeData(content)
558 570 }
  571 + case 0x8029://北斗卡号
  572 + print("北斗卡号")
  573 + let content = parseContentFromBytes(bytes)
  574 + if (content.count == 1 && content.first == 0xff) {
  575 + for delegate in syncDelegateList {
  576 + delegate.didReceiveFinishCommand(0x8029)
  577 + }
  578 + }else {
  579 + parseBeidouCardData(content)
  580 + }
559 581 default:
560 582 break
561 583 }
... ... @@ -751,4 +773,15 @@ extension BluetoothManager {
751 773 let gpsModel = NewIntensiveTimeModel.toIntensiveTimeModel(content)
752 774 intensiveTimeClosure?(gpsModel, nil)
753 775 }
  776 +
  777 + // 北斗卡号数据
  778 + func parseBeidouCardData(_ content: [UInt8]) {
  779 + guard content.count > 0 else {
  780 + print("无有效的信息")
  781 + intensiveTimeClosure?(nil, nil)
  782 + return
  783 + }
  784 + let card = String(bytes: content, encoding: .ascii)
  785 + beidouCardClosure?(card, nil)
  786 + }
754 787 }
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -97,6 +97,8 @@ class BluetoothManager: NSObject {
97 97 var gpsClosure: GpsClosure?
98 98 typealias IntensiveTimeClosure = (_ intensiveTime:NewIntensiveTimeModel?, _ error: Int?) -> Void
99 99 var intensiveTimeClosure: IntensiveTimeClosure?
  100 + typealias BeidouCardClosure = (_ card:String?, _ error: Int?) -> Void
  101 + var beidouCardClosure: BeidouCardClosure?
100 102  
101 103 typealias DialProgressClosure = (_ progress: Int) -> Void
102 104 var dialProgressClosure: DialProgressClosure?
... ... @@ -1295,6 +1297,7 @@ class BluetoothManager: NSObject {
1295 1297 mettClosure = nil
1296 1298 gpsClosure = nil
1297 1299 intensiveTimeClosure = nil
  1300 + beidouCardClosure = nil
1298 1301 switch closure {
1299 1302 case is BloodPressureClosure:
1300 1303 bloodPressureClosure = closure as? BloodPressureClosure
... ... @@ -1316,6 +1319,8 @@ class BluetoothManager: NSObject {
1316 1319 gpsClosure = closure as? GpsClosure
1317 1320 case is IntensiveTimeClosure:
1318 1321 intensiveTimeClosure = closure as? IntensiveTimeClosure
  1322 + case is BeidouCardClosure:
  1323 + beidouCardClosure = closure as? BeidouCardClosure
1319 1324 default:
1320 1325 break
1321 1326 }
... ...