BGXDevice

The BGXDevice class is used to represent the BGX device. More...

Classes

protocol  <BGXSerialDelegate>
 BGXSerialDelegate protocol. More...
 
protocol  <BGXDeviceDelegate>
 BGXDeviceDelegate protocol is used to be notified of state changes and device level events. More...
 
class  BGXDevice
 

Enumerations

enum  DeviceState : NSUInteger {
  Interrogating, Disconnected, Connecting, Connected,
  Disconnecting
}
 DeviceState values. More...
 
enum  BusMode {
  UNKNOWN_MODE, STREAM_MODE, LOCAL_COMMAND_MODE, REMOTE_COMMAND_MODE,
  UNSUPPORTED_MODE
}
 Values of the bus mode. More...
 

Detailed Description

The BGXDevice class is used to represent the BGX device.

It contains a group of properties as well as methods used to perform appropriate actions on a BGXDevice.

Supports two delegates, deviceDelegate and serialDelegate, as well as KVO.


Class Documentation

◆ BGXSerialDelegate-p

protocol BGXSerialDelegate-p

BGXSerialDelegate protocol.

The BGXSerialDelegate is used to perform serial read/write operations with the BGX.

Instance Methods

(void) - busModeChanged:forDevice:
 Detect bus mode changes. More...
 
(void) - dataRead:forDevice:
 Delegate method is called when data is received. More...
 
(void) - dataWrittenForDevice:
 Delegate method used to advise that the data has been written. More...
 

Method Documentation

◆ busModeChanged:forDevice:()

