mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 10:05:21 +00:00
better logging of device id
This commit is contained in:
@@ -121,7 +121,7 @@ class BluetoothGattServerManager(
|
||||
|
||||
when (newState) {
|
||||
BluetoothProfile.STATE_CONNECTED -> {
|
||||
Log.d(TAG, "Server: Device connected ${device.address}")
|
||||
Log.i(TAG, "Server: Device connected ${device.address}")
|
||||
val deviceConn = BluetoothConnectionTracker.DeviceConnection(
|
||||
device = device,
|
||||
isClient = false
|
||||
@@ -129,7 +129,7 @@ class BluetoothGattServerManager(
|
||||
connectionTracker.addDeviceConnection(device.address, deviceConn)
|
||||
}
|
||||
BluetoothProfile.STATE_DISCONNECTED -> {
|
||||
Log.d(TAG, "Server: Device disconnected ${device.address}")
|
||||
Log.i(TAG, "Server: Device disconnected ${device.address}")
|
||||
connectionTracker.cleanupDeviceConnection(device.address)
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class BluetoothGattServerManager(
|
||||
}
|
||||
|
||||
if (characteristic.uuid == CHARACTERISTIC_UUID) {
|
||||
Log.d(TAG, "Server: Received packet from ${device.address}, size: ${value.size} bytes")
|
||||
Log.i(TAG, "Server: Received packet from ${device.address}, size: ${value.size} bytes")
|
||||
val packet = BitchatPacket.fromBinaryData(value)
|
||||
if (packet != null) {
|
||||
val peerID = String(packet.senderID).replace("\u0000", "")
|
||||
|
||||
@@ -521,6 +521,27 @@ class BluetoothMeshService(private val context: Context) {
|
||||
*/
|
||||
fun getPeerRSSI(): Map<String, Int> = peerManager.getAllPeerRSSI()
|
||||
|
||||
/**
|
||||
* Get device address for a specific peer ID
|
||||
*/
|
||||
fun getDeviceAddressForPeer(peerID: String): String? {
|
||||
return connectionManager.addressPeerMap.entries.find { it.value == peerID }?.key
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all device addresses mapped to their peer IDs
|
||||
*/
|
||||
fun getDeviceAddressToPeerMapping(): Map<String, String> {
|
||||
return connectionManager.addressPeerMap.toMap()
|
||||
}
|
||||
|
||||
/**
|
||||
* Print device addresses for all connected peers
|
||||
*/
|
||||
fun printDeviceAddressesForPeers(): String {
|
||||
return peerManager.getDebugInfoWithDeviceAddresses(connectionManager.addressPeerMap)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get debug status information
|
||||
*/
|
||||
@@ -531,7 +552,7 @@ class BluetoothMeshService(private val context: Context) {
|
||||
appendLine()
|
||||
appendLine(connectionManager.getDebugInfo())
|
||||
appendLine()
|
||||
appendLine(peerManager.getDebugInfo())
|
||||
appendLine(peerManager.getDebugInfo(connectionManager.addressPeerMap))
|
||||
appendLine()
|
||||
appendLine(fragmentManager.getDebugInfo())
|
||||
appendLine()
|
||||
|
||||
@@ -183,7 +183,7 @@ class PeerManager {
|
||||
/**
|
||||
* Get debug information
|
||||
*/
|
||||
fun getDebugInfo(): String {
|
||||
fun getDebugInfo(addressPeerMap: Map<String, String>? = null): String {
|
||||
return buildString {
|
||||
appendLine("=== Peer Manager Debug Info ===")
|
||||
appendLine("Active Peers: ${activePeers.size}")
|
||||
@@ -191,13 +191,39 @@ class PeerManager {
|
||||
val nickname = peerNicknames[peerID] ?: "Unknown"
|
||||
val timeSince = (System.currentTimeMillis() - lastSeen) / 1000
|
||||
val rssi = peerRSSI[peerID]?.let { "${it} dBm" } ?: "No RSSI"
|
||||
appendLine(" - $peerID ($nickname) - last seen ${timeSince}s ago, RSSI: $rssi")
|
||||
|
||||
// Find device address for this peer ID
|
||||
val deviceAddress = addressPeerMap?.entries?.find { it.value == peerID }?.key
|
||||
val addressInfo = deviceAddress?.let { " [Device: $it]" } ?: " [Device: Unknown]"
|
||||
|
||||
appendLine(" - $peerID ($nickname)$addressInfo - last seen ${timeSince}s ago, RSSI: $rssi")
|
||||
}
|
||||
appendLine("Announced Peers: ${announcedPeers.size}")
|
||||
appendLine("Announced To Peers: ${announcedToPeers.size}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get debug information with device addresses
|
||||
*/
|
||||
fun getDebugInfoWithDeviceAddresses(addressPeerMap: Map<String, String>): String {
|
||||
return buildString {
|
||||
appendLine("=== Device Address to Peer Mapping ===")
|
||||
if (addressPeerMap.isEmpty()) {
|
||||
appendLine("No device address mappings available")
|
||||
} else {
|
||||
addressPeerMap.forEach { (deviceAddress, peerID) ->
|
||||
val nickname = peerNicknames[peerID] ?: "Unknown"
|
||||
val isActive = activePeers.containsKey(peerID)
|
||||
val status = if (isActive) "ACTIVE" else "INACTIVE"
|
||||
appendLine(" Device: $deviceAddress -> Peer: $peerID ($nickname) [$status]")
|
||||
}
|
||||
}
|
||||
appendLine()
|
||||
appendLine(getDebugInfo(addressPeerMap))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify delegate of peer list updates
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user