RVS_BTDriver_Device

class RVS_BTDriver_Device : NSObject, RVS_BTDriver_DeviceProtocol
extension RVS_BTDriver_Device: RVS_BTDriverCommunicatorTools

This is one “device,” which maps to a bluetooth “peripheral.”

Must derive from NSObject, for purposes of being a delegate.

Subscriber Support

Timeout Handling

  • This is a property that is set to a countdown timer when a timeout period begins. It should be canceled and niled, when not in use.

    Declaration

    Swift

    internal var timeoutTimer: Timer?
  • This is the timer timeout handler. When called, it will send an error to the delegate.

    This should be overridden, so that subclasses can provide meaninful data.

    Declaration

    Swift

    @objc
    internal func timeoutHandler(_ inTimer: Timer)

    Parameters

    inTimer

    The timer object calling this.

  • Begin the timeout ticker.

    Declaration

    Swift

    internal func startTimeout(_ inTimeoutInSeconds: TimeInterval)

    Parameters

    inTimeoutInSeconds

    A Double-precision floating-point number, containing the number of seconds to wait.

  • This stops the curret timeout, and restarts it.

    Declaration

    Swift

    internal func restartTimeout()
  • This stops the timeout ticker, and clears the decks.

    Declaration

    Swift

    internal func cancelTimeout()

RVS_BTDriver_Device Sequence-Style Support

  • This contains instances that have not yet passed a credit check.

    Declaration

    Swift

    internal var internal_holding_pen: [RVS_BTDriver_Service]
  • This contains the service list for this instance of the driver.

    Declaration

    Swift

    internal var internal_service_list: [RVS_BTDriver_Service]
  • This is a read-only accessor for the object that “owns,” this instance.

    Declaration

    Swift

    internal weak var internal_owner: RVS_BTDriver!
  • The interface for this device

    Declaration

    Swift

    internal var interface: RVS_BTDriver_InterfaceProtocol!
  • The vendor handler for this device

    Declaration

    Swift

    internal var vendor: RVS_BTDriver_VendorProtocol!
  • This is just here to give a handle to subclasses. This class does nothing.

    Declaration

    Swift

    internal func connect()
  • This is just here to give a handle to subclasses. This class does nothing.

    Declaration

    Swift

    internal func disconnect()
  • The device initializer

    Declaration

    Swift

    internal init(vendor inVendor: RVS_BTDriver_VendorProtocol!)

    Parameters

    vendor

    The vendor factory for the device. It can be nil (for testing purposes only).

  • This is a String, containing a unique ID for this peripheral.

    Declaration

    Swift

    public internal(set) var uuid: String!
  • A name for the device (may be the model name, may be something else).

    Declaration

    Swift

    public internal(set) var deviceName: String!
  • If the device has a Device Info Service with a model name, it is available here.

    Declaration

    Swift

    public internal(set) var modelName: String!
  • If the device has a Device Info Service with a manufacturer name, it is available here.

    Declaration

    Swift

    public internal(set) var manufacturerName: String!
  • If the device has a Device Info Service with a serial number, it is available here.

    Declaration

    Swift

    public internal(set) var serialNumber: String!
  • If the device has a Device Info Service with a hardware revision, it is available here.

    Declaration

    Swift

    public internal(set) var hardwareRevision: String!
  • If the device has a Device Info Service with a firmware revision, it is available here.

    Declaration

    Swift

    public internal(set) var firmwareRevision: String!
  • If the device has a Device Info Service with a software revision, it is available here.

    Declaration

    Swift

    public internal(set) var softwareRevision: String!
  • This is the device type. Default is .unTested

    Declaration

    Swift

    public internal(set) var deviceType: RVS_BTDriver_DeviceType
  • This is the public flag, determining whether or not the device is connected.

    Declaration

    Swift

    public var isConnected: Bool
  • This is true, if the device can be connected.

    Declaration

    Swift

    public internal(set) var canConnect: Bool
  • This refers to the driver instance that “owns” this device.

    Declaration

    Swift

    var owner: RVS_BTDriver! { get }
  • This displays a useful debug display of the device data.

    Declaration

    Swift

    override var description: String { get }
  • Notifies subscribers of a new service. This is defined here, so we can override.

    Declaration

    Swift

    internal func notifySubscribersOfNewService(_ inService: RVS_BTDriver_Service)

    Parameters

    inService

    The service to notify.

  • Notifies subscribers of a status update. This is defined here, so we can ovverride.

    Declaration

    Swift

    internal func notifySubscribersOfStatusUpdate()
  • This is declared here, so it can be overridden.

    This one does nothing. It should be overridden.

    Declaration

    Swift

    public func discoverServices()
  • Called to report that our holding pen is empty. We declare this here, so it can be overridden.

    Declaration

    Swift

    internal func reportCompletion()
  • This method should be called after all setup has been done, so that subclasses can do what needs doing. This base method does nothing.

    Declaration

    Swift

    internal func initialSetup()

Public Subscript

  • Simple “String Key” subscript, so we can treat the array as a dictionary.

    Declaration

    Swift

    public subscript(inStringKey: String) -> RVS_BTDriver_ServiceProtocol! { get }

    Parameters

    inStringKey

    A String, containing the unique UUID of the service we are looking for.

    Return Value

    The service, or nil, if not found.

Subscription Support Methods

  • Test to see if a subscriber is already subscribed.

    Declaration

    Swift

    public func isThisInstanceASubscriber(_ inSubscriber: RVS_BTDriver_DeviceSubscriberProtocol) -> Bool

    Parameters

    inSubscriber

    The subscriber to test.

    Return Value

    True, if the instance is subscribed.

  • Add an observer of the device.

    It should be noted that subscribers are held as strong references (if they are classes).

    Declaration

    Swift

    public func subscribe(_ inSubscriber: RVS_BTDriver_DeviceSubscriberProtocol)

    Parameters

    subscriber

    The instance to subscribe. Nothing is done, if we are already subscribed.

  • remove a subscriber from the list. Nothing happens if the subscriber is not already subscribed.

    Declaration

    Swift

    public func unsubscribe(_ inSubscriber: RVS_BTDriver_DeviceSubscriberProtocol)

    Parameters

    subscriber

    The instance to unsubscribe. Nothing is done, if we are not already subscribed.

Internal Instance Methods

  • This method will move a service from the holding pen to the main list.

    Declaration

    Swift

    internal func moveServiceFromHoldingPenToMainList(_ inService: RVS_BTDriver_Service)

    Parameters

    inService

    The service object to be moved.

  • This method will remove a service from the holding pen or the main list.

    Declaration

    Swift

    internal func removeThisService(_ inService: RVS_BTDriver_Service)

    Parameters

    inService

    The service object to be removed.

Communicator Support

  • This method will “kick the can” up to the driver, where the error will finally be sent to the delegate.

    Declaration

    Swift

    public func reportThisError(_ inError: RVS_BTDriver.Errors)

    Parameters

    inError

    The error to be sent to the subscribers, and up the chain.

Sequence-Style Support