Opcode.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Opcode.swift
  3. // xDripG5
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import Foundation
  8. enum Opcode: UInt8 {
  9. // Auth
  10. case authRequestTx = 0x01
  11. case authRequestRx = 0x03
  12. case authChallengeTx = 0x04
  13. case authChallengeRx = 0x05
  14. case keepAlive = 0x06 // auth; setAdvertisementParametersTx for control
  15. case bondRequest = 0x07
  16. // Control
  17. case disconnectTx = 0x09
  18. case setAdvertisementParametersRx = 0x1c
  19. case firmwareVersionTx = 0x20
  20. case firmwareVersionRx = 0x21
  21. case batteryStatusTx = 0x22
  22. case batteryStatusRx = 0x23
  23. case transmitterTimeTx = 0x24
  24. case transmitterTimeRx = 0x25
  25. case sessionStartTx = 0x26
  26. case sessionStartRx = 0x27
  27. case sessionStopTx = 0x28
  28. case sessionStopRx = 0x29
  29. case glucoseTx = 0x30
  30. case glucoseRx = 0x31
  31. case calibrationDataTx = 0x32
  32. case calibrationDataRx = 0x33
  33. case calibrateGlucoseTx = 0x34
  34. case calibrateGlucoseRx = 0x35
  35. case glucoseHistoryTx = 0x3e
  36. case resetTx = 0x42
  37. case resetRx = 0x43
  38. case transmitterVersionTx = 0x4a
  39. case transmitterVersionRx = 0x4b
  40. case glucoseG6Tx = 0x4e
  41. case glucoseG6Rx = 0x4f
  42. case glucoseBackfillTx = 0x50
  43. case glucoseBackfillRx = 0x51
  44. }
  45. extension Data {
  46. init(for opcode: Opcode) {
  47. self.init([opcode.rawValue])
  48. }
  49. func starts(with opcode: Opcode) -> Bool {
  50. guard count > 0 else {
  51. return false
  52. }
  53. return self[startIndex] == opcode.rawValue
  54. }
  55. }