⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sensehandler_8c-source.html

📁 仿真人工智能是指用人工的方法和技术
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>SenseHandler.C Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.12 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center><hr><h1>SenseHandler.C</h1><a href="SenseHandler_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>00002 <font class="comment">Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam</font>00003 <font class="comment">All rights reserved.</font>00004 <font class="comment"></font>00005 <font class="comment">Redistribution and use in source and binary forms, with or without </font>00006 <font class="comment">modification, are permitted provided that the following conditions are met:</font>00007 <font class="comment"></font>00008 <font class="comment">1. Redistributions of source code must retain the above copyright notice, this </font>00009 <font class="comment">list of conditions and the following disclaimer. </font>00010 <font class="comment"></font>00011 <font class="comment">2. Redistributions in binary form must reproduce the above copyright notice, </font>00012 <font class="comment">this list of conditions and the following disclaimer in the documentation </font>00013 <font class="comment">and/or other materials provided with the distribution. </font>00014 <font class="comment"></font>00015 <font class="comment">3. Neither the name of the University of Amsterdam nor the names of its </font>00016 <font class="comment">contributors may be used to endorse or promote products derived from this </font>00017 <font class="comment">software without specific prior written permission. </font>00018 <font class="comment"></font>00019 <font class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" </font>00020 <font class="comment">AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </font>00021 <font class="comment">IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE </font>00022 <font class="comment">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE </font>00023 <font class="comment">FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </font>00024 <font class="comment">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR </font>00025 <font class="comment">SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER </font>00026 <font class="comment">CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, </font>00027 <font class="comment">OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </font>00028 <font class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</font>00029 <font class="comment">*/</font>00042 <font class="preprocessor">#include "<a class="code" href="SenseHandler_8h.html">SenseHandler.h</a>"</font>00043 <font class="preprocessor">#include "<a class="code" href="ActHandler_8h.html">ActHandler.h</a>"</font>  <font class="comment">// sigalarmHandler</font>00044 <font class="preprocessor">#include "<a class="code" href="Parse_8h.html">Parse.h</a>"</font>00045 00046 <font class="preprocessor">#include &lt;signal.h&gt;</font>   <font class="comment">// needed for SIGALARM</font>00047 <font class="preprocessor">#include &lt;string.h&gt;</font>   <font class="comment">// needed for strlen</font>00048 <font class="preprocessor">#include &lt;stdio.h&gt;</font>    <font class="comment">// needed for printf</font>00049 <font class="preprocessor">#include &lt;iostream.h&gt;</font> <font class="comment">// needed for cout</font>00050 00051 <font class="comment">/******************************************************************************/</font>00052 <font class="comment">/********************** CLASS SENSEHANDLER ************************************/</font>00053 <font class="comment">/******************************************************************************/</font>00054 <a name="l00060"></a><a class="code" href="SenseHandler_8C.html#a0">00060</a> <font class="keywordtype">void</font>* <a class="code" href="SenseHandler_8h.html#a0">sense_callback</a>( <font class="keywordtype">void</font> *v )00061 {00062   Log.log( 1, <font class="stringliteral">"Starting to listen for server messages"</font> );00063   <a class="code" href="classSenseHandler.html">SenseHandler</a>* s = (<a class="code" href="classSenseHandler.html">SenseHandler</a>*)v;00064   s-&gt;<a class="code" href="classSenseHandler.html#a1">handleMessagesFromServer</a>( );00065   <font class="keywordflow">return</font> NULL;00066 }00067 00068 <a name="l00075"></a><a class="code" href="classSenseHandler.html#a0">00075</a> <a class="code" href="classSenseHandler.html#a0">SenseHandler::SenseHandler</a>( <a class="code" href="classConnection.html">Connection</a> *c, <a class="code" href="classWorldModel.html">WorldModel</a> *wm, <a class="code" href="classServerSettings.html">ServerSettings</a> *ss,00076                             <a class="code" href="classPlayerSettings.html">PlayerSettings</a> *ps )00077 {00078   <a class="code" href="classSenseHandler.html#o3">connection</a>             = c;00079   <a class="code" href="classSenseHandler.html#o1">SS</a>                     = ss;00080   <a class="code" href="classSenseHandler.html#o2">PS</a>                     = ps;00081   <a class="code" href="classSenseHandler.html#o0">WM</a>                     = wm;00082   <a class="code" href="classSenseHandler.html#o6">iSimStep</a>               = <a class="code" href="classSenseHandler.html#o1">SS</a>-&gt;<a class="code" href="classServerSettings.html#a134">getSimulatorStep</a>()*1000;00083   <a class="code" href="classSenseHandler.html#o4">iTimeSignal</a>            = (int)(<a class="code" href="classSenseHandler.html#o6">iSimStep</a>*0.85);00084 00085   <font class="keyword">struct </font>sigaction sigact;00086 00087   sigact.sa_flags = SA_RESTART; <font class="comment">// primitives (recvfrom) should not be unblocked</font>00088   sigact.sa_handler = (void (*)(int))sigalarmHandler;00089   sigaction( SIGALRM, &amp;sigact, NULL );00090 00091   <font class="comment">// set timer signal to indicate when ActHandler should sent commands to the</font>00092   <font class="comment">// server, this structure will later be filled with exact timing values</font>00093   <a class="code" href="classSenseHandler.html#o7">itv</a>.it_interval.tv_sec  = 0;00094   <a class="code" href="classSenseHandler.html#o7">itv</a>.it_interval.tv_usec = 0;00095   <a class="code" href="classSenseHandler.html#o7">itv</a>.it_value.tv_sec     = 0;00096   <a class="code" href="classSenseHandler.html#o7">itv</a>.it_value.tv_usec    = 0;00097 }00098 <a name="l00101"></a><a class="code" href="classSenseHandler.html#a1">00101</a> <font class="keywordtype">void</font> <a class="code" href="classSenseHandler.html#a1">SenseHandler::handleMessagesFromServer</a>( )00102 {00103   <font class="keywordtype">char</font> strBuf[<a class="code" href="SoccerTypes_8h.html#a6">MAX_MSG</a>];00104   <font class="keywordtype">int</font> i=0;00105 00106   <font class="keywordflow">while</font>( 1 )00107   {00108     strBuf[0]=<font class="charliteral">'\0'</font>;00109     <font class="keywordflow">if</font>( i != -1 )                                         <font class="comment">// if no error</font>00110       i = <a class="code" href="classSenseHandler.html#o3">connection</a>-&gt;<a class="code" href="classConnection.html#a7">receiveMessage</a>( strBuf, <a class="code" href="SoccerTypes_8h.html#a6">MAX_MSG</a> );  <font class="comment">// get message</font>00111     <font class="keywordflow">if</font>( strBuf[0] != <font class="charliteral">'\0'</font> )                               <font class="comment">// if not empty</font>00112       <a class="code" href="classSenseHandler.html#a3">analyzeMessage</a>( strBuf );                           <font class="comment">// parse message</font>00113   }00114 }00115 00116 <a name="l00125"></a><a class="code" href="classSenseHandler.html#a2">00125</a> <font class="keywordtype">void</font> <a class="code" href="classSenseHandler.html#a2">SenseHandler::setTimeSignal</a>( )00126 {00127   <font class="keywordflow">if</font>( <a class="code" href="classSenseHandler.html#o0">WM</a>-&gt;<a class="code" href="classWorldModel.html#a46">getAgentViewFrequency</a>() == 1.0 ) <font class="comment">// VA_NORMAL AND VQ_HIGH (default)</font>00128   {00129     <font class="keywordflow">if</font>( <a class="code" href="classSenseHandler.html#o5">iTriCounter</a> % 3 == 0 )             <font class="comment">// see will arrive first half cycle</font>00130     {00131       <a class="code" href="classSenseHandler.html#o4">iTimeSignal</a> = (int)(<a class="code" href="classSenseHandler.html#o6">iSimStep</a> * <a class="code" href="classSenseHandler.html#o2">PS</a>-&gt;<a class="code" href="classPlayerSettings.html#a31">getFractionWaitSeeBegin</a>() );00132       <a class="code" href="classSenseHandler.html#o5">iTriCounter</a> = 0;00133     }00134     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( <a class="code" href="classSenseHandler.html#o5">iTriCounter</a> % 3 == 1 )        <font class="comment">// see will arrive 2nd half of cycle</font>00135     {00136       <a class="code" href="classSenseHandler.html#o4">iTimeSignal</a> = (int)(<a class="code" href="classSenseHandler.html#o6">iSimStep</a> * <a class="code" href="classSenseHandler.html#o2">PS</a>-&gt;<a class="code" href="classPlayerSettings.html#a33">getFractionWaitSeeEnd</a>() );00137     }00138     <font class="keywordflow">else</font>                                   <font class="comment">// no see will arrive</font>00139       <a class="code" href="classSenseHandler.html#o4">iTimeSignal</a> = (int)(<a class="code" href="classSenseHandler.html#o6">iSimStep</a> * <a class="code" href="classSenseHandler.html#o2">PS</a>-&gt;<a class="code" href="classPlayerSettings.html#a29">getFractionWaitNoSee</a>( ) );00140   }00141   <font class="keywordflow">else</font> <font class="keywordflow">if</font>( <a class="code" href="classSenseHandler.html#o0">WM</a>-&gt;<a class="code" href="classWorldModel.html#a46">getAgentViewFrequency</a>() == 2.0 ) <font class="comment">// VA_WIDE AND VQ_HIGH</font>00142   {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -