cml__pdo_8h-source.html
来自「美国COPLEY驱动器,程序开发工具之一.」· HTML 代码 · 共 571 行 · 第 1/5 页
HTML
571 行
<a name="l00107"></a><a class="code" href="classPmap.html#a5">00107</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmap.html#a5">Set</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){};<a name="l00108"></a>00108 <span class="comment"></span><a name="l00109"></a>00109 <span class="comment"> /// Return the 32-bit code used to identify this variable in the</span><a name="l00110"></a>00110 <span class="comment"> /// CANopen node's PDO mapping block</span><a name="l00111"></a><a class="code" href="classPmap.html#a6">00111</a> <span class="comment"></span> <span class="keyword">virtual</span> <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <a class="code" href="classPmap.html#a6">GetMapCode</a>()<a name="l00112"></a>00112 {<a name="l00113"></a>00113 <span class="keywordflow">return</span> (<a class="code" href="CML__Utils_8h.html#a10">uint32</a>)<a class="code" href="classPmap.html#p0">index</a><<16 | (<a class="code" href="CML__Utils_8h.html#a10">uint32</a>)<a class="code" href="classPmap.html#p1">sub</a><<8 | <a class="code" href="classPmap.html#p2">bits</a>;<a name="l00114"></a>00114 }<a name="l00115"></a>00115 <span class="comment"></span><a name="l00116"></a>00116 <span class="comment"> /// Get the object index associated with this variable</span><a name="l00117"></a>00117 <span class="comment"> /// @return The 16-bit object index.</span><a name="l00118"></a><a class="code" href="classPmap.html#a7">00118</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#a7">GetIndex</a>(){<a name="l00119"></a>00119 <span class="keywordflow">return</span> <a class="code" href="classPmap.html#p0">index</a>;<a name="l00120"></a>00120 }<a name="l00121"></a>00121 <span class="comment"></span><a name="l00122"></a>00122 <span class="comment"> /// Get the object sub-index associated with this variable</span><a name="l00123"></a>00123 <span class="comment"> /// @return The 8-bit object sub-index.</span><a name="l00124"></a><a class="code" href="classPmap.html#a8">00124</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#a8">GetSub</a>(){<a name="l00125"></a>00125 <span class="keywordflow">return</span> <a class="code" href="classPmap.html#p1">sub</a>;<a name="l00126"></a>00126 }<a name="l00127"></a>00127 <span class="comment"></span><a name="l00128"></a>00128 <span class="comment"> /// Get the number of bits in this variable</span><a name="l00129"></a>00129 <span class="comment"> /// @return The number of bits.</span><a name="l00130"></a><a class="code" href="classPmap.html#a9">00130</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#a9">GetBits</a>(){<a name="l00131"></a>00131 <span class="keywordflow">return</span> <a class="code" href="classPmap.html#p2">bits</a>;<a name="l00132"></a>00132 }<a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="keyword">protected</span>:<span class="comment"></span><a name="l00135"></a>00135 <span class="comment"> /// The 16-bit index of the object in the object dictionary</span><a name="l00136"></a><a class="code" href="classPmap.html#p0">00136</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#p0">index</a>;<a name="l00137"></a>00137 <span class="comment"></span><a name="l00138"></a>00138 <span class="comment"> /// The 8-bit sub-index of the object in the object dictionary</span><a name="l00139"></a><a class="code" href="classPmap.html#p1">00139</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p1">sub</a>;<a name="l00140"></a>00140 <span class="comment"></span><a name="l00141"></a>00141 <span class="comment"> /// The number of bits that this object takes up.</span><a name="l00142"></a><a class="code" href="classPmap.html#p2">00142</a> <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p2">bits</a>;<a name="l00143"></a>00143 };<a name="l00144"></a>00144 <a name="l00145"></a>00145 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00146"></a>00146 <span class="comment">/**</span><a name="l00147"></a>00147 <span class="comment">This is the most generic PDO variable mapping class. It doesn't do any</span><a name="l00148"></a>00148 <span class="comment">special formatting, just holds up to 8 bytes of raw data.</span><a name="l00149"></a>00149 <span class="comment">*/</span><a name="l00150"></a>00150 <span class="comment">/***************************************************************************/</span><a name="l00151"></a><a class="code" href="classPmapRaw.html">00151</a> <span class="keyword">class </span><a class="code" href="classPmapRaw.html">PmapRaw</a>: <span class="keyword">public</span> <a class="code" href="classPmap.html">Pmap</a><a name="l00152"></a>00152 {<a name="l00153"></a>00153 <span class="keyword">public</span>:<span class="comment"></span><a name="l00154"></a>00154 <span class="comment"> /// Default constructor </span><a name="l00155"></a><a class="code" href="classPmapRaw.html#a0">00155</a> <span class="comment"></span> <a class="code" href="classPmapRaw.html#a0">PmapRaw</a>()<a name="l00156"></a>00156 {<a name="l00157"></a>00157 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i=0; i<8; i++ ) data[i] = 0;<a name="l00158"></a>00158 }<a name="l00159"></a>00159 <span class="comment"></span><a name="l00160"></a>00160 <span class="comment"> /// Create a new mapping object</span><a name="l00161"></a>00161 <span class="comment"> /// @param index Object index associated with this variable</span><a name="l00162"></a>00162 <span class="comment"> /// @param sub Object sub-index</span><a name="l00163"></a>00163 <span class="comment"> /// @param bits The size of the variable in bits</span><a name="l00164"></a><a class="code" href="classPmapRaw.html#a1">00164</a> <span class="comment"></span> <a class="code" href="classPmapRaw.html#a0">PmapRaw</a>( <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#p0">index</a>, <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p1">sub</a>, <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p2">bits</a> ):<a class="code" href="classPmap.html">Pmap</a>(index, sub, bits)<a name="l00165"></a>00165 {<a name="l00166"></a>00166 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i=0; i<8; i++ ) data[i] = 0;<a name="l00167"></a>00167 }<a name="l00168"></a>00168 <span class="comment"></span><a name="l00169"></a>00169 <span class="comment"> /// Copy the current value of this variable into the passed</span><a name="l00170"></a>00170 <span class="comment"> /// character array. This function is called when a receive</span><a name="l00171"></a>00171 <span class="comment"> /// PDO is about to be transmitted to a node.</span><a name="l00172"></a>00172 <span class="comment"> /// @param cptr A character pointer that references a char</span><a name="l00173"></a>00173 <span class="comment"> /// array large enough to hold this objects data.</span><a name="l00174"></a><a class="code" href="classPmapRaw.html#a2">00174</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmapRaw.html#a2">Get</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){<a name="l00175"></a>00175 <span class="keywordtype">int</span> bytes = <a class="code" href="classPmap.html#p2">bits</a>>>3;<a name="l00176"></a>00176 m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00177"></a>00177 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i=0; i<bytes; i++ ) *cptr++ = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(data[i]);<a name="l00178"></a>00178 m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00179"></a>00179 }<a name="l00180"></a>00180 <span class="comment"></span><a name="l00181"></a>00181 <span class="comment"> /// Update the value of this variable based on the data passed</span><a name="l00182"></a>00182 <span class="comment"> /// in a character array. This function is called when a transmit</span><a name="l00183"></a>00183 <span class="comment"> /// PDO that this variable is mapped to is received.</span><a name="l00184"></a>00184 <span class="comment"> /// @param cptr A pointer to the received data.</span><a name="l00185"></a><a class="code" href="classPmapRaw.html#a3">00185</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPmapRaw.html#a3">Set</a>( <a class="code" href="CML__Utils_8h.html#a2">byte</a> *cptr ){<a name="l00186"></a>00186 <span class="keywordtype">int</span> bytes = <a class="code" href="classPmap.html#p2">bits</a>>>3;<a name="l00187"></a>00187 m.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00188"></a>00188 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i=0; i<bytes; i++ ) data[i] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(cptr[i]);<a name="l00189"></a>00189 m.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00190"></a>00190 }<a name="l00191"></a>00191 <a name="l00192"></a>00192 <span class="keyword">private</span>:<span class="comment"></span><a name="l00193"></a>00193 <span class="comment"> /// A mutex used to protect access to this variable</span><a name="l00194"></a>00194 <span class="comment"></span> <a class="code" href="classMutex.html">Mutex</a> m;<a name="l00195"></a>00195 <span class="comment"></span><a name="l00196"></a>00196 <span class="comment"> /// The data associated with this mapping.</span><a name="l00197"></a>00197 <span class="comment"></span> <a class="code" href="CML__Utils_8h.html#a2">byte</a> data[8];<a name="l00198"></a>00198 };<a name="l00199"></a>00199 <a name="l00200"></a>00200 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00201"></a>00201 <span class="comment">/**</span><a name="l00202"></a>00202 <span class="comment">This is a PDO variable mapping class that extends the virtual Pmap class to</span><a name="l00203"></a>00203 <span class="comment">handle 32-bit integers.</span><a name="l00204"></a>00204 <span class="comment">*/</span><a name="l00205"></a>00205 <span class="comment">/***************************************************************************/</span><a name="l00206"></a><a class="code" href="classPmap32.html">00206</a> <span class="keyword">class </span><a class="code" href="classPmap32.html">Pmap32</a>: <span class="keyword">public</span> <a class="code" href="classPmap.html">Pmap</a><a name="l00207"></a>00207 {<a name="l00208"></a>00208 <span class="keyword">public</span>:<span class="comment"></span><a name="l00209"></a>00209 <span class="comment"> /// Default constructor for a 32-bit mapping object</span><a name="l00210"></a><a class="code" href="classPmap32.html#a0">00210</a> <span class="comment"></span> <a class="code" href="classPmap32.html#a0">Pmap32</a>(): data(0) {}<a name="l00211"></a>00211 <span class="comment"></span><a name="l00212"></a>00212 <span class="comment"> /// Create a new 32-bit mapping object</span><a name="l00213"></a>00213 <span class="comment"> /// @param index Object index associated with this variable</span><a name="l00214"></a>00214 <span class="comment"> /// @param sub Object sub-index (defaults to 0)</span><a name="l00215"></a><a class="code" href="classPmap32.html#a1">00215</a> <span class="comment"></span> <a class="code" href="classPmap32.html#a0">Pmap32</a>( <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#p0">index</a>, <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p1">sub</a>=0 ):<a class="code" href="classPmap.html">Pmap</a>(index,<a class="code" href="classPmap.html#p1">sub</a>,32), data(0){}<a name="l00216"></a>00216 <span class="comment"></span><a name="l00217"></a>00217 <span class="comment"> /// Initialize a 32-bit mapping object</span><a name="l00218"></a>00218 <span class="comment"> /// @param index Object index associated with this variable</span><a name="l00219"></a>00219 <span class="comment"> /// @param sub Object sub-index (defaults to 0)</span><a name="l00220"></a>00220 <span class="comment"> /// @return An error object</span><a name="l00221"></a><a class="code" href="classPmap32.html#a2">00221</a> <span class="comment"></span> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classPmap32.html#a2">Init</a>( <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <a class="code" href="classPmap.html#p0">index</a>, <a class="code" href="CML__Utils_8h.html#a2">byte</a> <a class="code" href="classPmap.html#p1">sub</a>=0 ){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?