documentation Transmitter

This commit is contained in:
Johan Degraeve 2019-02-08 22:22:13 +01:00
parent d5722c47f8
commit e67296f276
10 changed files with 227 additions and 108 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
Transmitter classes : https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/Transmitter/README.md
Calibration protocol : https://github.com/JohanDegraeve/xdripswift/tree/master/xdrip/Calibration

View File

@ -8,7 +8,7 @@ protocol CGMTransmitterDelegate:AnyObject {
/// transmitter reaches final connection status
///
/// needs to be called by deriving specific transmitter class, example in CGMG4xDripTransmitter, the function is called only when subscription to read characteristic has succeeded, whereas for other like MiaoMiao, the function is called as soon as real connection is made
func cgmTransmitterDidConnect()
func cgmTransmitterDidConnect(address:String?, name:String?)
/// transmitter did disconnect
func cgmTransmitterDidDisconnect()

View File

@ -50,7 +50,8 @@ final class CGMG4xDripTransmitter: BluetoothTransmitter, BluetoothTransmitterDel
// MARK: - BluetoothTransmitterDelegate functions
func centralManagerDidConnect() {
func centralManagerDidConnect(address:String?, name:String?) {
cgmTransmitterDelegate?.cgmTransmitterDidConnect(address: address, name: name)
}
func centralManagerDidFailToConnect(error: Error?) {
@ -65,9 +66,7 @@ final class CGMG4xDripTransmitter: BluetoothTransmitter, BluetoothTransmitterDel
}
func peripheralDidUpdateNotificationStateFor(characteristic: CBCharacteristic, error: Error?) {
os_log("in peripheralDidUpdateNotificationStateFor, it's an xdrip, assuming here full connect status", log: log, type: .info)
//In Spike and iosxdripreader, a device connection completed is transmitted in this case
cgmTransmitterDelegate?.cgmTransmitterDidConnect()
os_log("in peripheralDidUpdateNotificationStateFor", log: log, type: .info)
}
func peripheralDidUpdateValueFor(characteristic: CBCharacteristic, error: Error?) {

View File

@ -178,8 +178,8 @@ class CGMG5Transmitter:BluetoothTransmitter, BluetoothTransmitterDelegate, CGMTr
// MARK: BluetoothTransmitterDelegate functions
func centralManagerDidConnect() {
cgmTransmitterDelegate?.cgmTransmitterDidConnect()
func centralManagerDidConnect(address:String?, name:String?) {
cgmTransmitterDelegate?.cgmTransmitterDidConnect(address: address, name: name)
}
func centralManagerDidFailToConnect(error: Error?) {

View File

@ -78,8 +78,8 @@ class CGMMiaoMiaoTransmitter:BluetoothTransmitter, BluetoothTransmitterDelegate,
// MARK: - BluetoothTransmitterDelegate functions
func centralManagerDidConnect() {
cgmTransmitterDelegate?.cgmTransmitterDidConnect()
func centralManagerDidConnect(address:String?, name:String?) {
cgmTransmitterDelegate?.cgmTransmitterDidConnect(address: address, name: name)
}
func centralManagerDidFailToConnect(error: Error?) {

View File

@ -278,7 +278,7 @@ class BluetoothTransmitter: NSObject, CBCentralManagerDelegate, CBPeripheralDele
os_log("connected, will discover services", log: log, type: .info)
peripheral.discoverServices(services)
bluetoothTransmitterDelegate?.centralManagerDidConnect()
bluetoothTransmitterDelegate?.centralManagerDidConnect(address: deviceAddress, name: deviceName)
}
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {

View File

@ -8,7 +8,10 @@ import CoreBluetooth
protocol BluetoothTransmitterDelegate:AnyObject {
/// called when centralManager didConnect was called in BlueToothTransmitter class
/// the BlueToothTransmitter class handles the reconnect but the delegate class can for instance show the connection status to the user
func centralManagerDidConnect()
/// - parameters:
/// - address: the address that was received from the transmitter during connection phase
/// - name: the name that was received from the transmitter during connection phase
func centralManagerDidConnect(address:String?, name:String?)
/// called when centralManager didFailToConnect was called in BlueToothTransmitter class
/// the BlueToothTransmitter class handles will try to reconnect but the delegate class can for instance show the connection status to the user

View File

@ -19,7 +19,10 @@
</ul></li>
<li><a href="#protocolCGMTransmitter">conform to protocol CGMTransmitter</a>
<ul>
<li><a href="#canDetectNewSensorprotocol">canDetectNewSensor</a></li>
<li><a href="#canDetectNewSensor">canDetectNewSensor</a></li>
<li><a href="#address">address</a></li>
<li><a href="#name">name</a></li>
<li><a href="#startScanning">startScanning</a></li>
</ul></li>
<li><a href="#extendclassbuetoothtransmitter">extend class BluetoothTransmitter</a>
<ul>
@ -39,10 +42,11 @@
<li><a href="#didUpdateBluetoothState">didUpdateBluetoothState</a></li>
<li><a href="#newSensorDetected">newSensorDetected</a></li>
<li><a href="#sensorNotDetected">sensorNotDetected</a></li>
<li><a href="#newReadingsReceived">newReadingsReceived</a></li>
<li><a href="#cgmTransmitterInfoReceived">cgmTransmitterInfoReceived</a></li>
<li><a href="#transmitterNeedsPairing">transmitterNeedsPairing</a></li>
</ul></li>
</ul></li>
<li><a href="#implementtheprotocol">Implement the specific protocol</a>
<ul>
<li><a href="#functionsandpropertiesavailableintransmitterclasses">Functions and properties available in transmitter classes</a>
<ul>
<li><a href="#functionsinbluetoothtransmitterclasses">Functions in BluetoothTransmitter classes</a>
@ -53,21 +57,16 @@
<li><a href="#writeDataToPeripheral">writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool</a></li>
<li><a href="#setNotifyValue">setNotifyValue</a></li>
</ul></li>
<li><a href="#propertiesinbluetoothtransmitterclasses">Properties in BluetoothTransmitter classes</a>
<ul>
<li><a href="#address">address</a></li>
<li><a href="#name">name</a></li>
</ul></li>
<li><a href="#functionsincgmtransmitterclasses">Functions in CGM Transmitter classes</a>
<ul>
<li><a href="#canDetectNewSensor">canDetectNewSensor</a></li>
</ul></li>
</ul></li>
<li><a href="#availablecgmtransmitterclasses">Available CGM transmitter classes</a>
<ul>
<li><a href="#MiaoMiao">MiaoMiao</a></li>
<li><a href="#xDripG4">xDripG4</a></li>
<li><a href="#DexcomG5">Dexcom G5</a></li>
</ul></li>
<li><a href="#useatransmitterclass">Use a transmitter class</a></li>
</ul>
<h1><a name="summary"></a>Summary</h1>
@ -83,19 +82,23 @@ connect and reconnect, connect after app launch
<p>The protocol <strong>BluetoothTransmitterDelegate</strong> defines functions that allow to pass bluetooth activity information from the
BluetoothTransmitter class to a specific transmitter class. Example when a disconnect occurs, the BlueToothTransmitter class
handles the reconnect but the delegate class can for instance show the connection status to the user. It will be informed about
the connection status via the function centralManagerDidConnect in the BluetoothTransmitterDelegate</p>
the connection status via the function centralManagerDidConnect in the BluetoothTransmitterDelegate.</p>
<p><strong>CGMTransmitter</strong> defines functions that CGM transmitter classes need to implement.</p>
<p>The <strong>CGMTransmitter</strong> protocol defines functions that CGM transmitter classes need to implement.</p>
<p>The CGM transmitter communicates back to the caller via the <strong>CGMTransmitterDelegate</strong> protocol.<br>
Needs to be conformed to, for instance by a view controller, or manager, .. whatever<br>
This protocol allows passing information like new readings, sensor detected, and also connect/disconnect, bluetooth status change<br></p>
<p>Following specific transmitter classes exist:<br>
<strong>CGMG4xDripTransmitter</strong><br>
<strong>CGMG5Transmitter</strong><br></p>
<p>Following specific transmitter classes exist:<br></p>
<h1><a name="newtransmitters"></a>Steps for adding new (CGM) transmitter types</h1>
<ul>
<li><p><strong>CGMMiaoMiaoTransmitter</strong><br></p></li>
<li><p><strong>CGMG4xDripTransmitter</strong><br></p></li>
<li><p><strong>CGMG5Transmitter</strong><br></p></li>
</ul>
<h1><a name="newtransmitters"></a>Steps to adding new (CGM) transmitter types</h1>
<p>Every new type of bluetoothtransmitter needs to</p>
@ -112,7 +115,9 @@ This protocol allows passing information like new readings, sensor detected, and
<h2><a name="protocolbluetoothtransmitterdelegate"></a>conform to protocol BluetoothTransmitterDelegate</h2>
<p>The functions that not be implemented:</p>
<p>The protocol is used to pass back information from the BluetoothTransmitter class to the specific Transmitter class.</p>
<p>The functions that need to be implemented:</p>
<h3><a name="centralManagerdidconnect"><font color="purple">func</font> centralManagerDidConnect()</h3>
@ -153,6 +158,18 @@ For other types of transmitters there may be nothing to do.<br></p>
<p>can the cgm transmitter detect that a new sensor is placed ? Will return true only for Libre type of transmitters, eg MiaoMiao<br>
If it returns true the the transmitter should also use newSensorDetected</p>
<h3><a name="address"></a>address</h3>
<p>This function is already implemented in the parent class BluetoothTransmitter, there's no need to implement it.</p>
<h3><a name="name"></a>name</h3>
<p>This function is already implemented in the parent class BluetoothTransmitter, there's no need to implement it.</p>
<h3><a name="startScanning"></a>startScanning</h3>
<p>This function is already implemented in the parent class BluetoothTransmitter, there's no need to implement it.</p>
<h2><a name="extendclassbuetoothtransmitter"></a>extend class BluetoothTransmitter</h2>
<p>A new transmitter class needs to extend BluetoothTransmitter and</p>
@ -208,6 +225,8 @@ The advantage of scanning with advertisement UUID is that the app can also scan
<p>The new transmitter class needs to store a property of type CGMTransmitterDelegate<br>
This is used to pass back information to the controller<br></p>
<p>Define it as a weak var</p>
<p>Functions in CGMTransmitterDelegate:</p>
<h3><a name="cgmTransmitterDidConnect"></a>cgmTransmitterDidConnect</h3>
@ -234,63 +253,100 @@ This will typically be called in centralManagerDidUpdateState</p>
<p>When a sensor is not detected, only applicable to transmitters that have this functionality</p>
<h3><a name="newReadingsReceived"></a>newReadingsReceived</h3>
<h3><a name="cgmTransmitterInfoReceived"></a>cgmTransmitterInfoReceived</h3>
<p>This is the most important function, it passes new readings to the delegate</p>
<p>also battery info, sensor state, firmware &amp; hardware info if applicable</p>
<h3><a name="transmitterNeedsPairing"></a>transmitterNeedsPairing</h3>
<p>The transmitter needs pairing, app should give warning to user to keep the app in the foreground</p>
<h1><a name="functionsandpropertiesavailableintransmitterclasses"></a>Functions and properties available in transmitter classes</h1>
<h2><a name="implementtheprotocol"></a>Implement the transmitter protocol</h2>
<h2><a name="functionsinbluetoothtransmitterclasses"></a>Functions in BluetoothTransmitter classes</h2>
<p>The specific protocol needs to be implemented.</p>
<h3><a name="disconnect"></a>disconnect</h3>
<p>See as example already existing cgm transmitter classes.</p>
<p>All functions in the parent class can be overriden.</p>
<p>Following additional functions can be used :</p>
<h3><a name="functionsandpropertiesavailableintransmitterclasses"></a>Functions and properties available in transmitter classes</h3>
<h4><a name="functionsinbluetoothtransmitterclasses"></a>Functions in BluetoothTransmitter classes</h4>
<p>These functions should only be used by classes that extend the BluetoothTransmitter class.</p>
<h5><a name="disconnect"></a>disconnect</h5>
<p>will call centralManager.cancelPeripheralConnection</p>
<h3><a name="startScanning"></a>startScanning</h3>
<h5><a name="startScanning"></a>startScanning</h5>
<p>Will scan for the device.<br>
This should only be used the first time the app connects to a specific device and should not be done for transmittertypes that
start scanning at initialization<br>
//TODO: needs more clarification</p>
start scanning at initialization<br></p>
<h3><a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, type:CBCharacteristicWriteType) -> Bool</h3>
<h5><a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, type:CBCharacteristicWriteType) -> Bool</h5>
<p>calls peripheral.writeValue for characteristic CBUUID_WriteCharacteristic</p>
<p>calls peripheral.writeValue for characteristic CBUUID_WriteCharacteristic<br></p>
<h3><a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool</h3>
<p>Make sure that the parent class has initialized the parameter writeCharacteristic.<br>
This may not be the case of the deriving transmitter class has overriden the method func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)</p>
<h5><a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool</h5>
<p>calls peripheral.writeValue for characteristic that is given as argment : characteristicToWriteTo</p>
<h3><a name="setNotifyValuefunc"></a>setNotifyValue(_ enabled: Bool, for characteristic: CBCharacteristic)</h3>
<h5><a name="setNotifyValuefunc"></a>setNotifyValue(_ enabled: Bool, for characteristic: CBCharacteristic)</h5>
<p>calls setNotifyValue for characteristic with value enabled</p>
<h2><a name="propertiesinbluetoothtransmitterclasses"></a>Properties in BluetoothTransmitter classes</h2>
<h3><a name="address"></a>address</h3>
<p>the peripheral address, available after successfully connecting</p>
<h3><a name="name"></a>name</h3>
<p>the peripheral name, available after successfully connecting</p>
<h2><a name="functionsincgmtransmitterclasses"></a>Functions in CGM Transmitter classes</h2>
<h3><a name="canDetectNewSensor"></a>canDetectNewSensor</h3>
<p>can the cgm transmitter detect a new sensor ?</p>
<h1><a name="availablecgmtransmitterclasses"></a>Available CGM transmitter classes</h1>
<h2><a name="MiaoMiao"></a>MiaoMiao</h2>
<p>MiaoMiao transmitter is fully implemented</p>
<p>MiaoMiao transmitter is fully implemented<br>
class CGMMiaoMiaoTransmitter</p>
<h2><a name="xDripG4"></a>xDripG4</h2>
<p>xDripG4 transmitter is fully implemented</p>
<p>xDripG4 transmitter is fully implemented<br>
class CGMG4xDripTransmitter</p>
<h2><a name="DexcomG5"></a>Dexcom G5</h2>
<p>Dexcom G5 is implemented:</p>
<ul>
<li>no backfilling</li>
<li>not yet tested with transmitter on sensor</li>
</ul>
<h1><a name="useatransmitterclass"></a>Use a Transmitter class</h1>
<ul>
<li><p>conform to protocol CGMTransmitterDelegate</p></li>
<li><p>implement the functions in CGMTransmitterDelegate</p>
<ul>
<li><p>cgmTransmitterDidConnect : Called when the transmitter has connected. The function gives the name and address.<br>
Store the address in permanent storage, next time the transmitter is initialized, give it the address value<br>
It will ease the initial connect</p></li>
<li><p>cgmTransmitterDidDisconnect : To give info to the user that the transmitter has disconnected, if needed to give that info.</p></li>
<li><p>deviceDidUpdateBluetoothState : Gives the status of Bluetooth (on/off ..)<br>
Specifically useful if first scan still needs to occur. May not be useful at all.</p></li>
<li><p>newSensorDetected : Typically for MiaoMiao, can be used to automatically start the sensor, no need to ask the user to do this.</p></li>
<li><p>sensorNotDetected : Typically for MiaoMiao</p></li>
<li><p>func cgmTransmitterInfoReceived(glucoseData:inout [RawGlucoseData], transmitterBatteryInfo:TransmitterBatteryInfo?, sensorState:SensorState?, sensorTimeInMinutes:Int?, firmware:String?, hardware:String?)
Can contain lots of data, like new readings (raw readings), ...</p></li>
<li><p>cgmTransmitterNeedsPairing : Warn the user that app should stay in foreground</p></li>
</ul></li>
<li><p>Define a variable of type CGMTransmitter and initialize it with any of the transmitter classes</p>
<ul>
<li>In intializer, give it the address if known, or nil if not. If needed also transmitter id and pass it the CGMTransmitterDelegate</li>
</ul></li>
</ul>

View File

@ -14,7 +14,10 @@
- [peripheralDidUpdateNotificationStateFor](#peripheraldidupdatenotificationstatefor)
- [peripheralDidUpdateValueFor](#peripheraldidupatevaluefor)
- [conform to protocol CGMTransmitter](#protocolCGMTransmitter)
- [canDetectNewSensor](#canDetectNewSensorprotocol)
- [canDetectNewSensor](#canDetectNewSensor)
- [address](#address)
- [name](#name)
- [startScanning](#startScanning)
- [extend class BluetoothTransmitter](#extendclassbuetoothtransmitter)
- [initialize the super class BluetoothTransmitter](#initializebluetoothtransmitter)
- [BluetoothTransmitter.DeviceAddressAndName](#deviceaddressname)
@ -28,23 +31,21 @@
- [didUpdateBluetoothState](#didUpdateBluetoothState)
- [newSensorDetected](#newSensorDetected)
- [sensorNotDetected](#sensorNotDetected)
- [newReadingsReceived](#newReadingsReceived)
- [cgmTransmitterInfoReceived](#cgmTransmitterInfoReceived)
- [transmitterNeedsPairing](#transmitterNeedsPairing)
- [Functions and properties available in transmitter classes](#functionsandpropertiesavailableintransmitterclasses)
- [Functions in BluetoothTransmitter classes](#functionsinbluetoothtransmitterclasses)
- [disconnect](#disconnect)
- [startScanning](#startScanning)
- [writeDataToPeripheral(data:Data, type:CBCharacteristicWriteType) -> Bool](#writeDataToPeripheral)
- [writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool](#writeDataToPeripheral)
- [setNotifyValue](#setNotifyValue)
- [Properties in BluetoothTransmitter classes](#propertiesinbluetoothtransmitterclasses)
- [address](#address)
- [name](#name)
- [Functions in CGM Transmitter classes](#functionsincgmtransmitterclasses)
- [canDetectNewSensor](#canDetectNewSensor)
- [Implement the specific protocol](#implementtheprotocol)
- [Functions and properties available in transmitter classes](#functionsandpropertiesavailableintransmitterclasses)
- [Functions in BluetoothTransmitter classes](#functionsinbluetoothtransmitterclasses)
- [disconnect](#disconnect)
- [startScanning](#startScanning)
- [writeDataToPeripheral(data:Data, type:CBCharacteristicWriteType) -> Bool](#writeDataToPeripheral)
- [writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool](#writeDataToPeripheral)
- [setNotifyValue](#setNotifyValue)
- [Available CGM transmitter classes](#availablecgmtransmitterclasses)
- [MiaoMiao](#MiaoMiao)
- [xDripG4](#xDripG4)
- [Dexcom G5](#DexcomG5)
- [Use a transmitter class](#useatransmitterclass)
# <a name="summary"></a>Summary
@ -69,10 +70,15 @@ Needs to be conformed to, for instance by a view controller, or manager, .. what
This protocol allows passing information like new readings, sensor detected, and also connect/disconnect, bluetooth status change<br>
Following specific transmitter classes exist:<br>
**CGMG4xDripTransmitter**<br>
**CGMG5Transmitter**<br>
#<a name="newtransmitters"></a>Steps for adding new (CGM) transmitter types
* **CGMMiaoMiaoTransmitter**<br>
* **CGMG4xDripTransmitter**<br>
* **CGMG5Transmitter**<br>
# <a name="newtransmitters"></a>Steps to adding new (CGM) transmitter types
Every new type of bluetoothtransmitter needs to
@ -85,7 +91,9 @@ If it's a CGM transmitter (it could also be a bloodglucose meter that transmits
## <a name="protocolbluetoothtransmitterdelegate"></a>conform to protocol BluetoothTransmitterDelegate
The functions that not be implemented:
The protocol is used to pass back information from the BluetoothTransmitter class to the specific Transmitter class.
The functions that need to be implemented:
### <a name="centralManagerdidconnect"><font color="purple">func</font> centralManagerDidConnect()
@ -126,6 +134,18 @@ This will be the most important function, because it contains the data that need
can the cgm transmitter detect that a new sensor is placed ? Will return true only for Libre type of transmitters, eg MiaoMiao<br>
If it returns true the the transmitter should also use newSensorDetected
### <a name="address"></a>address
This function is already implemented in the parent class BluetoothTransmitter, there's no need to implement it.
### <a name="name"></a>name
This function is already implemented in the parent class BluetoothTransmitter, there's no need to implement it.
### <a name="startScanning"></a>startScanning
This function is already implemented in the parent class BluetoothTransmitter, there's no need to implement it.
## <a name="extendclassbuetoothtransmitter"></a>extend class BluetoothTransmitter
A new transmitter class needs to extend BluetoothTransmitter and
@ -179,6 +199,8 @@ write characteristic UUID
The new transmitter class needs to store a property of type CGMTransmitterDelegate<br>
This is used to pass back information to the controller<br>
Define it as a weak var
Functions in CGMTransmitterDelegate:
### <a name="cgmTransmitterDidConnect"></a>cgmTransmitterDidConnect
@ -205,64 +227,101 @@ When a new sensor is detected, only applicable to transmitters that have this fu
When a sensor is not detected, only applicable to transmitters that have this functionality
### <a name="newReadingsReceived"></a>newReadingsReceived
### <a name="cgmTransmitterInfoReceived"></a>cgmTransmitterInfoReceived
This is the most important function, it passes new readings to the delegate
also battery info, sensor state, firmware & hardware info if applicable
### <a name="transmitterNeedsPairing"></a>transmitterNeedsPairing
The transmitter needs pairing, app should give warning to user to keep the app in the foreground
# <a name="functionsandpropertiesavailableintransmitterclasses"></a>Functions and properties available in transmitter classes
## <a name="implementtheprotocol"></a>Implement the transmitter protocol
## <a name="functionsinbluetoothtransmitterclasses"></a>Functions in BluetoothTransmitter classes
The specific protocol needs to be implemented.
### <a name="disconnect"></a>disconnect
See as example already existing cgm transmitter classes.
All functions in the parent class can be overriden.
Following additional functions can be used :
### <a name="functionsandpropertiesavailableintransmitterclasses"></a>Functions and properties available in transmitter classes
#### <a name="functionsinbluetoothtransmitterclasses"></a>Functions in BluetoothTransmitter classes
These functions should only be used by classes that extend the BluetoothTransmitter class.
##### <a name="disconnect"></a>disconnect
will call centralManager.cancelPeripheralConnection
### <a name="startScanning"></a>startScanning
##### <a name="startScanning"></a>startScanning
Will scan for the device.<br>
This should only be used the first time the app connects to a specific device and should not be done for transmittertypes that
start scanning at initialization<br>
//TODO: needs more clarification
### <a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, type:CBCharacteristicWriteType) -> Bool
##### <a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, type:CBCharacteristicWriteType) -> Bool
calls peripheral.writeValue for characteristic CBUUID\_WriteCharacteristic
calls peripheral.writeValue for characteristic CBUUID\_WriteCharacteristic<br>
### <a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool
Make sure that the parent class has initialized the parameter writeCharacteristic.<br>
This may not be the case of the deriving transmitter class has overriden the method func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
##### <a name="writeDataToPeripheral"></a>writeDataToPeripheral(data:Data, characteristicToWriteTo:CBCharacteristic, type:CBCharacteristicWriteType) -> Bool
calls peripheral.writeValue for characteristic that is given as argment : characteristicToWriteTo
### <a name="setNotifyValuefunc"></a>setNotifyValue(_ enabled: Bool, for characteristic: CBCharacteristic)
##### <a name="setNotifyValuefunc"></a>setNotifyValue(_ enabled: Bool, for characteristic: CBCharacteristic)
calls setNotifyValue for characteristic with value enabled
## <a name="propertiesinbluetoothtransmitterclasses"></a>Properties in BluetoothTransmitter classes
### <a name="address"></a>address
the peripheral address, available after successfully connecting
### <a name="name"></a>name
the peripheral name, available after successfully connecting
## <a name="functionsincgmtransmitterclasses"></a>Functions in CGM Transmitter classes
### <a name="canDetectNewSensor"></a>canDetectNewSensor
can the cgm transmitter detect a new sensor ?
# <a name="availablecgmtransmitterclasses"></a>Available CGM transmitter classes
## <a name="MiaoMiao"></a>MiaoMiao
MiaoMiao transmitter is fully implemented
MiaoMiao transmitter is fully implemented<br>
class CGMMiaoMiaoTransmitter
## <a name="xDripG4"></a>xDripG4
xDripG4 transmitter is fully implemented
xDripG4 transmitter is fully implemented<br>
class CGMG4xDripTransmitter
## <a name="DexcomG5"></a>Dexcom G5
Dexcom G5 is implemented:
* no backfilling
* not yet tested with transmitter on sensor
# <a name="useatransmitterclass"></a>Use a Transmitter class
* conform to protocol CGMTransmitterDelegate
* implement the functions in CGMTransmitterDelegate
* cgmTransmitterDidConnect : Called when the transmitter has connected. The function gives the name and address.<br>
Store the address in permanent storage, next time the transmitter is initialized, give it the address value<br>
It will ease the initial connect
* cgmTransmitterDidDisconnect : To give info to the user that the transmitter has disconnected, if needed to give that info.
* deviceDidUpdateBluetoothState : Gives the status of Bluetooth (on/off ..)<br>
Specifically useful if first scan still needs to occur. May not be useful at all.
* newSensorDetected : Typically for MiaoMiao, can be used to automatically start the sensor, no need to ask the user to do this.
* sensorNotDetected : Typically for MiaoMiao
* func cgmTransmitterInfoReceived(glucoseData:inout [RawGlucoseData], transmitterBatteryInfo:TransmitterBatteryInfo?, sensorState:SensorState?, sensorTimeInMinutes:Int?, firmware:String?, hardware:String?)
Can contain lots of data, like new readings (raw readings), ...
* cgmTransmitterNeedsPairing : Warn the user that app should stay in foreground
* Define a variable of type CGMTransmitter and initialize it with any of the transmitter classes
* In intializer, give it the address if known, or nil if not. If needed also transmitter id and pass it the CGMTransmitterDelegate

View File

@ -31,7 +31,6 @@ final class RootHomeViewController: UIViewController, CGMTransmitterDelegate {
// Setup View
setupView()
//let test:CGMG4xDripTransmitter = CGMG4xDripTransmitter(addressAndName: CGMG4xDripTransmitter.G4DeviceAddressAndName.notYetConnected)
log = OSLog(subsystem: Constants.Log.subSystem, category: Constants.Log.categoryFirstView)
os_log("firstview viewdidload", log: log!, type: .info)
@ -49,8 +48,8 @@ final class RootHomeViewController: UIViewController, CGMTransmitterDelegate {
address = storedAddress
}
//test = CGMMiaoMiaoTransmitter(address: address, delegate: self, timeStampLastBgReading: timeStampLastBgReading)
//test = CGMG4xDripTransmitter(address: address, transmitterID: "6LSDU", delegate:self)
test = CGMG5Transmitter(address: address, transmitterID: "406QWK", delegate: self)
test = CGMG4xDripTransmitter(address: address, transmitterID: "6LSDU", delegate:self)
//test = CGMG5Transmitter(address: address, transmitterID: "406QWK", delegate: self)
UNUserNotificationCenter.current().delegate = self
@ -358,8 +357,8 @@ extension RootHomeViewController: UNUserNotificationCenterDelegate {
// MARK: - CGMTransmitter protocol functions
func cgmTransmitterDidConnect() {
if let address = test?.address(), let name = test?.name() {
func cgmTransmitterDidConnect(address:String?, name:String?) {
if let address = address, let name = name {
self.address = address
self.name = name
UserDefaults.standard.bluetoothDeviceAddress = address