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

📄 framer_8cpp.html

📁 计算crc校验码的程序
💻 HTML
📖 第 1 页 / 共 2 页
字号:
00152                                                                      <span class="comment">//寄存器,若为0,则无需变化</span>00153                         }       00154                         temp &lt;&lt;= 1;00155 00156                         <span class="keywordflow">if</span> ( oput )                              <span class="comment">//若输出位为1,则将crc与gx对应位取异或,</span>00157                                                                      <span class="comment">//若为0,取异或结果不变,无需计算  </span>00158                         {00159                                 <a class="code" href="framer_8cpp.html#a2">crc</a> ^= gx; 00160                         }00161                         i=i+1;00162                 }00163                 00164                 tfile.read((<span class="keywordtype">char</span>*)&amp;otemp,<span class="keyword">sizeof</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>));00165         }00166         00167         ofile.put(crc);                               <span class="comment">//输出校验和数据</span>00168         ofile.close();00169         tfile.close();00170         <span class="keywordflow">return</span> <span class="keyword">true</span>;00171 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a0" doxytag="framer.cpp::frameheader"></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">bool frameheader           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">char *&nbsp;</td>          <td class="mdname" nowrap> <em>outfile</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td class="md"></td>          <td class="md" nowrap>char *&nbsp;</td>          <td class="mdname" nowrap> <em>tempfile</em></td>        </tr>        <tr>          <td class="md"></td>          <td class="md">)&nbsp;</td>          <td class="md" colspan="2"></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>形成帧的前导码、帧定界符、目的地址和源地址,输出到输出文件。. <p><dl compact><dt><b>参数:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>char*</em>&nbsp;</td><td>outfile 为输出文件名 </td></tr>    <tr><td valign="top"></td><td valign="top"><em>char*</em>&nbsp;</td><td>tempfile 临时文件名 </td></tr>  </table></dl><dl compact><dt><b>返回:</b></dt><dd>输出成功,则返回为真 </dd></dl><div class="fragment"><pre class="fragment">00018 {00019         00020           <span class="comment">//数组存放7字节前导码、1字节帧定界符、6字节目的地址和6字节源地址。</span>00021             00022            00023         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> head[8]={0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAB};<span class="comment">// 7字节前导码,每字节均为10101010,帧前导码10101011;</span>00024         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> add[12]={0x00,0x00,0xE4,0x86,0x3A,0xDC,         <span class="comment">//目标地址00-00-E4-86-3A-DC;</span>00025                                                    0x00,0x00,0x80,0x1A,0xE6,0x65};        <span class="comment">//源地址00-00-80-1A-E6-65</span>00026                                                         00027    ofstream tfile( tempfile );00028    ofstream ofile( outfile );00029    tfile.write( (<span class="keywordtype">char</span> *) &amp;head, <span class="keyword">sizeof</span> head );00030    tfile.write( (<span class="keywordtype">char</span> *) &amp;add, <span class="keyword">sizeof</span> add);00031    ofile.write( (<span class="keywordtype">char</span> *) &amp;head, <span class="keyword">sizeof</span> head );00032    tfile.close();00033   ofile.close();00034    <span class="keywordflow">return</span> <span class="keyword">true</span>;00035 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a1" doxytag="framer.cpp::length"></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">bool length           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">char *&nbsp;</td>          <td class="mdname" nowrap> <em>infile</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td class="md"></td>          <td class="md" nowrap>char *&nbsp;</td>          <td class="mdname" nowrap> <em>tempfile</em></td>        </tr>        <tr>          <td class="md"></td>          <td class="md">)&nbsp;</td>          <td class="md" colspan="2"></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>将输入文件的字节长度文件数据输出到临时文件,不足46字节的以0补齐。 <p><dl compact><dt><b>参数:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>char*</em>&nbsp;</td><td>infile 输入文件名 </td></tr>    <tr><td valign="top"></td><td valign="top"><em>char*</em>&nbsp;</td><td>tempfile 临时文件名 </td></tr>  </table></dl><dl compact><dt><b>返回:</b></dt><dd>输出成功,则返回为真 </dd></dl><div class="fragment"><pre class="fragment">00044 {00045 00046         ifstream ifile(infile,ios::binary);00047         ofstream tfile( tempfile,ios_base::binary|ios::app );00048 00049         <span class="keywordflow">if</span>(!ifile)                                        <span class="comment">//输入文件无法打开,返回失败。</span>00050         {00051                 cout&lt;&lt;<span class="stringliteral">"cannot open"</span>&lt;&lt;infile&lt;&lt;endl;00052                 <span class="keywordflow">return</span> <span class="keyword">false</span>;00053         }00054         00055                                 00056         00057         <span class="keywordtype">char</span> tempchar;00058         <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> c1,c2,bytecnt ;00059 00060         00061         ifile.seekg( 0, ios_base::end );                  <span class="comment">//找到二进制文件尾</span>00062         c1=c2=bytecnt= ifile.tellg();                     <span class="comment">//数据字段长度计数器。</span>00063         00064         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b1=c1&amp;0x00ff;                       <span class="comment">//将数据长度字段输出到临时文件</span>00065         c2&gt;&gt;=8;00066     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b2=c2;00067         tfile.put(b2);00068     tfile.put(b1);00069         00070         ifile.seekg(0);                                   <span class="comment">//开始读取数据,并输出到临时文件</span>00071         <span class="keywordtype">int</span> cnt=bytecnt;00072         ifile.get(tempchar);00073         00074         <span class="keywordflow">while</span>(cnt&gt;0)00075         {00076                                  00077                 cnt--;00078                 tfile.put(tempchar);00079                 ifile.get(tempchar);00080         }00081         00082         00083         <span class="keywordflow">if</span>(bytecnt&gt;46)                                    <span class="comment">//数据字段大于46字节,成功返回</span>00084         {00085                 tfile.close();00086                 ifile.close();00087                 <span class="keywordflow">return</span> <span class="keyword">true</span>;00088         }00089         00090         tempchar=0;00091         <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=bytecnt;i&lt;46;i++)                      <span class="comment">//数据字段不足46字节,先用0补足46字节再返回;</span>00092                 tfile.put(tempchar);00093         00094 00095         tfile.close();00096         ifile.close();00097         <span class="keywordflow">return</span> <span class="keyword">true</span>;00098 }</pre></div><p>    </td>  </tr></table><hr size="1"><address style="align: right;"><small>Generated at Mon Oct 25 14:33:33 2004 for famer by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address></body></html>

⌨️ 快捷键说明

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