ioctl example
来源:互联网 发布:droid4x mac版 编辑:程序博客网 时间:2024/05/16 14:54
from
http://embedded.seattle.intel-research.net/wiki/index.php?title=An_example_Program_with_IOCTL
//************************************************************
// set_driver.c
//
// This file shows how to use ioctl to set/read settings of driver
//
// Author: Gefan Zhang
//*************************************************************
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "tosmac.h"
void msg_init(TOS_Msg* pMsg)
{
pMsg->length = 0;
pMsg->fcfhi = 0;
pMsg->fcflo = 0;
pMsg->dsn = 0;
pMsg->destpan = 0;
pMsg->addr = 0;
pMsg->type = 0;
pMsg->group = 0;
memset(pMsg->data, '/0', TOSH_DATA_LENGTH);
pMsg->strength = 0;
pMsg->lqi = 0;
pMsg->crc = 0;
pMsg->ack = 0;
pMsg->time = 0;
}
//--------------------- main -------------------------------
int main(int argc, char* argv[])
{
int tosmac_dev;
int ret;
// open as blocking mode
tosmac_dev = open(TOSMAC_DEVICE, O_RDWR);
if (tosmac_dev < 0)
{
fprintf(stderr, "Open error: %s/n", TOSMAC_DEVICE);
return 1;
}
//get frequency
ret = ioctl(tosmac_dev, TOSMAC_IOGETFREQ);
printf("freq is %d/n",ret);
//set channel
if(ioctl(tosmac_dev, TOSMAC_IOSETCHAN, 26) < 0)
{
fprintf (stderr, "IOCTL set TOSMAC channel error: %s/n", TOSMAC_DEVICE);
close (tosmac_dev);
return 1;
}
//set local address
if(ioctl(tosmac_dev, TOSMAC_IOSETADDR, 50) < 0)
{
fprintf (stderr, "IOCTL set TOSMAC address error: %s/n", TOSMAC_DEVICE);
close (tosmac_dev);
return 1;
}
// enable auto ack
ret = ioctl(tosmac_dev, TOSMAC_IOAUTOACK);
if(ret < 0)
{
fprintf (stderr, "IOCTL enable TOSMAC AutoAck error: %s/n", TOSMAC_DEVICE);
close (tosmac_dev);
return 1;
}
//change max payload size (max value can be set is 116 bytes)
if(ioctl(tosmac_dev, TOSMAC_IOSETMAXDATASIZE, 40) < 0)
{
fprintf (stderr, "IOCTL set TOSMAC max payload size error: %s/n", TOSMAC_DEVICE);
close (tosmac_dev);
return 1;
}
// close device
close (tosmac_dev);
return 0;
}
- ioctl example
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- ioctl
- oracle中length()与lengthb()区别
- 修复“我的电脑”或文件夹打开非常慢的问题
- 提高Request集合的效率
- Linux下编程为什么多用进程少用线程-编程讨论之二
- fckeditor php使用配置
- ioctl example
- Linux程序设计入门 - fork, pthread, and signals
- 开源BI系统的简述
- javascript正则表达式
- 用Tablediff把表數據生成SQL腳本
- 正则表达式
- jbpm入门例子
- 买票--真不容易呀
- SS5连接远程桌面总是中断