MirrorLink(三 UPNP)-- 使用

1、使用libupnp,首先发现设备:

可以获取到一些信息:

ApplicationServer相关信息:

serviceType : urn:schemas-upnp-org:service:TmApplicationServer:1
serviceId : urn:upnp-org:serviceId:TmApplicationServer1

SCPDURL : http://192.168.42.129:4004/tmapplicationserver.xml
controlURL : http://192.168.42.129:4004/TmApplicationServer-control
eventSubURL : http://192.168.42.129:4004/TmApplicationServer-eventing

2、ClientProfile相关信息

serviceType : urn:schemas-upnp-org:service:TmClientProfile:1...
Subscribing to serviceId : urn:upnp-org:serviceId:TmClientProfile1

Subscribing to serviceId : urn:upnp-org:serviceId:TmClientProfile1...
Subscribing to SCPDURL : http://192.168.42.129:4004/tmclientprofile.xml...
Subscribing to controlURL : http://192.168.42.129:4004/TmClientProfile1-control...
Subscribing to eventSubURL : http://192.168.42.129:4004/TmClientProfile1-eventing

二、然后通过这些url去获取其他的详细信息:

1、GetMaxNumProfiles,获取最大支持的profile数量,一般为1,那么说明profileID为0

<u:GetMaxNumProfilesResponse xmlns:u="urn:schemas-upnp-org:service:TmClientProfile:1">
<NumProfilesAllowed>1</NumProfilesAllowed>^M
</u:GetMaxNumProfilesResponse>

2、使用profileID=0调用SetClientProfile

3、之后就可以调用GetApplicationList获取所有application列表

<?xml version="1.0"?>
<u:GetApplicationListResponse xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppListing><appList>
	<app>
		<appID>0x4</appID>
		<name>Bluetooth HFP</name>
		<description>Bluetooth HFP Audio</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>BTHFP</protocolID>
			<direction>bi</direction>
		</remotingInfo>
		<audioInfo>
			<audioType>phone</audioType>
			<contentCategory>0x1</contentCategory>
			<contentRules>0x0</contentRules>
			<trustLevel>0x80</trustLevel>
		</audioInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0x3</appID>
		<name>Bluetooth A2DP</name>
		<description>Bluetooth A2DP Audio Server</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>BTA2DP</protocolID>
			<direction>out</direction>
		</remotingInfo>
		<audioInfo>
			<audioType>application</audioType>
			<contentCategory>0x2</contentCategory>
			<contentRules>0x0</contentRules>
			<trustLevel>0x80</trustLevel>
		</audioInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0x5</appID>
		<name>RTP Server 99</name>
		<description>RTP Audio Server</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>RTP</protocolID>
			<format>99</format>
			<direction>out</direction>
			<audioIPL>4800</audioIPL>
			<audioMPL>9600</audioMPL>
		</remotingInfo>
		<appInfo>
			<appCategory>0xf0000001</appCategory>
			<trustLevel>0x80</trustLevel>
		</appInfo>
		<audioInfo>
			<audioType>application</audioType>
			<contentCategory>0x2</contentCategory>
			<contentRules>0x0</contentRules>
			<trustLevel>0x80</trustLevel>
		</audioInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0x6</appID>
		<name>RTP Server 98</name>
		<description>RTP Audio Server</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>RTP</protocolID>
			<format>98</format>
			<direction>out</direction>
			<audioIPL>4800</audioIPL>
			<audioMPL>9600</audioMPL>
		</remotingInfo>
		<appInfo>
			<appCategory>0xf0000001</appCategory>
			<trustLevel>0x80</trustLevel>
		</appInfo>
		<audioInfo>
			<audioType>application</audioType>
			<contentCategory>0x2</contentCategory>
			<contentRules>0x0</contentRules>
			<trustLevel>0x80</trustLevel>
		</audioInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0x7</appID>
		<name>RTP Client 99</name>
		<description>RTP Audio Client</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>RTP</protocolID>
			<format>99</format>
			<direction>in</direction>
			<audioIPL>4800</audioIPL>
			<audioMPL>9600</audioMPL>
		</remotingInfo>
		<appInfo>
			<appCategory>0xf0000002</appCategory>
			<trustLevel>0x80</trustLevel>
		</appInfo>
		<audioInfo>
			<audioType>phone</audioType>
			<contentCategory>0x10</contentCategory>
			<contentRules>0x0</contentRules>
			<trustLevel>0x80</trustLevel>
		</audioInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0x8</appID>
		<name>RTP Client 98</name>
		<description>RTP Audio Client</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>RTP</protocolID>
			<format>98</format>
			<direction>in</direction>
			<audioIPL>4800</audioIPL>
			<audioMPL>9600</audioMPL>
		</remotingInfo>
		<appInfo>
			<appCategory>0xf0000002</appCategory>
			<trustLevel>0x80</trustLevel>
		</appInfo>
		<audioInfo>
			<audioType>phone</audioType>
			<contentCategory>0x10</contentCategory>
			<contentRules>0x0</contentRules>
			<trustLevel>0x80</trustLevel>
		</audioInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0x9</appID>
		<name>Device Attestation</name>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>DAP</protocolID>
		</remotingInfo>
		<appInfo>
			<appCategory>0xf0000001</appCategory>
			<trustLevel>0x0</trustLevel>
		</appInfo>
		<resourceStatus>free</resourceStatus>
	</app>
	<app>
		<appID>0xa</appID>
		<name>Common Data Bus</name>
		<description>CDB Server Endpoint</description>
		<allowedProfileIDs>0</allowedProfileIDs>
		<remotingInfo>
			<protocolID>CDB</protocolID>
			<format>1.1</format>
		</remotingInfo>
		<appInfo>
			<appCategory>0xf0000000</appCategory>
			<trustLevel>0x80</trustLevel>
		</appInfo>
		<resourceStatus>free</resourceStatus>
	</app>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
