Files
HaloKeymind/test/test_profile_heltec_v4.py
T
mikecarper 091c8d8324 Preserve radio lab experiments and reuse unchanged SX1262 modulation
Skip redundant modulation writes during owned fast RX retunes when the last
acknowledged SF/BW/CR/LDRO tuple matches. Invalidate that cache after ordinary
setters, failed writes, and lifecycle changes.

Include the remaining scan, preamble, settling, and memory-soak experiments,
their collectors, validation notes, and original capture records. Preserve
capture bytes across checkouts and keep private soak credentials local.

Run lab collector and compiled contract tests in CI. Update the expectation,
profile mapping, and result-buffer tests for the extended lab tools, and make
the private WiFi override header optional for ordinary soak diagnostics.

Validation: 145 host tests passed from the staged source snapshot. Clean
heltec_v4_repeater and Xiao_S3_WIO_companion_radio_usb builds passed their
RAM/flash gates. All 229 staged capture files retain their original bytes;
all 75 local documentation links resolve in the clean snapshot.
2026-09-14 22:34:17 -07:00

72 lines
2.5 KiB
Python

"""HIL V4 front-end selection and restoration around every direct TX path."""
from pathlib import Path
import unittest
from test_radio_receive_contract import method
import test_sx1262_batched_modulation as compiler
ROOT = Path(__file__).resolve().parents[1]
class HeltecHilTests(unittest.TestCase):
compile_run = compiler.BatchedModulationTests.compile_run
def test_gc_bypass_kct_tx_and_restore_even_on_error(self):
source = (ROOT / "tools/hil/ProfileHeltecV4.h").read_text().replace(
'#include "LoRaFEMControl.h"', '').replace('#pragma once', '')
tx = method((ROOT / "tools/hil/profile_switch.cpp").read_text(), 'int16_t benchTransmit(')
harness = r'''
#include <cassert>
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <string>
enum { GC1109_PA, KCT8103L_PA };
struct LoRaFEMControl {
int type=GC1109_PA; std::string calls;
void init() { calls+='I'; }
void setRxModeEnable() { calls+='R'; }
void setTxModeEnable() { calls+='T'; }
int getFEMType() const { return type; }
};
@SOURCE@
ProfileHeltecV4 v4FrontEnd;
struct {
int16_t rc=0;
int16_t transmit(uint8_t*,size_t n) {
assert(n==16);
assert(v4FrontEnd.fem.calls.back()==(v4FrontEnd.fem.type==GC1109_PA?'R':'T'));
v4FrontEnd.fem.calls+='X'; return rc;
}
} chip;
#define HIL_HELTEC_V4
@TX@
int main() {
uint8_t data[16]={};
for(int fem : {GC1109_PA,KCT8103L_PA}) {
v4FrontEnd.fem.type=fem; v4FrontEnd.fem.calls.clear();
v4FrontEnd.begin(); assert(v4FrontEnd.fem.calls=="IR");
assert(!strcmp(v4FrontEnd.type(),fem==GC1109_PA?"GC1109":"KCT8103L"));
assert(!strcmp(v4FrontEnd.txMode(),fem==GC1109_PA?"bypass":"amplified"));
for(int error : {0,-3}) {
chip.rc=error; v4FrontEnd.fem.calls.clear();
assert(benchTransmit(data,16)==error);
assert(v4FrontEnd.fem.calls==(fem==GC1109_PA?"RXR":"TXR"));
}
}
}
'''
self.compile_run(harness.replace('@SOURCE@',source).replace('@TX@',tx))
def test_all_direct_probe_transmits_use_frontend_adapter(self):
for name in ('profile_switch_channels.h','profile_switch_packets.h','profile_preamble_diagnostic.h'):
source=(ROOT/'tools/hil'/name).read_text()
self.assertNotIn('chip.transmit(',source)
self.assertIn('benchTransmit(',source)
source=(ROOT/'tools/hil/profile_switch.cpp').read_text()
setup=method(source,'void setup()')
self.assertLess(setup.index('v4FrontEnd.begin()'),setup.index('chip.std_init('))
if __name__ == '__main__':
unittest.main()