# 使用 QSH 客户端 API 开发应用程序

`SessionClient` 示例应用程序展示了如何使用 QSH 客户端 API 来开发应用程序。默认情况下，此示例应用程序构建于设备上的 `/usr/bin` 目录中。有关完整的代码示例，请参阅 `<workspace>/build-qcom-wayland/workspace/sources/sensinghub/sensing-hub/examples/SessionClient/SessionClient.cpp` 文件。

下图显示了进行加速度计传感器数据流的 call flow 以及 QSH 客户端 API 的使用情况。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by Microsoft Visio, SVG Export callflow-to-stream-a-given-sensor.svg Page-1 -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="5.01042in" height="5.33333in" viewbox="0 0 360.75 384" xml:space="preserve" color-interpolation-filters="sRGB" class="st20" aria-label="图：对指定传感器进行流传输的调用流程"><v:documentproperties v:langid="1033">	<v:userdefs>		<v:ud v:nameu="msvNoAutoConnect" v:val="VT0(1):26"></v:ud>	</v:userdefs></v:documentproperties>
<style>.svg-1 .st1 { fill: #f7f8fa; stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.75 }
.svg-1 .st2 { fill: #f7f8fa; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.999998 }
.svg-1 .st3 { fill: #000000; font-family: SimHei; font-size: 1.00001em }
.svg-1 .st4 { fill: #000000; font-family: Arial; font-size: 1.00001em }
.svg-1 .st5 { fill: none; stroke: none; stroke-width: 0.999999 }
.svg-1 .st6 { fill: none }
.svg-1 .st7 { stroke: #000000; stroke-dasharray: 6.99999, 4.99999; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.999998 }
.svg-1 .st8 { marker-end: url("#mrkr5-26"); stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.999998 }
.svg-1 .st9 { fill: #000000; fill-opacity: 1; stroke: #000000; stroke-opacity: 1; stroke-width: 0.28409057859308 }
.svg-1 .st10 { fill: #ffffff; stroke: none; stroke-linecap: butt; stroke-width: 7.2 }
.svg-1 .st11 { fill: #000000; font-family: Arial; font-size: 0.833336em }
.svg-1 .st12 { marker-start: url("#mrkr5-34"); stroke: #000000; stroke-dasharray: 6.99999, 4.99999; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.999998 }
.svg-1 .st13 { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.999998 }
.svg-1 .st14 { fill: #000000; font-family: SimHei; font-size: 0.833336em }
.svg-1 .st15 { font-family: Arial; font-size: 1em }
.svg-1 .st16 { marker-end: url("#mrkr5-26"); stroke: #000000; stroke-linecap: butt; stroke-width: 0.999998 }
.svg-1 .st17 { fill: none; stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.75 }
.svg-1 .st18 { fill: #000000; font-family: Arial; font-size: 0.666664em }
.svg-1 .st19 { font-family: SimHei; font-size: 1em }
.svg-1 .st20 { fill: none; fill-rule: evenodd; font-size: 12px; overflow: visible; stroke-linecap: square; stroke-miterlimit: 3 }</style>
<defs id="Markers">	<g id="lend5">		<path d="M 2 1 L 0 0 L 1.98117 -0.993387 C 1.67173 -0.364515 1.67301 0.372641 1.98465 1.00043 " style="stroke:none"></path>	</g>	<marker id="mrkr5-26" class="st9" v:arrowtype="5" v:arrowsize="2" v:setback="0" refx="-0" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend5" transform="scale(-3.5200040950051,-3.5200040950051) "></use>	</marker>	<marker id="mrkr5-34" class="st9" v:arrowtype="5" v:arrowsize="2" v:setback="0" refx="0" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend5" transform="scale(3.5200040950051) "></use>	</marker></defs><g v:mid="0" v:index="1" v:groupcontext="foregroundPage">	<title>Page-1</title>	<v:pageproperties v:drawingscale="1" v:pagescale="1" v:drawingunits="19" v:shadowoffsetx="8.99998" v:shadowoffsety="-8.99998"></v:pageproperties>	<g id="shape1-1" v:mid="1" v:groupcontext="shape" transform="translate(18.3754,-18.375)">		<title>shape1007-1</title>		<rect x="0" y="36.75" width="324" height="347.25" class="st1"></rect>	</g>	<g id="shape2-3" v:mid="2" v:groupcontext="shape" transform="translate(73.6254,-334.625)">		<title>shape2-3</title>		<desc>Application</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="42.7494" cy="370.5" width="85.5" height="27"></v:textrect>		<rect x="0" y="357" width="85.4998" height="27" class="st2"></rect>		<text x="18.75" y="374.1" class="st3" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>应用程序</text>		</g>	<g id="shape3-6" v:mid="3" v:groupcontext="shape" transform="translate(203,-334.625)">		<title>shape4-6</title>		<desc>libSensingHubSession</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="66.3744" cy="370.5" width="132.75" height="27"></v:textrect>		<rect x="0" y="357" width="132.75" height="27" class="st2"></rect>		<text x="6.34" y="374.1" class="st4" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>libSensingHubSession</text>		</g>	<g id="group4-9" transform="translate(499.25,49.375) rotate(90)" v:mid="4" v:groupcontext="group">		<title>shape5-9</title>		<g id="shape5-10" v:mid="5" v:groupcontext="shape">			<title>Sheet.5</title>			<path d="M0 384 L287 384 L0 384 Z" class="st5"></path>		</g>		<g id="shape6-12" v:mid="6" v:groupcontext="shape">			<title>Sheet.6</title>			<path d="M0 384 L287 384 L0 384 Z" class="st6"></path>			<path d="M0 384 L287 384" class="st7"></path>		</g>	</g>	<g id="group7-15" transform="translate(653.375,49.375) rotate(90)" v:mid="7" v:groupcontext="group">		<title>shape6-12</title>		<g id="shape8-16" v:mid="8" v:groupcontext="shape">			<title>Sheet.8</title>			<path d="M0 384 L305.85 384 L0 384 Z" class="st5"></path>		</g>		<g id="shape9-18" v:mid="9" v:groupcontext="shape">			<title>Sheet.9</title>			<path d="M0 384 L305.85 384 L0 384 Z" class="st6"></path>			<path d="M0 384 L305.85 384" class="st7"></path>		</g>	</g>	<g id="shape10-21" v:mid="10" v:groupcontext="shape" transform="translate(115.25,-316.625)">		<title>shape7-15</title>		<desc>getSession</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L147.96 384 L154.12 384" class="st8"></path>		<rect v:rectcontext="textBkgnd" x="52.3229" y="378" width="49.4783" height="12.0001" class="st10"></rect>		<text x="52.32" y="387" class="st11" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>getSession</text>		</g>	<g id="shape11-29" v:mid="11" v:groupcontext="shape" transform="translate(115.25,-298.625)">		<title>shape8-23</title>		<desc>ISession*</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L5.8 384 L6.16 384 L154.12 384" class="st12"></path>		<rect v:rectcontext="textBkgnd" x="55.9385" y="378" width="42.2468" height="12.0001" class="st10"></rect>		<text x="55.94" y="387" class="st11" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>ISession*</text>		</g>	<g id="shape12-37" v:mid="12" v:groupcontext="shape" transform="translate(24.1254,-229.875)">		<title>shape11-31</title>		<rect x="0" y="330" width="310.5" height="54" class="st13"></rect>	</g>	<g id="shape13-39" v:mid="13" v:groupcontext="shape" transform="translate(115.25,-261.375)">		<title>shape12-33</title>		<desc>get SUID using ISession*</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L147.96 384 L154.12 384" class="st8"></path>		<rect v:rectcontext="textBkgnd" x="19.8251" y="377.498" width="114.474" height="13.0037" class="st10"></rect>		<text x="19.83" y="387.25" class="st14" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>使用<tspan class="st15"> </tspan><tspan class="st15">ISession </tspan>获取<tspan class="st15"> </tspan><tspan class="st15">SUID*</tspan></text>		</g>	<g id="shape14-50" v:mid="14" v:groupcontext="shape" transform="translate(115.25,-243.375)">		<title>shape13-40</title>		<desc>SUID</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L5.8 384 L6.16 384 L154.12 384" class="st12"></path>		<rect v:rectcontext="textBkgnd" x="65.1162" y="378" width="23.8917" height="12.0001" class="st10"></rect>		<text x="65.12" y="387" class="st11" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>SUID</text>		</g>	<g id="shape15-57" v:mid="15" v:groupcontext="shape" transform="translate(115.25,-196.125)">		<title>shape14-47</title>		<desc>get Attributes using ISession*</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L147.96 384 L154.12 384" class="st8"></path>		<rect v:rectcontext="textBkgnd" x="10.6499" y="377.498" width="132.824" height="13.0037" class="st10"></rect>		<text x="10.65" y="387.25" class="st14" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>使用<tspan class="st15"> </tspan><tspan class="st15">ISession </tspan>获取<tspan class="st15"> </tspan><tspan class="st15">Attributes*</tspan></text>		</g>	<g id="shape16-68" v:mid="16" v:groupcontext="shape" transform="translate(115.25,-180.375)">		<title>shape15-54</title>		<desc>Attributes</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L5.8 384 L6.16 384 L154.12 384" class="st12"></path>		<rect v:rectcontext="textBkgnd" x="55.941" y="378" width="42.2419" height="12.0001" class="st10"></rect>		<text x="55.94" y="387" class="st11" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>Attributes</text>		</g>	<g id="shape17-75" v:mid="17" v:groupcontext="shape" transform="translate(115.25,-112.875)">		<title>shape17-61</title>		<desc>sensorEvents</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L5.8 384 L6.16 384 L154.12 384" class="st12"></path>		<rect v:rectcontext="textBkgnd" x="46.7685" y="378" width="60.5869" height="12.0001" class="st10"></rect>		<text x="46.77" y="387" class="st11" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>sensorEvents</text>		</g>	<g id="shape18-82" v:mid="18" v:groupcontext="shape" transform="translate(115.25,-70.125)">		<title>shape20-68</title>		<v:userdefs>			<v:ud v:nameu="TextPos" v:val="VT0(2):26"></v:ud>			<v:ud v:nameu="Scale" v:val="VT0(1):26"></v:ud>			<v:ud v:nameu="AntiScale" v:val="VT0(1):26"></v:ud>			<v:ud v:nameu="visVersion" v:val="VT0(15):26"></v:ud>			<v:ud v:nameu="msvDisableCustomConnectionPoints" v:prompt="" v:val="VT0(1):5"></v:ud>		</v:userdefs>		<path d="M0 370.5 L31.95 370.5 A6.75 6.75 0 0 1 38.7 377.25 A6.75 6.75 0 0 1 31.95 384 L6.16 384 L0 384" class="st16"></path>	</g>	<g id="shape19-87" v:mid="19" v:groupcontext="shape" transform="translate(72.3754,-24)">		<title>shape21-73</title>		<desc>Application</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="42.7494" cy="370.5" width="85.5" height="27"></v:textrect>		<rect x="0" y="357" width="85.4998" height="27" class="st2"></rect>		<text x="18.75" y="374.1" class="st3" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>应用程序</text>		</g>	<g id="shape20-90" v:mid="20" v:groupcontext="shape" transform="translate(203.217,-24)">		<title>shape22-76</title>		<desc>libSensingHubSession</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="66.3744" cy="370.5" width="132.75" height="27"></v:textrect>		<rect x="0" y="357" width="132.75" height="27" class="st2"></rect>		<text x="6.34" y="374.1" class="st4" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>libSensingHubSession</text>		</g>	<g id="shape21-93" v:mid="21" v:groupcontext="shape" transform="translate(29.7504,-78)">		<title>shape23-79</title>		<desc>delete ISession*</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="41.6244" cy="378.937" width="83.25" height="10.125"></v:textrect>		<rect x="0" y="373.875" width="83.2498" height="10.125" class="st17"></rect>		<text x="9.11" y="382.19" class="st14" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>删除<tspan class="st15"> </tspan><tspan class="st15">ISession*</tspan></text>		</g>	<g id="shape22-98" v:mid="22" v:groupcontext="shape" transform="translate(24.1254,484.125) scale(1,-1)">		<title>shape26-82</title>		<desc>opt</desc>		<v:userdefs>			<v:ud v:nameu="CTypeTopLeftSnip" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CTypeTopRightSnip" v:prompt="" v:val="VT0(1):5"></v:ud>			<v:ud v:nameu="CTypeBotLeftSnip" v:prompt="" v:val="VT0(1):5"></v:ud>			<v:ud v:nameu="CTypeBotRightSnip" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockHoriz" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockVert" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockDiag" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="TopLeftOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="TopRightOffset" v:prompt="" v:val="VT0(0):26"></v:ud>			<v:ud v:nameu="BotLeftOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="BotRightOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="visVersion" v:prompt="" v:val="VT0(15):26"></v:ud>		</v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="12.3746" cy="378.094" width="24.75" height="11.8125"></v:textrect>		<path d="M0 384 L24.75 384 L24.75 378.09 L18.84 372.19 L0 372.19 L0 384 Z" class="st2"></path>		<text x="6.81" y="-375.69" transform="scale(1,-1)" class="st18" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>opt</text>		</g>	<g id="shape23-101" v:mid="23" v:groupcontext="shape" transform="translate(48.7504,-272.062)">		<title>shape28-85</title>		<desc>[refer QSH Interface]</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="34.1244" cy="378.937" width="68.25" height="10.125"></v:textrect>		<rect x="0" y="373.875" width="68.2498" height="10.125" class="st17"></rect>		<text x="5.01" y="381.54" class="st18" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>[<tspan class="st19">参见</tspan> QSH <tspan class="st19">接口</tspan>]</text>		</g>	<g id="shape24-106" v:mid="24" v:groupcontext="shape" transform="translate(25.1254,-166.875)">		<title>shape1000-88</title>		<rect x="0" y="330" width="310.5" height="54" class="st13"></rect>	</g>	<g id="shape25-108" v:mid="25" v:groupcontext="shape" transform="translate(25.1254,547.125) scale(1,-1)">		<title>shape1001-90</title>		<desc>opt</desc>		<v:userdefs>			<v:ud v:nameu="CTypeTopLeftSnip" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CTypeTopRightSnip" v:prompt="" v:val="VT0(1):5"></v:ud>			<v:ud v:nameu="CTypeBotLeftSnip" v:prompt="" v:val="VT0(1):5"></v:ud>			<v:ud v:nameu="CTypeBotRightSnip" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockHoriz" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockVert" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockDiag" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="TopLeftOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="TopRightOffset" v:prompt="" v:val="VT0(0):26"></v:ud>			<v:ud v:nameu="BotLeftOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="BotRightOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="visVersion" v:prompt="" v:val="VT0(15):26"></v:ud>		</v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="12.3746" cy="378.094" width="24.75" height="11.8125"></v:textrect>		<path d="M0 384 L24.75 384 L24.75 378.09 L18.84 372.19 L0 372.19 L0 384 Z" class="st2"></path>		<text x="6.81" y="-375.69" transform="scale(1,-1)" class="st18" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>opt</text>		</g>	<g id="shape26-111" v:mid="26" v:groupcontext="shape" transform="translate(49.7504,-209.062)">		<title>shape1002-93</title>		<desc>[refer QSH Interface]</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="33.6244" cy="378.937" width="67.25" height="10.125"></v:textrect>		<rect x="0" y="373.875" width="67.2498" height="10.125" class="st17"></rect>		<text x="4.51" y="381.54" class="st18" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>[<tspan class="st19">参见</tspan> QSH <tspan class="st19">接口</tspan>]</text>		</g>	<g id="shape27-116" v:mid="27" v:groupcontext="shape" transform="translate(25.1254,-99.3748)">		<title>shape1003-96</title>		<rect x="0" y="330" width="310.5" height="54" class="st13"></rect>	</g>	<g id="shape28-118" v:mid="28" v:groupcontext="shape" transform="translate(25.1254,614.625) scale(1,-1)">		<title>shape1004-98</title>		<desc>opt</desc>		<v:userdefs>			<v:ud v:nameu="CTypeTopLeftSnip" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CTypeTopRightSnip" v:prompt="" v:val="VT0(1):5"></v:ud>			<v:ud v:nameu="CTypeBotLeftSnip" v:prompt="" v:val="VT0(1):5"></v:ud>			<v:ud v:nameu="CTypeBotRightSnip" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockHoriz" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockVert" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="CornerLockDiag" v:prompt="" v:val="VT0(0):5"></v:ud>			<v:ud v:nameu="TopLeftOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="TopRightOffset" v:prompt="" v:val="VT0(0):26"></v:ud>			<v:ud v:nameu="BotLeftOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="BotRightOffset" v:prompt="" v:val="VT0(0):1"></v:ud>			<v:ud v:nameu="visVersion" v:prompt="" v:val="VT0(15):26"></v:ud>		</v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="12.3746" cy="378.094" width="24.75" height="11.8125"></v:textrect>		<path d="M0 384 L24.75 384 L24.75 378.09 L18.84 372.19 L0 372.19 L0 384 Z" class="st2"></path>		<text x="6.81" y="-375.69" transform="scale(1,-1)" class="st18" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>opt</text>		</g>	<g id="shape29-121" v:mid="29" v:groupcontext="shape" transform="translate(49.7504,-141.563)">		<title>shape1005-101</title>		<desc>[refer QSH Interface]</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="33.6244" cy="378.937" width="67.25" height="10.125"></v:textrect>		<rect x="0" y="373.875" width="67.2498" height="10.125" class="st17"></rect>		<text x="4.51" y="381.54" class="st18" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>[<tspan class="st19">参见</tspan> QSH <tspan class="st19">接口</tspan>]</text>		</g>	<g id="shape30-126" v:mid="30" v:groupcontext="shape" transform="translate(115.25,-128.625)">		<title>shape1006-104</title>		<desc>Start Streaming using SUID</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)"></v:textblock>		<v:textrect cx="77.0619" cy="384" width="154.13" height="0"></v:textrect>		<path d="M0 384 L147.96 384 L154.12 384" class="st8"></path>		<rect v:rectcontext="textBkgnd" x="17.3375" y="377.498" width="119.449" height="13.0037" class="st10"></rect>		<text x="17.34" y="387.25" class="st14" v:langid="2052"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>使用<tspan class="st15"> </tspan><tspan class="st15">SUID </tspan>开始数据流传输</text>		</g></g>
</svg>

**图：对指定传感器进行流传输的调用流程**

在此示例中，客户端应用可以针对 SUID 查询、属性查询和流传输活动使用不同的传感器会话。它也可以对所有活动使用同一个会话，但必须妥善处理同步问题。

客户端应用程序可按如下方式向 aDSP 发送各种请求：

1. SUID 查询，获取指定传感器的 SUID：

    1. 通过使用新的 `sessionFactory()` 类调用 `getSession()` API 来创建 SUID 接口。对于任何用例而言，请求 SUID 是获取所请求数据类型的 SUID 的第一个请求，且非常重要。

/* Create a new ISession for UID discovery */
         sessionFactory* factory = new sessionFactory();
         if(nullptr == factory){
           printf("failed to create factory instance");
           return false;
         }
         ISession* suidSession = factory->getSession();
         if(nullptr == suidSession){
           printf("failed to create uid session");
           return false;
         }
        Copy to clipboard

    2. 通过调用 `open()` API 打开创建的会话接口。

/* Open the suidSession */
          int ret = suidSession->open();
          if(-1 == ret){
            printf("failed to open ISession for uid query");
            return false;
          }
        Copy to clipboard

    3. 通过调用 `setCallBacks()` API 并处理 SUID 活动的响应、事件或错误来设置回调。

/* Set callbacks for the session for 'uid' */
          ret = suidSession->setCallBacks(uid, suidResp, nullptr, suidEvent);
          if(-1 == ret)
             printf("all callbacks are null, no need to register it");
        Copy to clipboard

    4. 通过调用 `sendRequest()` API，为指定数据类型的 SUID 创建并发送 Pb 编码请求消息。

/*
           * Create SUID request message
           * (Please refer sns_client.proto and sns_suid.proto for more details)
           * */
          string pb_req_encoded = "";
          sns_suid_req pb_suid_req;
          pb_suid_req.set_data_type(sensorName);
          pb_suid_req.set_register_updates(true);
        sns_client_request_msg pb_req_msg;
        pb_req_msg.set_msg_id(SNS_SUID_MSGID_SNS_SUID_REQ);
        ..
        string pb_req_msg_encoded;
          pb_req_msg.SerializeToString(&pb_req_msg_encoded);
          /* send proto encoded message to sensing-hub using the opened session */
          unique_lock<mutex> respLock(respMutex);
          ret = suidSession->sendRequest(uid, pb_req_msg_encoded);
          if(0 != ret){
            printf("Error in sending uid discovery request");
            return false;
          }
        Copy to clipboard

    5. 通过调用 `close()` API 关闭会话，并在收到请求数据类型的 SUID 事件后将其删除。

/* Close and delete the session once SUIDs are received */
          suidSession->close();
          delete suidSession;
          delete factory;
        Copy to clipboard
2. 属性请求，获取指定传感器的属性：

    1. 通过使用新的 `sessionFactory()` 类调用 `getSession()` 为属性创建接口会话。对于任何用例而言，请求属性对于获取所请求数据类型的功能非常重要。

/* Create a new ISession for attribute query */
          sessionFactory* factory = new sessionFactory();
          if(nullptr == factory){
            printf("failed to create factory instance");
            return false;
          }
        
           ISession* attributeSession = factory->getSession();
          if(nullptr == attributeSession){
            printf("failed to create attribute session");
            return false;
          }
        Copy to clipboard

    2. 通过调用 `open()` API 打开创建的会话接口。

/* open the attributeSession session */
          int ret = attributeSession->open();
          if(-1 == ret){
            printf("failed to open ISession for attribute query");
            return false;
        Copy to clipboard

    3. 通过调用 `setCallBacks()` 并处理属性活动的响应、事件或错误来设置回调。

for (const suid& uid : suidList) {
            /* set callbacks for the session for 'uid' */
            int ret = attributeSession->setCallBacks(uid, attributeResp, nullptr, attributeEvent);
            if(-1 == ret)
                 printf("all callbacks are null, no need to register it");
        Copy to clipboard

    4. 通过调用 `sendRequest()` API，为指定数据类型的属性创建并发送 Pb 编码的配置请求。

/* create pb-encoded config request message to be sent for attribute query */
            sns_client_request_msg pb_req_msg;
            pb_req_msg.set_msg_id(SNS_STD_MSGID_SNS_STD_ATTR_REQ);
            pb_req_msg.mutable_request()->clear_payload();
            pb_req_msg.mutable_suid()->set_suid_high(uid.high);
        ..
        ..
        /* send proto encoded message to sensing-hub using the opened session */
            unique_lock<mutex> respLock(respMutex);
            ret = attributeSession->sendRequest(uid, pb_req_msg_encoded);
        Copy to clipboard

    5. 在收到请求数据类型的属性事件后，通过调用 `close()` API 来关闭会话。

/* close and delete the session once all attributes are received */
          attributeSession->close();
          delete attributeSession;
          delete factory;
        Copy to clipboard
3. 传感器流传输，进行传感器数据流传输并接收数据事件：

    1. 通过使用新的 `sessionFactory()` 类调用 `getSession()`，创建用于传感器流传输的接口会话。在这里，对于任何用例，请求传感器数据是请求数据类型的最后阶段。

sessionFactory()class.
        
        /* create a new ISession for streaming activity */
          sessionFactory* factory = new sessionFactory();
          if(nullptr == factory){
            printf("failed to create factory instance");
            return false;
          }
          ISession* streamingSession = factory->getSession();
          if(nullptr == streamingSession){
            printf("failed to create streaming session");
            return false;
          }
        Copy to clipboard

    2. 通过调用 `open()` API 打开创建的会话接口。

/* open the streamingSession session */
        int ret = streamingSession->open();
        if(-1 == ret){
          printf("failed to open ISession for attribute query");
          return false;
        Copy to clipboard

    3. 通过调用 `setCallBacks()` 并处理流传输活动的响应、事件或错误来设置回调。

for (const suid& uid : suidList){
            /* set callbacks for the session for 'uid' */
            int ret = streamingSession->setCallBacks(uid, dataResp, dataError, dataEvent);
            if(-1 == ret)
              printf("all callbacks are null, no need to register it");
        Copy to clipboard

    4. 通过调用 `sendRequest()` API 创建并发送 Pb 编码的配置请求，以便流传输指定数据类型的传感器，最终允许所请求的传感器。

/* create pb-encoded config request message to be sent for streaming request */
            string pb_req_encoded = "";
            sns_std_sensor_config pb_stream_cfg;
            pb_stream_cfg.set_sample_rate(sampleRate);
            pb_stream_cfg.SerializeToString(&pb_req_encoded);
            sns_client_request_msg pb_req_msg;
            pb_req_msg.mutable_request()->mutable_batching()->set_batch_period(batchPeriod);
            pb_req_msg.set_msg_id(SNS_STD_SENSOR_MSGID_SNS_STD_SENSOR_CONFIG);
        ..
        ..
        /* send proto encoded message to sensing-hub using the opened session */
            unique_lock<mutex> respLock(respMutex);
            ret = streamingSession->sendRequest(uid, pb_req_msg_encoded);
        Copy to clipboard

    5. 处理事件回调中的示例，并等待指定的测试持续时间。

void handle_event_cb(const uint8_t *data, size_t size, uint64_t time_stamp){
        if(true == deletion_started){
        printf("\nEvent coming when deletion of qmi connection started");
        return;
        }
        sns_client_event_msg pb_event_msg;
        /* Parse the pb encoded event */
        pb_event_msg.ParseFromArray(data, size);
        /* Iterate over all events in the message */
        for (int i = 0; i < pb_event_msg.events_size(); i++) {
        auto& pb_event = pb_event_msg.events(i);
        Copy to clipboard
4. 停止传感器流传输客户端，通过发送禁用请求来停止流传输：

    1. 调用 `sendRequest()` API。

pb_req_msg.set_msg_id(SNS_CLIENT_MSGID_SNS_CLIENT_DISABLE_REQ);
            pb_req_msg.mutable_suid()->set_suid_high(uid.high);
            pb_req_msg.mutable_suid()->set_suid_low(uid.low);
        ..
        ..
        /* send disable request to sensing-hub */
            int ret = streamingSession->sendRequest(uid, pb_req_msg_encoded);
        Copy to clipboard

    2. 在收到请求数据类型的数据流事件后，通过调用 `close()` API 来关闭会话。

/* close and delete the streamingSession */
          streamingSession->close();
          delete streamingSession;
          delete factory;
        Copy to clipboard

以下代码片段显示了 `SessionClient` 示例应用程序输出。它以 10 Hz 的采样率和 2 秒的批处理周期启用加速度计传感器 10 秒，并打印接收到的传感器事件。

[root@qcm6490](mailto:root&#37;&#52;&#48;qcm6490):~# SessionClient
Streaming configuration is as follows :

> 
> 
> Sensor name : accel     Sample rate : 10 Hz     Batch period : 2 sec    Test duration : 10 sec

SUID discovery response received.
Received SUIDs for accel, number of SUIDs received = 1

SUID received - suid\_low=6360260105974108950 suid\_high=7037810611998542250
Sensor suid list created

requesting attributes for - suid\_low=6360260105974108950 suid\_high=7037810611998542250

Attribute query response received.
Attributes for - suid\_low=6360260105974108950 suid\_high=7037810611998542250 are:
attribute count 0        and values are: attr\_id: 16     sint: 0
attribute count 1        and values are: attr\_id: 9      sint: 50sint: 240sint: 240
attribute count 2        and values are: attr\_id: 12     std: LPM std: NORMAL std: HIGH\_PERF
attribute count 3        and values are: attr\_id: 5      std: sns\_accel.proto
attribute count 4        and values are: attr\_id: 0      std: icm4x6xx
attribute count 5        and values are: attr\_id: 1      std: TDK-Invensense
attribute count 6        and values are: attr\_id: 26     boolean 1
attribute count 7        and values are: attr\_id: 17     boolean 0
attribute count 8        and values are: attr\_id: 10     sint: 6
attribute count 9        and values are: attr\_id: 15     sint: 16
attribute count 10       and values are: attr\_id: 21     boolean 1
attribute count 11       and values are: attr\_id: 22     sint: 3sint: 2sint: 1
attribute count 12       and values are: attr\_id: 2      std: accel
attribute count 13       and values are: attr\_id: 4      sint: 82179
attribute count 14       and values are: attr\_id: 13     boolean 1
attribute count 15       and values are: attr\_id: 14     boolean 0
attribute count 16       and values are: attr\_id: 18     sint: 0
attribute count 17       and values are: attr\_id: 20     flt: 0.000000  flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000flt: 0.000000    flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000
attribute count 18       and values are: attr\_id: 19     sint: 0
attribute count 19       and values are: attr\_id: 11
attribute count 20       and values are: attr\_id: 7      flt: 0.000019  flt: 0.000037   flt: 0.000075   flt: 0.000150   flt: 0.000299
attribute count 21       and values are: attr\_id: 24
attribute count 22       and values are: attr\_id: 23     flt: 0.000299
attribute count 23       and values are: attr\_id: 6      flt: 12.500000 flt: 25.000000  flt: 50.000000  flt: 100.000000 flt: 200.000000 flt: 500.000000
attribute count 24       and values are: attr\_id: 25     flt: 1000.000000       flt: 2000.000000
attribute count 25       and values are: attr\_id: 8      sint: 80
attribute count 26       and values are: attr\_id: 3      boolean 1

Attributes for all SUIDs received

Streaming started
sending request for - suid\_low=6360260105974108950 suid\_high=7037810611998542250
Data request response received.
Received re-configuration event
Cal event packet received
Received Samples:       [0.347159],     [-0.181959],    [9.450213],
Received Samples:       [0.102951],     [-0.183156],    [9.545981],
Received Samples:       [0.096965],     [-0.189142],    [9.550770],
Received Samples:       [0.092177],     [-0.192733],    [9.541193],
Received Samples:       [0.090980],     [-0.183156],    [9.555558],
Received Samples:       [0.093374],     [-0.185551],    [9.555558],
Received Samples:       [0.108936],     [-0.184354],    [9.541193],
Received Samples:       [0.098162],     [-0.185551],    [9.565135],
Received Samples:       [0.095768],     [-0.185551],    [9.550770],
Received Samples:       [0.100556],     [-0.193930],    [9.550770],
Received Samples:       [0.092177],     [-0.186748],    [9.550770],
Received Samples:       [0.094571],     [-0.199916],    [9.541193],
Received Samples:       [0.105345],     [-0.199916],    [9.550770],
Received Samples:       [0.098162],     [-0.185551],    [9.550770],

有关常见问题排查，请参阅[排除传感器故障](https://docs.qualcomm.com/doc/80-70022-7SC/topic/debug.html#debug)。

如需了解更多信息，请参阅 [QSH 直接通道 API 工作流](https://docs.qualcomm.com/bundle/resource/topics/80-70022-7A/develop_and_integrate.html#qsh_direct_channel_api_workflow)。

# 配置传感器

要配置注册表、Island 内存、多传感器（双）和串行总线配置，请参阅[配置传感器](https://docs.qualcomm.com/bundle/resource/topics/80-70022-7A/configuration_customization.html)。

# 开发并集成传感器驱动程序

要开发和集成自定义传感器驱动程序，请参阅[开发和集成传感器驱动程序](https://docs.qualcomm.com/bundle/resource/topics/80-70022-7A/develop_and_integrate.html#develop-and-integrate-sensor-drivers)。

# 开发并集成自定义传感器算法

要开发和集成符合 QSH 标准的传感器算法，请参阅[开发和集成自定义传感器算法](https://docs.qualcomm.com/bundle/resource/topics/80-70022-7A/develop_and_integrate.html#developing_custom_algorithm_and_integrating_with_qsh)。

后续步骤

- [校准传感器](https://docs.qualcomm.com/doc/80-70022-7SC/topic/calibrate.html#calibrate)

Last Published: Nov 03, 2025

[Previous Topic
开发传感器](https://docs.qualcomm.com/bundle/publicresource/80-70022-7SC/topics/develop_sensors.md) [Next Topic
校准传感器](https://docs.qualcomm.com/bundle/publicresource/80-70022-7SC/topics/calibrate.md)