-
Notifications
You must be signed in to change notification settings - Fork 0
/
a00013.html
183 lines (159 loc) · 11.5 KB
/
a00013.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!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>Contiki 2.5: example-rucb.c</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.6.1 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="dirs.html"><span>Directories</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>example-rucb.c</h1><div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * Copyright (c) 2007, Swedish Institute of Computer Science.</span>
<span class="comment"> * All rights reserved.</span>
<span class="comment"> *</span>
<span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<span class="comment"> * modification, are permitted provided that the following conditions</span>
<span class="comment"> * are met:</span>
<span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
<span class="comment"> * notice, this list of conditions and the following disclaimer.</span>
<span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
<span class="comment"> * documentation and/or other materials provided with the distribution.</span>
<span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors</span>
<span class="comment"> * may be used to endorse or promote products derived from this software</span>
<span class="comment"> * without specific prior written permission.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND</span>
<span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE</span>
<span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
<span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
<span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
<span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
<span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
<span class="comment"> * SUCH DAMAGE.</span>
<span class="comment"> *</span>
<span class="comment"> * This file is part of the Contiki operating system.</span>
<span class="comment"> *</span>
<span class="comment"> * $Id: example-rucb.c,v 1.7 2010/01/15 10:24:37 nifi Exp $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * \file</span>
<span class="comment"> * Testing the rucb code in Rime</span>
<span class="comment"> * \author</span>
<span class="comment"> * Adam Dunkels <adam@sics.se></span>
<span class="comment"> */</span>
<span class="preprocessor">#include "contiki.h"</span>
<span class="preprocessor">#include "<a class="code" href="a00361.html" title="Header file for the reliable unicast bulk transfer module.">net/rime/rucb.h</a>"</span>
<span class="preprocessor">#include "dev/button-sensor.h"</span>
<span class="preprocessor">#include "dev/leds.h"</span>
<span class="preprocessor">#include "<a class="code" href="a00127.html" title="CFS header file.">cfs/cfs.h</a>"</span>
<span class="preprocessor">#include "<a class="code" href="a00214.html" title="Convenience function for printing system statistics.">lib/print-stats.h</a>"</span>
<span class="preprocessor">#include "<a class="code" href="a00461.html" title="Header file for the Contiki profiling system.">sys/profile.h</a>"</span>
<span class="preprocessor">#include <stdio.h></span>
<span class="preprocessor">#if CONTIKI_TARGET_NETSIM</span>
<span class="preprocessor"></span><span class="preprocessor">#include "ether.h"</span>
<span class="preprocessor">#include "node.h"</span>
<span class="preprocessor">#endif </span><span class="comment">/* CONTIKI_TARGET_NETSIM */</span>
<span class="preprocessor">#define FILESIZE 40000</span>
<span class="preprocessor"></span>
<span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> bytecount;
<span class="keyword">static</span> clock_time_t start_time;
<span class="keyword">extern</span> <span class="keywordtype">int</span> profile_max_queuelen;
<span class="comment">/*---------------------------------------------------------------------------*/</span>
<a name="a0"></a><a class="code" href="a01627.html#ga27e9b6fc13f0438e37a198f69b38b4cf" title="Declare a process.">PROCESS</a>(example_rucb_process, <span class="stringliteral">"Rucb example"</span>);
AUTOSTART_PROCESSES(&example_rucb_process);
<span class="comment">/*---------------------------------------------------------------------------*/</span>
<span class="keyword">static</span> <span class="keywordtype">void</span>
write_chunk(<span class="keyword">struct</span> rucb_conn *c, <span class="keywordtype">int</span> offset, <span class="keywordtype">int</span> flag,
<span class="keywordtype">char</span> *data, <span class="keywordtype">int</span> datalen)
{
<span class="preprocessor">#if CONTIKI_TARGET_NETSIM</span>
<span class="preprocessor"></span> {
<span class="keywordtype">char</span> buf[100];
printf(<span class="stringliteral">"received %d; %d\n"</span>, offset, datalen);
sprintf(buf, <span class="stringliteral">"%d%%"</span>, (100 * (offset + datalen)) / FILESIZE);
ether_set_text(buf);
}
<span class="preprocessor">#endif </span><span class="comment">/* CONTIKI_TARGET_NETSIM */</span>
}
<span class="keyword">static</span> <span class="keywordtype">int</span>
read_chunk(<span class="keyword">struct</span> rucb_conn *c, <span class="keywordtype">int</span> offset, <span class="keywordtype">char</span> *to, <span class="keywordtype">int</span> maxsize)
{
<span class="keywordtype">int</span> size;
size = maxsize;
<span class="keywordflow">if</span>(bytecount + maxsize >= FILESIZE) {
size = FILESIZE - bytecount;
}
bytecount += size;
<span class="keywordflow">if</span>(bytecount == FILESIZE) {
printf(<span class="stringliteral">"Completion time %lu / %u\n"</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)<a name="a1"></a><a class="code" href="a01620.html#ga50c22f9b9d60dd1f9e59b63a3a6676b1" title="Get the current clock time.">clock_time</a>() - start_time, <a name="a2"></a><a class="code" href="a01620.html#gae3ced0551b26c9b99cb45a86f34d100a" title="A second, measured in system clock time.">CLOCK_SECOND</a>);
<span class="comment">/* profile_aggregates_print(); */</span>
<span class="comment">/* profile_print_stats(); */</span>
print_stats();
}
<span class="comment">/* printf("bytecount %lu\n", bytecount);*/</span>
<span class="keywordflow">return</span> size;
}
<span class="keyword">const</span> <span class="keyword">static</span> <span class="keyword">struct </span>rucb_callbacks rucb_call = {write_chunk, read_chunk,
NULL};
<span class="keyword">static</span> <span class="keyword">struct </span>rucb_conn rucb;
<span class="comment">/*---------------------------------------------------------------------------*/</span>
<span class="preprocessor">#include "node-id.h"</span>
<a name="a3"></a><a class="code" href="a01627.html#gaa4cff8e4f3abc50c74619a90ae347200" title="Define the body of a process.">PROCESS_THREAD</a>(example_rucb_process, ev, data)
{
<a name="a4"></a><a class="code" href="a01627.html#ga3dee46e19ad8848b86d9d06321b75c0e" title="Specify an action when a process exits.">PROCESS_EXITHANDLER</a>(rucb_close(&rucb);)
<a name="a5"></a><a class="code" href="a01627.html#ga8efc62947f2ca2c870f52896e0dc1a81" title="Define the beginning of a process.">PROCESS_BEGIN</a>();
<a name="a6"></a><a class="code" href="a01627.html#ga29eb92d7ef01f486d70a90cc34800a5d" title="Yield the process for a short while.">PROCESS_PAUSE</a>();
rucb_open(&rucb, 137, &rucb_call);
SENSORS_ACTIVATE(button_sensor);
<a class="code" href="a01627.html#ga29eb92d7ef01f486d70a90cc34800a5d" title="Yield the process for a short while.">PROCESS_PAUSE</a>();
<span class="keywordflow">if</span>(<a name="a7"></a><a class="code" href="a01606.html#gaade5a80096fb3b4296cf89eeaca3087d" title="The Rime address of the node.">rimeaddr_node_addr</a>.u8[0] == 51 &&
<a class="code" href="a01606.html#gaade5a80096fb3b4296cf89eeaca3087d" title="The Rime address of the node.">rimeaddr_node_addr</a>.u8[1] == 0) {
rimeaddr_t recv;
recv.u8[0] = 52;
recv.u8[1] = 0;
start_time = <a class="code" href="a01620.html#ga50c22f9b9d60dd1f9e59b63a3a6676b1" title="Get the current clock time.">clock_time</a>();
<span class="comment">/*printf("%u.%u: sending rucb to address %u.%u at time %u\n",</span>
<span class="comment"> rimeaddr_node_addr.u8[0],</span>
<span class="comment"> rimeaddr_node_addr.u8[1],</span>
<span class="comment"> recv.u8[0],</span>
<span class="comment"> recv.u8[1],</span>
<span class="comment"> start_time);*/</span>
rucb_send(&rucb, &recv);
<span class="preprocessor">#if CONTIKI_TARGET_NETSIM</span>
<span class="preprocessor"></span> ether_send_done();
<span class="preprocessor">#endif </span><span class="comment">/* CONTIKI_TARGET_NETSIM */</span>
}
<span class="keywordflow">while</span>(1) {
<a name="a8"></a><a class="code" href="a01627.html#ga996168a0f904c0e28e3f6ed18dddd129" title="Wait for an event to be posted to the process, with an extra condition.">PROCESS_WAIT_EVENT_UNTIL</a>(ev == sensors_event &&
data == &button_sensor);
<span class="comment">/*rucb_stop(&rucb);*/</span>
}
<a name="a9"></a><a class="code" href="a01627.html#ga9c2681a0070eba8a7c9fdf4dbb6db05e" title="Define the end of a process.">PROCESS_END</a>();
}
<span class="comment">/*---------------------------------------------------------------------------*/</span>
</pre></div> </div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Mon Apr 11 14:23:26 2011 for Contiki 2.5 by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>