资源简介
linux 下的 dnw,整合了安装脚本,点击脚本直接安装,比其他繁琐的安装版本容易得多,具体使用方法见:http://blog.csdn.net/huanghui167/article/details/8174763
代码片段和文件信息
/* dnw2 linux main file. This depends on libusb.
*
* Author: Fox
* License: GPL
*
*/
#include
#include
#include
#include
#include
#include
#define QQ2440_SECBULK_IDVENDOR 0x5345
#define QQ2440_SECBULK_IDPRODUCT 0x1234
struct usb_dev_handle * open_port()
{
struct usb_bus *busses *bus;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
for(bus=busses;bus;bus=bus->next)
{
struct usb_device *dev;
for(dev=bus->devices;dev;dev=dev->next)
{
if( QQ2440_SECBULK_IDVENDOR==dev->descriptor.idVendor
&& QQ2440_SECBULK_IDPRODUCT==dev->descriptor.idProduct)
{
printf(“Target usb device found!\n“);
struct usb_dev_handle *hdev = usb_open(dev);
if(!hdev)
{
perror(“Cannot open device“);
}
else
{
if(0!=usb_claim_interface(hdev 0))
{
perror(“Cannot claim interface“);
usb_close(hdev);
hdev = NULL;
}
}
return hdev;
}
}
}
printf(“Target usb device not found!\n“);
return NULL;
}
void usage()
{
printf(“Usage: dnw2 \n\n“);
}
unsigned char* prepare_write_buf(char *filename unsigned int *len)
{
unsigned char *write_buf = NULL;
struct stat fs;
int fd = open(filename O_RDONLY);
if(-1==fd)
{
perror(“Cannot open file“);
return NULL;
}
if(-1==fstat(fd &fs))
{
perror(“Cannot get file size“);
goto error;
}
write_buf = (unsigned char*)malloc(fs.st_size+10);
if(NULL==write_buf)
{
perror(“malloc failed“);
goto error;
}
if(fs.st_size != read(fd write_buf+8 fs.st_size))
{
perror(“Reading file failed“);
goto error;
}
printf(“Filename : %s\n“ filename);
printf(“Filesize : %d bytes\n“ fs.st_size);
*((u_int32_t*)write_buf) = 0x30000000; //download address
*((u_int32_t*)write_buf+1) = fs.st_size + 10; //download size;
*len = fs.st_size + 10;
return write_buf;
error:
if(fd!=-1) close(fd);
if(NULL!=write_buf) free(write_buf);
fs.st_size = 0;
return NULL;
}
int main(int argc char *argv[])
{
if(2!=argc)
{
usage();
return 1;
}
struct usb_dev_handle *hdev = open_port();
if(!hdev)
{
return 1;
}
unsigned int len = 0;
unsigned char* write_buf = prepare_write_buf(argv[1] &len);
if(NULL==write_buf) return 1;
unsigned int remain = len;
unsigned int towrite;
printf(“Writing data ...\n“);
while(remain)
{
towrite = remain>512 ? 512 : remain;
if(towrite != usb_bulk_write(hdev 0x03 write_buf+(len-remain) towrite 3000))
{
perror(“usb_bulk_write failed“);
break;
}
remain-=towrite;
printf(“\r%d%\t %d bytes “ (len-remain)*100/len len-remain);
fflush(stdout);
}
if(0==remain) printf(“Done!\n“);
return 0;
}
- 上一篇:电脑鼠竞赛
- 下一篇:爬山算法和禁忌搜索对比代码+数据,可运行
相关资源
-
fr
amebuffer显示图片 - DM9008 linux 驱动
- linux c select简单
- Lua中调用C函数
- Linux mpu6050驱动程序
- linux 配置文件读写C
- linux0.11内核源码
- linux进程监控和守护进程的程序
- rocky凝思操作系统ISO镜像刻录到U盘里
- linux按键测试,获取按键状态
- Linux基本命令操作实验报告
- 学习用4.0版Linux下Zynq的axitimer中断驱动
- ros的urdf机器人模型功能包
- ROS创建工作空间代码我写的博客配套
- 2020大数据面试题总汇
- Linux实验1_常用命令应用.doc
- 树莓派用I2C读取mpu9250代码
- pgilinux-2019-1910-x86-64.txt
- 56706-Linux驱动程序开发第2版源码
- Linux下基于UDP的socket编程,适用多客户
- linux调用kettle所用到的自动化脚本 k
- linux计算器代码
- max9286+96705 4路AHDcamera方案
- 三期视频网上买的,带课件,安装包
- 基于Linux的网络聊天室.rar
- linux 命令.docx
- linux 下QT讯飞语音合成demo
- linux下查看端口是否被占用以及查看所
- socket编程常用API汇总
- arcsde10.2百度云连接linux版本
评论
共有 条评论