messages.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. // Autogenerated from Pigeon (v9.1.0), do not edit directly.
  2. // See also: https://pub.dev/packages/pigeon
  3. import Foundation
  4. #if os(iOS)
  5. import Flutter
  6. #elseif os(macOS)
  7. import FlutterMacOS
  8. #else
  9. #error("Unsupported platform.")
  10. #endif
  11. private func wrapResult(_ result: Any?) -> [Any?] {
  12. return [result]
  13. }
  14. private func wrapError(_ error: Any) -> [Any?] {
  15. if let flutterError = error as? FlutterError {
  16. return [
  17. flutterError.code,
  18. flutterError.message,
  19. flutterError.details
  20. ]
  21. }
  22. return [
  23. "\(error)",
  24. "\(type(of: error))",
  25. "Stacktrace: \(Thread.callStackSymbols)"
  26. ]
  27. }
  28. /// Generated class from Pigeon that represents data sent in messages.
  29. struct Orientation {
  30. var x: Double? = nil
  31. var y: Double? = nil
  32. var z: Double? = nil
  33. static func fromList(_ list: [Any]) -> Orientation? {
  34. let x = list[0] as! Double?
  35. let y = list[1] as! Double?
  36. let z = list[2] as! Double?
  37. return Orientation(
  38. x: x,
  39. y: y,
  40. z: z
  41. )
  42. }
  43. func toList() -> [Any?] {
  44. return [
  45. x,
  46. y,
  47. z,
  48. ]
  49. }
  50. }
  51. /// Generated class from Pigeon that represents data sent in messages.
  52. struct Position {
  53. var latitude: Double? = nil
  54. var longitude: Double? = nil
  55. var altitude: Double? = nil
  56. var bearing: Double? = nil
  57. var accuracy: Double? = nil
  58. /// the speed at the time of this location in meters per second.
  59. var speed: Double? = nil
  60. var timeMs: Int64? = nil
  61. static func fromList(_ list: [Any]) -> Position? {
  62. let latitude = list[0] as! Double?
  63. let longitude = list[1] as! Double?
  64. let altitude = list[2] as! Double?
  65. let bearing = list[3] as! Double?
  66. let accuracy = list[4] as! Double?
  67. let speed = list[5] as! Double?
  68. let timeMs = list[6] as! Int64?
  69. return Position(
  70. latitude: latitude,
  71. longitude: longitude,
  72. altitude: altitude,
  73. bearing: bearing,
  74. accuracy: accuracy,
  75. speed: speed,
  76. timeMs: timeMs
  77. )
  78. }
  79. func toList() -> [Any?] {
  80. return [
  81. latitude,
  82. longitude,
  83. altitude,
  84. bearing,
  85. accuracy,
  86. speed,
  87. timeMs,
  88. ]
  89. }
  90. }
  91. /// Generated class from Pigeon that represents data sent in messages.
  92. struct SportWear {
  93. var address: String? = nil
  94. var name: String? = nil
  95. var rssi: Int64? = nil
  96. var batteryLevel: Int64? = nil
  97. static func fromList(_ list: [Any]) -> SportWear? {
  98. let address = list[0] as! String?
  99. let name = list[1] as! String?
  100. let rssi = list[2] as! Int64?
  101. let batteryLevel = list[3] as! Int64?
  102. return SportWear(
  103. address: address,
  104. name: name,
  105. rssi: rssi,
  106. batteryLevel: batteryLevel
  107. )
  108. }
  109. func toList() -> [Any?] {
  110. return [
  111. address,
  112. name,
  113. rssi,
  114. batteryLevel,
  115. ]
  116. }
  117. }
  118. /// Generated class from Pigeon that represents data sent in messages.
  119. struct HeartRateMeasurement {
  120. var deviceMac: String? = nil
  121. var heartRate: Int64? = nil
  122. var contactDetected: Bool? = nil
  123. var rrIntervals: [Int64?]? = nil
  124. var timestampMill: Int64? = nil
  125. static func fromList(_ list: [Any]) -> HeartRateMeasurement? {
  126. let deviceMac = list[0] as! String?
  127. let heartRate = list[1] as! Int64?
  128. let contactDetected = list[2] as! Bool?
  129. let rrIntervals = list[3] as! [Int64?]?
  130. let timestampMill = list[4] as! Int64?
  131. return HeartRateMeasurement(
  132. deviceMac: deviceMac,
  133. heartRate: heartRate,
  134. contactDetected: contactDetected,
  135. rrIntervals: rrIntervals,
  136. timestampMill: timestampMill
  137. )
  138. }
  139. func toList() -> [Any?] {
  140. return [
  141. deviceMac,
  142. heartRate,
  143. contactDetected,
  144. rrIntervals,
  145. timestampMill,
  146. ]
  147. }
  148. }
  149. private class SensorApiCodecReader: FlutterStandardReader {
  150. override func readValue(ofType type: UInt8) -> Any? {
  151. switch type {
  152. case 128:
  153. return HeartRateMeasurement.fromList(self.readValue() as! [Any])
  154. case 129:
  155. return Orientation.fromList(self.readValue() as! [Any])
  156. case 130:
  157. return Position.fromList(self.readValue() as! [Any])
  158. case 131:
  159. return SportWear.fromList(self.readValue() as! [Any])
  160. default:
  161. return super.readValue(ofType: type)
  162. }
  163. }
  164. }
  165. private class SensorApiCodecWriter: FlutterStandardWriter {
  166. override func writeValue(_ value: Any) {
  167. if let value = value as? HeartRateMeasurement {
  168. super.writeByte(128)
  169. super.writeValue(value.toList())
  170. } else if let value = value as? Orientation {
  171. super.writeByte(129)
  172. super.writeValue(value.toList())
  173. } else if let value = value as? Position {
  174. super.writeByte(130)
  175. super.writeValue(value.toList())
  176. } else if let value = value as? SportWear {
  177. super.writeByte(131)
  178. super.writeValue(value.toList())
  179. } else {
  180. super.writeValue(value)
  181. }
  182. }
  183. }
  184. private class SensorApiCodecReaderWriter: FlutterStandardReaderWriter {
  185. override func reader(with data: Data) -> FlutterStandardReader {
  186. return SensorApiCodecReader(data: data)
  187. }
  188. override func writer(with data: NSMutableData) -> FlutterStandardWriter {
  189. return SensorApiCodecWriter(data: data)
  190. }
  191. }
  192. class SensorApiCodec: FlutterStandardMessageCodec {
  193. static let shared = SensorApiCodec(readerWriter: SensorApiCodecReaderWriter())
  194. }
  195. /// Generated protocol from Pigeon that represents a handler of messages from Flutter.
  196. protocol SensorApi {
  197. /// 获取当前位置,[force]为 false 时,
  198. /// 优先使用 lastPosition,为 true 强制重新获取当前位置。
  199. func getCurrentPosition(force: Bool, completion: @escaping (Result<Position, Error>) -> Void)
  200. func locationStart(minTimeMs: Int64, minDistanceM: Double) throws
  201. func locationStop() throws
  202. func sportWearScanStart() throws
  203. func sportWearScanStop() throws
  204. func askEnableBluetooth(completion: @escaping (Result<Bool, Error>) -> Void)
  205. func sportWearConnect(wear: SportWear, completion: @escaping (Result<Void, Error>) -> Void)
  206. func sportWearDisconnect(wear: SportWear, completion: @escaping (Result<Void, Error>) -> Void)
  207. /// 是否开启位置服务
  208. func isLocationServiceOpen() throws -> Bool
  209. func getYDPI() throws -> Double
  210. func getXDPI() throws -> Double
  211. /// 只需要空实现即可,class必须有函数引用才会生成代码
  212. func toGenAllClass(orientation: Orientation, hrm: HeartRateMeasurement, position: Position) throws
  213. }
  214. /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
  215. class SensorApiSetup {
  216. /// The codec used by SensorApi.
  217. static var codec: FlutterStandardMessageCodec { SensorApiCodec.shared }
  218. /// Sets up an instance of `SensorApi` to handle messages through the `binaryMessenger`.
  219. static func setUp(binaryMessenger: FlutterBinaryMessenger, api: SensorApi?) {
  220. /// 获取当前位置,[force]为 false 时,
  221. /// 优先使用 lastPosition,为 true 强制重新获取当前位置。
  222. let getCurrentPositionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.getCurrentPosition", binaryMessenger: binaryMessenger, codec: codec)
  223. if let api = api {
  224. getCurrentPositionChannel.setMessageHandler { message, reply in
  225. let args = message as! [Any]
  226. let forceArg = args[0] as! Bool
  227. api.getCurrentPosition(force: forceArg) { result in
  228. switch result {
  229. case .success(let res):
  230. reply(wrapResult(res))
  231. case .failure(let error):
  232. reply(wrapError(error))
  233. }
  234. }
  235. }
  236. } else {
  237. getCurrentPositionChannel.setMessageHandler(nil)
  238. }
  239. let locationStartChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.locationStart", binaryMessenger: binaryMessenger, codec: codec)
  240. if let api = api {
  241. locationStartChannel.setMessageHandler { message, reply in
  242. let args = message as! [Any]
  243. let minTimeMsArg = (args[0] is Int) ? Int64(args[0] as! Int) : args[0] as! Int64
  244. let minDistanceMArg = args[1] as! Double
  245. do {
  246. try api.locationStart(minTimeMs: minTimeMsArg, minDistanceM: minDistanceMArg)
  247. reply(wrapResult(nil))
  248. } catch {
  249. reply(wrapError(error))
  250. }
  251. }
  252. } else {
  253. locationStartChannel.setMessageHandler(nil)
  254. }
  255. let locationStopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.locationStop", binaryMessenger: binaryMessenger, codec: codec)
  256. if let api = api {
  257. locationStopChannel.setMessageHandler { _, reply in
  258. do {
  259. try api.locationStop()
  260. reply(wrapResult(nil))
  261. } catch {
  262. reply(wrapError(error))
  263. }
  264. }
  265. } else {
  266. locationStopChannel.setMessageHandler(nil)
  267. }
  268. let sportWearScanStartChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearScanStart", binaryMessenger: binaryMessenger, codec: codec)
  269. if let api = api {
  270. sportWearScanStartChannel.setMessageHandler { _, reply in
  271. do {
  272. try api.sportWearScanStart()
  273. reply(wrapResult(nil))
  274. } catch {
  275. reply(wrapError(error))
  276. }
  277. }
  278. } else {
  279. sportWearScanStartChannel.setMessageHandler(nil)
  280. }
  281. let sportWearScanStopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearScanStop", binaryMessenger: binaryMessenger, codec: codec)
  282. if let api = api {
  283. sportWearScanStopChannel.setMessageHandler { _, reply in
  284. do {
  285. try api.sportWearScanStop()
  286. reply(wrapResult(nil))
  287. } catch {
  288. reply(wrapError(error))
  289. }
  290. }
  291. } else {
  292. sportWearScanStopChannel.setMessageHandler(nil)
  293. }
  294. let askEnableBluetoothChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.askEnableBluetooth", binaryMessenger: binaryMessenger, codec: codec)
  295. if let api = api {
  296. askEnableBluetoothChannel.setMessageHandler { _, reply in
  297. api.askEnableBluetooth() { result in
  298. switch result {
  299. case .success(let res):
  300. reply(wrapResult(res))
  301. case .failure(let error):
  302. reply(wrapError(error))
  303. }
  304. }
  305. }
  306. } else {
  307. askEnableBluetoothChannel.setMessageHandler(nil)
  308. }
  309. let sportWearConnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearConnect", binaryMessenger: binaryMessenger, codec: codec)
  310. if let api = api {
  311. sportWearConnectChannel.setMessageHandler { message, reply in
  312. let args = message as! [Any]
  313. let wearArg = args[0] as! SportWear
  314. api.sportWearConnect(wear: wearArg) { result in
  315. switch result {
  316. case .success:
  317. reply(wrapResult(nil))
  318. case .failure(let error):
  319. reply(wrapError(error))
  320. }
  321. }
  322. }
  323. } else {
  324. sportWearConnectChannel.setMessageHandler(nil)
  325. }
  326. let sportWearDisconnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.sportWearDisconnect", binaryMessenger: binaryMessenger, codec: codec)
  327. if let api = api {
  328. sportWearDisconnectChannel.setMessageHandler { message, reply in
  329. let args = message as! [Any]
  330. let wearArg = args[0] as! SportWear
  331. api.sportWearDisconnect(wear: wearArg) { result in
  332. switch result {
  333. case .success:
  334. reply(wrapResult(nil))
  335. case .failure(let error):
  336. reply(wrapError(error))
  337. }
  338. }
  339. }
  340. } else {
  341. sportWearDisconnectChannel.setMessageHandler(nil)
  342. }
  343. /// 是否开启位置服务
  344. let isLocationServiceOpenChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.isLocationServiceOpen", binaryMessenger: binaryMessenger, codec: codec)
  345. if let api = api {
  346. isLocationServiceOpenChannel.setMessageHandler { _, reply in
  347. do {
  348. let result = try api.isLocationServiceOpen()
  349. reply(wrapResult(result))
  350. } catch {
  351. reply(wrapError(error))
  352. }
  353. }
  354. } else {
  355. isLocationServiceOpenChannel.setMessageHandler(nil)
  356. }
  357. let getYDPIChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.getYDPI", binaryMessenger: binaryMessenger, codec: codec)
  358. if let api = api {
  359. getYDPIChannel.setMessageHandler { _, reply in
  360. do {
  361. let result = try api.getYDPI()
  362. reply(wrapResult(result))
  363. } catch {
  364. reply(wrapError(error))
  365. }
  366. }
  367. } else {
  368. getYDPIChannel.setMessageHandler(nil)
  369. }
  370. let getXDPIChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.getXDPI", binaryMessenger: binaryMessenger, codec: codec)
  371. if let api = api {
  372. getXDPIChannel.setMessageHandler { _, reply in
  373. do {
  374. let result = try api.getXDPI()
  375. reply(wrapResult(result))
  376. } catch {
  377. reply(wrapError(error))
  378. }
  379. }
  380. } else {
  381. getXDPIChannel.setMessageHandler(nil)
  382. }
  383. /// 只需要空实现即可,class必须有函数引用才会生成代码
  384. let toGenAllClassChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.SensorApi.toGenAllClass", binaryMessenger: binaryMessenger, codec: codec)
  385. if let api = api {
  386. toGenAllClassChannel.setMessageHandler { message, reply in
  387. let args = message as! [Any]
  388. let orientationArg = args[0] as! Orientation
  389. let hrmArg = args[1] as! HeartRateMeasurement
  390. let positionArg = args[2] as! Position
  391. do {
  392. try api.toGenAllClass(orientation: orientationArg, hrm: hrmArg, position: positionArg)
  393. reply(wrapResult(nil))
  394. } catch {
  395. reply(wrapError(error))
  396. }
  397. }
  398. } else {
  399. toGenAllClassChannel.setMessageHandler(nil)
  400. }
  401. }
  402. }