// // UserInfo.swift // Twear // // Created by yangbin on 2021/12/8. // import UIKit import HandyJSON import SwiftDate class AdminModel: NSObject, HandyJSON { var userInfo: UserInfoModel = UserInfoModel() var device: DeviceModel = DeviceModel() required override init() { } } enum Platform: String, HandyJSONEnum { case _828 = "828" case other = "other" } class RemindModel: NSObject, HandyJSON { var isOn: Bool = false var startDate: Date = Date() var endDate: Date = Date() var interval: Int = 0 var cycle: Int = 127 init(isOn: Bool, startDate: Date, endDate: Date) { super.init() self.isOn = isOn self.startDate = startDate self.endDate = endDate } init(type: String) { super.init() self.isOn = false switch type { case "disturb": self.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 22, minute: 0).date self.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 22, minute: 0).date case "sedentary", "drink": self.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 9, minute: 0).date self.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 23, minute: 00).date self.interval = 45 default: break } } override func isEqual(_ object: Any?) -> Bool { if let otherFoo = object as? RemindModel { return self.isOn == otherFoo.isOn && self.startDate == otherFoo.startDate && self.endDate == otherFoo.endDate && self.interval == otherFoo.interval && self.cycle == otherFoo.cycle } return false } class func toRemindModel(_ bytes: [UInt8]) -> RemindModel { let remind = RemindModel() remind.isOn = bytes[0] == 1 if bytes.count == 5 { remind.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[1]), minute: Int(bytes[2])).date remind.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[3]), minute: Int(bytes[4])).date } else if bytes.count == 6 { remind.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[1]), minute: 0).date remind.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[2]), minute: 0).date remind.cycle = Int(bytes[3]) remind.interval = bytesToInt(Array(bytes[4.. AlarmClockModel? { let alarmClock = AlarmClockModel() if Int(bytes[3]) == 0 { return nil } alarmClock.date = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[0]), minute: Int(bytes[1])).date alarmClock.cycle = Int(bytes[2]) alarmClock.isOn = Int(bytes[4]) == 1 return alarmClock } init(date: Date, isOn: Bool, cycle: Int) { self.date = date self.isOn = isOn self.cycle = cycle } func mapping(mapper: HelpingMapper) { mapper <<< date <-- CustomDateFormatTransform(formatString: "HH:mm") } func toBytes() -> [UInt8] { let bytes: [UInt8] = [UInt8(self.date.hour), UInt8(self.date.minute), UInt8(self.cycle), 0x01, isOn ? 0x01 : 0x00] print("闹钟:\(bytes)") return [UInt8(self.date.hour), UInt8(self.date.minute), UInt8(self.cycle), 0x01, isOn ? 0x01 : 0x00] } required override init() { } } class MessagePushModel: NSObject, HandyJSON { var value: Int { get { return bitsToInt([other ? 1 : 0, facebook ? 1 : 0, ins ? 1 : 0, linkedin ? 1 : 0, twitter ? 1 : 0, messenger ? 1 : 0, whatsapp ? 1 : 0, wechat ? 1 : 0, qq ? 1 : 0, sms ? 1 : 0, call ? 1 : 0]) } } var call: Bool = false var sms: Bool = false var qq: Bool = false var wechat: Bool = false var whatsapp: Bool = false var messenger: Bool = false var twitter: Bool = false var linkedin: Bool = false var ins: Bool = false var facebook: Bool = false var other: Bool = false var app: Bool { get { return qq || wechat || whatsapp || messenger || twitter || linkedin || ins || facebook || other } } init(value: Int) { super.init() let array = toBits(value) self.call = array[0] == 1 self.sms = array[1] == 1 self.qq = array[2] == 1 self.wechat = array[3] == 1 self.whatsapp = array[4] == 1 self.messenger = array[5] == 1 self.twitter = array[6] == 1 self.linkedin = array[7] == 1 self.ins = array[8] == 1 self.facebook = array[9] == 1 self.other = array[10] == 1 } private func bitsToInt(_ bits: [Int]) -> Int { let decimalValue = bits.reduce(0) { v, byte in return v << 1 | Int(byte) } print(decimalValue) return Int(decimalValue) } private func toBits(_ value: Int) -> [Int] { var byte = value var bits = [Int](repeating: 0, count: 11) for i in 0..<11 { let currentBit = byte & 0x01 if currentBit != 0 { bits[i] = 1 } byte >>= 1 } return bits } required override init() { } } class MenstrualModel: NSObject, HandyJSON { var days: Int = 0 var cycle: Int = 0 var lastDate: Date? // var calendar: MenstrualCalendarModel = MenstrualCalendarModel() init(days: Int, cycle: Int, lastDate: Date) { super.init() self.days = days self.cycle = cycle self.lastDate = lastDate } func mapping(mapper: HelpingMapper) { mapper <<< lastDate <-- CustomDateFormatTransform(formatString: "yyyy-MM-dd") } required override init() { } } class DeviceModel: NSObject, HandyJSON { var uuid: String = "" var name: String = "" // var typeRaw: String = "other" var isSync: Bool = false var isConnected: Bool = false var mac: String = "" var disturb: RemindModel = RemindModel(type: "disturb") var type: String = "" var languageRaw: String = "system" var version: String = "" var allFunctions: [String] = ["HeartRate", "Sleep", "Train", "WomenHealth", "MotionRecord"] var homePage: [String] = ["HeartRate", "Sleep", "WomenHealth", "Train", "MotionRecord"] var queryArray: [String] { get { var array = allFunctions if let i = array.firstIndex(of: "MotionRecord") { array.remove(at: i) } if let i = array.firstIndex(of: "WomenHealth") { array.remove(at: i) } if platform == ._828 { if let i = array.firstIndex(of: "BloodPressure") { array.remove(at: i) } if let i = array.firstIndex(of: "BloodOxygen") { array.remove(at: i) } } array.append(contentsOf: ["Step", "Setting"]) return array } } var platform: Platform = .other init(uuid: String, name: String, platform: Platform, mac: String) { super.init() self.uuid = uuid self.name = name self.platform = platform self.mac = mac switch platform { case ._828: self.allFunctions = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train", "MotionRecord", "WomenHealth"] self.homePage = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train", "MotionRecord", "WomenHealth"] if name.contains("P8GT") { self.allFunctions = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train", "MotionRecord", "WomenHealth"] self.homePage = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train", "MotionRecord", "WomenHealth"] } // self.queryArray = ["BloodPressure", "Step", "HeartRate", "Sleep", "Train", "Setting"] case .other: break } } required override init() { } } class NFCModel: NSObject, HandyJSON { var type: String = "" var identifier: String = "" var payload: String = "" var format: String = "" var image: String = "4" var name: String = LocString("门卡") required override init() { } } class ContactModel: NSObject, HandyJSON { var name: String = "" var number: String = "" var isSOS: Bool = false var isSelected: Bool = false init(name: String, number: String) { super.init() self.name = name self.number = number } func toBytes(_ index: Int) -> [UInt8] { var bytes: [UInt8] = [UInt8](repeating: 0x00, count: 66) if name == "" && number == "" { return bytes } var phoneNumber = number phoneNumber = phoneNumber.replacingOccurrences(of: " ", with: "") if name == "" { for (i, scalar) in phoneNumber.unicodeScalars.enumerated() { if i < 16 { bytes[i*2+30] = UInt8(scalar.value & 0xFF) bytes[i*2+31] = UInt8(scalar.value >> 8) } } } else { for (i, scalar) in name.unicodeScalars.enumerated() { if i < 16 { if #available(iOS 10.2, *) { if scalar.properties.isEmoji && scalar.value > 0x238C { bytes[i*2+30] = UInt8("□".unicodeScalars.first!.value & 0xFF) bytes[i*2+31] = UInt8("□".unicodeScalars.first!.value >> 8) } else { bytes[i*2+30] = UInt8(scalar.value & 0xFF) bytes[i*2+31] = UInt8(scalar.value >> 8) } } else { if scalar.value > 0xFFFF { bytes[i*2+30] = UInt8("□".unicodeScalars.first!.value & 0xFF) bytes[i*2+31] = UInt8("□".unicodeScalars.first!.value >> 8) } else { bytes[i*2+30] = UInt8(scalar.value & 0xFF) bytes[i*2+31] = UInt8(scalar.value >> 8) } } } } } //54, 65, 108, 101, 110 // let num = number.replacingOccurrences(of: " ", with: "") for (i, scalar) in phoneNumber.unicodeScalars.enumerated() { if i < 15 { bytes[i*2] = UInt8(scalar.value & 0xFF) bytes[i*2+1] = UInt8(scalar.value >> 8) } } bytes[62] = UInt8(phoneNumber.count > 15 ? 15 : phoneNumber.count) bytes[63] = UInt8(name.count > 16 ? 16 : name.count) bytes[64] = UInt8(index) bytes[65] = isSOS ? 0x01 : 0x00 return bytes // l2KeyValue[startIndex+50]=(byte)numberLength; // l2KeyValue[startIndex+51]=(byte)nameLength; // l2KeyValue[startIndex+52]=(byte)(i+1); // l2KeyValue[startIndex+53]=(byte)(sos[i]); } required override init() { } } class UserInfoModel: NSObject, HandyJSON { var name: String = "" var gender: Int = 1 // 1男 0女 var mac: String = "" var height: Int = 175 //cm var weight: Int = 65 //kg var age: Int = 24 var phone: String = "" var userId: Int = Int(arc4random_uniform(89999999) + 10000000) var stepsGoal: Int = 8000 var birth: Date = (DateInRegion().date - 24.years).dateAtStartOf(.year) var menstrual: MenstrualModel = MenstrualModel() var contacts: [ContactModel] = [] var nfc: [NFCModel] = [] var isDailSync: Bool = false var dailIndex: Int = -1 var dialIndexPath: String = "" var customDial: String = "" var dialNumDic: [String: Int] = [:] var dailVersion: String = "0" var medalVersion: String = "0" var push: MessagePushModel = MessagePushModel() var drink: RemindModel = RemindModel(type: "drink") var sedentary: RemindModel = RemindModel(type: "sedentary") var alarmClocks: [AlarmClockModel] = [] // var avatarUrl: String = "" //头像 var distanceUnit: Int = 0 var temperatureUnit: Int = 0 var timeFormat: Int = 0 var wrist: Bool = true var autoMasure: Bool = false func mapping(mapper: HelpingMapper) { mapper <<< birth <-- CustomDateFormatTransform(formatString: "yyyy-MM-dd") } required override init() { } } // //class MedalTypeModel: NSObject { // var title: String = "" // var medals: [MedalModel] = [] //}