BlueZ API - hci_get_route(), hci_open_dev(), hci_inquiry(), hci_read_remote()
android/Bluetooth 2014. 8. 20. 17:17int hci_get_route(bdaddr_t *bdaddr)
: bdaddr의 값으로 NULL값을 주면 사용가능한 Local의 첫 번째 Adapter의 Index값을 반환해 준다.
: local에 2개 이상의 Adapter가 존재하며 해당 bdaddr의 값을 알고 있을 경우 다음과 같은 함수를 사용하여 ID값을 반환 받을 수 있다.
ex) int dev_id = hci_devid("01:23:45:67:89:AB")
typedef struct {
uint8_t b[ 6 ];
} --attribute--( (packed) ) bdaddr_t;
int hci_devid ( const char *addr ) ;
int hci_open_dev(int dev_id)
: socket을 생성하고 성공시 device descriptor를 리턴하게 된다. Error일 경우 -1을 리턴하게 된다.
int hci_inquiry(int dev_id, int len, int max_rsp, const uint8_t *lap, inquiry_info **ii, long flags)
#2 len : inquiry 동작 시간을 설정하는 것이며 약 1.28s * len 이 된다.
#6 flags : IREQ_CACHE_FLUSH(1)의 값이 들어가면 기존의 cache에 있는 값을 flush한 다음 다시 inquiry 하게
되며 0의 값을 가지게 되면 Remote Device가 범위내에 없더라도 cache에 그 정보가 있다면 출력하게 된다.
typedef struct {
bdaddr_t bdaddr;
uint8_t pscan_rep_mode;
uint8_t pscan_period_mode;
uint8_t pscan_mode;
uint8_t dev_class[3];
uint16_t clock_offset;
} --attribute-- ( (packed) ) inquiry_info;
int hci_read_remote(int dd, const bdaddr_t *bdaddr, int len, char *name, int timout)
마지막 Paramter인 timeout의 단위는 ms 이다.
* Compile
arm-none-linux-gnueabi-gcc -o simplescan simplescan.c --static -lbluetooth
* simplescan.c
#include <stdio.h> |
춮처 : Bluetooth Essentials
'android > Bluetooth' 카테고리의 다른 글
L2CAP을 이용한 Socket Programming Note (0) | 2014.08.21 |
---|---|
Ubuntu v12.04.5에서의 BlueZ 개발 환경 (0) | 2014.08.21 |
RFCOMM을 이용한 Socket programming Note (0) | 2014.08.20 |
Kitkat-4.4.2(BlueZ vs Bluedroid) Module 정리 (0) | 2014.07.08 |
[Tip] Bluetooth를 이용하여 파일을 수신할 경우 수신된 파일 위치 (0) | 2013.12.03 |