diff --git a/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index 7b19cc77..136c5f60 100644
--- a/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -74,10 +74,10 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "822"
- endingLineNumber = "822"
+ startingLineNumber = "826"
+ endingLineNumber = "826"
landmarkName = "sendMessage(message:)"
- landmarkType = "9">
+ landmarkType = "7">
+ landmarkType = "7">
@@ -138,8 +138,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "454"
- endingLineNumber = "454"
+ startingLineNumber = "457"
+ endingLineNumber = "457"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
@@ -154,8 +154,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "663"
- endingLineNumber = "663"
+ startingLineNumber = "666"
+ endingLineNumber = "666"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
@@ -170,8 +170,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "706"
- endingLineNumber = "706"
+ startingLineNumber = "709"
+ endingLineNumber = "709"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift
index 23057c8f..e0960380 100644
--- a/MeshtasticClient/Helpers/BLEManager.swift
+++ b/MeshtasticClient/Helpers/BLEManager.swift
@@ -79,9 +79,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
func startScanning() {
if isSwitchedOn {
-
+
+ self.peripherals.removeAll()
centralManager.scanForPeripherals(withServices: [meshtasticServiceCBUUID], options: nil)
self.isScanning = self.centralManager.isScanning
+
print("Scanning Started")
}
}
@@ -93,6 +95,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
self.centralManager.stopScan()
self.isScanning = self.centralManager.isScanning
+
print("Stopped Scanning")
}
}
@@ -167,7 +170,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
peripheralName = name
}
- let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: "", longName: "", firmwareVersion: "Unknown", rssi: RSSI.intValue, subscribed: false, peripheral: peripheral)
+ let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: String(peripheralName.suffix(3)), longName: peripheralName, firmwareVersion: "Unknown", rssi: RSSI.intValue, subscribed: false, peripheral: peripheral)
let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id })
if peripheralIndex != nil && newPeripheral.peripheral.state != CBPeripheralState.connected {
@@ -485,7 +488,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
position.longitudeI = decodedInfo.nodeInfo.position.longitudeI
position.altitude = decodedInfo.nodeInfo.position.altitude
position.batteryLevel = decodedInfo.nodeInfo.position.batteryLevel
- position.time = Int32(bitPattern: decodedInfo.nodeInfo.position.time)
+ position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time)))
var newPostions = [PositionEntity]()
newPostions.append(position)
@@ -522,14 +525,14 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
fetchedNode[0].user!.shortName = decodedInfo.nodeInfo.user.shortName
fetchedNode[0].user!.hwModel = String(describing: decodedInfo.nodeInfo.user.hwModel).uppercased()
}
- if decodedInfo.nodeInfo.hasPosition {
+ if decodedInfo.nodeInfo.hasPosition && decodedInfo.nodeInfo.position.latitudeI != 0 && decodedInfo.nodeInfo.position.longitudeI != 0 {
let position = PositionEntity(context: context!)
position.latitudeI = decodedInfo.nodeInfo.position.latitudeI
position.longitudeI = decodedInfo.nodeInfo.position.longitudeI
position.altitude = decodedInfo.nodeInfo.position.altitude
position.batteryLevel = decodedInfo.nodeInfo.position.batteryLevel
- position.time = Int32(bitPattern: decodedInfo.nodeInfo.position.time)
+ position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time)))
if position.latitudeI != 0 {
let mutablePositions = fetchedNode[0].positions!.mutableCopy() as! NSMutableSet
@@ -671,7 +674,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if fetchedNode.count == 1 {
fetchedNode[0].id = Int64(decodedInfo.packet.from)
fetchedNode[0].num = Int64(decodedInfo.packet.from)
- fetchedNode[0].lastHeard = Date()//Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.packet.rxTime)))
+ fetchedNode[0].lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.packet.rxTime)))
fetchedNode[0].snr = decodedInfo.packet.rxSnr
}
else {
@@ -766,6 +769,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if meshLoggingEnabled { MeshLogger.log("BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)") }
print("BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)")
self.connectedPeripheral.subscribed = true
+ self.peripherals.removeAll()
}
default:
diff --git a/MeshtasticClient/Views/Messages/Messages.swift b/MeshtasticClient/Views/Messages/Messages.swift
index 59b385b5..93f52739 100644
--- a/MeshtasticClient/Views/Messages/Messages.swift
+++ b/MeshtasticClient/Views/Messages/Messages.swift
@@ -48,10 +48,10 @@ struct Messages: View {
ForEach(messages) { message in
HStack(alignment: .top) {
- //let currentUser: true//(message.fromUser != nil && bleManager.connectedPeripheral.num == message.fromUser!.num)
+ let currentUser: Bool = (message.fromUser != nil && bleManager.connectedPeripheral.num == message.fromUser!.num)
- CircleText(text: (message.fromUser?.longName ?? "???"), color: true ? .accentColor : Color(.darkGray)).padding(.all, 5)
+ CircleText(text: (message.fromUser?.longName ?? "???"), color: currentUser ? .accentColor : Color(.darkGray)).padding(.all, 5)
.gesture(LongPressGesture(minimumDuration: 2)
.onEnded {_ in
print("I want to delete message: \(message.messageId)")
@@ -66,7 +66,7 @@ struct Messages: View {
.textSelection(.enabled)
.padding(10)
.foregroundColor(.white)
- .background(true ? Color.blue : Color(.darkGray))
+ .background(currentUser ? Color.blue : Color(.darkGray))
.cornerRadius(10)
HStack(spacing: 4) {
diff --git a/MeshtasticClient/Views/Nodes/NodeDetail.swift b/MeshtasticClient/Views/Nodes/NodeDetail.swift
index d1269bc2..5f5a60cc 100644
--- a/MeshtasticClient/Views/Nodes/NodeDetail.swift
+++ b/MeshtasticClient/Views/Nodes/NodeDetail.swift
@@ -29,7 +29,10 @@ struct NodeDetail: View {
if node.positions != nil && node.positions!.count > 0 {
-// let nodeCoordinatePosition = CLLocationCoordinate2D(latitude: node.position.latitude!, longitude: node.position.longitude!)
+// let mostRecentPositions = node.positions.max(by: {
+// $0. < $1.timeIntervalSinceReferenceDate
+// })
+// let nodeCoordinatePosition = CLLocationCoordinate2D(latitude: node.positions.latitude!, longitude: node.position.longitude!)
//
// let regionBinding = Binding(
// get: {
@@ -37,7 +40,7 @@ struct NodeDetail: View {
// },
// set: { _ in }
// )
-// let annotations = [MapLocation(name: node.user.shortName, coordinate: node.position.coordinate!)]
+// let annotations = [MapLocation(name: node.user!.shortName, coordinate: node.positions?.first(where: <#T##(Any) throws -> Bool#>).coordinate!)]
//
// Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none, annotationItems: annotations) { location in
// MapAnnotation(
diff --git a/MeshtasticClient/Views/Nodes/NodeMap.swift b/MeshtasticClient/Views/Nodes/NodeMap.swift
index 8d177d4d..76bb8c3f 100644
--- a/MeshtasticClient/Views/Nodes/NodeMap.swift
+++ b/MeshtasticClient/Views/Nodes/NodeMap.swift
@@ -43,32 +43,21 @@ struct NodeMap: View {
NavigationView {
ZStack {
-
- Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none)
- .frame(maxHeight: .infinity)
- //, annotationItems: locationNodes[0].positions?) { location in
-// MapAnnotation(
-// coordinate: location.coordinate,
-// content: {
-// CircleText(text: location.latitude, color: .accentColor)
-// }
-// )
-// }.frame(maxHeight: .infinity)
- //Map(coordinateRegion: regionBinding,
- // interactionModes: [.all],
- // showsUserLocation: true,
- // userTrackingMode: .constant(.follow), annotationItems: locationNodes) { node in
-
- //MapAnnotation(
- //coordinate: node.positions[0].coordinate,
- //content: {
- // CircleText(text: node.user!.shortName, color: .accentColor)
- //}
- // )
- //}
- //.frame(maxHeight: .infinity)
- //.ignoresSafeArea(.all, edges: [.leading, .trailing])
+// Map(coordinateRegion: regionBinding,
+// interactionModes: [.all],
+// showsUserLocation: true,
+// userTrackingMode: .constant(.follow), annotationItems: $locationNodes) { node in
+//
+// MapAnnotation(
+// coordinate: node.positions[0].coordinate,
+// content: {
+// CircleText(text: node.user!.shortName, color: .accentColor)
+// }
+// )
+// }
+// .frame(maxHeight: .infinity)
+// .ignoresSafeArea(.all, edges: [.leading, .trailing])
}
.navigationTitle("Mesh Map")
.navigationBarTitleDisplayMode(.inline)