Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 1728

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: dtnmoteproxy.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</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>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>dtnmoteproxy.c</h1><a href="dtnmoteproxy_8c.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"> *    Copyright 1996-2006 Intel Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> * </span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="comment">/*</span>
<a name="l00019"></a>00019 <span class="comment"> * moteproxy: a DTN &lt;-&gt; mote proxying app, intended for use with GSK</span>
<a name="l00020"></a>00020 <span class="comment"> *   for MICA-2, use 57600 baud rate</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="comment">/* Modified to recognize Mote-PC protocol -- Mark Thomas (23/06/04) </span>
<a name="l00024"></a>00024 <span class="comment"> * Now uses serialsource.c to communicate with serial port </span>
<a name="l00025"></a>00025 <span class="comment"> * Files: crc16.c, misc.c, mote_io.c and mote_io.h are not used anymore */</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;signal.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;getopt.h&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include "<a class="code" href="serialsource_8h.html">serialsource.h</a>"</span>
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;strings.h&gt;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="preprocessor">#include &lt;oasys/compat/inttypes.h&gt;</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="preprocessor">#include "<a class="code" href="dtn__api_8h.html">dtn_api.h</a>"</span>
<a name="l00050"></a>00050  
<a name="l00051"></a><a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">00051</a> <span class="preprocessor">#define dout    stderr</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;ctype.h&gt;</span>
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="dtnmoteproxy_8c.html#b9e1449fd00c98428516f0b41eddcb10">00055</a> <span class="keywordtype">char</span> *<a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>;
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="dtnmoteproxy_8c.html#5bc78906abbe48e86727269a2f648b13">00057</a> <span class="keyword">static</span> <span class="keywordtype">char</span> *<a class="code" href="dtnmoteproxy_8c.html#5bc78906abbe48e86727269a2f648b13">msgs</a>[] = {
<a name="l00058"></a>00058   <span class="stringliteral">"unknown_packet_type"</span>,
<a name="l00059"></a>00059   <span class="stringliteral">"ack_timeout"</span> ,
<a name="l00060"></a>00060   <span class="stringliteral">"sync"</span>        ,
<a name="l00061"></a>00061   <span class="stringliteral">"too_long"</span>    ,
<a name="l00062"></a>00062   <span class="stringliteral">"too_short"</span>   ,
<a name="l00063"></a>00063   <span class="stringliteral">"bad_sync"</span>    ,
<a name="l00064"></a>00064   <span class="stringliteral">"bad_crc"</span>     ,
<a name="l00065"></a>00065   <span class="stringliteral">"closed"</span>      ,
<a name="l00066"></a>00066   <span class="stringliteral">"no_memory"</span>   ,
<a name="l00067"></a>00067   <span class="stringliteral">"unix_error"</span>
<a name="l00068"></a>00068 };
<a name="l00069"></a>00069 
<a name="l00070"></a><a class="code" href="structdata__packet.html">00070</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structdata__packet.html">data_packet</a>
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072     <span class="comment">// MultiHop Header </span>
<a name="l00073"></a><a class="code" href="structdata__packet.html#865074585264db3cec8f66f5167bd4a2">00073</a>     u_int16_t <a class="code" href="structdata__packet.html#865074585264db3cec8f66f5167bd4a2">source_mote_id</a>;
<a name="l00074"></a><a class="code" href="structdata__packet.html#1a1cca228d454a021049f58e89c5b50e">00074</a>     u_int16_t <a class="code" href="structdata__packet.html#1a1cca228d454a021049f58e89c5b50e">origin_mote_id</a>;
<a name="l00075"></a><a class="code" href="structdata__packet.html#aeda1f6af632b2f4b0cd3c1582fd853b">00075</a>     u_int16_t <a class="code" href="structdata__packet.html#aeda1f6af632b2f4b0cd3c1582fd853b">seq_no</a>;
<a name="l00076"></a><a class="code" href="structdata__packet.html#1982ab61d4d9053a9ddb477d304b0cce">00076</a>     u_int8_t <a class="code" href="structdata__packet.html#1982ab61d4d9053a9ddb477d304b0cce">hop_cnt</a>;
<a name="l00077"></a>00077 
<a name="l00078"></a>00078     <span class="comment">// Surge Sensor Header </span>
<a name="l00079"></a><a class="code" href="structdata__packet.html#a1cedf739677342bc34917f821172c28">00079</a>     u_int8_t <a class="code" href="structdata__packet.html#a1cedf739677342bc34917f821172c28">surge_pkt_type</a>;
<a name="l00080"></a><a class="code" href="structdata__packet.html#b2fc4691fea04e1c7ee297282b83ce3a">00080</a>     u_int16_t <a class="code" href="structdata__packet.html#b2fc4691fea04e1c7ee297282b83ce3a">surge_reading</a>;
<a name="l00081"></a><a class="code" href="structdata__packet.html#e8d9b23afb7fbb84d4bc111a1edcd73c">00081</a>     u_int16_t <a class="code" href="structdata__packet.html#e8d9b23afb7fbb84d4bc111a1edcd73c">surge_parent_addr</a>;
<a name="l00082"></a><a class="code" href="structdata__packet.html#f45dca592e2c2470075a77e98e487100">00082</a>     u_int32_t <a class="code" href="structdata__packet.html#f45dca592e2c2470075a77e98e487100">surge_seq_no</a>;
<a name="l00083"></a><a class="code" href="structdata__packet.html#b9468891d372c4004d28213a9ed5a661">00083</a>     u_int8_t <a class="code" href="structdata__packet.html#b9468891d372c4004d28213a9ed5a661">light</a>;
<a name="l00084"></a><a class="code" href="structdata__packet.html#5ea481c1a02b7bfae777bbcffef1abca">00084</a>     u_int8_t <a class="code" href="structdata__packet.html#5ea481c1a02b7bfae777bbcffef1abca">temp</a>;
<a name="l00085"></a><a class="code" href="structdata__packet.html#f48b1fdf77dfef7c3eefd7af15b39e9a">00085</a>     u_int8_t <a class="code" href="structdata__packet.html#f48b1fdf77dfef7c3eefd7af15b39e9a">magx</a>;
<a name="l00086"></a><a class="code" href="structdata__packet.html#63249e6b1b8c273e8d366fd77a091b9f">00086</a>     u_int8_t <a class="code" href="structdata__packet.html#63249e6b1b8c273e8d366fd77a091b9f">magy</a>;
<a name="l00087"></a><a class="code" href="structdata__packet.html#71446b4f0a8bea593ab1b717ebad58f7">00087</a>     u_int8_t <a class="code" href="structdata__packet.html#71446b4f0a8bea593ab1b717ebad58f7">accelx</a>;
<a name="l00088"></a><a class="code" href="structdata__packet.html#cfe3d93cbc34f1b4735f92824a07d03a">00088</a>     u_int8_t <a class="code" href="structdata__packet.html#cfe3d93cbc34f1b4735f92824a07d03a">accely</a>;
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 }<a class="code" href="structdata__packet.html">DATAPACKET</a>;
<a name="l00091"></a>00091 
<a name="l00092"></a><a class="code" href="dtnmoteproxy_8c.html#6422fc77e66a7c9f359cc0d81b3549d2">00092</a> <span class="preprocessor">#define DATAPACKET_SIZE 22</span>
<a name="l00093"></a><a class="code" href="dtnmoteproxy_8c.html#223118b852b11fb92879327173496faf">00093</a> <span class="preprocessor"></span><span class="preprocessor">#define SURGE_PKT       0x11</span>
<a name="l00094"></a><a class="code" href="dtnmoteproxy_8c.html#c75731c89378f785fa4983fffae5f59d">00094</a> <span class="preprocessor"></span><span class="preprocessor">#define DEBUG_PKT       0x03</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span>
<a name="l00096"></a>00096 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">parse_options</a>(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>**);
<a name="l00097"></a>00097 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtn__api_8h.html#566289d829b69370d7635c21364bfe18" title="The basic handle for communication with the dtn router.">dtn_handle_t</a> <a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid, 
<a name="l00098"></a>00098                           <span class="keywordtype">char</span> * str);
<a name="l00099"></a>00099 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>();
<a name="l00100"></a>00100 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="keywordtype">char</span> * label, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid);
<a name="l00101"></a>00101 <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#9ea9f901b7c8a430667973e8afb61e89">init_motes</a>();
<a name="l00102"></a>00102 <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#6a8fbdb1d98f54eadb6d0b5d93f83b37">stderr_msg</a>(<a class="code" href="serialsource_8h.html#606dc90f6ac5ac49f0296e9b7111b640">serial_source_msg</a> problem);
<a name="l00103"></a>00103 <span class="keywordtype">void</span> <a class="code" href="dtncpd_8c.html#2ef30c42cbc289d899a8be5d2d8f77d0">usage</a>(<span class="keywordtype">char</span> *str1, <span class="keywordtype">char</span> *str2);
<a name="l00104"></a>00104 <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#9abf80836181d78b2711d4d473d04e23">readCommandLineArgs</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv);
<a name="l00105"></a>00105 <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#fcfbfe49d70cde92b6f96050f295ea58">hexdump</a>();
<a name="l00106"></a>00106 <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#a21023159718c55a350afa42de887360">read_packet_file</a>(<span class="keywordtype">char</span>* <a class="code" href="dtnrecv_8c.html#b49244970ed5ca30989c2dab2129de34">filename</a>);
<a name="l00107"></a>00107 
<a name="l00108"></a>00108 <span class="comment">// specified options</span>
<a name="l00109"></a><a class="code" href="dtnmoteproxy_8c.html#a20698c008a0c4e0ba61b946cee297cf">00109</a> <span class="keywordtype">char</span> <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>[128];
<a name="l00110"></a><a class="code" href="dtnmoteproxy_8c.html#db8451edd36ea98d54a6189f3be08cae">00110</a> <span class="keywordtype">char</span> <a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a>[128];
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="dtnmoteproxy_8c.html#b52122d60a4add6ad99f3b4edfa8c792">00112</a> <span class="keywordtype">char</span> <a class="code" href="dtnmoteproxy_8c.html#b52122d60a4add6ad99f3b4edfa8c792">devicename</a>[128] = <span class="stringliteral">"/dev/ttyS0"</span>;
<a name="l00113"></a><a class="code" href="dtnmoteproxy_8c.html#4c3c3013cd09e4589bbb9634cb9ba1fb">00113</a> <span class="keywordtype">char</span> <a class="code" href="dtnmoteproxy_8c.html#4c3c3013cd09e4589bbb9634cb9ba1fb">baud</a>[128] = <span class="stringliteral">"57600"</span>;
<a name="l00114"></a><a class="code" href="dtnmoteproxy_8c.html#e904fd25559fa3de8aa035bebae938bb">00114</a> <span class="keywordtype">char</span> <a class="code" href="dtnmoteproxy_8c.html#e904fd25559fa3de8aa035bebae938bb">directory</a>[128]=<span class="stringliteral">"send"</span>;
<a name="l00115"></a><a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">00115</a> u_int32_t <a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> = 0;             <span class="comment">// higher values cause more info to print</span>
<a name="l00116"></a><a class="code" href="dtnmoteproxy_8c.html#e1ade0f5a1b32f6c8be72f31a99e2a18">00116</a> <a class="code" href="structserial__source.html">serial_source</a> <a class="code" href="dtnmoteproxy_8c.html#e1ade0f5a1b32f6c8be72f31a99e2a18">src</a>;
<a name="l00117"></a>00117 
<a name="l00118"></a><a class="code" href="dtnmoteproxy_8c.html#56a0ec58e8a4c0f144ab10e9eabc8934">00118</a> <span class="keywordtype">int</span> <a class="code" href="dtnmoteproxy_8c.html#56a0ec58e8a4c0f144ab10e9eabc8934">g_argc</a>;
<a name="l00119"></a><a class="code" href="dtnmoteproxy_8c.html#42cc1f3030bc4fced497d4a33ac59959">00119</a> <span class="keywordtype">char</span> **<a class="code" href="dtnmoteproxy_8c.html#42cc1f3030bc4fced497d4a33ac59959">g_argv</a>;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 <span class="keywordtype">int</span>
<a name="l00122"></a><a class="code" href="dtnmoteproxy_8c.html#3c04138a5bfe5d72780bb7e82a18e627">00122</a> <a class="code" href="dtncat_8c.html#3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124     <span class="comment">/* save in case of crash */</span>
<a name="l00125"></a>00125     <a class="code" href="dtnmoteproxy_8c.html#56a0ec58e8a4c0f144ab10e9eabc8934">g_argc</a> = argc;
<a name="l00126"></a>00126     <a class="code" href="dtnmoteproxy_8c.html#42cc1f3030bc4fced497d4a33ac59959">g_argv</a> = argv;
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     <a class="code" href="dtnmoteproxy_8c.html#9abf80836181d78b2711d4d473d04e23">readCommandLineArgs</a>(argc, argv);
<a name="l00129"></a>00129     <a class="code" href="dtnmoteproxy_8c.html#9ea9f901b7c8a430667973e8afb61e89">init_motes</a>();
<a name="l00130"></a>00130 
<a name="l00131"></a>00131     <span class="comment">// NOTREACHED </span>
<a name="l00132"></a>00132     <span class="keywordflow">return</span> (EXIT_FAILURE);      <span class="comment">// should never get here </span>
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134 
<a name="l00135"></a><a class="code" href="dtnmoteproxy_8c.html#6a8fbdb1d98f54eadb6d0b5d93f83b37">00135</a> <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#6a8fbdb1d98f54eadb6d0b5d93f83b37">stderr_msg</a>(<a class="code" href="serialsource_8h.html#606dc90f6ac5ac49f0296e9b7111b640">serial_source_msg</a> problem)
<a name="l00136"></a>00136 {
<a name="l00137"></a>00137   fprintf(stderr, <span class="stringliteral">"Note: %s\n"</span>, <a class="code" href="dtnmoteproxy_8c.html#5bc78906abbe48e86727269a2f648b13">msgs</a>[problem]);
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00140"></a><a class="code" href="dtnmoteproxy_8c.html#9c9c8f66b524a79298821db167e9d0a7">00140</a> <span class="keywordtype">int</span> <a class="code" href="dtnmoteproxy_8c.html#9c9c8f66b524a79298821db167e9d0a7">read_packet</a>(<span class="keywordtype">char</span> *<a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>, <span class="keywordtype">int</span> *n)
<a name="l00141"></a>00141 {
<a name="l00142"></a>00142     <span class="keyword">const</span> <span class="keywordtype">char</span> *buff;
<a name="l00143"></a>00143     <span class="keywordtype">int</span> i;
<a name="l00144"></a>00144     
<a name="l00145"></a>00145     <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 0) fprintf(stdout, <span class="stringliteral">"Reading packet:\n"</span>);
<a name="l00146"></a>00146     
<a name="l00147"></a>00147     <span class="keywordflow">if</span>(!(buff = <a class="code" href="serialsource_8c.html#ecafeccd1e584af0ad57764d1b05c962">read_serial_packet</a>(src, n)))
<a name="l00148"></a>00148         <span class="keywordflow">return</span> 0;
<a name="l00149"></a>00149 
<a name="l00150"></a>00150     <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 0) fprintf(stdout, <span class="stringliteral">" ==&gt; : "</span>);
<a name="l00151"></a>00151     <span class="keywordflow">for</span> (i = 0; i &lt; buff[4]; i++)
<a name="l00152"></a>00152         printf(<span class="stringliteral">" %02x"</span>, buff[i]);
<a name="l00153"></a>00153     putchar(<span class="charliteral">'\n'</span>);
<a name="l00154"></a>00154 
<a name="l00155"></a>00155    
<a name="l00156"></a>00156     <span class="comment">// strip TOS header &amp; copy to buf </span>
<a name="l00157"></a>00157     memset(buf,0,BUFSIZ);
<a name="l00158"></a>00158     memcpy(buf,buff,buff[4]+5);
<a name="l00159"></a>00159     *n=buff[4] + 5;
<a name="l00160"></a>00160     <span class="keywordflow">if</span>(buff[2]==<a class="code" href="dtnmoteproxy_8c.html#223118b852b11fb92879327173496faf">SURGE_PKT</a> || buff[2]==<a class="code" href="dtnmoteproxy_8c.html#c75731c89378f785fa4983fffae5f59d">DEBUG_PKT</a>) <span class="keywordflow">return</span> buff[2];
<a name="l00161"></a>00161     <span class="keywordflow">return</span> -1;
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 <span class="keywordtype">int</span>
<a name="l00165"></a><a class="code" href="dtnmoteproxy_8c.html#90b237b7351de6a657b9b54419e8ba1e">00165</a> <a class="code" href="dtnmoteproxy_8c.html#90b237b7351de6a657b9b54419e8ba1e">reader_thread</a>(<span class="keywordtype">void</span> *p)
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167 
<a name="l00168"></a>00168     <span class="comment">// loop reading from motes, writing to directory</span>
<a name="l00169"></a>00169 
<a name="l00170"></a>00170     <span class="keyword">static</span> <span class="keywordtype">int</span> tcnt=0;
<a name="l00171"></a>00171     <a class="code" href="structdata__packet.html">DATAPACKET</a> *dataPacket;
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     <span class="comment">// dtn api variables</span>
<a name="l00174"></a>00174     <span class="keywordtype">int</span> ret;
<a name="l00175"></a>00175     <a class="code" href="dtn__api_8h.html#566289d829b69370d7635c21364bfe18" title="The basic handle for communication with the dtn router.">dtn_handle_t</a> <a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>;
<a name="l00176"></a>00176     <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reginfo;
<a name="l00177"></a>00177     <a class="code" href="dtn__types_8h.html#d9378ff6ab7ee699568e037a8105f9b6" title="A registration cookie.">dtn_reg_id_t</a> <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a> = <a class="code" href="dtn__types_8h.html#f96cd9cebfff24e37ccececf05ebb4e6" title="Value for an unspecified registration cookie (i.e.">DTN_REGID_NONE</a>;
<a name="l00178"></a>00178     <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> <a class="code" href="dtncat_8c.html#70f601fc23b0cc97480972bf1ecf7f6c">bundle_spec</a>;
<a name="l00179"></a>00179     <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> send_payload;
<a name="l00180"></a>00180     <a class="code" href="structdtn__bundle__id__t.html" title="Type definition for a unique bundle identifier.">dtn_bundle_id_t</a> <a class="code" href="dtncat_8c.html#0d43174f8d3844aa5df38af2712ccb00">bundle_id</a>;
<a name="l00181"></a>00181     <span class="keywordtype">char</span> demux[4096];
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     p = NULL;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185     <span class="comment">// open the ipc handle</span>
<a name="l00186"></a>00186     <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 0) fprintf(stdout, <span class="stringliteral">"Opening connection to local DTN daemon\n"</span>);
<a name="l00187"></a>00187 
<a name="l00188"></a>00188     <span class="keywordtype">int</span> err = <a class="code" href="dtn__api_8c.html#3afc66b2e2c75fae07a45467df9f74e9" title="Open a new connection to the router.">dtn_open</a>(&amp;handle);
<a name="l00189"></a>00189     <span class="keywordflow">if</span> (err != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) {
<a name="l00190"></a>00190         fprintf(stderr, <span class="stringliteral">"fatal error opening dtn handle: %s\n"</span>,
<a name="l00191"></a>00191                 <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(err));
<a name="l00192"></a>00192         exit(1);
<a name="l00193"></a>00193     }
<a name="l00194"></a>00194 
<a name="l00195"></a>00195     <span class="comment">// ----------------------------------------------------</span>
<a name="l00196"></a>00196     <span class="comment">// initialize bundle spec with src/dest/replyto</span>
<a name="l00197"></a>00197     <span class="comment">// ----------------------------------------------------</span>
<a name="l00198"></a>00198 
<a name="l00199"></a>00199     <span class="comment">// initialize bundle spec</span>
<a name="l00200"></a>00200     memset(&amp;bundle_spec, 0, <span class="keyword">sizeof</span>(bundle_spec));
<a name="l00201"></a>00201 
<a name="l00202"></a>00202     <span class="comment">// destination host is specified at run time, demux is hardcoded</span>
<a name="l00203"></a>00203     sprintf(demux, <span class="stringliteral">"%s/dtnmoteproxy/recv"</span>, <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>);
<a name="l00204"></a>00204     <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(handle, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>, demux);
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     <span class="comment">// source is local eid with file path as demux string</span>
<a name="l00207"></a>00207     sprintf(demux, <span class="stringliteral">"/dtnmoteproxy/send"</span>);
<a name="l00208"></a>00208     <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(handle, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>, demux);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     <span class="comment">// reply to is the same as the source</span>
<a name="l00211"></a>00211     <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>);
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 
<a name="l00214"></a>00214     <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 2)
<a name="l00215"></a>00215     {
<a name="l00216"></a>00216         <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="stringliteral">"source_eid"</span>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>);
<a name="l00217"></a>00217         <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="stringliteral">"replyto_eid"</span>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>);
<a name="l00218"></a>00218         <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="stringliteral">"dest_eid"</span>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>);
<a name="l00219"></a>00219     }
<a name="l00220"></a>00220 
<a name="l00221"></a>00221     <span class="comment">// set the return receipt option</span>
<a name="l00222"></a>00222     bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000961c42551cde98aaccb2272d32f0a06c">DOPTS_DELIVERY_RCPT</a>;
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <span class="comment">// send file and wait for reply</span>
<a name="l00225"></a>00225 
<a name="l00226"></a>00226     <span class="comment">// create a new dtn registration to receive bundle status reports</span>
<a name="l00227"></a>00227     memset(&amp;reginfo, 0, <span class="keyword">sizeof</span>(reginfo));
<a name="l00228"></a>00228     <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&amp;reginfo.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>);
<a name="l00229"></a>00229     reginfo.<a class="code" href="structdtn__reg__info__t.html#7bf2e33b713b585bfe1792c40fa8cd6c">flags</a> = <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00d21fdf39ccc69d6790aec0c70ce5f972">DTN_REG_DEFER</a>;
<a name="l00230"></a>00230     reginfo.<a class="code" href="structdtn__reg__info__t.html#6909a69cc63e748899cf4f9fe8c8901a">regid</a> = regid;
<a name="l00231"></a>00231     reginfo.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = 0;
<a name="l00232"></a>00232     <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#7384bf592d4aff0892ff948aafa98b0c" title="Create a dtn registration.">dtn_register</a>(handle, &amp;reginfo, &amp;regid)) != 0) {
<a name="l00233"></a>00233         fprintf(stderr, <span class="stringliteral">"error creating registration (id=%d): %d (%s)\n"</span>,
<a name="l00234"></a>00234                 regid, ret, <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(handle)));
<a name="l00235"></a>00235         exit(1);
<a name="l00236"></a>00236     }
<a name="l00237"></a>00237     
<a name="l00238"></a>00238     <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 3) printf(<span class="stringliteral">"dtn_register succeeded, regid 0x%x\n"</span>, regid);
<a name="l00239"></a>00239 
<a name="l00240"></a>00240     <span class="keywordflow">while</span> (1) {
<a name="l00241"></a>00241         <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> motedata[BUFSIZ];
<a name="l00242"></a>00242         <span class="keywordtype">int</span> length;
<a name="l00243"></a>00243         <span class="keywordtype">int</span> ret;
<a name="l00244"></a>00244 
<a name="l00245"></a>00245         <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 1) fprintf(<a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">dout</a>, <span class="stringliteral">"about to read from motes...\n"</span>);
<a name="l00246"></a>00246 
<a name="l00247"></a>00247         <span class="keywordflow">while</span>((ret=<a class="code" href="dtnmoteproxy_8c.html#9c9c8f66b524a79298821db167e9d0a7">read_packet</a>((<span class="keywordtype">char</span> *) motedata, (<span class="keywordtype">int</span> *) &amp;length))){
<a name="l00248"></a>00248             <span class="keywordflow">if</span>(ret==<a class="code" href="dtnmoteproxy_8c.html#c75731c89378f785fa4983fffae5f59d">DEBUG_PKT</a>)
<a name="l00249"></a>00249                 <span class="keywordflow">continue</span>;
<a name="l00250"></a>00250             <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 0) {
<a name="l00251"></a>00251                 fprintf(<a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">dout</a>, <span class="stringliteral">"\nreader loop... got [%d] bytes from motes\n"</span>, 
<a name="l00252"></a>00252                         length);
<a name="l00253"></a>00253                 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 1) <a class="code" href="dtnmoteproxy_8c.html#fcfbfe49d70cde92b6f96050f295ea58">hexdump</a>(motedata, length);
<a name="l00254"></a>00254             }
<a name="l00255"></a>00255            
<a name="l00256"></a>00256             <span class="comment">// the extra cast to void* is needed to circumvent gcc warnings</span>
<a name="l00257"></a>00257             <span class="comment">// about unsafe casting </span>
<a name="l00258"></a>00258             dataPacket=(<a class="code" href="structdata__packet.html">DATAPACKET</a> *)((<span class="keywordtype">void</span>*)motedata);
<a name="l00259"></a>00259             
<a name="l00260"></a>00260             <span class="comment">// skip packets from base mote </span>
<a name="l00261"></a>00261             <span class="keywordflow">if</span>(dataPacket-&gt;<a class="code" href="structdata__packet.html#1a1cca228d454a021049f58e89c5b50e">origin_mote_id</a> == 0) <span class="keywordflow">continue</span>;
<a name="l00262"></a>00262 
<a name="l00263"></a>00263             <span class="comment">// set a default expiration time of one hour</span>
<a name="l00264"></a>00264             bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#57f2d6068db6a5b38a73416ea721e814">expiration</a> = 3600;
<a name="l00265"></a>00265             
<a name="l00266"></a>00266             <span class="comment">// fill in a payload</span>
<a name="l00267"></a>00267             memset(&amp;send_payload, 0, <span class="keyword">sizeof</span>(send_payload));
<a name="l00268"></a>00268 
<a name="l00269"></a>00269             <a class="code" href="dtn__api_8c.html#21b6d705673aae970524972aca3db99f" title="Sets the value of the given payload structure to either a memory buffer or a file...">dtn_set_payload</a>(&amp;send_payload, <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>,
<a name="l00270"></a>00270                             (<span class="keywordtype">char</span> *) motedata, length);
<a name="l00271"></a>00271  
<a name="l00272"></a>00272             memset(&amp;bundle_id, 0, <span class="keyword">sizeof</span>(bundle_id));
<a name="l00273"></a>00273                         
<a name="l00274"></a>00274             <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#9bcce797cfff268e49c0f5b2e5f21788" title="Send a bundle either from memory or from a file.">dtn_send</a>(handle, regid, &amp;bundle_spec, &amp;send_payload,
<a name="l00275"></a>00275                                 &amp;bundle_id)) != 0)
<a name="l00276"></a>00276             {
<a name="l00277"></a>00277                 fprintf(stderr, <span class="stringliteral">"error sending bundle: %d (%s)\n"</span>,
<a name="l00278"></a>00278                         ret, <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(handle)));
<a name="l00279"></a>00279             }   
<a name="l00280"></a>00280             <span class="keywordflow">else</span> fprintf(stderr, <span class="stringliteral">"motedata bundle sent"</span>);
<a name="l00281"></a>00281 
<a name="l00282"></a>00282             printf(<span class="stringliteral">"Mote ID = %u\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#1a1cca228d454a021049f58e89c5b50e">origin_mote_id</a>);
<a name="l00283"></a>00283             printf(<span class="stringliteral">"Source Mote ID = %u\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#865074585264db3cec8f66f5167bd4a2">source_mote_id</a>);
<a name="l00284"></a>00284             printf(<span class="stringliteral">"Hop Count = %u\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#1982ab61d4d9053a9ddb477d304b0cce">hop_cnt</a>);
<a name="l00285"></a>00285             printf(<span class="stringliteral">"Packet Type = %u\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#a1cedf739677342bc34917f821172c28">surge_pkt_type</a>);
<a name="l00286"></a>00286             printf(<span class="stringliteral">"Parent Address = %u\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#e8d9b23afb7fbb84d4bc111a1edcd73c">surge_parent_addr</a>);
<a name="l00287"></a>00287             printf(<span class="stringliteral">"Sequence Number = %u\n"</span>, (u_int)dataPacket-&gt;<a class="code" href="structdata__packet.html#f45dca592e2c2470075a77e98e487100">surge_seq_no</a>);
<a name="l00288"></a>00288             printf(<span class="stringliteral">"Light = %u\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#b9468891d372c4004d28213a9ed5a661">light</a>);
<a name="l00289"></a>00289             printf(<span class="stringliteral">"Temperature = %u\n\n"</span>,dataPacket-&gt;<a class="code" href="structdata__packet.html#5ea481c1a02b7bfae777bbcffef1abca">temp</a>);        
<a name="l00290"></a>00290 
<a name="l00291"></a>00291             tcnt=(tcnt+1)%10000;
<a name="l00292"></a>00292           
<a name="l00293"></a>00293         }
<a name="l00294"></a>00294         <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> &gt; 0)
<a name="l00295"></a>00295             fprintf(<a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">dout</a>, <span class="stringliteral">"reader loop.... nothing to do? [shouldn't happen]\n"</span>);
<a name="l00296"></a>00296     }
<a name="l00297"></a>00297 
<a name="l00298"></a>00298     <span class="comment">// if this was ever changed to gracefully shutdown, it would be good to call:</span>
<a name="l00299"></a>00299     <a class="code" href="dtn__api_8c.html#887c16260463d6057bf5b03a1ff0e224" title="Close an open dtn handle.">dtn_close</a>(handle);
<a name="l00300"></a>00300     
<a name="l00301"></a>00301     <span class="keywordflow">return</span> (1);
<a name="l00302"></a>00302     <span class="comment">// NOTREACHED </span>
<a name="l00303"></a>00303 }
<a name="l00304"></a>00304 
<a name="l00305"></a>00305 
<a name="l00306"></a>00306 <span class="keywordtype">void</span>
<a name="l00307"></a><a class="code" href="dtnmoteproxy_8c.html#9abf80836181d78b2711d4d473d04e23">00307</a> <a class="code" href="dtnmoteproxy_8c.html#9abf80836181d78b2711d4d473d04e23">readCommandLineArgs</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00308"></a>00308 {
<a name="l00309"></a>00309     <span class="keywordtype">int</span> c;
<a name="l00310"></a>00310 
<a name="l00311"></a>00311     <span class="keywordflow">while</span> ((c = getopt(argc, argv, <span class="stringliteral">"hr:d:b:D:t:"</span>)) != EOF) {
<a name="l00312"></a>00312         <span class="keywordflow">switch</span> (c) {
<a name="l00313"></a>00313         <span class="keywordflow">case</span> <span class="charliteral">'h'</span>:
<a name="l00314"></a>00314             <a class="code" href="dtncpd_8c.html#2ef30c42cbc289d899a8be5d2d8f77d0">usage</a>(<span class="stringliteral">"moteproxy"</span>, <span class="stringliteral">""</span>);
<a name="l00315"></a>00315             exit(0);
<a name="l00316"></a>00316             <span class="keywordflow">break</span>;
<a name="l00317"></a>00317         <span class="keywordflow">case</span> <span class="charliteral">'r'</span>:
<a name="l00318"></a>00318             <a class="code" href="dtnmoteproxy_8c.html#a21023159718c55a350afa42de887360">read_packet_file</a>(optarg);
<a name="l00319"></a>00319             exit(0);
<a name="l00320"></a>00320         <span class="keywordflow">case</span> <span class="charliteral">'d'</span>:
<a name="l00321"></a>00321             <a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> = atoi(optarg);
<a name="l00322"></a>00322             <span class="keywordflow">break</span>;
<a name="l00323"></a>00323         <span class="keywordflow">case</span> <span class="charliteral">'b'</span>:
<a name="l00324"></a>00324             strcpy(<a class="code" href="dtnmoteproxy_8c.html#4c3c3013cd09e4589bbb9634cb9ba1fb">baud</a>, optarg);
<a name="l00325"></a>00325             <span class="keywordflow">break</span>;
<a name="l00326"></a>00326         <span class="keywordflow">case</span> <span class="charliteral">'t'</span>:
<a name="l00327"></a>00327             strcpy(<a class="code" href="dtnmoteproxy_8c.html#b52122d60a4add6ad99f3b4edfa8c792">devicename</a>, optarg);
<a name="l00328"></a>00328             <span class="keywordflow">break</span>;
<a name="l00329"></a>00329         <span class="keywordflow">case</span> <span class="charliteral">'D'</span>:
<a name="l00330"></a>00330             strcpy(<a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>,optarg);
<a name="l00331"></a>00331             <span class="keywordflow">break</span>;              
<a name="l00332"></a>00332         <span class="keywordflow">default</span>:
<a name="l00333"></a>00333             fprintf(stderr, <span class="stringliteral">"mfproxy: unknown option: '%c'\n"</span>, (<span class="keywordtype">char</span>) c);
<a name="l00334"></a>00334             <a class="code" href="dtncpd_8c.html#2ef30c42cbc289d899a8be5d2d8f77d0">usage</a>(<span class="stringliteral">"moteproxy"</span>, <span class="stringliteral">""</span>);
<a name="l00335"></a>00335             exit(EXIT_FAILURE);
<a name="l00336"></a>00336         }
<a name="l00337"></a>00337     }
<a name="l00338"></a>00338 }
<a name="l00339"></a>00339 
<a name="l00340"></a>00340 <span class="keywordtype">void</span>
<a name="l00341"></a><a class="code" href="dtnmoteproxy_8c.html#28805ae879318ac40b2fc40d9dfce237">00341</a> <a class="code" href="dtncpd_8c.html#2ef30c42cbc289d899a8be5d2d8f77d0">usage</a>(<span class="keywordtype">char</span> *str1, <span class="keywordtype">char</span> *str2)
<a name="l00342"></a>00342 {
<a name="l00343"></a>00343     (void)str2;
<a name="l00344"></a>00344     
<a name="l00345"></a>00345     fprintf(stderr, <span class="stringliteral">"usage: %s\n"</span>, str1);
<a name="l00346"></a>00346     fprintf(stderr, <span class="stringliteral">"  [-b baudrate]     - baud rate\n"</span>);
<a name="l00347"></a>00347     fprintf(stderr, <span class="stringliteral">"  [-t devicename]      - name of mote network dev tty\n"</span>);
<a name="l00348"></a>00348     fprintf(stderr, <span class="stringliteral">"  [-d debugValue]\n"</span>);
<a name="l00349"></a>00349     fprintf(stderr, <span class="stringliteral">"  [-D directory]\n"</span>);
<a name="l00350"></a>00350     fprintf(stderr, <span class="stringliteral">"  [-h]              - print this message.\n"</span>);
<a name="l00351"></a>00351     fprintf(stderr, <span class="stringliteral">"\n"</span>);
<a name="l00352"></a>00352 }
<a name="l00353"></a>00353 
<a name="l00354"></a>00354 
<a name="l00355"></a>00355 <span class="comment">// initialize the motes</span>
<a name="l00356"></a>00356 <span class="keywordtype">void</span>
<a name="l00357"></a><a class="code" href="dtnmoteproxy_8c.html#9ea9f901b7c8a430667973e8afb61e89">00357</a> <a class="code" href="dtnmoteproxy_8c.html#9ea9f901b7c8a430667973e8afb61e89">init_motes</a>()
<a name="l00358"></a>00358 {
<a name="l00359"></a>00359     src = <a class="code" href="serialsource_8c.html#1f56b3ed3ca860efcd58d5c212b17066">open_serial_source</a>(<a class="code" href="dtnmoteproxy_8c.html#b52122d60a4add6ad99f3b4edfa8c792">devicename</a>, atoi(<a class="code" href="dtnmoteproxy_8c.html#4c3c3013cd09e4589bbb9634cb9ba1fb">baud</a>), 0, <a class="code" href="dtnmoteproxy_8c.html#6a8fbdb1d98f54eadb6d0b5d93f83b37">stderr_msg</a>);
<a name="l00360"></a>00360 
<a name="l00361"></a>00361     <span class="keywordflow">if</span>(<a class="code" href="dtnmoteproxy_8c.html#90b237b7351de6a657b9b54419e8ba1e">reader_thread</a>(NULL) == 1) {
<a name="l00362"></a>00362         fprintf(stderr, <span class="stringliteral">"couldn't start reader on mote network\n"</span>);
<a name="l00363"></a>00363         exit(EXIT_FAILURE);
<a name="l00364"></a>00364     }
<a name="l00365"></a>00365     <span class="keywordflow">return</span>;
<a name="l00366"></a>00366 }
<a name="l00367"></a>00367 
<a name="l00368"></a><a class="code" href="dtnmoteproxy_8c.html#a21023159718c55a350afa42de887360">00368</a> <span class="keywordtype">void</span> <a class="code" href="dtnmoteproxy_8c.html#a21023159718c55a350afa42de887360">read_packet_file</a>(<span class="keywordtype">char</span>* <a class="code" href="dtnrecv_8c.html#b49244970ed5ca30989c2dab2129de34">filename</a>)
<a name="l00369"></a>00369 {
<a name="l00370"></a>00370     <span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#6f8059414f0228f0256115e024eeed4b">fd</a> = open(filename, O_RDONLY);
<a name="l00371"></a>00371     <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>[BUFSIZ];
<a name="l00372"></a>00372     <span class="keywordtype">int</span> n = read(fd, buf, BUFSIZ);
<a name="l00373"></a>00373     <a class="code" href="dtnmoteproxy_8c.html#fcfbfe49d70cde92b6f96050f295ea58">hexdump</a>(buf, n);
<a name="l00374"></a>00374 }
<a name="l00375"></a>00375 
<a name="l00376"></a>00376 <span class="keywordtype">void</span>
<a name="l00377"></a><a class="code" href="dtnmoteproxy_8c.html#601d8e7ee37c096dfd4c14ddd21451c5">00377</a> <a class="code" href="dtnmoteproxy_8c.html#fcfbfe49d70cde92b6f96050f295ea58">hexdump</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *<a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>, <span class="keywordtype">int</span> n)
<a name="l00378"></a>00378 {
<a name="l00379"></a>00379     <span class="keywordtype">int</span> i;
<a name="l00380"></a>00380     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *p = buf;
<a name="l00381"></a>00381 
<a name="l00382"></a>00382     fprintf(<a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">dout</a>,<span class="stringliteral">"Packet contains %d:\n"</span>,n);
<a name="l00383"></a>00383     <span class="keywordflow">for</span> (i = 0; i &lt; n; i++) {
<a name="l00384"></a>00384         fprintf(<a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">dout</a>,<span class="stringliteral">"%02x "</span>, *p++);
<a name="l00385"></a>00385         <span class="keywordflow">if</span> ((i &amp; 0x7) == 0x7)
<a name="l00386"></a>00386             fprintf(<a class="code" href="dtnmoteproxy_8c.html#61fed2eba7bb9f87e1b1ab5f68be592a">dout</a>,<span class="stringliteral">"\n"</span>);
<a name="l00387"></a>00387     }
<a name="l00388"></a>00388     printf(<span class="stringliteral">"\n\n"</span>);
<a name="l00389"></a>00389     fflush(stdout);
<a name="l00390"></a>00390 }
<a name="l00391"></a>00391 
<a name="l00392"></a>00392 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtn__api_8h.html#566289d829b69370d7635c21364bfe18" title="The basic handle for communication with the dtn router.">dtn_handle_t</a> <a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, 
<a name="l00393"></a>00393                           <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid, <span class="keywordtype">char</span> * str)
<a name="l00394"></a>00394 {
<a name="l00395"></a>00395     
<a name="l00396"></a>00396     <span class="comment">// try the string as an actual dtn eid</span>
<a name="l00397"></a>00397     <span class="keywordflow">if</span> (!<a class="code" href="dtn__api_8c.html#055c8bb8eaa570aacbe6a164ff123c84" title="Parse a string into an endpoint id structure, validating that it is in fact a valid...">dtn_parse_eid_string</a>(eid, str)) 
<a name="l00398"></a>00398     {
<a name="l00399"></a>00399         <span class="keywordflow">return</span> eid;
<a name="l00400"></a>00400     }
<a name="l00401"></a>00401     <span class="comment">// build a local eid based on the configuration of our dtn</span>
<a name="l00402"></a>00402     <span class="comment">// router plus the str as demux string</span>
<a name="l00403"></a>00403     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!<a class="code" href="dtn__api_8c.html#0947b9119c69984edf25df43ead8858b" title="Build an appropriate local endpoint id by appending the specified service tag to...">dtn_build_local_eid</a>(handle, eid, str))
<a name="l00404"></a>00404     {
<a name="l00405"></a>00405         <span class="keywordflow">return</span> eid;
<a name="l00406"></a>00406     }
<a name="l00407"></a>00407     <span class="keywordflow">else</span>
<a name="l00408"></a>00408     {
<a name="l00409"></a>00409         fprintf(stderr, <span class="stringliteral">"invalid eid string '%s'\n"</span>, str);
<a name="l00410"></a>00410         exit(1);
<a name="l00411"></a>00411     }
<a name="l00412"></a>00412 }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="keywordtype">char</span>* label, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a>* eid)
<a name="l00415"></a>00415 {
<a name="l00416"></a>00416     printf(<span class="stringliteral">"%s [%s]\n"</span>, label, eid-&gt;<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>);
<a name="l00417"></a>00417 }
<a name="l00418"></a>00418     
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:55 2009 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>