PumpMessageSender.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // PumpMessageSender.swift
  3. // RileyLink
  4. //
  5. // Created by Jaim Zuber on 3/2/17.
  6. // Copyright © 2017 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. import RileyLinkBLEKit
  10. public protocol PumpMessageSender {
  11. /// - Throws: LocalizedError
  12. func resetRadioConfig() throws
  13. /// - Throws: LocalizedError
  14. func updateRegister(_ address: CC111XRegister, value: UInt8) throws
  15. /// - Throws: LocalizedError
  16. func setBaseFrequency(_ frequency: Measurement<UnitFrequency>) throws
  17. /// - Throws: LocalizedError
  18. func listen(onChannel channel: Int, timeout: TimeInterval) throws -> RFPacket?
  19. /// - Throws: LocalizedError
  20. func send(_ msg: PumpMessage) throws
  21. /// - Throws: LocalizedError
  22. func getRileyLinkStatistics() throws -> RileyLinkStatistics
  23. /// Sends a message to the pump, expecting a PumpMessage with specific response body type
  24. ///
  25. /// - Parameters:
  26. /// - message: The message to send
  27. /// - responseType: The expected response message type
  28. /// - repeatCount: The number of times to repeat the message before listening begins
  29. /// - timeout: The length of time to listen for a pump response
  30. /// - retryCount: The number of times to repeat the send & listen sequence
  31. /// - Returns: The expected response message body
  32. /// - Throws:
  33. /// - PumpOpsError.couldNotDecode
  34. /// - PumpOpsError.crosstalk
  35. /// - PumpOpsError.deviceError
  36. /// - PumpOpsError.noResponse
  37. /// - PumpOpsError.pumpError
  38. /// - PumpOpsError.unexpectedResponse
  39. /// - PumpOpsError.unknownResponse
  40. func getResponse<T: MessageBody>(to message: PumpMessage, responseType: MessageType, repeatCount: Int, timeout: TimeInterval, retryCount: Int) throws -> T
  41. /// Sends a message to the pump, listening for a any known PumpMessage in reply
  42. ///
  43. /// - Parameters:
  44. /// - message: The message to send
  45. /// - repeatCount: The number of times to repeat the message before listening begins
  46. /// - timeout: The length of time to listen for a pump response
  47. /// - retryCount: The number of times to repeat the send & listen sequence
  48. /// - Returns: The message reply
  49. /// - Throws: An error describing a failure in the sending or receiving of a message:
  50. /// - PumpOpsError.couldNotDecode
  51. /// - PumpOpsError.crosstalk
  52. /// - PumpOpsError.deviceError
  53. /// - PumpOpsError.noResponse
  54. /// - PumpOpsError.unknownResponse
  55. func sendAndListen(_ message: PumpMessage, repeatCount: Int, timeout: TimeInterval, retryCount: Int) throws -> PumpMessage
  56. // Send a PumpMessage, and listens for a packet; used by callers who need to see RSSI
  57. /// - Throws:
  58. /// - PumpOpsError.noResponse
  59. /// - PumpOpsError.deviceError
  60. func sendAndListenForPacket(_ message: PumpMessage, repeatCount: Int, timeout: TimeInterval, retryCount: Int) throws -> RFPacket
  61. /// - Throws: PumpOpsError.deviceError
  62. func listenForPacket(onChannel channel: Int, timeout: TimeInterval) throws -> RFPacket?
  63. }