资源简介
基于bluez协议的linux下蓝牙设备搜索, 对初学者有点用.
代码片段和文件信息
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2000-2001 Qualcomm Incorporated
* Copyright (C) 2002-2003 Maxim Krasnyansky
* Copyright (C) 2002-2008 Marcel Holtmann
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not write to the Free Software
* Foundation Inc. 51 Franklin St Fifth Floor Boston MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
void baswap(bdaddr_t *dst const bdaddr_t *src)
{
register unsigned char *d = (unsigned char *) dst;
register const unsigned char *s = (const unsigned char *) src;
register int i;
for (i = 0; i < 6; i++)
d[i] = s[5-i];
}
char *batostr(const bdaddr_t *ba)
{
char *str = bt_malloc(18);
if (!str)
return NULL;
sprintf(str “%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X“
ba->b[0] ba->b[1] ba->b[2]
ba->b[3] ba->b[4] ba->b[5]);
return str;
}
bdaddr_t *strtoba(const char *str)
{
const char *ptr = str;
int i;
uint8_t *ba = bt_malloc(sizeof(bdaddr_t));
if (!ba)
return NULL;
for(i = 0; i < 6; i++) {
ba[i] = (uint8_t) strtol(ptr NULL 16);
if (i != 5 && !(ptr = strchr(ptr‘:‘)))
ptr = “:00:00:00:00:00“;
ptr++;
}
return (bdaddr_t *) ba;
}
int ba2str(const bdaddr_t *ba char *str)
{
uint8_t b[6];
baswap((bdaddr_t *) b ba);
return sprintf(str “%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X“
b[0] b[1] b[2] b[3] b[4] b[5]);
}
int str2ba(const char *str bdaddr_t *ba)
{
uint8_t b[6];
const char *ptr = str;
int i;
for (i = 0; i < 6; i++) {
b[i] = (uint8_t) strtol(ptr NULL 16);
if (i != 5 && !(ptr = strchr(ptr ‘:‘)))
ptr = “:00:00:00:00:00“;
ptr++;
}
baswap(ba (bdaddr_t *) b);
return 0;
}
int ba2oui(const bdaddr_t *ba char *str)
{
uint8_t b[6];
baswap((bdaddr_t *) b ba);
return sprintf(str “%2.2X-%2.2X-%2.2X“ b[0] b[1] b[2]);
}
int bachk(const char *str)
{
char tmp[18] *ptr = tmp;
if (!str)
return -1;
if (strlen(str) != 17)
return -1;
memcpy(tmp str 18);
while (*ptr) {
*ptr = toupper(*ptr);
if (*ptr < ‘0‘|| (*ptr > ‘9‘ && *ptr < ‘A‘) || *ptr > ‘F‘)
return -1;
ptr++;
*ptr = toupper(*ptr);
if (*ptr < ‘0‘|| (*ptr > ‘9‘ && *ptr < ‘A‘) || *ptr > ‘F‘)
return
- 上一篇:docker周阳老师的脑图xmind整理
- 下一篇:软件工程 实验室设备管理系统
相关资源
- bison-devel
- LINUX端口扫描源代码(C实现)
- MLdonkey_与_sancho_的安装使用
- 实验四 Linux用户和组的管理
- BASH中文帮助文档
- Linux上Qt-OpenCV采集摄像头视频并显示
- udp网络通信源代码(单播、组播、广
- linux下v4l2实现图片采集
- arm9 + linux modbus tcp 运行文件,可用于
- Linux下组播源码,含客户端和服务器
- 温湿度传感器DHT11在mini2440上基于lin
- UBUNTU LINUX教程
- linux内核裁剪具体步骤的图解及细解
- LINUX-FTP服务包 vsftpd-2.0.1-5.src.rpm
- 大恒相机QT例程LINUX
- vnc-3.3.7-x86_linux
- SecureCRTTomcat工程发布到linux系统上
- dnw-linux-v1.01.tar.gz
- Linux下基于epoll_线程池高并发服务器实
- udp 多线程实现多客户端并发,并采用
- AD9361驱动
- Linux/Windows局域网远程开机唤醒的例程
- linux系统调用表
- ap6255 firmware
- Linux内核视频教程.txt
- linux 语音实时对讲
- Linux网络编程(四)——epoll+多线程实
- LINUX操作系统文件系统设计实验代码
- WSL2使用xrdp连接xfce4桌面详细配置教程
- chat_room.zip
评论
共有 条评论