mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Method to create empty node info
This commit is contained in:
parent
97e69af44a
commit
5dd805cb2d
3 changed files with 24 additions and 14 deletions
|
|
@ -6,6 +6,7 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
extension NodeInfoEntity {
|
||||
|
||||
|
|
@ -37,4 +38,22 @@ extension NodeInfoEntity {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public func createNodeInfo(num: Int64, context: NSManagedObjectContext) -> NodeInfoEntity {
|
||||
|
||||
let newNode = NodeInfoEntity(context: context)
|
||||
newNode.id = Int64(num)
|
||||
newNode.num = Int64(num)
|
||||
let newUser = UserEntity(context: context)
|
||||
newUser.num = Int64(num)
|
||||
let userId = String(format:"%2X", num)
|
||||
newUser.userId = "!\(userId)"
|
||||
let last4 = String(userId.suffix(4))
|
||||
newUser.longName = "Meshtastic \(last4)"
|
||||
newUser.shortName = last4
|
||||
newUser.hwModel = "UNSET"
|
||||
newNode.user = newUser
|
||||
return newNode
|
||||
}
|
||||
|
|
|
|||
|
|
@ -649,7 +649,10 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
var routeString = "You --> "
|
||||
var hopNodes: [TraceRouteHopEntity] = []
|
||||
for node in routingMessage.route {
|
||||
let hopNode = getNodeInfo(id: Int64(node), context: context!)
|
||||
var hopNode = getNodeInfo(id: Int64(node), context: context!)
|
||||
if hopNode == nil {
|
||||
hopNode = createNodeInfo(num: Int64(node), context: context!)
|
||||
}
|
||||
let traceRouteHop = TraceRouteHopEntity(context: context!)
|
||||
traceRouteHop.time = Date()
|
||||
if hopNode?.hasPositions ?? false {
|
||||
|
|
|
|||
|
|
@ -208,19 +208,7 @@ func deviceMetadataPacket (metadata: DeviceMetadata, fromNum: Int64, context: NS
|
|||
if fetchedNode.count > 0 {
|
||||
fetchedNode[0].metadata = newMetadata
|
||||
} else {
|
||||
|
||||
let newNode = NodeInfoEntity(context: context)
|
||||
newNode.id = Int64(fromNum)
|
||||
newNode.num = Int64(fromNum)
|
||||
let newUser = UserEntity(context: context)
|
||||
newUser.num = Int64(fromNum)
|
||||
let userId = String(format:"%2X", fromNum)
|
||||
newUser.userId = "!\(userId)"
|
||||
let last4 = String(userId.suffix(4))
|
||||
newUser.longName = "Meshtastic \(last4)"
|
||||
newUser.shortName = last4
|
||||
newUser.hwModel = "UNSET"
|
||||
newNode.user = newUser
|
||||
let newNode = createNodeInfo(num: Int64(fromNum), context: context)
|
||||
newNode.metadata = newMetadata
|
||||
}
|
||||
do {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue