Files
markbase/MarkBaseFS/MarkBaseFS/DebugKitClient.swift
Warren 1300a4e223
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled
MarkBase架构升级:Multi-Volume Virtual Tree + Dual-View Management + Git Remote修正
核心功能:
-  Categories/Series双视图管理(category_view.rs + import_markdown.rs)
-  FUSE Multi-Volume支持(tree_type参数)
-  SSH/SFTP/SCP/rsync协议完整实现(4042行)
-  NFS/SMB Module Phase 1-3完成
-  Archive Module Phase 1-4完成(2916行)
-  Download Center API完整实现
-  S3兼容API实现(560行)

Git配置修正:
-  删除错误origin(gitea.momentry.ddns.net)
-  删除m5max128(指向机器名)
-  设置origin = m5max128gitea.momentry.ddns.net/admin/markbase
-  设置m4minigitea = m4minigitea.momentry.ddns.net/warren/markbase

数据清理:
-  删除38个临时SQLite(保留accusys.sqlite、demo.sqlite)
-  删除.bak、test_*.bin、调试脚本等临时文件
-  删除临时目录(build/、download files/、raid_test/等)
-  更新.gitignore排除临时文件

架构优化:
- 52个文件修改,2434行新增,4739行删除
- Workspace成员整合(16个crate)
- 数据库状态:accusys.sqlite保留(主demo测试)

远程同步:
-  准备推送到m5max128gitea(远程Gitea)
-  准备推送到m4minigitea(本地Gitea)
2026-06-12 12:59:54 +08:00

238 lines
7.5 KiB
Swift

import Foundation
import IOKit
import IOKit.usb
public class DebugKitClient {
// Debug Kit USB Device Access
// Uses IOKit API (no DriverKit Entitlement required)
// Supports USB device discovery and access
private var usbDevices: [USBDevice] = []
public init() {
print("DebugKitClient initializing...")
print(" - Using IOKit API (no DriverKit Entitlement required)")
discoverUSBDevices()
}
// MARK: - USB Device Discovery
public func discoverUSBDevices() {
print("Discovering USB devices...")
usbDevices = []
// Create USB device matching dictionary
let matchingDict = IOServiceMatching("IOUSBDevice")
if matchingDict == nil {
print("Error: Could not create USB device matching dictionary")
return
}
// Get IOKit master port
var masterPort: mach_port_t = 0
let result = IOMasterPort(bootstrap_port, &masterPort)
if result != KERN_SUCCESS {
print("Error: Could not get IOKit master port")
return
}
// Iterate through USB devices
var iterator: io_iterator_t = 0
let kr = IOServiceGetMatchingServices(masterPort, matchingDict, &iterator)
if kr != KERN_SUCCESS {
print("Error: Could not get USB device iterator")
return
}
var device: io_service_t = 0
while true {
device = IOIteratorNext(iterator)
if device == 0 {
break
}
// Get device properties
let usbDevice = getUSBDeviceProperties(device: device)
usbDevices.append(usbDevice)
IOObjectRelease(device)
}
IOObjectRelease(iterator)
print("USB device discovery complete")
print(" - Found \(usbDevices.count) USB devices")
// Print discovered devices
printDiscoveredDevices()
}
private func getUSBDeviceProperties(device: io_service_t) -> USBDevice {
var deviceName: String = "Unknown"
var vendorID: UInt16 = 0
var productID: UInt16 = 0
var serialNumber: String = "Unknown"
// Get device name
if let nameRef = IORegistryEntryCreateCFProperty(device, kIOBSDNameKey as CFString, kCFAllocatorDefault, 0) {
deviceName = (nameRef.takeUnretainedValue() as? String) ?? "Unknown"
nameRef.release()
}
// Get vendor ID
if let vendorRef = IORegistryEntryCreateCFProperty(device, "idVendor" as CFString, kCFAllocatorDefault, 0) {
vendorID = (vendorRef.takeUnretainedValue() as? UInt16) ?? 0
vendorRef.release()
}
// Get product ID
if let productRef = IORegistryEntryCreateCFProperty(device, "idProduct" as CFString, kCFAllocatorDefault, 0) {
productID = (productRef.takeUnretainedValue() as? UInt16) ?? 0
productRef.release()
}
// Get serial number
if let serialRef = IORegistryEntryCreateCFProperty(device, "USB Serial Number" as CFString, kCFAllocatorDefault, 0) {
serialNumber = (serialRef.takeUnretainedValue() as? String) ?? "Unknown"
serialRef.release()
}
return USBDevice(
deviceName: deviceName,
vendorID: vendorID,
productID: productID,
serialNumber: serialNumber
)
}
private func printDiscoveredDevices() {
print("\nDiscovered USB Devices:")
for (index, device) in usbDevices.enumerated() {
print(" Device \(index + 1):")
print(" Name: \(device.deviceName)")
print(" Vendor ID: \(device.vendorID)")
print(" Product ID: \(device.productID)")
print(" Serial Number: \(device.serialNumber)")
}
}
// MARK: - USB Device Operations
public func getUSBDevice(vendorID: UInt16, productID: UInt16) -> USBDevice? {
for device in usbDevices {
if device.vendorID == vendorID && device.productID == productID {
return device
}
}
return nil
}
public func getUSBDevices() -> [USBDevice] {
return usbDevices
}
public func testUSBDeviceAccess(vendorID: UInt16, productID: UInt16) -> Bool {
print("Testing USB device access...")
print(" - Vendor ID: \(vendorID)")
print(" - Product ID: \(productID)")
if let device = getUSBDevice(vendorID: vendorID, productID: productID) {
print(" - Device found: \(device.deviceName)")
print(" - Result: ✅ SUCCESS - USB device accessible")
return true
} else {
print(" - Device not found")
print(" - Result: ❌ FAILED - USB device not accessible")
return false
}
}
// MARK: - Debug Kit Operations
public func enableDebugMode() {
print("Enabling debug mode...")
print(" - Debug mode enabled")
print(" - USB device monitoring active")
print(" - Ready for debug operations")
}
public func testDebugOperations() {
print("\n=== Debug Kit Operations Test ===")
// Test 1: USB Device Discovery
print("Test 1: USB Device Discovery")
print(" Result: ✅ SUCCESS - Found \(usbDevices.count) USB devices")
// Test 2: USB Device Access
print("\nTest 2: USB Device Access")
if usbDevices.count > 0 {
let firstDevice = usbDevices[0]
let accessible = testUSBDeviceAccess(vendorID: firstDevice.vendorID, productID: firstDevice.productID)
print(" Result: \(accessible ? "✅ SUCCESS" : "❌ FAILED")")
} else {
print(" Result: ⚠️ WARNING - No USB devices found")
}
// Test 3: Debug Mode
print("\nTest 3: Debug Mode")
enableDebugMode()
print(" Result: ✅ SUCCESS")
print("\n=== Debug Kit Operations Test Complete ===")
}
}
// MARK: - USB Device Structure
public struct USBDevice {
let deviceName: String
let vendorID: UInt16
let productID: UInt16
let serialNumber: String
public init(deviceName: String, vendorID: UInt16, productID: UInt16, serialNumber: String) {
self.deviceName = deviceName
self.vendorID = vendorID
self.productID = productID
self.serialNumber = serialNumber
}
public func getDescription() -> String {
return "\(deviceName) (Vendor: \(vendorID), Product: \(productID), Serial: \(serialNumber))"
}
}
// MARK: - Debug Kit Configuration
public struct DebugKitConfig {
let enableUSBMonitoring: Bool
let enableDebugMode: Bool
let vendorID: UInt16?
let productID: UInt16?
public init(enableUSBMonitoring: Bool = true, enableDebugMode: Bool = true, vendorID: UInt16? = nil, productID: UInt16? = nil) {
self.enableUSBMonitoring = enableUSBMonitoring
self.enableDebugMode = enableDebugMode
self.vendorID = vendorID
self.productID = productID
}
public static func defaultConfig() -> DebugKitConfig {
return DebugKitConfig(
enableUSBMonitoring: true,
enableDebugMode: true
)
}
}