mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 03:15:36 +00:00
Model the audio path, which is a single enable line and no samples
Asked for a speaker and a microphone. The honest answer is that neither exists to
model: on the real radio neither passes through the MCU. Receive audio is demodulated
inside the BK4819 and leaves it as analogue on its AF pin; transmit audio goes from
the microphone into the chip's own ADC. The firmware's entire involvement is
- PA8, the amplifier enable (GPIO_EnableAudioPath, driver/gpio.h:34)
- REG_47, which AF source the chip routes
- REG_64, a level it displays
No audio samples exist anywhere in the MCU's address space, so a device model has
nothing to capture or play, and a browser has nothing to be granted permission for.
Synthesising sound would be inventing data the firmware never produced.
What is real is the firmware's intent, and PA8 states it exactly. TYPE_UVK5_AUDIO
watches that pin and exposes read-only speaker-on; the web UI shows it as a speaker
glyph beside the power state, and /api/status reports it. Read-only deliberately:
letting a test write it would only let the test lie to itself. The page asks for no
audio permission, and a test asserts it never will -- no getUserMedia, no
AudioContext, no <audio>.
Measured: amplifier off while idle in power save, on after SIDE1 engages monitor, and
still on afterwards rather than blipping.
One bug found the hard way, and the stub was the cause. QmpClient.command returns the
unwrapped value and raises on error, but the test stub returned {"return": ...}. So
webui.py was written to unwrap a second time, every test passed, and the live UI
returned 500 with "argument of type 'bool' is not iterable". The stub is now pinned to
the real contract by a test. A stub more forgiving than the real thing is worse than
no stub.
Also stopped swallowing the failure: a bare `except: return None` made the error
indistinguishable from a radio that simply was not making sound, and cost a detour
into looking for a stale process.
This commit is contained in:
1 parent
8d1a1c4415
commit
7d299dbad2
4 files changed
+355
-1
No files matched your search
@@ -11,11 +11,20 @@ class StubClient:
|
||||
|
||||
def __init__(self):
|
||||
self.sent = []
|
||||
self.speaker = False
|
||||
|
||||
def command(self, name, **args):
|
||||
self.sent.append((name, args))
|
||||
if name == "query-status":
|
||||
return {"status": "running", "running": True}
|
||||
if name == "qom-get" and args.get("property") == "speaker-on":
|
||||
# The real client unwraps: QmpClient.command returns msg["return"]
|
||||
# directly and raises on error. An earlier version of this stub returned
|
||||
# {"return": ...}, so webui.py was written to unwrap a second time and blew
|
||||
# up with "argument of type 'bool' is not iterable" against a live guest,
|
||||
# while the tests passed. A stub that is more forgiving than the real thing
|
||||
# is worse than no stub.
|
||||
return self.speaker
|
||||
if name == "memsave":
|
||||
with open(args["filename"], "wb") as fh:
|
||||
fh.write(bytes(args["size"]))
|
||||
@@ -733,3 +742,52 @@ class TestClientIpInLogs(unittest.TestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class TestSpeakerIndicator(unittest.TestCase):
|
||||
"""The UI reports whether the firmware wants sound.
|
||||
|
||||
Deliberately not audio. The microphone and speaker are wired to the BK4819 rather
|
||||
than the MCU, so no samples reach the emulator, there is nothing to stream, and the
|
||||
page needs no audio permission. What is reported is the amplifier enable (PA8), i.e.
|
||||
the firmware's intent.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.client, self.http = make_app()
|
||||
|
||||
def test_stub_matches_the_real_client_contract(self):
|
||||
"""qom-get must yield the value itself, not a {"return": ...} envelope.
|
||||
|
||||
This pins the stub to QmpClient.command's actual behaviour. When they diverged,
|
||||
every test passed and the live web UI returned 500.
|
||||
"""
|
||||
result = self.client.command("qom-get", path="/machine/audio",
|
||||
property="speaker-on")
|
||||
self.assertIsInstance(result, bool)
|
||||
|
||||
def test_status_reports_the_speaker_state(self):
|
||||
self.client.speaker = True
|
||||
body = self.http.get("/api/status").get_json()
|
||||
self.assertTrue(body["speaker"])
|
||||
|
||||
def test_status_reports_a_silent_radio(self):
|
||||
self.client.speaker = False
|
||||
body = self.http.get("/api/status").get_json()
|
||||
self.assertFalse(body["speaker"])
|
||||
|
||||
def test_page_has_an_indicator_wired_to_the_poll(self):
|
||||
body = self.http.get("/").get_data(as_text=True)
|
||||
self.assertIn('id="speaker"', body)
|
||||
self.assertIn("showSpeaker", body)
|
||||
|
||||
def test_page_requests_no_audio_permission(self):
|
||||
"""Nothing here should ask the browser for a microphone or to play audio.
|
||||
|
||||
There is no audio to carry, so a permission prompt would be asking the user to
|
||||
approve something that cannot happen.
|
||||
"""
|
||||
body = self.http.get("/").get_data(as_text=True)
|
||||
for forbidden in ("getUserMedia", "AudioContext", "navigator.mediaDevices",
|
||||
"new Audio", "<audio"):
|
||||
self.assertNotIn(forbidden, body)
|
||||
Reference in new issue
Block a user