2017-11-21 24 views
0

dbus가있는 초보자이며 bash dbus-send 명령으로 블루투스 스캔을 수행하려고합니다. 나는이 줄을 사용하십시오dbus를 통해 블루투스 검색을 어떻게 수행합니까?

$dbus-send --system --type=method_call --dest=org.bluez --print-reply /org/bluez/hci0 org.bluez.Adapter1.StartDiscovery 

을하지만 발견은 DBUS 모니터에서

내가 볼 ... 시작하지 :

method call time=1511273024.833459 sender=:1.55 -> destination=org.freedesktop.DBus serial=1 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=Hello 
method return time=1511273024.921444 sender=org.freedesktop.DBus -> destination=:1.55 serial=1 reply_serial=1 
    string ":1.55" 
signal time=1511273024.923719 sender=org.freedesktop.DBus -> destination=(null destination) serial=101 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged 
string ":1.55" 
string "" 
string ":1.55" 
    signal time=1511273024.926411 sender=org.freedesktop.DBus -> destination=:1.55 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired 
string ":1.55" 
method call time=1511273024.927109 sender=:1.55 -> destination=org.bluez serial=2 path=/org/bluez/hci0; interface=org.bluez.Adapter1; member=StartDiscovery 
method call time=1511273024.927628 sender=:1.1 -> destination=org.freedesktop.DBus serial=69 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch 
string "type='signal',sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0=':1.55'" 
method return time=1511273024.928272 sender=org.freedesktop.DBus -> destination=:1.1 serial=43 reply_serial=69 
method return time=1511273024.928729 sender=:1.1 -> destination=:1.55 serial=70 reply_serial=2 
signal time=1511273024.929236 sender=org.freedesktop.DBus -> destination=:1.55 serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost 
string ":1.55" 
signal time=1511273024.929945 sender=org.freedesktop.DBus -> destination=(null destination) serial=44 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged 
string ":1.55" 
string ":1.55" 
string "" 
method call time=1511273024.930956 sender=:1.1 -> destination=org.freedesktop.DBus serial=71 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch 
string "type='signal',sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0=':1.55'" 
method return time=1511273024.931635 sender=org.freedesktop.DBus -> destination=:1.1 serial=45 reply_serial=71 
signal time=1511273024.932142 sender=:1.1 -> destination=(null destination) serial=72 path=/org/bluez/hci0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged 
string "org.bluez.Adapter1" 
array [ 
    dict entry(
     string "Discovering" 
     variant    boolean false 
    ) 
] 
array [ 
] 

내가 블루투스 검색을 수행 할 수 있습니다 scan onbluetoothctl를 사용하는 경우. 나는 bluetoothctl 도구와 bash 사이의 dbus 메시지를 비교하려고했습니다. 내가 bash는 DBUS를 사용할 때 나는

다른 DBUS 방법이 작동합니다 .... 항상 나를 호기심 RemoveMatch 다음 NameOwnerChanged 신호를 많이 수신 (ListNames, GetManagedObjects, Connect, RemoveDevice) 저도 같은 문제로이 게시물을 본 : How to use dbus-send to call org.bluez.Adapter1.StartDiscovery?

그러나 나는 "살아있는 어댑터에 D-Bus 프록시 개체를 유지하는 방법을 모른다."

리드가 있습니까? 내가 작업

: DBUS - 데몬 1.10.10, Bluez 시간에 5.41

감사

답변

0

난 당신이 일반적으로 DBUS-보내거나 쉘이 작업을 수행 할 수 없습니다 확신 해요 :에서 예를 들어, 도구 호출이 끊어지면 메소드 호출이 반환되는 즉시 검사가 종료됩니다. 그런 다음 Bluez는 클라이언트가 더 이상 존재하지 않으며 더 이상 아무도 관심이 없다고 가정하고 검색을 중지합니다.

나는 적절한 프로그래밍 언어를 사용하는 것이 좋습니다. Bluez와 같은 복잡한 DBus API로 간단한 작업을 수행하려는 경우 어쨌든해야합니다. 파이썬과 같은 스크립트 언어는 D-Bus 바인딩이 충분하면 잘 작동합니다. Bash는 거의 그것을 가지고 있지 않습니다. 쉘에서 복잡한 D-Bus 서명을 표현하려고하면 매우 고통스럽고 아마도 불가능할 것입니다.

0

dbus-send에서는이 작업을 수행 할 수 없습니다. Bluez는이 경우 발신자에게 연결 해제 감시자를 추가합니다. 응용 프로그램은 DBus 연결을 확보해야하며 검색 수행을 위해 실행 중이어야합니다.

Bluez 소스 디렉토리에서 test/test-discovery python 스크립트를 사용해보십시오. 그것은 당신이 원하는 것을 해줍니다. 검색 필터를 추가하지 않으려면 python 스크립트의 기본 줄 아래에 주석을 달아 실행하십시오.

 adapter.SetDiscoveryFilter(scan_filter) 
# after commenting, run it with: python test-discovery