mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Bump version * update the translations (#1540) update the translations * Don't alert (with sound: .default) when updating Live Activity (#1536) * Fix adding channels (#1532) * Full translation into Spanish (#1529) * tapback with any emoji (#1538) * Call clearStaleNodes at start of sendWantConfig (#1535) * NFC Tag contact (#1537) * Accessorymanager background discovery (#1542) * Don't add new BLE devices to the device list in the backgournd * Bump version * Update Meshtastic/MeshtasticApp.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/MeshtasticApp.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert "Full translation into Spanish (#1529)" (#1543) This reverts commitf25fdfb89f. * Revert "update the translations (#1540)" (#1544) This reverts commitcb2fd8cc15. * Revert "NFC Tag contact (#1537)" (#1545) This reverts commit5c22b8b6e0. * Update Meshtastic/Views/Messages/TapbackInputView.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Helpers/EmojiOnlyTextField.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert "Accessorymanager background discovery (#1542)" (#1553) This reverts commit487f24b99a. * Update protobufs * Remove UI Kit code, clean up waypoint form emoji picker * Remove redundant nested Task in tapback emoji handler (#1552) * Initial plan * Remove nested Task block in tapback handler Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Delete empty file * Handle nil for emoji keyboard type extension * Remove UI kit method from waypoint form emoji picker * Remove UI kit emoji picker from tapback * Add Exchange User Info (#1550) * Emoji keyboard (#1559) * Add file missing from project, must have merged badly * Remove ui kit emoji keyboard * Discovery background fixes (#1561) * Make BLE Transport an actor to fix background discovery crashes * Protobufs * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Throw too many retries error again, remove return --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Increase connection timeout * Update protobufs * Revert "Fix adding channels (#1532)" (#1562) This reverts commitbff8ca018b. --------- Co-authored-by: MGJ <62177301+MGJ520@users.noreply.github.com> Co-authored-by: Mike Robbins <mrobbins@alum.mit.edu> Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Co-authored-by: Alvaro Samudio <alvarosamudio@protonmail.com> Co-authored-by: Mathew Kamkar <578302+matkam@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Brian Hardie <777730+bhardie@users.noreply.github.com>
85 lines
2.1 KiB
Swift
85 lines
2.1 KiB
Swift
//
|
|
// Transport.swift
|
|
// Meshtastic
|
|
//
|
|
// Created by Jake Bordens on 7/10/25.
|
|
//
|
|
|
|
import Foundation
|
|
import CommonCrypto
|
|
import SwiftUI
|
|
|
|
enum TransportType: String, CaseIterable, Codable {
|
|
case ble = "BLE"
|
|
case tcp = "TCP"
|
|
case serial = "Serial"
|
|
|
|
var icon: Image {
|
|
switch self {
|
|
case .ble:
|
|
Image("custom.bluetooth")
|
|
case .tcp:
|
|
Image(systemName: "network")
|
|
case .serial:
|
|
Image(systemName: "cable.connector.horizontal")
|
|
}
|
|
}
|
|
}
|
|
|
|
enum TransportStatus: Equatable {
|
|
case uninitialized
|
|
case ready
|
|
case discovering
|
|
case error(String)
|
|
}
|
|
|
|
enum DiscoveryEvent {
|
|
case deviceFound(Device)
|
|
case deviceUpdated(Device)
|
|
case deviceLost(UUID)
|
|
case deviceReportedRssi(UUID, Int)
|
|
}
|
|
|
|
protocol Transport {
|
|
var type: TransportType { get }
|
|
var status: TransportStatus { get async }
|
|
|
|
// Discovers devices asynchronously. For ongoing scans (e.g., BLE), this can yield via AsyncStream.
|
|
func discoverDevices() async -> AsyncStream<DiscoveryEvent>
|
|
|
|
// Connects to a device and returns a Connection.
|
|
func connect(to device: Device) async throws -> any Connection
|
|
|
|
var requiresPeriodicHeartbeat: Bool { get }
|
|
var supportsManualConnection: Bool { get }
|
|
|
|
func device(forManualConnection: String) -> Device?
|
|
func manuallyConnect(toDevice: Device) async throws
|
|
}
|
|
|
|
// Used to make stable-ish ID's for accessories that don't have a UUID
|
|
extension String {
|
|
func toUUIDFormatHash() -> UUID {
|
|
// Convert string to data
|
|
let data = self.data(using: .utf8) ?? Data()
|
|
|
|
// Create buffer for SHA-256 hash (32 bytes)
|
|
var digest = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
|
|
|
|
// Perform SHA-256 hashing
|
|
_ = data.withUnsafeBytes { buffer in
|
|
CC_SHA256(buffer.baseAddress, CC_LONG(buffer.count), &digest)
|
|
}
|
|
|
|
// Take first 16 bytes (128 bits) for UUID
|
|
let uuidBytes = Array(digest.prefix(16))
|
|
|
|
// Create UUID from bytes
|
|
return UUID(uuid: (
|
|
uuidBytes[0], uuidBytes[1], uuidBytes[2], uuidBytes[3],
|
|
uuidBytes[4], uuidBytes[5], uuidBytes[6], uuidBytes[7],
|
|
uuidBytes[8], uuidBytes[9], uuidBytes[10], uuidBytes[11],
|
|
uuidBytes[12], uuidBytes[13], uuidBytes[14], uuidBytes[15]
|
|
))
|
|
}
|
|
}
|