mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
NodeMap Checkpoint
This commit is contained in:
parent
f65224f5ac
commit
df20110604
5 changed files with 162 additions and 59 deletions
|
|
@ -83,15 +83,15 @@
|
|||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "384A95D5-E5B6-46C8-94DA-506E31489BA6"
|
||||
uuid = "BD16DE86-365A-47B2-8DBB-340D5A835D76"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "527"
|
||||
endingLineNumber = "527"
|
||||
startingLineNumber = "492"
|
||||
endingLineNumber = "492"
|
||||
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
|
|
@ -99,15 +99,63 @@
|
|||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "274F633B-F186-4C7E-964A-850655473405"
|
||||
uuid = "77F5CE1E-8BA3-4831-8A0D-6CEE16E9E8FD"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "718"
|
||||
endingLineNumber = "718"
|
||||
startingLineNumber = "841"
|
||||
endingLineNumber = "841"
|
||||
landmarkName = "sendMessage(message:toUserNum:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "2612CBA3-75B4-425A-BE58-67803A216FD8"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "760"
|
||||
endingLineNumber = "760"
|
||||
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "09F62D50-739F-4296-AEB8-6390CDC17EC1"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "701"
|
||||
endingLineNumber = "701"
|
||||
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "AAA52FF4-A075-47F6-BA0C-DE2D63401B87"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "768"
|
||||
endingLineNumber = "768"
|
||||
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
|
|
|
|||
|
|
@ -489,11 +489,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
newNode.user = newUser
|
||||
}
|
||||
|
||||
|
||||
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 = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time)))
|
||||
|
||||
|
|
@ -541,8 +541,17 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
|
||||
let mutablePositions = fetchedNode[0].positions!.mutableCopy() as! NSMutableOrderedSet
|
||||
mutablePositions.add(position)
|
||||
fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet
|
||||
|
||||
|
||||
if position.coordinate == nil {
|
||||
var newPostions = [PositionEntity]()
|
||||
newPostions.append(position)
|
||||
fetchedNode[0].positions? = NSOrderedSet(array : newPostions)
|
||||
|
||||
} else {
|
||||
|
||||
fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet
|
||||
}
|
||||
|
||||
// Look for a MyInfo
|
||||
let fetchMyInfoRequest:NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "MyInfoEntity")
|
||||
fetchMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", Int64(decodedInfo.nodeInfo.num))
|
||||
|
|
@ -680,6 +689,19 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
fetchedNode[0].num = Int64(decodedInfo.packet.from)
|
||||
fetchedNode[0].lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.packet.rxTime)))
|
||||
fetchedNode[0].snr = decodedInfo.packet.rxSnr
|
||||
|
||||
let array = [UInt8](decodedInfo.packet.decoded.payload)
|
||||
print (array[0])
|
||||
print (array[1])
|
||||
print (array[2])
|
||||
print (array[3])
|
||||
print (array[4])
|
||||
print (array)
|
||||
|
||||
let bytes = decodedInfo.packet.decoded.payload
|
||||
print(bytes, String(bytes: bytes, encoding: .utf8))
|
||||
|
||||
print(bytes2String(array))
|
||||
}
|
||||
else {
|
||||
return
|
||||
|
|
@ -715,9 +737,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
|
||||
do {
|
||||
|
||||
let fetchedNode = try context?.fetch(fetchNodePositionRequest) as! [NodeInfoEntity]
|
||||
|
||||
|
||||
|
||||
let fetchedNode = try context?.fetch(fetchNodePositionRequest) as! [NodeInfoEntity]
|
||||
|
||||
// Never run
|
||||
if fetchedNode.count == 1 {
|
||||
fetchedNode[0].id = Int64(decodedInfo.packet.from)
|
||||
fetchedNode[0].num = Int64(decodedInfo.packet.from)
|
||||
|
|
@ -733,6 +757,23 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
}
|
||||
fetchedNode[0].snr = decodedInfo.packet.rxSnr
|
||||
|
||||
let array = [UInt8](decodedInfo.packet.decoded.payload)
|
||||
//print(array)
|
||||
//let payload = decodedInfo.packet.decoded.payload as NSData
|
||||
let bytes = decodedInfo.packet.decoded.payload
|
||||
print(bytes, String(bytes: bytes, encoding: .utf8))
|
||||
|
||||
// Get a string from the byte array.
|
||||
if let result = String(bytes: bytes, encoding: .utf8) {
|
||||
print(result)
|
||||
}
|
||||
|
||||
let testBytes : [UInt8] = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64]
|
||||
|
||||
|
||||
var test = bytes2String(testBytes)
|
||||
print(test)
|
||||
|
||||
}
|
||||
else {
|
||||
return
|
||||
|
|
@ -892,3 +933,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
return success
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func bytes2String(_ array: [UInt8]) -> String {
|
||||
return String(data: Data(bytes: array, count: array.count), encoding: .utf8) ?? ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ extension PositionEntity {
|
|||
}
|
||||
|
||||
var coordinate: CLLocationCoordinate2D? {
|
||||
if latitude != nil && longitude != nil {
|
||||
if latitudeI != 0 && longitudeI != 0 {
|
||||
let coord = CLLocationCoordinate2D(latitude: latitude!, longitude: longitude!)
|
||||
|
||||
return coord
|
||||
|
|
|
|||
|
|
@ -20,30 +20,38 @@ struct NodeDetail: View {
|
|||
|
||||
VStack {
|
||||
|
||||
if ((node.myInfo?.hasGps) != nil) {
|
||||
if node.positions?.count ?? 0 > 0 {
|
||||
|
||||
let mostRecent = node.positions?.lastObject as! PositionEntity
|
||||
|
||||
let nodeCoordinatePosition = CLLocationCoordinate2D(latitude: mostRecent.latitude!, longitude: mostRecent.longitude!)
|
||||
|
||||
let regionBinding = Binding<MKCoordinateRegion>(
|
||||
get: {
|
||||
MKCoordinateRegion(center: nodeCoordinatePosition, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))
|
||||
},
|
||||
set: { _ in }
|
||||
)
|
||||
let annotations = [MapLocation(name: node.user!.shortName ?? "???", coordinate: mostRecent.coordinate!)]
|
||||
|
||||
Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none, annotationItems: annotations) { location in
|
||||
MapAnnotation(
|
||||
coordinate: location.coordinate,
|
||||
content: {
|
||||
CircleText(text: node.user!.shortName ?? "???", color: .accentColor)
|
||||
}
|
||||
)
|
||||
}
|
||||
.frame(idealWidth: bounds.size.width, maxHeight: bounds.size.height / 3)
|
||||
|
||||
if mostRecent.coordinate != nil {
|
||||
|
||||
let nodeCoordinatePosition = CLLocationCoordinate2D(latitude: mostRecent.latitude!, longitude: mostRecent.longitude!)
|
||||
|
||||
let regionBinding = Binding<MKCoordinateRegion>(
|
||||
get: {
|
||||
MKCoordinateRegion(center: nodeCoordinatePosition, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))
|
||||
},
|
||||
set: { _ in }
|
||||
)
|
||||
let annotations = [MapLocation(name: node.user!.shortName ?? "???", coordinate: mostRecent.coordinate!)]
|
||||
|
||||
Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none, annotationItems: annotations) { location in
|
||||
MapAnnotation(
|
||||
coordinate: location.coordinate,
|
||||
content: {
|
||||
CircleText(text: node.user!.shortName ?? "???", color: .accentColor)
|
||||
}
|
||||
)
|
||||
}
|
||||
.frame(idealWidth: bounds.size.width, maxHeight: bounds.size.height / 3)
|
||||
} else {
|
||||
|
||||
Image(node.user?.hwModel ?? "UNSET")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: bounds.size.width, height: bounds.size.height / 2)
|
||||
}
|
||||
} else {
|
||||
|
||||
Image(node.user?.hwModel ?? "UNSET")
|
||||
|
|
@ -167,7 +175,7 @@ struct NodeDetail: View {
|
|||
}
|
||||
}.padding()
|
||||
|
||||
if ((node.myInfo?.hasGps) != nil) {
|
||||
if node.positions?.count ?? 0 > 0 {
|
||||
|
||||
Divider()
|
||||
|
||||
|
|
@ -177,7 +185,7 @@ struct NodeDetail: View {
|
|||
.font(.title)
|
||||
.foregroundColor(.accentColor)
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
Text("Position History (\(node.positions?.count ?? 0) Points)").font(.title2)
|
||||
Text("Location History").font(.title2)
|
||||
}
|
||||
.padding()
|
||||
|
||||
|
|
@ -185,7 +193,9 @@ struct NodeDetail: View {
|
|||
|
||||
ForEach(node.positions!.array as! [PositionEntity], id: \.self) { (mappin: PositionEntity) in
|
||||
|
||||
VStack {
|
||||
//if mappin.coordinate != nil {
|
||||
|
||||
VStack {
|
||||
|
||||
HStack {
|
||||
|
||||
|
|
@ -222,8 +232,9 @@ struct NodeDetail: View {
|
|||
.symbolRenderingMode(.hierarchical)
|
||||
}
|
||||
}
|
||||
.padding(1)
|
||||
Divider()
|
||||
.padding(1)
|
||||
Divider()
|
||||
//}
|
||||
}
|
||||
.padding(.bottom, 5) // Without some padding here there is a transparent contentview bug
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,25 +9,21 @@
|
|||
import SwiftUI
|
||||
import MapKit
|
||||
import CoreLocation
|
||||
import CoreData
|
||||
|
||||
struct NodeMap: View {
|
||||
|
||||
// CoreData
|
||||
@Environment(\.managedObjectContext) var context
|
||||
@EnvironmentObject var bleManager: BLEManager
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \NodeInfoEntity.lastHeard, ascending: false)],
|
||||
animation: .default)
|
||||
@State private var showLabels: Bool = false
|
||||
|
||||
@State private var annotationItems: [MapLocation] = []
|
||||
@FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \NodeInfoEntity.lastHeard, ascending: false)], animation: .default)
|
||||
|
||||
private var locationNodes: FetchedResults<NodeInfoEntity>
|
||||
|
||||
struct MapLocation: Identifiable {
|
||||
|
||||
let id = UUID()
|
||||
let name: String
|
||||
let coordinate: CLLocationCoordinate2D
|
||||
}
|
||||
var annotations: [MapLocation] = [MapLocation]()
|
||||
|
||||
var body: some View {
|
||||
|
||||
|
|
@ -39,7 +35,7 @@ struct NodeMap: View {
|
|||
},
|
||||
set: { _ in }
|
||||
)
|
||||
|
||||
|
||||
NavigationView {
|
||||
|
||||
ZStack {
|
||||
|
|
@ -47,17 +43,19 @@ struct NodeMap: View {
|
|||
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)
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
userTrackingMode: .constant(.follow)//,
|
||||
//ForEach ( locationNodes ) { node in
|
||||
// let mostRecent = node.positions?.lastObject as! PositionEntity
|
||||
// if mostRecent.coordinate != nil {
|
||||
|
||||
// annotations.append(MapLocation(name: node.user?.shortName! ?? "???", coordinate: mostRecent.coordinate!))
|
||||
|
||||
// }
|
||||
// }
|
||||
)
|
||||
//}
|
||||
.frame(maxHeight: .infinity)
|
||||
.ignoresSafeArea(.all, edges: [.leading, .trailing])
|
||||
.ignoresSafeArea(.all, edges: [.leading, .trailing])
|
||||
}
|
||||
.navigationTitle("Mesh Map")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue