[pixhawk笔记]6-uORB流程及关键函数解析
本文中将结合代码、文档及注释,给出uORB执行流程及关键函数的解析,由于uORB的机制实现较为复杂,所以本文主要学习如何使用uORB的接口来实现通信。回到上一篇笔记中的代码:
#include <px4_config.h>
#include <px4_tasks.h>
#include <px4_posix.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>
#include <string.h> #include <uORB/uORB.h>
#include <uORB/topics/sensor_combined.h>
#include <uORB/topics/vehicle_attitude.h> __EXPORT int px4_simple_app_main(int argc, char *argv[]); int px4_simple_app_main(int argc, char *argv[])
{
PX4_INFO("Hello Sky!");
int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
orb_set_interval(sensor_sub_fd,200);/* limit the update rate to 5 Hz */ struct vehicle_attitude_s att;
memset(&att,0,sizeof(att));
orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude),&att); px4_pollfd_struct_t fds[] = {
{.fd = sensor_sub_fd, .events = POLLIN},
}; int error_counter = 0; for(int i=0;i<5;i++){
int poll_ret = px4_poll(fds,1,1000); if(poll_ret == 0){
PX4_ERR("Got no data within a second");
}else if(poll_ret<0){
if(error_counter<10 || error_counter % 50 == 0){
PX4_ERR("ERROR return value from poll():%d",poll_ret);
} error_counter++;
}else{
if(fds[0].revents & POLLIN){
struct sensor_combined_s raw;
orb_copy(ORB_ID(sensor_combined),sensor_sub_fd,&raw);
PX4_INFO("Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
(double)raw.accelerometer_m_s2[0],
(double)raw.accelerometer_m_s2[1],
(double)raw.accelerometer_m_s2[2]); att.rollspeed = raw.accelerometer_m_s2[0];
att.pitchspeed = raw.accelerometer_m_s2[1];
att.yawspeed = raw.accelerometer_m_s2[2]; orb_publish(ORB_ID(vehicle_attitude),att_pub,&att);
}
}
}
PX4_INFO("exiting");
return OK;
}
- 订阅
可以看出,订阅一个并获取一个主题的信息主要流程及其中关键函数如下: #include <uORB/topics/sensor_combined.h>
..
int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
该语句先包含一个主题头文件,该文件内容如下:
/****************************************************************************
*
* Copyright (C) 2013-2016 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/ /* Auto-generated by genmsg_cpp from file /home/spy/src/Firmware/msg/sensor_combined.msg */ #pragma once #include <stdint.h>
#ifdef __cplusplus
#include <cstring>
#else
#include <string.h>
#endif #include <uORB/uORB.h> #ifndef __cplusplus
#define RELATIVE_TIMESTAMP_INVALID 2147483647 #endif #ifdef __cplusplus
struct __EXPORT sensor_combined_s {
#else
struct sensor_combined_s {
#endif
uint64_t timestamp; // required for logger
float gyro_rad[3];
uint32_t gyro_integral_dt;
int32_t accelerometer_timestamp_relative;
float accelerometer_m_s2[3];
uint32_t accelerometer_integral_dt;
int32_t magnetometer_timestamp_relative;
float magnetometer_ga[3];
int32_t baro_timestamp_relative;
float baro_alt_meter;
float baro_temp_celcius; #ifdef __cplusplus
static constexpr int32_t RELATIVE_TIMESTAMP_INVALID = 2147483647; #endif
}; /* register this as object request broker structure */
ORB_DECLARE(sensor_combined);
可以看出,该文件定义了一个sensor_combined的结构体,该结构体中包含了陀螺仪、加速度计、磁罗盘和气压计的数据。并使用ORB_DECLARE()宏声明一个sensor_combined的主题。该文件由genmsg.cpp由/msg/sensor_combined.msg中的内容生成,该msg文件内容如下:
#
# Sensor readings in SI-unit form.
#
# These fields are scaled and offset-compensated where possible and do not
# change with board revisions and sensor updates.
# int32 RELATIVE_TIMESTAMP_INVALID = 2147483647 # (0x7fffffff) If one of the relative timestamps is set to this value, it means the associated sensor values are invalid # gyro timstamp is equal to the timestamp of the message
float32[3] gyro_rad # average angular rate measured in the XYZ body frame in rad/s over the last gyro sampling period
uint32 gyro_integral_dt # gyro measurement sampling period in us int32 accelerometer_timestamp_relative # timestamp + accelerometer_timestamp_relative = Accelerometer timestamp
float32[3] accelerometer_m_s2 # average value acceleration measured in the XYZ body frame in m/s/s over the last accelerometer sampling period
uint32 accelerometer_integral_dt # accelerometer measurement sampling period in us int32 magnetometer_timestamp_relative # timestamp + magnetometer_timestamp_relative = Magnetometer timestamp
float32[3] magnetometer_ga # Magnetic field in NED body frame, in Gauss int32 baro_timestamp_relative # timestamp + baro_timestamp_relative = Barometer timestamp
float32 baro_alt_meter # Altitude, already temp. comp.
float32 baro_temp_celcius # Temperature in degrees celsius
可以看出,在.msg文件中主要定义了一些成员变量项,自动生成的.h文件使用这些成员变量生成了结构体, 并使用ORB_DECLARE()宏声明了这些主题,ORB_DECLARE()代码如下:读者也可以按该方法加入自定义的.msg文件,并编写对应的CMakeLists.txt,来生成消息,通过uORB来交换数据。
/**
* Declare (prototype) the uORB metadata for a topic (used by code generators).
*
* @param _name The name of the topic.
*/
#if defined(__cplusplus)
# define ORB_DECLARE(_name) extern "C" const struct orb_metadata __orb_##_name __EXPORT
#else
# define ORB_DECLARE(_name) extern const struct orb_metadata __orb_##_name __EXPORT
#endif
可以看出,ORB_DECLARE()宏实际上定义了一些orb_metadata 的结构体变量,变量名为__orb_prototype_name。
订阅时指定了ORB_ID,ORB_ID宏如下:
/**
* Generates a pointer to the uORB metadata structure for
* a given topic.
*
* The topic must have been declared previously in scope
* with ORB_DECLARE().
*
* @param _name The name of the topic.
*/
#define ORB_ID(_name) &__orb_##_name
其实是取了ORB_DECLARE()宏生成__orb_prototype_name结构体的地址。orb_subscribe的原型如下:
/**
* Subscribe to 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.
*
* Internally this will call orb_subscribe_multi with instance 0.
*
* @param meta The uORB metadata (usually from the ORB_ID() macro)
* 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) ;
可看出,其接受参数就是一个orb_metadata的常值指针,从注释看,其返回一个int类型的fd,表示文件描述符,该描述符作为一个句柄,可以用来读取并更新数据,如果订阅失败,则返回ERROR。
还有个orb_subscribe_multi函数可以用于订阅主题有多个实例的情况:
/**
* 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) ;
该函数可以通过instance参数来指定实例索引。
订阅了之后可以获取该主题的数据,获取主题数据有如下几个函数可用:
- px4_poll
本文开头的代码中即用的该函数,该函数其实是调用的nuttx系统的poll函数,该函数原型如下:
/****************************************************************************
* Name: poll
*
* Description:
* poll() waits for one of a set of file descriptors to become ready to
* perform I/O. If none of the events requested (and no error) has
* occurred for any of the file descriptors, then poll() blocks until
* one of the events occurs.
*
* Inputs:
* fds - List of structures describing file descriptors to be monitored
* nfds - The number of entries in the list
* timeout - Specifies an upper limit on the time for which poll() will
* block in milliseconds. A negative value of timeout means an infinite
* timeout.
*
* Return:
* On success, the number of structures that have non-zero revents fields.
* A value of 0 indicates that the call timed out and no file descriptors
* were ready. On error, -1 is returned, and errno is set appropriately:
*
* EBADF - An invalid file descriptor was given in one of the sets.
* EFAULT - The fds address is invalid
* EINTR - A signal occurred before any requested event.
* EINVAL - The nfds value exceeds a system limit.
* ENOMEM - There was no space to allocate internal data structures.
* ENOSYS - One or more of the drivers supporting the file descriptor
* does not support the poll method.
*
****************************************************************************/ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
可以看出,该函数用于阻塞等待文件描述符更新,等待时间为timeout毫秒。该函数返回值大于0表示等到数据更新,0表示没有等到数据更新,小于0则表示发生错误。(返回值的详细情况参见注释)。
- orb_check
该函数原型及注释如下:/**
* 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 to missed updates.
*
* @param handle A handle returned from orb_subscribe.
* @param updated Set to true if the topic has been updated since the
* last time it was copied using this handle.
* @return OK if the check was successful, ERROR otherwise with
* errno set accordingly.
*/
int orb_check(int handle, bool *updated) ;该函数也是用于检查主题是否有更新,与px4_poll不同的是没有阻塞等待,如果从上次orb_copy函数执行之后,主题发生了更新,则将第二个参数设置为true,否则为false。若函数正确执行,返回OK,否则返回ERROR。相比于px4_poll,该函数不会阻塞等待,所以不会造成系统过载。
orb_stat
/**
* Return the last time that the topic was updated. If a queue is used, it returns
* the timestamp of the latest element in the queue.
*
* @param handle A handle returned from orb_subscribe.
* @param time Returns the absolute time that the topic was updated, or zero if it has
* never been updated. Time is measured in microseconds.
* @return OK on success, ERROR otherwise with errno set accordingly.
*/
int orb_stat(int handle, uint64_t *time) ;该函数用于获得指定的主题上一次更新的绝对时间,为毫秒数。返回值为OK表示成功执行,ERROR为有错误发生,具体错误可以查看errno。从orb_check的注释中可以看出,该函数有缺陷,因为在orb_stat和orb_copy之间的时间窗口有可能发生更新,而根据返回的毫秒数来确定可能会错过该更新。
- orb_check
使用以上三个函数可以确定主题是否发生更新,如有更新发生,则可以使用orb_copy来从主题中获得更新数据:
- orb_copy
该函数原型如下:/**
* 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) ;代码中调用时形式如下:
struct sensor_combined_s raw;
orb_copy(ORB_ID(sensor_combined),sensor_sub_fd,&raw);第一个参数为ORB_ID获取的主题ID(orb_metadata的指针),第二个参数为文件描述符,可用订阅时返回值,第三个参数为更新数据的缓存地址,可以为一个主题对应结构体类型的地址。
此外,在订阅时还有其他函数: orb_set_interval(sensor_sub_fd,200);该函数用于设置主题更新速率。
- orb_copy
- 发布
发布主题主要使用两个函数:- orb_advertise(ORB_ID(vehicle_attitude),&att);
该函数原型及注释如下:// ==== uORB interface methods ====
/**
* 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.
*
* Internally this will call orb_advertise_multi with an instance of 0 and
* default priority.
*
* @param meta The uORB metadata (usually from the ORB_ID() macro)
* 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
* used.
* @return nullptr on error, otherwise returns an object pointer
* 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 nullptr and set errno to 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);
}该函数用来广播一个主题发布者,返回一个对象指针,该对象可用来发布主题,若出现错误,则返回空指针。
该函数接收参数为有三个:第一个ORB_ID,表示要发布的主题ID;第二个为结构体指针,指向要发布的数据结构体;第三个为队列大小,默认为1,表示没有消息队列。
通过查看代码,发现其实该函数调用了orb_advertise_multi函数,使用空指针0作为主题的实例索引,表示只广播主题的第一个实例,并使用默认优先级来广播。
也可以使用orb_advertise_multi函数。其原型和注释如下:/**
* 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
* (each instance has its own buffer).
* 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)
* 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 instance Pointer to an integer which will yield the instance ID (0-based)
* of the publication. This is an output parameter and will be set to the newly
* 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
* used.
* @return ERROR on error, otherwise returns a handle
* 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) ;该函数可以指定int*类型的instance参数,可以在一个主题存在多个实例时使用。
orb_publish(ORB_ID(vehicle_attitude),att_pub,&att);
该函数用于在广播主题之后发布主题,使用广播时返回的主题句柄。函数原型及注释如下:/**
* 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)
* for the topic.
* @handle The handle returned from orb_advertise.
* @param data A pointer to the data to be published.
* @return OK on success, ERROR otherwise with errno set accordingly.
*/
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) ;该函数用于发布主题,发布之后会通知所有订阅者主题已更新(例如使用px4_poll进行阻塞等待的订阅者),而orb_check需要手动检查是否已更新。
- orb_advertise(ORB_ID(vehicle_attitude),&att);
[pixhawk笔记]6-uORB流程及关键函数解析的更多相关文章
- C++ Opencv 傅里叶变换的代码实现及关键函数详解
一.前言 最近几天接触了图像的傅里叶变换,数学原理依旧不是很懂,因此不敢在这里妄言.下午用Opencv代码实现了这一变换,有一些经验心得,愿与大家分享. 二.关键函数解析 2.1copyMakeBor ...
- [pixhawk笔记]5-uORB消息传递
本文主要内容翻译自官方文档:https://dev.px4.io/en/middleware/uorb.html 在前一篇笔记中使用uORB完成消息传递,实现了一个简单示例程序,本文将对uORB进行系 ...
- online ddl 使用、测试及关键函数栈
[MySQL 5.6] MySQL 5.6 online ddl 使用.测试及关键函数栈 http://mysqllover.com/?p=547 本文主要分为三个部分,第一部分是看文档时的笔记:第 ...
- [pixhawk笔记]4-如何写一个简单的应用程序
本文主要内容来自于:https://dev.px4.io/en/tutorials/tutorial_hello_sky.html,并对文档中的部分问题进行更正. 本文假设已经建立好开发环境并能正确编 ...
- 深入分析ENode的内部实现流程和关键地方的幂等设计
ENode 2.0 - 深入分析ENode的内部实现流程和关键地方的幂等设计 前言 ENode架构图 ENode框架内部实现流程分析 Command的幂等处理 Domain Event持久化时的并发冲 ...
- ES6学习笔记(十五)Generator函数的异步应用
1.传统方法 ES6 诞生以前,异步编程的方法,大概有下面四种. 回调函数 事件监听 发布/订阅 Promise 对象 Generator 函数将 JavaScript 异步编程带入了一个全新的阶段. ...
- Go语言学习之3 流程控制、函数
主要内容: 1. strings和strconv使用2. Go中的时间和日期类型3. 指针类型4. 流程控制5. 函数详解 1. strings和strconv使用 //strings . strin ...
- MQTT协议笔记之发布流程
MQTT协议笔记之发布流程 前言 这次要讲到客户端/服务器的发布消息行为,与PUBLISH相关的消息类型,会在这里看到. PUBLISH 客户端发布消息经由服务器分发到所有对应的订阅者那里.一个订阅者 ...
- Linux基础-shell脚本知识整理和脚本编写----------变量、运算符、流程控制、函数、计划任务(发送邮件)
I:知识整理:变量.运算符.流程控制.函数.计划任务 变量 系统变量:set:显示所有变量 env:环境变量 常用系统变量: path pwd lang home his ...
随机推荐
- forEach循环dom
大家都知道forEach是循环数组用的,而且很方便,可以丢掉for循环了,但是它不能循环Dom元素.其实我们可以利用call来完成forEach循环Dom; html结构: <ul class= ...
- Django学习笔记第十二篇--关于自定义数据库字段数据类型
一.需求背景: django的models模块提供了很多数据字段的数据类型field,但是总有写奇葩需求不能依靠默认字段满足,所以需要自定义数据数据库数据字段类型.所有的自定义field应该在app路 ...
- LAMP集群项目
vi /etc/sysconfig/network 一.安装硬件环境(安装虚拟机) 1.安装VMware步骤 1.修改网卡配置 vi /etc/sysconfig/network-scripts/if ...
- Java+selenium+Fitnesse
刚开始接触selenium是进公司后,老大给我们培训了一下UI自动化(其实也不叫培训啦,就是让我们知道有这么个东西吧,我这么说,老大看到得打人了,哈哈).要进行自动化测试,当然就得搭建一个自动化测试框 ...
- UVA12470—Tribonacci (类似斐波那契,简单题)
题目链接:https://vjudge.net/problem/UVA-12470 题目意思:我们都知道斐波那契数列F[i]=F[i-1]+F[i-2],现在我们要算这样的一个式子T[i]=T[i-1 ...
- [iOS微博项目 - 4.4] - 会员标识
github: https://github.com/hellovoidworld/HVWWeibo A.会员标识 1.需求 给vip会员打上会员标识 不同等级的vip会员使用不同的标识 使用橙色作为 ...
- Android /system/build.prop 文件
# begin build properties (开始设置系统性能) # autogenerated by buildinfo.sh (通过设置形成系统信息) ro.build.id=GRI40 ( ...
- element自定义表单验证
element-ui框架下修改密码弹窗进行表单验证. 除了基础校验,密码不为空,长度不小于6字符,需求中还需校验密码由数字和字母组合. 处理代码如下: <el-dialog :visible.s ...
- 浅析Android View(二)
深入理解Android View(一) View的位置參数信息 二.View的绘制过程 View的绘制过程一共分为三个部分: - measure(測量View的大小) - layout(确定View的 ...
- NSUserDefaults保存对象数组报错
在使用NSUserDefaults的时候插入数据有时候会报以下错误:Attempt to set a non-property-list objec 这种错误的原因是插入了不识别的数据类型,NSUse ...