mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #215 from meshtastic/share_channel
Save channel qr code
This commit is contained in:
commit
3e5308e51f
3 changed files with 68 additions and 36 deletions
|
|
@ -1067,12 +1067,72 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
if let decodedData = Data(base64Encoded: decodedString) {
|
||||
do {
|
||||
var channelSet: ChannelSet = try ChannelSet(serializedData: decodedData)
|
||||
var i:Int32 = 0
|
||||
for cs in channelSet.settings {
|
||||
|
||||
i += 1
|
||||
var chan = Channel()
|
||||
chan.settings = cs
|
||||
chan.index = i
|
||||
if i == 1 {
|
||||
chan.role = Channel.Role.primary
|
||||
} else {
|
||||
chan.role = Channel.Role.secondary
|
||||
}
|
||||
var adminPacket = AdminMessage()
|
||||
adminPacket.setChannel = chan
|
||||
var meshPacket: MeshPacket = MeshPacket()
|
||||
meshPacket.to = UInt32(connectedPeripheral.num)
|
||||
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
|
||||
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
|
||||
meshPacket.priority = MeshPacket.Priority.reliable
|
||||
meshPacket.wantAck = true
|
||||
meshPacket.hopLimit = 0
|
||||
var dataMessage = DataMessage()
|
||||
dataMessage.payload = try! adminPacket.serializedData()
|
||||
dataMessage.portnum = PortNum.adminApp
|
||||
meshPacket.decoded = dataMessage
|
||||
var toRadio: ToRadio!
|
||||
toRadio = ToRadio()
|
||||
toRadio.packet = meshPacket
|
||||
let binaryData: Data = try! toRadio.serializedData()
|
||||
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
|
||||
connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse)
|
||||
MeshLogger.log("💾 Saved a Channel for: \(String(connectedPeripheral.num))")
|
||||
}
|
||||
print(chan)
|
||||
}
|
||||
// Save the LoRa Config and the device will reboot
|
||||
var adminPacket = AdminMessage()
|
||||
adminPacket.setConfig.lora = channelSet.loraConfig
|
||||
|
||||
var meshPacket: MeshPacket = MeshPacket()
|
||||
meshPacket.to = UInt32(connectedPeripheral.num)
|
||||
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
|
||||
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
|
||||
|
||||
meshPacket.priority = MeshPacket.Priority.reliable
|
||||
meshPacket.wantAck = true
|
||||
meshPacket.hopLimit = 0
|
||||
|
||||
var dataMessage = DataMessage()
|
||||
dataMessage.payload = try! adminPacket.serializedData()
|
||||
dataMessage.portnum = PortNum.adminApp
|
||||
|
||||
meshPacket.decoded = dataMessage
|
||||
var toRadio: ToRadio!
|
||||
toRadio = ToRadio()
|
||||
toRadio.packet = meshPacket
|
||||
let binaryData: Data = try! toRadio.serializedData()
|
||||
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
|
||||
connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse)
|
||||
MeshLogger.log("💾 Saved a LoRaConfig for: \(String(connectedPeripheral.num))")
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
print(channelSet)
|
||||
} catch {
|
||||
print("Invalid Meshtastic QR Code Link")
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
import SwiftUI
|
||||
|
||||
struct SaveChannelQRCode: View {
|
||||
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
var channelSetLink: String
|
||||
var bleManager: BLEManager
|
||||
@State var connectedToDevice = false
|
||||
|
|
@ -23,6 +25,9 @@ struct SaveChannelQRCode: View {
|
|||
|
||||
Button {
|
||||
let success = bleManager.saveChannelSet(base64UrlString: channelSetLink)
|
||||
if success {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
|
||||
} label: {
|
||||
Label("Save", systemImage: "square.and.arrow.down")
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@ struct Settings: View {
|
|||
@EnvironmentObject var bleManager: BLEManager
|
||||
@EnvironmentObject var userSettings: UserSettings
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(key: "lastHeard", ascending: false)],
|
||||
animation: .default)
|
||||
|
||||
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "lastHeard", ascending: false)], animation: .default)
|
||||
private var nodes: FetchedResults<NodeInfoEntity>
|
||||
|
||||
var body: some View {
|
||||
|
|
@ -70,17 +67,14 @@ struct Settings: View {
|
|||
|
||||
BluetoothConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "antenna.radiowaves.left.and.right")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Bluetooth (BLE)")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
DeviceConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "flipphone")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
Text("Device")
|
||||
|
|
@ -89,7 +83,6 @@ struct Settings: View {
|
|||
NavigationLink {
|
||||
DisplayConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "display")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
Text("Display (Device Screen)")
|
||||
|
|
@ -101,7 +94,6 @@ struct Settings: View {
|
|||
|
||||
Image(systemName: "network")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Network (ESP32 Only)")
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +103,6 @@ struct Settings: View {
|
|||
|
||||
Image(systemName: "location")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Position")
|
||||
}
|
||||
|
||||
|
|
@ -131,77 +122,53 @@ struct Settings: View {
|
|||
NavigationLink {
|
||||
ExternalNotificationConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "megaphone")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("External Notification")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
MQTTConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "dot.radiowaves.right")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("MQTT (ESP32 Only)")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
RangeTestConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "point.3.connected.trianglepath.dotted")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Range Test (ESP32 Only)")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
SerialConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "terminal")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Serial")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
TelemetryConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
||||
Image(systemName: "chart.xyaxis.line")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Telemetry (Sensors)")
|
||||
}
|
||||
}
|
||||
Section(header: Text("Logging")) {
|
||||
|
||||
NavigationLink {
|
||||
|
||||
MeshLog()
|
||||
|
||||
} label: {
|
||||
|
||||
Image(systemName: "list.bullet.rectangle")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Mesh Log")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
|
||||
let connectedNode = nodes.first(where: { $0.num == connectedNodeNum })
|
||||
|
||||
AdminMessageList(user: connectedNode?.user)
|
||||
} label: {
|
||||
|
||||
Image(systemName: "building.columns")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
|
||||
Text("Admin Message Log")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue