linux iio_dev iio_inio 成员

struct iio_dev {
	int				id;

	int				modes;
	int				currentmode;
	struct device			dev;

	struct iio_event_interface	*event_interface;

	struct iio_buffer		*buffer;
	struct list_head		buffer_list;
	int				scan_bytes;
	struct mutex			mlock;

	const unsigned long		*available_scan_masks;
	unsigned			masklength;
	const unsigned long		*active_scan_mask;
	bool				scan_timestamp;
	unsigned			scan_index_timestamp;
	struct iio_trigger		*trig;
	bool				trig_readonly;
	struct iio_poll_func		*pollfunc;
	struct iio_poll_func		*pollfunc_event;

	struct iio_chan_spec const	*channels;
	int				num_channels;

	struct list_head		channel_attr_list;
	struct attribute_group		chan_attr_group;
	const char			*name;
	const struct iio_info		*info;
	clockid_t			clock_id;
	struct mutex			info_exist_lock;
	const struct iio_buffer_setup_ops	*setup_ops;
	struct cdev			chrdev;
#define IIO_MAX_GROUPS 6
	const struct attribute_group	*groups[IIO_MAX_GROUPS + 1];
	int				groupcounter;

	unsigned long			flags;
#if defined(CONFIG_DEBUG_FS)
	struct dentry			*debugfs_dentry;
	unsigned			cached_reg_addr;
#endif
};

/**?
struct iio_info {
	struct module			*driver_module;
	const struct attribute_group	*event_attrs;
	const struct attribute_group	*attrs;

	int (*read_raw)(struct iio_dev *indio_dev,
			struct iio_chan_spec const *chan,
			int *val,
			int *val2,
			long mask);

	int (*read_raw_multi)(struct iio_dev *indio_dev,
			struct iio_chan_spec const *chan,
			int max_len,
			int *vals,
			int *val_len,
			long mask);

	int (*read_avail)(struct iio_dev *indio_dev,
			  struct iio_chan_spec const *chan,
			  const int **vals,
			  int *type,
			  int *length,
			  long mask);

	int (*write_raw)(struct iio_dev *indio_dev,
			 struct iio_chan_spec const *chan,
			 int val,
			 int val2,
			 long mask);

	int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
			 struct iio_chan_spec const *chan,
			 long mask);

	int (*read_event_config)(struct iio_dev *indio_dev,
				 const struct iio_chan_spec *chan,
				 enum iio_event_type type,
				 enum iio_event_direction dir);

	int (*write_event_config)(struct iio_dev *indio_dev,
				  const struct iio_chan_spec *chan,
				  enum iio_event_type type,
				  enum iio_event_direction dir,
				  int state);

	int (*read_event_value)(struct iio_dev *indio_dev,
				const struct iio_chan_spec *chan,
				enum iio_event_type type,
				enum iio_event_direction dir,
				enum iio_event_info info, int *val, int *val2);

	int (*write_event_value)(struct iio_dev *indio_dev,
				 const struct iio_chan_spec *chan,
				 enum iio_event_type type,
				 enum iio_event_direction dir,
				 enum iio_event_info info, int val, int val2);

	int (*validate_trigger)(struct iio_dev *indio_dev,
				struct iio_trigger *trig);
	int (*update_scan_mode)(struct iio_dev *indio_dev,
				const unsigned long *scan_mask);
	int (*debugfs_reg_access)(struct iio_dev *indio_dev,
				  unsigned reg, unsigned writeval,
				  unsigned *readval);
	int (*of_xlate)(struct iio_dev *indio_dev,
			const struct of_phandle_args *iiospec);
	int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned val);
	int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev,
				      unsigned count);
};


                                    
展开阅读全文

linux网络编程sockaddr_in里面的成员

08-09

这是小弟来论坛第一次求助,希望论坛的大哥大姐们能够指点迷津。我用的是 ubuntu 系统,在学linux编程,前面似乎都很顺利。但是到了和网络这部分就有点小伤感了。我尝试编写UDP的客户端和服务器程序。rn[code=c]#include rn#includern#includern#include rn#include rn#include rn#include rn#include rn#include rn#include rn /*包含相关的头文件。*/rnrn#define REMOTEPORT 4567 /*定义表示端口号的常量。*/rn#define REMOTEIP "127.0.0.1" /*定义表示表IP的常量。*/rnrnint main(int argc,char *argv[])rnrn int s,len; /*定义相关的变量。*/rn struct sockaddr_in addr;rn int addr_len;rn char msg[256]; /*定义一个数组发送与接收数据。*/rn int i=0;rn if (( s= socket(AF_INET, SOCK_DGRAM, 0) )<0) /*建立一个socket。*/rn rn perror("error"); /*输出错误。*/rn exit(1);rn rn elsern rn printf("socket created .\n"); /*输出提示信息。*/rn printf("socked id: %d \n",s);rn printf("remote ip: %s \n",REMOTEIP);rn printf("remote port: %d \n",REMOTEPORT);rn rnrn len=sizeof(struct sockaddr_in); /*长度。*/rn bzero(&addr,sizeof(addr)); /*空间地址结构体所在的内存空间。*/rn addr.sin_family=AF_INET; /*填充地址与端口的信息。*/rn addr.sin_port=htons(REMOTEPORT); /*端口。*/rn addr.sin_addr.s_addr=inet_addr(REMOTEIP);rnrn while (1) /*循环。*/rn rn bzero(msg,sizeof(msg)); /*清空msg所在的内存。*/rn len = read(STDIN_FILENO,msg,sizeof(msg)); /*接收信息。*/rn sendto(s,msg,len,0,&addr,addr_len); /*发送信息。*/rn printf("\nInput message: %s \n",msg); /*输出结果。*/rn len= recvfrom (s,msg,sizeof(msg),0,&addr,&addr_len);rn /*这是接收到的信息。*/rn printf("%d :",i); /*输出计数。*/rn i++; /*计数自加。*/rn printf("Received message: %s \n",msg); /*这是服务器返回的信息。*/rn rnrn[/code]rn这是其中的客户端代码,代码本身我能理解,只是现实和课本还有视频有出路难以理解。rn我最难以理解的是为什么sockaddr_in这个结构体类型原型是这样的:rnsockaddr_in(在netinet/in.h中定义):rn[code=c]sockaddr_in(在netinet/in.h中定义):rnstructsockaddr_inrn rnrn rnshortsin_family;/*Addressfamily一般来说AF_INET(地址族)PF_INET(协议族)*/rn rnunsignedshortsin_port;/*Portnumber(必须要采用网络数据格式,普通数字可以用htons()函数转换成网络数据格式的数字)*/rn rnstructin_addrsin_addr;/*Internetaddress*/rn rnunsignedcharsin_zero[8];/*Samesizeasstructsockaddr没有实际意义,只是为了 跟SOCKADDR结构在内存中对齐*/rn rn;[/code]rn但是我打开该头文件发现rn情况是这样的(课本和百度如是说)rn[code=c]struct sockaddr_inrn rn __SOCKADDR_COMMON (sin_);rn in_port_t sin_port; /* Port number. */rn struct in_addr sin_addr; /* Internet address. */rnrn /* Pad to size of `struct sockaddr'. */rn unsigned char sin_zero[sizeof (struct sockaddr) -rn __SOCKADDR_COMMON_SIZE -rn sizeof (in_port_t) -rn sizeof (struct in_addr)];rn ;rn[/code]rn并且在sockaddr.h发现了这个rn[code=c]typedef unsigned short int sa_family_t;rnrn/* This macro is used to declare the initial common membersrn of the data types used for socket addresses, `struct sockaddr',rn `struct sockaddr_in', `struct sockaddr_un', etc. */rnrn#define __SOCKADDR_COMMON(sa_prefix) \rn sa_family_t sa_prefix##familyrn[/code]rn很奇怪为什么这么定义啊,和书上提到的我感觉是等价的,这样岂不是很麻烦。最让我头疼的是,我用的是codeblocks,我在编写代码的时候如果创建sockaddr_in结构体变量,在进行操作时根只有两个成员sin_port,sin_zero,请问这是怎么回事啊,有图有真相[img=https://img-bbs.csdn.net/upload/201408/09/1407555579_477473.jpg][/img]rn在编译的时候会出现很多警告,后来我加了一些头文件比如stdlib.h和string.h警告少了些。但是还是有:如下[img=https://img-bbs.csdn.net/upload/201408/09/1407556068_88273.png][/img]rn这个这些警告出现很奇怪,如果代码没有语法错误,我再点击一次编译运行,是会出结果的,但是如果我故意制造一个语法错误,然后再点击编译运行会出现,这时候再点击一次就直接出结果了,只有不更改代码就不出现这样的警告,这是为什么呀。 论坛

没有更多推荐了,返回首页