Contiki 2.5
test-abc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * $Id: test-abc.c,v 1.5 2010/02/05 11:52:37 nvt-se Exp $
32  */
33 
34 /**
35  * \file
36  * Testing the abc layer in Rime
37  * \author
38  * Adam Dunkels <adam@sics.se>
39  */
40 
41 #include "contiki.h"
42 #include "net/rime.h"
43 #include "node-id.h"
44 
45 #include <stdio.h>
46 
47 #ifndef SENDER_ID
48 #define SENDER_ID 1
49 #endif
50 
51 #ifndef SEND_INTERVAL
52 #define SEND_INTERVAL (CLOCK_SECOND * 3)
53 #endif
54 
55 /*---------------------------------------------------------------------------*/
56 PROCESS(test_abc_process, "ABC test");
57 AUTOSTART_PROCESSES(&test_abc_process);
58 /*---------------------------------------------------------------------------*/
59 static void
60 abc_recv(struct abc_conn *c)
61 {
62  char *s;
63  int i;
64 
65  s = packetbuf_dataptr();
66 
67  printf("abc message received '%s'\n", (char *)packetbuf_dataptr());
68  printf("message length: %u\n", packetbuf_datalen());
69  for (i = 0; i < packetbuf_datalen(); i++) {
70  printf("0x%x ", s[i]);
71  }
72  printf("\n");
73 }
74 const static struct abc_callbacks abc_call = {abc_recv};
75 static struct abc_conn abc;
76 /*---------------------------------------------------------------------------*/
77 PROCESS_THREAD(test_abc_process, ev, data)
78 {
79  static unsigned i;
80  static struct etimer et;
81  static int len;
82  static char buf[32];
83 
85 
86  PROCESS_BEGIN();
87 
88  abc_open(&abc, 128, &abc_call);
89 
90  while(1) {
91  etimer_set(&et, SEND_INTERVAL);
93  if (etimer_expired(&et) && node_id == SENDER_ID) {
94  len = snprintf(buf, sizeof (buf), "%u", ++i);
95  printf("Sending packet %d\n", i);
96  packetbuf_copyfrom(buf, len + 1);
97  abc_send(&abc);
98  }
99  }
100 
101  PROCESS_END();
102 }
103 /*---------------------------------------------------------------------------*/