]> oss.titaniummirror.com Git - tinyos-2.x.git/blob - apps/tests/NxFloat/TestSerialC.nc
add support for IRIS (it was CC2420 specific)
[tinyos-2.x.git] / apps / tests / NxFloat / TestSerialC.nc
1 // $Id$
2
3 /* tab:4
4 * "Copyright (c) 2000-2005 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation for any purpose, without fee, and without written agreement is
9 * hereby granted, provided that the above copyright notice, the following
10 * two paragraphs and the author appear in all copies of this software.
11 *
12 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
14 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
15 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
20 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
21 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
22 *
23 * Copyright (c) 2002-2003 Intel Corporation
24 * All rights reserved.
25 *
26 * This file is distributed under the terms in the attached INTEL-LICENSE
27 * file. If you do not find these files, copies can be found by writing to
28 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
29 * 94704. Attention: Intel License Inquiry.
30 */
31
32 /**
33 * Application to test that the TinyOS java toolchain can communicate
34 * with motes over the serial port.
35 *
36 * @author Gilman Tolle
37 * @author Philip Levis
38 *
39 * @date Aug 12 2005
40 *
41 **/
42
43 #include "Timer.h"
44 #include "TestSerial.h"
45
46 module TestSerialC {
47 uses {
48 interface SplitControl as Control;
49 interface Leds;
50 interface Boot;
51 interface Receive;
52 interface AMSend;
53 interface Timer<TMilli> as MilliTimer;
54 interface Packet;
55 }
56 }
57 implementation {
58
59 message_t packet;
60
61 bool locked = FALSE;
62 uint16_t counter = 0;
63
64 event void Boot.booted() {
65 call Control.start();
66 }
67
68 event void MilliTimer.fired() {
69 counter++;
70 if (locked) {
71 return;
72 }
73 else {
74 test_serial_msg_t* rcm = (test_serial_msg_t*)call Packet.getPayload(&packet, sizeof(test_serial_msg_t));
75 if (rcm == NULL) {return;}
76 if (call Packet.maxPayloadLength() < sizeof(test_serial_msg_t)) {
77 return;
78 }
79
80 rcm->counter = counter * 3.2;
81 if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(test_serial_msg_t)) == SUCCESS) {
82 locked = TRUE;
83 }
84 }
85 }
86
87 event message_t* Receive.receive(message_t* bufPtr,
88 void* payload, uint8_t len) {
89 if (len != sizeof(test_serial_msg_t)) {return bufPtr;}
90 else {
91 test_serial_msg_t* rcm = (test_serial_msg_t*)payload;
92 if ((int)rcm->counter & 0x1) {
93 call Leds.led0On();
94 }
95 else {
96 call Leds.led0Off();
97 }
98 if ((int)rcm->counter & 0x2) {
99 call Leds.led1On();
100 }
101 else {
102 call Leds.led1Off();
103 }
104 if ((int)rcm->counter & 0x4) {
105 call Leds.led2On();
106 }
107 else {
108 call Leds.led2Off();
109 }
110 return bufPtr;
111 }
112 }
113
114 event void AMSend.sendDone(message_t* bufPtr, error_t error) {
115 if (&packet == bufPtr) {
116 locked = FALSE;
117 }
118 }
119
120 event void Control.startDone(error_t err) {
121 if (err == SUCCESS) {
122 call MilliTimer.startPeriodic(1000);
123 }
124 }
125 event void Control.stopDone(error_t err) {}
126 }
127
128
129
130