diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-26 14:50:23 +0100 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-26 19:01:07 +0100 |
commit | abeae7b6f6d70042c6b0bed493ade52727648c2d (patch) | |
tree | 548171e0583ade29721efcbd91310549e4fcfd25 /src/examples/subscriber | |
parent | 8dbb1fc8d443b1f8e2e454d4b82051fa63a48398 (diff) | |
download | px4-firmware-abeae7b6f6d70042c6b0bed493ade52727648c2d.tar.gz px4-firmware-abeae7b6f6d70042c6b0bed493ade52727648c2d.tar.bz2 px4-firmware-abeae7b6f6d70042c6b0bed493ade52727648c2d.zip |
extend subscriber/publisher example
Diffstat (limited to 'src/examples/subscriber')
-rw-r--r-- | src/examples/subscriber/subscriber_example.cpp | 26 | ||||
-rw-r--r-- | src/examples/subscriber/subscriber_example.h | 3 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/examples/subscriber/subscriber_example.cpp b/src/examples/subscriber/subscriber_example.cpp index 781dde486..e1292f788 100644 --- a/src/examples/subscriber/subscriber_example.cpp +++ b/src/examples/subscriber/subscriber_example.cpp @@ -67,9 +67,15 @@ SubscriberExample::SubscriberExample() : /* No callback */ _sub_rc_chan = _n.subscribe<px4_rc_channels>(500); - /* Class Method */ + /* Class method */ _n.subscribe<px4_rc_channels>(&SubscriberExample::rc_channels_callback, this, 1000); + /* Another class method */ + _n.subscribe<px4_vehicle_attitude>(&SubscriberExample::vehicle_attitude_callback, this, 1000); + + /* Yet antoher class method */ + _n.subscribe<px4_parameter_update>(&SubscriberExample::parameter_update_callback, this, 1000); + PX4_INFO("subscribed"); } @@ -78,8 +84,22 @@ SubscriberExample::SubscriberExample() : * Also the current value of the _sub_rc_chan subscription is printed */ void SubscriberExample::rc_channels_callback(const px4_rc_channels &msg) { - PX4_INFO("Callback (method): [%llu]", + PX4_INFO("rc_channels_callback (method): [%llu]", msg.data().timestamp_last_valid); - PX4_INFO("Callback (method): value of _sub_rc_chan: [%llu]", + PX4_INFO("rc_channels_callback (method): value of _sub_rc_chan: [%llu]", _sub_rc_chan->data().timestamp_last_valid); } + +void SubscriberExample::vehicle_attitude_callback(const px4_vehicle_attitude &msg) { + PX4_INFO("vehicle_attitude_callback (method): [%llu]", + msg.data().timestamp); +} + +void SubscriberExample::parameter_update_callback(const px4_parameter_update &msg) { + PX4_INFO("parameter_update_callback (method): [%llu]", + msg.data().timestamp); + PX4_PARAM_GET(_p_sub_interv, &_interval); + PX4_INFO("Param SUB_INTERV = %d", _interval); + PX4_PARAM_GET(_p_test_float, &_test_float); + PX4_INFO("Param SUB_TESTF = %.3f", (double)_test_float); +} diff --git a/src/examples/subscriber/subscriber_example.h b/src/examples/subscriber/subscriber_example.h index 8da3df438..9b6d890e3 100644 --- a/src/examples/subscriber/subscriber_example.h +++ b/src/examples/subscriber/subscriber_example.h @@ -59,6 +59,7 @@ protected: px4::Subscriber<px4_rc_channels> * _sub_rc_chan; void rc_channels_callback(const px4_rc_channels &msg); - + void vehicle_attitude_callback(const px4_vehicle_attitude &msg); + void parameter_update_callback(const px4_parameter_update &msg); }; |