mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #190 from meshtastic/1.3.42_Cleanup
Assorted cleanup and nodedb reset fixes
This commit is contained in:
commit
6e13d7d8b7
8 changed files with 65 additions and 43 deletions
|
|
@ -909,7 +909,15 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
var positionPacket = Position()
|
||||
positionPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7)
|
||||
positionPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7)
|
||||
positionPacket.satsInView = UInt32(LocationHelper.satsInView)
|
||||
positionPacket.altitude = Int32(LocationHelper.currentAltitude)
|
||||
positionPacket.timestamp = UInt32(LocationHelper.currentTimestamp.timeIntervalSince1970)
|
||||
positionPacket.groundSpeed = UInt32(LocationHelper.currentSpeed)
|
||||
//positionPacket.groundTrack = UInt32(LocationHelper.currentHeading)
|
||||
|
||||
var waypointPacket = Waypoint()
|
||||
waypointPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7)
|
||||
waypointPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7)
|
||||
|
|
@ -925,8 +933,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
meshPacket.wantAck = true//wantAck
|
||||
|
||||
var dataMessage = DataMessage()
|
||||
dataMessage.payload = try! waypointPacket.serializedData()
|
||||
dataMessage.portnum = PortNum.waypointApp
|
||||
dataMessage.payload = try! positionPacket.serializedData()
|
||||
dataMessage.portnum = PortNum.positionApp
|
||||
|
||||
meshPacket.decoded = dataMessage
|
||||
|
||||
|
|
@ -1156,7 +1164,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
adminPacket.nodedbReset = 1
|
||||
|
||||
var meshPacket: MeshPacket = MeshPacket()
|
||||
meshPacket.to = 0//UInt32(connectedPeripheral.num)
|
||||
meshPacket.to = UInt32(destNum)
|
||||
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
|
||||
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
|
||||
meshPacket.priority = MeshPacket.Priority.reliable
|
||||
|
|
|
|||
|
|
@ -1126,7 +1126,7 @@ func adminAppPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedOb
|
|||
|
||||
if meshLogging {
|
||||
|
||||
MeshLogger.log("💾 Updated MyInfo channel \(channelMessage.settings.channelNum) from Channel App Packet For: \(fetchedMyInfo[0].myNodeNum)")
|
||||
MeshLogger.log("💾 Updated MyInfo channel \(channelMessage.settings.channelNum + 1) from Channel App Packet For: \(fetchedMyInfo[0].myNodeNum)")
|
||||
}
|
||||
|
||||
} catch {
|
||||
|
|
@ -1169,7 +1169,6 @@ func positionPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedOb
|
|||
position.satsInView = Int32(positionMessage.satsInView)
|
||||
position.speed = Int32(positionMessage.groundSpeed)
|
||||
position.heading = Int32(positionMessage.groundTrack)
|
||||
|
||||
if positionMessage.timestamp != 0 {
|
||||
position.time = Date(timeIntervalSince1970: TimeInterval(Int64(positionMessage.timestamp)))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -67,15 +67,21 @@ public func clearCoreDataDatabase(context: NSManagedObjectContext) {
|
|||
for i in 0...persistenceController.managedObjectModel.entities.count-1 {
|
||||
let entity = persistenceController.managedObjectModel.entities[i]
|
||||
|
||||
do {
|
||||
let query = NSFetchRequest<NSFetchRequestResult>(entityName: entity.name!)
|
||||
let deleterequest = NSBatchDeleteRequest(fetchRequest: query)
|
||||
try context.execute(deleterequest)
|
||||
try context.save()
|
||||
//do {
|
||||
let query = NSFetchRequest<NSFetchRequestResult>(entityName: entity.name!)
|
||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: query)
|
||||
//try context.execute(deleterequest)
|
||||
//try context.save()
|
||||
|
||||
do {
|
||||
try context.executeAndMergeChanges(using: deleteRequest)
|
||||
} catch let error as NSError {
|
||||
print(error)
|
||||
}
|
||||
|
||||
} catch let error as NSError {
|
||||
print("Error: \(error.localizedDescription)")
|
||||
abort()
|
||||
}
|
||||
//} catch let error as NSError {
|
||||
// print("Error: \(error.localizedDescription)")
|
||||
// abort()
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,3 +69,17 @@ class PersistenceController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NSManagedObjectContext {
|
||||
|
||||
/// Executes the given `NSBatchDeleteRequest` and directly merges the changes to bring the given managed object context up to date.
|
||||
///
|
||||
/// - Parameter batchDeleteRequest: The `NSBatchDeleteRequest` to execute.
|
||||
/// - Throws: An error if anything went wrong executing the batch deletion.
|
||||
public func executeAndMergeChanges(using batchDeleteRequest: NSBatchDeleteRequest) throws {
|
||||
batchDeleteRequest.resultType = .resultTypeObjectIDs
|
||||
let result = try execute(batchDeleteRequest) as? NSBatchDeleteResult
|
||||
let changes: [AnyHashable: Any] = [NSDeletedObjectsKey: result?.result as? [NSManagedObjectID] ?? []]
|
||||
NSManagedObjectContext.mergeChanges(fromRemoteContextSave: changes, into: [self])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,11 +370,11 @@ struct UserMessageList: View {
|
|||
|
||||
})
|
||||
.onChange(of: messageCount, perform: { value in
|
||||
//scrollView.scrollTo(user.messageList.firstIndex(of: user.messageList.last! ), anchor: .bottom)
|
||||
scrollView.scrollTo(user.messageList.last!.messageId)
|
||||
if messageCount > 0 {
|
||||
scrollView.scrollTo(user.messageList.last!.messageId)
|
||||
}
|
||||
})
|
||||
.onChange(of: user.messageList, perform: { messages in
|
||||
|
||||
refreshId = UUID()
|
||||
messageCount = messages.count
|
||||
})
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ struct PositionLog: View {
|
|||
Divider()
|
||||
ForEach(node.positions!.reversed() as! [PositionEntity], id: \.self) { (mappin: PositionEntity) in
|
||||
GridRow {
|
||||
Text(String(mappin.latitude ?? 0))
|
||||
Text(String(format: "%.6f", mappin.latitude ?? 0))
|
||||
.font(.caption2)
|
||||
Text(String(mappin.longitude ?? 0))
|
||||
Text(String(format: "%.6f", mappin.longitude ?? 0))
|
||||
.font(.caption2)
|
||||
Text(String(mappin.satsInView))
|
||||
.font(.caption2)
|
||||
|
|
|
|||
|
|
@ -93,19 +93,20 @@ struct DeviceConfig: View {
|
|||
.controlSize(.large)
|
||||
.padding()
|
||||
.confirmationDialog(
|
||||
"Are you sure?",
|
||||
"All device and app data will be deleted. You will also need to forget your devices under Settings > Bluetooth.",
|
||||
isPresented: $isPresentingFactoryResetConfirm,
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
Button("Erase all device and app settings and data?", role: .destructive) {
|
||||
Button("Factory reset your device and app? ", role: .destructive) {
|
||||
|
||||
if !bleManager.sendFactoryReset(destNum: bleManager.connectedPeripheral.num) {
|
||||
|
||||
print("Factory Reset Failed")
|
||||
} else {
|
||||
clearCoreDataDatabase(context: context)
|
||||
// Disconnect from device
|
||||
bleManager.disconnectPeripheral()
|
||||
clearCoreDataDatabase(context: context)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,37 +146,37 @@ struct PositionConfig: View {
|
|||
.listRowSeparator(.visible)
|
||||
|
||||
Toggle(isOn: $includeAltitude) {
|
||||
|
||||
Label("Altitude", systemImage: "arrow.up")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeAltitudeMsl) {
|
||||
|
||||
Label("Altitude is Mean Sea Level", systemImage: "arrow.up.to.line.compact")
|
||||
if includeAltitude {
|
||||
Toggle(isOn: $includeAltitudeMsl) {
|
||||
Label("Altitude is Mean Sea Level", systemImage: "arrow.up.to.line.compact")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
Toggle(isOn: $includeGeoidalSeparation) {
|
||||
Label("Altitude Geoidal Seperation", systemImage: "globe.americas")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeSatsinview) {
|
||||
|
||||
Label("Number of satellites", systemImage: "skew")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeSeqNo) { //64
|
||||
|
||||
Label("Sequence number", systemImage: "number")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeTimestamp) { //128
|
||||
|
||||
Label("Timestamp", systemImage: "clock")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeHeading) { //128
|
||||
|
||||
Label("Vehicle heading", systemImage: "location.circle")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
|
@ -189,23 +189,17 @@ struct PositionConfig: View {
|
|||
}
|
||||
Section(header: Text("Advanced Position Flags")) {
|
||||
|
||||
Toggle(isOn: $includeGeoidalSeparation) {
|
||||
|
||||
Text("Geoidal Seperation")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeDop) {
|
||||
|
||||
Text("Dilution of precision (DOP) PDOP used by default")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
|
||||
Toggle(isOn: $includeHvdop) {
|
||||
|
||||
Text("If DOP is set use, HDOP / VDOP values instead of PDOP")
|
||||
if includeDop {
|
||||
Toggle(isOn: $includeHvdop) {
|
||||
Text("If DOP is set use, HDOP / VDOP values instead of PDOP")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
}
|
||||
}
|
||||
.disabled(bleManager.connectedPeripheral == nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue