uORBMain.cpp学习
uorb_main
- int
- uorb_main(int argc, char *argv[])
- {
- if (argc < 2) {
- usage(); //使用说明
- return -EINVAL;
- }
- /*
- * Start/load the driver. //开始或加载驱动
- */
- if (!strcmp(argv[1], "start")) {
- if (g_dev != nullptr) { //判断是否已经启动
- PX4_WARN("already loaded");
- /* user wanted to start uorb, its already running, no error */
- return 0;
- }
- if (!uORB::Manager::initialize()) { //初始化uORB::Manager
- PX4_ERR("uorb manager alloc failed");
- return -ENOMEM;
- }
- /* create the driver */ //创建一个驱动设备
- g_dev = uORB::Manager::get_instance()->get_device_master(uORB::PUBSUB);
- if (g_dev == nullptr) {
- return -errno;
- }
- #if !defined(__PX4_QURT) && !defined(__PX4_POSIX_EAGLE) && !defined(__PX4_POSIX_EXCELSIOR)
- /* FIXME: this fails on Snapdragon (see https://github.com/PX4/Firmware/issues/5406),
- * so we disable logging messages to the ulog for now. This needs further investigations.
- */
- px4_log_initialize();
- #endif
- return OK;
- }
- /*
- * Print driver information. //打印设备信息status
- */
- if (!strcmp(argv[1], "status")) {
- if (g_dev != nullptr) {
- g_dev->printStatistics(true);
- } else {
- PX4_INFO("uorb is not running");
- }
- return OK;
- }
- //topming'li
- if (!strcmp(argv[1], "top")) {
- if (g_dev != nullptr) {
- g_dev->showTop(argv + 2, argc - 2);
- } else {
- PX4_INFO("uorb is not running");
- }
- return OK;
- }
- usage();
- return -EINVAL;
- }
uORB::Manager::initialize():
- bool uORB::Manager::initialize()
- {
- if (_Instance == nullptr) {
- _Instance = new uORB::Manager(); //创建了一个新的uORB实例
- }
- return _Instance != nullptr;
- }
uORB::Manager:
- /**
- * This is implemented as a singleton. This class manages creating the //这是一个实施的单例,这个class管理创建uORB节点给每个uORB topics
- * uORB nodes for each uORB topics and also implements the behavor of the //并且也实施uORB的API行为
- * uORB Api's.
- */
- class uORB::Manager : public uORBCommunicator::IChannelRxHandler
- {
- public:
- // public interfaces for this class. //公共的类接口
- /** //初始化单例,调用这个在所有事情之前
- * Initialize the singleton. Call this before everything else.
- * @return true on success //返回true是成功
- */
- static bool initialize();
- /** //获取instance的方法
- * Method to get the singleton instance for the uORB::Manager.
- * Make sure initialize() is called first. //确保initialize()先被调用
- * @return uORB::Manager* //返回创建的uORB::Manager*
- */
- static uORB::Manager *get_instance()
- {
- return _Instance;
- }
- /**
- * Get the DeviceMaster for a given Flavor. If it does not exist, //给定一个flavoe,会返回DeciveMaster* 如果不存在会创建并且初始化
- * it will be created and initialized.
- * Note: the first call to this is not thread-safe. //第一次调用thread-safe不是这个?
- * @return nullptr if initialization failed (and errno will be set) //初始化失败返回一个nullptr
- */
- uORB::DeviceMaster *get_device_master(Flavor flavor);
- // ==== uORB interface methods ====
- /**
- * Advertise as the publisher of a topic. //广告作为发布话题
- *
- * This performs the initial advertisement of a topic; it creates the topic //执行初始化的广告topic;它创造topic
- * node in /obj if required and publishes the initial data.
- *
- * Any number of advertisers may publish to a topic; publications are atomic
- * but co-ordination between publishers is not provided by the ORB.
- *
- * Internally this will call orb_advertise_multi with an instance of 0 and //函数内部调用了orb_advertis_multi
- * default priority.
- *
- * @param meta The uORB metadata (usually from the ORB_ID() macro) //uORB metadata(通常来自ORB_ID()宏)作为topic
- * for the topic.
- * @param data A pointer to the initial data to be published. //数据指针
- * For topics updated by interrupt handlers, the advertisement //中断处理函数
- * must be performed from non-interrupt context. //必须执行无中断的内容
- * @param queue_size Maximum number of buffered elements. If this is 1, no queuing is //最大的buffer元素个数,如果是1,没有队列被使用
- * used.
- * @return nullptr on error, otherwise returns an object pointer //返回空指针如果错误,否则返回一个类指针
- * that can be used to publish to the topic. //那个可以用来公布topic
- * If the topic in question is not known (due to an //如果topic在问题中不被知道(由于ORB_DEFINE不和ORB_DECLARE一致)
- * ORB_DEFINE with no corresponding ORB_DECLARE)
- * this function will return nullptr and set errno to ENOENT. //这个函数将会返回nullptr并且设置errno到ENOENT
- */
- orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data, unsigned int queue_size = 1)
- {
- return orb_advertise_multi(meta, data, nullptr, ORB_PRIO_DEFAULT, queue_size);
- }
- /**
- * Advertise as the publisher of a topic.
- *
- * This performs the initial advertisement of a topic; it creates the topic
- * node in /obj if required and publishes the initial data.
- *
- * Any number of advertisers may publish to a topic; publications are atomic
- * but co-ordination between publishers is not provided by the ORB.
- *
- * The multi can be used to create multiple independent instances of the same topic //用来创建多个独立接口用于相同的topic
- * (each instance has its own buffer). //每个接口都有自己的buff
- * This is useful for multiple publishers who publish the same topic. The subscriber
- * then subscribes to all instances and chooses which source he wants to use.
- *
- * @param meta The uORB metadata (usually from the ORB_ID() macro) //meta通常来自于ORB_ID()宏,是uORB的metadata
- * for the topic.
- * @param data A pointer to the initial data to be published. //data是一个初始化要发布数据的指针
- * For topics updated by interrupt handlers, the advertisement //通过中断处理函数更新,
- * must be performed from non-interrupt context.
- * @param instance Pointer to an integer which will yield the instance ID (0-based) //一个整形指针,用于接口ID(0-based)
- * of the publication. This is an output parameter and will be set to the newly //创建接口等等,0是第一个广告,1是下一个,如此往下
- * created instance, ie. 0 for the first advertiser, 1 for the next and so on.
- * @param priority The priority of the instance. If a subscriber subscribes multiple //接口的优先级
- * instances, the priority allows the subscriber to prioritize the best
- * data source as long as its available. The subscriber is responsible to check
- * and handle different priorities (@see orb_priority()).
- * @param queue_size Maximum number of buffered elements. If this is 1, no queuing is //最大的buffer元素个数,如果是1,没有queuing被使用
- * used.
- * @return ERROR on error, otherwise returns a handle //返回ERROR在错误时,否则返回一个句柄。用于创建一个topic和publish
- * that can be used to publish to the topic.
- * If the topic in question is not known (due to an
- * ORB_DEFINE with no corresponding ORB_DECLARE)
- * this function will return -1 and set errno to ENOENT.
- */
- orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance,
- int priority, unsigned int queue_size = 1) ;
- /**
- * Unadvertise a topic.
- *
- * @param handle handle returned by orb_advertise or orb_advertise_multi. //用于取消一个topic, handle是orb_advertise_multi返回的handle
- * @return 0 on success
- */
- int orb_unadvertise(orb_advert_t handle);
- /**
- * Publish new data to a topic. //发布一个新的
- *
- * The data is atomically published to the topic and any waiting subscribers
- * will be notified. Subscribers that are not waiting can check the topic
- * for updates using orb_check and/or orb_stat.
- *
- * @param meta The uORB metadata (usually from the ORB_ID() macro) //从ORB_ID宏的metadata
- * for the topic.
- * @handle The handle returned from orb_advertise. //orb_advertise返回的handle
- * @param data A pointer to the data to be published. //publish的数据的指针
- * @return OK on success, ERROR otherwise with errno set accordingly. //返回OK如果成功
- */
- int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) ;
- /**
- * Subscribe to a topic. //订阅一个topic
- *
- * The returned value is a file descriptor that can be passed to poll()
- * in order to wait for updates to a topic, as well as topic_read,
- * orb_check and orb_stat.
- *
- * Subscription will succeed even if the topic has not been advertised;
- * in this case the topic will have a timestamp of zero, it will never
- * signal a poll() event, checking will always return false and it cannot
- * be copied. When the topic is subsequently advertised, poll, check,
- * stat and copy calls will react to the initial publication that is
- * performed as part of the advertisement.
- *
- * Subscription will fail if the topic is not known to the system, i.e.
- * there is nothing in the system that has declared the topic and thus it
- * can never be published.
- *
- * Internally this will call orb_subscribe_multi with instance 0.
- *
- * @param meta The uORB metadata (usually from the ORB_ID() macro) //订阅主题的metadata
- * for the topic.
- * @return ERROR on error, otherwise returns a handle
- * that can be used to read and update the topic.
- */
- int orb_subscribe(const struct orb_metadata *meta) ;
- /**
- * Subscribe to a multi-instance of a topic. //订阅多个主题
- *
- * The returned value is a file descriptor that can be passed to poll()
- * in order to wait for updates to a topic, as well as topic_read,
- * orb_check and orb_stat.
- *
- * Subscription will succeed even if the topic has not been advertised;
- * in this case the topic will have a timestamp of zero, it will never
- * signal a poll() event, checking will always return false and it cannot
- * be copied. When the topic is subsequently advertised, poll, check,
- * stat and copy calls will react to the initial publication that is
- * performed as part of the advertisement.
- *
- * Subscription will fail if the topic is not known to the system, i.e.
- * there is nothing in the system that has declared the topic and thus it
- * can never be published.
- *
- * If a publisher publishes multiple instances the subscriber should
- * subscribe to each instance with orb_subscribe_multi
- * (@see orb_advertise_multi()).
- *
- * @param meta The uORB metadata (usually from the ORB_ID() macro)
- * for the topic.
- * @param instance The instance of the topic. Instance 0 matches the
- * topic of the orb_subscribe() call, higher indices
- * are for topics created with orb_advertise_multi().
- * @return ERROR on error, otherwise returns a handle
- * that can be used to read and update the topic.
- * If the topic in question is not known (due to an
- * ORB_DEFINE_OPTIONAL with no corresponding ORB_DECLARE)
- * this function will return -1 and set errno to ENOENT.
- */
- int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance) ;
- /**
- * Unsubscribe from a topic.
- *
- * @param handle A handle returned from orb_subscribe.
- * @return OK on success, ERROR otherwise with errno set accordingly.
- */
- int orb_unsubscribe(int handle) ; //取消订阅一个主题,handle是orb_subscribe返回的句柄
- /**
- * Fetch data from a topic.
- *
- * This is the only operation that will reset the internal marker that
- * indicates that a topic has been updated for a subscriber. Once poll
- * or check return indicating that an updaet is available, this call
- * must be used to update the subscription.
- *
- * @param meta The uORB metadata (usually from the ORB_ID() macro)
- * for the topic.
- * @param handle A handle returned from orb_subscribe.
- * @param buffer Pointer to the buffer receiving the data, or NULL
- * if the caller wants to clear the updated flag without
- * using the data.
- * @return OK on success, ERROR otherwise with errno set accordingly.
- */
- int orb_copy(const struct orb_metadata *meta, int handle, void *buffer) ; //从主题中获取数据,buffer就是接收数据存放的位置
- /**
- * Check whether a topic has been published to since the last orb_copy.
- *
- * This check can be used to determine whether to copy the topic when
- * not using poll(), or to avoid the overhead of calling poll() when the
- * topic is likely to have updated.
- *
- * Updates are tracked on a per-handle basis; this call will continue to
- * return true until orb_copy is called using the same handle. This interface
- * should be preferred over calling orb_stat due to the race window between
- * stat and copy that can lead t
uORBMain.cpp学习的更多相关文章
- <CPP学习>第一天 第一个CPP程序 hello word
由于我是计算机类嵌入式专业的大一学生,之前一直使用的是生万物的C语言,了解了其过程性语言的特性及其基础语法,在大一下学期期末阶段想自学一下C++,其实在开学初就买了一本C++ Primer,但由于各种 ...
- cpp学习笔记 1一个简单的小程序以及一些的知识点
今天买的cpp到了从今天開始又一次学习cpp如今发现学校发的书真的不怎莫样. <em>#include<stdio.h>//预处理命令 int main()/*第一个被调用的函 ...
- <CPP学习 第二天> 字符串的输入 及 String类
今天简单的学习了字符串的输入以及C++的String类. 1.面向行的输入: getline(); getline()函数读取整行,通过回车键输入的换行符来确定输入结尾.要调用这种方法,可以使用cin ...
- cpp 学习笔记
1.C++中模仿gets是 getline(cin, string object) #include <bits/stdc++.h> #define IOS ios::sync_with ...
- src/lib/framework/src/driverFramework.cpp学习
int Framework::initialize() { DF_LOG_DEBUG("Framework::initialize"); g_framework = new Syn ...
- 传智播客C++视频学习笔记(3)
#include<iostream> using namespace std; //内存分区模型 //代码区,存放二进制代码,由操作系统进行管理 //全局区,存放全局变量.静态变量.常量( ...
- C++ map排序(按照value值排序)_glp_hit_新浪博客
C++ map排序(按照value值排序)_glp_hit_新浪博客 C++ map排序(按照value值排序) (2012-07-12 14:19:51) 转载▼ 标签: ...
- Linux 新系统个人配置
1,装codeblocks 2,装vim,检查gcc,g++,修改vim环境 cd ~vim .vimrc添加如下几行:set shiftwidth=4 (表示每一级缩进的长度)s ...
- AndroidStudio2.2.x以上使用cMake编译调用底层c生成依赖库
最近使用AndroidStudio的最新ndk编译方式cMake来编译底层cpp文件,由于之前没有接触过cMake语法,先附上官方学习文档地址:https://developer.android.co ...
随机推荐
- 左手Mongodb右手Redis 第一章,进入Mongodb和Redis的世界
---恢复内容开始--- 1,为什么要使用非关系型数据库,关系型数据库咋滴,不能用嘛? 存在即合理,非关系型数据库的出现,那说明关系型数据库不适用了. 非关系型数据库(NOSQL)-->Not ...
- Python 进阶_生成器 & 生成器表达式
目录 目录 相关知识点 生成器 生成器 fab 的执行过程 生成器和迭代器的区别 生成器的优势 加强的生成器特性 生成器表达式 生成器表达式样例 小结 相关知识点 Python 进阶_迭代器 & ...
- java方法调用及传参
静态方法:有static修饰的方法. 非静态方法:没有static修饰的方法. 方法调用: 一静态方法调用 静态方法/属性 1)一个类:直接调用. 2)不同类/不同文件: a: 类名.属性名/方法名 ...
- 字符串模式匹配算法系列(一):BF算法
算法背景: BF(Brute Force)算法,是一种在字符串匹配的算法中,比较符合人类自然思维方式的方法,即对源字符串和目标字符串逐个字符地进行比较,直到在源字符串中找到完全与目标字符串匹配的子字符 ...
- 斯坦福【概率与统计】课程笔记(二):从EDA开始
探索性数据分析(Exploratory Data Analysis) 本节课程先从统计分析四步骤中的第二步:EDA开始. 课程定义了若干个术语,如果学习过机器学习的同学,应该很容易类比理解: popu ...
- Java享元模式(Flyweight Pattern)
享元模式(Flyweight Pattern)主要用于减少创建的对象数量,并减少内存占用并提高性能. 这种类型的设计模式属于结构模式,因为该模式提供了减少对象计数的方法,从而改善应用的对象结构. 享元 ...
- 系统安装2---BIOS设置
对于新的电脑通过U盘安装Windows系统,我们第一步绝对是修改BIOS设置.在这里面我们要修改几项比较重要的选项.如下介绍: 修改第一启动项:目的就是让电脑的第一启动项变为U盘启动. 调节引导方式: ...
- for语句和if语句画正方形菱形
public static void main(String[] args) { int n =8; // 空心正方形 for(int i=0;i<=n;i++){ if(i==0||i==n) ...
- HDU 2152 Fruit( DP )
Fruit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- VINS 回环检测与全局优化
回环检测 VINS回环检测与全局优化都在pose_graph.cpp内处理.首先在pose_graph_node加载vocabulary文件给BriefDatabase用,如果要加载地图,会loadP ...