RVS_BTDriver_Device_OBD

class RVS_BTDriver_Device_OBD : RVS_BTDriver_Device_BLE, RVS_BTDriver_OBD_DeviceProtocol

This is a specialization of the device for OBD Devices.

OBD devices handle communications in a single-threaded manner, so we use a queue to hold transactions. As a transaction completes, the next one is sent out.

This allows us to match responses with commands, so we keep the transactions in a struct that is sent to the delegate, so the delegate gets to have access to the sent command, as well as the response.

  • This is how many seconds we wait for a command to finish.

    Declaration

    Swift

    internal static let timeoutInterval: TimeInterval
  • This contains the staged transactions in a queue.

    Declaration

    Swift

    internal var transactionQueue: RVS_FIFOQueue<RVS_BTDriver_OBD_Device_TransactionStruct>
  • This contains the current transaction. It may be nil, for no transaction.

    Declaration

    Swift

    internal var currentTransaction: RVS_BTDriver_OBD_Device_TransactionStruct!
  • This is a weak reference to the instance delegate.

    Declaration

    Swift

    public weak var delegate: RVS_BTDriver_OBD_DeviceDelegate!
  • This property is one that the driver uses to receive responses from the OBD unit.

    Declaration

    Swift

    public var readProperty: RVS_BTDriver_PropertyProtocol!
  • This property is one that the driver uses to send commands to the OBD unit.

    Declaration

    Swift

    public var writeProperty: RVS_BTDriver_PropertyProtocol!
  • This method will send a command to the OBD unit. This variant of the method will fectch any command in the _currentTransaction property. If none, then nothing happens.

    Declaration

    Swift

    internal func sendCommand()
  • This method will send a command to the OBD unit.

    Declaration

    Swift

    public func sendCommand(_ inCommandString: String, rawCommand inRawCommand: String)

    Parameters

    inCommandString

    The String for the command.

    rawCommand

    The command String, without data or the appended CRLF.

  • Called to send the data to the delegate.

    Declaration

    Swift

    internal func receiveCommandData(_ inData: Data)

    Parameters

    inData

    The data received.

  • This returns an easy-to-display description string

    Declaration

    Swift

    public override var description: String { get }
  • This cancels all I/O, and flushes the transaction queue. You may get a response from the last transaction, but it will not be sent to the delegate.

    Declaration

    Swift

    public func cancelTransactions()
  • 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

    override internal func timeoutHandler(_ inTimer: Timer)

    Parameters

    inTimer

    The timer object calling this.

  • Called if there was a disconnection, after initializing. We use this to cancel any open timeout, and re-queue any incomplete transaction.

    Declaration

    Swift

    internal override func disconnectedPostInit()
  • Called if there was a connection, after initializing. If we had a command in the queue, we retry it.

    Declaration

    Swift

    internal override func connectedPostInit()

Device Delegate Handler

  • Declaration

    Swift

    internal override func peripheral(_ inPeripheral: CBPeripheral, didUpdateValueFor inCharacteristic: CBCharacteristic, error inError: Error?)

    Parameters

    inPeripheral

    The peripheral that owns this service.

    didUpdateValueFor

    The characteristic that was updated.

    error

    Any error that may have occurred. It can be nil.