Skip to content

Commit db8ea5d

Browse files
committed
logs: added logging for BLE actions
1 parent 093f28a commit db8ea5d

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

InfiniLink/BLE/BLEFS.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class BLEFSHandler: ObservableObject {
100100
@Published var externalResourcesSize: Int = 0
101101

102102
func uploadExternalResources(completion: @escaping() -> Void) {
103+
log("External resource upload requested", type: .info, caller: "BLEFSHandler")
104+
103105
DispatchQueue.global(qos: .default).async { [self] in
104106
do {
105107
let unzipDirectory = try Zip.quickUnzipFile(dfuUpdater.resourceURL)
@@ -161,6 +163,8 @@ class BLEFSHandler: ObservableObject {
161163
}
162164

163165
private func createDir(path: String) {
166+
log("Create directory called", type: .info, caller: "BLEFSHandler")
167+
164168
let dir = path.components(separatedBy: "/").filter { $0 != "" }
165169

166170
if dir.count > 1 {
@@ -178,6 +182,8 @@ class BLEFSHandler: ObservableObject {
178182
}
179183

180184
func readFile(path: String, offset: UInt32) -> ReadFileFS {
185+
log("Read file called", type: .info, caller: "BLEFSHandler")
186+
181187
var writeData = Data()
182188

183189
readFileFS = ReadFileFS()
@@ -220,6 +226,8 @@ class BLEFSHandler: ObservableObject {
220226
}
221227

222228
func writeFile(data: Data, path: String, offset: UInt32) -> WriteFileFS {
229+
log("Write file called", type: .info, caller: "BLEFSHandler")
230+
223231
var write = WriteFileFS()
224232
write.group = DispatchGroup()
225233
write.group.enter()
@@ -297,6 +305,8 @@ class BLEFSHandler: ObservableObject {
297305
}
298306

299307
func deleteFile(path: String) -> Bool {
308+
log("Delete file called", type: .info, caller: "BLEFSHandler")
309+
300310
var rm = InformationFS()
301311
rm.group = DispatchGroup()
302312
rm.group.enter()
@@ -321,6 +331,8 @@ class BLEFSHandler: ObservableObject {
321331
}
322332

323333
func makeDir(path: String) -> Bool {
334+
log("Make directory called", type: .info, caller: "BLEFSHandler")
335+
324336
var mk = InformationFS()
325337
mk.group = DispatchGroup()
326338
mk.group.enter()
@@ -352,6 +364,8 @@ class BLEFSHandler: ObservableObject {
352364
}
353365

354366
func listDir(path: String) -> DirList {
367+
log("List directory called", type: .info, caller: "BLEFSHandler")
368+
355369
var ls = InformationFS()
356370
ls.group = DispatchGroup()
357371
ls.group.enter()
@@ -377,6 +391,8 @@ class BLEFSHandler: ObservableObject {
377391
}
378392

379393
func moveFileOrDir(oldPath: String, newPath: String) -> Bool {
394+
log("Move file/directory called", type: .info, caller: "BLEFSHandler")
395+
380396
var mv = InformationFS()
381397
mv.group = DispatchGroup()
382398
mv.group.enter()
@@ -586,6 +602,8 @@ class BLEFSHandler: ObservableObject {
586602
}
587603

588604
func readSettings(completion: @escaping(Settings) -> Void) {
605+
log("Settings requested", type: .info, caller: "BLEFSHandler")
606+
589607
DispatchQueue.global(qos: .default).async {
590608
let readFile = self.readFile(path: "/settings.dat", offset: 0)
591609
let firmwareVersion = DeviceManager.shared.firmware

InfiniLink/BLE/BLEWriteManager.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@ struct BLEWriteManager {
2222
return
2323
}
2424
bleManager.infiniTime.writeValue(writeData, for: characteristic, type: .withResponse)
25+
log("Wrote to music app", type: .info, caller: "BLEWriteManager")
2526
}
2627

2728
func writeHexToMusicApp(message: [UInt8], characteristic: CBCharacteristic) -> Void {
2829
guard bleManager.infiniTime != nil else { return }
2930
let writeData = Data(bytes: message, count: message.capacity)
3031

3132
bleManager.infiniTime.writeValue(writeData, for: characteristic, type: .withResponse)
33+
log("Wrote to music app", type: .info, caller: "BLEWriteManager")
3234
}
3335

3436
func setTime(characteristic: CBCharacteristic) {
3537
guard bleManager.infiniTime != nil else { return }
3638

3739
do {
3840
try bleManager.infiniTime.writeValue(SetTime().currentTime().hexData, for: characteristic, type: .withResponse)
41+
log("Set watch time", type: .info, caller: "BLEWriteManager")
3942
} catch {
4043
bleManager.setTimeError = true
44+
log("Error setting watch time", caller: "BLEWriteManager")
4145
}
4246
}
4347

@@ -52,6 +56,7 @@ struct BLEWriteManager {
5256

5357
if !notification.isEmpty && watchNotifications {
5458
bleManager.infiniTime.writeValue(notification, for: bleManager.notifyCharacteristic, type: .withResponse)
59+
log("Notification sent with title: \(notif.title)", caller: "BLEWriteManager")
5560
}
5661
}
5762

@@ -65,6 +70,7 @@ struct BLEWriteManager {
6570

6671
if notification.count > 0 && watchNotifications {
6772
bleManager.infiniTime.writeValue(notification, for: bleManager.notifyCharacteristic, type: .withResponse)
73+
log("Sent lost notification", type: .info, caller: "BLEWriteManager")
6874
}
6975
}
7076

@@ -102,6 +108,7 @@ struct BLEWriteManager {
102108
let writeData = Data(bytes: bytes as [UInt8], count: 49)
103109
if bleManager.weatherCharacteristic != nil && bleManager.infiniTime != nil {
104110
bleManager.infiniTime.writeValue(writeData, for: bleManager.weatherCharacteristic, type: .withResponse)
111+
log("Set watch current weather", type: .info, caller: "BLEWriteManager")
105112
}
106113
}
107114

@@ -133,6 +140,7 @@ struct BLEWriteManager {
133140

134141
if bleManager.weatherCharacteristic != nil && bleManager.infiniTime != nil {
135142
bleManager.infiniTime.writeValue(writeData, for: bleManager.weatherCharacteristic, type: .withResponse)
143+
log("Set watch forecast", type: .info, caller: "BLEWriteManager")
136144
}
137145
}
138146

@@ -151,6 +159,8 @@ struct BLEWriteManager {
151159
bleManager.infiniTime.writeValue(distance, for: bleManager.navigationDistanceCharacteristic, type: .withResponse)
152160
bleManager.infiniTime.writeValue(progress, for: bleManager.navigationProgressCharacteristic, type: .withResponse)
153161
bleManager.infiniTime.writeValue(icon, for: bleManager.navigationFlagsCharacteristic, type: .withResponse)
162+
163+
log("Wrote navigation update", type: .info, caller: "BLEWriteManager")
154164
}
155165
}
156166

InfiniLink/Utils/DownloadManager.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class DownloadManager: NSObject, ObservableObject {
4343

4444
@AppStorage("releases") var releases: [Result] = []
4545
@AppStorage("buildArtifacts") var buildArtifacts: [Artifact] = []
46+
@AppStorage("lastTimeReleasesFetched") var lastTimeReleasesFetched: Double = 0
4647

4748
@Published var updateVersion: String = "0.0.0"
4849
@Published var updateBody: String = ""
@@ -217,9 +218,16 @@ class DownloadManager: NSObject, ObservableObject {
217218
}
218219

219220
func getUpdates() {
220-
getInfiniLinkReleases()
221-
getInfiniTimeReleases()
222-
getWorkflowRuns()
221+
let now = Date()
222+
223+
// Make sure we haven't checked for updates in the past 30 minutes
224+
if (now.timeIntervalSince1970 - lastTimeReleasesFetched) > (30 * 20) {
225+
getInfiniLinkReleases()
226+
getInfiniTimeReleases()
227+
getWorkflowRuns()
228+
229+
lastTimeReleasesFetched = now.timeIntervalSince1970
230+
}
223231
}
224232

225233
func getInfiniLinkReleases() {

0 commit comments

Comments
 (0)