<ds:Reference URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>pAijzscQ7RO3w/PwNyDLvYgLKps=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
ydcWz3u/32wDEVbG7D/hB8/P0TG0KL2Plt3y8zMIg95LRsKNcafX/nR40/JLH/bfCtg4lmrgoHCq
3OJvtrhZUhm6cRS/WnyX0WX8mZR9d0clt4q7SYKDVbO8kLX9yL4/HspvACAZtMYd6y6ODKP6s/DM
niJwsDgfpEoR1u8JBDEA6GtzElTgdZdIws3QlM/IzEQm0K4BVVlkUxF4QmBVIQiLymp+6rNWWtd8
U2K3mRtaEwUhHVG8on0xNCyx+7+WgrbQHp5eLBirVEw4gXxMXp5UEIH17CPbHw5le1tRsPz9es1K
ip8JDw0EChmxEmdLn/Om3s34vibLWpyBWBPH9g==
</ds:SignatureValue>
</ds:Signature></appList>
</AppListing>
</u:GetApplicationListResponse>

4、然后可以根据app相关信息调用函数GetCertifiedApplicationsList、GetApplicationCertificateInfo、GetApplicationStatus、LaunchApplication和TerminateApplication

<?xml version="1.0"?>
<u:GetCertifiedApplicationsList xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppCertFilter>*</AppCertFilter>
<ProfileID>0</ProfileID>
</u:GetCertifiedApplicationsList>

<?xml version="1.0"?>
<u:GetCertifiedApplicationsListResponse xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<CertifiedAppList>0x2,0xb</CertifiedAppList>
</u:GetCertifiedApplicationsListResponse>

<?xml version="1.0"?>
<u:LaunchApplication xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppID>0x2</AppID>
<ProfileID>0</ProfileID>
</u:LaunchApplication>

<?xml version="1.0"?>
<u:TerminateApplication xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppID>0x2</AppID>
<ProfileID>0</ProfileID>
</u:TerminateApplication>

<?xml version="1.0"?>
<u:GetApplicationCertificateInfo xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppID>0x6</AppID>
</u:GetApplicationCertificateInfo>

<?xml version="1.0"?>
<u:GetApplicationCertificateInfoResponse xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppCertification></AppCertification>
</u:GetApplicationCertificateInfoResponse>

<?xml version="1.0"?>
<u:GetApplicationStatus xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppID>0x6</AppID>
</u:GetApplicationStatus>

<?xml version="1.0"?>
<u:GetApplicationStatusResponse xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppStatus>&lt;appStatusList&gt;
	&lt;appStatus&gt;
		&lt;appID&gt;0x6&lt;/appID&gt;
		&lt;status&gt;
			&lt;profileID&gt;0&lt;/profileID&gt;
			&lt;statusType&gt;Notrunning&lt;/statusType&gt;
		&lt;/status&gt;
	&lt;/appStatus&gt;
&lt;/appStatusList&gt;
</AppStatus>
</u:GetApplicationStatusResponse>

解析以后:
<?xml version="1.0"?>
<u:GetApplicationStatusResponse xmlns:u="urn:schemas-upnp-org:service:TmApplicationServer:1">
<AppStatus><appStatusList>
	<appStatus>
		<appID>0x6</appID>
		<status>
			<profileID>0</profileID>
			<statusType>Notrunning</statusType>
		</status>
	</appStatus>
</appStatusList>
</AppStatus>
</u:GetApplicationStatusResponse>

三、libupnp的编译

libupnp 来源于http://pupnp.sourceforge.net/,其有多个版本可以下载;

如libupnp版本1.8.4下载后为libupnp-1.8.4.tar.bz2,需要将其放置到Ubuntu中进行解压,libupnp的文档也在此压缩档中;

解压方式是:

.tar.gz     格式解压为  tar   -zxvf   xx.tar.gz

.tar.bz2   格式解压为   tar   -jxvf    xx.tar.bz2

编译

系统要求

            libpthread程序包 --由于threadutil使用了pthread线程,所以这个包要提前安装

编译

        核心库的编译

            $ cd $(LIBUPNP) 进入libupnp根目录

            $ ./configure   #默认配置下,会将include文件安在/usr/local/include/upnp目录

                    #将lib文件安装在/usr/local/lib目录下

            $ make    #编译核心库    

            $ sudo make install

四、libupnp库的修改

由于usb断开时,upnp发送断开太慢,所以需要进行修改:

1、\libupnp-1.8.4\upnp\src\inc\upnpapi.h(socket读写超时设置成2s)

2、libupnp-1.8.4\upnp\src\inc\httpreadwrite.h(http超时设置成2s)

3、libupnp-1.8.4\upnp\src\genlib\net\http\httpreadwrite.c(connect非阻塞模式timeout由5s修改成2s)

4、libupnp-1.8.4\configure(connect修改成非阻塞模式)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值