2017-01-07 1 views
1

나는 나무 딸기 파이를 사용하여 내 차에 블루투스 오디오를 설정하려고합니다. 나는 휴대 전화에서 스트리밍하는 음악과 DBus 메시지를 사용하여 트랙을 앞뒤로 움직이는 2 개의 GPIO 버튼을 설정했습니다. 현재 재생중인 노래가 표시된 화면을 만들고 싶지만 걸쇠를 치고 있습니다.dbus를 "오버로드"할 수 있습니까? 속성 가져 오기 명령?

DBUS 보내 --system --type = method_call --print 회신 --dest = org.bluez/조직/bluez/hci0/dev_DC_41_5F_17_4C_79/:

내가이 명령을 실행할 수 있습니다 DBUS 사용 player0 org.freedesktop.DBus.Properties.Get 문자열 : org.bluez.MediaPlayer1 문자열 : 트랙

내가하고 싶은 어떤이 "변형"

variant  array [ 
    dict entry(
     string "Item" 
     variant    object path "/org/bluez/hci0/dev_DC_41_5F_17_4C_79/player0/NowPlaying/item751498629074736430" 
    ) 
    dict entry(
     string "Album" 
     variant    string "Horse Of A Different Color" 
    ) 
    dict entry(
     string "TrackNumber" 
     variant    uint32 1 
    ) 
    dict entry(
     string "Genre" 
     variant    string "Country" 
    ) 
    dict entry(
     string "Duration" 
     variant    uint32 173061 
    ) 
    dict entry(
     string "NumberOfTracks" 
     variant    uint32 50 
    ) 
    dict entry(
     string "Title" 
     variant    string "Drinkin' 'Bout You" 
    ) 
    dict entry(
     string "Artist" 
     variant    string "Big & Rich" 
    ) 
    ] 

을 반환 단지가있다 노래 제목이 반환됩니다. 나는 'Track'대신 'Title'이라는 단어를 입력 해 보았습니다. 또한 'string : Title'명령 끝에 다른 연산자를 추가하여 정보를 좁힐 수 있기를 바랍니다. 하지만 나는 운이 없다.

제목 만 표시하는 방법에 대해 알려줄 수 있습니까? 감사합니다.

답변

0

프로그램 외부에서 변형을 읽는 방법이 확실하지 않습니다. 그렇지 않다면, 당신이하고 싶은 일을 성취 할 수있는 작은 프로그램을 만들어야합니다.

변형은 컨테이너입니다. 찾는 정보는이 변형 안에 있습니다. 귀하의 변형은 유형이 {sv}인데, 이는 키가 문자열이고 값이 변형 (v) 인 사전 {key, value}을 의미합니다.

다음 C 코드 (입심 GDBus API를 사용하여) 변형을 구문 분석 : 여기

https://developer.gnome.org/glib/stable/glib-GVariant.html

과 : 당신은 여기 변형에 대한 자세한 정보를 얻을 수 있습니다

/* Call the method that will return your variant dictionary */ 
GVariant *returnValue = MethodCallThatWillReturnTheDictionary(); 

/* This will be used to iterate through the dict */ 
GVariantIter *iter_dict; 

/* These two will be used to store the key and value pair in the dict */ 
const gchar *key; 
GVariant value; 

/* Init the iterator */ 
g_variant_get(returnValue, "a{sv}", &iter_dict); 

/* Iterate through the dict */ 
while(g_variant_iter_loop(iter_dict, "{&sv}", &key, &value)){ 

    /* Each time we iterate, check if the key is "Title" */ 
    if(! strcmp(key, "Title")){ 

     /* You now know that the Title is inside the "value" variant 
      We still have to extract it */ 

     int title_length /* This will receive the Title length */ 
     const gchar *yourTitle = g_variant_get_string(value, &title_length); 

    } 
} 
g_variant_iter_free(iter_dict); /* We don't need it anymore */ 

https://developer.gnome.org/glib/stable/gvariant-format-strings.html

DBus 및 GDBus (DBus 용 GLib 바인딩)에 대해 잘 모르는 경우 아래 링크에서 자세한 내용을 읽고 저수준 및 고급 D 버스 지원을 찾으십시오. 귀하의 경우에는 GDBusConnection 및 GDBusProxy가 필요합니다 :

버스에 대한 연결을 작성한 다음 dbus-send에서 사용한 이름, 경로 및 인터페이스 이름을 사용하여 프록시를 작성하십시오. 그런 다음 내가 준 코드 예제를 사용하여 제목을 추출하십시오.

https://developer.gnome.org/gio/stable/