mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-14 04:42:03 +10:00
add flags for manual contact addition and telemetry mode handling
This commit is contained in:
@@ -163,6 +163,12 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
bool _autoAddRoomServers = false;
|
bool _autoAddRoomServers = false;
|
||||||
bool _autoAddSensors = false;
|
bool _autoAddSensors = false;
|
||||||
bool _overwriteOldest = false;
|
bool _overwriteOldest = false;
|
||||||
|
bool _manualAddContacts = false;
|
||||||
|
int _telemetryModeBase = 0;
|
||||||
|
int _telemetryModeLoc = 0;
|
||||||
|
int _telemetryModeEnv = 0;
|
||||||
|
int _advertLocPolicy = 0;
|
||||||
|
int _multiAcks = 0;
|
||||||
|
|
||||||
static const int _defaultMaxContacts = 32;
|
static const int _defaultMaxContacts = 32;
|
||||||
static const int _defaultMaxChannels = 8;
|
static const int _defaultMaxChannels = 8;
|
||||||
@@ -1095,6 +1101,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
await requestBatteryStatus(force: true);
|
await requestBatteryStatus(force: true);
|
||||||
await sendFrame(buildGetCustomVarsFrame());
|
await sendFrame(buildGetCustomVarsFrame());
|
||||||
await sendFrame(buildGetAutoAddFlagsFrame());
|
await sendFrame(buildGetAutoAddFlagsFrame());
|
||||||
|
|
||||||
_scheduleSelfInfoRetry();
|
_scheduleSelfInfoRetry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1980,6 +1987,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
break;
|
break;
|
||||||
case respCodeAutoAddConfig:
|
case respCodeAutoAddConfig:
|
||||||
_handleAutoAddConfig(frame);
|
_handleAutoAddConfig(frame);
|
||||||
|
_checkManualAddContacts();
|
||||||
break;
|
break;
|
||||||
case respCodeBattAndStorage:
|
case respCodeBattAndStorage:
|
||||||
_handleBatteryAndStorage(frame);
|
_handleBatteryAndStorage(frame);
|
||||||
@@ -2052,28 +2060,35 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
// [56] = sf
|
// [56] = sf
|
||||||
// [57] = cr
|
// [57] = cr
|
||||||
// [58+] = node_name
|
// [58+] = node_name
|
||||||
if (frame.length < 4 + pubKeySize) return;
|
final reader = BufferReader(frame);
|
||||||
|
try {
|
||||||
|
reader.skipBytes(2);
|
||||||
|
_currentTxPower = reader.readByte();
|
||||||
|
_maxTxPower = reader.readByte();
|
||||||
|
_selfPublicKey = reader.readBytes(pubKeySize);
|
||||||
|
_selfLatitude = reader.readInt32LE() / 1000000.0;
|
||||||
|
_selfLongitude = reader.readInt32LE() / 1000000.0;
|
||||||
|
_multiAcks = reader.readByte();
|
||||||
|
_advertLocPolicy = reader.readByte();
|
||||||
|
|
||||||
_currentTxPower = frame[2];
|
final telemetryFlag = reader.readByte();
|
||||||
_maxTxPower = frame[3];
|
_telemetryModeBase = telemetryFlag & 0x03;
|
||||||
_selfPublicKey = Uint8List.fromList(frame.sublist(4, 4 + pubKeySize));
|
_telemetryModeEnv = telemetryFlag >> 2 & 0x03;
|
||||||
_selfLatitude = readInt32LE(frame, 36) / 1000000.0;
|
_telemetryModeLoc = telemetryFlag >> 4 & 0x03;
|
||||||
_selfLongitude = readInt32LE(frame, 40) / 1000000.0;
|
|
||||||
|
|
||||||
if (frame.length >= 48 && frame[47] == 0x00) {
|
_manualAddContacts = reader.readByte() & 0x01 == 0x00;
|
||||||
sendFrame(buildSetOtherParamsFrame(0, 0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Radio settings (if frame is long enough)
|
_currentFreqHz = reader.readUInt32LE();
|
||||||
if (frame.length >= 58) {
|
_currentBwHz = reader.readUInt32LE();
|
||||||
_currentFreqHz = readUint32LE(frame, 48);
|
_currentSf = reader.readByte();
|
||||||
_currentBwHz = readUint32LE(frame, 52);
|
_currentCr = reader.readByte();
|
||||||
_currentSf = frame[56];
|
|
||||||
_currentCr = frame[57];
|
_selfName = reader.readString();
|
||||||
}
|
} catch (e) {
|
||||||
// Node name starts at offset 58 if frame is long enough
|
_appDebugLogService?.error(
|
||||||
if (frame.length > 58) {
|
'Error parsing SELF_INFO frame: $e',
|
||||||
_selfName = readCString(frame, 58, frame.length - 58);
|
tag: 'Connector',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_awaitingSelfInfo = false;
|
_awaitingSelfInfo = false;
|
||||||
_selfInfoRetryTimer?.cancel();
|
_selfInfoRetryTimer?.cancel();
|
||||||
@@ -2151,6 +2166,32 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _checkManualAddContacts() async {
|
||||||
|
// If manual add contacts is enabled, set auto add config and other params.
|
||||||
|
// and disable it after
|
||||||
|
if (_manualAddContacts) {
|
||||||
|
await sendFrame(
|
||||||
|
buildSetAutoAddConfigFrame(
|
||||||
|
autoAddChat: true,
|
||||||
|
autoAddRepeater: true,
|
||||||
|
autoAddRoomServer: true,
|
||||||
|
autoAddSensor: true,
|
||||||
|
overwriteOldest: _overwriteOldest,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await sendFrame(
|
||||||
|
buildSetOtherParamsFrame(
|
||||||
|
(_telemetryModeEnv << 4) |
|
||||||
|
(_telemetryModeLoc << 2) |
|
||||||
|
(_telemetryModeBase),
|
||||||
|
_advertLocPolicy,
|
||||||
|
_multiAcks,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_manualAddContacts = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Calculate timeout for a message based on radio settings and path length
|
/// Calculate timeout for a message based on radio settings and path length
|
||||||
/// Returns timeout in milliseconds, considering number of hops
|
/// Returns timeout in milliseconds, considering number of hops
|
||||||
int calculateTimeout({required int pathLength, int messageBytes = 100}) {
|
int calculateTimeout({required int pathLength, int messageBytes = 100}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user