Commit Graph

36 Commits

Author SHA1 Message Date
Beat Küng
6c8048d057 uorb: fix several race conditions during topic initialization
Possible race conditions (they all happen between the check of existence
of a topic and trying to create the node):
- single instance, with multiple advertisers during the first advertise:
  both advertisers see the topic as non-existent and try to advertise it.
  One of them will fail, leading to an error message.
  This is the cause for telemetry_status advert failure seen in SITL in
  rare cases.
- multi-instance: subscription to non-existing instance -> px4_open fails,
  and the subscriber tries to create the node. If during that time a
  publisher publishes that instance, the subscriber will get (instance+1)
  (or fails if the max number of instances is exceeded).
  This is a race that goes pretty much unnoticed.
- multi-instance: 2 publishers can get the same instance (if is_published()
  is false in case both have not published data yet).
  This can also go unnoticed.
  Therefore the patch changes where _advertised is set: it is now set
  directly during the advertisement instead of during publication.
2019-11-23 10:10:05 -05:00
Beat Küng
63b2befeed refactor uorb: rename published to advertised
No semantic change (yet)
2019-11-23 10:10:05 -05:00
Beat Küng
3198610f85 src/platforms: move all headers to platforms/common/include/px4_platform_common
and remove the px4_ prefix, except for px4_config.h.

command to update includes:
for k in app.h atomic.h cli.h console_buffer.h defines.h getopt.h i2c.h init.h log.h micro_hal.h module.h module_params.h param.h param_macros.h posix.h sem.h sem.hpp shmem.h shutdown.h tasks.h time.h workqueue.h; do for i in $(grep -rl 'include <px4_'$k src platforms boards); do sed -i 's/#include <px4_'$k'/#include <px4_platform_common\/'$k/ $i; done; done
for in $(grep -rl 'include <px4_config.h' src platforms boards); do sed -i 's/#include <px4_config.h/#include <px4_platform_common\/px4_config.h'/ $i; done

Transitional headers for submodules are added (px4_{defines,log,time}.h)
2019-10-30 11:48:47 +01:00
Beat Küng
173337e49c uORBManager: print errno for advertisement failures
Helps with debugging.
2019-10-16 13:13:17 +02:00
Julian Kent
d70b024ec7 GTest functional tests that include parameters and uORB messaging (#12521)
* Add kdevelop to gitignore

* Add test stubs

* Rename px4_add_gtest to px4_add_unit_gtest

* Add infrastructure to run functional tests

* Add example tests with parameters and uorb messages

* Fix memory issues in destructors in uORB manager and CDev

* Add a more real-world test of the collision prevention
2019-08-09 15:10:09 +02:00
Daniel Agar
a6684c6f9a uORB orb_exists use internal linked list instead of file path 2018-11-23 08:15:48 +01:00
Daniel Agar
cfac2cc38e uORB advertise through uORBDeviceMaster directly 2018-09-19 10:00:45 +02:00
Daniel Agar
dbf2d25e2f uORB move to standalone CDev
- uORB topics should not be Devices with bus, address, device id
2018-08-27 13:14:15 -04:00
Daniel Agar
7d389a35ce uORB: split uORBDevices into uORBDeviceNode and uORBDeviceMaster 2018-08-17 22:25:29 -04:00
Beat Küng
c0cac0594e file paths: add PX4_STORAGEDIR & use it where appropriate 2018-08-08 21:09:39 +02:00
Daniel Agar
8599495082 uORB add ORB_COMMUNICATOR define to enable remote uORB 2018-07-01 16:03:03 +00:00
Daniel Agar
edea1b65cd uORB delete unused Flavor 2018-05-02 00:48:46 -04:00
Beat Küng
90513e719e ASSERT: remove some inappropriate asserts
Since assertions lead to crashes, we need better failure handling. In all
the cases in this patch, the assert is not required.

All the ones with the task id should be replaced with the module base
class.

Ah yes, and this reduces flash space, since the ASSERT macro will expand to
a printf that contains the source file name.
2018-04-11 07:47:06 +02:00
Beat Küng
45458fe9eb uORBManager: add comment about not having to set the priority 2018-01-19 14:11:01 +01:00
Beat Küng
2f2c0440c4 orb_exists: change semantics from (is published or subscribed) to (is published)
Existing users of orb_exists:
- logger (dynamic subscribe to multi-instances)
- mavlink (orb subscription)
- sdlog2
- preflightcheck (check for home_position)
- wait_for_topic shell command (it's not used)
- orb_group_count() (sensors: dynamic sensor addition)

All use-cases benefit from the changed semantics: they are really only
interested if there is a publisher, not another subscriber.
2017-10-18 08:40:32 +02:00
Daniel Agar
e63da5860e uORB cleanup Subscription/Publication c++ 2017-08-20 20:42:42 +02:00
Daniel Agar
61fd6f4c8a uorb failure print topic name 2017-07-09 14:40:11 +02:00
Daniel Agar
070cd55636 clang-tidy readability 2017-02-01 22:15:50 -05:00
Daniel Agar
6631e72d6f clang-tidy modernize-redundant-void-arg 2017-02-01 22:15:50 -05:00
Mark Charlebois
f529069368 Fixed code format issues
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2017-01-09 15:41:54 -08:00
Mark Charlebois
830eb8528e fixed merge conflict
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2017-01-09 15:41:54 -08:00
Mark Charlebois
9834155d09 Removed extra debug
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2017-01-09 15:41:54 -08:00
Mark Charlebois
b556528984 Fixed wait_for_topic and orb_exists
orb_exists was not updating the DSP topics on apps proc side

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2017-01-09 15:41:54 -08:00
Mark Charlebois
62a3e07423 orb_exists support for muorb
Also added builtin command wait_for_topic

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2017-01-09 15:41:54 -08:00
Beat Küng
0f2b31b41e uorb: inline orb_advertise (directly calls orb_advertise_multi)
reduces the stack depth
2016-11-06 14:48:20 +01:00
Beat Küng
7280f71cef orb: rm static from DeviceMaster::_node_map & use the non-static getDeviceNode in uORB::Manager
Reasons:
- DeviceMaster::_node_map does not need to be shared among instances,
  because there is at most 1 instance per Flavor and different Flavors
  have non-intersecting device paths.
- Keeping it static would also require a static lock
- DeviceMaster::_node_map was not locked at all when used from
  uORB::Manager

So this fixes two synchronization issues:
- Different DeviceMaster objects could access the same static data in
  parallel
- getDeviceNode() called from uORB::Manager did not use any locking at all
2016-08-06 20:44:23 +02:00
Beat Küng
45a0a7c5ab refactor orb: uORB::Manager is responsible for the DeviceMaster objects
This has the following benefits:
- Manager can ensure that there is at most one instance of DeviceMaster
  per Flavor
- The Manager needs access to (static) data of DeviceMaster already.
  This will make it easier to access this data in a non-static way, and
  does not introduce new dependencies.
2016-08-06 20:44:23 +02:00
Beat Küng
ffcefd9047 orb: read & apply publisher rules from file (currently disabled via #ifdef)
If enabled, orb reads a rules file (./rootfs/orb_publisher.rules) on
startup. This can contain rules about which module is allowed to publish
which topic. It is completely transparent, so a publisher does not know
if he's not allowed to publish, and publications will look as if they
succeeded.

To test, add
#define ORB_USE_PUBLISHER_RULES
to uORBManager.hpp
2016-07-07 12:51:42 +02:00
Julian Oes
6b1bcef644 uORBManager: removed printfs 2016-06-07 22:10:56 +02:00
Beat Küng
e709048fb8 orb: add orb_get_interval to API 2016-06-06 23:27:16 +02:00
Beat Küng
43d734ef43 orb: consistently use unsigned int for queue_size 2016-06-02 07:24:44 +02:00
Beat Küng
5b1273e334 orb: add optional queuing of messages
This adds two uORB API calls:
- orb_advertise_queue
- orb_advertise_multi_queue

Both add a queue_size parameter to define a maximum number of buffered
item. The existing orb calls use all a queue size of one and thus their
behavior is unchanged. If a writer publishes too fast, the oldest elements
from the queue are silently dropped.
The returned timestamp is always the one from the latest message in the
queue.

Queue size can be set via ioctl during advertisement phase. After that it
cannot be changed anymore.
2016-06-02 07:24:44 +02:00
Beat Küng
1a57488ac6 orb: add a separate uORB::Manager::initialize() method
This fixes a race condition: uORB::Manager::get_instance() is used in a
multi-thread context, but the singleton initialization was not thread-safe.
Further, this avoids having to check for nullptr every time the singleton
is accessed.

uORB::Manager::initialize() is called when uorb is started. No one else
accesses the singleton before that point, because it is only used in the
orb_* methods, and in muorb. Both require uorb to be started already when
they are used.
2016-04-29 11:15:15 +02:00
Beat Küng
9da537c092 uorb: add uorb_unadvertise method
This is necessary when using multiple instances of a topic. However it does
not free the underlying resources, as it is assumed they will be used again
at a later point.
2016-04-29 09:31:08 +02:00
Beat Küng
fdc10d212b orb: fix when orb_subscribe_multi is called before orb_advertise_multi
This fixes the previously introduced unit test. It fixes the case where
orb_subscribe_multi is called multiple times with different instances,
and no publisher advertised the topic yet. In this case all subscribers
got the same instance 0.
2016-04-19 11:12:36 +02:00
Beat Küng
934207b518 uORB: merge the files uORBManager_{nuttx,posix}.cpp, largely the same code 2016-04-19 11:12:35 +02:00