Three fixes the real aircraft found, that the simulator could not
Acknowledge on data type alone, never on buffer id. A live Bebop 2 sends DATA_WITH_ACK on buffer 126 and plain DATA on 127, the opposite of what the buffer names imply, so requiring both to agree meant nothing was ever acknowledged. The drone resent its state instead of continuing: 35 telemetry keys where there should be 192, and a connect that took 4 s instead of 1.7. Record argument-less events. Eight events carry no arguments and their arrival is the whole message, including AllStatesChanged and AllSettingsChanged, which mark the end of a state dump. Keying only by argument decoded them to an empty dict and lost them. Wait for those terminators instead of a quiet period. The drone streams attitude at about 5 Hz throughout, so the link is never quiet and the wait always ran to its timeout with a partial burst. Also: preflight no longer reports ready when a blocking check has no data. It answered 'ready' on an aircraft it knew almost nothing about, which is worse than refusing to answer.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
"""Regressions for three bugs that only a real aircraft exposed.
|
||||
|
||||
Each of these passed every simulator test while being wrong against the drone,
|
||||
which is why they have their own file: the simulator was written from the same
|
||||
assumptions as the code, so it agreed with it.
|
||||
"""
|
||||
|
||||
from mcbebop.arsdk.types import BufferId, DataType, Frame
|
||||
from mcbebop.protocol import codec, xml_index
|
||||
from mcbebop.protocol.types import Direction
|
||||
|
||||
|
||||
def test_argument_less_events_are_recorded():
|
||||
"""Eight events carry no arguments; their arrival IS the message.
|
||||
|
||||
AllStatesChanged and AllSettingsChanged are how the drone says a state dump
|
||||
is finished. Keying only by argument meant they decoded to an empty dict and
|
||||
disappeared, so nothing could wait for the end of a burst.
|
||||
"""
|
||||
for name in ("common.CommonState.AllStatesChanged", "common.SettingsState.AllSettingsChanged"):
|
||||
spec = xml_index.get(name)
|
||||
assert spec.args == (), "this test is about events that have no arguments"
|
||||
_, values = codec.decode_event(codec.encode_command(spec, {}))
|
||||
assert values == {spec.name: True}
|
||||
|
||||
bare = [c for c in xml_index.all_commands() if c.direction is Direction.FROM_DRONE and not c.args]
|
||||
assert len(bare) == 8
|
||||
|
||||
|
||||
def test_every_bare_event_decodes_to_something():
|
||||
for spec in xml_index.all_commands():
|
||||
if spec.direction is Direction.FROM_DRONE and not spec.args:
|
||||
_, values = codec.decode_event(codec.encode_command(spec, {}))
|
||||
assert values, f"{spec.full_name} decoded to nothing"
|
||||
|
||||
|
||||
def test_acknowledgement_is_decided_by_data_type_not_buffer():
|
||||
"""A live Bebop 2 sends DATA_WITH_ACK on buffer 126, not 127.
|
||||
|
||||
The naming says 127 is the drone's acknowledged buffer, and requiring both
|
||||
the type and the buffer to agree meant no frame was ever acknowledged. The
|
||||
drone then resent its state rather than continuing, and most of it never
|
||||
arrived: 35 keys instead of 192.
|
||||
"""
|
||||
import inspect
|
||||
|
||||
from mcbebop.arsdk import connection as conn_mod
|
||||
|
||||
source = inspect.getsource(conn_mod.Connection._handle)
|
||||
ack_line = next(line for line in source.splitlines() if "DataType.DATA_WITH_ACK" in line)
|
||||
assert "buffer_id" not in ack_line, "the ack decision must not depend on which buffer it arrived on"
|
||||
|
||||
# Both buffers must round-trip to a valid ack target.
|
||||
for buffer_id in (BufferId.D2C_NON_ACK, BufferId.D2C_ACK):
|
||||
frame = Frame(DataType.DATA_WITH_ACK, buffer_id, 9, b"\x00\x05\x00\x00")
|
||||
assert Frame.decode_all(frame.encode())[0].buffer_id == buffer_id
|
||||
assert 0 <= BufferId.ack_for(buffer_id) <= 255
|
||||
Reference in New Issue
Block a user