mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Implement optimized contact fetching by public key to enhance performance
This commit is contained in:
@@ -311,6 +311,20 @@ class MeshCoreBleService {
|
||||
await _commandSender.writeData(FrameBuilder.buildGetContacts());
|
||||
}
|
||||
|
||||
/// Get a single contact by public key from device
|
||||
///
|
||||
/// This is more efficient than getContacts() when you only need to refresh
|
||||
/// one specific contact (e.g., after receiving an advertisement).
|
||||
///
|
||||
/// The contact will be delivered via the onContactReceived callback.
|
||||
Future<void> getContactByKey(Uint8List publicKey) async {
|
||||
debugPrint('🔍 [BLE] Requesting single contact by key:');
|
||||
debugPrint(
|
||||
' Public key prefix: ${publicKey.sublist(0, 6).map((b) => b.toRadixString(16).padLeft(2, '0')).join(':')}...',
|
||||
);
|
||||
await _commandSender.writeData(FrameBuilder.buildGetContactByKey(publicKey));
|
||||
}
|
||||
|
||||
/// Manually add or update a contact on the companion radio
|
||||
Future<void> addOrUpdateContact(Contact contact) async {
|
||||
debugPrint('📝 [BLE] Adding/updating contact on companion radio:');
|
||||
|
||||
@@ -39,6 +39,7 @@ class MeshCoreConstants {
|
||||
static const int cmdSendRawData = 25;
|
||||
static const int cmdSendLogin = 26;
|
||||
static const int cmdSendStatusReq = 27;
|
||||
static const int cmdGetContactByKey = 30;
|
||||
static const int cmdGetChannel = 31;
|
||||
static const int cmdSetChannel = 32;
|
||||
static const int cmdSignStart = 33;
|
||||
|
||||
@@ -59,6 +59,8 @@ class MeshCoreOpcodeNames {
|
||||
return 'SEND_LOGIN';
|
||||
case MeshCoreConstants.cmdSendStatusReq:
|
||||
return 'SEND_STATUS_REQ';
|
||||
case MeshCoreConstants.cmdGetContactByKey:
|
||||
return 'GET_CONTACT_BY_KEY';
|
||||
case MeshCoreConstants.cmdGetChannel:
|
||||
return 'GET_CHANNEL';
|
||||
case MeshCoreConstants.cmdSetChannel:
|
||||
|
||||
@@ -31,6 +31,14 @@ class FrameBuilder {
|
||||
return writer.toBytes();
|
||||
}
|
||||
|
||||
/// Build GetContactByKey command - retrieves a single contact by public key
|
||||
static Uint8List buildGetContactByKey(Uint8List publicKey) {
|
||||
final writer = BufferWriter();
|
||||
writer.writeByte(MeshCoreConstants.cmdGetContactByKey); // 0x1E (30)
|
||||
writer.writeBytes(publicKey); // 32 bytes
|
||||
return writer.toBytes();
|
||||
}
|
||||
|
||||
/// Build AddUpdateContact command
|
||||
static Uint8List buildAddUpdateContact(Contact contact) {
|
||||
final writer = BufferWriter();
|
||||
|
||||
Reference in New Issue
Block a user