- (void) busModeChanged: (BusMode newBusMode
forDevice: (BGXDevice *)  device 
required

Detect bus mode changes.

Delegate method called when the bus mode changes or is read. If you call the BGXpressManager method -(BOOL)readBusMode, this delegate will be called with the bus mode that was read whether or not it was different than the previous bus mode.

Parameters
newBusModethe new bus mode for the connection

◆ dataRead:forDevice:()

- (void) dataRead: (NSData *)  newData
forDevice: (BGXDevice *)  device 
required

Delegate method is called when data is received.

Parameters
newDataupdated values

◆ dataWrittenForDevice:()

- (void) dataWrittenForDevice: (BGXDevice *)  device
required

Delegate method used to advise that the data has been written.

◆ BGXDeviceDelegate-p

protocol BGXDeviceDelegate-p

BGXDeviceDelegate protocol is used to be notified of state changes and device level events.

Instance Methods

(void) - connectionTimeoutForDevice:
 The device was connecting but the connection operation failed to finish within the timeout period. More...
 
(void) - stateChangedForDevice:
 The value of the deviceState variable changed. More...
 
(void) - rssiChangedForDevice:
 The RSSI value changed for the device. More...
 

Method Documentation

◆ connectionTimeoutForDevice:()

- (void) connectionTimeoutForDevice: (BGXDevice *)  device
optional

The device was connecting but the connection operation failed to finish within the timeout period.

The device is probably disconnected as a result.

Parameters
deviceThe device whose connection timed out.

◆ stateChangedForDevice:()

- (void) stateChangedForDevice: (BGXDevice *)  device
optional

The value of the deviceState variable changed.

This could mean that the device connected, disconencted, etc. The typical flow is: Connect operation: Disconnected -> Connecting -> Interrograting -> Connected.

Disconnect operation: Connected -> Disconnecting -> Disconnected

Parameters
deviceThe device whose state changed.

◆ rssiChangedForDevice:()

- (void) rssiChangedForDevice: (BGXDevice *)  device
optional

The RSSI value changed for the device.

Parameters
deviceThe device for which the RSSI changed.

◆ BGXDevice

class BGXDevice

Inherits NSObject, and <CBPeripheralDelegate>.

Instance Methods

(BOOL) - connect
 Method to connect to the device. More...
 
(BOOL) - disconnect
 Method to disconnect to the device. More...
 
(BOOL) - readBusMode
 Method used to read the BusMode for a device eg Stream, Local or Remote commands. More...
 
(BOOL) - writeBusMode:
 Method used to write new bus mode for device. More...
 
(BOOL) - canWrite
 Method to see if you can write to the device. More...
 
(BOOL) - writeData:
 Method used to write data to a device. More...
 
(BOOL) - writeString:
 Method used to write a string to device. More...
 
(BOOL) - sendCommand:args:
 Method used to send commands to the device. More...
 
(nullable NSString *) - device_unique_id
 Returns the device unique id. More...
 
(CBPeripheral *) - peripheral
 Access to the CBPeripheral. More...
 

Class Methods

(NSString *) + nameForDeviceState:
 Printable name for a device state value. More...
 

Protected Attributes

DeviceState _deviceState
 
BusMode _busMode
 

Properties

NSObject< BGXDeviceDelegate > * deviceDelegate
 
NSObject< BGXSerialDelegate > * serialDelegate
 
NSString * name
 
NSNumber * rssi
 
NSUUID * identifier
 
DeviceState deviceState
 
BusMode busMode
 
NSString * modelNumber
 
NSString * firmwareRevision
 
NSString * bootloaderVersion
 
BOOL writeWithResponse
 YES = Writes occur using CBCharacteristicWriteWithResponse NO = Writes occur using CBCharacteristicWriteWithoutResponse = YES. More...
 

Method Documentation

◆ connect()

- (BOOL) connect

Method to connect to the device.

Operation happens asynchronously. Observe the deviceState property to determine the outcome of the operation.

Returns
BOOL value to indicate if the connection operation started successfully.

◆ disconnect()

- (BOOL) disconnect

Method to disconnect to the device.

Operation happens asynchronously. Observe the deviceState property to determine the outcome of the operation.

Returns
BOOL value to indicate if the disconnection operation started successfully.

◆ readBusMode()

- (BOOL) readBusMode

Method used to read the BusMode for a device eg Stream, Local or Remote commands.

This operation occurs asynchronously. Observe the changes to the busMode property.

Returns
BOOL value, YES to indicate that the read operation could be initiated. NO if the read operation could not be started.

◆ writeBusMode:()

- (BOOL) writeBusMode: (BusMode newBusMode

Method used to write new bus mode for device.

Operation occurs asynchronously.

Parameters
newBusModeThe new BusMode for the device
Returns
BOOL value, YES if BusMode write operation could be started.

◆ canWrite()

- (BOOL) canWrite

Method to see if you can write to the device.

Returns
BOOL value, YES if device is connected and no data waiting to be written to the device, else NO.

◆ writeData:()

- (BOOL) writeData: (NSData *)  data

Method used to write data to a device.

Parameters
dataData to be writted to device.
Returns
BOOL value advising if the data has been written to the device or not.

◆ writeString:()

- (BOOL) writeString: (NSString *)  string

Method used to write a string to device.

Parameters
stringString value to be writted to device.
Returns
BOOL value advising if the string has been written to the device or not.

◆ sendCommand:args:()

- (BOOL) sendCommand: (NSString *)  command
args: (NSString *)  args 

Method used to send commands to the device.

Parameters
commandCommand
argsArguments
Returns
BOOL value advising if the command has been written to the device or not.

◆ device_unique_id()

- (nullable NSString *) device_unique_id

Returns the device unique id.

Returns
NSString with the unique id of the device. Nil on error.

◆ nameForDeviceState:()

+ (NSString *) nameForDeviceState: (DeviceState ds

Printable name for a device state value.

◆ peripheral()

- (CBPeripheral *) peripheral

Access to the CBPeripheral.

Member Data Documentation

◆ _deviceState

- (DeviceState) _deviceState
protected

◆ _busMode

- (BusMode) _busMode
protected

Property Documentation

◆ deviceDelegate

- (NSObject<BGXDeviceDelegate>*) deviceDelegate
readwritenonatomicweak

◆ serialDelegate

- (NSObject<BGXSerialDelegate>*) serialDelegate
readwritenonatomicweak

◆ name

- (NSString*) name
readnonatomicassign

◆ rssi

- (NSNumber*) rssi
readnonatomicassign

◆ identifier

- (NSUUID*) identifier
readnonatomicassign

◆ deviceState

- (DeviceState) deviceState
readnonatomicassign

◆ busMode

- (BusMode) busMode
readnonatomicassign

◆ modelNumber

- (NSString*) modelNumber
readwritenonatomicstrong

◆ firmwareRevision

- (NSString*) firmwareRevision
readwritenonatomicstrong

◆ bootloaderVersion

- (NSString*) bootloaderVersion
readwritenonatomicstrong

◆ writeWithResponse

- (BOOL) writeWithResponse
readwritenonatomicassign

YES = Writes occur using CBCharacteristicWriteWithResponse NO = Writes occur using CBCharacteristicWriteWithoutResponse = YES.

Enumeration Type Documentation

◆ DeviceState

enum DeviceState : NSUInteger

DeviceState values.

Enumerator
Interrogating 

The BGXDevice has connected and bluetooth services and characteristics are being discovered.

Disconnected 

The BGXDevice is not connected (to this iOS device).

Connecting 

The BGXDevice is in the process of connecting.

Connected 

The BGXDevice is connected.

Disconnecting 

The BGXDevice is in the process of disconnecting.

◆ BusMode

enum BusMode

Values of the bus mode.

Enumerator
UNKNOWN_MODE 

an invalid mode used to indicate that the

mode has not been determined

STREAM_MODE 

send and receive serial data to the device to

which the BGX is connected

LOCAL_COMMAND_MODE 

data received over the serial lines is

processed as a command by the BGX and results returned over the serial lines

REMOTE_COMMAND_MODE 

data received over bluetooth is processed as

a command by the BGX and results returned over bluetooth

UNSUPPORTED_MODE 

an invalid mode state