Exemple #1
0
void Domain::checkTransports()
{
	// Now update topics with values from the transports and channels
	// Loop over all transports and for each topic, see if it needs parameters from the channel
	for (unsigned int i = 0; i < transports.size(); i++) {
		// Get channel
		Channel* channel = findChannel(transports[i]->channelID);
		if (channel == NULL) {
			throw ops::ConfigException(
				std::string("Non existing channelID: '") + transports[i]->channelID +
				std::string("' used in transport spcification."));
		} else {
			for (unsigned int j = 0; j < transports[i]->topics.size(); j++) {
				Topic* top = findTopic(transports[i]->topics[j]);
				if (top == NULL) {
					throw ops::ConfigException(
						std::string("Non existing topicID: '") + transports[i]->topics[j] +
						std::string("' used in transport spcification."));
				} else {
					channel->populateTopic(top);
				}
			}
		}
	}
}
orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance,
		int priority, unsigned int queue_size)
{
#ifdef ORB_USE_PUBLISHER_RULES

	// check publisher rule
	if (_has_publisher_rules) {
		const char *prog_name = px4_get_taskname();

		if (strcmp(_publisher_rule.module_name, prog_name) == 0) {
			if (_publisher_rule.ignore_other_topics) {
				if (!findTopic(_publisher_rule, meta->o_name)) {
					PX4_DEBUG("not allowing %s to publish topic %s", prog_name, meta->o_name);
					return (orb_advert_t)_Instance;
				}
			}

		} else {
			if (findTopic(_publisher_rule, meta->o_name)) {
				PX4_DEBUG("not allowing %s to publish topic %s", prog_name, meta->o_name);
				return (orb_advert_t)_Instance;
			}
		}
	}

#endif /* ORB_USE_PUBLISHER_RULES */

	int result, fd;
	orb_advert_t advertiser;

	/* open the node as an advertiser */
	fd = node_open(meta, data, true, instance, priority);

	if (fd == PX4_ERROR) {
		PX4_ERR("%s advertise failed", meta->o_name);
		return nullptr;
	}

	/* Set the queue size. This must be done before the first publication; thus it fails if
	 * this is not the first advertiser.
	 */
	result = px4_ioctl(fd, ORBIOCSETQUEUESIZE, (unsigned long)queue_size);

	if (result < 0 && queue_size > 1) {
		PX4_WARN("orb_advertise_multi: failed to set queue size");
	}

	/* get the advertiser handle and close the node */
	result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser);
	px4_close(fd);

	if (result == PX4_ERROR) {
		PX4_WARN("px4_ioctl ORBIOCGADVERTISER failed. fd = %d", fd);
		return nullptr;
	}

#ifdef ORB_COMMUNICATOR
	// For remote systems call over and inform them
	uORB::DeviceNode::topic_advertised(meta, priority);
#endif /* ORB_COMMUNICATOR */

	/* the advertiser must perform an initial publish to initialise the object */
	result = orb_publish(meta, advertiser, data);

	if (result == PX4_ERROR) {
		PX4_WARN("orb_publish failed");
		return nullptr;
	}

	return advertiser;
}