2012年7月5日 星期四

Linux uPnP Programming (一)

在 Linux 上要如何開發 uPnP 程式呢?當然要先安裝 uPnP lib 。然後我以 lib 中所附上的 sample code 來解說,本篇我們先來解說  Control Point。下載完成之後解壓縮,再目錄中你會看到 upup/sample 目錄,我們現在來編譯看看
shanchieh@peter:Downloads$ cd libupnp-1.6.17/
shanchieh@peter:libupnp-1.6.17$ ./configure
shanchieh@peter:libupnp-1.6.17$ make
shanchieh@peter:libupnp-1.6.17$ cd upnp/sample/

這個時候你應該會看到三的執行檔案,如下:



現在我們來執行 tv_device 這個程式,你會看到如下的訊息:
shanchieh@peter:sample$ ./tv_device
Initializing UPnP Sdk with
ipaddress = {NULL} port = 0
UPnP Initialized
ipaddress = 192.168.11.101 port = 49152
Specifying the webserver root directory -- ./web
Registering the RootDevice
with desc_doc_url: http://192.168.11.101:49152/tvdevicedesc.xml
RootDevice Registered
Initializing State Table
common/sample_util.c(221): Error finding URLBase in XML Node
Found service: urn:schemas-upnp-org:service:tvcontrol:1
serviceId: urn:upnp-org:serviceId:tvcontrol1
common/sample_util.c(221): Error finding URLBase in XML Node
Found service: urn:schemas-upnp-org:service:tvpicture:1
serviceId: urn:upnp-org:serviceId:tvpicture1
State Table Initialized
Advertisements Sent

這表示 Server端已經執行,接下來就是要執行 Control Point ,請執行: ./tv_ctrlpt

CP 程式執行之後,就會開始搜尋 uPnP 裝置,如果之前的 Server 有順利執行,就會搜尋到這台裝置,如下:



輸入 Help 可以查詢到 Server 支援的指令,如下圖:



這些支援的指令,都是透過 uPnP 協定,根據 Server的XML所得知,之後我們就會透過 uPnP 的 Action 方式來控制 Server,這個我們會再後續的文章來說明,各位現在就可以透過這的 Sample 來看看uPnP是怎麼運作的。

沒有留言:

張貼留言