Friends and their log-sequence Numbers now get listed when receiving WANT-Vector

This commit is contained in:
severin.memmishofer 2023-07-15 16:18:16 +02:00
parent 653c2068e7
commit 1582f57eab
3 changed files with 13 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import CoreBluetooth
class BluetoothPeripheral: NSObject, ObservableObject {
@Published var incomingMsg: String = ""
@Published var wantVector: WantMessage = WantMessage()
private var peripheralManager: CBPeripheralManager?
let BLE_SERVICE_UUID = CBUUID(string: "6e400001-7646-4b5b-9a50-71becce51558")
@ -98,6 +99,7 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate {
// Use the received object to update your app state as needed
print("Received Write")
self.incomingMsg = receivedObject.printMsg()
self.wantVector = receivedObject
print(receivedObject.printMsg())
} catch {
print("Failed to decode JSON: \(error)")

View File

@ -55,6 +55,10 @@ extension BluetoothController: CBCentralManagerDelegate, CBPeripheralDelegate {
}
}
func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) {
// Not implemented yet
}
// func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
// print("Discovering services...")
// peripheral.discoverCharacteristics(BLE_CHARACTERISTIC_UUID_RX)

View File

@ -19,6 +19,12 @@ struct PeeringView: View {
}
.navigationTitle("Peering")
.navigationViewStyle(StackNavigationViewStyle())
List {
ForEach(btPeripheral.wantVector.friends.keys.sorted(), id: \.self) { friend in
Text("Feed: \(friend.description), SEQ: \(btPeripheral.wantVector.friends[friend] ?? -1)")
// Send new log Entries...
}
}
Text("Incoming msg: \(btPeripheral.incomingMsg)")
Button(action: {
do {
@ -51,6 +57,6 @@ struct WantMessage: Codable {
var friends = [String:Int]()
func printMsg() -> String {
return ("\(command) : \(friends.description)")
return ("{\(command) : \(friends.description)}")
}
}