Skip to content

Commit

Permalink
Merge pull request #58 from BIDMCDigitalPsychiatry/bugfix/frequencyUp…
Browse files Browse the repository at this point in the history
…date

Bugfix/frequency update.
  • Loading branch information
jijopulikkottil authored Dec 20, 2023
2 parents 952f524 + 5be2868 commit 85c9c7f
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 117 deletions.
Binary file modified .github/secrets/Certificates.p12.gpg
Binary file not shown.
20 changes: 10 additions & 10 deletions .github/secrets/decrypt_secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ echo "Start Import"

gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/Certificates.p12 .github/secrets/Certificates.p12.gpg

gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_2022.mobileprovision .github/secrets/mindLAMP2_2022.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_Custom_Notification_Extension_AppStore.mobileprovision .github/secrets/mindLAMP2_Custom_Notification_Extension_AppStore.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_Notification_Service_AppStore.mobileprovision .github/secrets/mindLAMP2_Notification_Service_AppStore.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2.mobileprovision .github/secrets/mindLAMP2.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_Custom_Notification_Extension.mobileprovision .github/secrets/mindLAMP2_Custom_Notification_Extension.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_Notification_Service.mobileprovision .github/secrets/mindLAMP2_Notification_Service.mobileprovision.gpg

gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_WatchApp_Extension_AppStore.mobileprovision .github/secrets/mindLAMP2_WatchApp_Extension_AppStore.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_WatchApp_AppStore.mobileprovision .github/secrets/mindLAMP2_WatchApp_AppStore.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_WatchApp_Extension.mobileprovision .github/secrets/mindLAMP2_WatchApp_Extension.mobileprovision.gpg
gpg --quiet --batch --yes --decrypt --passphrase="$IOS_KEYS" --output .github/secrets/mindLAMP2_WatchApp.mobileprovision .github/secrets/mindLAMP2_WatchApp.mobileprovision.gpg

echo "Imported"

mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles

cp .github/secrets/mindLAMP2_2022.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_2022.mobileprovision
cp .github/secrets/mindLAMP2_Custom_Notification_Extension_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_Custom_Notification_Extension_AppStore.mobileprovision
cp .github/secrets/mindLAMP2_Notification_Service_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_Notification_Service_AppStore.mobileprovision
cp .github/secrets/mindLAMP2_2022.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2.mobileprovision
cp .github/secrets/mindLAMP2_Custom_Notification_Extension_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_Custom_Notification_Extension.mobileprovision
cp .github/secrets/mindLAMP2_Notification_Service_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_Notification_Service.mobileprovision

cp .github/secrets/mindLAMP2_WatchApp_Extension_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_WatchApp_Extension_AppStore.mobileprovision
cp .github/secrets/mindLAMP2_WatchApp_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_WatchApp_AppStore.mobileprovision
cp .github/secrets/mindLAMP2_WatchApp_Extension_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_WatchApp_Extension.mobileprovision
cp .github/secrets/mindLAMP2_WatchApp_AppStore.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/mindLAMP2_WatchApp.mobileprovision

echo "Copied"

Expand Down
Binary file added .github/secrets/mindLAMP2.mobileprovision.gpg
Binary file not shown.
Binary file removed .github/secrets/mindLAMP2_2022.mobileprovision.gpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions SharedToWatchExt/Logging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class Logging {
// MARK: - Global functions for logging

func print(_ items: Any ..., separator: String = " ", terminator: String = "\n") {
//#if DEBUG
#if DEBUG
var idx = items.startIndex
let endIdx = items.endIndex
repeat {
Swift.print(items[idx], separator: separator, terminator: idx == endIdx ? terminator : separator)
idx += 1
}
while idx < endIdx
//#endif
#endif
}
/**
Prints the filename, function name, line number and textual representation of `object` and a newline character into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ extension LMSensorManager: SensorStore {
DispatchQueue.main.async {
(UIApplication.shared.delegate as? AppDelegate)?.calculateBadgeCount()
}
sensor_wifi?.startScanning()

//set 15 seconds delay to fetch all healthkit data
printToFile("15 seconds delay")
DispatchQueue.global().asyncAfter(deadline: .now() + 15) {
printToFile("----")
self.sensor_wifi?.stopScanning()
if self.sensor_location == nil {
printToFile("\ndeallocated")
return } //stop syncing if sensors are stopped
Expand Down Expand Up @@ -293,23 +291,4 @@ extension LMSensorManager: ScreenStateObserver {
}
}

// MARK: - WiFiObserver
extension LMSensorManager: WiFiObserver {

func onWiFiAPDetected(data: WiFiScanData) {
latestWifiData = data
}

func onWiFiDisabled() {
print("\(#function)")
}

func onWiFiScanStarted() {
print("\(#function)")
}

func onWiFiScanEnded() {
print("\(#function)")
}
}
#endif
113 changes: 60 additions & 53 deletions SharedToWatchExt/SensorManager/LMSensorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ class LMSensorManager {
#if os(iOS)
var sensor_calls: CallsSensor?
var lampScreenSensor: ScreenSensor?
var sensor_wifi: WiFiSensor?
//var sensor_wifi: WiFiSensor?
#endif

#if os(iOS)
var reachability: Reachability = try! Reachability()
#endif

var sensor_bluetooth: LMBluetoothSensor?
var nearByDevice: NearByDevice?
var sensor_healthKit: LMHealthKitSensor?
var sensor_pedometer: PedometerSensor?

Expand All @@ -100,8 +100,6 @@ class LMSensorManager {
var pedometerDataBuffer = [PedometerData]()
let queuePedometerData = DispatchQueue(label: "thread-safe-PedometerData", attributes: .concurrent)

var latestWifiData: WiFiScanData?

//SensorKit Data
let queueSensorKitBufferData = DispatchQueue(label: "thread-safe-VisitData", attributes: .concurrent)
var sensorKitDataBuffer: [SensorKitEvent] = []
Expand Down Expand Up @@ -292,8 +290,7 @@ class LMSensorManager {
setupScreenSensor()
}
if sensorIdentifiers.contains(SensorType.lamp_nearby_device.lampIdentifier) {
setupWifiSensor()
setupBluetoothSensor()
setupNearBySensor()
}

setupHealthKitSensor(sensorIdentifiers)
Expand All @@ -307,15 +304,14 @@ class LMSensorManager {
private func deinitSensors() {

sensor_motionManager = nil
sensor_bluetooth = nil
nearByDevice = nil
sensor_healthKit = nil
sensor_location = nil

sensor_Activity = nil
sensor_pedometer = nil
#if os(iOS)
sensor_calls = nil
sensor_wifi = nil
lampScreenSensor = nil
#endif
}
Expand Down Expand Up @@ -616,9 +612,13 @@ private extension LMSensorManager {
return false
}

func setupBluetoothSensor() {
sensor_bluetooth = LMBluetoothSensor()
sensorManager.addSensor(sensor_bluetooth!)
func setupNearBySensor() {
nearByDevice = NearByDevice(NearByDevice.Config().apply(closure: { config in
if let frquency = frquencySettings[SensorType.lamp_nearby_device.lampIdentifier] {
config.frequency = frquency
}
}))
sensorManager.addSensor(nearByDevice!)
}

func setupHealthKitSensor(_ specIdentifiers: [String]) {
Expand Down Expand Up @@ -704,14 +704,6 @@ private extension LMSensorManager {
}))
sensorManager.addSensor(lampScreenSensor!)
}

func setupWifiSensor() {
//we start scanning only when using the default timer (i.e when calling timeTostore() )
sensor_wifi = WiFiSensor.init(WiFiSensor.Config().apply(closure: { config in
config.sensorObserver = self
}))
sensorManager.addSensor(sensor_wifi!)
}
#endif
}

Expand Down Expand Up @@ -750,6 +742,10 @@ private extension LMSensorManager {
if let data = fetchHealthKitQuantityData() {
arraySensorData.append(contentsOf: data)
}
if let data = fetchBPData() {
arraySensorData.append(contentsOf: data)
}

if let data = fetchHKCategoryData() {
arraySensorData.append(contentsOf: data)
}
Expand All @@ -759,7 +755,6 @@ private extension LMSensorManager {
}
sensor_healthKit?.clearDataArrays()//clear all healthkit data fetched
#endif

return arraySensorData
}
}
Expand Down Expand Up @@ -906,26 +901,30 @@ private extension LMSensorManager {

func fetchNearbyDeviceData() -> [SensorEvent<SensorDataModel>] {
var dataArray: [SensorEvent<SensorDataModel>] = []
if let data = sensor_bluetooth?.latestData() {
var model = SensorDataModel()
model.type = SensorType.NearbyDevicetype.bluetooth
model.address = data.address
model.name = data.name
model.strength = data.rssi
let bluetoothevent = SensorEvent(timestamp: data.timestamp, sensor: SensorType.lamp_nearby_device.lampIdentifier, data: model)
dataArray.append(bluetoothevent)
if let dataa = nearByDevice?.latestBluetoothData() {
dataa.forEach { data in
var model = SensorDataModel()
model.type = SensorType.NearbyDevicetype.bluetooth
model.address = data.address
model.name = data.name
model.strength = data.rssi
let bluetoothevent = SensorEvent(timestamp: data.timestamp, sensor: SensorType.lamp_nearby_device.lampIdentifier, data: model)
dataArray.append(bluetoothevent)
}

}

if let data = latestWifiData {
var model = SensorDataModel()
model.type = SensorType.NearbyDevicetype.wifi
model.address = data.bssid
model.name = data.ssid
model.strength = data.rssi
let wifiEvent = SensorEvent(timestamp: data.timestamp, sensor: SensorType.lamp_nearby_device.lampIdentifier, data: model)
dataArray.append(wifiEvent)
//clear existing
latestWifiData = nil
if let dataa = nearByDevice?.latestWifiData() {
dataa.forEach { data in
var model = SensorDataModel()
model.type = SensorType.NearbyDevicetype.wifi
model.address = data.bssid
model.name = data.ssid
model.strength = data.rssi
let wifiEvent = SensorEvent(timestamp: data.timestamp, sensor: SensorType.lamp_nearby_device.lampIdentifier, data: model)
dataArray.append(wifiEvent)
}

}
return dataArray
}
Expand Down Expand Up @@ -994,32 +993,40 @@ private extension LMSensorManager {
}
return arrayData
}

func fetchBPData() -> [SensorEvent<SensorDataModel>]? {
guard let arrData = sensor_healthKit?.latestBPData() else {
return nil
}

return arrData.compactMap { bpdata in

if let sys = bpdata.systolic, let dias = bpdata.diastolic {
var model = SensorDataModel()
model.diastolic = SensorDataModel.Pressure(value: dias, units: bpdata.unit, source: bpdata.source, timestamp: UInt64(bpdata.timestamp))
model.systolic = SensorDataModel.Pressure(value: sys, units: bpdata.unit, source: bpdata.source, timestamp: UInt64(bpdata.timestamp))
model.startDate = bpdata.startDate
model.endDate = bpdata.endDate
model.source = Tristate(bpdata.source)
model.device_model = Tristate(bpdata.hkDevice)
return SensorEvent(timestamp: Double(Date().timeInMilliSeconds), sensor: bpdata.hkIdentifier.lampIdentifier, data: model)
}
return nil
}
}

func fetchHealthKitQuantityData() -> [SensorEvent<SensorDataModel>]? {
guard let arrData = sensor_healthKit?.latestQuantityData() else {
return nil
}
var arrayData = [SensorEvent<SensorDataModel>]()

guard let quantityTypes: [HKQuantityTypeIdentifier] = sensor_healthKit?.healthQuantityTypes.map( {HKQuantityTypeIdentifier(rawValue: $0.identifier)} ) else { return nil }
guard let quantityTypes: [HKQuantityTypeIdentifier] = sensor_healthKit?.healthQuantityTypes(isForAuthoroization: false).map( {HKQuantityTypeIdentifier(rawValue: $0.identifier)} ) else { return nil }
for quantityType in quantityTypes {
switch quantityType {

case .bloodPressureSystolic:
if let dataDiastolic = latestData(for: HKQuantityTypeIdentifier.bloodPressureDiastolic, in: arrData), let dataSystolic = latestData(for: HKQuantityTypeIdentifier.bloodPressureSystolic, in: arrData) {
var model = SensorDataModel()
if let diastolic = dataDiastolic.value {
model.diastolic = SensorDataModel.Pressure(value: diastolic, units: dataDiastolic.unit, source: dataDiastolic.source, timestamp: UInt64(dataDiastolic.timestamp))
}
if let systolic = dataSystolic.value {
model.systolic = SensorDataModel.Pressure(value: systolic, units: dataSystolic.unit, source: dataSystolic.source, timestamp: UInt64(dataSystolic.timestamp))
}
model.startDate = dataSystolic.startDate
model.endDate = dataSystolic.endDate
model.source = Tristate(dataDiastolic.source)
model.device_model = Tristate(dataDiastolic.hkDevice)
arrayData.append(SensorEvent(timestamp: Double(Date().timeInMilliSeconds), sensor: quantityType.lampIdentifier, data: model))
}
()
case .bloodPressureDiastolic:
()//handled with Systolic
default://bodyMass, height, respiratoryRate, heartRate
Expand Down
Loading

0 comments on commit 85c9c7f

Please sign in to comment.