|
| 1 | +from dronekit import connect, VehicleMode |
| 2 | +from dronekit.test import with_sitl |
| 3 | +from dronekit_solo import SoloVehicle |
| 4 | + |
| 5 | +from nose.tools import assert_equals |
| 6 | + |
| 7 | +class FakeGoproState: |
| 8 | + def __init__(self, cmd_id, status, value): |
| 9 | + self.cmd_id = cmd_id |
| 10 | + self.status = status |
| 11 | + self.value = value |
| 12 | + |
| 13 | +class FakeGoproResponse: |
| 14 | + def __init__(self, cmd_id, status): |
| 15 | + self.cmd_id = cmd_id |
| 16 | + self.status = status |
| 17 | + |
| 18 | +@with_sitl |
| 19 | +def test_gopro_state(connpath): |
| 20 | + v = connect(connpath, wait_ready=True, vehicle_class=SoloVehicle) |
| 21 | + |
| 22 | + fake_gopro_state = FakeGoproState(123, 1, [1, 1, 1, 1]) |
| 23 | + |
| 24 | + def on_gopro_status(vehicle, attribute, value): |
| 25 | + assert_equals(vehicle.gopro_status, value) |
| 26 | + assert_equals(value.cmd_id, fake_gopro_state.cmd_id) |
| 27 | + assert_equals(value.status, fake_gopro_state.status) |
| 28 | + assert_equals(value.value, fake_gopro_state.value) |
| 29 | + |
| 30 | + v.add_attribute_listener('gopro_status', on_gopro_status) |
| 31 | + |
| 32 | + # manually notify the attribute listenr |
| 33 | + v.notify_message_listeners('GOPRO_HEARTBEAT', fake_gopro_state) |
| 34 | + |
| 35 | +@with_sitl |
| 36 | +def test_gopro_set_response(connpath): |
| 37 | + v = connect(connpath, wait_ready=True, vehicle_class=SoloVehicle) |
| 38 | + |
| 39 | + fake_gopro_response = FakeGoproResponse(123, 456) |
| 40 | + |
| 41 | + def on_gopro_set_response(vehicle, attribute, value): |
| 42 | + assert_equals(value[0], fake_gopro_response.cmd_id) |
| 43 | + assert_equals(value[1], fake_gopro_response.status) |
| 44 | + |
| 45 | + v.add_attribute_listener('gopro_set_response', on_gopro_set_response) |
| 46 | + |
| 47 | + # manually notify the attribute listenr |
| 48 | + v.notify_message_listeners('GOPRO_SET_RESPONSE', fake_gopro_response) |
0 commit comments