<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>KatanaNativeInterface: include/KNI/cplSerial.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">KatanaNativeInterface <span id="projectnumber">$VERSION$</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('cplSerial_8h.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>cplSerial.h</h1> </div> </div> <div class="contents"> <a href="cplSerial_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Katana Native Interface - A C++ interface to the robot arm Katana.</span> <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2005 Neuronics AG</span> <a name="l00004"></a>00004 <span class="comment"> * Check out the AUTHORS file for detailed contact information.</span> <a name="l00005"></a>00005 <span class="comment"> *</span> <a name="l00006"></a>00006 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span> <a name="l00007"></a>00007 <span class="comment"> * it under the terms of the GNU General Public License as published by</span> <a name="l00008"></a>00008 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span> <a name="l00009"></a>00009 <span class="comment"> * (at your option) any later version.</span> <a name="l00010"></a>00010 <span class="comment"> *</span> <a name="l00011"></a>00011 <span class="comment"> * This program is distributed in the hope that it will be useful,</span> <a name="l00012"></a>00012 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00013"></a>00013 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00014"></a>00014 <span class="comment"> * GNU General Public License for more details.</span> <a name="l00015"></a>00015 <span class="comment"> *</span> <a name="l00016"></a>00016 <span class="comment"> * You should have received a copy of the GNU General Public License</span> <a name="l00017"></a>00017 <span class="comment"> * along with this program; if not, write to the Free Software</span> <a name="l00018"></a>00018 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> <a name="l00019"></a>00019 <span class="comment"> */</span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="comment">/******************************************************************************************************************/</span> <a name="l00023"></a>00023 <span class="preprocessor">#ifndef _CPLSERIAL_H_</span> <a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#define _CPLSERIAL_H_</span> <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="comment">/******************************************************************************************************************/</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "common/dllexport.h"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "common/exception.h"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "KNI/cplBase.h"</span> <a name="l00029"></a>00029 <span class="preprocessor">#include "KNI/cdlCOMExceptions.h"</span> <a name="l00030"></a>00030 <a name="l00031"></a><a class="code" href="cplSerial_8h.html#a6f5ea9aa44a03569f7aaf6c1011ecb96">00031</a> <span class="preprocessor">#define NUMBER_OF_RETRIES_SEND 3 // Number of retries after a failing in the Communication</span> <a name="l00032"></a><a class="code" href="cplSerial_8h.html#a33efec9577cfb39dbce2b0f825cf71db">00032</a> <span class="preprocessor"></span><span class="preprocessor">#define NUMBER_OF_RETRIES_RECV 3 // Number of retries after a failing in the Communication</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="comment">/******************************************************************************************************************/</span> <a name="l00034"></a>00034 <a name="l00036"></a><a class="code" href="cplSerial_8h.html#a6a0bb669bf468fb6d6a551d150fdd3b0">00036</a> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="cplSerial_8h.html#a6a0bb669bf468fb6d6a551d150fdd3b0" title="defines the error flag number">KATANA_ERROR_FLAG</a> = 192; <a name="l00041"></a>00041 <a name="l00044"></a><a class="code" href="classWrongCRCException.html">00044</a> <span class="keyword">class </span><a class="code" href="classWrongCRCException.html" title="CRC check for the answer package failed.">WrongCRCException</a> : <span class="keyword">public</span> <a class="code" href="classException.html">Exception</a> { <a name="l00045"></a>00045 <span class="keyword">public</span>: <a name="l00046"></a><a class="code" href="classWrongCRCException.html#a08b1afde1a962d96f9fac2417b05b72e">00046</a> <a class="code" href="classWrongCRCException.html#a08b1afde1a962d96f9fac2417b05b72e">WrongCRCException</a>() throw (): <a name="l00047"></a>00047 <a class="code" href="classException.html">Exception</a>("CRC check failed", -20) {} <a name="l00048"></a>00048 }; <a name="l00049"></a>00049 <a name="l00052"></a><a class="code" href="classFirmwareException.html">00052</a> <span class="keyword">class </span><a class="code" href="classFirmwareException.html" title="Exception reported by the firmware.">FirmwareException</a> : <span class="keyword">public</span> <a class="code" href="classException.html">Exception</a> { <a name="l00053"></a>00053 <span class="keyword">protected</span>: <a name="l00054"></a><a class="code" href="classFirmwareException.html#af2d223cdacbab687b54ba57eb566ab26">00054</a> <span class="keywordtype">int</span> <a class="code" href="classFirmwareException.html#af2d223cdacbab687b54ba57eb566ab26" title="axis number, if any">_axis_number</a>; <a name="l00055"></a><a class="code" href="classFirmwareException.html#a98cbf4ba78ddc5dd933dac51de303992">00055</a> <span class="keywordtype">char</span> <a class="code" href="classFirmwareException.html#a98cbf4ba78ddc5dd933dac51de303992" title="the command that caused the error">_command_char</a>; <a name="l00056"></a>00056 <span class="keyword">public</span>: <a name="l00057"></a><a class="code" href="classFirmwareException.html#af01204e9c2c55258daf752a927668fce">00057</a> <a class="code" href="classFirmwareException.html#af01204e9c2c55258daf752a927668fce">FirmwareException</a>(<span class="keyword">const</span> std::string & error, <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classException.html#a6913e80ebb7961989b64744cb7ba43d7">error_number</a>, <span class="keyword">const</span> <span class="keywordtype">int</span> axis, <span class="keyword">const</span> <span class="keywordtype">char</span> command) <span class="keywordflow">throw</span> (): <a name="l00058"></a>00058 <a class="code" href="classException.html#a1e7d40687c861dba563a3e0275b3cede">Exception</a>(<span class="stringliteral">"FirmwareException : '"</span> + error + <span class="stringliteral">"'"</span>, <a class="code" href="classException.html#a6913e80ebb7961989b64744cb7ba43d7">error_number</a>), <a name="l00059"></a>00059 <a class="code" href="classFirmwareException.html#af2d223cdacbab687b54ba57eb566ab26" title="axis number, if any">_axis_number</a>(axis), <a name="l00060"></a>00060 <a class="code" href="classFirmwareException.html#a98cbf4ba78ddc5dd933dac51de303992" title="the command that caused the error">_command_char</a>(command) {} <a name="l00061"></a><a class="code" href="classFirmwareException.html#a6119a872d516b4da3483c6e8c83b1026">00061</a> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classFirmwareException.html#a6119a872d516b4da3483c6e8c83b1026">axis_number</a>() <span class="keyword">const</span> throw() { <a name="l00062"></a>00062 <span class="keywordflow">return</span> <a class="code" href="classFirmwareException.html#af2d223cdacbab687b54ba57eb566ab26" title="axis number, if any">_axis_number</a>; <a name="l00063"></a>00063 } <a name="l00064"></a><a class="code" href="classFirmwareException.html#a43ff13414cfa427f51ee260ba39f7c29">00064</a> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="classFirmwareException.html#a43ff13414cfa427f51ee260ba39f7c29">command_char</a>() <span class="keyword">const</span> throw() { <a name="l00065"></a>00065 <span class="keywordflow">return</span> <a class="code" href="classFirmwareException.html#a98cbf4ba78ddc5dd933dac51de303992" title="the command that caused the error">_command_char</a>; <a name="l00066"></a>00066 } <a name="l00067"></a>00067 }; <a name="l00068"></a>00068 <a name="l00072"></a>00072 <a name="l00075"></a><a class="code" href="structTHeader.html">00075</a> <span class="keyword">struct </span><a class="code" href="structTHeader.html" title="Header of a communication packet.">THeader</a> { <a name="l00076"></a><a class="code" href="structTHeader.html#aeeb0e869444847c84c174057e3b507e9">00076</a> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> <a class="code" href="structTHeader.html#aeeb0e869444847c84c174057e3b507e9" title="header size">size</a>; <a name="l00077"></a><a class="code" href="structTHeader.html#a6f94c812f2b77101929850e776ad2470">00077</a> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> <a class="code" href="structTHeader.html#a6f94c812f2b77101929850e776ad2470" title="data part: 16x zero, 1x one, 1x katadr">data</a>[256]; <a name="l00078"></a>00078 }; <a name="l00079"></a>00079 <a name="l00082"></a><a class="code" href="structTPacket.html">00082</a> <span class="keyword">struct </span><a class="code" href="structTPacket.html" title="Communication packet.">TPacket</a> { <a name="l00083"></a><a class="code" href="structTPacket.html#acb17718e21c2885a1a2e3e257101a56b">00083</a> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> <a class="code" href="structTPacket.html#acb17718e21c2885a1a2e3e257101a56b" title="send size of the packet">send_sz</a>; <a name="l00084"></a><a class="code" href="structTPacket.html#a492134ca5e79bfb0ac13f0c5bec696ff">00084</a> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> <a class="code" href="structTPacket.html#a492134ca5e79bfb0ac13f0c5bec696ff" title="read size of the packet">read_sz</a>; <a name="l00085"></a>00085 }; <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="comment">//----------------------------------------------------------------------------------------------------------------//</span> <a name="l00088"></a>00088 <a name="l00089"></a>00089 <a name="l00092"></a><a class="code" href="classCCplSerial.html">00092</a> <span class="keyword">class </span><a class="code" href="dllexport_8h.html#af6e7daabccc187ef1005a8e9a68ecce4">DLLDIR</a> <a class="code" href="classCCplSerial.html" title="Base class of two different serial protocols.">CCplSerial</a> : <span class="keyword">public</span> <a class="code" href="classCCplBase.html" title="Abstract base class for protocol definiton.">CCplBase</a> { <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="keyword">protected</span>: <a name="l00095"></a><a class="code" href="classCCplSerial.html#a76137628017339bc2a063967b05c02c0">00095</a> <a class="code" href="structTHeader.html" title="Header of a communication packet.">THeader</a> <a class="code" href="classCCplSerial.html#a76137628017339bc2a063967b05c02c0" title="header">hdr</a>; <a name="l00096"></a><a class="code" href="classCCplSerial.html#aa5d45ae4a5e2a9cc63c3ffd5c10f91c2">00096</a> <a class="code" href="structTPacket.html" title="Communication packet.">TPacket</a> cmd[256]; <a name="l00097"></a>00097 <a name="l00098"></a><a class="code" href="classCCplSerial.html#a04aaf3680d306fc8e0630cda47e267d6">00098</a> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> send_buf[256]; <a name="l00099"></a><a class="code" href="classCCplSerial.html#adab2f13f0ab3faea9235adb81a7875f7">00099</a> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> read_buf[256]; <a name="l00100"></a>00100 <a name="l00101"></a>00101 <span class="keyword">protected</span>: <a name="l00102"></a>00102 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> load_tbl() = 0; <a name="l00103"></a>00103 <span class="keyword">virtual</span> <span class="keywordtype">void</span> defineProtocol(<a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> _kataddr) = 0; <a name="l00104"></a>00104 }; <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="comment">//----------------------------------------------------------------------------------------------------------------//</span> <a name="l00107"></a>00107 <a name="l00112"></a>00112 <span class="comment">// class DLLDIR CCplSerialZero : public CCplSerial {</span> <a name="l00113"></a>00113 <span class="comment">// </span> <a name="l00114"></a>00114 <span class="comment">// protected:</span> <a name="l00115"></a>00115 <span class="comment">// virtual bool load_tbl(); //!< Loads the command table from the robot's firmware.</span> <a name="l00116"></a>00116 <span class="comment">// virtual void defineProtocol(byte _kataddr); //!< Defines the protocol's attributes.</span> <a name="l00117"></a>00117 <span class="comment">// </span> <a name="l00118"></a>00118 <span class="comment">// public:</span> <a name="l00119"></a>00119 <span class="comment">// /*! \brief Initializing function</span> <a name="l00120"></a>00120 <span class="comment">// *</span> <a name="l00121"></a>00121 <span class="comment">// * Init the protocols basic attributes.</span> <a name="l00122"></a>00122 <span class="comment">// */</span> <a name="l00123"></a>00123 <span class="comment">// virtual bool init(CCdlBase* _device, byte _kataddr = 24);</span> <a name="l00124"></a>00124 <span class="comment">// </span> <a name="l00125"></a>00125 <span class="comment">// </span> <a name="l00126"></a>00126 <span class="comment">// /*! \brief Communication function</span> <a name="l00127"></a>00127 <span class="comment">// *</span> <a name="l00128"></a>00128 <span class="comment">// * Sends a communications packet and receives one from the robot.</span> <a name="l00129"></a>00129 <span class="comment">// */</span> <a name="l00130"></a>00130 <span class="comment">// virtual TRetCOMM comm(const byte* _pack, byte* _buf, byte* _size);</span> <a name="l00131"></a>00131 <span class="comment">// };</span> <a name="l00132"></a>00132 <a name="l00133"></a>00133 <span class="comment">//----------------------------------------------------------------------------------------------------------------//</span> <a name="l00134"></a>00134 <a name="l00137"></a><a class="code" href="classCCplSerialCRC.html">00137</a> <span class="keyword">class </span><a class="code" href="dllexport_8h.html#af6e7daabccc187ef1005a8e9a68ecce4">DLLDIR</a> <a class="code" href="classCCplSerialCRC.html" title="Implement the Serial-Zero protocol.">CCplSerialCRC</a> : <span class="keyword">public</span> <a class="code" href="classCCplSerial.html" title="Base class of two different serial protocols.">CCplSerial</a> { <a name="l00138"></a>00138 <a name="l00139"></a>00139 <span class="keyword">protected</span>: <a name="l00140"></a>00140 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classCCplSerial.html#a55bbd27e1bde075bb06eb60e75a89f0b" title="Loads the command table from the robot&#39;s firmware.">load_tbl</a>(); <a name="l00141"></a>00141 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCCplSerial.html#a9428975b706d75ae0fce04fea1dfa42c" title="Defines the protocol&#39;s attributes.">defineProtocol</a>(<a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> _kataddr); <a name="l00142"></a>00142 <span class="keyword">virtual</span> <span class="keywordtype">void</span> send(<a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a>* send_buf, <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> write_sz, <span class="keywordtype">short</span> retries = 3); <span class="comment">// Sends a packet.</span> <a name="l00143"></a>00143 <span class="keyword">virtual</span> <span class="keywordtype">void</span> recv(<a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a>* read_buf, <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> read_sz, <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a>* size); <span class="comment">// Receives the packet and checks the CRC.</span> <a name="l00144"></a>00144 <a name="l00145"></a>00145 <span class="keyword">public</span>: <a name="l00150"></a>00150 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classCCplBase.html#af552a1fecb58819245c930cb0de05211" title="Basic initializing function.">init</a>(<a class="code" href="classCCdlBase.html" title="Abstract base class for devices.">CCdlBase</a>* _device, <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a> _kataddr = 24); <a name="l00151"></a>00151 <a name="l00156"></a>00156 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCCplBase.html#a8f96d7f7bc108dee3e99b028b02b2af2" title="Base communication function.">comm</a>(<span class="keyword">const</span> <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a>* pack, <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a>* buf, <a class="code" href="cdlBase_8h.html#a0c8186d9b9b7880309c27230bbb5e69d" title="type specification (8 bit)">byte</a>* size); <a name="l00157"></a>00157 <a name="l00162"></a>00162 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCCplBase.html#a4920c0b9c8312ab80bb1fc39a4d54f25" title="Get the master firmware of the robot we are communicating with.">getMasterFirmware</a>(<span class="keywordtype">short</span>* fw, <span class="keywordtype">short</span>* rev); <a name="l00163"></a>00163 <a name="l00164"></a>00164 }; <a name="l00165"></a>00165 <a name="l00166"></a>00166 <span class="comment">/******************************************************************************************************************/</span> <a name="l00167"></a>00167 <span class="preprocessor">#endif //_CPLSERIALZERO_H_</span> <a name="l00168"></a>00168 <span class="preprocessor"></span><span class="comment">/******************************************************************************************************************/</span> </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="cplSerial_8h.html">cplSerial.h</a> </li> <li class="footer">Generated on Tue Feb 8 2011 for KatanaNativeInterface by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>