ReadOtherDevicesIDsMessageBody.swift 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // ReadOtherDevicesIDsMessageBody.swift
  3. // MinimedKit
  4. //
  5. // Copyright © 2018 Pete Schwamb. All rights reserved.
  6. //
  7. import Foundation
  8. public class ReadOtherDevicesIDsMessageBody: CarelinkLongMessageBody {
  9. public let ids: [Data]
  10. public required init?(rxData: Data) {
  11. guard rxData.count == type(of: self).length else {
  12. return nil
  13. }
  14. let count = Int(rxData[1])
  15. var ids: [Data] = []
  16. for index in stride(from: 0, to: count, by: 1) {
  17. let start = (index * 5 + 3)
  18. let end = start + 4
  19. ids.append(rxData.subdata(in: start..<end))
  20. }
  21. self.ids = ids
  22. super.init(rxData: rxData)
  23. }
  24. }
  25. // Body[1] is the count Body[3..<7] is the first ID.
  26. // 1f0101 a2105728 00 00000636 036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000
  27. // 1f0201 a2105728 00 a2016016 036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000