Skip to content

Commit b6f0b55

Browse files
committed
Merge pull request #1 from dronekit/rroche/message_listeners_api_update
Attribute Listener interface changed
2 parents fc6170e + 326622e commit b6f0b55

File tree

5 files changed

+106
-6
lines changed

5 files changed

+106
-6
lines changed

dronekit_solo/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ def __init__(self, *args):
1515
self.add_message_listener('GOPRO_GET_RESPONSE', self.__on_gopro_get_response)
1616
self.add_message_listener('GOPRO_SET_RESPONSE', self.__on_gopro_set_response)
1717

18-
def __on_gopro_status(self, name, m):
19-
self.__msg_gopro_status = m.status
18+
def __on_gopro_status(self, vehicle, name, m):
19+
self.__msg_gopro_status = m
2020
self.notify_attribute_listeners('gopro_status', self.gopro_status)
2121

2222
@property
2323
def gopro_status(self):
2424
return self.__msg_gopro_status
2525

26-
def __on_gopro_get_response(self, name, m):
27-
self.__msg_gopro_get_response = (m.cmd_id, m.value)
26+
def __on_gopro_get_response(self, vehicle, name, m):
27+
self.__msg_gopro_get_response = (m.cmd_id, m.status, m.value)
2828
self.notify_attribute_listeners('gopro_get_response', self.gopro_get_response)
2929

3030
@property
3131
def gopro_get_response(self):
3232
return self.__msg_gopro_get_response
3333

34-
def __on_gopro_set_response(self, name, m):
35-
self.__msg_gopro_set_response = (m.cmd_id, m.result)
34+
def __on_gopro_set_response(self, vehicle, name, m):
35+
self.__msg_gopro_set_response = (m.cmd_id, m.status)
3636
self.notify_attribute_listeners('gopro_set_response', self.gopro_set_response)
3737

3838
@property

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dronekit==2.1.0
2+
dronekit-sitl==3.0.1
3+
nose==1.3.7
4+
psutil==3.4.2
5+
pymavlink==1.1.70
6+
wheel==0.24.0

tests/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import print_function
2+
import os
3+
import sys
4+
from dronekit_sitl import SITL
5+
from nose.tools import assert_equals, with_setup
6+
7+
sitl = None
8+
sitl_args = ['-I0', '--model', 'quad', '--home=-35.363261,149.165230,584,353']
9+
10+
if 'SITL_SPEEDUP' in os.environ:
11+
sitl_args += ['--speedup', str(os.environ['SITL_SPEEDUP'])]
12+
if 'SITL_RATE' in os.environ:
13+
sitl_args += ['-r', str(os.environ['SITL_RATE'])]
14+
15+
def setup_solo_sitl():
16+
global sitl
17+
sitl = SITL()
18+
sitl.download('solo', '1.2.0')
19+
sitl.launch(sitl_args, await_ready=True, restart=True)
20+
21+
def teardown_sitl():
22+
sitl.stop()
23+
24+
def with_solo_sitl(fn):
25+
@with_setup(setup_solo_sitl, teardown_sitl)
26+
def test(*args, **kargs):
27+
return fn('tcp:127.0.0.1:5760', *args, **kargs)
28+
return test
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
@with_sitl
8+
def test_attribute_listener(connpath):
9+
'''check if the attribute listener api is up to date'''
10+
v = connect(connpath, wait_ready=True, vehicle_class=SoloVehicle)
11+
random_value = 123
12+
13+
def on_gopro_status(vehicle, attribute, value):
14+
assert_equals(value, random_value)
15+
16+
v.add_attribute_listener('GOPRO_STATUS', on_gopro_status)
17+
# manually notify the attribute listenr
18+
v.notify_attribute_listeners('GOPRO_STATUS', random_value)

tests/test_gopro_state.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)