watlaa master connect working, receives packages
This commit is contained in:
parent
4a95c2c50d
commit
14fe568e65
|
@ -68,6 +68,7 @@
|
|||
F830992623C32251005741DF /* WatlaaMasterBluetoothPeripheralViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F830992523C32251005741DF /* WatlaaMasterBluetoothPeripheralViewModel.swift */; };
|
||||
F830992823C32A13005741DF /* TextsWatlaaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F830992723C32A13005741DF /* TextsWatlaaView.swift */; };
|
||||
F830992A23C32A98005741DF /* WatlaaView.strings in Resources */ = {isa = PBXBuildFile; fileRef = F830992923C32A98005741DF /* WatlaaView.strings */; };
|
||||
F830992C23C694F4005741DF /* WatlaaAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F830992B23C694F4005741DF /* WatlaaAccessor.swift */; };
|
||||
F856CE5B22EDC8E50083E436 /* ConstantsBluetoothPairing.swift in Sources */ = {isa = PBXBuildFile; fileRef = F856CE5A22EDC8E50083E436 /* ConstantsBluetoothPairing.swift */; };
|
||||
F85DC2ED21CFE2F500B9F74A /* BgReading+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85DC2E721CFE2F500B9F74A /* BgReading+CoreDataProperties.swift */; };
|
||||
F85DC2EF21CFE2F500B9F74A /* Sensor+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85DC2E921CFE2F500B9F74A /* Sensor+CoreDataProperties.swift */; };
|
||||
|
@ -326,6 +327,7 @@
|
|||
F830992523C32251005741DF /* WatlaaMasterBluetoothPeripheralViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatlaaMasterBluetoothPeripheralViewModel.swift; sourceTree = "<group>"; };
|
||||
F830992723C32A13005741DF /* TextsWatlaaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextsWatlaaView.swift; sourceTree = "<group>"; };
|
||||
F830992923C32A98005741DF /* WatlaaView.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = WatlaaView.strings; sourceTree = "<group>"; };
|
||||
F830992B23C694F4005741DF /* WatlaaAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatlaaAccessor.swift; sourceTree = "<group>"; };
|
||||
F846CDD523046BAC00DCF016 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/SettingsViews.strings"; sourceTree = "<group>"; };
|
||||
F846CDD623046BAE00DCF016 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/SettingsViews.strings; sourceTree = "<group>"; };
|
||||
F856CE5A22EDC8E50083E436 /* ConstantsBluetoothPairing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsBluetoothPairing.swift; sourceTree = "<group>"; };
|
||||
|
@ -1105,6 +1107,7 @@
|
|||
F8B3A819227DEC92004BA588 /* README.md */,
|
||||
F8B3A815227DEC91004BA588 /* SensorsAccessor.swift */,
|
||||
F8F6226F233AA3B200BE8796 /* M5StackAccessor.swift */,
|
||||
F830992B23C694F4005741DF /* WatlaaAccessor.swift */,
|
||||
);
|
||||
path = accessors;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1958,6 +1961,7 @@
|
|||
F8B3A84C227F090E004BA588 /* SettingsViewController.swift in Sources */,
|
||||
F8EEDD5222FECE3800D2D610 /* ConstantsLibreOOP.swift in Sources */,
|
||||
F8F9720B23A5915900C3F17D /* SensorDataRxMessage.swift in Sources */,
|
||||
F830992C23C694F4005741DF /* WatlaaAccessor.swift in Sources */,
|
||||
F8AC426021ADEBD60078C348 /* RootViewController.swift in Sources */,
|
||||
F8B3A78B225D473D004BA588 /* UIAlertController.swift in Sources */,
|
||||
F8F9720E23A5915900C3F17D /* AuthRequestRxMessage.swift in Sources */,
|
||||
|
@ -2411,7 +2415,7 @@
|
|||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 3009;
|
||||
DEVELOPMENT_TEAM = 8DKSZ5HNLB;
|
||||
DEVELOPMENT_TEAM = RNX44PP998;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/xdrip/Supporting Files/Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
|
@ -2419,7 +2423,7 @@
|
|||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 3.6.1;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.johandegraeve.iosxdripreader;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.johandegraeve.xdripswift;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "xdrip/xdrip-Bridging-Header.h";
|
||||
|
@ -2439,7 +2443,7 @@
|
|||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 3009;
|
||||
DEVELOPMENT_TEAM = 8DKSZ5HNLB;
|
||||
DEVELOPMENT_TEAM = RNX44PP998;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/xdrip/Supporting Files/Info.plist";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
|
@ -2447,7 +2451,7 @@
|
|||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 3.6.1;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.johandegraeve.iosxdripreader;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.johandegraeve.xdripswift;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "xdrip/xdrip-Bridging-Header.h";
|
||||
|
|
|
@ -442,6 +442,7 @@ class BluetoothTransmitter: NSObject, CBCentralManagerDelegate, CBPeripheralDele
|
|||
timeStampLastStatusUpdate = Date()
|
||||
|
||||
trace("didDiscoverServices for peripheral with name %{public}@", log: log, type: .info, deviceName ?? "'unknown'")
|
||||
|
||||
if let error = error {
|
||||
trace(" didDiscoverServices error: %{public}@", log: log, type: .error , "\(error.localizedDescription)")
|
||||
}
|
||||
|
|
|
@ -101,6 +101,8 @@ class WatlaaBluetoothTransmitterMaster: BluetoothTransmitter {
|
|||
|
||||
private func handleUpdateValueFor_RawData_Characteristic(value: Data) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private func handleUpdateValueFor_BridgeConnectionStatus_Characteristic(value: Data) {
|
||||
|
|
|
@ -29,7 +29,7 @@ enum ConstantsLog {
|
|||
static let categoryCGMG5 = "CGMG5"
|
||||
|
||||
/// watlaa
|
||||
static let categoryWatlaa = "watlaa"
|
||||
static let categoryWatlaa = "Watlaa"
|
||||
|
||||
/// GNSEntry
|
||||
static let categoryCGMGNSEntry = "CGMGNSEntry"
|
||||
|
@ -58,6 +58,9 @@ enum ConstantsLog {
|
|||
/// application data for M5Stack
|
||||
static let categoryApplicationDataM5Stacks = "ApplicationDataM5Stacks"
|
||||
|
||||
/// application data for M5Stack
|
||||
static let categoryApplicationDataWatlaa = "ApplicationDataWatlaa"
|
||||
|
||||
/// application for for M5StackName
|
||||
static let categoryApplicationDataM5StackNames = "ApplicationDataM5StackNames"
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import Foundation
|
||||
import os
|
||||
import CoreData
|
||||
|
||||
class WatlaaAccessor {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
/// CoreDataManager to use
|
||||
private let coreDataManager:CoreDataManager
|
||||
|
||||
/// for logging
|
||||
private var log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryApplicationDataWatlaa)
|
||||
|
||||
// MARK: - initializer
|
||||
|
||||
init(coreDataManager:CoreDataManager) {
|
||||
self.coreDataManager = coreDataManager
|
||||
}
|
||||
|
||||
// MARK: Public functions
|
||||
|
||||
/// gets all Watlaa instances from coredata
|
||||
func getWatlaas() -> [Watlaa] {
|
||||
|
||||
// create fetchRequest to get watlaa's as Watlaa classes
|
||||
let watlaaFetchRequest: NSFetchRequest<Watlaa> = Watlaa.fetchRequest()
|
||||
|
||||
// fetch the Watlaa's
|
||||
var watlaaArray = [Watlaa]()
|
||||
coreDataManager.mainManagedObjectContext.performAndWait {
|
||||
do {
|
||||
// Execute Fetch Request
|
||||
watlaaArray = try watlaaFetchRequest.execute()
|
||||
} catch {
|
||||
let fetchError = error as NSError
|
||||
trace("in getWatlaas, Unable to Execute Watlaas Fetch Request : %{public}@", log: self.log, type: .error, fetchError.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
return watlaaArray
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,7 @@ public class Watlaa: NSManagedObject {
|
|||
/// - rotation is internally stored as Int32, actual value should always be between 0 and 360 so UInt16 as parameter is sufficient.
|
||||
init(address: String, name: String, alias: String?, nsManagedObjectContext:NSManagedObjectContext) {
|
||||
|
||||
let entity = NSEntityDescription.entity(forEntityName: "M5Stack", in: nsManagedObjectContext)!
|
||||
let entity = NSEntityDescription.entity(forEntityName: "Watlaa", in: nsManagedObjectContext)!
|
||||
|
||||
super.init(entity: entity, insertInto: nsManagedObjectContext)
|
||||
|
||||
|
@ -22,4 +22,8 @@ public class Watlaa: NSManagedObject {
|
|||
|
||||
}
|
||||
|
||||
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
|
||||
super.init(entity: entity, insertInto: context)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ class BluetoothPeripheralManager: NSObject {
|
|||
/// reference to BgReadingsAccessor
|
||||
private var bgReadingsAccessor: BgReadingsAccessor
|
||||
|
||||
/// reference to watlaaAccessor
|
||||
private var watlaaAccessor: WatlaaAccessor
|
||||
|
||||
/// if scan is called, and a connection is successfully made to a new device, then a new M5Stack must be created, and this function will be called. It is owned by the UIViewController that calls the scan function
|
||||
private var callBackAfterDiscoveringDevice: ((BluetoothPeripheral) -> Void)?
|
||||
|
||||
|
@ -48,37 +51,84 @@ class BluetoothPeripheralManager: NSObject {
|
|||
self.coreDataManager = coreDataManager
|
||||
self.m5StackAccessor = M5StackAccessor(coreDataManager: coreDataManager)
|
||||
self.bgReadingsAccessor = BgReadingsAccessor(coreDataManager: coreDataManager)
|
||||
self.watlaaAccessor = WatlaaAccessor(coreDataManager: coreDataManager)
|
||||
self.cgmTransmitterDelegate = cgmTransmitterDelegate
|
||||
|
||||
super.init()
|
||||
|
||||
// initialize m5Stacks
|
||||
let m5Stacks = m5StackAccessor.getM5Stacks()
|
||||
for m5Stack in m5Stacks {
|
||||
// need to initialize all types of bluetoothperipheral
|
||||
// using enum here to make sure future types are not forgotten
|
||||
for bluetoothPeripheralType in BluetoothPeripheralType.allCases {
|
||||
|
||||
// add it to the list of bluetoothPeripherals
|
||||
bluetoothPeripherals.append(m5Stack)
|
||||
|
||||
if m5Stack.shouldconnect {
|
||||
switch bluetoothPeripheralType {
|
||||
|
||||
case .M5StickCType:
|
||||
// no seperate handling needed for M5StickC because M5StickC is stored in coredata as M5Stack objecct, so it will be handled when going through case M5StackType
|
||||
break
|
||||
|
||||
// create an instance of M5StackBluetoothTransmitter, M5StackBluetoothTransmitter will automatically try to connect to the M5Stack with the address that is stored in m5Stack
|
||||
// add it to the array of bluetoothTransmitters
|
||||
bluetoothTransmitters.append(M5StackBluetoothTransmitter(address: m5Stack.address, name: m5Stack.name, delegate: self, blePassword: m5Stack.blepassword, bluetoothPeripheralType: m5Stack.isM5StickC ? .M5StickCType : .M5StackType))
|
||||
case .M5StackType:
|
||||
|
||||
} else {
|
||||
// initialize m5Stacks
|
||||
let m5Stacks = m5StackAccessor.getM5Stacks()
|
||||
for m5Stack in m5Stacks {
|
||||
|
||||
// add it to the list of bluetoothPeripherals
|
||||
bluetoothPeripherals.append(m5Stack)
|
||||
|
||||
if m5Stack.shouldconnect {
|
||||
|
||||
// create an instance of M5StackBluetoothTransmitter, M5StackBluetoothTransmitter will automatically try to connect to the M5Stack with the address that is stored in m5Stack
|
||||
// add it to the array of bluetoothTransmitters
|
||||
bluetoothTransmitters.append(M5StackBluetoothTransmitter(address: m5Stack.address, name: m5Stack.name, delegate: self, blePassword: m5Stack.blepassword, bluetoothPeripheralType: m5Stack.isM5StickC ? .M5StickCType : .M5StackType))
|
||||
|
||||
} else {
|
||||
|
||||
// shouldn't connect, so don't create an instance of M5StackBluetoothTransmitter
|
||||
// but append a nil element
|
||||
bluetoothTransmitters.append(nil)
|
||||
|
||||
}
|
||||
|
||||
// each time the app launches, we will send the parameters to all BluetoothPeripherals
|
||||
m5Stack.parameterUpdateNeededAtNextConnect()
|
||||
|
||||
}
|
||||
|
||||
// shouldn't connect, so don't create an instance of M5StackBluetoothTransmitter
|
||||
// but append a nil element
|
||||
bluetoothTransmitters.append(nil)
|
||||
|
||||
|
||||
case .watlaaMaster:
|
||||
|
||||
// initialize watlaa's
|
||||
let watlaas = watlaaAccessor.getWatlaas()
|
||||
for watlaa in watlaas {
|
||||
|
||||
// add it to the list of bluetoothPeripherals
|
||||
bluetoothPeripherals.append(watlaa)
|
||||
|
||||
if watlaa.shouldconnect {
|
||||
|
||||
// create an instance of WatlaaBluetoothTransmitter, WatlaaBluetoothTransmitter will automatically try to connect to the watlaa with the address that is stored in watlaa
|
||||
// add it to the array of bluetoothTransmitters
|
||||
bluetoothTransmitters.append(WatlaaBluetoothTransmitterMaster(address: watlaa.address, name: watlaa.name, cgmTransmitterDelegate: cgmTransmitterDelegate, bluetoothTransmitterDelegate: self, bluetoothPeripheralType: .watlaaMaster))
|
||||
|
||||
} else {
|
||||
|
||||
// shouldn't connect, so don't create an instance of M5StackBluetoothTransmitter
|
||||
// but append a nil element
|
||||
bluetoothTransmitters.append(nil)
|
||||
|
||||
}
|
||||
|
||||
// each time the app launches, we will send the parameters to all BluetoothPeripherals
|
||||
watlaa.parameterUpdateNeededAtNextConnect()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// each time the app launches, we will send the parameters to all BluetoothPeripherals
|
||||
m5Stack.parameterUpdateNeededAtNextConnect()
|
||||
|
||||
}
|
||||
|
||||
// when user changes M5Stack related settings, then the transmitter need to get that info
|
||||
// when user changes any of the buetooth peripheral related settings, that need to be sent to the transmitter
|
||||
addObservers()
|
||||
|
||||
}
|
||||
|
@ -151,7 +201,6 @@ class BluetoothPeripheralManager: NSObject {
|
|||
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.nightScoutUrl.rawValue, options: .new, context: nil)
|
||||
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.nightScoutAPIKey.rawValue, options: .new, context: nil)
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// disconnect from bluetoothPeripheral - and don't reconnect - set shouldconnect to false
|
||||
|
@ -559,6 +608,8 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
|
|||
self.callBackAfterDiscoveringDevice = nil
|
||||
}
|
||||
|
||||
// assign tempBlueToothTransmitterWhileScanningForNewBluetoothPeripheral to nil here
|
||||
self.tempBlueToothTransmitterWhileScanningForNewBluetoothPeripheral = nil
|
||||
}
|
||||
|
||||
func deviceDidUpdateBluetoothState(state: CBManagerState, bluetoothTransmitter: BluetoothTransmitter) {
|
||||
|
@ -567,7 +618,7 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
|
|||
|
||||
if bluetoothTransmitter.deviceAddress == nil {
|
||||
/// this bluetoothTransmitter is created to start scanning for a new, unknown M5Stack, so start scanning
|
||||
bluetoothTransmitter.startScanning()
|
||||
_ = bluetoothTransmitter.startScanning()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>3164</string>
|
||||
<string>3179</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
|
|
|
@ -227,17 +227,17 @@ class BluetoothPeripheralViewController: UIViewController {
|
|||
/// user cliks done button
|
||||
public func doneButtonHandler() {
|
||||
|
||||
if let bluetoothPeripheralASNSObject = bluetoothPeripheralAsNSObject, let coreDataManager = coreDataManager {
|
||||
if let bluetoothPeripheralAsNSObject = bluetoothPeripheralAsNSObject, let coreDataManager = coreDataManager {
|
||||
|
||||
// set variable delegate in bluetoothPeripheralASNSObject to nil, no need anymore to receive info
|
||||
bluetoothPeripheralManager.getBluetoothTransmitter(for: bluetoothPeripheralASNSObject, createANewOneIfNecesssary: false)?.variableBluetoothTransmitterDelegate = nil
|
||||
bluetoothPeripheralManager.getBluetoothTransmitter(for: bluetoothPeripheralAsNSObject, createANewOneIfNecesssary: false)?.variableBluetoothTransmitterDelegate = nil
|
||||
|
||||
// set alias temp value, possibly this is a nil value
|
||||
bluetoothPeripheralASNSObject.setAlias(aliasTemporaryValue)
|
||||
bluetoothPeripheralAsNSObject.setAlias(aliasTemporaryValue)
|
||||
|
||||
|
||||
// temp values stored by viewmodel needs to be written to bluetoothPeripheralASNSObject
|
||||
bluetoothPeripheralViewModel.writeTempValues(to: bluetoothPeripheralASNSObject)
|
||||
bluetoothPeripheralViewModel.writeTempValues(to: bluetoothPeripheralAsNSObject)
|
||||
|
||||
// save all changes now
|
||||
coreDataManager.saveChanges()
|
||||
|
|
Loading…
Reference in New Issue