feat(#769): stock and Offband fake radio profiles from protocol manifests
tool/fake_radio/gen_protocol_manifest.py reads companion firmware source at a git ref and emits the manifest format proposed in OffbandMesh/meshcore-firmware#1318. Pinned copies, verified identical to the generator's output: - offband-v1.5.0-beta7 (53951759): code 22, MeshCore base v1.17.0 - companion-v1.17.1 (stock, d9296435): code 13 FakeRadioProfile.fromManifest takes codes, bits and the DEVICE_INFO version string (offbandClientVersion() derivation) from the manifest; naming a bit the manifest lacks throws instead of reading 0. Offband answers GPS status, the block list (BlockStore dedup/swap-remove semantics) and the packet-hash query; stock rejects every Offband command as unsupported. Found writing it: the A2 default had OFFBAND_CAP_CAPLOG as 0x08 (it is 0x20) and the version string as 1.5.0-1.17.1 (beta7 is on v1.17.0). Both now come from the manifest. 27 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>feat/756-fake-radio-core
parent
a0df51274e
commit
39977787f8
@ -0,0 +1,163 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../support/fake_radio/fake_radio.dart';
|
||||
import '../support/fake_radio/fake_radio_codes.dart';
|
||||
import '../support/fake_radio/fake_radio_manifest.dart';
|
||||
import '../support/fake_radio/fake_radio_profile.dart';
|
||||
|
||||
Uint8List _cmd(List<int> b) => Uint8List.fromList(b);
|
||||
|
||||
void main() {
|
||||
group('pinned manifests (#769)', () {
|
||||
test('Offband: offband-v1.5.0-beta7 on MeshCore v1.17.0, code 22', () {
|
||||
final m = FakeRadioManifest.pinnedOffband();
|
||||
expect(m.isOffband, isTrue);
|
||||
expect(m.ref, 'offband-v1.5.0-beta7');
|
||||
expect(m.firmwareVerCode, 22);
|
||||
expect(m.firmwareVersion, 'v1.17.0');
|
||||
expect(m.deviceInfoVersion, '1.5.0-1.17.0');
|
||||
expect(m.offbandCaps['OFFBAND_CAP_CAPLOG'], 0x20);
|
||||
expect(m.offbandCommands['CMD_OFFBAND_PKT_HASH'], 0xC6);
|
||||
});
|
||||
|
||||
test('stock: companion-v1.17.1, code 13, no Offband anything', () {
|
||||
final m = FakeRadioManifest.pinnedStock();
|
||||
expect(m.isOffband, isFalse);
|
||||
expect(m.firmwareVerCode, 13);
|
||||
expect(m.deviceInfoVersion, 'v1.17.1');
|
||||
expect(m.offbandCaps, isEmpty);
|
||||
expect(m.offbandCommands, isEmpty);
|
||||
});
|
||||
|
||||
test('a wrong format or a newer format_version is refused', () {
|
||||
expect(
|
||||
() => FakeRadioManifest.parse(jsonEncode({'format': 'x'})),
|
||||
throwsFormatException,
|
||||
);
|
||||
expect(
|
||||
() => FakeRadioManifest.parse(
|
||||
jsonEncode({
|
||||
'format': 'offband-protocol-manifest',
|
||||
'format_version': 2,
|
||||
}),
|
||||
),
|
||||
throwsFormatException,
|
||||
);
|
||||
});
|
||||
|
||||
test('a capability the manifest lacks fails loudly, never reads as 0', () {
|
||||
final m = FakeRadioManifest.pinnedOffband();
|
||||
expect(() => m.capsOf(['OFFBAND_CAP_NOPE']), throwsStateError);
|
||||
expect(
|
||||
() => FakeRadioProfile.fromManifest(m, caps: ['OFFBAND_CAP_NOPE']),
|
||||
throwsStateError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('profiles', () {
|
||||
test('Offband defaults to the bits every companion sets', () {
|
||||
final p = FakeRadioProfile.offband();
|
||||
expect(p.offbandCaps, 0x02 | 0x20); // BLOCK | CAPLOG
|
||||
expect(p.offbandCaps2, 0x08); // PKT_HASH
|
||||
});
|
||||
|
||||
test('board bits can be named', () {
|
||||
final p = FakeRadioProfile.fromManifest(
|
||||
FakeRadioManifest.pinnedOffband(),
|
||||
caps: ['OFFBAND_CAP_BLOCK', 'OFFBAND_CAP_FEM_LNA'],
|
||||
caps2: ['OFFBAND_CAP2_NOTIFY_SCOPE'],
|
||||
);
|
||||
expect(p.offbandCaps, 0x06);
|
||||
expect(p.offbandCaps2, 0x01);
|
||||
});
|
||||
|
||||
test('stock rejects every Offband command as unsupported', () {
|
||||
final radio = FakeRadio(profile: FakeRadioProfile.stock());
|
||||
for (final code in [
|
||||
fwOffbandConfig,
|
||||
fwOffbandGps,
|
||||
fwOffbandBlock,
|
||||
fwOffbandPktHash,
|
||||
]) {
|
||||
expect(radio.handle(_cmd([code, fwBlockList])).single, [
|
||||
fwRespErr,
|
||||
fwErrUnsupportedCmd,
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('Offband commands', () {
|
||||
final key = List<int>.filled(fwPubKeySize, 0x42);
|
||||
final other = List<int>.filled(fwPubKeySize, 0x43);
|
||||
|
||||
test('block: add dedups, remove swaps, list streams start/keys/end', () {
|
||||
final radio = FakeRadio();
|
||||
expect(radio.handle(_cmd([fwOffbandBlock, fwBlockAdd, ...key])).single, [
|
||||
fwOffbandBlock,
|
||||
fwBlockAdd,
|
||||
1,
|
||||
]);
|
||||
// A repeat is still OK (BlockStore dedup).
|
||||
expect(
|
||||
radio.handle(_cmd([fwOffbandBlock, fwBlockAdd, ...key])).single[2],
|
||||
1,
|
||||
);
|
||||
radio.handle(_cmd([fwOffbandBlock, fwBlockAdd, ...other]));
|
||||
final list = radio.handle(_cmd([fwOffbandBlock, fwBlockList]));
|
||||
expect(list.first, [fwOffbandBlock, fwBlockList, 0xFF, 2]);
|
||||
expect(list[1].sublist(3), key);
|
||||
expect(list.last, [fwOffbandBlock, fwBlockList, 0xFE]);
|
||||
|
||||
expect(
|
||||
radio.handle(_cmd([fwOffbandBlock, fwBlockRemove, ...key])).single[2],
|
||||
1,
|
||||
);
|
||||
expect(radio.blockedKeys.single, other);
|
||||
expect(
|
||||
radio.handle(_cmd([fwOffbandBlock, fwBlockRemove, ...key])).single[2],
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
test('GPS status reply is "enabled=N " plus board text, NUL-ended', () {
|
||||
final f = FakeRadio().handle(_cmd([fwOffbandGps])).single;
|
||||
expect(f[0], fwOffbandGps);
|
||||
expect(f.last, 0);
|
||||
expect(utf8.decode(f.sublist(1, f.length - 1)), 'enabled=0 detected=0');
|
||||
});
|
||||
|
||||
test('packet hash: unknown key, or malformed when not 7 bytes', () {
|
||||
final radio = FakeRadio();
|
||||
expect(
|
||||
radio.handle(_cmd([fwOffbandPktHash, fwPktHashGet, 1, 2, 3, 4, 0])),
|
||||
[
|
||||
[fwOffbandPktHash, fwPktHashErr, fwPktHashErrUnknownKey],
|
||||
],
|
||||
);
|
||||
expect(radio.handle(_cmd([fwOffbandPktHash, fwPktHashGet, 1])).single, [
|
||||
fwOffbandPktHash,
|
||||
fwPktHashErr,
|
||||
fwPktHashErrMalformed,
|
||||
]);
|
||||
});
|
||||
|
||||
test('commands needing unadvertised bits are unsupported', () {
|
||||
final radio = FakeRadio();
|
||||
for (final code in [
|
||||
fwOffbandConfig,
|
||||
fwOffbandFemLna,
|
||||
fwOffbandDeviceUi,
|
||||
]) {
|
||||
expect(radio.handle(_cmd([code, 0])).single, [
|
||||
fwRespErr,
|
||||
fwErrUnsupportedCmd,
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
/// A firmware protocol manifest (#769): the codes, capability bits and version
|
||||
/// a firmware build defines, generated from its source. Today's copies are
|
||||
/// pinned under `manifests/` by `tool/fake_radio/gen_protocol_manifest.py`;
|
||||
/// OffbandMesh/meshcore-firmware#1318 will publish them from firmware CI.
|
||||
class FakeRadioManifest {
|
||||
FakeRadioManifest._(this.json);
|
||||
|
||||
factory FakeRadioManifest.parse(String text) {
|
||||
final json = jsonDecode(text) as Map<String, dynamic>;
|
||||
if (json['format'] != 'offband-protocol-manifest') {
|
||||
throw FormatException('not a protocol manifest: ${json['format']}');
|
||||
}
|
||||
if (json['format_version'] != 1) {
|
||||
throw FormatException(
|
||||
'unsupported manifest format_version ${json['format_version']}',
|
||||
);
|
||||
}
|
||||
return FakeRadioManifest._(json);
|
||||
}
|
||||
|
||||
factory FakeRadioManifest.load(String path) =>
|
||||
FakeRadioManifest.parse(File(path).readAsStringSync());
|
||||
|
||||
static const String _dir = 'test/support/fake_radio/manifests';
|
||||
|
||||
/// The Offband release the fake's Offband profile is pinned to.
|
||||
static FakeRadioManifest pinnedOffband() =>
|
||||
FakeRadioManifest.load('$_dir/offband-v1.5.0-beta7.json');
|
||||
|
||||
/// The upstream MeshCore release the fake's stock profile is pinned to.
|
||||
static FakeRadioManifest pinnedStock() =>
|
||||
FakeRadioManifest.load('$_dir/stock-companion-v1.17.1.json');
|
||||
|
||||
final Map<String, dynamic> json;
|
||||
|
||||
Map<String, dynamic> get _firmware =>
|
||||
json['firmware'] as Map<String, dynamic>;
|
||||
|
||||
String get flavor => _firmware['flavor'] as String;
|
||||
bool get isOffband => flavor == 'offband';
|
||||
String get ref => _firmware['ref'] as String;
|
||||
String get commit => _firmware['commit'] as String;
|
||||
|
||||
/// `FIRMWARE_VERSION`, the MeshCore base, e.g. `v1.17.0`.
|
||||
String get firmwareVersion => _firmware['firmware_version'] as String;
|
||||
int get firmwareVerCode => _firmware['firmware_ver_code'] as int;
|
||||
|
||||
Map<String, int> section(String name) =>
|
||||
(json[name] as Map<String, dynamic>).map((k, v) => MapEntry(k, v as int));
|
||||
|
||||
Map<String, int> get commands => section('commands');
|
||||
Map<String, int> get responses => section('responses');
|
||||
Map<String, int> get pushes => section('pushes');
|
||||
Map<String, int> get errors => section('errors');
|
||||
Map<String, int> get offbandCommands => section('offband_commands');
|
||||
Map<String, int> get offbandResponses => section('offband_responses');
|
||||
Map<String, int> get offbandCaps => section('offband_caps');
|
||||
Map<String, int> get offbandCaps2 => section('offband_caps2');
|
||||
|
||||
/// OR of the named capability bits; throws if the manifest lacks one, so a
|
||||
/// renamed or removed bit fails loudly instead of reading as 0.
|
||||
int capsOf(Iterable<String> names, {bool second = false}) {
|
||||
final table = second ? offbandCaps2 : offbandCaps;
|
||||
var bits = 0;
|
||||
for (final n in names) {
|
||||
final v = table[n];
|
||||
if (v == null) throw StateError('$ref defines no $n');
|
||||
bits |= v;
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
/// The 20-byte DEVICE_INFO version field this build reports.
|
||||
///
|
||||
/// Offband: `offbandClientVersion()` (MyMesh.cpp:1761), the Offband core,
|
||||
/// a '-', then the MeshCore core (e.g. `1.5.0-1.17.0`); each core is cut at
|
||||
/// its first '-', with the 'v' stripped from the MeshCore one. Stock:
|
||||
/// `FIRMWARE_VERSION` as is.
|
||||
String get deviceInfoVersion {
|
||||
if (!isOffband) return firmwareVersion;
|
||||
var mc = firmwareVersion;
|
||||
if (mc.startsWith('v') || mc.startsWith('V')) mc = mc.substring(1);
|
||||
mc = mc.split('-').first;
|
||||
final at = ref.indexOf('offband-v');
|
||||
if (at < 0) return mc;
|
||||
final ob = ref.substring(at + 'offband-v'.length).split('-').first;
|
||||
return ob.isEmpty ? mc : '$ob-$mc';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,159 @@
|
||||
{
|
||||
"commands": {
|
||||
"CMD_ADD_UPDATE_CONTACT": 9,
|
||||
"CMD_APP_START": 1,
|
||||
"CMD_DEVICE_QUERY": 22,
|
||||
"CMD_EXPORT_CONTACT": 17,
|
||||
"CMD_EXPORT_PRIVATE_KEY": 23,
|
||||
"CMD_FACTORY_RESET": 51,
|
||||
"CMD_GET_ADVERT_PATH": 42,
|
||||
"CMD_GET_ALLOWED_REPEAT_FREQ": 60,
|
||||
"CMD_GET_AUTOADD_CONFIG": 59,
|
||||
"CMD_GET_BATT_AND_STORAGE": 20,
|
||||
"CMD_GET_CHANNEL": 31,
|
||||
"CMD_GET_CONTACTS": 4,
|
||||
"CMD_GET_CONTACT_BY_KEY": 30,
|
||||
"CMD_GET_CUSTOM_VARS": 40,
|
||||
"CMD_GET_DEFAULT_FLOOD_SCOPE": 64,
|
||||
"CMD_GET_DEVICE_TIME": 5,
|
||||
"CMD_GET_STATS": 56,
|
||||
"CMD_GET_TUNING_PARAMS": 43,
|
||||
"CMD_HAS_CONNECTION": 28,
|
||||
"CMD_IMPORT_CONTACT": 18,
|
||||
"CMD_IMPORT_PRIVATE_KEY": 24,
|
||||
"CMD_LOGOUT": 29,
|
||||
"CMD_REBOOT": 19,
|
||||
"CMD_REMOVE_CONTACT": 15,
|
||||
"CMD_RESET_PATH": 13,
|
||||
"CMD_SEND_ANON_REQ": 57,
|
||||
"CMD_SEND_BINARY_REQ": 50,
|
||||
"CMD_SEND_CHANNEL_DATA": 62,
|
||||
"CMD_SEND_CHANNEL_TXT_MSG": 3,
|
||||
"CMD_SEND_CONTROL_DATA": 55,
|
||||
"CMD_SEND_LOGIN": 26,
|
||||
"CMD_SEND_PATH_DISCOVERY_REQ": 52,
|
||||
"CMD_SEND_RAW_DATA": 25,
|
||||
"CMD_SEND_RAW_PACKET": 65,
|
||||
"CMD_SEND_SELF_ADVERT": 7,
|
||||
"CMD_SEND_STATUS_REQ": 27,
|
||||
"CMD_SEND_TELEMETRY_REQ": 39,
|
||||
"CMD_SEND_TRACE_PATH": 36,
|
||||
"CMD_SEND_TXT_MSG": 2,
|
||||
"CMD_SET_ADVERT_LATLON": 14,
|
||||
"CMD_SET_ADVERT_NAME": 8,
|
||||
"CMD_SET_AUTOADD_CONFIG": 58,
|
||||
"CMD_SET_CHANNEL": 32,
|
||||
"CMD_SET_CUSTOM_VAR": 41,
|
||||
"CMD_SET_DEFAULT_FLOOD_SCOPE": 63,
|
||||
"CMD_SET_DEVICE_PIN": 37,
|
||||
"CMD_SET_DEVICE_TIME": 6,
|
||||
"CMD_SET_FLOOD_SCOPE_KEY": 54,
|
||||
"CMD_SET_OTHER_PARAMS": 38,
|
||||
"CMD_SET_PATH_HASH_MODE": 61,
|
||||
"CMD_SET_RADIO_PARAMS": 11,
|
||||
"CMD_SET_RADIO_TX_POWER": 12,
|
||||
"CMD_SET_TUNING_PARAMS": 21,
|
||||
"CMD_SHARE_CONTACT": 16,
|
||||
"CMD_SIGN_DATA": 34,
|
||||
"CMD_SIGN_FINISH": 35,
|
||||
"CMD_SIGN_START": 33,
|
||||
"CMD_SYNC_NEXT_MESSAGE": 10
|
||||
},
|
||||
"errors": {
|
||||
"ERR_CODE_BAD_STATE": 4,
|
||||
"ERR_CODE_FILE_IO_ERROR": 5,
|
||||
"ERR_CODE_ILLEGAL_ARG": 6,
|
||||
"ERR_CODE_NOT_FOUND": 2,
|
||||
"ERR_CODE_TABLE_FULL": 3,
|
||||
"ERR_CODE_UNSUPPORTED_CMD": 1
|
||||
},
|
||||
"firmware": {
|
||||
"commit": "53951759bceb4a6b4a90aac55d9ae9829712abf5",
|
||||
"firmware_ver_code": 22,
|
||||
"firmware_version": "v1.17.0",
|
||||
"flavor": "offband",
|
||||
"ref": "offband-v1.5.0-beta7"
|
||||
},
|
||||
"format": "offband-protocol-manifest",
|
||||
"format_version": 1,
|
||||
"generated_by": "meshcore-client tool/fake_radio/gen_protocol_manifest.py",
|
||||
"offband_caps": {
|
||||
"OFFBAND_CAP_BLOCK": 2,
|
||||
"OFFBAND_CAP_CAPLOG": 32,
|
||||
"OFFBAND_CAP_FEM_LNA": 4,
|
||||
"OFFBAND_CAP_WIFI_OBSERVER": 1
|
||||
},
|
||||
"offband_caps2": {
|
||||
"OFFBAND_CAP2_BUTTON_MATRIX": 2,
|
||||
"OFFBAND_CAP2_INDICATORS": 4,
|
||||
"OFFBAND_CAP2_NOTIFY_SCOPE": 1,
|
||||
"OFFBAND_CAP2_PKT_HASH": 8
|
||||
},
|
||||
"offband_commands": {
|
||||
"CMD_OFFBAND_BLOCK": 194,
|
||||
"CMD_OFFBAND_CAPLOG": 196,
|
||||
"CMD_OFFBAND_CONFIG": 192,
|
||||
"CMD_OFFBAND_DEVICE_UI": 197,
|
||||
"CMD_OFFBAND_FEM_LNA": 195,
|
||||
"CMD_OFFBAND_GPS": 193,
|
||||
"CMD_OFFBAND_PKT_HASH": 198
|
||||
},
|
||||
"offband_responses": {
|
||||
"RESP_CODE_OFFBAND_BLOCK": 194,
|
||||
"RESP_CODE_OFFBAND_CAPLOG": 196,
|
||||
"RESP_CODE_OFFBAND_CONFIG": 192,
|
||||
"RESP_CODE_OFFBAND_DEVICE_UI": 197,
|
||||
"RESP_CODE_OFFBAND_FEM_LNA": 195,
|
||||
"RESP_CODE_OFFBAND_GPS": 193,
|
||||
"RESP_CODE_OFFBAND_PKT_HASH": 198
|
||||
},
|
||||
"pushes": {
|
||||
"PUSH_CODE_ADVERT": 128,
|
||||
"PUSH_CODE_BINARY_RESPONSE": 140,
|
||||
"PUSH_CODE_CONTACTS_FULL": 144,
|
||||
"PUSH_CODE_CONTACT_DELETED": 143,
|
||||
"PUSH_CODE_CONTROL_DATA": 142,
|
||||
"PUSH_CODE_LOGIN_FAIL": 134,
|
||||
"PUSH_CODE_LOGIN_SUCCESS": 133,
|
||||
"PUSH_CODE_LOG_RX_DATA": 136,
|
||||
"PUSH_CODE_MSG_WAITING": 131,
|
||||
"PUSH_CODE_NEW_ADVERT": 138,
|
||||
"PUSH_CODE_PATH_DISCOVERY_RESPONSE": 141,
|
||||
"PUSH_CODE_PATH_UPDATED": 129,
|
||||
"PUSH_CODE_RAW_DATA": 132,
|
||||
"PUSH_CODE_SEND_CONFIRMED": 130,
|
||||
"PUSH_CODE_STATUS_RESPONSE": 135,
|
||||
"PUSH_CODE_TELEMETRY_RESPONSE": 139,
|
||||
"PUSH_CODE_TRACE_DATA": 137
|
||||
},
|
||||
"responses": {
|
||||
"RESP_CODE_ADVERT_PATH": 22,
|
||||
"RESP_CODE_AUTOADD_CONFIG": 25,
|
||||
"RESP_CODE_BATT_AND_STORAGE": 12,
|
||||
"RESP_CODE_CHANNEL_DATA_RECV": 27,
|
||||
"RESP_CODE_CHANNEL_INFO": 18,
|
||||
"RESP_CODE_CHANNEL_MSG_RECV": 8,
|
||||
"RESP_CODE_CHANNEL_MSG_RECV_V3": 17,
|
||||
"RESP_CODE_CONTACT": 3,
|
||||
"RESP_CODE_CONTACTS_START": 2,
|
||||
"RESP_CODE_CONTACT_MSG_RECV": 7,
|
||||
"RESP_CODE_CONTACT_MSG_RECV_V3": 16,
|
||||
"RESP_CODE_CURR_TIME": 9,
|
||||
"RESP_CODE_CUSTOM_VARS": 21,
|
||||
"RESP_CODE_DEFAULT_FLOOD_SCOPE": 28,
|
||||
"RESP_CODE_DEVICE_INFO": 13,
|
||||
"RESP_CODE_DISABLED": 15,
|
||||
"RESP_CODE_END_OF_CONTACTS": 4,
|
||||
"RESP_CODE_ERR": 1,
|
||||
"RESP_CODE_EXPORT_CONTACT": 11,
|
||||
"RESP_CODE_NO_MORE_MESSAGES": 10,
|
||||
"RESP_CODE_OK": 0,
|
||||
"RESP_CODE_PRIVATE_KEY": 14,
|
||||
"RESP_CODE_SELF_INFO": 5,
|
||||
"RESP_CODE_SENT": 6,
|
||||
"RESP_CODE_SIGNATURE": 20,
|
||||
"RESP_CODE_SIGN_START": 19,
|
||||
"RESP_CODE_STATS": 24,
|
||||
"RESP_CODE_TUNING_PARAMS": 23
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
{
|
||||
"commands": {
|
||||
"CMD_ADD_UPDATE_CONTACT": 9,
|
||||
"CMD_APP_START": 1,
|
||||
"CMD_DEVICE_QUERY": 22,
|
||||
"CMD_EXPORT_CONTACT": 17,
|
||||
"CMD_EXPORT_PRIVATE_KEY": 23,
|
||||
"CMD_FACTORY_RESET": 51,
|
||||
"CMD_GET_ADVERT_PATH": 42,
|
||||
"CMD_GET_ALLOWED_REPEAT_FREQ": 60,
|
||||
"CMD_GET_AUTOADD_CONFIG": 59,
|
||||
"CMD_GET_BATT_AND_STORAGE": 20,
|
||||
"CMD_GET_CHANNEL": 31,
|
||||
"CMD_GET_CONTACTS": 4,
|
||||
"CMD_GET_CONTACT_BY_KEY": 30,
|
||||
"CMD_GET_CUSTOM_VARS": 40,
|
||||
"CMD_GET_DEFAULT_FLOOD_SCOPE": 64,
|
||||
"CMD_GET_DEVICE_TIME": 5,
|
||||
"CMD_GET_STATS": 56,
|
||||
"CMD_GET_TUNING_PARAMS": 43,
|
||||
"CMD_HAS_CONNECTION": 28,
|
||||
"CMD_IMPORT_CONTACT": 18,
|
||||
"CMD_IMPORT_PRIVATE_KEY": 24,
|
||||
"CMD_LOGOUT": 29,
|
||||
"CMD_REBOOT": 19,
|
||||
"CMD_REMOVE_CONTACT": 15,
|
||||
"CMD_RESET_PATH": 13,
|
||||
"CMD_SEND_ANON_REQ": 57,
|
||||
"CMD_SEND_BINARY_REQ": 50,
|
||||
"CMD_SEND_CHANNEL_DATA": 62,
|
||||
"CMD_SEND_CHANNEL_TXT_MSG": 3,
|
||||
"CMD_SEND_CONTROL_DATA": 55,
|
||||
"CMD_SEND_LOGIN": 26,
|
||||
"CMD_SEND_PATH_DISCOVERY_REQ": 52,
|
||||
"CMD_SEND_RAW_DATA": 25,
|
||||
"CMD_SEND_RAW_PACKET": 65,
|
||||
"CMD_SEND_SELF_ADVERT": 7,
|
||||
"CMD_SEND_STATUS_REQ": 27,
|
||||
"CMD_SEND_TELEMETRY_REQ": 39,
|
||||
"CMD_SEND_TRACE_PATH": 36,
|
||||
"CMD_SEND_TXT_MSG": 2,
|
||||
"CMD_SET_ADVERT_LATLON": 14,
|
||||
"CMD_SET_ADVERT_NAME": 8,
|
||||
"CMD_SET_AUTOADD_CONFIG": 58,
|
||||
"CMD_SET_CHANNEL": 32,
|
||||
"CMD_SET_CUSTOM_VAR": 41,
|
||||
"CMD_SET_DEFAULT_FLOOD_SCOPE": 63,
|
||||
"CMD_SET_DEVICE_PIN": 37,
|
||||
"CMD_SET_DEVICE_TIME": 6,
|
||||
"CMD_SET_FLOOD_SCOPE_KEY": 54,
|
||||
"CMD_SET_OTHER_PARAMS": 38,
|
||||
"CMD_SET_PATH_HASH_MODE": 61,
|
||||
"CMD_SET_RADIO_PARAMS": 11,
|
||||
"CMD_SET_RADIO_TX_POWER": 12,
|
||||
"CMD_SET_TUNING_PARAMS": 21,
|
||||
"CMD_SHARE_CONTACT": 16,
|
||||
"CMD_SIGN_DATA": 34,
|
||||
"CMD_SIGN_FINISH": 35,
|
||||
"CMD_SIGN_START": 33,
|
||||
"CMD_SYNC_NEXT_MESSAGE": 10
|
||||
},
|
||||
"errors": {
|
||||
"ERR_CODE_BAD_STATE": 4,
|
||||
"ERR_CODE_FILE_IO_ERROR": 5,
|
||||
"ERR_CODE_ILLEGAL_ARG": 6,
|
||||
"ERR_CODE_NOT_FOUND": 2,
|
||||
"ERR_CODE_TABLE_FULL": 3,
|
||||
"ERR_CODE_UNSUPPORTED_CMD": 1
|
||||
},
|
||||
"firmware": {
|
||||
"commit": "d92964352441e53b93e8667b802e04f6e072b39e",
|
||||
"firmware_ver_code": 13,
|
||||
"firmware_version": "v1.17.1",
|
||||
"flavor": "stock",
|
||||
"ref": "companion-v1.17.1"
|
||||
},
|
||||
"format": "offband-protocol-manifest",
|
||||
"format_version": 1,
|
||||
"generated_by": "meshcore-client tool/fake_radio/gen_protocol_manifest.py",
|
||||
"offband_caps": {},
|
||||
"offband_caps2": {},
|
||||
"offband_commands": {},
|
||||
"offband_responses": {},
|
||||
"pushes": {
|
||||
"PUSH_CODE_ADVERT": 128,
|
||||
"PUSH_CODE_BINARY_RESPONSE": 140,
|
||||
"PUSH_CODE_CONTACTS_FULL": 144,
|
||||
"PUSH_CODE_CONTACT_DELETED": 143,
|
||||
"PUSH_CODE_CONTROL_DATA": 142,
|
||||
"PUSH_CODE_LOGIN_FAIL": 134,
|
||||
"PUSH_CODE_LOGIN_SUCCESS": 133,
|
||||
"PUSH_CODE_LOG_RX_DATA": 136,
|
||||
"PUSH_CODE_MSG_WAITING": 131,
|
||||
"PUSH_CODE_NEW_ADVERT": 138,
|
||||
"PUSH_CODE_PATH_DISCOVERY_RESPONSE": 141,
|
||||
"PUSH_CODE_PATH_UPDATED": 129,
|
||||
"PUSH_CODE_RAW_DATA": 132,
|
||||
"PUSH_CODE_SEND_CONFIRMED": 130,
|
||||
"PUSH_CODE_STATUS_RESPONSE": 135,
|
||||
"PUSH_CODE_TELEMETRY_RESPONSE": 139,
|
||||
"PUSH_CODE_TRACE_DATA": 137
|
||||
},
|
||||
"responses": {
|
||||
"RESP_CODE_ADVERT_PATH": 22,
|
||||
"RESP_CODE_AUTOADD_CONFIG": 25,
|
||||
"RESP_CODE_BATT_AND_STORAGE": 12,
|
||||
"RESP_CODE_CHANNEL_DATA_RECV": 27,
|
||||
"RESP_CODE_CHANNEL_INFO": 18,
|
||||
"RESP_CODE_CHANNEL_MSG_RECV": 8,
|
||||
"RESP_CODE_CHANNEL_MSG_RECV_V3": 17,
|
||||
"RESP_CODE_CONTACT": 3,
|
||||
"RESP_CODE_CONTACTS_START": 2,
|
||||
"RESP_CODE_CONTACT_MSG_RECV": 7,
|
||||
"RESP_CODE_CONTACT_MSG_RECV_V3": 16,
|
||||
"RESP_CODE_CURR_TIME": 9,
|
||||
"RESP_CODE_CUSTOM_VARS": 21,
|
||||
"RESP_CODE_DEFAULT_FLOOD_SCOPE": 28,
|
||||
"RESP_CODE_DEVICE_INFO": 13,
|
||||
"RESP_CODE_DISABLED": 15,
|
||||
"RESP_CODE_END_OF_CONTACTS": 4,
|
||||
"RESP_CODE_ERR": 1,
|
||||
"RESP_CODE_EXPORT_CONTACT": 11,
|
||||
"RESP_CODE_NO_MORE_MESSAGES": 10,
|
||||
"RESP_CODE_OK": 0,
|
||||
"RESP_CODE_PRIVATE_KEY": 14,
|
||||
"RESP_CODE_SELF_INFO": 5,
|
||||
"RESP_CODE_SENT": 6,
|
||||
"RESP_CODE_SIGNATURE": 20,
|
||||
"RESP_CODE_SIGN_START": 19,
|
||||
"RESP_CODE_STATS": 24,
|
||||
"RESP_CODE_TUNING_PARAMS": 23
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate a protocol manifest from MeshCore companion firmware source.
|
||||
|
||||
Bootstrap for the fake radio (#769, Feature #755) until
|
||||
OffbandMesh/meshcore-firmware#1318 publishes manifests from firmware CI.
|
||||
Reads the source at a git ref (no checkout) and prints JSON to stdout.
|
||||
|
||||
python tool/fake_radio/gen_protocol_manifest.py \
|
||||
--repo C:/Dev/meshcore-firmware --ref offband-v1.5.0-beta7 \
|
||||
--flavor offband > test/support/fake_radio/manifests/offband-v1.5.0-beta7.json
|
||||
|
||||
Stock: --ref companion-v1.17.1 --flavor stock (upstream meshcore-dev/MeshCore
|
||||
tag, fetched into the clone).
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
COMPANION = "examples/companion_radio"
|
||||
DEFINE = re.compile(r"^#define\s+([A-Z0-9_]+)\s+(0x[0-9A-Fa-f]+|\d+)\b", re.M)
|
||||
CONSTEXPR = re.compile(
|
||||
r"^constexpr\s+uint8_t\s+([A-Z0-9_]+)\s*=\s*(0x[0-9A-Fa-f]+|\d+)\s*;", re.M
|
||||
)
|
||||
VER_CODE = re.compile(r"^#define\s+FIRMWARE_VER_CODE\s+(\d+)", re.M)
|
||||
VERSION = re.compile(r'^#define\s+FIRMWARE_VERSION\s+"([^"]+)"', re.M)
|
||||
|
||||
|
||||
def show(repo, ref, path):
|
||||
out = subprocess.run(
|
||||
["git", "-C", repo, "show", f"{ref}:{path}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
if out.returncode != 0:
|
||||
return None
|
||||
return out.stdout
|
||||
|
||||
|
||||
def pick(pairs, prefix):
|
||||
return {name: int(value, 0) for name, value in pairs if name.startswith(prefix)}
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--repo", required=True)
|
||||
ap.add_argument("--ref", required=True)
|
||||
ap.add_argument("--flavor", choices=["offband", "stock"], required=True)
|
||||
args = ap.parse_args()
|
||||
|
||||
header = show(args.repo, args.ref, f"{COMPANION}/MyMesh.h")
|
||||
source = show(args.repo, args.ref, f"{COMPANION}/MyMesh.cpp")
|
||||
if header is None or source is None:
|
||||
sys.exit(f"can't read {COMPANION} at {args.ref}")
|
||||
commit = subprocess.run(
|
||||
["git", "-C", args.repo, "rev-parse", f"{args.ref}^{{commit}}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
).stdout.strip()
|
||||
|
||||
defines = DEFINE.findall(source)
|
||||
pairs = list(defines)
|
||||
offband = show(args.repo, args.ref, f"{COMPANION}/OffbandConfigProtocol.h")
|
||||
if args.flavor == "offband":
|
||||
if offband is None:
|
||||
sys.exit("offband flavor but OffbandConfigProtocol.h is missing")
|
||||
pairs += CONSTEXPR.findall(offband) + DEFINE.findall(offband)
|
||||
|
||||
commands = pick(pairs, "CMD_")
|
||||
responses = pick(pairs, "RESP_CODE_")
|
||||
manifest = {
|
||||
"format": "offband-protocol-manifest",
|
||||
"format_version": 1,
|
||||
"generated_by": "meshcore-client tool/fake_radio/gen_protocol_manifest.py",
|
||||
"firmware": {
|
||||
"flavor": args.flavor,
|
||||
"ref": args.ref,
|
||||
"commit": commit,
|
||||
"firmware_version": VERSION.search(header).group(1),
|
||||
"firmware_ver_code": int(VER_CODE.search(header).group(1)),
|
||||
},
|
||||
"commands": {k: v for k, v in commands.items() if "OFFBAND" not in k},
|
||||
"responses": {k: v for k, v in responses.items() if "OFFBAND" not in k},
|
||||
"pushes": pick(pairs, "PUSH_CODE_"),
|
||||
"errors": pick(pairs, "ERR_CODE_"),
|
||||
"offband_commands": {k: v for k, v in commands.items() if "OFFBAND" in k},
|
||||
"offband_responses": {k: v for k, v in responses.items() if "OFFBAND" in k},
|
||||
"offband_caps": {
|
||||
k: v for k, v in pick(pairs, "OFFBAND_CAP_").items()
|
||||
},
|
||||
"offband_caps2": pick(pairs, "OFFBAND_CAP2_"),
|
||||
}
|
||||
print(json.dumps(manifest, indent=2, sort_keys=True))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in new issue