免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2548 | 回复: 0
打印 上一主题 下一主题

Test The Felix UPnP Project [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-20 16:59 |只看该作者 |倒序浏览

1.       What is UPnP?     (
http://en.wikipedia.org/wiki/Upnp
)
Universal Plug and Play (UPnP) is a set of networking
protocols
promulgated by the
UPnP Forum
. The goals of UPnP are to allow
devices
to connect seamlessly and to simplify the implementation of
networks
in the home (data sharing, communications, and entertainment) and in corporate environments for simplified installation of computer components. UPnP achieves this by defining and publishing UPnP device control protocols (DCP) built upon open,
Internet
-based communication
standards
.
The term UPnP is derived from
plug-and-play
, a technology for dynamically attaching devices directly to a computer, although UPnP is not directly related to the earlier plug-and-play technology. UPnP devices are "plug-and-play" in that when connected to a network they automatically announce their network address and supported device and services types, enabling clients that recognize those types to immediately begin using the device.
2.       Felix UPnP Project Introduction    (
http://felix.apache.org/site/apache-felix-upnp.html
)
The Felix UPnP project provides an implementation of the OSGI UPnP specification (version1.1) as described in
OSGI Service Compendium (Release 4)
. The specification is implemented by the org.apache.felix.upnp.basedriver bundle and it comes with other bundles, which have been developed to ease the writing and testing of UPnP code.
The OSGi UPnP specification defines a set of interfaces which should be used by the developers in order to write UPnP Devices and UPnP Control Points on the OSGi Service Platform. From the OSGi point of view, UPnP devices are services registered with the framework, thus the different phases of the UPnP protocol stack, as defined in the
UPnP™ Device Architecture 1.1
, have been mapped to the discovery and notification mechanisms offered by the OSGi framework.
The specification defines a UPnP Base Driver component that acts as software bridge between UPnP networks and OSGi. Developers writing UPnP code do not need to interact directly with the driver through some API. The driver works in background by exporting the registered services as UPnP devices, and by registering as services the UPnP devices discovered on UPnP networks. However, the Felix UPnP project has defined few additional interfaces, so a base knowledge of the way the UPnP Base Driver works is useful and will help developers to write their code.
3.       Building Felix    (
http://felix.apache.org/site/building-felix.html
)
4.       Getting Started    (
http://felix.apache.org/site/upnp-getting-started.html
)
4.1   Run UPnP Samples
After building the Felix project, you can start the script file upnp.sh.bat inside the /upnp/doc directory; it launches a Felix runtime with all the UPnP bundles released by the project. The script file config.properties.upnp defines a profile called upnp. When running upnp.sh.bat,It show load fail for bundle version error. So I changed config.properties.upnp to fix the bug. The file is as follows.
//config.properties.upnp
#
# Framework config properties.
#
org.osgi.framework.system.packages=org.osgi.framework; version=1.5.0, \
org.osgi.service.packageadmin; version=1.2.0, \
org.osgi.service.startlevel; version=1.1.0, \
org.osgi.service.url; version=1.0.0, \
org.osgi.util.tracker; version=1.3.3 \
${jre-${java.specification.version}}

#org.osgi.framework.bootdelegation=sun.*,com.sun.*

felix.cache.profile=upnp

felix.auto.start.1= \
file:bundle/org.apache.felix.shell-1.5.0-SNAPSHOT.jar \
file:bundle/org.apache.felix.shell.tui-1.5.0-SNAPSHOT.jar \
file:bundle/org.apache.felix.bundlerepository-1.5.0-SNAPSHOT.jar \
file:../org.osgi.core/target/org.osgi.core-1.5.0-SNAPSHOT.jar \
file:../javax.servlet/target/javax.servlet-1.0.1-SNAPSHOT.jar \
file:../org.osgi.compendium/target/org.osgi.compendium-1.5.0-SNAPSHOT.jar \
file:../http.jetty/target/org.apache.felix.http.jetty-1.1.0-SNAPSHOT.jar \
file:../upnp/basedriver/target/org.apache.felix.upnp.basedriver-0.9.0-SNAPSHOT.jar \
file:../upnp/extra/target/org.apache.felix.upnp.extra-0.5.0-SNAPSHOT.jar \
file:../upnp/tester/target/org.apache.felix.upnp.tester-0.5.0-SNAPSHOT.jar \
file:../upnp/samples/tv/target/org.apache.felix.upnp.sample.tv-0.2.0-SNAPSHOT.jar \
file:../upnp/samples/clock/target/org.apache.felix.upnp.sample.clock-0.2.0-SNAPSHOT.jar \
file:../upnp/samples/binarylight/target/org.apache.felix.upnp.sample.binaryLight-0.2.0-SNAPSHOT.jar

The UPnP Tester is a bundle that provides a browser utility to control and subscribe all the UPnP devices registered with the OSGi framework. After executing the script, you should see in the window opened by the UPnP Tester bundle three UPnP devices, which correspond to the TV, Clock and BinaryLight devices shown in Figure 3. Of course the number of discovered devices may be higher if other UPnP devices are installed in your local network.
4.2   Modify UPnP Samples
Changed the file upnp\samples\tv\src\main\java\org\apache\felix\upnp\sample\tv\TvDevice.java for BinayLight control point to control TV device.
public class TvDevice implements UPnPDevice,UPnPEventListener,ServiceListener  
{     
//private final static String LIGHT_DEVICE_TYPE = "urn:schemas-upnp-org:device:light:1";      
       private final static String LIGHT_DEVICE_TYPE = "urn:schemas-upnp-org:device:BinaryLight:1";
       private final static String POWER_SERVICE_TYPE = "urn:schemas-upnp-org:service:SwitchPower:1";
}

public void notifyUPnPEvent(String deviceId, String serviceId, Dictionary events)
{
              if( !LinkedDevices.contains(deviceId))
                     LinkedDevices.add(deviceId);
              if (deviceId.indexOf("Clock") != -1){
                            Date date = (Date) events.get("Time");
                            clockTime = date.toString();                       
              }
              else if (deviceId.indexOf("AirCon") != -1)
                            airconTemp = (String) events.get("Temp");
              else if (deviceId.indexOf("Washer") != -1)
                            message = (String) events.get("State");
              else if (deviceId.indexOf("BinaryLight") != -1)
              {
                     if(((Boolean)events.get("Status")).booleanValue())
                     {
                            //System.out.println("TV notifyUPnPEvent: BinaryLight on");
                            message = "BinaryLight on";
                            powerState.setPower(Boolean.TRUE);
                     }
                     else
                     {
                            //System.out.println("TV notifyUPnPEvent: BinaryLight off");
                            message = "BinaryLight off";
                            powerState.setPower(Boolean.FALSE);
                     }
              }
             comp.repaint();
}



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/100479/showart_2074222.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP